XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
jquery.php
Go to the documentation of this file.
1 <?php
20 include dirname( dirname( dirname( __FILE__ ) ) ) . '/header.php';
21 
22 if (!defined('XOOPS_ROOT_PATH')) { die('Error'); }
23 
24 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
25 
26 error_reporting(0);
27 $GLOBALS['xoopsLogger']->activated = false;
28 
29 if ( file_exists("./../../language/".$xoopsConfig['language']."/admin/tplsets.php") ) {
30  include_once("./../../language/".$xoopsConfig['language']."/admin/tplsets.php");
31 } else {
32  include_once("./../../language/english/admin/tplsets.php");
33 }
34 
35 if (isset($_REQUEST["op"])) {
36  $op = $_REQUEST["op"];
37 } else {
38  @$op = "default";
39 }
40 
41 $GLOBALS['xoopsLogger']->usePopup = true;
42 
43 switch ($op) {
44  // Display tree folder
45  case "tpls_display_folder":
46  $_REQUEST['dir'] = urldecode($_REQUEST['dir']);
47  $root = XOOPS_THEME_PATH;
48  if( file_exists($root . $_REQUEST['dir']) ) {
49  $files = scandir($root . $_REQUEST['dir']);
50  natcasesort($files);
51  if( count($files) > 2 ) { /* The 2 accounts for . and .. */
52  echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
53  // All dirs
54  foreach( $files as $file ) {
55 
56  if( file_exists($root . $_REQUEST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_REQUEST['dir'] . $file) ) {
57  //retirer .svn
58  $file_no_valid = array('.svn', 'icons', 'img', 'images', 'language');
59 
60  if(!in_array($file, $file_no_valid))
61  {
62  echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_REQUEST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
63  }
64  }
65  }
66  // All files
67  foreach( $files as $file )
68  {
69  if( file_exists($root . $_REQUEST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_REQUEST['dir'] . $file) && $file != 'index.html' ) {
70  $ext = preg_replace('/^.*\./', '', $file);
71 
72  $extensions = array('.html', '.htm', '.css');
73  $extension_verif = strrchr($file, '.');
74 
75  if(in_array($extension_verif, $extensions)) {
76  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>";
77  } else {
78  //echo "<li class=\"file ext_$ext\">" . htmlentities($file) . "</li>";
79  }
80 
81  }
82  }
83  echo "</ul>";
84  }
85  }
86  break;
87  // Edit File
88  case 'tpls_edit_file':
89  $path_file = realpath(XOOPS_ROOT_PATH.'/themes'.trim($_REQUEST['path_file']));
90  $path_file = str_replace('\\','/',$path_file);
91 
92  //Button restore
93  if(file_exists($path_file.'.back')){
94  $restore = '<button class="ui-corner-all tooltip" type="button" onclick="tpls_restore(\''.$path_file.'\')" value="'._AM_SYSTEM_TEMPLATES_RESTORE.'" title="'._AM_SYSTEM_TEMPLATES_RESTORE.'">
95  <img src="'.system_AdminIcons('revert.png').'" alt="'._AM_SYSTEM_TEMPLATES_RESTORE.'" />
96  </button>';
97  }else{
98  $restore = '';
99  }
100  xoops_load('XoopsFile');
101  XoopsFile::load('file');
102 
103  $file = XoopsFile::getHandler('file', $path_file);
104  $content = $file->read();
105  if(empty($content)) {
106  echo _AM_SYSTEM_TEMPLATES_EMPTY_FILE;
107  }
108  $ext = preg_replace('/^.*\./', '', $_REQUEST['path_file']);
109 
110  echo '<form name="back" action="admin.php?fct=tplsets&op=tpls_save" method="POST">
111  <table border="0">
112  <tr>
113  <td>
114  <div class="xo-btn-actions">
115  <div class="xo-buttons">
116  <button class="ui-corner-all tooltip" type="submit" value="'._AM_SYSTEM_TEMPLATES_SAVE.'" title="'._AM_SYSTEM_TEMPLATES_SAVE.'">
117  <img src="'.system_AdminIcons('save.png').'" alt="'._AM_SYSTEM_TEMPLATES_SAVE.'" />
118  </button>
119  '.$restore.'
120  <button class="ui-corner-all tooltip" type="button" onclick="$(\'#display_contenu\').hide();$(\'#display_form\').fadeIn(\'fast\');" title="'._AM_SYSTEM_TEMPLATES_CANCEL.'">
121  <img src="'.system_AdminIcons('cancel.png').'" alt="'._AM_SYSTEM_TEMPLATES_CANCEL.'" />
122  </button>
123  <div class="clear"></div>
124  </div>
125  </div>
126  </td>
127  </tr>
128  <tr>
129  <td><textarea id="code_mirror" name="templates" rows=24 cols=110>'.$content.'</textarea></td>
130  </tr>
131  </table>';
132  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>';
133  break;
134 
135  // Restore backup file
136  case 'tpls_restore':
137  $extensions = array('.html', '.htm', '.css');
138 
139  //check if the file is inside themes directory
140  $valid_dir = stristr(realpath($_REQUEST['path_file']), realpath(XOOPS_ROOT_PATH . '/themes'));
141 
142  $old_file = $_REQUEST['path_file'].'.back';
143  $new_file = $_REQUEST['path_file'];
144 
145  $extension_verif = strrchr($new_file, '.');
146  if($valid_dir && in_array($extension_verif, $extensions) && file_exists($old_file) && file_exists($new_file) )
147  {
148  if(unlink($new_file))
149  {
150  if(rename($old_file, $new_file))
151  {
153  exit();
154  }
155  }
156  }
158  break;
159 
160 }
161 
162 ?>