source: extensions/header_manager/include/header_manager.inc.php @ 20169

Last change on this file since 20169 was 20169, checked in by mistic100, 11 years ago

display banners size, list specific album banners

File size: 3.2 KB
Line 
1<?php
2if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
3
4/**
5 * add personal banner to page banner
6 */
7function header_manager_render($page_banner)
8{
9  global $conf, $user, $template, $page;
10 
11  if ( script_basename() == 'picture' and !$conf['header_manager']['banner_on_picture'] )
12  {
13    return null;
14  }
15 
16  // search banner for a specific category
17  if (isset($page['category']))
18  {
19    // we use the banner configured for this category
20    // if no banner is configured we use the banner of the first parent category with a "deep" banner
21    // if nothing found we use the default banner
22    $query = '
23SELECT *
24  FROM '.HEADER_MANAGER_TABLE.'
25  WHERE
26    category_id IN ('.$page['category']['uppercats'].')
27    AND (category_id = '.$page['category']['id'].' OR deep = 1)
28;';
29    $cat_banners = hash_from_query($query, 'category_id');
30   
31    if (count($cat_banners))
32    {
33      usort($cat_banners, 'hm_uppercats_sort');
34     
35      foreach ($cat_banners as $cat_banner)
36      {
37        $cat_banner = get_banner($cat_banner['image']);
38        if ($cat_banner !== false)
39        {
40          $banner = $cat_banner;
41          break;
42        }
43      }
44    }
45  }
46 
47  // use default banner
48  if (!isset($banner))
49  {
50    if ( empty($conf['header_manager']['image']) or $conf['header_manager']['image'] == 'random')
51    {
52      $banners = array_values(list_banners());
53      if (!count($banners)) return $page_banner;
54      $banner = $banners[ mt_rand(0, count($banners)-1) ];
55    }
56    else
57    {
58      $banner = get_banner($conf['header_manager']['image']);
59      if ($banner === false) return $page_banner;
60    }
61  }
62 
63  // for MontBlancXL and BlancMontXL the banner is displayed as background of the header
64  if ( in_array($user['theme'], array('blancmontxl','montblancxl')) )
65  {
66    $template->append('head_elements',
67'<style type="text/css">
68#theHeader { background: transparent url('.$banner['PATH'].') center bottom no-repeat; }
69</style>'
70      );
71
72    if ($conf['header_manager']['display'] == 'image_only')
73    {
74      $page_banner = null;
75    }
76    else
77    {
78      $page_banner = str_replace('%header_manager%', null, $page_banner);
79    }
80  }
81  // no support for Kardon (not enough space)
82  else if ($user['theme'] != 'kardon')
83  {
84    $template->append('head_elements',
85'<style type="text/css">
86#theHeader div.banner { background:transparent url(\''.$banner['PATH'].'\') center center no-repeat;height:'.$banner['SIZE'][1].'px;line-height:'.($banner['SIZE'][1]-12).'px;font-size:2.5em;color:#fff;text-shadow:0 0 5px #000;text-align:center; }
87</style>'
88      );
89   
90    $banner_img = '<div class="banner">'.($conf['header_manager']['display']=='with_title' ? $conf['gallery_title'] : '&nbsp;').'</div>';
91   
92    if ($conf['header_manager']['display'] == 'with_text')
93    {
94      $page_banner = str_replace('%header_manager%', $banner_img, $page_banner);
95    }
96    else
97    {
98      $page_banner = '<a href="'.get_gallery_home_url().'">'.$banner_img.'</a>';
99    }
100  }
101
102  return $page_banner;
103}
104
105function hm_uppercats_sort($a, $b)
106{
107  global $page;
108  $ids = explode(',', $page['category']['uppercats']);
109  return array_search($a['category_id'], $ids) < array_search($b['category_id'], $ids);
110}
111
112?>
Note: See TracBrowser for help on using the repository browser.