Changeset 16937


Ignore:
Timestamp:
Jul 23, 2012, 4:41:12 PM (8 years ago)
Author:
mistic100
Message:

ability to define a specific banner for an album + apply to sub-cats
(needs Piwigo 2.4.2 for tabs)

Location:
extensions/header_manager
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/header_manager/admin.php

    r15854 r16937  
    1010}
    1111
     12$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : 'config';
    1213
    13 // tabsheet
    14 include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    15 $page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'config';
    16  
    17 $tabsheet = new tabsheet();
    18 $tabsheet->add('config', l10n('Configuration'), HEADER_MANAGER_ADMIN . '-config');
    19 $tabsheet->add('add', l10n('Add a banner'), HEADER_MANAGER_ADMIN . '-add');
    20 $tabsheet->select($page['tab']);
    21 $tabsheet->assign();
     14if ($page['tab'] == 'album')
     15{
     16  include(HEADER_MANAGER_PATH . 'admin/album.php');
     17}
     18else
     19{
     20  // tabsheet
     21  include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');   
     22  $tabsheet = new tabsheet();
     23  $tabsheet->add('config', l10n('Configuration'), HEADER_MANAGER_ADMIN . '-config');
     24  $tabsheet->add('add', l10n('Add a banner'), HEADER_MANAGER_ADMIN . '-add');
     25  $tabsheet->select($page['tab']);
     26  $tabsheet->assign();
    2227
    23 // include page
    24 include(HEADER_MANAGER_PATH . 'admin/' . $page['tab'] . '.php');
     28  // include page
     29  include(HEADER_MANAGER_PATH . 'admin/' . $page['tab'] . '.php');
    2530
    26 // template
    27 $template->assign(array(
    28   'HEADER_MANAGER_PATH'=> HEADER_MANAGER_PATH,
    29   'CONFIG_URL' => HEADER_MANAGER_ADMIN . '-config',
    30   'ADD_IMAGE_URL' => HEADER_MANAGER_ADMIN . '-add',
    31   ));
     31  // template
     32  $template->assign(array(
     33    'CONFIG_URL' => HEADER_MANAGER_ADMIN . '-config',
     34    'ADD_IMAGE_URL' => HEADER_MANAGER_ADMIN . '-add',
     35    ));
     36}
     37
     38$template->assign('HEADER_MANAGER_PATH', HEADER_MANAGER_PATH);
     39
    3240$template->assign_var_from_handle('ADMIN_CONTENT', 'header_manager');
    3341
  • extensions/header_manager/include/header_manager.inc.php

    r15922 r16937  
    77function header_manager_render($page_banner)
    88{
    9   global $conf, $user, $template;
     9  global $conf, $user, $template, $page;
    1010 
    11   if ($conf['header_manager']['image'] == 'random')
     11  // search banner for a specific category
     12  if (isset($page['category']))
    1213  {
    13     $banners = list_banners();
    14     if (!count($banners)) return $page_banner;
    15     $banner = $banners[ mt_rand(0, count($banners)-1) ];
     14    // we use the banner configured for this category
     15    // if no banner is configured we use the banner of the first parent category with a "deep" banner
     16    // if nothing found we use the default banner
     17    $query = '
     18SELECT *
     19  FROM '.HEADER_MANAGER_TABLE.'
     20  WHERE
     21    category_id IN ('.$page['category']['uppercats'].')
     22    AND (category_id = '.$page['category']['id'].' OR deep = 1)
     23;';
     24    $cat_banners = hash_from_query($query, 'category_id');
     25   
     26    if (count($cat_banners))
     27    {
     28      function uppercats_sort($a, $b)
     29      {
     30        global $page;
     31        $ids = explode(',', $page['category']['uppercats']);
     32        return array_search($a['category_id'], $ids) < array_search($b['category_id'], $ids);
     33      }
     34      usort($cat_banners, 'uppercats_sort');
     35     
     36      foreach ($cat_banners as $cat_banner)
     37      {
     38        $cat_banner = get_banner($cat_banner['image']);
     39        if ($cat_banner !== false)
     40        {
     41          $banner = $cat_banner;
     42          break;
     43        }
     44      }
     45    }
    1646  }
    17   else
     47 
     48  // use default banner
     49  if (!isset($banner))
    1850  {
    19     $banner = get_banner($conf['header_manager']['image']);
    20     if (!file_exists($banner['PATH'])) return $page_banner;
     51    if ($conf['header_manager']['image'] == 'random')
     52    {
     53      $banners = list_banners();
     54      if (!count($banners)) return $page_banner;
     55      $banner = $banners[ mt_rand(0, count($banners)-1) ];
     56    }
     57    else
     58    {
     59      $banner = get_banner($conf['header_manager']['image']);
     60      if ($banner === false) return $page_banner;
     61    }
    2162  }
    2263 
     
    75116}
    76117
     118/**
     119 * tab on album edition page
     120 */
     121function header_manager_tab($sheets, $id)
     122{
     123  if ($id == 'album')
     124  {
     125    load_language('plugin.lang', HEADER_MANAGER_PATH);
     126   
     127    $sheets['headermanager'] = array(
     128      'caption' => l10n('Banner'),
     129      'url' => HEADER_MANAGER_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'],
     130      );
     131  }
     132 
     133  return $sheets;
     134}
     135
    77136?>
  • extensions/header_manager/language/en_UK/plugin.lang.php

    r15854 r16937  
    3131$lang['Add a banner'] = 'Add a banner';
    3232
     33$lang['Default banner'] = 'Default banner';
     34
    3335?>
  • extensions/header_manager/language/fr_FR/plugin.lang.php

    r15854 r16937  
    3131$lang['Add a banner'] = 'Ajouter une bannière';
    3232
     33$lang['Default banner'] = 'Bannière par défaut';
     34
    3335?>
  • extensions/header_manager/main.inc.php

    r16088 r16937  
    1111if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1212
     13global $prefixeTable;
    1314define('HEADER_MANAGER_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
    1415define('HEADER_MANAGER_ADMIN', get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
    1516define('HEADER_MANAGER_DIR', PWG_LOCAL_DIR . 'banners/');
     17define('HEADER_MANAGER_TABLE', $prefixeTable . 'category_banner');
    1618
    1719add_event_handler('init', 'header_manager_init');
     
    3133  if (defined('IN_ADMIN'))
    3234  {
     35    add_event_handler('tabsheet_before_select', 'header_manager_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    3336    add_event_handler('get_admin_plugin_menu_links', 'header_manager_admin_menu');
    3437  }
  • extensions/header_manager/maintain.inc.php

    r15854 r16937  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 define('HEADER_MANAGER_DIR', PWG_LOCAL_DIR . 'banners/');
     4define('header_dir', PWG_LOCAL_DIR . 'banners/');
    55
    66define(
     
    1717function plugin_install()
    1818{
     19  global $prefixeTable;
     20 
     21        pwg_query(
     22'CREATE TABLE IF NOT EXISTS `' .$prefixeTable . 'category_banner` (
     23  `category_id` smallint(5) unsigned NOT NULL,
     24  `image` varchar(255) NOT NULL,
     25  `deep` tinyint(1) DEFAULT 1,
     26  PRIMARY KEY (`category_id`)
     27) ENGINE=MyISAM DEFAULT CHARSET=utf8
     28;');
     29
    1930  conf_update_param('header_manager', header_manager_default_config);
    20   mkdir(HEADER_MANAGER_DIR, 0755);
     31  mkdir(header_dir, 0755);
    2132}
    2233
    2334function plugin_activate()
    2435{
    25   global $conf;
     36  global $conf, $prefixeTable;
    2637
    2738  if (empty($conf['header_manager']))
     
    2940    conf_update_param('header_manager', header_manager_default_config);
    3041  }
    31   if (!file_exists(HEADER_MANAGER_DIR))
     42  if (!file_exists(header_dir))
    3243  {
    33     mkdir(HEADER_MANAGER_DIR, 0755);
     44    mkdir(header_dir, 0755);
    3445  }
     46 
     47  pwg_query(
     48'CREATE TABLE IF NOT EXISTS `' .$prefixeTable . 'category_banner` (
     49  `category_id` smallint(5) unsigned NOT NULL,
     50  `image` varchar(255) NOT NULL,
     51  `deep` tinyint(1) DEFAULT 1,
     52  PRIMARY KEY (`category_id`)
     53) ENGINE=MyISAM DEFAULT CHARSET=utf8
     54;');
    3555}
    3656
    3757function plugin_uninstall()
    3858{
     59  global $prefixeTable;
     60 
     61  pwg_query('DROP TABLE `' .$prefixeTable . 'category_banner`;');
    3962  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "header_manager" LIMIT 1;');
    4063}
Note: See TracChangeset for help on using the changeset viewer.