Skip to content

Commit

Permalink
feature 2703: make it easy for plugins to add tabs in admin screens
Browse files Browse the repository at this point in the history
centralize all core tabs in one file

git-svn-id: http://piwigo.org/svn/trunk@16928 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jul 23, 2012
1 parent 7b181f0 commit 9a4a9d8
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 180 deletions.
1 change: 1 addition & 0 deletions admin.php
Expand Up @@ -31,6 +31,7 @@
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php');
include_once(PHPWG_ROOT_PATH.'admin/include/add_core_tabs.inc.php');

trigger_action('loc_begin_admin');

Expand Down
4 changes: 0 additions & 4 deletions admin/album.php
Expand Up @@ -63,10 +63,6 @@

$tabsheet = new tabsheet();
$tabsheet->set_id('album');
$tabsheet->add('properties', l10n('Properties'), $admin_album_base_url.'-properties');
$tabsheet->add('sort_order', l10n('Manage photo ranks'), $admin_album_base_url.'-sort_order');
$tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
$tabsheet->add('notification', l10n('Notification'), $admin_album_base_url.'-notification');
$tabsheet->select($page['tab']);
$tabsheet->assign();

Expand Down
40 changes: 7 additions & 33 deletions admin/batch_manager.php
Expand Up @@ -350,46 +350,21 @@
// +-----------------------------------------------------------------------+
// | Tabs |
// +-----------------------------------------------------------------------+

$tabs = array(
array(
'code' => 'global',
'label' => l10n('global mode'),
),
array(
'code' => 'unit',
'label' => l10n('unit mode'),
),
);

$tab_codes = array_map(
create_function('$a', 'return $a["code"];'),
$tabs
);
$manager_link = get_root_url().'admin.php?page=batch_manager&mode=';

if (isset($_GET['mode']))
{
$page['tab'] = $_GET['mode'];
}
else
{
$page['tab'] = $tabs[0]['code'];
$page['tab'] = 'global';
}

if (in_array($page['tab'], $tab_codes))
{
$tabsheet = new tabsheet();
$tabsheet->set_id('batch_manager');
foreach ($tabs as $tab)
{
$tabsheet->add(
$tab['code'],
$tab['label'],
get_root_url().'admin.php?page='.$_GET['page'].'&mode='.$tab['code']
);
}
$tabsheet->select($page['tab']);
$tabsheet->assign();
$tabsheet = new tabsheet();
$tabsheet->set_id('batch_manager');
$tabsheet->select($page['tab']);
$tabsheet->assign();

// +-----------------------------------------------------------------------+
// | tags |
Expand All @@ -405,6 +380,5 @@
// | open specific mode |
// +-----------------------------------------------------------------------+

include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php');
}
include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php');
?>
14 changes: 0 additions & 14 deletions admin/cat_options.php
Expand Up @@ -139,21 +139,7 @@
// TabSheet
$tabsheet = new tabsheet();
$tabsheet->set_id('cat_options');
// TabSheet initialization
$opt_link = $link_start.'cat_options&section=';
$tabsheet->add('status', l10n('Public / Private'), $opt_link.'status');
$tabsheet->add('visible', l10n('Lock'), $opt_link.'visible');
if ($conf['activate_comments'])
{
$tabsheet->add('comments', l10n('Comments'), $opt_link.'comments');
}
if ($conf['allow_random_representative'])
{
$tabsheet->add('representative', l10n('Representative'), $opt_link.'representative');
}
// TabSheet selection
$tabsheet->select($page['section']);
// Assign tabsheet to template
$tabsheet->assign();

// +-----------------------------------------------------------------------+
Expand Down
1 change: 0 additions & 1 deletion admin/comments.php
Expand Up @@ -99,7 +99,6 @@

$tabsheet = new tabsheet();
$tabsheet->set_id('comments');
$tabsheet->add('', l10n('User comments validation'), '');
$tabsheet->select('');
$tabsheet->assign();

