18 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
72 function loadInfoAsVar(
$dirname, $verbose =
true)
75 if (!isset($this->modinfo)) {
78 $this->setVar(
'name', $this->modinfo[
'name'],
true);
79 $this->setVar(
'version', intval(100 * ($this->modinfo[
'version'] + 0.001)),
true);
80 $this->setVar(
'dirname', $this->modinfo[
'dirname'],
true);
81 $hasmain = (isset($this->modinfo[
'hasMain']) && $this->modinfo[
'hasMain'] == 1) ? 1 : 0;
82 $hasadmin = (isset($this->modinfo[
'hasAdmin']) && $this->modinfo[
'hasAdmin'] == 1) ? 1 : 0;
83 $hassearch = (isset($this->modinfo[
'hasSearch']) && $this->modinfo[
'hasSearch'] == 1) ? 1 : 0;
84 $hasconfig = ((isset($this->modinfo[
'config']) && is_array($this->modinfo[
'config'])) || ! empty($this->modinfo[
'hasComments'])) ? 1 : 0;
85 $hascomments = (isset($this->modinfo[
'hasComments']) && $this->modinfo[
'hasComments'] == 1) ? 1 : 0;
87 $hasnotification = (isset($this->modinfo[
'hasNotification']) && $this->modinfo[
'hasNotification'] == 1) ? 1 : 0;
88 $this->setVar(
'hasmain', $hasmain);
89 $this->setVar(
'hasadmin', $hasadmin);
90 $this->setVar(
'hassearch', $hassearch);
91 $this->setVar(
'hasconfig', $hasconfig);
92 $this->setVar(
'hascomments', $hascomments);
94 $this->setVar(
'hasnotification', $hasnotification);
103 function setMessage($str)
105 $this->_msg[] = trim($str);
114 function getMessages()
126 function setInfo($name, $value)
129 $this->modinfo = $value;
131 $this->modinfo[$name] = $value;
143 function &getInfo($name = null)
145 if (!isset($this->modinfo)) {
146 $this->loadInfo($this->getVar(
'dirname'));
149 if (isset($this->modinfo[$name])) {
150 return $this->modinfo[$name];
155 return $this->modinfo;
165 if ($this->getVar(
'hasmain') == 1) {
166 $ret =
'<a href="' . XOOPS_URL .
'/modules/' . $this->getVar(
'dirname') .
'/">' . $this->getVar(
'name') .
'</a>';
180 if ($this->getInfo(
'sub') && is_array($this->getInfo(
'sub'))) {
181 foreach ($this->getInfo(
'sub') as $submenu) {
183 'name' => $submenu[
'name'] ,
184 'url' => $submenu[
'url']);
193 function loadAdminMenu()
195 if ($this->getInfo(
'adminmenu') && $this->getInfo(
'adminmenu') !=
'' && file_exists(XOOPS_ROOT_PATH .
'/modules/' . $this->getVar(
'dirname') .
'/' . $this->getInfo(
'adminmenu'))) {
196 $adminmenu = array();
197 include XOOPS_ROOT_PATH .
'/modules/' . $this->getVar(
'dirname') .
'/' . $this->getInfo(
'adminmenu');
207 function &getAdminMenu()
209 if (!isset($this->adminmenu)) {
210 $this->loadAdminMenu();
225 if (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' .
$dirname .
'/language/' . $xoopsConfig[
'language'] .
'/modinfo.php'))) {
227 }
else if (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' .
$dirname .
'/language/english/modinfo.php'))) {
232 if (
false != $verbose) {
233 echo
"Module File for $dirname Not Found!";
252 function search($term =
'',
$andor =
'AND',
$limit = 0, $offset = 0, $userid = 0)
254 if ($this->getVar(
'hassearch') != 1) {
257 $search =& $this->getInfo(
'search');
258 if ($this->getVar(
'hassearch') != 1 || ! isset($search[
'file']) || ! isset($search[
'func']) || $search[
'func'] ==
'' || $search[
'file'] ==
'') {
261 if (file_exists(
$file =
$GLOBALS[
'xoops']->path(
'modules/' . $this->getVar(
'dirname') .
'/' . $search[
'file']))) {
266 if (function_exists($search[
'func'])) {
267 $func = $search[
'func'];
276 function id($format =
'N')
278 return $this->getVar(
'mid', $format);
284 function mid($format =
'')
286 return $this->getVar(
'mid', $format);
292 function name($format =
'')
294 return $this->getVar(
'name', $format);
300 function version($format =
'')
302 return $this->getVar(
'version', $format);
308 function last_update($format =
'')
310 return $this->getVar(
'last_update', $format);
316 function weight($format =
'')
318 return $this->getVar(
'weight', $format);
324 function isactive($format =
'')
326 return $this->getVar(
'isactive', $format);
332 function dirname($format =
'')
334 return $this->getVar(
'dirname', $format);
340 function hasmain($format =
'')
342 return $this->getVar(
'hasmain', $format);
348 function hasadmin($format =
'')
350 return $this->getVar(
'hasadmin', $format);
356 function hassearch($format =
'')
358 return $this->getVar(
'hassearch', $format);
364 function hasconfig($format =
'')
366 return $this->getVar(
'hasconfig', $format);
372 function hascomments($format =
'')
374 return $this->getVar(
'hascomments', $format);
380 function hasnotification($format =
'')
382 return $this->getVar(
'hasnotification', $format);
388 $inst =& $modhandler->getByDirname(
$dirname);
392 ##################### Deprecated Methods ######################
397 function checkAccess()
399 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
403 function loadLanguage(
$type =
"main")
405 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
409 function loadErrorMessages()
411 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
415 function getCurrentPage()
417 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
421 function install($admingroups = array(), $accessgroups = array())
423 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
429 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
435 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
439 function executeSQL()
441 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
445 function insertTemplates()
447 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
451 function gettemplate($template, $block =
false)
453 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
457 function insertBlocks()
459 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
463 function insertConfigCategories()
465 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
469 function insertConfig()
471 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
475 function insertProfileFields()
477 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
481 function executeScript(
$type, $state = 2)
483 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
489 trigger_error(__CLASS__ .
"::" . __FUNCTION__ .
' is deprecated', E_USER_WARNING);
554 $sql =
'SELECT * FROM ' . $this->db->prefix(
'modules') .
' WHERE mid = ' . $id;
558 $numrows = $this->db->getRowsNum(
$result);
561 $myrow = $this->db->fetchArray(
$result);
582 if (strpos(strtolower(
$dirname),
' union ')) {
591 $sql =
"SELECT * FROM " . $this->db->prefix(
'modules') .
" WHERE dirname = '" . trim($dirname) .
"'";
595 $numrows = $this->db->getRowsNum(
$result);
598 $myrow = $this->db->fetchArray(
$result);
619 if (!is_a(
$module,
'xoopsmodule')) {
628 foreach (
$module->cleanVars as $k => $v) {
632 $mid = $this->db->genId(
'modules_mid_seq');
633 $sql = sprintf(
"INSERT INTO %s (mid, name, version, last_update, weight, isactive, dirname, hasmain, hasadmin, hassearch, hasconfig, hascomments, hasnotification) VALUES (%u, %s, %u, %u, %u, %u, %s, %u, %u, %u, %u, %u, %u)", $this->db->prefix(
'modules'),
$mid, $this->db->quoteString($name), $version, time(), $weight, 1, $this->db->quoteString(
$dirname), $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification);
635 $sql = sprintf(
"UPDATE %s SET name = %s, dirname = %s, version = %u, last_update = %u, weight = %u, isactive = %u, hasmain = %u, hasadmin = %u, hassearch = %u, hasconfig = %u, hascomments = %u, hasnotification = %u WHERE mid = %u", $this->db->prefix(
'modules'), $this->db->quoteString($name), $this->db->quoteString(
$dirname), $version, time(), $weight, $isactive, $hasmain, $hasadmin, $hassearch, $hasconfig, $hascomments, $hasnotification,
$mid);
641 $mid = $this->db->getInsertId();
644 if (!empty($this->_cachedModule_dirname[
$dirname])) {
645 unset($this->_cachedModule_dirname[$dirname]);
647 if (!empty($this->_cachedModule_mid[
$mid])) {
648 unset($this->_cachedModule_mid[$mid]);
665 if (!is_a(
$module,
'xoopsmodule')) {
668 $sql = sprintf(
"DELETE FROM %s WHERE mid = %u", $this->db->prefix(
'modules'),
$module->getVar(
'mid'));
673 $sql = sprintf(
"DELETE FROM %s WHERE gperm_name = 'module_admin' AND gperm_itemid = %u", $this->db->prefix(
'group_permission'),
$module->getVar(
'mid'));
674 $this->db->query(
$sql);
676 $sql = sprintf(
"DELETE FROM %s WHERE gperm_name = 'module_read' AND gperm_itemid = %u", $this->db->prefix(
'group_permission'),
$module->getVar(
'mid'));
677 $this->db->query(
$sql);
679 $sql = sprintf(
"SELECT block_id FROM %s WHERE module_id = %u", $this->db->prefix(
'block_module_link'),
$module->getVar(
'mid'));
681 $block_id_arr = array();
682 while ($myrow = $this->db->fetchArray(
$result)) {
683 array_push($block_id_arr, $myrow[
'block_id']);
687 if (isset($block_id_arr)) {
688 foreach ($block_id_arr as
$i) {
689 $sql = sprintf(
"SELECT block_id FROM %s WHERE module_id != %u AND block_id = %u", $this->db->prefix(
'block_module_link'),
$module->getVar(
'mid'),
$i);
690 if ($result2 = $this->db->query(
$sql)) {
691 if (0 < $this->db->getRowsNum($result2)) {
693 $sql = sprintf(
"DELETE FROM %s WHERE (module_id = %u) AND (block_id = %u)", $this->db->prefix(
'block_module_link'),
$module->getVar(
'mid'),
$i);
694 $this->db->query(
$sql);
697 $sql = sprintf(
"UPDATE %s SET visible = 0 WHERE bid = %u", $this->db->prefix(
'newblocks'),
$i);
698 $this->db->query(
$sql);
699 $sql = sprintf(
"UPDATE %s SET module_id = -1 WHERE module_id = %u", $this->db->prefix(
'block_module_link'),
$module->getVar(
'mid'));
700 $this->db->query(
$sql);
706 if (!empty($this->_cachedModule_dirname[
$module->getVar(
'dirname')])) {
707 unset($this->_cachedModule_dirname[
$module->getVar(
'dirname')]);
709 if (!empty($this->_cachedModule_mid[
$module->getVar(
'mid')])) {
710 unset($this->_cachedModule_mid[
$module->getVar(
'mid')]);
726 $sql =
'SELECT * FROM ' . $this->db->prefix(
'modules');
729 $sql .=
' ORDER BY weight ' .
$criteria->getOrder() .
', mid ASC';
737 while ($myrow = $this->db->fetchArray(
$result)) {
758 $sql =
'SELECT COUNT(*) FROM ' . $this->db->prefix(
'modules');
765 list ($count) = $this->db->fetchRow(
$result);
781 foreach (array_keys($modules) as
$i) {
782 if (!$dirname_as_key) {
783 $ret[
$i] = $modules[
$i]->getVar(
'name');
785 $ret[$modules[
$i]->getVar(
'dirname')] = $modules[
$i]->getVar(
'name');