source: trunk/plugins/LocalFilesEditor/admin.php @ 3665

Last change on this file since 3665 was 3665, checked in by vdigital, 15 years ago

merge r3664 from branch 2.0 to trunk
New: picture_nav_buttons.tpl gets in template-extension support

  • Property svn:eol-style set to LF
File size: 14.7 KB
RevLine 
[2235]1<?php
2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[3049]5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[2235]23
24if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
25include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[2291]26include_once(LOCALEDIT_PATH.'functions.inc.php');
[2235]27load_language('plugin.lang', LOCALEDIT_PATH);
28$my_base_url = get_admin_plugin_menu_link(__FILE__);
29
30// +-----------------------------------------------------------------------+
31// |                            Tabssheet
32// +-----------------------------------------------------------------------+
33if (!isset($_GET['tab']))
34    $page['tab'] = 'localconf';
35else
36    $page['tab'] = $_GET['tab'];
37
38$tabsheet = new tabsheet();
39$tabsheet->add('localconf',
40               l10n('locfiledit_onglet_localconf'),
41               $my_base_url.'&amp;tab=localconf');
42$tabsheet->add('css',
43               l10n('locfiledit_onglet_css'),
44               $my_base_url.'&amp;tab=css');
45$tabsheet->add('tpl',
46               l10n('locfiledit_onglet_tpl'),
47               $my_base_url.'&amp;tab=tpl');
48$tabsheet->add('lang',
49               l10n('locfiledit_onglet_lang'),
50               $my_base_url.'&amp;tab=lang');
51$tabsheet->add('plug',
52               l10n('locfiledit_onglet_plug'),
53               $my_base_url.'&amp;tab=plug');
54$tabsheet->select($page['tab']);
55$tabsheet->assign();
56
57
58// +-----------------------------------------------------------------------+
59// |                            Variables init
60// +-----------------------------------------------------------------------+
[2588]61$edited_file = isset($_POST['edited_file']) ? $_POST['edited_file'] : '';
[2235]62$content_file = '';
[2588]63$new_file['localconf'] = "<?php\n\n/* ".l10n('locfiledit_newfile')." */\n\n\n\n\n?>";
64$new_file['css'] = "/* " . l10n('locfiledit_newfile') . " */\n\n";
65$new_file['tpl'] = "{* " . l10n('locfiledit_newfile') . " *}\n\n";
66$new_file['lang'] = $new_file['localconf'];
[2235]67$new_file['plug'] = "<?php\n/*
68Plugin Name: " . l10n('locfiledit_onglet_plug') . "
69Version: 1.0
70Description: " . l10n('locfiledit_onglet_plug') . "
[3133]71Plugin URI: http://piwigo.org
[2235]72Author:
73Author URI:
74*/\n\n\n\n\n?>";
[2588]75$newfile_page = isset($_GET['newfile']) ? true : false;
[2235]76
[2291]77// Editarea options
[2588]78$editarea_options = array(
79  'language' => substr($user['language'], 0, 2),
[2291]80  'start_highlight' => true,
[2588]81  'allow_toggle' => false,
[2291]82  'toolbar' => 'search,fullscreen, |,select_font, |, undo, redo, change_smooth_selection, highlight, reset_highlight, |, help');
83
[2235]84// Edit selected file for CSS, template and language
85if ((isset($_POST['edit'])) and !is_numeric($_POST['file_to_edit']))
86{
87  $edited_file = $_POST['file_to_edit'];
88  $content_file = file_exists($edited_file) ? 
89    file_get_contents($edited_file) : $new_file[$page['tab']];
90}
91
[2588]92// Edit new tpl file
93if (isset($_POST['create_tpl']))
94{
95  $filename = $_POST['tpl_name'];
[2906]96  if (empty($filename))
97  {
98    array_push($page['errors'], l10n('locfiledit_empty_filename'));
99  }
[2588]100  if (get_extension($filename) != 'tpl')
101  {
102    $filename .= '.tpl';
103  }
104  if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $filename))
105  {
106    array_push($page['errors'], l10n('locfiledit_filename_error'));
107  }
108  if (is_numeric($_POST['tpl_model']) and $_POST['tpl_model'] != '0')
109  {
110    array_push($page['errors'], l10n('locfiledit_model_error'));
111  }
112  if (file_exists($_POST['tpl_parent'] . '/' . $filename))
113  {
114    array_push($page['errors'], l10n('locfiledit_file_already_exists'));
[2906]115  }
116  if (!empty($page['errors']))
117  {
[2588]118    $newfile_page = true;
119  }
[2906]120  else
[2588]121  {
122    $edited_file = $_POST['tpl_parent'] . '/' . $filename;
123    $content_file = ($_POST['tpl_model'] == '0') ? $new_file['tpl'] : file_get_contents($_POST['tpl_model']);
124  }
125}
[2235]126
127// +-----------------------------------------------------------------------+
128// |                            Process tabsheet
129// +-----------------------------------------------------------------------+
130switch ($page['tab'])
131{
132  case 'localconf':
133    $edited_file = PHPWG_ROOT_PATH . "include/config_local.inc.php";
134    $content_file = file_exists($edited_file) ?
135      file_get_contents($edited_file) : $new_file['localconf'];
136       
137    $template->assign('show_default' , array(
138        array('SHOW_DEFAULT' => LOCALEDIT_PATH
139                . 'show_default.php?file=include/config_default.inc.php',
140              'FILE' => 'config_default.inc.php')));
[2588]141    $editarea_options['syntax'] = 'php';
[2235]142    break;
143
144  case 'css':
145    $template_dir = PHPWG_ROOT_PATH . 'template';
[2588]146    $selected = 0; 
147    $options[] = l10n('locfiledit_choose_file');
[2235]148    $options[] = '----------------------';
149    $value = PHPWG_ROOT_PATH . "template-common/local-layout.css";
150    $options[$value] = 'template-common / local-layout.css';
151    if ($edited_file == $value) $selected = $value;
152       
153    foreach (get_dirs($template_dir) as $pwg_template)
154    {
155      $options[] = '----------------------';
156      $value = $template_dir . '/' . $pwg_template . '/local-layout.css';
157      $options[$value] = $pwg_template . ' / local-layout.css';
158      if ($edited_file == $value) $selected = $value;
159      $options[] = '----------------------';
160      foreach (get_dirs($template_dir.'/'.$pwg_template.'/theme') as $theme)
161      {
162        $value = $template_dir.'/'.$pwg_template.'/theme/'.$theme.'/theme.css';
163        $options[$value] = $pwg_template . ' / ' . $theme . ' / theme.css';
164        if ($edited_file == $value) $selected = $value;
165      }
166    }
167    $template->assign('css_lang_tpl', array(
168        'OPTIONS' => $options,
169        'SELECTED' => $selected));
[2588]170    $editarea_options['syntax'] = 'css';
[2235]171    break;
172 
173  case 'tpl':
[2588]174    // New file form creation
175    if ($newfile_page and !is_adviser())
[2235]176    {
[2588]177      $filename = isset($_POST['tpl_name']) ? $_POST['tpl_name'] : '';
178      $selected['model'] = isset($_POST['tpl_model']) ? $_POST['tpl_model'] : '0';
179      $selected['parent'] = isset($_POST['tpl_parent']) ? $_POST['tpl_parent'] : PHPWG_ROOT_PATH . 'template-extension';
180
181      // Parent directories list
182      $options['parent'] = array(PHPWG_ROOT_PATH . 'template-extension' => 'template-extension');
183      $options['parent'] = array_merge($options['parent'], get_rec_dirs(PHPWG_ROOT_PATH . 'template-extension'));
184
185      // Model list
186      $eligible_templates = array(
187          'about.tpl',
[3182]188          'footer.tpl',
189          'header.tpl',
[2588]190          'identification.tpl',
[3182]191          'index.tpl',
[2588]192          'mainpage_categories.tpl',
[2712]193          'menubar.tpl',
194          'menubar_categories.tpl',
195          'menubar_identification.tpl',
196          'menubar_links.tpl',
197          'menubar_menu.tpl',
198          'menubar_specials.tpl',
199          'menubar_tags.tpl',
[3182]200          'navigation_bar.tpl',
[2588]201          'nbm.tpl',
202          'notification.tpl',
[3182]203          'picture.tpl',
[2588]204          'picture_content.tpl',
[3665]205          'picture_nav_buttons.tpl',
[2588]206          'popuphelp.tpl',
207          'profile.tpl',
208          'profile_content.tpl',
[3182]209          'redirect.tpl',
[2588]210          'register.tpl',
211          'search.tpl',
212          'search_rules.tpl',
213          'slideshow.tpl',
214          'tags.tpl',
[3182]215          'thumbnails.tpl',
[2588]216          'upload.tpl');
217
218      $options['model'][] = l10n('locfiledit_empty_page');
219      $options['model'][] = '----------------------';
220      foreach (get_extents() as $pwg_template)
[2235]221      {
[2588]222        $value = PHPWG_ROOT_PATH . 'template-extension/' . $pwg_template;
223        $options['model'][$value] =  'template-extension / ' . str_replace('/', ' / ', $pwg_template);
224      }
225      $template_dir = PHPWG_ROOT_PATH . 'template';
226      foreach (get_dirs($template_dir) as $pwg_template)
227      {
228        if (count($options['model']) > 2)
[2235]229        {
[2588]230          $options['model'][] = '----------------------';
231        }
232        $dir = $template_dir . '/' . $pwg_template . '/';
233        if (is_dir($dir) and $content = opendir($dir))
234        {
235          while ($node = readdir($content))
[2235]236          {
[2588]237            if (is_file($dir . $node) and in_array($node, $eligible_templates))
238            {
239              $value = $dir . $node;
240              $options['model'][$value] = $pwg_template . ' / ' . $node;
241            }
[2235]242          }
243        }
244      }
[2588]245      // Assign variables to template
246      $template->assign('create_tpl', array(
247        'NEW_FILE_NAME' => $filename,
248        'MODEL_OPTIONS' => $options['model'],
249        'MODEL_SELECTED' => $selected['model'],
250        'PARENT_OPTIONS' => $options['parent'],
251        'PARENT_SELECTED' => $selected['parent']));
252      break;
[2235]253    }
[2588]254    // List existing template extensions
255    $template_dir = PHPWG_ROOT_PATH . 'template-extension';
256    $selected = 0; 
257    $options[] = l10n('locfiledit_choose_file');
258    $options[] = '----------------------';
259    foreach (get_extents() as $pwg_template)
260    {
261      $value = './template-extension/' . $pwg_template;
262      $options[$value] =  str_replace('/', ' / ', $pwg_template);
263      if ($edited_file == $value) $selected = $value;
264    }
265    if ($selected == 0 and !empty($edited_file))
266    {
267      $options[$edited_file] =  str_replace(array('./template-extension/', '/'), array('', ' / '), $edited_file);
268      $selected = $edited_file;
269    }
[2235]270    $template->assign('css_lang_tpl', array(
[2588]271      'OPTIONS' => $options,
272      'SELECTED' => $selected,
273      'NEW_FILE_URL' => $my_base_url.'&amp;tab=tpl&amp;newfile',
274      'NEW_FILE_CLASS' => empty($edited_file) ? '' : 'top_right'));
275
276    $editarea_options['syntax'] = 'html';
[2235]277    break;
278
279  case 'lang':
[2588]280    $selected = 0; 
281    $options[] = l10n('locfiledit_choose_file');
[2235]282    $options[] = '----------------------';
283    foreach (get_languages() as $language_code => $language_name)
284    {
285      $value = PHPWG_ROOT_PATH.'language/'.$language_code.'/local.lang.php';
286      if ($edited_file == $value)
287      {
288        $selected = $value;
289        $template->assign('show_default', array(
290          array('SHOW_DEFAULT' => LOCALEDIT_PATH
291                  . 'show_default.php?file='
292                  . 'language/'.$language_code.'/common.lang.php',
293                'FILE' => 'common.lang.php'),
294          array('SHOW_DEFAULT' => LOCALEDIT_PATH
295                  . 'show_default.php?file='
296                  . 'language/'.$language_code.'/admin.lang.php',
297                'FILE' => 'admin.lang.php')));
298      }
299      $options[$value] = $language_name;
300    }
301    $template->assign('css_lang_tpl', array(
302        'OPTIONS' => $options,
303        'SELECTED' => $selected));
[2588]304    $editarea_options['syntax'] = 'php';
[2235]305    break;
306   
307  case 'plug':
308    $edited_file = PHPWG_PLUGINS_PATH . "PersonalPlugin/main.inc.php";
309    $content_file = file_exists($edited_file) ?
310      file_get_contents($edited_file) : $new_file['plug'];
[2588]311    $editarea_options['syntax'] = 'php';
[2235]312    break;
313}
314
315// +-----------------------------------------------------------------------+
316// |                           Load backup file
317// +-----------------------------------------------------------------------+
318if (isset($_POST['restore']) and !is_adviser())
319{
320  $edited_file = $_POST['edited_file'];
[2588]321  $content_file = file_get_contents(get_bak_file($edited_file));
[2235]322  array_push($page['infos'],
[2588]323    l10n('locfiledit_bak_loaded1'),
324    l10n('locfiledit_bak_loaded2'));
[2235]325}
326
327// +-----------------------------------------------------------------------+
328// |                            Save file
329// +-----------------------------------------------------------------------+
330if (isset($_POST['submit']) and !is_adviser())
331{
332  $edited_file = $_POST['edited_file'];
333  $content_file = stripslashes($_POST['text']);
334  if (get_extension($edited_file) == 'php')
335        {
336    $content_file = eval_syntax($content_file);
337  }
338  if ($content_file === false)
339        {
340    array_push($page['errors'], l10n('locfiledit_syntax_error'));
341  }
342        else
343        {
[2588]344    if ($page['tab'] == 'plug' and !is_dir(PHPWG_PLUGINS_PATH . 'PersonalPlugin'))
[2235]345    {
346      @mkdir(PHPWG_PLUGINS_PATH . "PersonalPlugin");
347    }
348    if (file_exists($edited_file))
349    {
[2588]350      @copy($edited_file, get_bak_file($edited_file));
351      array_push($page['infos'], sprintf(l10n('locfiledit_saved_bak'), substr(get_bak_file($edited_file), 2)));
[2235]352    }
353   
354    if ($file = @fopen($edited_file , "w"))
355                {
356      @fwrite($file , $content_file);
357      @fclose($file);
[2588]358      array_unshift($page['infos'], l10n('locfiledit_save_config'));
[2235]359    }
360                else
361    {
362      array_push($page['errors'], l10n('locfiledit_cant_save'));
363    }
364  }
365}
366
367// +-----------------------------------------------------------------------+
368// |                            template initialization
369// +-----------------------------------------------------------------------+
370$template->set_filenames(array(
371    'plugin_admin_content' => dirname(__FILE__) . '/admin.tpl'));
372
373if (!empty($edited_file))
374{
375  if (!empty($page['errors']))
376        {
377    $content_file = stripslashes($_POST['text']);
378  }
379  $template->assign('zone_edit',
380    array('EDITED_FILE' => $edited_file,
381          'CONTENT_FILE' => htmlspecialchars($content_file),
382          'FILE_NAME' => trim($edited_file, './\\')));
[2588]383  if (file_exists(get_bak_file($edited_file)))
[2235]384  {
385    $template->assign('restore', true);
386  }
[2588]387  if (file_exists($edited_file))
388  {
389    $template->assign('restore_infos', true);
390  }
391 
[2235]392}
393
[2588]394$template->assign(array(
395  'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section=LocalFilesEditor%2Fadmin.php&amp;tab=' . $page['tab'],
396  'LOCALEDIT_PATH' => LOCALEDIT_PATH,
397  'LOAD_EDITAREA' => isset($conf['LocalFilesEditor']) ? $conf['LocalFilesEditor'] : 'off',
398  'EDITAREA_OPTIONS' => $editarea_options));
[2291]399
[2235]400$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
401
402?>
Note: See TracBrowser for help on using the repository browser.