Expand Down
9 changes: 0 additions & 9 deletions admin/configuration.php
Expand Up @@ -287,16 +287,7 @@
// TabSheet
$tabsheet = new tabsheet();
$tabsheet->set_id('configuration');
// TabSheet initialization
$tabsheet->add('main', l10n('Main'), $conf_link.'main');
$tabsheet->add('sizes', l10n('Photo sizes'), $conf_link.'sizes');
$tabsheet->add('watermark', l10n('Watermark'), $conf_link.'watermark');
$tabsheet->add('display', l10n('Display'), $conf_link.'display');
$tabsheet->add('comments', l10n('Comments'), $conf_link.'comments');
$tabsheet->add('default', l10n('Guest Settings'), $conf_link.'default');
// TabSheet selection
$tabsheet->select($page['section']);
// Assign tabsheet to template
$tabsheet->assign();

$action = get_root_url().'admin.php?page=configuration';
Expand Down
44 changes: 5 additions & 39 deletions admin/help.php
Expand Up @@ -29,66 +29,32 @@
// +-----------------------------------------------------------------------+
check_status(ACCESS_ADMINISTRATOR);

$link = get_root_url().'admin.php?page=help&section=';
$help_link = get_root_url().'admin.php?page=help&section=';
$selected = null;
$help_section_title = null;

$tabs = array();
$tabs[] = array(
'code' => 'add_photos',
'label' => l10n('Add Photos'),
);
$tabs[] = array(
'code' => 'permissions',
'label' => l10n('Permissions'),
);
$tabs[] = array(
'code' => 'groups',
'label' => l10n('Groups'),
);
$tabs[] = array(
'code' => 'virtual_links',
'label' => l10n('Virtual Links'),
);
$tabs[] = array(
'code' => 'misc',
'label' => l10n('Miscellaneous'),
);

if (!isset($_GET['section']))
{
$section = $tabs[0]['code'];
$selected = 'add_photos';
}
else
{
$section = $_GET['section'];
$selected = $_GET['section'];
}

$tabsheet = new tabsheet();
$tabsheet->set_id('help');
foreach ($tabs as $tab)
{
if ($tab['code'] == $section)
{
$selected_tab = $tab['code'];
$help_section_title = $tab['label'];
}

$tabsheet->add($tab['code'], $tab['label'], $link.$tab['code']);
}
$tabsheet->select($selected_tab);
$tabsheet->assign();

$template->set_filenames(array('help' => 'help.tpl'));

$template->assign(
array(
'HELP_CONTENT' => load_language(
'help/help_'.$selected_tab.'.html',
'help/help_'.$tabsheet->selected.'.html',
'',
array('return'=>true)
),
'HELP_SECTION_TITLE' => $help_section_title,
'HELP_SECTION_TITLE' => $tabsheet->sheets[ $tabsheet->selected ]['caption'],
)
);

Expand Down
147 changes: 147 additions & 0 deletions admin/include/add_core_tabs.inc.php
@@ -0,0 +1,147 @@
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+

add_event_handler('tabsheet_before_select', 'add_core_tabs', 0, 2);

