source: trunk/admin/extend_for_templates.php @ 9917

Last change on this file since 9917 was 8728, checked in by plg, 14 years ago

Happy new year 2011

Change "Piwigo - a PHP based picture gallery" into "Piwigo - a PHP based photo gallery"

  • Property svn:eol-style set to LF
File size: 7.8 KB
RevLine 
[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
42if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
43include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
44check_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 = '
67SELECT 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',
[3182]80    'footer.tpl'                 => 'tail',
81    'header.tpl'                 => 'header',
[2712]82    'identification.tpl'         => 'identification',
[3182]83    'index.tpl'                  => 'index',
[2712]84    'mainpage_categories.tpl'    => 'index_category_thumbnails',
85    'menubar.tpl'                => 'menubar',
86    'menubar_categories.tpl'     => 'mbCategories',
87    'menubar_identification.tpl' => 'mbIdentification',
88    'menubar_links.tpl'          => 'mbLinks',
89    'menubar_menu.tpl'           => 'mbMenu',
90    'menubar_specials.tpl'       => 'mbSpecials',
91    'menubar_tags.tpl'           => 'mbTags',
[3182]92    'navigation_bar.tpl'         => 'navbar',
[2712]93    'nbm.tpl'                    => 'nbm',
94    'notification.tpl'           => 'notification',
[3182]95    'picture.tpl'                => 'picture',
[2712]96    'picture_content.tpl'        => 'default_content',
[3665]97    'picture_nav_buttons.tpl'    => 'picture_nav_buttons',
[2712]98    'popuphelp.tpl'              => 'popuphelp',
99    'profile.tpl'                => 'profile',
100    'profile_content.tpl'        => 'profile_content',
[3182]101    'redirect.tpl'               => 'redirect',
[2712]102    'register.tpl'               => 'register',
103    'search.tpl'                 => 'search',
104    'search_rules.tpl'           => 'search_rules',
105    'slideshow.tpl'              => 'slideshow',
106    'tags.tpl'                   => 'tags',
[3182]107    'thumbnails.tpl'             => 'index_thumbnails',
[2712]108    'upload.tpl'                 => 'upload',);
[2923]109
110$flip_templates = array_flip($eligible_templates);
111
112$available_templates = array_merge(
113  array('N/A' => '----------'),
[5126]114  get_dirs(PHPWG_ROOT_PATH.'themes'));
[2923]115
[2434]116// +-----------------------------------------------------------------------+
117// |                            selected templates                         |
118// +-----------------------------------------------------------------------+
119
[8126]120if (isset($_POST['submit']))
[2434]121{
122  $replacements = array();
123  $i = 0;
124  while (isset($_POST['reptpl'][$i]))
125  {
126    $newtpl = $_POST['reptpl'][$i];
127    $original = $_POST['original'][$i];
128    $handle = $eligible_templates[$original];
129    $url_keyword = $_POST['url'][$i];
130    if ($url_keyword == '----------') $url_keyword = 'N/A';
[2923]131    $bound_tpl = $_POST['bound'][$i];
132    if ($bound_tpl == '----------') $bound_tpl = 'N/A';
[2434]133    if ($handle != 'N/A')
134    {
[2923]135      $replacements[$newtpl] = array($handle, $url_keyword, $bound_tpl);
[2434]136    }
137    $i++;
138  }
139  $conf['extents_for_templates'] = serialize($replacements);
140  $tpl_extension = $replacements;
141  /* ecrire la nouvelle conf */
[6550]142  $query = '
143UPDATE '.CONFIG_TABLE.'
144  SET value = \''. $conf['extents_for_templates'] .'\'
145WHERE param = \'extents_for_templates\';';
[2434]146  if (pwg_query($query))
147  {
148    array_push($page['infos'], 
[5021]149      l10n('Templates configuration has been recorded.'));
[2434]150  }
151}
152
153// +-----------------------------------------------------------------------+
154// |                             template init                             |
155// +-----------------------------------------------------------------------+
156
157/* Clearing (remove old extents, add new ones) */
158foreach ($tpl_extension as $file => $conditions)
159{
160  if ( !in_array($file,$new_extensions) ) unset($tpl_extension[$file]);
161  else $new_extensions = array_diff($new_extensions,array($file)); 
162}
163foreach ($new_extensions as $file)
164{
[2923]165  $tpl_extension[$file] = array('N/A', 'N/A', 'N/A');
[2434]166}
167
168$template->set_filenames(array('extend_for_templates'
[2530]169     => 'extend_for_templates.tpl'));
[2434]170
171$base_url = PHPWG_ROOT_PATH.'admin.php?page=extend_for_templates';
172
173$template->assign(
174  array(
[5920]175    'U_HELP' => get_root_url().'admin/popuphelp.php?page=extend_for_templates',
[2434]176    ));
177ksort($tpl_extension);
178foreach ($tpl_extension as $file => $conditions)   
179{
180  $handle = $conditions[0];
181  $url_keyword = $conditions[1];
[2923]182  $bound_tpl = $conditions[2];
[2434]183  { 
184  $template->append('extents',
185    array(
[2923]186      'replacer'       => $file,
187      'url_parameter'  => $relevant_parameters,
188      'original_tpl'   => array_keys($eligible_templates),
189      'bound_tpl'          => $available_templates,
190      'selected_tpl'   => $flip_templates[$handle],
191      'selected_url'   => $url_keyword,
192      'selected_bound' => $bound_tpl,)
[2434]193      );
194  }
195}
196// +-----------------------------------------------------------------------+
197// |                           html code display                           |
198// +-----------------------------------------------------------------------+
199
200$template->assign_var_from_handle('ADMIN_CONTENT', 'extend_for_templates');
201?>
Note: See TracBrowser for help on using the repository browser.