| [2434] | 1 | <?php |
|---|
| 2 | // +-----------------------------------------------------------------------+ |
|---|
| [8728] | 3 | // | Piwigo - a PHP based photo gallery | |
|---|
| [2434] | 4 | // +-----------------------------------------------------------------------+ |
|---|
| [8728] | 5 | // | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org | |
|---|
| [2434] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
|---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
|---|
| 8 | // +-----------------------------------------------------------------------+ |
|---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
|---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
|---|
| 11 | // | the Free Software Foundation | |
|---|
| 12 | // | | |
|---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
|---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|---|
| 16 | // | General Public License for more details. | |
|---|
| 17 | // | | |
|---|
| 18 | // | You should have received a copy of the GNU General Public License | |
|---|
| 19 | // | along with this program; if not, write to the Free Software | |
|---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
|---|
| 21 | // | USA. | |
|---|
| 22 | // +-----------------------------------------------------------------------+ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * Define replacement conditions for each template from template-extension |
|---|
| 26 | * (template called "replacer"). |
|---|
| 27 | * |
|---|
| 28 | * "original template" from ./template/yoga (or any other than yoga) |
|---|
| 29 | * will be replaced by a "replacer" if the replacer is linked to this "original template" |
|---|
| 30 | * (and optionally, when the requested URL contains an "optional URL keyword"). |
|---|
| 31 | * |
|---|
| 32 | * "Optional URL keywords" are those you can find after the module name in URLs. |
|---|
| 33 | * |
|---|
| 34 | * Therefore "Optional URL keywords" can be an active "permalink" |
|---|
| 35 | * (see permalinks in our documentation for further explanation). |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | // +-----------------------------------------------------------------------+ |
|---|
| 39 | // initialization | |
|---|
| 40 | // +-----------------------------------------------------------------------+ |
|---|
| 41 | |
|---|
| 42 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
|---|
| 43 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
|---|
| 44 | check_status(ACCESS_ADMINISTRATOR); |
|---|
| 45 | |
|---|
| 46 | $tpl_extension = isset($conf['extents_for_templates']) ? |
|---|
| 47 | unserialize($conf['extents_for_templates']) : array(); |
|---|
| 48 | $new_extensions = get_extents(); |
|---|
| 49 | |
|---|
| 50 | /* Selective URLs keyword */ |
|---|
| 51 | $relevant_parameters = array( |
|---|
| 52 | '----------', |
|---|
| 53 | 'category', |
|---|
| 54 | 'favorites', |
|---|
| 55 | 'most_visited', |
|---|
| 56 | 'best_rated', |
|---|
| 57 | 'recent_pics', |
|---|
| 58 | 'recent_cats', |
|---|
| 59 | 'created-monthly-calendar', |
|---|
| 60 | 'posted-monthly-calendar', |
|---|
| 61 | 'search', |
|---|
| 62 | 'flat', |
|---|
| [3207] | 63 | 'list', /* <=> Random */ |
|---|
| 64 | 'tags', |
|---|
| 65 | ); |
|---|
| [2434] | 66 | $query = ' |
|---|
| 67 | SELECT permalink |
|---|
| 68 | FROM '.CATEGORIES_TABLE.' |
|---|
| 69 | WHERE permalink IS NOT NULL |
|---|
| 70 | '; |
|---|
| 71 | |
|---|
| 72 | /* Add active permalinks */ |
|---|
| 73 | $permalinks = array_from_query($query, 'permalink'); |
|---|
| 74 | $relevant_parameters = array_merge($relevant_parameters, $permalinks); |
|---|
| 75 | |
|---|
| 76 | /* Link all supported templates to their respective handle */ |
|---|
| 77 | $eligible_templates = array( |
|---|
| [2712] | 78 | '----------' => 'N/A', |
|---|
| 79 | 'about.tpl' => 'about', |
|---|
| [10005] | 80 | 'comments.tpl' => 'comments', |
|---|
| 81 | 'comment_list.tpl' => 'comment_list', |
|---|
| [3182] | 82 | 'footer.tpl' => 'tail', |
|---|
| 83 | 'header.tpl' => 'header', |
|---|
| [2712] | 84 | 'identification.tpl' => 'identification', |
|---|
| [3182] | 85 | 'index.tpl' => 'index', |
|---|
| [2712] | 86 | 'mainpage_categories.tpl' => 'index_category_thumbnails', |
|---|
| 87 | 'menubar.tpl' => 'menubar', |
|---|
| 88 | 'menubar_categories.tpl' => 'mbCategories', |
|---|
| 89 | 'menubar_identification.tpl' => 'mbIdentification', |
|---|
| 90 | 'menubar_links.tpl' => 'mbLinks', |
|---|
| 91 | 'menubar_menu.tpl' => 'mbMenu', |
|---|
| 92 | 'menubar_specials.tpl' => 'mbSpecials', |
|---|
| 93 | 'menubar_tags.tpl' => 'mbTags', |
|---|
| [10005] | 94 | 'month_calendar.tpl' => 'month_calendar', |
|---|
| [3182] | 95 | 'navigation_bar.tpl' => 'navbar', |
|---|
| [2712] | 96 | 'nbm.tpl' => 'nbm', |
|---|
| 97 | 'notification.tpl' => 'notification', |
|---|
| [10005] | 98 | 'password.tpl' => 'password', |
|---|
| [3182] | 99 | 'picture.tpl' => 'picture', |
|---|
| [2712] | 100 | 'picture_content.tpl' => 'default_content', |
|---|
| [3665] | 101 | 'picture_nav_buttons.tpl' => 'picture_nav_buttons', |
|---|
| [2712] | 102 | 'popuphelp.tpl' => 'popuphelp', |
|---|
| 103 | 'profile.tpl' => 'profile', |
|---|
| 104 | 'profile_content.tpl' => 'profile_content', |
|---|
| [3182] | 105 | 'redirect.tpl' => 'redirect', |
|---|
| [2712] | 106 | 'register.tpl' => 'register', |
|---|
| 107 | 'search.tpl' => 'search', |
|---|
| 108 | 'search_rules.tpl' => 'search_rules', |
|---|
| 109 | 'slideshow.tpl' => 'slideshow', |
|---|
| 110 | 'tags.tpl' => 'tags', |
|---|
| [3182] | 111 | 'thumbnails.tpl' => 'index_thumbnails', |
|---|
| [10005] | 112 | ); |
|---|
| [2923] | 113 | |
|---|
| 114 | $flip_templates = array_flip($eligible_templates); |
|---|
| 115 | |
|---|
| 116 | $available_templates = array_merge( |
|---|
| 117 | array('N/A' => '----------'), |
|---|
| [5126] | 118 | get_dirs(PHPWG_ROOT_PATH.'themes')); |
|---|
| [2923] | 119 | |
|---|
| [2434] | 120 | // +-----------------------------------------------------------------------+ |
|---|
| 121 | // | selected templates | |
|---|
| 122 | // +-----------------------------------------------------------------------+ |
|---|
| 123 | |
|---|
| [8126] | 124 | if (isset($_POST['submit'])) |
|---|
| [2434] | 125 | { |
|---|
| 126 | $replacements = array(); |
|---|
| 127 | $i = 0; |
|---|
| 128 | while (isset($_POST['reptpl'][$i])) |
|---|
| 129 | { |
|---|
| 130 | $newtpl = $_POST['reptpl'][$i]; |
|---|
| 131 | $original = $_POST['original'][$i]; |
|---|
| 132 | $handle = $eligible_templates[$original]; |
|---|
| 133 | $url_keyword = $_POST['url'][$i]; |
|---|
| 134 | if ($url_keyword == '----------') $url_keyword = 'N/A'; |
|---|
| [2923] | 135 | $bound_tpl = $_POST['bound'][$i]; |
|---|
| 136 | if ($bound_tpl == '----------') $bound_tpl = 'N/A'; |
|---|
| [2434] | 137 | if ($handle != 'N/A') |
|---|
| 138 | { |
|---|
| [2923] | 139 | $replacements[$newtpl] = array($handle, $url_keyword, $bound_tpl); |
|---|
| [2434] | 140 | } |
|---|
| 141 | $i++; |
|---|
| 142 | } |
|---|
| 143 | $conf['extents_for_templates'] = serialize($replacements); |
|---|
| 144 | $tpl_extension = $replacements; |
|---|
| 145 | /* ecrire la nouvelle conf */ |
|---|
| [6550] | 146 | $query = ' |
|---|
| 147 | UPDATE '.CONFIG_TABLE.' |
|---|
| 148 | SET value = \''. $conf['extents_for_templates'] .'\' |
|---|
| 149 | WHERE param = \'extents_for_templates\';'; |
|---|
| [2434] | 150 | if (pwg_query($query)) |
|---|
| 151 | { |
|---|
| 152 | array_push($page['infos'], |
|---|
| [5021] | 153 | l10n('Templates configuration has been recorded.')); |
|---|
| [2434] | 154 | } |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | // +-----------------------------------------------------------------------+ |
|---|
| 158 | // | template init | |
|---|
| 159 | // +-----------------------------------------------------------------------+ |
|---|
| 160 | |
|---|
| 161 | /* Clearing (remove old extents, add new ones) */ |
|---|
| 162 | foreach ($tpl_extension as $file => $conditions) |
|---|
| 163 | { |
|---|
| 164 | if ( !in_array($file,$new_extensions) ) unset($tpl_extension[$file]); |
|---|
| 165 | else $new_extensions = array_diff($new_extensions,array($file)); |
|---|
| 166 | } |
|---|
| 167 | foreach ($new_extensions as $file) |
|---|
| 168 | { |
|---|
| [2923] | 169 | $tpl_extension[$file] = array('N/A', 'N/A', 'N/A'); |
|---|
| [2434] | 170 | } |
|---|
| 171 | |
|---|
| 172 | $template->set_filenames(array('extend_for_templates' |
|---|
| [2530] | 173 | => 'extend_for_templates.tpl')); |
|---|
| [2434] | 174 | |
|---|
| 175 | $base_url = PHPWG_ROOT_PATH.'admin.php?page=extend_for_templates'; |
|---|
| 176 | |
|---|
| 177 | $template->assign( |
|---|
| 178 | array( |
|---|
| [5920] | 179 | 'U_HELP' => get_root_url().'admin/popuphelp.php?page=extend_for_templates', |
|---|
| [2434] | 180 | )); |
|---|
| 181 | ksort($tpl_extension); |
|---|
| 182 | foreach ($tpl_extension as $file => $conditions) |
|---|
| 183 | { |
|---|
| 184 | $handle = $conditions[0]; |
|---|
| 185 | $url_keyword = $conditions[1]; |
|---|
| [2923] | 186 | $bound_tpl = $conditions[2]; |
|---|
| [2434] | 187 | { |
|---|
| 188 | $template->append('extents', |
|---|
| 189 | array( |
|---|
| [2923] | 190 | 'replacer' => $file, |
|---|
| 191 | 'url_parameter' => $relevant_parameters, |
|---|
| 192 | 'original_tpl' => array_keys($eligible_templates), |
|---|
| 193 | 'bound_tpl' => $available_templates, |
|---|
| 194 | 'selected_tpl' => $flip_templates[$handle], |
|---|
| 195 | 'selected_url' => $url_keyword, |
|---|
| 196 | 'selected_bound' => $bound_tpl,) |
|---|
| [2434] | 197 | ); |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | // +-----------------------------------------------------------------------+ |
|---|
| 201 | // | html code display | |
|---|
| 202 | // +-----------------------------------------------------------------------+ |
|---|
| 203 | |
|---|
| 204 | $template->assign_var_from_handle('ADMIN_CONTENT', 'extend_for_templates'); |
|---|
| 205 | ?> |
|---|