function add_core_tabs($sheets, $tab_id)
{
switch($tab_id)
{
case 'album':
global $admin_album_base_url;
$sheets['properties'] = array('caption' => l10n('Properties'), 'url' => $admin_album_base_url.'-properties');
$sheets['sort_order'] = array('caption' => l10n('Manage photo ranks'), 'url' => $admin_album_base_url.'-sort_order');
$sheets['permissions'] = array('caption' => l10n('Permissions'), 'url' => $admin_album_base_url.'-permissions');
$sheets['notification'] = array('caption' => l10n('Notification'), 'url' => $admin_album_base_url.'-notification');
break;

case 'albums':
global $my_base_url;
$sheets['list'] = array('caption' => l10n('List'), 'url' => $my_base_url.'cat_list');
$sheets['move'] = array('caption' => l10n('Move'), 'url' => $my_base_url.'cat_move');
$sheets['permalinks'] = array('caption' => l10n('Permalinks'), 'url' => $my_base_url.'permalinks');
break;

case 'batch_manager':
global $manager_link;
$sheets['global'] = array('caption' => l10n('global mode'), 'url' => $manager_link.'global');
$sheets['unit'] = array('caption' => l10n('unit mode'), 'url' => $manager_link.'unit');
break;

case 'cat_options':
global $link_start, $conf;
$sheets['status'] = array('caption' => l10n('Public / Private'), 'url' => $link_start.'cat_options&amp;section=status');
$sheets['visible'] = array('caption' => l10n('Lock'), 'url' => $link_start.'cat_options&amp;section=visible');
if ($conf['activate_comments'])
$sheets['comments'] = array('caption' => l10n('Comments'), 'url' => $link_start.'cat_options&amp;section=comments');
if ($conf['allow_random_representative'])
$sheets['representative'] = array('caption' => l10n('Representative'), 'url' => $link_start.'cat_options&amp;section=representative');
break;

case 'comments':
$sheets[''] = array('caption' => l10n('User comments validation'), 'url' => '');
break;

case 'configuration':
global $conf_link;
$sheets['main'] = array('caption' => l10n('Main'), 'url' => $conf_link.'main');
$sheets['sizes'] = array('caption' => l10n('Photo sizes'), 'url' => $conf_link.'sizes');
$sheets['watermark'] = array('caption' => l10n('Watermark'), 'url' => $conf_link.'watermark');
$sheets['display'] = array('caption' => l10n('Display'), 'url' => $conf_link.'display');
$sheets['comments'] = array('caption' => l10n('Comments'), 'url' => $conf_link.'comments');
$sheets['default'] = array('caption' => l10n('Guest Settings'), 'url' => $conf_link.'default');
break;

case 'help':
global $help_link;
$sheets['add_photos'] = array('caption' => l10n('Add Photos'), 'url' => $help_link.'add_photos');
$sheets['permissions'] = array('caption' => l10n('Permissions'), 'url' => $help_link.'permissions');
$sheets['groups'] = array('caption' => l10n('Groups'), 'url' => $help_link.'groups');
$sheets['virtual_links'] = array('caption' => l10n('Virtual Links'), 'url' => $help_link.'virtual_links');
$sheets['misc'] = array('caption' => l10n('Miscellaneous'), 'url' => $help_link.'misc');
break;

case 'history':
global $link_start;
$sheets['stats'] = array('caption' => l10n('Statistics'), 'url' => $link_start.'stats');
$sheets['history'] = array('caption' => l10n('Search'), 'url' => $link_start.'history');
break;

case 'languages':
global $my_base_url;
$sheets['installed'] = array('caption' => l10n('Installed Languages'), 'url' => $my_base_url.'&amp;tab=installed');
$sheets['update'] = array('caption' => l10n('Check for updates'), 'url' => $my_base_url.'&amp;tab=update');
$sheets['new'] = array('caption' => l10n('Add New Language'), 'url' => $my_base_url.'&amp;tab=new');
break;

case 'nbm':
global $base_url;
$sheets['param'] = array('caption' => l10n('Parameter'), 'url' => $base_url.'?page=notification_by_mail&amp;mode=param');
$sheets['subscribe'] = array('caption' => l10n('Subscribe'), 'url' => $base_url.'?page=notification_by_mail&amp;mode=subscribe');
$sheets['send'] = array('caption' => l10n('Send'), 'url' => $base_url.'?page=notification_by_mail&amp;mode=send');
break;

case 'photo':
global $admin_photo_base_url;
$sheets['properties'] = array('caption' => l10n('Properties'), 'url' => $admin_photo_base_url.'-properties');
$sheets['coi'] = array('caption' => l10n('Center of interest'), 'url' => $admin_photo_base_url.'-coi');
break;

case 'photos_add':
global $conf;
$sheets['direct'] = array('caption' => l10n('Web Form'), 'url' => PHOTOS_ADD_BASE_URL.'&amp;section=direct');
$sheets['applications'] = array('caption' => l10n('Applications'), 'url' => PHOTOS_ADD_BASE_URL.'&amp;section=applications');
if ($conf['enable_synchronization'])
$sheets['ftp'] = array('caption' => l10n('FTP + Synchronization'), 'url' => PHOTOS_ADD_BASE_URL.'&amp;section=ftp');
break;

case 'plugins':
global $my_base_url;
$sheets['installed'] = array('caption' => l10n('Plugin list'), 'url' => $my_base_url.'&amp;tab=installed');
$sheets['update'] = array('caption' => l10n('Check for updates'), 'url' => $my_base_url.'&amp;tab=update');
$sheets['new'] = array('caption' => l10n('Other plugins'), 'url' => $my_base_url.'&amp;tab=new');
break;

case 'rating':
$sheets['rating'] = array('caption' => l10n('Photos'), 'url' => get_root_url().'admin.php?page=rating');
$sheets['rating_user'] = array('caption' => l10n('Users'), 'url' => get_root_url().'admin.php?page=rating_user');
break;

case 'themes':
global $my_base_url;
$sheets['installed'] = array('caption' => l10n('Installed Themes'), 'url' => $my_base_url.'&amp;tab=installed');
$sheets['update'] = array('caption' => l10n('Check for updates'), 'url' => $my_base_url.'&amp;tab=update');
$sheets['new'] = array('caption' => l10n('Add New Theme'), 'url' => $my_base_url.'&amp;tab=new');
break;

case 'updates':
global $my_base_url;
$sheets['pwg'] = array('caption' => l10n('Piwigo Update'), 'url' => $my_base_url);
$sheets['ext'] = array('caption' => l10n('Extensions Update'), 'url' => $my_base_url.'&amp;tab=ext');
break;
}

return $sheets;
}

