source: trunk/admin/extend_for_templates.php @ 2522

Last change on this file since 2522 was 2453, checked in by vdigital, 16 years ago

Swift Theme Creator (minor changes): non functional version yet (4).
Bug 836: "Extend for templates" minor change.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 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// |                              functions                                |
40// +-----------------------------------------------------------------------+
41
42/**
43 * returns a list of templates currently available in template-extension
44 *
45 * Each .tpl file is extracted from template-extension.
46 *
47 * @return array
48 */
49function get_extents($start='')
50{
51  if ($start == '') { $start = './template-extension'; }
52  $dir = opendir($start);
53  $extents = array();
54
55  while (($file = readdir($dir)) !== false)
56  {
57    if ( $file == '.' or $file == '..' or $file == '.svn') continue;
58    $path = $start . '/' . $file;
59    if (is_dir($path))
60    {
61      $extents = array_merge($extents, get_extents($path));
62    }
63    elseif ( !is_link($path) and file_exists($path) 
64            and strripos($path,'.tpl') > 0 )
65    {
66      $extents[] = substr($path, 21);
67    }
68  }
69  return $extents;
70}
71// +-----------------------------------------------------------------------+
72//                            initialization                              |
73// +-----------------------------------------------------------------------+
74
75if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
76include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
77check_status(ACCESS_ADMINISTRATOR);
78
79$tpl_extension = isset($conf['extents_for_templates']) ?
80      unserialize($conf['extents_for_templates']) : array();
81$new_extensions = get_extents(); 
82
83/* Selective URLs keyword */
84$relevant_parameters = array(
85    '----------',
86    'category',
87    'favorites',
88    'most_visited',
89    'best_rated',
90    'recent_pics',
91    'recent_cats',
92    'created-monthly-calendar',
93    'posted-monthly-calendar',
94    'search',
95    'flat',
96    'list',); /* <=> Random */
97  $query = '
98SELECT permalink
99  FROM '.CATEGORIES_TABLE.'
100  WHERE permalink IS NOT NULL
101';
102
103/* Add active permalinks */ 
104$permalinks = array_from_query($query, 'permalink');
105$relevant_parameters = array_merge($relevant_parameters, $permalinks);
106
107/* Link all supported templates to their respective handle */
108$eligible_templates = array(
109    '----------'              => 'N/A',
110    'about.tpl'               => 'about',
111    'identification.tpl'      => 'identification',
112    'mainpage_categories.tpl' => 'index_category_thumbnails',
113    'thumbnails.tpl'          => 'index_thumbnails',
114    'redirect.tpl'            => 'redirect',
115    'menubar.tpl'             => 'menubar',
116    'header.tpl'              => 'header',
117    'footer.tpl'              => 'tail',
118    'index.tpl'               => 'index',
119    'nbm.tpl'                 => 'nbm',
120    'notification.tpl'        => 'notification',
121    'picture_content.tpl'     => 'default_content',
122    'slideshow.tpl'           => 'picture', /* => slideshow is missing */ 
123    'picture.tpl'             => 'picture',
124    'popuphelp.tpl'           => 'popuphelp',
125    'profile.tpl'             => 'profile',
126    'profile_content.tpl'     => 'profile_content',
127    'register.tpl'            => 'register',
128    'search.tpl'              => 'search',
129    'search_rules.tpl'        => 'search_rules',
130    'tags.tpl'                => 'tags',
131    'upload.tpl'              => 'upload',);
132  $flip_templates = array_flip($eligible_templates);
133// +-----------------------------------------------------------------------+
134// |                            selected templates                         |
135// +-----------------------------------------------------------------------+
136
137if (isset($_POST['submit']) and !is_adviser())
138{
139  $replacements = array();
140  $i = 0;
141  while (isset($_POST['reptpl'][$i]))
142  {
143    $newtpl = $_POST['reptpl'][$i];
144    $original = $_POST['original'][$i];
145    $handle = $eligible_templates[$original];
146    $url_keyword = $_POST['url'][$i];
147    if ($url_keyword == '----------') $url_keyword = 'N/A';
148    if ($handle != 'N/A')
149    {
150      $replacements[$newtpl] = array($handle, $url_keyword);
151    }
152    $i++;
153  }
154  $conf['extents_for_templates'] = serialize($replacements);
155  $tpl_extension = $replacements;
156  /* ecrire la nouvelle conf */
157  $query = "
158UPDATE ".CONFIG_TABLE."
159  SET value = '". $conf['extents_for_templates'] ."'
160WHERE param = 'extents_for_templates';";
161  if (pwg_query($query))
162  {
163    array_push($page['infos'], 
164      l10n('Templates recorded.'));
165  }
166}
167
168// +-----------------------------------------------------------------------+
169// |                             template init                             |
170// +-----------------------------------------------------------------------+
171
172/* Clearing (remove old extents, add new ones) */
173foreach ($tpl_extension as $file => $conditions)
174{
175  if ( !in_array($file,$new_extensions) ) unset($tpl_extension[$file]);
176  else $new_extensions = array_diff($new_extensions,array($file)); 
177}
178foreach ($new_extensions as $file)
179{
180  $tpl_extension[$file] = array('N/A', 'N/A');
181}
182
183$template->set_filenames(array('extend_for_templates'
184     => 'admin/extend_for_templates.tpl'));
185
186$base_url = PHPWG_ROOT_PATH.'admin.php?page=extend_for_templates';
187
188$template->assign(
189  array(
190    'U_HELP' => get_root_url().'popuphelp.php?page=extend_for_templates',
191    ));
192ksort($tpl_extension);
193foreach ($tpl_extension as $file => $conditions)   
194{
195  $handle = $conditions[0];
196  $url_keyword = $conditions[1];
197  { 
198  $template->append('extents',
199    array(
200      'replacer'      => $file,
201      'url_parameter' => $relevant_parameters,
202      'original_tpl'  => array_keys($eligible_templates),
203      'selected_tpl'  => $flip_templates[$handle],
204      'selected_url'  => $url_keyword,)
205      );
206  }
207}
208// +-----------------------------------------------------------------------+
209// |                           html code display                           |
210// +-----------------------------------------------------------------------+
211
212$template->assign_var_from_handle('ADMIN_CONTENT', 'extend_for_templates');
213?>
Note: See TracBrowser for help on using the repository browser.