XOOPS  2.6.0
main.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 
14 
25 // Get main instance
29 
30 // Check users rights
31 if (!$xoops->isUser() || !$xoops->isModule() || !$xoops->user->isAdmin($xoops->module->mid())) {
33 }
34 
35 // Get Action type
36 $op = $system->cleanVars($_REQUEST, 'op', 'default', 'string');
37 
38 // Call Header
39 $xoops->header('admin:system/system_templates.tpl');
40 // Define scripts
41 $xoops->theme()->addBaseScriptAssets(array('@jquery', '@jqueryui'));
42 $xoops->theme()->addScript('media/jquery/plugins/jquery.easing.js');
43 $xoops->theme()->addScript('media/jquery/plugins/jqueryFileTree.js');
44 $xoops->theme()->addScript('modules/system/js/admin.js');
45 $xoops->theme()->addScript('modules/system/js/templates.js');
46 $xoops->theme()->addScript('modules/system/js/code_mirror/codemirror.js');
47 // Define Stylesheet
48 $xoops->theme()->addStylesheet('modules/system/css/admin.css');
49 $xoops->theme()->addStylesheet('modules/system/css/code_mirror/docs.css');
50 // Define Breadcrumb and tips
52 
53 switch ($op) {
54  //index
55  default:
56 
57  // Define Breadcrumb and tips
58  $admin_page = new \Xoops\Module\Admin();
59  $admin_page->addBreadcrumbLink(SystemLocale::CONTROL_PANEL, \XoopsBaseConfig::get('url') . '/admin.php', true);
60  $admin_page->addBreadcrumbLink(SystemLocale::TEMPLATES_MANAGER, $system->adminVersion('tplsets', 'adminpath'));
61  $admin_page->renderBreadcrumb();
63  $admin_page->renderTips();
64 
65  $xoops->tpl()->assign('index', true);
66 
67  $form = new Xoops\Form\ThemeForm(SystemLocale::TEMPLATE_OVERLOADED, "form", 'admin.php?fct=tplsets', "post", true);
68 
69  $ele = new Xoops\Form\Select(SystemLocale::CHOOSE_TEMPLATE, 'tplset', $xoops->getConfig('tplset'));
70  $tplset_handler = $xoops->getHandlerTplset();
71  $tplsetlist = $tplset_handler->getNameList();
72  asort($tplsetlist);
73  foreach ($tplsetlist as $key => $name) {
74  $ele->addOption($key, $name);
75  }
76  $form->addElement($ele);
77  $form->addElement(new Xoops\Form\SelectTheme(XoopsLocale::SELECT_THEME, 'select_theme', 1, 5), true);
78  $form->addElement(new Xoops\Form\RadioYesNo(SystemLocale::FORCED_FILE_GENERATION, 'force_generated', 0), true);
79 
80  $modules = new Xoops\Form\Select(XoopsLocale::SELECT_MODULE, 'select_modules');
81 
82  $module_handler = $xoops->getHandlerModule();
83  $criteria = new CriteriaCompo(new Criteria('isactive', 1));
84  $moduleslist = $module_handler->getNameList($criteria, true);
85  $modules->addOption(0, XoopsLocale::ALL_MODULES);
86  $modules->addOptionArray($moduleslist);
87  $form->addElement($modules, true);
88 
89  $form->addElement(new Xoops\Form\Hidden("active_templates", "0"));
90  $form->addElement(new Xoops\Form\Hidden("active_modules", "0"));
91  $form->addElement(new Xoops\Form\Hidden("op", "tpls_overload"));
92  $form->addElement(new Xoops\Form\Button("", "submit", XoopsLocale::A_SUBMIT, "submit"));
93  $form->display();
94  break;
95 
96  //overload template
97  case 'tpls_overload':
98  if (!$xoops->security()->check()) {
99  $xoops->redirect('admin.php?fct=tplsets', 3, implode('<br />', $xoops->security()->getErrors()));
100  }
101  // Assign Breadcrumb menu
102  $system_breadcrumb->addHelp(system_adminVersion('tplsets', 'help') . '#override');
104  $system_breadcrumb->render();
105 
106  if ($_REQUEST['select_modules'] == '0' || $_REQUEST['active_modules'] == '1') {
107  //Generate modules
108  if (isset($_REQUEST['select_theme']) && isset($_REQUEST['force_generated'])) {
109  //on verifie si le dossier module existe
110  $template_overload = \XoopsBaseConfig::get('themes-path') . '/' . $_REQUEST['select_theme'] . '/modules';
111  $indexFile = \XoopsBaseConfig::get('root-path') . "/modules/system/include/index.html";
112  $verif_write = false;
113  $text = '';
114 
115  if (!is_dir($template_overload)) {
116  //Creation du dossier modules
117 
118  if (!is_dir($template_overload)) {
119  mkdir($template_overload, 0777);
120  }
121  chmod($template_overload, 0777);
122  copy($indexFile, $template_overload . "/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->getHandlerModule();
129  $tplset_handler = $xoops->getHandlerTplset();
130  $tpltpl_handler = $xoops->getHandlerTplfile();
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  $installed_mods = $tpltpl_handler->getModuleTplCount($tplset);
138 
139  //all templates or only one template
140  if ($_REQUEST['active_templates'] == 0) {
141  foreach (array_keys($tplsets_arr) as $i) {
142  $tplsetname = $tplsets_arr[$i]->getVar('tplset_name');
143  $tplstats = $tpltpl_handler->getModuleTplCount($tplsetname);
144 
145  if (count($tplstats) > 0) {
146  foreach ($tplstats as $moddir => $filecount) {
147  $module = $xoops->getModuleByDirname($moddir);
148  if (is_object($module)) {
149  // create module folder
150  if (!is_dir($template_overload . '/' . $module->getVar('dirname'))) {
151  mkdir($template_overload . '/' . $module->getVar('dirname'), 0777);
152  chmod($template_overload . '/' . $module->getVar('dirname'), 0777);
153  copy($indexFile, $template_overload . '/' . $module->getVar('dirname') . '/index.html');
154  }
155 
156  // create block folder
157  if (!is_dir($template_overload . '/' . $module->getVar('dirname') . '/blocks')) {
158  if (!is_dir($template_overload . '/' . $module->getVar('dirname') . '/blocks')) {
159  mkdir($template_overload . '/' . $module->getVar('dirname') . '/blocks', 0777);
160  }
161  chmod($template_overload . '/' . $module->getVar('dirname') . '/blocks', 0777);
162  copy($indexFile, $template_overload . '/' . $module->getVar('dirname') . '/blocks' . '/index.html');
163  }
164 
165  $class = "odd";
166  $text .= '<table cellspacing="1" class="outer"><tr><th colspan="3" align="center">' . XoopsLocale::C_MODULES . ucfirst($module->getVar('dirname')) . '</th></tr><tr><th align="center">' . XoopsLocale::TYPES . '</th><th align="center">' . XoopsLocale::FILES . '</th><th>' . XoopsLocale::STATUS . '</th></tr>';
167 
168  // create template
169  $templates = $tpltpl_handler->find($tplsetname, 'module', null, $moddir);
170  for ($j = 0; $j < count($templates); ++$j) {
171  $filename = $templates[$j]->getVar('tpl_file');
172  if ($tplsetname == $tplset) {
173  $physical_file = \XoopsBaseConfig::get('themes-path') . '/' . $_REQUEST['select_theme'] . '/modules/' . $moddir . '/' . $filename;
174 
175  $tplfile = $tpltpl_handler->get($templates[$j]->getVar('tpl_id'), true);
176 
177  if (is_object($tplfile)) {
178  if (!XoopsLoad::fileExists($physical_file) || $_REQUEST['force_generated'] == 1) {
179  $open = fopen("" . $physical_file . "", "w+");
180  if (fwrite($open, "" . html_entity_decode($tplfile->getVar('tpl_source', 'E'), ENT_QUOTES))) {
181  $text .= '<tr class="' . $class . '"><td align="center">' . XoopsLocale::TEMPLATES . '</td><td>' . $physical_file . '</td><td align="center">';
182  if (XoopsLoad::fileExists($physical_file)) {
183  $text .= '<img width="16" src="' . system_AdminIcons('success.png') . '" /></td></tr>';
184  } else {
185  $text .= '<img width="16" src="' . system_AdminIcons('cancel.png') . '" /></td></tr>';
186  }
187  $verif_write = true;
188  }
189  fclose($open);
190  $class = ($class == "even") ? "odd" : "even";
191  }
192  }
193  }
194  }
195 
196  // create block template
197  $btemplates = $tpltpl_handler->find($tplsetname, 'block', null, $moddir);
198  for ($k = 0; $k < count($btemplates); ++$k) {
199  $filename = $btemplates[$k]->getVar('tpl_file');
200  if ($tplsetname == $tplset) {
201  $physical_file = \XoopsBaseConfig::get('themes-path') . '/' . $_REQUEST['select_theme'] . '/modules/' . $moddir . '/blocks/' . $filename;
202  $btplfile = $tpltpl_handler->get($btemplates[$k]->getVar('tpl_id'), true);
203 
204  if (is_object($btplfile)) {
205  if (!XoopsLoad::fileExists($physical_file) || $_REQUEST['force_generated'] == 1) {
206  $open = fopen("" . $physical_file . "", "w+");
207  if (fwrite($open, "" . utf8_encode(html_entity_decode($btplfile->getVar('tpl_source', 'E'))) . "")) {
208  $text .= '<tr class="' . $class . '"><td align="center">' . XoopsLocale::BLOCKS . '</td><td>' . $physical_file . '</td><td align="center">';
209  if (XoopsLoad::fileExists($physical_file)) {
210  $text .= '<img width="16" src="' . system_AdminIcons('success.png') . '" /></td></tr>';
211  } else {
212  $text .= '<img width="16" src="' . system_AdminIcons('cancel.png') . '" /></td></tr>';
213  }
214  $verif_write = true;
215  }
216  fclose($open);
217  $class = ($class == "even") ? "odd" : "even";
218  }
219  }
220  }
221  }
222  $text .= '</table>';
223  }
224  }
225  unset($module);
226  }
227  }
228  } else {
229  foreach (array_keys($tplsets_arr) as $i) {
230  $tplsetname = $tplsets_arr[$i]->getVar('tplset_name');
231  $tplstats = $tpltpl_handler->getModuleTplCount($tplsetname);
232 
233  if (count($tplstats) > 0) {
234  $moddir = $_REQUEST['select_modules'];
235  $module = $xoops->getModuleByDirname($moddir);
236  if (is_object($module)) {
237  // create module folder
238  if (!is_dir($template_overload . '/' . $module->getVar('dirname'))) {
239  mkdir($template_overload . '/' . $module->getVar('dirname'), 0777);
240  chmod($template_overload . '/' . $module->getVar('dirname'), 0777);
241  copy($indexFile, $template_overload . '/' . $module->getVar('dirname') . '/index.html');
242  }
243 
244  // create block folder
245  if (!is_dir($template_overload . '/' . $module->getVar('dirname') . '/blocks')) {
246  if (!is_dir($template_overload . '/' . $module->getVar('dirname') . '/blocks')) {
247  mkdir($template_overload . '/' . $module->getVar('dirname') . '/blocks', 0777);
248  }
249  chmod($template_overload . '/' . $module->getVar('dirname') . '/blocks', 0777);
250  copy($indexFile, $template_overload . '/' . $module->getVar('dirname') . '/blocks' . '/index.html');
251  }
252 
253  $class = "odd";
254  $text .= '<table cellspacing="1" class="outer"><tr><th colspan="3" align="center">' . XoopsLocale::C_MODULES . ucfirst($module->getVar('dirname')) . '</th></tr><tr><th align="center">' . XoopsLocale::TYPES . '</th><th align="center">' . XoopsLocale::FILES . '</th><th>' . XoopsLocale::STATUS . '</th></tr>';
255  $select_templates_modules = $_REQUEST['select_templates_modules'];
256  for ($l = 0; $l < count($_REQUEST['select_templates_modules']); ++$l) {
257  // create template
258  $templates = $tpltpl_handler->find($tplsetname, 'module', null, $moddir);
259  for ($j = 0; $j < count($templates); ++$j) {
260  $filename = $templates[$j]->getVar('tpl_file');
261  if ($tplsetname == $tplset) {
262  $physical_file = \XoopsBaseConfig::get('themes-path') . '/' . $_REQUEST['select_theme'] . '/modules/' . $moddir . '/' . $filename;
263 
264  $tplfile = $tpltpl_handler->get($templates[$j]->getVar('tpl_id'), true);
265 
266  if (is_object($tplfile)) {
267  if (!XoopsLoad::fileExists($physical_file) || $_REQUEST['force_generated'] == 1) {
268  if ($select_templates_modules[$l] == $filename) {
269  $open = fopen("" . $physical_file . "", "w+");
270  if (fwrite($open, "" . html_entity_decode($tplfile->getVar('tpl_source', 'E'), ENT_QUOTES))) {
271  $text .= '<tr class="' . $class . '"><td align="center">' . XoopsLocale::TEMPLATES . '</td><td>' . $physical_file . '</td><td align="center">';
272  if (XoopsLoad::fileExists($physical_file)) {
273  $text .= '<img width="16" src="' . system_AdminIcons('success.png') . '" /></td></tr>';
274  } else {
275  $text .= '<img width="16" src="' . system_AdminIcons('cancel.png') . '" /></td></tr>';
276  }
277  $verif_write = true;
278  }
279  fclose($open);
280  }
281  $class = ($class == "even") ? "odd" : "even";
282  }
283  }
284  }
285  }
286 
287  // create block template
288  $btemplates = $tpltpl_handler->find($tplsetname, 'block', null, $moddir);
289  for ($k = 0; $k < count($btemplates); ++$k) {
290  $filename = $btemplates[$k]->getVar('tpl_file');
291  if ($tplsetname == $tplset) {
292  $physical_file = \XoopsBaseConfig::get('themes-path') . '/' . $_REQUEST['select_theme'] . '/modules/' . $moddir . '/blocks/' . $filename;
293  $btplfile = $tpltpl_handler->get($btemplates[$k]->getVar('tpl_id'), true);
294 
295  if (is_object($btplfile)) {
296  if (!XoopsLoad::fileExists($physical_file) || $_REQUEST['force_generated'] == 1) {
297  if ($select_templates_modules[$l] == $filename) {
298  $open = fopen("" . $physical_file . "", "w+");
299  if (fwrite($open, "" . utf8_encode(html_entity_decode($btplfile->getVar('tpl_source', 'E'))) . "")) {
300  $text .= '<tr class="' . $class . '"><td align="center">' . XoopsLocale::BLOCKS . '</td><td>' . $physical_file . '</td><td align="center">';
301  if (XoopsLoad::fileExists($physical_file)) {
302  $text .= '<img width="16" src="' . system_AdminIcons('success.png') . '" /></td></tr>';
303  } else {
304  $text .= '<img width="16" src="' . system_AdminIcons('cancel.png') . '" /></td></tr>';
305  }
306  $verif_write = true;
307  }
308  fclose($open);
309  }
310  $class = ($class == "even") ? "odd" : "even";
311  }
312  }
313  }
314  }
315  }
316  $text .= '</table>';
317  }
318  unset($module);
319  }
320  }
321  }
322  $xoops->tpl()->assign('infos', $text);
323  $xoops->tpl()->assign('verif', $verif_write);
324  } else {
325  $xoops->redirect("admin.php?fct=tplsets", 2, XoopsLocale::S_DONE);
326  }
327  } else {
328  // Generate one module
329  $xoops->tpl()->assign('index', true);
330 
331  $tplset = $system->cleanVars($POST, 'tplset', 'default', 'string');
332 
333  $form = new Xoops\Form\ThemeForm(XoopsLocale::SELECT_TEMPLATES, "form", 'admin.php?fct=tplsets', "post", true);
334 
335  $tpltpl_handler = $xoops->getHandlerTplfile();
336  $templates_arr = $tpltpl_handler->find($tplset, '', null, $_REQUEST['select_modules']);
337 
338  $modules = new Xoops\Form\Select(XoopsLocale::SELECT_TEMPLATES, 'select_templates_modules', null, 10, true);
339  foreach (array_keys($templates_arr) as $i) {
340  $modules->addOption($templates_arr[$i]->getVar('tpl_file'));
341  }
342  $form->addElement($modules);
343 
344  $form->addElement(new Xoops\Form\Hidden("active_templates", "1"));
345  $form->addElement(new Xoops\Form\Hidden("force_generated", $_REQUEST['force_generated']));
346  $form->addElement(new Xoops\Form\Hidden("select_modules", $_REQUEST['select_modules']));
347  $form->addElement(new Xoops\Form\Hidden("active_modules", "1"));
348  $form->addElement(new Xoops\Form\Hidden("select_theme", $_REQUEST['select_theme']));
349  $form->addElement(new Xoops\Form\Hidden("op", "tpls_overload"));
350  $form->addElement(new Xoops\Form\Button("", "submit", XoopsLocale::A_SUBMIT, "submit"));
351  $xoops->tpl()->assign('form', $form->render());
352  }
353  break;
354 
355  // save
356  case 'tpls_save':
357  $path_file = $_REQUEST['path_file'];
358  if (isset($path_file)) {
359  // copy file
360  $copy_file = $path_file;
361  copy($copy_file, $path_file . '.back');
362  // Save modif
363  if (isset($_REQUEST['templates'])) {
364  $open = fopen("" . $path_file . "", "w+");
365  if (!fwrite($open, utf8_encode(stripslashes($_REQUEST['templates'])))) {
366  $xoops->redirect("admin.php?fct=tplsets", 2, XoopsLocale::E_NOT_DONE);
367  }
368  fclose($open);
369  }
370  }
371  $xoops->redirect("admin.php?fct=tplsets", 2, XoopsLocale::S_DONE);
372  break;
373 }
374 // Call Footer
375 $xoops->footer();
const ALL_MODULES
Definition: en_US.php:63
const A_SUBMIT
Definition: en_US.php:128
system_AdminIcons($img)
Definition: functions.php:117
const TEMPLATES
Definition: en_US.php:1044
$installed_mods
Definition: help.php:166
$i
Definition: dialog.php:68
$system
Definition: main.php:26
static getInstance($fct= '')
$l
Definition: main.php:88
static getInstance()
Definition: system.php:46
static getInstance()
Definition: Xoops.php:160
system_adminVersion($version, $value= '')
Definition: functions.php:95
$text
Definition: qrrender.php:27
$admin_page
Definition: main.php:34
const FILES_GENERATED
Definition: en_US.php:300
const C_MODULES
Definition: en_US.php:186
$form
Definition: xoops_code.php:21
const TEMPLATES_TIPS
Definition: en_US.php:400
exit
Definition: browse.php:104
$op
Definition: main.php:30
static fileExists($file)
Definition: xoopsload.php:506
const FORCED_FILE_GENERATION
Definition: en_US.php:301
static get($name)
$module
Definition: main.php:52
const TEMPLATE_OVERLOADED
Definition: en_US.php:315
const SELECT_TEMPLATES
Definition: en_US.php:975
const CONTROL_PANEL
Definition: en_US.php:247
const BLOCKS
Definition: en_US.php:138
const E_NOT_DONE
Definition: en_US.php:350
const E_NO_ACCESS_PERMISSION
Definition: en_US.php:351
$modules
Definition: userinfo.php:185
$criteria
$module_handler
Definition: main.php:55
$xoops
Definition: main.php:25
const SELECT_MODULE
Definition: en_US.php:974
$system_breadcrumb
Definition: main.php:30
$j
Definition: help.php:169
const CHOOSE_TEMPLATE
Definition: en_US.php:68
const TEMPLATES_MANAGER
Definition: en_US.php:399
const SELECT_THEME
Definition: en_US.php:976