?>
5 changes: 1 addition & 4 deletions admin/include/albums_tab.inc.php
Expand Up @@ -26,10 +26,7 @@
$my_base_url = get_root_url().'admin.php?page=';

$tabsheet = new tabsheet();
$tabsheet->set_id('cat_list');
$tabsheet->add('list', l10n('List'), $my_base_url.'cat_list');
$tabsheet->add('move', l10n('Move'), $my_base_url.'cat_move');
$tabsheet->add('permalinks', l10n('Permalinks'), $my_base_url.'permalinks');
$tabsheet->set_id('albums');
$tabsheet->select($page['tab']);
$tabsheet->assign();

Expand Down
5 changes: 0 additions & 5 deletions admin/include/functions_history.inc.php
Expand Up @@ -30,12 +30,7 @@ function history_tabsheet()
// TabSheet
$tabsheet = new tabsheet();
$tabsheet->set_id('history');
// TabSheet initialization
$tabsheet->add('stats', l10n('Statistics'), $link_start.'stats');
$tabsheet->add('history', l10n('Search'), $link_start.'history');
// TabSheet selection
$tabsheet->select($page['page']);
// Assign tabsheet to template
$tabsheet->assign();
}

Expand Down
5 changes: 5 additions & 0 deletions admin/include/tabsheet.class.php
Expand Up @@ -89,6 +89,11 @@ function delete($name)
function select($name)
{
$this->sheets = trigger_event('tabsheet_before_select', $this->sheets, $this->uniqid);
if (!array_key_exists($name, $this->sheets))
{
$keys = array_keys($this->sheets);
$name = $keys[0];
}
$this->selected = $name;
}

Expand Down
6 changes: 1 addition & 5 deletions admin/languages.php
Expand Up @@ -35,11 +35,7 @@
else
$page['tab'] = 'installed';

$tabsheet = new tabsheet();
$tabsheet->set_id('languages');
$tabsheet->add('installed', l10n('Installed Languages'), $my_base_url.'&amp;tab=installed');
$tabsheet->add('update', l10n('Check for updates'), $my_base_url.'&amp;tab=update');
$tabsheet->add('new', l10n('Add New Language'), $my_base_url.'&amp;tab=new');
$tabsheet = new tabsheet('languages');
$tabsheet->select($page['tab']);
$tabsheet->assign();

Expand Down

0 comments on commit 9a4a9d8

Please sign in to comment.