XOOPS  2.6.0
module.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 
16 use Xoops\Core\Yaml;
19 
31 {
32  public $error = array();
33  public $trace = array();
34  protected $modulesList = array();
35  protected $modulesDirnames = array();
36  protected $config_delng = array();
37  protected $template_delng = array();
38  protected $config_old = array();
39  protected $reservedTables = array(
40  'block_module_link',
41  'config',
42  'configoption',
43  'groups',
44  'groups_users_link',
45  'group_permission',
46  'imgset',
47  'imgsetimg',
48  'imgset_tplset_link',
49  'modules',
50  'newblocks',
51  'online',
52  'priv_msgs',
53  'session',
54  'tplfile',
55  'tplset',
56  'tplsource',
57  'users',
58  );
59 
63  public function __construct()
64  {
65  // Get main instance
67  $module_handler = $xoops->getHandlerModule();
68 
69  $this->modulesList = XoopsLists::getModulesList();
70 
71  $modules = $module_handler->getObjectsArray();
72  /* @var $module XoopsModule */
73  foreach ($modules as $module) {
74  $this->modulesDirnames[] = $module->getInfo('dirname');
75  }
76  }
77 
83  public function getModuleList()
84  {
85  // Get main instance
87  $module_handler = $xoops->getHandlerModule();
88  $moduleperm_handler = $xoops->getHandlerGroupperm();
89 
90  $criteria = new CriteriaCompo();
91  $criteria->setSort('weight');
92  // Get all installed modules
93  $modules = $module_handler->getObjects($criteria, true);
94  $list = array();
95  /* @var $module XoopsModule */
96  foreach ($modules as $module) {
97  if (!$module->getInfo('extension')) {
98  if ($module->getInfo('dirname') == 'system') {
99  $module->setInfo('can_delete', false);
100  $module->setInfo('can_disable', false);
101  } else {
102  $module->setInfo('can_delete', true);
103  $module->setInfo('can_disable', true);
104  }
105  if (round($module->getInfo('version'), 2) != $module->getVar('version')) {
106  $module->setInfo('warning_update', true);
107  }
109  \XoopsBaseConfig::get('root-path') . '/modules/' . $module->getVar('dirname') . '/icons/logo_small.png'
110  )) {
111  $module->setInfo(
112  'logo_small',
113  \XoopsBaseConfig::get('url') . '/modules/' . $module->getVar('dirname') . '/icons/logo_small.png'
114  );
115  } else {
116  $module->setInfo('logo_small', \XoopsBaseConfig::get('url') . '/media/xoops/images/icons/16/default.png');
117  }
118  $module->setInfo('version', round($module->getVar('version') / 100, 2));
119  $module->setInfo('update', XoopsLocale::formatTimestamp($module->getVar('last_update'), 's'));
120  $module->setInfo(
121  'link_admin',
122  \XoopsBaseConfig::get('url') . '/modules/' . $module->getVar('dirname') . '/' . $module->getInfo('adminindex')
123  );
124 
125  if ($module->getVar('isactive')) {
126  $module->setInfo('options', $module->getAdminMenu());
127  }
128 
129  $groups = array();
130  if (is_object($xoops->user)) {
131  $groups = $xoops->user->getGroups();
132  }
133 
134  $sadmin = $moduleperm_handler->checkRight(
135  'module_admin',
136  $module->getVar('mid'),
137  $groups
138  );
139  if ($sadmin && ($module->getVar('hasnotification')
140  || is_array($module->getInfo('config')) || is_array($module->getInfo('comments')))
141  ) {
142  $module->setInfo(
143  'link_pref',
144  \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod='
145  . $module->getVar('mid')
146  );
147  }
148 
149  $list[] = $module;
150  }
151  }
152  return $list;
153  }
154 
160  public function getInstalledModules()
161  {
162  // Get main instance
164  $module_handler = $xoops->getHandlerModule();
165 
166  $ret = array();
167  $i = 0;
168  foreach ($this->modulesList as $file) {
169  if (XoopsLoad::fileExists(\XoopsBaseConfig::get('root-path') . '/modules/' . $file . '/xoops_version.php')) {
170  clearstatcache();
171  $file = trim($file);
172  if (!in_array($file, $this->modulesDirnames)) {
173  /* @var $module XoopsModule */
174  $module = $module_handler->create();
175  $module->loadInfo($file);
176  if (!$module->getInfo('extension')) {
177  $module->setInfo('mid', $i);
178  $module->setInfo('version', round($module->getInfo('version'), 2));
179  $ret[] = $module;
180  unset($module);
181  ++$i;
182  }
183  }
184  }
185  }
186  return $ret;
187  }
188 
197  public function install($mod = '', $force = false)
198  {
200  $module_handler = $xoops->getHandlerModule();
201  $mod = trim($mod);
202  try {
203  $cnt = $module_handler->getCount(new Criteria('dirname', $mod));
204  } catch (DBALException $e) {
205  $cnt = 0;
206  }
207  if ($cnt == 0) {
208  /* @var $module XoopsModule */
209  $module = $module_handler->create();
210  $module->loadInfoAsVar($mod);
211  $module->setVar('weight', 1);
212  $module->setVar('isactive', 1);
213  $module->setVar('last_update', time());
214  $install_script = $module->getInfo('onInstall');
215  if ($install_script && trim($install_script) != '') {
216  XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($install_script)));
217  }
218  $func = "xoops_module_pre_install_{$mod}";
219  // If pre install function is defined, execute
220  if (function_exists($func)) {
221  $result = $func($module);
222  if (!$result) {
223  $this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
224  $this->error = array_merge($this->error, $module->getErrors());
225  return false;
226  } else {
227  $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
228  $this->trace = array_merge($this->trace, $module->getMessages());
229  }
230  }
231  // Create tables
232  $created_tables = array();
233  if (count($this->error) == 0) {
234  $schema_file = $module->getInfo('schema');
235  $sql_file = $module->getInfo('sqlfile');
236  if (!empty($schema_file)) {
237  $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
238  if (!XoopsLoad::fileExists($schema_file_path)) {
239  $this->error[] =
240  sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
241  return false;
242  }
243  $importer = new ImportSchema;
244  $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
245  $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
246  $synchronizer->updateSchema($importSchema, true);
247  } elseif (is_array($sql_file) && !empty($sql_file[\XoopsBaseConfig::get('db-type')])) {
248  $xoops->deprecated('Install SQL files are deprecated since 2.6.0. Convert to portable Schemas');
249 
250  $sql_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $sql_file[\XoopsBaseConfig::get('db-type')];
251  if (!XoopsLoad::fileExists($sql_file_path)) {
252  $this->error[] =
253  sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
254  return false;
255  } else {
256  $this->trace[] = sprintf(SystemLocale::SF_SQL_FILE_FOUND, "<strong>{$sql_file_path}</strong>");
257  $this->trace[] = SystemLocale::MANAGING_TABLES;
258 
259  $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
260  $sql_query = trim($sql_query);
261  SqlUtility::splitMySqlFile($pieces, $sql_query);
262  foreach ($pieces as $piece) {
263  // [0] contains the prefixed query
264  // [4] contains unprefixed table name
265  $prefixed_query = SqlUtility::prefixQuery($piece, $xoops->db()->prefix());
266  if (!$prefixed_query) {
267  $this->error[]['sub'] = '<span class="red">' . sprintf(
269  '<strong>' . $piece . '</strong>'
270  ) . '</span>';
271  break;
272  }
273  // check if the table name is reserved
274  if (!in_array($prefixed_query[4], $this->reservedTables) || $mod == 'system') {
275  // not reserved, so try to create one
276  try {
277  $result = $xoops->db()->query($prefixed_query[0]);
278  } catch (Exception $e) {
279  $xoops->events()->triggerEvent('core.exception', $e);
280  $result=false;
281  }
282 
283  if (!$result) {
284  $this->error[] = $xoops->db()->errorInfo();
285  break;
286  } else {
287  if (!in_array($prefixed_query[4], $created_tables)) {
288  $this->trace[]['sub'] = sprintf(
290  '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>'
291  );
292  $created_tables[] = $prefixed_query[4];
293  } else {
294  $this->trace[]['sub'] = sprintf(
296  '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>'
297  );
298  }
299  }
300  } else {
301  // the table name is reserved, so halt the installation
302  $this->error[]['sub'] = sprintf(
304  '<strong>' . $prefixed_query[4] . '</strong>'
305  );
306  break;
307  }
308  }
309  // if there was an error, delete the tables created so far,
310  // so the next installation will not fail
311  if (count($this->error) > 0) {
312  foreach ($created_tables as $table) {
313  try {
314  $xoops->db()->query('DROP TABLE ' . $xoops->db()->prefix($table));
315  } catch (Exception $e) {
316  $xoops->events()->triggerEvent('core.exception', $e);
317  }
318  }
319  return false;
320  }
321  }
322  }
323  }
324  // Save module info, blocks, templates and perms
325  if (count($this->error) == 0) {
326  if (!$module_handler->insertModule($module)) {
327  $this->error[] = sprintf(
329  '<strong>' . $module->getVar('name') . '</strong>'
330  );
331  foreach ($created_tables as $ct) {
332  try {
333  $xoops->db()->query('DROP TABLE ' . $xoops->db()->prefix($ct));
334  } catch (Exception $e) {
335  $xoops->events()->triggerEvent('core.exception', $e);
336  }
337  }
338  $this->error[] = sprintf(XoopsLocale::EF_NOT_INSTALLED, "<strong>" . $module->name() . "</strong>");
339  $this->error[] = XoopsLocale::C_ERRORS;
340  unset($module);
341  unset($created_tables);
342  return false;
343  }
344  unset($created_tables);
345  $this->trace[] = XoopsLocale::S_DATA_INSERTED . sprintf(
347  '<strong>' . $module->getVar('mid') . '</strong>'
348  );
349  $xoops->db()->beginTransaction();
350  // install Templates
351  $this->installTemplates($module);
352 
353  $xoops->templateClearModuleCache($module->getVar('mid'));
354 
355  // install blocks
356  $this->installBlocks($module);
357 
358  // Install Configs
359  $this->installConfigs($module, 'add');
360 
361  if ($module->getInfo('hasMain')) {
362  $groups = array(FixedGroups::ADMIN, FixedGroups::USERS, FixedGroups::ANONYMOUS);
363  } else {
364  $groups = array(FixedGroups::ADMIN);
365  }
366  // retrieve all block ids for this module
367  $block_handler = $xoops->getHandlerBlock();
368  $blocks = $block_handler->getByModule($module->getVar('mid'), false);
369  $this->trace[] = SystemLocale::MANAGING_PERMISSIONS;
370  $gperm_handler = $xoops->getHandlerGroupperm();
371  foreach ($groups as $mygroup) {
372  if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
373  $mperm = $gperm_handler->create();
374  $mperm->setVar('gperm_groupid', $mygroup);
375  $mperm->setVar('gperm_itemid', $module->getVar('mid'));
376  $mperm->setVar('gperm_name', 'module_admin');
377  $mperm->setVar('gperm_modid', 1);
378  if (!$gperm_handler->insert($mperm)) {
379  $this->trace[]['sub'] = '<span class="red">' . sprintf(
381  '<strong>' . $mygroup . '</strong>'
382  ) . '</span>';
383  } else {
384  $this->trace[]['sub'] = sprintf(
386  '<strong>' . $mygroup . '</strong>'
387  );
388  }
389  unset($mperm);
390  }
391  $mperm = $gperm_handler->create();
392  $mperm->setVar('gperm_groupid', $mygroup);
393  $mperm->setVar('gperm_itemid', $module->getVar('mid'));
394  $mperm->setVar('gperm_name', 'module_read');
395  $mperm->setVar('gperm_modid', 1);
396  if (!$gperm_handler->insert($mperm)) {
397  $this->trace[]['sub'] = '<span class="red">' . sprintf(
399  '<strong>' . $mygroup . '</strong>'
400  ) . '</span>';
401  } else {
402  $this->trace[]['sub'] = sprintf(
404  '<strong>' . $mygroup . '</strong>'
405  );
406  }
407  unset($mperm);
408  foreach ($blocks as $blc) {
409  $bperm = $gperm_handler->create();
410  $bperm->setVar('gperm_groupid', $mygroup);
411  $bperm->setVar('gperm_itemid', $blc);
412  $bperm->setVar('gperm_name', 'block_read');
413  $bperm->setVar('gperm_modid', 1);
414  if (!$gperm_handler->insert($bperm)) {
415  $this->trace[]['sub'] = '<span class="red">'
416  . SystemLocale::E_BLOCK_ACCESS_NOT_ADDED . ' Block ID: <strong>'
417  . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
418  } else {
419  $this->trace[]['sub'] = SystemLocale::S_BLOCK_ACCESS_ADDED
420  . sprintf(SystemLocale::F_BLOCK_ID, "<strong>" . $blc . "</strong>")
421  . sprintf(SystemLocale::F_GROUP_ID, "<strong>" . $mygroup . "</strong>");
422  }
423  unset($bperm);
424  }
425  }
426  unset($blocks);
427  unset($groups);
428 
429  // execute module specific install script if any
430  // If pre install function is defined, execute
431  $func = "xoops_module_install_{$mod}";
432  if (function_exists($func)) {
433  $result = $func($module);
434  if (!$result) {
435  $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
436  $this->trace = array_merge($this->trace, $module->getErrors());
437  } else {
438  $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
439  $this->trace = array_merge($this->trace, $module->getMessages());
440  }
441  }
442 
443  $this->trace[] = sprintf(
445  '<strong>' . $module->getVar('name', 's') . '</strong>'
446  );
447  unset($blocks);
448 
449  $xoops->db()->commit();
450 
451  XoopsPreload::getInstance()->triggerEvent('onModuleInstall', array(&$module, &$this));
452  return $module;
453  }
454  } else {
455  $this->error[] = sprintf(
457  '<strong>' . $mod . '</strong>'
458  ) . "&nbsp;" . XoopsLocale::C_ERRORS;
459  return false;
460  }
461  return false;
462  }
463 
471  public function uninstall($mod = '')
472  {
474  $module_handler = $xoops->getHandlerModule();
475  $module = $module_handler->getByDirname($mod);
476  $xoops->templateClearModuleCache($module->getVar('mid'));
477 
478  if ($module->getVar('dirname') == 'system') {
479  $this->error[] = sprintf(
481  '<strong>' . $module->getVar('name') . '</strong>'
482  ) . "&nbsp;" . XoopsLocale::C_ERRORS;
484  return false;
485  } elseif ($module->getVar('dirname') == $xoops->getConfig('startpage')) {
486  $this->error[] = sprintf(
488  '<strong>' . $module->getVar('name') . '</strong>'
489  ) . "&nbsp;" . XoopsLocale::C_ERRORS;
491  return false;
492  } else {
493  // Load module specific install script if any
494  $uninstall_script = $module->getInfo('onUninstall');
495  if ($uninstall_script && trim($uninstall_script) != '') {
496  XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($uninstall_script)));
497  }
498  $func = "xoops_module_pre_uninstall_{$mod}";
499  // If pre uninstall function is defined, execute
500  if (function_exists($func)) {
501  $result = $func($module);
502  if (!$result) {
503  $this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
504  $this->error[] = sprintf(
506  '<strong>' . $module->getVar('name') . '</strong>'
507  ) . "&nbsp;" . XoopsLocale::C_ERRORS;
508  $this->error = array_merge($this->error, $module->getErrors());
509  return false;
510  } else {
511  $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
512  $this->trace = array_merge($this->trace, $module->getMessages());
513  }
514  }
515 
516  if (false === $module_handler->deleteModule($module)) {
517  $this->error[] = sprintf(XoopsLocale::EF_NOT_DELETED, $module->getVar('name'));
518  return false;
519  } else {
520  // delete templates
521  $this->deleteTemplates($module);
522 
523  // Delete blocks and block template files
524  $this->deleteBlocks($module);
525 
526  // Delete tables used by this module
527  $modtables = $module->getInfo('tables');
528  if ($modtables != false && is_array($modtables)) {
529  // get a schema manager
530  $schemaManager = $xoops->db()->getSchemaManager();
531  // create schema from the current database
532  $toSchema = $schemaManager->createSchema();
533 
534  $this->trace[] = SystemLocale::MANAGING_TABLES;
535  foreach ($modtables as $table) {
536  // prevent deletion of reserved core tables!
537  if (!in_array($table, $this->reservedTables)) {
538  $toSchema->dropTable($xoops->db()->prefix($table));
539  $this->trace[]['sub'] = sprintf(
541  '<strong>' . $xoops->db()->prefix($table) . '</strong>'
542  );
543  } else {
544  $this->trace[]['sub'] = '<span class="red">' . sprintf(
546  '<strong>' . $xoops->db()->prefix($table) . '</strong>'
547  ) . '</span>';
548  }
549  }
550  $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
551  $synchronizer->updateSchema($toSchema, false);
552  }
553 
554  // delete permissions if any
555  $gperm_handler = $xoops->getHandlerGroupperm();
556  if (false === $gperm_handler->deleteByModule($module->getVar('mid'))) {
557  $this->trace[] = '<span class="red">' . SystemLocale::E_GROUP_PERMISSIONS_NOT_DELETED . '</span>';
558  } else {
560  }
561 
562  // delete module config options if any
563  $this->deleteConfigs($module);
564 
565  // execute module specific install script if any
566  $func = 'xoops_module_uninstall_' . $mod;
567  if (function_exists($func)) {
568  $result = $func($module);
569  if (!$result) {
570  $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
571  $this->trace = array_merge($this->error, $module->getErrors());
572  } else {
573  $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
574  $this->trace = array_merge($this->trace, $module->getMessages());
575  }
576  }
577  $this->trace[] = sprintf(
579  '<strong>' . $module->getVar('name') . '</strong>'
580  );
581  XoopsPreload::getInstance()->triggerEvent('onModuleUninstall', array(&$module, &$this));
582  return $module;
583  }
584  }
585  }
586 
594  public function update($mod = '')
595  {
597  $module_handler = $xoops->getHandlerModule();
598  $module = $module_handler->getByDirname($mod);
599  $xoops->templateClearModuleCache($module->getVar('mid'));
600  // Save current version for use in the update function
601  $prev_version = $module->getVar('version');
602  // we dont want to change the module name set by admin
603  $temp_name = $module->getVar('name');
604  $module->loadInfoAsVar($module->getVar('dirname'));
605  $module->setVar('name', $temp_name);
606  $module->setVar('last_update', time());
607 
608  if (!$module_handler->insertModule($module)) {
609  $this->error[] = sprintf(XoopsLocale::EF_NOT_UPDATED, "<strong>" . $module->getVar('name') . "</strong>");
610  return false;
611  } else {
612  // execute module specific preupdate script if any
613  $update_script = $module->getInfo('onUpdate');
614  if (false != $update_script && trim($update_script) != '') {
615  XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script)));
616  $func = 'xoops_module_preupdate_' . $mod;
617  if (function_exists($func)) {
618  $result = $func($module, $prev_version);
619  if (!$result) {
620  $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
621  $this->trace = array_merge($this->error, $module->getErrors());
622  } else {
623  $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
624  $this->trace = array_merge($this->trace, $module->getMessages());
625  }
626  }
627  }
628 
629  // update schema
630  $schema_file = $module->getInfo('schema');
631  if (!empty($schema_file)) {
632  $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
633  if (!XoopsLoad::fileExists($schema_file_path)) {
634  $this->error[] =
635  sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
636  return false;
637  }
638  $importer = new ImportSchema;
639  $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
640  $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
641  $synchronizer->updateSchema($importSchema, true);
642  }
643 
644  // delete templates
645  $this->deleteTemplates($module);
646 
647  // install templates
648  $this->installTemplates($module);
649 
650  // install blocks
651  $this->installBlocks($module);
652 
653  // reset compile_id
654  $xoops->tpl()->setCompileId();
655 
656  // first delete all config entries
657  $this->deleteConfigs($module);
658 
659  // Install Configs
660  $this->installConfigs($module, 'update');
661 
662  // execute module specific update script if any
663  $update_script = $module->getInfo('onUpdate');
664  if (false != $update_script && trim($update_script) != '') {
665  XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script)));
666  $func = 'xoops_module_update_' . $mod;
667  if (function_exists($func)) {
668  $result = $func($module, $prev_version);
669  if (!$result) {
670  $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
671  $this->trace = array_merge($this->error, $module->getErrors());
672  } else {
673  $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
674  $this->trace = array_merge($this->trace, $module->getMessages());
675  }
676  }
677  }
678  $this->trace[] = sprintf(XoopsLocale::SF_UPDATED, '<strong>' . $module->getVar('name', 's') . '</strong>');
679  return $module;
680  }
681  }
682 
692  public function getTemplate($dirname, $template, $type = '')
693  {
695  $ret = '';
696  switch ($type) {
697  case 'blocks':
698  case 'admin':
699  $path = $xoops->path('modules/' . $dirname . '/templates/' . $type . '/' . $template);
700  break;
701  default:
702  $path = $xoops->path('modules/' . $dirname . '/templates/' . $template);
703  break;
704  }
706  return $ret;
707  } else {
708  $lines = file($path);
709  }
710  if (!$lines) {
711  return $ret;
712  }
713  $count = count($lines);
714  for ($i = 0; $i < $count; ++$i) {
715  $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
716  }
717  return $ret;
718  }
719 
728  {
730  $templates = $module->getInfo('templates');
731  if (is_array($templates) && count($templates) > 0) {
732  $this->trace[] = SystemLocale::MANAGING_TEMPLATES;
733  $tplfile_handler = $xoops->getHandlerTplfile();
734  foreach ($templates as $tpl) {
735  $tpl['file'] = trim($tpl['file']);
736  if (!in_array($tpl['file'], $this->template_delng)) {
737  $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
738  $tpldata = $this->getTemplate($module->getVar('dirname'), $tpl['file'], $type);
739  $tplfile = $tplfile_handler->create();
740  $tplfile->setVar('tpl_refid', $module->getVar('mid'));
741  $tplfile->setVar('tpl_lastimported', 0);
742  $tplfile->setVar('tpl_lastmodified', time());
743 
744  if (preg_match("/\.css$/i", $tpl['file'])) {
745  $tplfile->setVar('tpl_type', 'css');
746  } else {
747  $tplfile->setVar('tpl_type', $type);
748  }
749  $tplfile->setVar('tpl_source', $tpldata, true);
750  $tplfile->setVar('tpl_module', $module->getVar('dirname'));
751  $tplfile->setVar('tpl_tplset', 'default');
752  $tplfile->setVar('tpl_file', $tpl['file'], true);
753  $tplfile->setVar('tpl_desc', $tpl['description'], true);
754  if (!$tplfile_handler->insertTpl($tplfile)) {
755  $this->trace[]['sub'] = '<span class="red">' . sprintf(
757  '<strong>' . $tpl['file'] . '</strong>'
758  ) . '</span>';
759  } else {
760  $newid = $tplfile->getVar('tpl_id');
761  $this->trace[]['sub'] = sprintf(
763  '<strong>' . $tpl['file'] . '</strong>'
764  );
765  if ($module->getVar('dirname') == 'system') {
766  if (!$xoops->templateTouch($newid)) {
767  $this->trace[]['sub'] = '<span class="red">' . sprintf(
769  '<strong>' . $tpl['file'] . '</strong>'
770  ) . '</span>';
771  } else {
772  $this->trace[]['sub'] = sprintf(
774  '<strong>' . $tpl['file'] . '</strong>'
775  );
776  }
777  } else {
778  if ($xoops->config['template_set'] == 'default') {
779  if (!$xoops->templateTouch($newid)) {
780  $this->trace[]['sub'] = '<span class="red">' . sprintf(
782  '<strong>' . $tpl['file'] . '</strong>'
783  ) . '</span>';
784  } else {
785  $this->trace[]['sub'] = sprintf(
787  '<strong>' . $tpl['file'] . '</strong>'
788  );
789  }
790  }
791  }
792  }
793  unset($tpldata);
794  } else {
795  $this->trace[]['sub'] = '<span class="red">' . sprintf(
797  '<strong>' . $tpl['file'] . '</strong>'
798  ) . '</span>';
799  }
800  }
801  }
802  }
803 
812  {
814  $tplfile_handler = $xoops->getHandlerTplfile();
815  $templates = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
816  if (is_array($templates) && count($templates) > 0) {
817  $this->trace[] = SystemLocale::MANAGING_TEMPLATES;
818  // delete template file entry in db
819  /* @var $template XoopsTplfile */
820  foreach ($templates as $template) {
821  if (!$tplfile_handler->deleteTpl($template)) {
822  $this->template_delng[] = $template->getVar('tpl_file');
823  }
824  }
825  }
826  }
827 
836  {
838  $blocks = $module->getInfo('blocks');
839  $this->trace[] = SystemLocale::MANAGING_BLOCKS;
840  $block_handler = $xoops->getHandlerBlock();
841  $blockmodulelink_handler = $xoops->getHandlerBlockmodulelink();
842  $tplfile_handler = $xoops->getHandlerTplfile();
843  $showfuncs = array();
844  $funcfiles = array();
845  if (is_array($blocks) && count($blocks) > 0) {
846  foreach ($blocks as $i => $block) {
847  if (isset($block['show_func']) && $block['show_func'] != ''
848  && isset($block['file']) && $block['file'] != ''
849  ) {
850  $showfuncs[] = $block['show_func'];
851  $funcfiles[] = $block['file'];
852 
853  $criteria = new CriteriaCompo();
854  $criteria->add(new Criteria('mid', $module->getVar('mid')));
855  $criteria->add(new Criteria('func_num', $i));
856 
857  $block_obj = $block_handler->getObjects($criteria);
858  if (count($block_obj) == 0) {
859  $block_obj[0] = $block_handler->create();
860  $block_obj[0]->setVar('func_num', $i);
861  $block_obj[0]->setVar('mid', $module->getVar('mid'));
862  $block_obj[0]->setVar('name', addslashes($block['name']));
863  $block_obj[0]->setVar('title', addslashes($block['name']));
864  $block_obj[0]->setVar('side', 0);
865  $block_obj[0]->setVar('weight', 0);
866  $block_obj[0]->setVar('visible', 0);
867  $block_obj[0]->setVar('block_type', ($module->getVar('dirname') == 'system') ? 'S' : 'M');
868  $block_obj[0]->setVar('isactive', 1);
869  $block_obj[0]->setVar('content', '');
870  $block_obj[0]->setVar('c_type', 'H');
871  $block_obj[0]->setVar('dirname', $module->getVar('dirname'));
872  $block_obj[0]->setVar('options', isset($block['options']) ? $block['options'] : '');
873  }
874  $block_obj[0]->setVar('func_file', $block['file']);
875  $block_obj[0]->setVar('show_func', isset($block['show_func']) ? $block['show_func'] : '');
876  $block_obj[0]->setVar('edit_func', isset($block['edit_func']) ? $block['edit_func'] : '');
877  $template = $this->getTemplate($module->getVar('dirname'), $block['template'], 'blocks');
878  $block_obj[0]->setVar('template', !empty($template) ? $block['template'] : '');
879  $block_obj[0]->setVar('last_modified', time());
880 
881  if (!$block_handler->insert($block_obj[0])) {
882  $this->trace[]['sub'] = '<span class="red">' . sprintf(
884  $block_obj[0]->getVar('name')
885  ) . '</span>';
886  } else {
887  $this->trace[]['sub'] = sprintf(
889  '<strong>' . $block_obj[0]->getVar('name')
890  ) . '</strong>' . sprintf(
892  '<strong>' . $block_obj[0]->getVar('bid') . '</strong>'
893  );
894 
895  if (0 == $blockmodulelink_handler->getCount(new Criteria('block_id', $block_obj[0]->getVar('bid')))) {
896  $blockmodulelink = $blockmodulelink_handler->create();
897  $blockmodulelink->setVar('block_id', $block_obj[0]->getVar('bid'));
898  $blockmodulelink->setVar('module_id', 0); //show on all pages
899  $blockmodulelink_handler->insert($blockmodulelink);
900  }
901 
902  if ($template != '') {
903  $tplfile = $tplfile_handler->find('default', 'block', $block_obj[0]->getVar('bid'));
904  if (count($tplfile) == 0) {
905  $tplfile_new = $tplfile_handler->create();
906  $tplfile_new->setVar('tpl_module', $module->getVar('dirname'));
907  $tplfile_new->setVar('tpl_refid', $block_obj[0]->getVar('bid'));
908  $tplfile_new->setVar('tpl_tplset', 'default');
909  $tplfile_new->setVar('tpl_file', $block_obj[0]->getVar('template'), true);
910  $tplfile_new->setVar('tpl_type', 'block');
911  } else {
912  /* @var $tplfile_new XoopsTplfile */
913  $tplfile_new = $tplfile[0];
914  $tplfile_new->setVars($tplfile_new->getValues());
915  }
916  $tplfile_new->setVar('tpl_source', $template, true);
917  $tplfile_new->setVar('tpl_desc', $block['description'], true);
918  $tplfile_new->setVar('tpl_lastmodified', time());
919  $tplfile_new->setVar('tpl_lastimported', 0);
920  if (!$tplfile_handler->insertTpl($tplfile_new)) {
921  $this->trace[]['sub'] = '<span class="red">' . sprintf(
923  '<strong>' . $block['template'] . '</strong>'
924  ) . '</span>';
925  } else {
926  $this->trace[]['sub'] = sprintf(
928  '<strong>' . $block['template'] . '</strong>'
929  );
930  if ($module->getVar('dirname') == 'system') {
931  if (!$xoops->templateTouch($tplfile_new->getVar('tpl_id'))) {
932  $this->trace[]['sub'] = '<span class="red">' . sprintf(
934  '<strong>' . $block['template'] . '</strong>'
935  ) . '</span>';
936  } else {
937  $this->trace[]['sub'] = sprintf(
939  '<strong>' . $block['template'] . '</strong>'
940  );
941  }
942  } else {
943  if ($xoops->config['template_set'] == 'default') {
944  if (!$xoops->templateTouch($tplfile_new->getVar('tpl_id'))) {
945  $this->trace[]['sub'] = '<span class="red">' . sprintf(
947  '<strong>' . $block['template'] . '</strong>'
948  ) . '</span>';
949  } else {
950  $this->trace[]['sub'] = sprintf(
952  '<strong>' . $block['template'] . '</strong>'
953  );
954  }
955  }
956  }
957  }
958  }
959  }
960  }
961  }
962  }
963  $blocks = $block_handler->getByModule($module->getVar('mid'));
964  foreach ($blocks as $block) {
965  /* @var $block XoopsBlock */
966  if (!in_array($block->getVar('show_func'), $showfuncs)
967  || !in_array($block->getVar('func_file'), $funcfiles)
968  ) {
969  if (!$block_handler->delete($block)) {
970  $this->trace[]['sub'] = '<span class="red">' . sprintf(
972  "<strong>" . $block->getVar('name') . "</strong>"
973  ) . sprintf(
975  "<strong>" . $block->getVar('bid') . "</strong>"
976  ) . '</span>';
977  } else {
978  $this->trace[]['sub'] = sprintf(
980  '<strong>' . $block->getVar('name') . '</strong>'
981  ) . '&nbsp;' . sprintf(
983  '<strong>' . $block->getVar('bid') . '</strong>'
984  );
985  if ($block->getVar('template') != '') {
986  $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
987  if (is_array($tplfiles)) {
988  /* @var $tplfile XoopsTplfile */
989  foreach ($tplfiles as $tplfile) {
990  if (!$tplfile_handler->deleteTpl($tplfile)) {
991  $this->trace[]['sub'] = '<span class="red">'
993  . '(ID: <strong>' . $tplfile->getVar('tpl_id') . '</strong>)</span>';
994  } else {
995  $this->trace[]['sub'] = sprintf(
997  "<strong>" . $tplfile->getVar('tpl_file') . "</strong>"
998  );
999  }
1000  }
1001  }
1002  }
1003  }
1004  }
1005  }
1006  }
1007 
1016  {
1018  $block_handler = $xoops->getHandlerBlock();
1019  $blocks = $block_handler->getByModule($module->getVar('mid'));
1020  if (is_array($blocks) && count($blocks) > 0) {
1021  $tplfile_handler = $xoops->getHandlerTplfile();
1022  $this->trace[] = SystemLocale::MANAGING_BLOCKS;
1023  /* @var $block XoopsBlock */
1024  foreach ($blocks as $block) {
1025  if (false === $block_handler->deleteBlock($block)) {
1026  $this->trace[]['sub'] = '<span class="red">' . sprintf(
1028  "<strong>" . $block->getVar('name') . "</strong>"
1029  ) . sprintf(
1031  "<strong>" . $block->getVar('bid') . "</strong>"
1032  ) . '</span>';
1033  } else {
1034  $this->trace[]['sub'] = sprintf(
1036  "<strong>" . $block->getVar('name') . "</strong>"
1037  ) . sprintf(
1039  "<strong>" . $block->getVar('bid') . "</strong>"
1040  );
1041  }
1042  if ($block->getVar('template') != '') {
1043  $templates = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
1044  /* @var $template XoopsTplfile */
1045  foreach ($templates as $template) {
1046  if (!$tplfile_handler->delete($template)) {
1047  $this->trace[]['sub'] = '<span class="red">' . sprintf(
1049  $template->getVar('tpl_file')
1050  ) . sprintf(
1052  "<strong>" . $template->getVar('tpl_id') . "</strong>"
1053  ) . '</span>';
1054  } else {
1055  $this->trace[]['sub'] = sprintf(
1057  "<strong>" . $template->getVar('tpl_file') . "</strong>"
1058  ) . sprintf(
1060  "<strong>" . $template->getVar('tpl_id') . "</strong>"
1061  );
1062  }
1063  }
1064  unset($templates);
1065  }
1066  }
1067  }
1068  }
1069 
1078  {
1080 
1081  $config_handler = $xoops->getHandlerConfig();
1082  $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
1083  if (is_array($configs) && count($configs) > 0) {
1084  $this->trace[] = SystemLocale::MANAGING_PREFERENCES;
1085  /* @var $config XoopsConfigItem */
1086  foreach ($configs as $config) {
1087  if (!$config_handler->deleteConfig($config)) {
1088  $this->trace[]['sub'] = '<span class="red">'
1090  . sprintf(SystemLocale::F_CONFIG_ID, "<strong>" . $config->getvar('conf_id') . "</strong>")
1091  . '</span>';
1092  // save the name of config failed to delete for later use
1093  $this->config_delng[] = $config->getvar('conf_name');
1094  } else {
1095  $this->config_old[$config->getvar('conf_name')]['value'] = $config->getvar('conf_value', 'N');
1096  $this->config_old[$config->getvar('conf_name')]['formtype'] = $config->getvar('conf_formtype');
1097  $this->config_old[$config->getvar('conf_name')]['valuetype'] = $config->getvar('conf_valuetype');
1098  $this->trace[]['sub'] = SystemLocale::S_CONFIG_DATA_DELETED
1099  . sprintf(SystemLocale::F_CONFIG_ID, "<strong>" . $config->getVar('conf_id') . "</strong>");
1100  }
1101  }
1102  }
1103  }
1104 
1113  {
1115  // now reinsert them with the new settings
1116  $configs = $module->getInfo('config');
1117  if (!is_array($configs)) {
1118  $configs = array();
1119  }
1120 
1121  XoopsPreload::getInstance()->triggerEvent('onModuleUpdateConfigs', array($module, &$configs));
1122 
1123  if (is_array($configs) && count($configs) > 0) {
1124  $this->trace[] = SystemLocale::MANAGING_PREFERENCES;
1125  $config_handler = $xoops->getHandlerConfig();
1126  $order = 0;
1127  foreach ($configs as $config) {
1128  // only insert ones that have been deleted previously with success
1129  if (!in_array($config['name'], $this->config_delng)) {
1130  $confobj = $config_handler->createConfig();
1131  $confobj->setVar('conf_modid', $module->getVar('mid'));
1132  $confobj->setVar('conf_catid', 0);
1133  $confobj->setVar('conf_name', $config['name']);
1134  $confobj->setVar('conf_title', $config['title'], true);
1135  $confobj->setVar('conf_desc', $config['description'], true);
1136  $confobj->setVar('conf_formtype', $config['formtype']);
1137  $confobj->setVar('conf_valuetype', $config['valuetype']);
1138  if (isset($this->config_old[$config['name']]['value'])
1139  && $this->config_old[$config['name']]['formtype'] == $config['formtype']
1140  && $this->config_old[$config['name']]['valuetype'] == $config['valuetype']
1141  ) {
1142  // preserver the old value if any
1143  // form type and value type must be the same
1144  $confobj->setVar('conf_value', $this->config_old[$config['name']]['value'], true);
1145  } else {
1146  $confobj->setConfValueForInput($config['default'], true);
1147  //$confobj->setVar('conf_value', $config['default'], true);
1148  }
1149  $confobj->setVar('conf_order', $order);
1150  $confop_msgs = '';
1151  if (isset($config['options']) && is_array($config['options'])) {
1152  foreach ($config['options'] as $key => $value) {
1153  $confop = $config_handler->createConfigOption();
1154  $confop->setVar('confop_name', $key, true);
1155  $confop->setVar('confop_value', $value, true);
1156  $confobj->setConfOptions($confop);
1157  $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
1158  $confop_msgs .= SystemLocale::S_CONFIG_OPTION_ADDED;
1159  $confop_msgs .= '&nbsp;';
1160  $confop_msgs .= XoopsLocale::C_NAME;
1161  $confop_msgs .= ' <strong>'
1162  . Xoops_Locale::translate($key, $module->getVar('dirname'))
1163  . '</strong> ';
1164  $confop_msgs .= XoopsLocale::C_VALUE . ' <strong>' . $value . '</strong> ';
1165  unset($confop);
1166  }
1167  }
1168  ++$order;
1169  if (false != $config_handler->insertConfig($confobj)) {
1170  $this->trace[]['sub'] = sprintf(
1172  "<strong>" . $config['name'] . "</strong>"
1173  ) . $confop_msgs;
1174  } else {
1175  $this->trace[]['sub'] = '<span class="red">'
1176  . sprintf(SystemLocale::EF_CONFIG_NOT_ADDED, "<strong>" . $config['name'] . "</strong>")
1177  . '</span>';
1178  }
1179  unset($confobj);
1180  }
1181  }
1182  unset($configs);
1183  }
1184  }
1185 }
const EF_GROUP_ID_ADMIN_ACCESS_RIGHT_NOT_ADDED
Definition: en_US.php:277
const EF_GROUP_ID_USER_ACCESS_RIGHT_NOT_ADDED
Definition: en_US.php:278
const E_BLOCK_ACCESS_NOT_ADDED
Definition: en_US.php:289
$tpl
Definition: backend.php:39
const F_MODULE_ID
Definition: en_US.php:308
installconfigs(XoopsModule $module)
Definition: module.php:1112
$path
Definition: execute.php:31
static formatTimestamp($time, $format= 'l', $timeoffset=null)
Definition: Abstract.php:289
const EF_TABLE_DROP_NOT_ALLOWED
Definition: en_US.php:269
const SF_CONFIG_ADDED
Definition: en_US.php:381
$i
Definition: dialog.php:68
static getInstance()
Definition: Events.php:57
static prefixQuery($query, $prefix)
Definition: sqlutility.php:126
const EF_NOT_INSTALLED
Definition: en_US.php:263
const EF_NOT_UNINSTALLED
Definition: en_US.php:264
const SF_EXECUTED
Definition: en_US.php:985
deleteBlocks(XoopsModule $module)
Definition: module.php:1015
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
const SF_TEMPLATE_RECOMPILED
Definition: en_US.php:386
const S_DATA_INSERTED
Definition: en_US.php:1025
const SF_TABLE_CREATED
Definition: en_US.php:995
const EF_NOT_EXECUTED
Definition: en_US.php:261
$result
Definition: pda.php:33
const S_BLOCK_ACCESS_ADDED
Definition: en_US.php:393
const E_SYSTEM_MODULE_CANNOT_BE_DEACTIVATED
Definition: en_US.php:296
getTemplate($dirname, $template, $type= '')
Definition: module.php:692
const SF_TEMPLATE_UPDATED
Definition: en_US.php:387
const SF_BLOCK_TEMPLATE_DELETED
Definition: en_US.php:378
update($mod= '')
Definition: module.php:594
__construct()
Definition: module.php:63
const S_GROUP_PERMISSIONS_DELETED
Definition: en_US.php:396
const SF_DATA_INSERTED_TO_TABLE
Definition: en_US.php:982
getInfo($name=null)
Definition: module.php:153
const SF_TEMPLATE_ADDED
Definition: en_US.php:385
const EF_BLOCK_NOT_DELETED
Definition: en_US.php:269
const SF_INSTALLED
Definition: en_US.php:989
installTemplates(XoopsModule $module)
Definition: module.php:727
const MANAGING_BLOCKS
Definition: en_US.php:333
$gperm_handler
const EF_SQL_FILE_NOT_FOUND
Definition: en_US.php:279
getVar($key, $format= 's')
const MANAGING_TEMPLATES
Definition: en_US.php:337
const EF_TEMPLATE_NOT_ADDED_TO_DATABASE
Definition: en_US.php:281
const EF_NOT_INSERTED_TO_DATABASE
Definition: en_US.php:262
getInstalledModules()
Definition: module.php:160
$modulesDirnames
Definition: module.php:35
const F_BLOCK_ID
Definition: en_US.php:302
const SF_BLOCK_DELETED
Definition: en_US.php:377
$xoops
Definition: admin.php:25
const F_CONFIG_ID
Definition: en_US.php:303
const EF_TEMPLATE_NOT_UPDATED
Definition: en_US.php:284
const EF_TABLE_IS_RESERVED
Definition: en_US.php:280
const C_NAME
Definition: en_US.php:187
const C_ERRORS
Definition: en_US.php:180
deleteTemplates(XoopsModule $module)
Definition: module.php:811
const S_CONFIG_DATA_DELETED
Definition: en_US.php:394
const SF_SQL_FILE_FOUND
Definition: en_US.php:384
static splitMySqlFile(&$ret, $sql)
Definition: sqlutility.php:43
static fileExists($file)
Definition: xoopsload.php:506
getModuleList()
Definition: module.php:83
const SF_GROUP_ID_ADMIN_ACCESS_RIGHT_ADDED
Definition: en_US.php:382
const SF_BLOCK_TEMPLATE_DEPRECATED
Definition: en_US.php:379
if($_SERVER['REQUEST_METHOD']== 'POST') $config_handler
const SF_TABLE_DROPPED
Definition: en_US.php:996
install($mod= '', $force=false)
Definition: module.php:197
static get($name)
uninstall($mod= '')
Definition: module.php:471
const MANAGING_PREFERENCES
Definition: en_US.php:335
const E_GROUP_PERMISSIONS_NOT_DELETED
Definition: en_US.php:292
$module
Definition: main.php:52
const SF_UPDATED
Definition: en_US.php:1000
$configs
Definition: config.php:27
const SF_GROUP_ID_USER_ACCESS_RIGHT_ADDED
Definition: en_US.php:383
installBlocks(XoopsModule $module)
Definition: module.php:835
$type
Definition: misc.php:33
const S_CONFIG_OPTION_ADDED
Definition: en_US.php:395
$groups
$modules
Definition: userinfo.php:185
return $config
deleteConfigs(XoopsModule $module)
Definition: module.php:1077
static translate($key, $dirname= 'xoops')
Definition: Locale.php:128
const E_CONFIG_DATA_NOT_DELETED
Definition: en_US.php:291
const EF_TEMPLATE_NOT_DELETED
Definition: en_US.php:282
$criteria
const E_BLOCK_TEMPLATE_DEPRECATED_NOT_REMOVED
Definition: en_US.php:290
const F_GROUP_ID
Definition: en_US.php:306
const MANAGING_TABLES
Definition: en_US.php:336
$dirname
Definition: backend.php:38
$module_handler
Definition: main.php:55
static loadFile($file, $once=true)
Definition: xoopsload.php:454
const E_THIS_MODULE_IS_SET_AS_DEFAULT_START_PAGE
Definition: en_US.php:298
const EF_BLOCK_TEMPLATE_NOT_DELETED
Definition: en_US.php:270
const EF_TEMPLATE_NOT_RECOMPILED
Definition: en_US.php:283
const EF_NOT_UPDATED
Definition: en_US.php:265
const F_TEMPLATE_ID
Definition: en_US.php:309
const EF_CONFIG_NOT_ADDED
Definition: en_US.php:272
const SF_BLOCK_UPDATED
Definition: en_US.php:380
const MANAGING_PERMISSIONS
Definition: en_US.php:334
const EF_NOT_DELETED
Definition: en_US.php:260
$moduleperm_handler
Definition: cp_header.php:31
const C_VALUE
Definition: en_US.php:195
const EF_INVALID_SQL
Definition: en_US.php:255
const SF_UNINSTALLED
Definition: en_US.php:999