XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 8445 2011-12-08 12:32:52Z trabis $
3 // ------------------------------------------------------------------------ //
4 // XOOPS - PHP Content Management System //
5 // Copyright (c) 2000 XOOPS.org //
6 // <http://www.xoops.org/> //
7 // ------------------------------------------------------------------------ //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation; either version 2 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // You may not change or alter any portion of this comment or credits //
14 // of supporting developers from this source code or any supporting //
15 // source code which is considered copyrighted (c) material of the //
16 // original comment or credit authors. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details. //
22 // //
23 // You should have received a copy of the GNU General Public License //
24 // along with this program; if not, write to the Free Software //
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26 // ------------------------------------------------------------------------ //
27 // Author: Kazumi Ono (AKA onokazu) //
28 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29 // Project: The XOOPS Project //
30 // ------------------------------------------------------------------------- //
31 
32 // Check users rights
33 if ( !is_object($GLOBALS['xoopsUser']) || !is_object($GLOBALS['xoopsModule']) || !$GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()) ) exit( _NOPERM );
34 
35 // Get Action type
36 $op = system_CleanVars ( $_REQUEST, 'op', 'default', 'string' );
37 
38 // Define main template
39 $xoopsOption['template_main'] = 'system_templates.html';
40 // Call Header
42 // Define scripts
43 $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
44 $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
45 $xoTheme->addScript('modules/system/js/jquery.easing.js');
46 $xoTheme->addScript('modules/system/js/jqueryFileTree.js');
47 $xoTheme->addScript('modules/system/js/admin.js');
48 $xoTheme->addScript('modules/system/js/templates.js');
49 $xoTheme->addScript('modules/system/js/code_mirror/codemirror.js');
50 // Define Stylesheet
51 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
52 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/code_mirror/docs.css');
53 // Define Breadcrumb and tips
54 $xoBreadCrumb->addLink( _AM_SYSTEM_TEMPLATES_NAV_MAIN, system_adminVersion('tplsets', 'adminpath') );
55 
56 switch ($op) {
57  //index
58  default:
59  // Assign Breadcrumb menu
60  $xoBreadCrumb->addHelp( system_adminVersion('tplsets', 'help') );
62  $xoBreadCrumb->render();
63 
64  $GLOBALS['xoopsTpl']->assign('index', true);
65 
66  $form = new XoopsThemeForm(_AM_SYSTEM_TEMPLATES_GENERATE, "form", 'admin.php?fct=tplsets', "post", true);
67 
68  $ele = new XoopsFormSelect(_AM_SYSTEM_TEMPLATES_SET, 'tplset', $GLOBALS['xoopsConfig']['template_set']);
69  $tplset_handler =& xoops_gethandler('tplset');
70  $tplsetlist = $tplset_handler->getList();
71  asort($tplsetlist);
72  foreach ($tplsetlist as $key => $name) {
73  $ele->addOption($key, $name);
74  }
75  $form->addElement($ele);
76  $form->addElement(new XoopsFormSelectTheme(_AM_SYSTEM_TEMPLATES_SELECT_THEME, 'select_theme', 1, 5), true);
77  $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_TEMPLATES_FORCE_GENERATED, 'force_generated', 0, _YES, _NO), true);
78 
79  $modules = new XoopsFormSelect(_AM_SYSTEM_TEMPLATES_SELECT_MODULES, 'select_modules');
80  $module_handler =& xoops_gethandler('module');
81  $criteria = new CriteriaCompo(new Criteria('isactive', 1));
82  $moduleslist = $module_handler->getList($criteria, true);
83  $modules->addOption(0, _AM_SYSTEM_TEMPLATES_ALL_MODULES);
84  $modules->addOptionArray($moduleslist);
85  $form->addElement($modules, true);
86 
87  $form->addElement(new XoopsFormHidden("active_templates", "0"));
88  $form->addElement(new XoopsFormHidden("active_modules", "0"));
89  $form->addElement(new XoopsFormHidden("op", "tpls_generate_surcharge"));
90  $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
91  $xoopsTpl->assign('form', $form->render());
92  break;
93 
94  //generate surcharge
95  case 'tpls_generate_surcharge':
96  if (!$GLOBALS['xoopsSecurity']->check()) {
97  redirect_header('admin.php?fct=tplsets', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
98  }
99  // Assign Breadcrumb menu
100  $xoBreadCrumb->addHelp( system_adminVersion('tplsets', 'help') . '#override' );
102  $xoBreadCrumb->render();
103 
104  if($_REQUEST['select_modules'] == '0' || $_REQUEST['active_modules'] == '1')
105  {
106  //Generate modules
107  if(isset($_REQUEST['select_theme']) && isset($_REQUEST['force_generated']))
108  {
109  //on verifie si le dossier module existe
110  $theme_surcharge = XOOPS_THEME_PATH.'/'.$_REQUEST['select_theme'].'/modules';
111  $indexFile = XOOPS_ROOT_PATH."/modules/system/include/index.html";
112  $verif_write = false;
113  $text = '';
114 
115  if (!is_dir($theme_surcharge))
116  {
117  //Creation du dossier modules
118 
119  if(!is_dir($theme_surcharge))
120  mkdir($theme_surcharge, 0777);
121  chmod($theme_surcharge, 0777);
122  copy($indexFile, $theme_surcharge."/index.html");
123  }
124 
125  $tplset = system_CleanVars($POST, 'tplset', 'default', 'string' );
126 
127  //on cr�e uniquement les templates qui n'existent pas
128  $module_handler = xoops_gethandler('module');
129  $tplset_handler = xoops_gethandler('tplset');
130  $tpltpl_handler = xoops_gethandler('tplfile');
131 
132  $criteria = new CriteriaCompo();
133  $criteria->add(new Criteria('tplset_name', $tplset));
134  $tplsets_arr = $tplset_handler->getObjects();
135  $tcount = $tplset_handler->getCount();
136 
137 
138  $tpltpl_handler = xoops_gethandler('tplfile');
139  $installed_mods = $tpltpl_handler->getModuleTplCount($tplset);
140 
141  //all templates or only one template
142  if($_REQUEST['active_templates'] == 0)
143  {
144  foreach (array_keys($tplsets_arr) as $i)
145  {
146  $tplsetname = $tplsets_arr[$i]->getVar('tplset_name');
147  $tplstats = $tpltpl_handler->getModuleTplCount($tplsetname);
148 
149  if (count($tplstats) > 0)
150  {
151  foreach ($tplstats as $moddir => $filecount)
152  {
153  $module =& $module_handler->getByDirname($moddir);
154  if (is_object($module))
155  {
156  // create module folder
157  if(!is_dir($theme_surcharge.'/'.$module->getVar('dirname')))
158  {
159  mkdir($theme_surcharge.'/'.$module->getVar('dirname'), 0777);
160  chmod($theme_surcharge.'/'.$module->getVar('dirname'), 0777);
161  copy($indexFile, $theme_surcharge.'/'.$module->getVar('dirname').'/index.html');
162  }
163 
164  // create block folder
165  if (!is_dir($theme_surcharge.'/'.$module->getVar('dirname').'/blocks'))
166  {
167  if(!is_dir($theme_surcharge.'/'.$module->getVar('dirname').'/blocks'))
168  mkdir($theme_surcharge.'/'.$module->getVar('dirname').'/blocks', 0777);
169  chmod($theme_surcharge.'/'.$module->getVar('dirname').'/blocks', 0777);
170  copy($indexFile, $theme_surcharge.'/'.$module->getVar('dirname').'/blocks'.'/index.html');
171  }
172 
173  $class = "odd";
174  $text .= '<table cellspacing="1" class="outer"><tr><th colspan="3" align="center">'._AM_SYSTEM_TEMPLATES_MODULES.ucfirst($module->getVar('dirname')).'</th></tr><tr><th align="center">'._AM_SYSTEM_TEMPLATES_TYPES.'</th><th align="center">'._AM_SYSTEM_TEMPLATES_FILES.'</th><th>'._AM_SYSTEM_TEMPLATES_STATUS.'</th></tr>';
175 
176 
177  // create template
178  $templates =& $tpltpl_handler->find($tplsetname, 'module', null, $moddir);
179  for ($j=0; $j<count($templates); $j++)
180  {
181  $filename = $templates[$j]->getVar('tpl_file');
182  if ($tplsetname == $tplset)
183  {
184  $physical_file = XOOPS_THEME_PATH.'/'.$_REQUEST['select_theme'].'/modules/'.$moddir.'/'.$filename;
185 
186  $tplfile =& $tpltpl_handler->get($templates[$j]->getVar('tpl_id'), true);
187 
188  if (is_object($tplfile))
189  {
190  if(!file_exists($physical_file) || $_REQUEST['force_generated'] == 1) {
191  $open = fopen("".$physical_file."","w+");
192  if(fwrite($open, "".$tplfile->getVar('tpl_source', 'n')))
193  {
194  $text .= '<tr class="'.$class.'"><td align="center">'._AM_SYSTEM_TEMPLATES_TEMPLATES.'</td><td>'.$physical_file.'</td><td align="center">';
195  if(file_exists($physical_file)) {
196  $text .= '<img width="16" src="'.system_AdminIcons('success.png').'" /></td></tr>';
197  }else{
198  $text .= '<img width="16" src="'.system_AdminIcons('cancel.png').'" /></td></tr>';
199  }
200  $verif_write = true;
201  }
202  fclose($open);
203  $class = ($class == "even") ? "odd" : "even";
204  }
205  }
206  }
207  }
208 
209  // create block template
210  $btemplates =& $tpltpl_handler->find($tplsetname, 'block', null, $moddir);
211  for ($k = 0; $k < count($btemplates); $k++)
212  {
213  $filename = $btemplates[$k]->getVar('tpl_file');
214  if ($tplsetname == $tplset)
215  {
216  $physical_file = XOOPS_THEME_PATH.'/'.$_REQUEST['select_theme'].'/modules/'.$moddir.'/blocks/'.$filename;
217  $btplfile =& $tpltpl_handler->get($btemplates[$k]->getVar('tpl_id'), true);
218 
219  if (is_object($btplfile))
220  {
221  if(!file_exists($physical_file) || $_REQUEST['force_generated'] == 1)
222  {
223  $open = fopen($physical_file,"w+");
224  if(fwrite($open, $btplfile->getVar('tpl_source', 'n')))
225  {
226  $text .= '<tr class="'.$class.'"><td align="center">'._AM_SYSTEM_TEMPLATES_BLOCKS.'</td><td>'.$physical_file.'</td><td align="center">';
227  if(file_exists($physical_file)) {
228  $text .= '<img width="16" src="'.system_AdminIcons('success.png').'" /></td></tr>';
229  }else{
230  $text .= '<img width="16" src="'.system_AdminIcons('cancel.png').'" /></td></tr>';
231  }
232  $verif_write = true;
233  }
234  fclose($open);
235  $class = ($class == "even") ? "odd" : "even";
236  }
237  }
238  }
239  }
240  $text .= '</table>';
241  }
242  }
243  unset($module);
244  }
245  }
246  } else {
247  foreach (array_keys($tplsets_arr) as $i)
248  {
249  $tplsetname = $tplsets_arr[$i]->getVar('tplset_name');
250  $tplstats = $tpltpl_handler->getModuleTplCount($tplsetname);
251 
252  if (count($tplstats) > 0)
253  {
254  $moddir = $_REQUEST['select_modules'];
255  $module =& $module_handler->getByDirname($moddir);
256  if (is_object($module))
257  {
258  // create module folder
259  if(!is_dir($theme_surcharge.'/'.$module->getVar('dirname')))
260  {
261  mkdir($theme_surcharge.'/'.$module->getVar('dirname'), 0777);
262  chmod($theme_surcharge.'/'.$module->getVar('dirname'), 0777);
263  copy($indexFile, $theme_surcharge.'/'.$module->getVar('dirname').'/index.html');
264  }
265 
266  // create block folder
267  if (!is_dir($theme_surcharge.'/'.$module->getVar('dirname').'/blocks'))
268  {
269  if(!is_dir($theme_surcharge.'/'.$module->getVar('dirname').'/blocks'))
270  mkdir($theme_surcharge.'/'.$module->getVar('dirname').'/blocks', 0777);
271  chmod($theme_surcharge.'/'.$module->getVar('dirname').'/blocks', 0777);
272  copy($indexFile, $theme_surcharge.'/'.$module->getVar('dirname').'/blocks'.'/index.html');
273  }
274 
275  $class = "odd";
276  $text .= '<table cellspacing="1" class="outer"><tr><th colspan="3" align="center">'._AM_SYSTEM_TEMPLATES_MODULES.ucfirst($module->getVar('dirname')).'</th></tr><tr><th align="center">'._AM_SYSTEM_TEMPLATES_TYPES.'</th><th align="center">'._AM_SYSTEM_TEMPLATES_FILES.'</th><th>'._AM_SYSTEM_TEMPLATES_STATUS.'</th></tr>';
277  $select_templates_modules = $_REQUEST['select_templates_modules'];
278  for($l=0; $l<count($_REQUEST['select_templates_modules']); $l++)
279  {
280  // create template
281  $templates =& $tpltpl_handler->find($tplsetname, 'module', null, $moddir);
282  for ($j=0; $j<count($templates); $j++)
283  {
284  $filename = $templates[$j]->getVar('tpl_file');
285  if ($tplsetname == $tplset)
286  {
287  $physical_file = XOOPS_THEME_PATH.'/'.$_REQUEST['select_theme'].'/modules/'.$moddir.'/'.$filename;
288 
289  $tplfile =& $tpltpl_handler->get($templates[$j]->getVar('tpl_id'), true);
290 
291  if (is_object($tplfile))
292  {
293  if(!file_exists($physical_file) || $_REQUEST['force_generated'] == 1) {
294  if ($select_templates_modules[$l] == $filename)
295  {
296  $open = fopen("".$physical_file."","w+");
297  if(fwrite($open, "".$tplfile->getVar('tpl_source', 'n')))
298  {
299  $text .= '<tr class="'.$class.'"><td align="center">'._AM_SYSTEM_TEMPLATES_TEMPLATES.'</td><td>'.$physical_file.'</td><td align="center">';
300  if(file_exists($physical_file)) {
301  $text .= '<img width="16" src="'.system_AdminIcons('success.png').'" /></td></tr>';
302  }else{
303  $text .= '<img width="16" src="'.system_AdminIcons('cancel.png').'" /></td></tr>';
304  }
305  $verif_write = true;
306  }
307  fclose($open);
308  }
309  $class = ($class == "even") ? "odd" : "even";
310  }
311  }
312  }
313  }
314 
315  // create block template
316  $btemplates =& $tpltpl_handler->find($tplsetname, 'block', null, $moddir);
317  for ($k = 0; $k < count($btemplates); $k++)
318  {
319  $filename = $btemplates[$k]->getVar('tpl_file');
320  if ($tplsetname == $tplset)
321  {
322  $physical_file = XOOPS_THEME_PATH.'/'.$_REQUEST['select_theme'].'/modules/'.$moddir.'/blocks/'.$filename;
323  $btplfile =& $tpltpl_handler->get($btemplates[$k]->getVar('tpl_id'), true);
324 
325  if (is_object($btplfile))
326  {
327  if(!file_exists($physical_file) || $_REQUEST['force_generated'] == 1)
328  {
329  if ($select_templates_modules[$l] == $filename)
330  {
331  $open = fopen("".$physical_file."","w+");
332  if(fwrite($open, "".$btplfile->getVar('tpl_source', 'n').""))
333  {
334  $text .= '<tr class="'.$class.'"><td align="center">'._AM_SYSTEM_TEMPLATES_BLOCKS.'</td><td>'.$physical_file.'</td><td align="center">';
335  if(file_exists($physical_file)) {
336  $text .= '<img width="16" src="'.system_AdminIcons('success.png').'" /></td></tr>';
337  }else{
338  $text .= '<img width="16" src="'.system_AdminIcons('cancel.png').'" /></td></tr>';
339  }
340  $verif_write = true;
341  }
342  fclose($open);
343  }
344  $class = ($class == "even") ? "odd" : "even";
345  }
346  }
347  }
348  }
349  }
350  $text .= '</table>';
351  }
352  unset($module);
353  }
354  }
355  }
356  $xoopsTpl->assign('infos', $text);
357  $xoopsTpl->assign('verif', $verif_write);
358  } else {
359  redirect_header("admin.php?fct=tplsets", 2, _AM_SYSTEM_TEMPLATES_SAVE);
360  }
361  } else {
362  // Generate one module
363  $GLOBALS['xoopsTpl']->assign('index', true);
364 
365  $tplset = system_CleanVars($POST, 'tplset', 'default', 'string' );
366 
367  $form = new XoopsThemeForm(_AM_SYSTEM_TEMPLATES_SELECT_TEMPLATES, "form", 'admin.php?fct=tplsets', "post", true);
368 
369  $tpltpl_handler =& xoops_gethandler('tplfile');
370  $templates_arr =& $tpltpl_handler->find($tplset, '', null, $_REQUEST['select_modules']);
371 
372  $modules = new XoopsFormSelect(_AM_SYSTEM_TEMPLATES_SELECT_TEMPLATES, 'select_templates_modules', null, 10, true);
373  foreach (array_keys($templates_arr) as $i)
374  {
375  $modules->addOption($templates_arr[$i]->getVar('tpl_file'));
376  }
377  $form->addElement($modules);
378 
379  $form->addElement(new XoopsFormHidden("active_templates", "1"));
380  $form->addElement(new XoopsFormHidden("force_generated", $_REQUEST['force_generated']));
381  $form->addElement(new XoopsFormHidden("select_modules", $_REQUEST['select_modules']));
382  $form->addElement(new XoopsFormHidden("active_modules", "1"));
383  $form->addElement(new XoopsFormHidden("select_theme", $_REQUEST['select_theme']));
384  $form->addElement(new XoopsFormHidden("op", "tpls_generate_surcharge"));
385  $form->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
386  $xoopsTpl->assign('form', $form->render());
387  }
388  break;
389 
390  // save
391  case 'tpls_save':
392  $path_file = $_REQUEST['path_file'];
393  if(isset($path_file))
394  {
395  // copy file
396  $copy_file = $path_file;
397  copy($copy_file, $path_file.'.back');
398  // Save modif
399  if(isset($_REQUEST['templates']))
400  {
401  $open = fopen("".$path_file."","w+");
402  if(!fwrite($open, utf8_encode(stripslashes($_REQUEST['templates']))))
403  {
404  redirect_header("admin.php?fct=tplsets", 2, _AM_SYSTEM_TEMPLATES_ERROR);
405  }
406  fclose($open);
407  }
408  }
409  redirect_header("admin.php?fct=tplsets", 2, _AM_SYSTEM_TEMPLATES_SAVE);
410  break;
411 }
412 // Call Footer
414 
415 ?>