source: branches/2.2/plugins/LocalFilesEditor/admin.php @ 10349

Last change on this file since 10349 was 10349, checked in by patdenice, 13 years ago

merge r10348 from trunk to branch 2.2
Clean code

  • Property svn:eol-style set to LF
File size: 5.7 KB
RevLine 
[2235]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[8728]5// | Copyright(C) 2008-2011 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');
[10349]26include_once(LOCALEDIT_PATH.'include/functions.inc.php');
[2235]27load_language('plugin.lang', LOCALEDIT_PATH);
[9359]28$my_base_url = get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__));
[2235]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'),
[9359]41               $my_base_url.'-localconf');
[5216]42$tabsheet->add('css',
43               l10n('locfiledit_onglet_css'),
[9359]44               $my_base_url.'-css');
[2235]45$tabsheet->add('tpl',
46               l10n('locfiledit_onglet_tpl'),
[9359]47               $my_base_url.'-tpl');
[2235]48$tabsheet->add('lang',
49               l10n('locfiledit_onglet_lang'),
[9359]50               $my_base_url.'-lang');
[2235]51$tabsheet->add('plug',
52               l10n('locfiledit_onglet_plug'),
[9359]53               $my_base_url.'-plug');
[2235]54$tabsheet->select($page['tab']);
55$tabsheet->assign();
56
[10349]57include_once(LOCALEDIT_PATH.'include/'.$page['tab'].'.inc.php');
[2235]58
59// +-----------------------------------------------------------------------+
60// |                           Load backup file
61// +-----------------------------------------------------------------------+
[8126]62if (isset($_POST['restore']))
[2235]63{
64  $edited_file = $_POST['edited_file'];
[2588]65  $content_file = file_get_contents(get_bak_file($edited_file));
[2235]66  array_push($page['infos'],
[2588]67    l10n('locfiledit_bak_loaded1'),
68    l10n('locfiledit_bak_loaded2'));
[2235]69}
70
71// +-----------------------------------------------------------------------+
72// |                            Save file
73// +-----------------------------------------------------------------------+
[8126]74if (isset($_POST['submit']))
[2235]75{
[5272]76  if (!is_webmaster())
[5256]77  {
78    array_push($page['errors'], l10n('locfiledit_webmaster_only'));
[2235]79  }
[5256]80  else
81  {
82    $edited_file = $_POST['edited_file'];
83    $content_file = stripslashes($_POST['text']);
84    if (get_extension($edited_file) == 'php')
[2235]85    {
[5256]86      $content_file = eval_syntax($content_file);
[2235]87    }
[5256]88    if ($content_file === false)
[2235]89    {
[5256]90      array_push($page['errors'], l10n('locfiledit_syntax_error'));
[2235]91    }
[5256]92    else
[2235]93    {
[5256]94      if ($page['tab'] == 'plug' and !is_dir(PHPWG_PLUGINS_PATH . 'PersonalPlugin'))
95      {
96        @mkdir(PHPWG_PLUGINS_PATH . "PersonalPlugin");
97      }
98      if (file_exists($edited_file))
99      {
100        @copy($edited_file, get_bak_file($edited_file));
101        array_push($page['infos'], sprintf(l10n('locfiledit_saved_bak'), substr(get_bak_file($edited_file), 2)));
102      }
103     
104      if ($file = @fopen($edited_file , "w"))
105      {
106        @fwrite($file , $content_file);
107        @fclose($file);
108        array_unshift($page['infos'], l10n('locfiledit_save_config'));
109        $template->delete_compiled_templates();
110      }
111      else
112      {
113        array_push($page['errors'], l10n('locfiledit_cant_save'));
114      }
[2235]115    }
116  }
117}
118
119// +-----------------------------------------------------------------------+
120// |                            template initialization
121// +-----------------------------------------------------------------------+
122$template->set_filenames(array(
[10349]123    'plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl'));
[2235]124
125if (!empty($edited_file))
126{
127  if (!empty($page['errors']))
128        {
129    $content_file = stripslashes($_POST['text']);
130  }
131  $template->assign('zone_edit',
[10349]132    array(
133      'EDITED_FILE' => $edited_file,
134      'CONTENT_FILE' => htmlspecialchars($content_file),
135      'FILE_NAME' => trim($edited_file, './\\')
136    )
137  );
[2588]138  if (file_exists(get_bak_file($edited_file)))
[2235]139  {
140    $template->assign('restore', true);
141  }
[2588]142  if (file_exists($edited_file))
143  {
144    $template->assign('restore_infos', true);
145  }
[2235]146}
147
[2588]148$template->assign(array(
[9359]149  'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=plugin-LocalFilesEditor-'.$page['tab'],
[2588]150  'LOCALEDIT_PATH' => LOCALEDIT_PATH,
[10310]151  'CODEMIRROR_MODE' => @$codemirror_mode
152  )
153);
[2291]154
[2235]155$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
156
157?>
Note: See TracBrowser for help on using the repository browser.