source: trunk/admin/extend_for_templates.php @ 3182

Last change on this file since 3182 was 3182, checked in by patdenice, 15 years ago

Re-order templates extension alphabetically.
Allow to use template extension for navigation bar.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
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',
63    'list',); /* <=> Random */
64  $query = '
65SELECT permalink
66  FROM '.CATEGORIES_TABLE.'
67  WHERE permalink IS NOT NULL
68';
69
70/* Add active permalinks */ 
71$permalinks = array_from_query($query, 'permalink');
72$relevant_parameters = array_merge($relevant_parameters, $permalinks);
73
74/* Link all supported templates to their respective handle */
75$eligible_templates = array(
76    '----------'                 => 'N/A',
77    'about.tpl'                  => 'about',
78    'footer.tpl'                 => 'tail',
79    'header.tpl'                 => 'header',
80    'identification.tpl'         => 'identification',
81    'index.tpl'                  => 'index',
82    'mainpage_categories.tpl'    => 'index_category_thumbnails',
83    'menubar.tpl'                => 'menubar',
84    'menubar_categories.tpl'     => 'mbCategories',
85    'menubar_identification.tpl' => 'mbIdentification',
86    'menubar_links.tpl'          => 'mbLinks',
87    'menubar_menu.tpl'           => 'mbMenu',
88    'menubar_specials.tpl'       => 'mbSpecials',
89    'menubar_tags.tpl'           => 'mbTags',
90    'navigation_bar.tpl'         => 'navbar',
91    'nbm.tpl'                    => 'nbm',
92    'notification.tpl'           => 'notification',
93    'picture.tpl'                => 'picture',
94    'picture_content.tpl'        => 'default_content',
95    'popuphelp.tpl'              => 'popuphelp',
96    'profile.tpl'                => 'profile',
97    'profile_content.tpl'        => 'profile_content',
98    'redirect.tpl'               => 'redirect',
99    'register.tpl'               => 'register',
100    'search.tpl'                 => 'search',
101    'search_rules.tpl'           => 'search_rules',
102    'slideshow.tpl'              => 'slideshow',
103    'tags.tpl'                   => 'tags',
104    'thumbnails.tpl'             => 'index_thumbnails',
105    'upload.tpl'                 => 'upload',);
106
107$flip_templates = array_flip($eligible_templates);
108
109$available_templates = array_merge(
110  array('N/A' => '----------'),
111  get_dirs(PHPWG_ROOT_PATH.'template'));
112
113// +-----------------------------------------------------------------------+
114// |                            selected templates                         |
115// +-----------------------------------------------------------------------+
116
117if (isset($_POST['submit']) and !is_adviser())
118{
119  $replacements = array();
120  $i = 0;
121  while (isset($_POST['reptpl'][$i]))
122  {
123    $newtpl = $_POST['reptpl'][$i];
124    $original = $_POST['original'][$i];
125    $handle = $eligible_templates[$original];
126    $url_keyword = $_POST['url'][$i];
127    if ($url_keyword == '----------') $url_keyword = 'N/A';
128    $bound_tpl = $_POST['bound'][$i];
129    if ($bound_tpl == '----------') $bound_tpl = 'N/A';
130    if ($handle != 'N/A')
131    {
132      $replacements[$newtpl] = array($handle, $url_keyword, $bound_tpl);
133    }
134    $i++;
135  }
136  $conf['extents_for_templates'] = serialize($replacements);
137  $tpl_extension = $replacements;
138  /* ecrire la nouvelle conf */
139  $query = "
140UPDATE ".CONFIG_TABLE."
141  SET value = '". $conf['extents_for_templates'] ."'
142WHERE param = 'extents_for_templates';";
143  if (pwg_query($query))
144  {
145    array_push($page['infos'], 
146      l10n('Templates recorded.'));
147  }
148}
149
150// +-----------------------------------------------------------------------+
151// |                             template init                             |
152// +-----------------------------------------------------------------------+
153
154/* Clearing (remove old extents, add new ones) */
155foreach ($tpl_extension as $file => $conditions)
156{
157  if ( !in_array($file,$new_extensions) ) unset($tpl_extension[$file]);
158  else $new_extensions = array_diff($new_extensions,array($file)); 
159}
160foreach ($new_extensions as $file)
161{
162  $tpl_extension[$file] = array('N/A', 'N/A', 'N/A');
163}
164
165$template->set_filenames(array('extend_for_templates'
166     => 'extend_for_templates.tpl'));
167
168$base_url = PHPWG_ROOT_PATH.'admin.php?page=extend_for_templates';
169
170$template->assign(
171  array(
172    'U_HELP' => get_root_url().'popuphelp.php?page=extend_for_templates',
173    ));
174ksort($tpl_extension);
175foreach ($tpl_extension as $file => $conditions)   
176{
177  $handle = $conditions[0];
178  $url_keyword = $conditions[1];
179  $bound_tpl = $conditions[2];
180  { 
181  $template->append('extents',
182    array(
183      'replacer'       => $file,
184      'url_parameter'  => $relevant_parameters,
185      'original_tpl'   => array_keys($eligible_templates),
186      'bound_tpl'          => $available_templates,
187      'selected_tpl'   => $flip_templates[$handle],
188      'selected_url'   => $url_keyword,
189      'selected_bound' => $bound_tpl,)
190      );
191  }
192}
193// +-----------------------------------------------------------------------+
194// |                           html code display                           |
195// +-----------------------------------------------------------------------+
196
197$template->assign_var_from_handle('ADMIN_CONTENT', 'extend_for_templates');
198?>
Note: See TracBrowser for help on using the repository browser.