XOOPS  2.6.0
jquery.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 include dirname(dirname(__DIR__)) . '/header.php';
23 
25 $xoops->disableErrorReporting();
26 
27 if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->user->isAdmin($xoops->module->mid())) {
29 }
30 
31 include_once $xoops->path('modules/system/functions.php');
32 $xoops->loadLocale('system');
33 
34 if (isset($_REQUEST["op"])) {
35  $op = $_REQUEST["op"];
36 } else {
37  @$op = "default";
38 }
39 
40 switch ($op) {
41  // Display tree folder
42  case "tpls_display_folder":
43  $_REQUEST['dir'] = urldecode($_REQUEST['dir']);
44  $root = \XoopsBaseConfig::get('themes-path');
45  if (XoopsLoad::fileExists($root . $_REQUEST['dir'])) {
46  $files = scandir($root . $_REQUEST['dir']);
47  natcasesort($files);
48  if (count($files) > 2) { /* The 2 accounts for . and .. */
49  echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
50  // All dirs
51  foreach ($files as $file) {
52 
53  if (XoopsLoad::fileExists($root . $_REQUEST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_REQUEST['dir'] . $file)) {
54  //retirer .svn
55  $file_no_valid = array('.svn', 'icons', 'img', 'images', 'language', 'locale');
56 
57  if (!in_array($file, $file_no_valid)) {
58  echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_REQUEST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
59  }
60  }
61  }
62  // All files
63  foreach ($files as $file) {
64  if (XoopsLoad::fileExists($root . $_REQUEST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_REQUEST['dir'] . $file) && $file != 'index.html') {
65  $ext = preg_replace('/^.*\./', '', $file);
66 
67  $extensions = array('.tpl', '.html', '.htm', '.css');
68  $extension_verif = strrchr($file, '.');
69 
70  if (in_array($extension_verif, $extensions)) {
71  echo "<li class=\"file ext_$ext\"><a href=\"#\" onclick=\"tpls_edit_file('" . htmlentities($_REQUEST['dir'] . $file) . "', '" . htmlentities($_REQUEST['dir']) . "', '" . htmlentities($file) . "', '" . $ext . "');\" rel=\"tpls_edit_file('" . htmlentities($_REQUEST['dir'] . $file) . "', '" . htmlentities($_REQUEST['dir']) . "', '" . htmlentities($file) . "', '" . $ext . "');\">" . htmlentities($file) . "</a></li>";
72  } else {
73  //echo "<li class=\"file ext_$ext\">" . htmlentities($file) . "</li>";
74  }
75  }
76  }
77  echo "</ul>";
78  }
79  }
80  break;
81  // Edit File
82  case 'tpls_edit_file':
83  $path_file = realpath(\XoopsBaseConfig::get('root-path') . '/themes' . trim($_REQUEST['path_file']));
84  $path_file = str_replace('\\', '/', $path_file);
85 
86  //Button restore
87  if (XoopsLoad::fileExists($path_file . '.back')) {
88  $restore = '<button class="ui-corner-all tooltip" type="button" onclick="tpls_restore(\'' . $path_file . '\')" value="' . XoopsLocale::A_RESTORE . '" title="' . XoopsLocale::A_RESTORE . '">
89  <img src="' . system_AdminIcons('revert.png') . '" alt="' . XoopsLocale::A_RESTORE . '" />
90  </button>';
91  } else {
92  $restore = '';
93  }
94 
95  $file = XoopsFile::getHandler('file', $path_file);
96  $content = $file->read();
97  if (empty($content)) {
98  echo SystemLocale::EMPTY_FILE;
99  }
100  $ext = preg_replace('/^.*\./', '', $_REQUEST['path_file']);
101 
102  echo '<form name="back" action="admin.php?fct=tplsets&op=tpls_save" method="POST">
103  <table border="0">
104  <tr>
105  <td>
106  <div class="xo-btn-actions">
107  <div class="xo-buttons">
108  <button class="ui-corner-all tooltip" type="submit" value="' . XoopsLocale::A_SAVE . '" title="' . XoopsLocale::A_SAVE . '">
109  <img src="' . system_AdminIcons('save.png') . '" alt="' . XoopsLocale::A_SAVE . '" />
110  </button>
111  ' . $restore . '
112  <button class="ui-corner-all tooltip" type="button" onclick="$(\'#display_contenu\').hide();$(\'#display_form\').fadeIn(\'fast\');" title="' . XoopsLocale::A_CANCEL . '">
113  <img src="' . system_AdminIcons('cancel.png') . '" alt="' . XoopsLocale::A_CANCEL . '" />
114  </button>
115  <div class="clear"></div>
116  </div>
117  </div>
118  </td>
119  </tr>
120  <tr>
121  <td><textarea id="code_mirror" name="templates" rows=24 cols=110>' . $content . '</textarea></td>
122  </tr>
123  </table>';
124  echo '<input type="hidden" name="path_file" value="' . $path_file . '"><input type="hidden" name="file" value="' . trim($_REQUEST['file']) . '"><input type="hidden" name="ext" value="' . $ext . '"></form>';
125  break;
126 
127  // Restore backup file
128  case 'tpls_restore':
129  $extensions = array('.tpl', '.html', '.htm', '.css');
130 
131  //check if the file is inside themes directory
132  $valid_dir = stristr(realpath($_REQUEST['path_file']), realpath(\XoopsBaseConfig::get('root-path') . '/themes'));
133 
134  $old_file = $_REQUEST['path_file'] . '.back';
135  $new_file = $_REQUEST['path_file'];
136 
137  $extension_verif = strrchr($new_file, '.');
138  if ($valid_dir && in_array($extension_verif, $extensions) && XoopsLoad::fileExists($old_file) && XoopsLoad::fileExists($new_file)) {
139  if (unlink($new_file)) {
140  if (rename($old_file, $new_file)) {
141  echo $xoops->alert('info', SystemLocale::S_RESTORED);
142  exit();
143  }
144  }
145  }
146  echo $xoops->alert('error', SystemLocale::E_NOT_RESTORED);
147  break;
148 }
system_AdminIcons($img)
Definition: functions.php:117
const S_RESTORED
Definition: en_US.php:397
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
const E_NOT_RESTORED
Definition: en_US.php:294
$files
Definition: index.php:35
exit
Definition: browse.php:104
$root
static fileExists($file)
Definition: xoopsload.php:506
static get($name)
const A_CANCEL
Definition: en_US.php:82
$ext
Definition: browse.php:87
$xoops
Definition: jquery.php:24
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$op