From 9a4a9d846e6bd74a61d1ab390ea4deb3224f4170 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Mon, 23 Jul 2012 11:50:41 +0000 Subject: feature 2703: make it easy for plugins to add tabs in admin screens centralize all core tabs in one file git-svn-id: http://piwigo.org/svn/trunk@16928 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin.php | 1 + admin/album.php | 4 - admin/batch_manager.php | 40 ++------- admin/cat_options.php | 14 --- admin/comments.php | 1 - admin/configuration.php | 9 -- admin/help.php | 44 ++-------- admin/include/add_core_tabs.inc.php | 147 ++++++++++++++++++++++++++++++++ admin/include/albums_tab.inc.php | 5 +- admin/include/functions_history.inc.php | 5 -- admin/include/tabsheet.class.php | 5 ++ admin/languages.php | 6 +- admin/notification_by_mail.php | 12 --- admin/photo.php | 3 - admin/photos_add.php | 40 +-------- admin/plugins.php | 3 - admin/rating.php | 2 - admin/rating_user.php | 2 - admin/themes.php | 3 - admin/updates.php | 4 +- 20 files changed, 170 insertions(+), 180 deletions(-) create mode 100644 admin/include/add_core_tabs.inc.php diff --git a/admin.php b/admin.php index 7282f1096..2a9f4cdd1 100644 --- a/admin.php +++ b/admin.php @@ -31,6 +31,7 @@ define('IN_ADMIN', true); 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'); diff --git a/admin/album.php b/admin/album.php index 289be09ee..8115d2e5c 100644 --- a/admin/album.php +++ b/admin/album.php @@ -63,10 +63,6 @@ if (isset($_GET['tab'])) $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(); diff --git a/admin/batch_manager.php b/admin/batch_manager.php index ddca63ed0..113d4c629 100644 --- a/admin/batch_manager.php +++ b/admin/batch_manager.php @@ -350,22 +350,7 @@ else // +-----------------------------------------------------------------------+ // | 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'])) { @@ -373,23 +358,13 @@ if (isset($_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 | @@ -405,6 +380,5 @@ $template->assign('tags', get_taglist($query, false)); // | open specific mode | // +-----------------------------------------------------------------------+ - include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php'); -} +include(PHPWG_ROOT_PATH.'admin/batch_manager_'.$page['tab'].'.php'); ?> \ No newline at end of file diff --git a/admin/cat_options.php b/admin/cat_options.php index aa871c309..18542d1f9 100644 --- a/admin/cat_options.php +++ b/admin/cat_options.php @@ -139,21 +139,7 @@ $template->assign( // 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(); // +-----------------------------------------------------------------------+ diff --git a/admin/comments.php b/admin/comments.php index 9b330ac8b..c36e42202 100644 --- a/admin/comments.php +++ b/admin/comments.php @@ -99,7 +99,6 @@ include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); $tabsheet = new tabsheet(); $tabsheet->set_id('comments'); -$tabsheet->add('', l10n('User comments validation'), ''); $tabsheet->select(''); $tabsheet->assign(); diff --git a/admin/configuration.php b/admin/configuration.php index aa27cc5f3..e4e881051 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -287,16 +287,7 @@ $template->set_filename('config', 'configuration.tpl'); // 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'; diff --git a/admin/help.php b/admin/help.php index ec4a1fc45..e47740ca9 100644 --- a/admin/help.php +++ b/admin/help.php @@ -29,54 +29,20 @@ include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); // +-----------------------------------------------------------------------+ check_status(ACCESS_ADMINISTRATOR); -$link = get_root_url().'admin.php?page=help§ion='; +$help_link = get_root_url().'admin.php?page=help§ion='; $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')); @@ -84,11 +50,11 @@ $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'], ) ); diff --git a/admin/include/add_core_tabs.inc.php b/admin/include/add_core_tabs.inc.php new file mode 100644 index 000000000..7f31b9bd5 --- /dev/null +++ b/admin/include/add_core_tabs.inc.php @@ -0,0 +1,147 @@ + 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&section=status'); + $sheets['visible'] = array('caption' => l10n('Lock'), 'url' => $link_start.'cat_options&section=visible'); + if ($conf['activate_comments']) + $sheets['comments'] = array('caption' => l10n('Comments'), 'url' => $link_start.'cat_options&section=comments'); + if ($conf['allow_random_representative']) + $sheets['representative'] = array('caption' => l10n('Representative'), 'url' => $link_start.'cat_options&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.'&tab=installed'); + $sheets['update'] = array('caption' => l10n('Check for updates'), 'url' => $my_base_url.'&tab=update'); + $sheets['new'] = array('caption' => l10n('Add New Language'), 'url' => $my_base_url.'&tab=new'); + break; + + case 'nbm': + global $base_url; + $sheets['param'] = array('caption' => l10n('Parameter'), 'url' => $base_url.'?page=notification_by_mail&mode=param'); + $sheets['subscribe'] = array('caption' => l10n('Subscribe'), 'url' => $base_url.'?page=notification_by_mail&mode=subscribe'); + $sheets['send'] = array('caption' => l10n('Send'), 'url' => $base_url.'?page=notification_by_mail&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.'&section=direct'); + $sheets['applications'] = array('caption' => l10n('Applications'), 'url' => PHOTOS_ADD_BASE_URL.'&section=applications'); + if ($conf['enable_synchronization']) + $sheets['ftp'] = array('caption' => l10n('FTP + Synchronization'), 'url' => PHOTOS_ADD_BASE_URL.'&section=ftp'); + break; + + case 'plugins': + global $my_base_url; + $sheets['installed'] = array('caption' => l10n('Plugin list'), 'url' => $my_base_url.'&tab=installed'); + $sheets['update'] = array('caption' => l10n('Check for updates'), 'url' => $my_base_url.'&tab=update'); + $sheets['new'] = array('caption' => l10n('Other plugins'), 'url' => $my_base_url.'&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.'&tab=installed'); + $sheets['update'] = array('caption' => l10n('Check for updates'), 'url' => $my_base_url.'&tab=update'); + $sheets['new'] = array('caption' => l10n('Add New Theme'), 'url' => $my_base_url.'&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.'&tab=ext'); + break; + } + + return $sheets; +} + +?> \ No newline at end of file diff --git a/admin/include/albums_tab.inc.php b/admin/include/albums_tab.inc.php index 22457efd3..9f555075c 100644 --- a/admin/include/albums_tab.inc.php +++ b/admin/include/albums_tab.inc.php @@ -26,10 +26,7 @@ include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); $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(); diff --git a/admin/include/functions_history.inc.php b/admin/include/functions_history.inc.php index 301ae6b7d..3a8aadf5e 100644 --- a/admin/include/functions_history.inc.php +++ b/admin/include/functions_history.inc.php @@ -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(); } diff --git a/admin/include/tabsheet.class.php b/admin/include/tabsheet.class.php index 02ee9a3d1..fdeeb2afd 100644 --- a/admin/include/tabsheet.class.php +++ b/admin/include/tabsheet.class.php @@ -89,6 +89,11 @@ class tabsheet 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; } diff --git a/admin/languages.php b/admin/languages.php index fd282d556..cc8057453 100644 --- a/admin/languages.php +++ b/admin/languages.php @@ -35,11 +35,7 @@ if (isset($_GET['tab'])) else $page['tab'] = 'installed'; -$tabsheet = new tabsheet(); -$tabsheet->set_id('languages'); -$tabsheet->add('installed', l10n('Installed Languages'), $my_base_url.'&tab=installed'); -$tabsheet->add('update', l10n('Check for updates'), $my_base_url.'&tab=update'); -$tabsheet->add('new', l10n('Add New Language'), $my_base_url.'&tab=new'); +$tabsheet = new tabsheet('languages'); $tabsheet->select($page['tab']); $tabsheet->assign(); diff --git a/admin/notification_by_mail.php b/admin/notification_by_mail.php index 1db2bae32..b65989bb3 100644 --- a/admin/notification_by_mail.php +++ b/admin/notification_by_mail.php @@ -589,19 +589,7 @@ if (is_autorize_status(ACCESS_WEBMASTER)) // TabSheet $tabsheet = new tabsheet(); $tabsheet->set_id('nbm'); - // TabSheet initialization - $tabsheet->add('param', l10n('Parameter'), - add_url_params($base_url.get_query_string_diff(array('mode', 'select')), - array('mode' => 'param'))); - $tabsheet->add('subscribe', l10n('Subscribe'), - add_url_params($base_url.get_query_string_diff(array('mode', 'select')), - array('mode' => 'subscribe'))); - $tabsheet->add('send', l10n('Send'), - add_url_params($base_url.get_query_string_diff(array('mode', 'select')), - array('mode' => 'send'))); - // TabSheet selection $tabsheet->select($page['mode']); - // Assign tabsheet to template $tabsheet->assign(); } diff --git a/admin/photo.php b/admin/photo.php index b016b4bcb..a2742d261 100644 --- a/admin/photo.php +++ b/admin/photo.php @@ -62,9 +62,6 @@ if (isset($_GET['tab'])) $tabsheet = new tabsheet(); $tabsheet->set_id('photo'); -$tabsheet->add('properties', l10n('Properties'), $admin_photo_base_url.'-properties'); -$tabsheet->add('coi', l10n('Center of interest'), $admin_photo_base_url.'-coi'); - $tabsheet->select($page['tab']); $tabsheet->assign(); diff --git a/admin/photos_add.php b/admin/photos_add.php index 92fd6b0bb..fbc7deeab 100644 --- a/admin/photos_add.php +++ b/admin/photos_add.php @@ -49,53 +49,17 @@ $upload_form_config = get_upload_form_config(); // +-----------------------------------------------------------------------+ // | Tabs | // +-----------------------------------------------------------------------+ - -$tabs = array( - array( - 'code' => 'direct', - 'label' => l10n('Web Form'), - ), - array( - 'code' => 'applications', - 'label' => l10n('Applications'), - ), - ); - -if ($conf['enable_synchronization']) -{ - array_push( - $tabs, - array( - 'code' => 'ftp', - 'label' => l10n('FTP + Synchronization'), - ) - ); -} - -$tab_codes = array_map( - create_function('$a', 'return $a["code"];'), - $tabs - ); - -if (isset($_GET['section']) and in_array($_GET['section'], $tab_codes)) +if (isset($_GET['section'])) { $page['tab'] = $_GET['section']; } else { - $page['tab'] = $tabs[0]['code']; + $page['tab'] = 'direct'; } $tabsheet = new tabsheet(); $tabsheet->set_id('photos_add'); -foreach ($tabs as $tab) -{ - $tabsheet->add( - $tab['code'], - $tab['label'], - PHOTOS_ADD_BASE_URL.'&section='.$tab['code'] - ); -} $tabsheet->select($page['tab']); $tabsheet->assign(); diff --git a/admin/plugins.php b/admin/plugins.php index 9c4e1d239..4e6d65821 100644 --- a/admin/plugins.php +++ b/admin/plugins.php @@ -37,9 +37,6 @@ else $tabsheet = new tabsheet(); $tabsheet->set_id('plugins'); -$tabsheet->add('installed', l10n('Plugin list'), $my_base_url.'&tab=installed'); -$tabsheet->add('update', l10n('Check for updates'), $my_base_url.'&tab=update'); -$tabsheet->add('new', l10n('Other plugins'), $my_base_url.'&tab=new'); $tabsheet->select($page['tab']); $tabsheet->assign(); diff --git a/admin/rating.php b/admin/rating.php index 0f495c876..44eaa55ec 100644 --- a/admin/rating.php +++ b/admin/rating.php @@ -37,8 +37,6 @@ check_status(ACCESS_ADMINISTRATOR); include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); $tabsheet = new tabsheet(); $tabsheet->set_id('rating'); -$tabsheet->add('rating', l10n('Photos'), get_root_url().'admin.php?page=rating'); -$tabsheet->add('rating_user', l10n('Users'), get_root_url().'admin.php?page=rating_user'); $tabsheet->select('rating'); $tabsheet->assign(); diff --git a/admin/rating_user.php b/admin/rating_user.php index 480ec41c4..cba290260 100644 --- a/admin/rating_user.php +++ b/admin/rating_user.php @@ -26,8 +26,6 @@ defined('PHPWG_ROOT_PATH') or die ("Hacking attempt!"); include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); $tabsheet = new tabsheet(); $tabsheet->set_id('rating'); -$tabsheet->add('rating', l10n('Photos'), get_root_url().'admin.php?page=rating'); -$tabsheet->add('rating_user', l10n('Users'), get_root_url().'admin.php?page=rating_user'); $tabsheet->select('rating_user'); $tabsheet->assign(); diff --git a/admin/themes.php b/admin/themes.php index 93d159dc2..a7a7278ef 100644 --- a/admin/themes.php +++ b/admin/themes.php @@ -37,9 +37,6 @@ else $tabsheet = new tabsheet(); $tabsheet->set_id('themes'); -$tabsheet->add('installed', l10n('Installed Themes'), $my_base_url.'&tab=installed'); -$tabsheet->add('update', l10n('Check for updates'), $my_base_url.'&tab=update'); -$tabsheet->add('new', l10n('Add New Theme'), $my_base_url.'&tab=new'); $tabsheet->select($page['tab']); $tabsheet->assign(); diff --git a/admin/updates.php b/admin/updates.php index 3a2c3609d..bb0337d47 100644 --- a/admin/updates.php +++ b/admin/updates.php @@ -33,10 +33,8 @@ if (isset($_GET['tab'])) else $page['tab'] = 'pwg'; -$tabsheet = new tabsheet(); +$tabsheet = new tabsheet(); $tabsheet->set_id('updates'); -$tabsheet->add('pwg', l10n('Piwigo Update'), $my_base_url); -$tabsheet->add('ext', l10n('Extensions Update'), $my_base_url.'&tab=ext'); $tabsheet->select($page['tab']); $tabsheet->assign(); -- cgit v1.2.3