From df29ffbde72e88635f454d5d6d84c5a7209460f3 Mon Sep 17 00:00:00 2001 From: vdigital Date: Mon, 14 Jul 2008 21:42:40 +0000 Subject: Feature template-extension based on 2006 chrisaga's idea. chrisaga wrote: "If you want to make some template customization without building a brand new template, you should use ..." git-svn-id: http://piwigo.org/svn/trunk@2434 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/extend_for_templates.php | 213 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 admin/extend_for_templates.php (limited to 'admin/extend_for_templates.php') diff --git a/admin/extend_for_templates.php b/admin/extend_for_templates.php new file mode 100644 index 000000000..c6319368a --- /dev/null +++ b/admin/extend_for_templates.php @@ -0,0 +1,213 @@ + 0 ) + { + $extents[] = substr($path, 21); + } + } + return $extents; +} +// +-----------------------------------------------------------------------+ +// initialization | +// +-----------------------------------------------------------------------+ + +if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } +include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); +check_status(ACCESS_ADMINISTRATOR); + +$tpl_extension = isset($conf['extents_for_templates']) ? + unserialize($conf['extents_for_templates']) : array(); +$new_extensions = get_extents(); + +/* Selective URLs keyword */ +$relevant_parameters = array( + '----------', + 'category', + 'favorites', + 'most_visited', + 'best_rated', + 'recent_pics', + 'recent_cats', + 'created-monthly-calendar', + 'posted-monthly-calendar', + 'search', + 'flat', + 'list',); /* <=> Random */ + $query = ' +SELECT permalink + FROM '.CATEGORIES_TABLE.' + WHERE permalink IS NOT NULL +'; + +/* Add active permalinks */ +$permalinks = array_from_query($query, 'permalink'); +$relevant_parameters = array_merge($relevant_parameters, $permalinks); + +/* Link all supported templates to their respective handle */ +$eligible_templates = array( + '----------' => 'N/A', + 'about.tpl' => 'about', + 'identification.tpl' => 'identification', + 'mainpage_categories.tpl' => 'index_category', + 'thumbnails.tpl' => 'index_thumbnails', + 'redirect.tpl' => 'redirect', + 'menubar.tpl' => 'menubar', + 'header.tpl' => 'header', + 'footer.tpl' => 'tail', + 'index.tpl' => 'index', + 'nbm.tpl' => 'nbm', + 'notification.tpl' => 'notification', + 'picture_content.tpl' => 'default_content', + 'slideshow.tpl' => 'picture', /* => slideshow is missing */ + 'picture.tpl' => 'picture', + 'popuphelp.tpl' => 'popuphelp', + 'profile.tpl' => 'profile', + 'profile_content.tpl' => 'profile_content', + 'register.tpl' => 'register', + 'search.tpl' => 'search', + 'search_rules.tpl' => 'search_rules', + 'tags.tpl' => 'tags', + 'upload.tpl' => 'upload',); + $flip_templates = array_flip($eligible_templates); +// +-----------------------------------------------------------------------+ +// | selected templates | +// +-----------------------------------------------------------------------+ + +if (isset($_POST['submit']) and !is_adviser()) +{ + $replacements = array(); + $i = 0; + while (isset($_POST['reptpl'][$i])) + { + $newtpl = $_POST['reptpl'][$i]; + $original = $_POST['original'][$i]; + $handle = $eligible_templates[$original]; + $url_keyword = $_POST['url'][$i]; + if ($url_keyword == '----------') $url_keyword = 'N/A'; + if ($handle != 'N/A') + { + $replacements[$newtpl] = array($handle, $url_keyword); + } + $i++; + } + $conf['extents_for_templates'] = serialize($replacements); + $tpl_extension = $replacements; + /* ecrire la nouvelle conf */ + $query = " +UPDATE ".CONFIG_TABLE." + SET value = '". $conf['extents_for_templates'] ."' +WHERE param = 'extents_for_templates';"; + if (pwg_query($query)) + { + array_push($page['infos'], + l10n('Templates recorded.')); + } +} + +// +-----------------------------------------------------------------------+ +// | template init | +// +-----------------------------------------------------------------------+ + +/* Clearing (remove old extents, add new ones) */ +foreach ($tpl_extension as $file => $conditions) +{ + if ( !in_array($file,$new_extensions) ) unset($tpl_extension[$file]); + else $new_extensions = array_diff($new_extensions,array($file)); +} +foreach ($new_extensions as $file) +{ + $tpl_extension[$file] = array('N/A' => 'N/A'); +} + +$template->set_filenames(array('extend_for_templates' + => 'admin/extend_for_templates.tpl')); + +$base_url = PHPWG_ROOT_PATH.'admin.php?page=extend_for_templates'; + +$template->assign( + array( + 'U_HELP' => get_root_url().'popuphelp.php?page=extend_for_templates', + )); +ksort($tpl_extension); +foreach ($tpl_extension as $file => $conditions) +{ + $handle = $conditions[0]; + $url_keyword = $conditions[1]; + { + $template->append('extents', + array( + 'replacer' => $file, + 'url_parameter' => $relevant_parameters, + 'original_tpl' => array_keys($eligible_templates), + 'selected_tpl' => $flip_templates[$handle], + 'selected_url' => $url_keyword,) + ); + } +} +// +-----------------------------------------------------------------------+ +// | html code display | +// +-----------------------------------------------------------------------+ + +$template->assign_var_from_handle('ADMIN_CONTENT', 'extend_for_templates'); +?> \ No newline at end of file -- cgit v1.2.3