source: trunk/admin/extend_for_templates.php @ 2712

Last change on this file since 2712 was 2712, checked in by patdenice, 16 years ago
  • Add known_template function (maybe we can change function name).
  • Template extensions are working with menubar blocks templates.
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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    'identification.tpl'         => 'identification',
79    'mainpage_categories.tpl'    => 'index_category_thumbnails',
80    'thumbnails.tpl'             => 'index_thumbnails',
81    'redirect.tpl'               => 'redirect',
82    'menubar.tpl'                => 'menubar',
83    'menubar_categories.tpl'     => 'mbCategories',
84    'menubar_identification.tpl' => 'mbIdentification',
85    'menubar_links.tpl'          => 'mbLinks',
86    'menubar_menu.tpl'           => 'mbMenu',
87    'menubar_specials.tpl'       => 'mbSpecials',
88    'menubar_tags.tpl'           => 'mbTags',
89    'header.tpl'                 => 'header',
90    'footer.tpl'                 => 'tail',
91    'index.tpl'                  => 'index',
92    'nbm.tpl'                    => 'nbm',
93    'notification.tpl'           => 'notification',
94    'picture_content.tpl'        => 'default_content',
95    'picture.tpl'                => 'picture',
96    'popuphelp.tpl'              => 'popuphelp',
97    'profile.tpl'                => 'profile',
98    'profile_content.tpl'        => 'profile_content',
99    'register.tpl'               => 'register',
100    'search.tpl'                 => 'search',
101    'search_rules.tpl'           => 'search_rules',
102    'slideshow.tpl'              => 'slideshow',
103    'tags.tpl'                   => 'tags',
104    'upload.tpl'                 => 'upload',);
105  $flip_templates = array_flip($eligible_templates);
106// +-----------------------------------------------------------------------+
107// |                            selected templates                         |
108// +-----------------------------------------------------------------------+
109
110if (isset($_POST['submit']) and !is_adviser())
111{
112  $replacements = array();
113  $i = 0;
114  while (isset($_POST['reptpl'][$i]))
115  {
116    $newtpl = $_POST['reptpl'][$i];
117    $original = $_POST['original'][$i];
118    $handle = $eligible_templates[$original];
119    $url_keyword = $_POST['url'][$i];
120    if ($url_keyword == '----------') $url_keyword = 'N/A';
121    if ($handle != 'N/A')
122    {
123      $replacements[$newtpl] = array($handle, $url_keyword);
124    }
125    $i++;
126  }
127  $conf['extents_for_templates'] = serialize($replacements);
128  $tpl_extension = $replacements;
129  /* ecrire la nouvelle conf */
130  $query = "
131UPDATE ".CONFIG_TABLE."
132  SET value = '". $conf['extents_for_templates'] ."'
133WHERE param = 'extents_for_templates';";
134  if (pwg_query($query))
135  {
136    array_push($page['infos'], 
137      l10n('Templates recorded.'));
138  }
139}
140
141// +-----------------------------------------------------------------------+
142// |                             template init                             |
143// +-----------------------------------------------------------------------+
144
145/* Clearing (remove old extents, add new ones) */
146foreach ($tpl_extension as $file => $conditions)
147{
148  if ( !in_array($file,$new_extensions) ) unset($tpl_extension[$file]);
149  else $new_extensions = array_diff($new_extensions,array($file)); 
150}
151foreach ($new_extensions as $file)
152{
153  $tpl_extension[$file] = array('N/A', 'N/A');
154}
155
156$template->set_filenames(array('extend_for_templates'
157     => 'extend_for_templates.tpl'));
158
159$base_url = PHPWG_ROOT_PATH.'admin.php?page=extend_for_templates';
160
161$template->assign(
162  array(
163    'U_HELP' => get_root_url().'popuphelp.php?page=extend_for_templates',
164    ));
165ksort($tpl_extension);
166foreach ($tpl_extension as $file => $conditions)   
167{
168  $handle = $conditions[0];
169  $url_keyword = $conditions[1];
170  { 
171  $template->append('extents',
172    array(
173      'replacer'      => $file,
174      'url_parameter' => $relevant_parameters,
175      'original_tpl'  => array_keys($eligible_templates),
176      'selected_tpl'  => $flip_templates[$handle],
177      'selected_url'  => $url_keyword,)
178      );
179  }
180}
181// +-----------------------------------------------------------------------+
182// |                           html code display                           |
183// +-----------------------------------------------------------------------+
184
185$template->assign_var_from_handle('ADMIN_CONTENT', 'extend_for_templates');
186?>
Note: See TracBrowser for help on using the repository browser.