function queryFromFile($sql_file_path) { $tables = array(); if (!file_exists($sql_file_path)) { return false; } $sql_query = trim(fread(fopen($sql_file_path, 'r'), filesize($sql_file_path))); SqlUtility::splitMySqlFile($pieces, $sql_query); $this->db->connect(); foreach ($pieces as $piece) { $piece = trim($piece); // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $this->db->prefix()); if ($prefixed_query != false) { $table = $this->db->prefix($prefixed_query[4]); if ($prefixed_query[1] == 'CREATE TABLE') { if ($this->db->query($prefixed_query[0]) != false) { if (!isset($this->s_tables['create'][$table])) { $this->s_tables['create'][$table] = 1; } } else { if (!isset($this->f_tables['create'][$table])) { $this->f_tables['create'][$table] = 1; } } } elseif ($prefixed_query[1] == 'INSERT INTO') { if ($this->db->query($prefixed_query[0]) != false) { if (!isset($this->s_tables['insert'][$table])) { $this->s_tables['insert'][$table] = 1; } else { $this->s_tables['insert'][$table]++; } } else { if (!isset($this->f_tables['insert'][$table])) { $this->f_tables['insert'][$table] = 1; } else { $this->f_tables['insert'][$table]++; } } } elseif ($prefixed_query[1] == 'ALTER TABLE') { if ($this->db->query($prefixed_query[0]) != false) { if (!isset($this->s_tables['alter'][$table])) { $this->s_tables['alter'][$table] = 1; } } else { if (!isset($this->s_tables['alter'][$table])) { $this->f_tables['alter'][$table] = 1; } } } elseif ($prefixed_query[1] == 'DROP TABLE') { if ($this->db->query('DROP TABLE ' . $table) != false) { if (!isset($this->s_tables['drop'][$table])) { $this->s_tables['drop'][$table] = 1; } } else { if (!isset($this->s_tables['drop'][$table])) { $this->f_tables['drop'][$table] = 1; } } } } } return true; }
/** * perform queries from SQL dump file in a batch * * @param string $file file path to an SQL dump file * * @return bool FALSE if failed reading SQL file or * TRUE if the file has been read and queries executed */ public function queryFromFile($file) { if (false !== ($fp = fopen($file, 'r'))) { $sql_queries = trim(fread($fp, filesize($file))); \SqlUtility::splitMySqlFile($pieces, $sql_queries); foreach ($pieces as $query) { $prefixed_query = \SqlUtility::prefixQuery(trim($query), $this->prefix()); if ($prefixed_query != false) { $this->query($prefixed_query[0]); } } return true; } return false; }
function bulletin_oninstall_base($module, $mydirname) { // transations on module install global $ret; $db =& Database::getInstance(); $mid = $module->getVar('mid'); // for Cube 2.1 if (defined('XOOPS_CUBE_LEGACY')) { $isCube = true; $root =& XCube_Root::getSingleton(); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'bulletin_message_append_oninstall'); $ret = array(); } else { $isCube = false; if (!is_array($ret)) { $ret = array(); } } // transations on module installation $bulletin_posting_permissions = array(1, 2, 3, 7); $gperm_handler = xoops_gethandler('groupperm'); foreach ($bulletin_posting_permissions as $itemid) { $gperm =& $gperm_handler->create(); $gperm->setVar('gperm_groupid', 1); $gperm->setVar('gperm_name', 'bulletin_permit'); $gperm->setVar('gperm_modid', $mid); $gperm->setVar('gperm_itemid', $itemid); $gperm_handler->insert($gperm); } // TABLES (loading mysql.sql) $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql'; $prefix_mod = $db->prefix() . '_' . $mydirname; if (file_exists($sql_file_path)) { $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables...<br />"; if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) { include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php'; $sqlutil = new OldSqlUtility(); } else { include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sqlutil = new SqlUtility(); } $sql_query = trim(file_get_contents($sql_file_path)); $sqlutil->splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod); if (!$prefixed_query) { $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />"; return false; } if (!$db->query($prefixed_query[0])) { $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />'; var_dump($db->error()); return false; } else { if (!in_array($prefixed_query[4], $created_tables)) { $ret[] = ' Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />'; $created_tables[] = $prefixed_query[4]; } else { $ret[] = ' Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />'; } } } } // TEMPLATES $tplfile_handler =& xoops_gethandler('tplfile'); $tpl_path = dirname(__FILE__) . '/templates'; if ($handler = @opendir($tpl_path . '/')) { while (($file = readdir($handler)) !== false) { if (substr($file, 0, 1) == '.') { continue; } $file_path = $tpl_path . '/' . $file; if (is_file($file_path) && substr($file, -5) == '.html') { $mtime = intval(@filemtime($file_path)); $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_source', file_get_contents($file_path), true); $tplfile->setVar('tpl_refid', $mid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $mydirname . '_' . $file); $tplfile->setVar('tpl_desc', '', true); $tplfile->setVar('tpl_module', $mydirname); $tplfile->setVar('tpl_lastmodified', $mtime); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />'; } else { $tplid = $tplfile->getVar('tpl_id'); $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($tplid)) { $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />'; } else { $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />'; } } } } closedir($handler); } include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($mid); // BLOCKS $tpl_path = dirname(__FILE__) . '/templates/blocks'; if ($handler = @opendir($tpl_path . '/')) { while (($file = readdir($handler)) !== false) { if (substr($file, 0, 1) == '.') { continue; } $file_path = $tpl_path . '/' . $file; if (is_file($file_path) && substr($file, -5) == '.html') { $mtime = intval(@filemtime($file_path)); $tpl_file = $mydirname . '_' . $file; $sql = "SELECT tpl_id FROM " . $db->prefix('tplfile') . " WHERE tpl_module='{$mydirname}' AND tpl_file='" . mysql_escape_string($tpl_file) . "'"; list($tpl_id) = $db->fetchRow($db->query($sql)); $tpl_source = file_get_contents($file_path); if (!empty($tpl_id) && isset($tpl_source) && $tpl_source != '') { $sql = sprintf("INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)", $db->prefix('tplsource'), $tpl_id, $db->quoteString($tpl_source)); if (!($result = $db->query($sql))) { $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />'; } else { $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tpl_id . '</b>)<br />'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($tpl_id)) { $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />'; } else { $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />'; } } } } } closedir($handler); } return true; }
function xoops_module_install($dirname) { global $xoopsUser, $xoopsConfig; $dirname = trim($dirname); $db =& Database::getInstance(); $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); $module_handler =& xoops_gethandler('module'); if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) { $module =& $module_handler->create(); $module->loadInfoAsVar($dirname); $module->setVar('weight', 1); $error = false; $errs = array(); $sqlfile =& $module->getInfo('sqlfile'); $msgs = array(); $msgs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>'; if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') { $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />'; } $msgs[] = '<b>Version:</b> ' . $module->getInfo('version'); if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') { $msgs[] = '<b>Author:</b> ' . trim($module->getInfo('author')); } $msgs[] = ''; $errs[] = '<h4 style="text-align:left;margin-bottom: 0px;border-bottom: dashed 1px #000000;">Installing ' . $module->getInfo('name') . '</h4>'; if ($sqlfile != false && is_array($sqlfile)) { $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE]; if (!file_exists($sql_file_path)) { $errs[] = "SQL file not found at <b>{$sql_file_path}</b>"; $error = true; } else { $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br /> Creating tables..."; include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $errs[] = "<b>{$piece}</b> is not a valid SQL!"; $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $errs[] = $db->error(); $error = true; break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $msgs[] = ' Table <b>' . $db->prefix($prefixed_query[4]) . '</b> created.'; $created_tables[] = $prefixed_query[4]; } else { $msgs[] = ' Data inserted to table <b>' . $db->prefix($prefixed_query[4]) . '</b>.'; } } } else { // the table name is reserved, so halt the installation $errs[] = '<b>' . $prefixed_query[4] . "</b> is a reserved table!"; $error = true; break; } } // if there was an error, delete the tables created so far, so the next installation will not fail if ($error == true) { foreach ($created_tables as $ct) { //echo $ct; $db->query("DROP TABLE " . $db->prefix($ct)); } } } } // if no error, save the module info and blocks info associated with it if ($error == false) { if (!$module_handler->insert($module)) { $errs[] = 'Could not insert <b>' . $module->getVar('name') . '</b> to database.'; foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $module->name() . "</b>") . " " . _MD_AM_ERRORSC . "<br />"; foreach ($errs as $err) { $ret .= " - " . $err . "<br />"; } $ret .= "</p>"; unset($module); unset($created_tables); unset($errs); unset($msgs); return $ret; } else { $newmid = $module->getVar('mid'); unset($created_tables); $msgs[] = 'Module data inserted successfully. Module ID: <b>' . $newmid . '</b>'; $tplfile_handler =& xoops_gethandler('tplfile'); $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = 'Adding templates...'; foreach ($templates as $tpl) { $tplfile =& $tplfile_handler->create(); $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file']); $tplfile->setVar('tpl_desc', $tpl['description'], true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>' . $tpl['file'] . '</b> to the database.</span>'; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = ' Template <b>' . $tpl['file'] . '</b> added to the database. (ID: <b>' . $newtplid . '</b>)'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $tpl['file'] . '</b>.</span>'; } else { $msgs[] = ' Template <b>' . $tpl['file'] . '</b> compiled.</span>'; } } unset($tpldata); } } include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($newmid); $blocks = $module->getInfo('blocks'); if ($blocks != false) { $msgs[] = 'Adding blocks...'; foreach ($blocks as $blockkey => $block) { // break the loop if missing block config if (!isset($block['file']) || !isset($block['show_func'])) { break; } $options = ''; if (!empty($block['options'])) { $options = trim($block['options']); } $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq'); $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : ''; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content =& xoops_module_gettemplate($dirname, $block['template'], true); } if (!isset($content)) { $content = ''; } else { $template = trim($block['template']); } $block_name = addslashes(trim($block['name'])); $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ({$newbid}, {$newmid}, " . intval($blockkey) . ", '{$options}', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ")"; if (!$db->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block <b>' . $block['name'] . '</b> to the database! Database error: <b>' . $db->error() . '</b></span>'; } else { if (empty($newbid)) { $newbid = $db->getInsertId(); } $msgs[] = ' Block <b>' . $block['name'] . '</b> added. Block ID: <b>' . $newbid . '</b>'; $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $db->query($sql); if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template']); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_desc', $block['description'], true); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>' . $block['template'] . '</b> to the database.</span>'; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = ' Template <b>' . $block['template'] . '</b> added to the database. (ID: <b>' . $newtplid . '</b>)'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Failed compiling template <b>' . $block['template'] . '</b>.</span>'; } else { $msgs[] = ' Template <b>' . $block['template'] . '</b> compiled.</span>'; } } } } unset($content); } unset($blocks); } $configs = $module->getInfo('config'); if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event-specific notification options // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; } } $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = 'Adding module config data...'; $config_handler =& xoops_gethandler('config'); $order = 0; foreach ($configs as $config) { $confobj =& $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); $confobj->setConfValueForInput($config['default'], true); //$confobj->setVar('conf_value', $config['default'], true); $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>'; unset($confop); } } $order++; if ($config_handler->insertConfig($confobj) != false) { $msgs[] = ' Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>'; } unset($confobj); } unset($configs); } } $groups = $xoopsUser->getGroups(); // retrieve all block ids for this module $blocks =& XoopsBlock::getByModule($newmid, false); $msgs[] = 'Setting group rights...'; $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add admin access right for Group ID <b>' . $mygroup . '</b></span>'; } else { $msgs[] = ' Added admin access right for Group ID <b>' . $mygroup . '</b>'; } unset($mperm); } $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add user access right for Group ID: <b>' . $mygroup . '</b></span>'; } else { $msgs[] = ' Added user access right for Group ID: <b>' . $mygroup . '</b>'; } unset($mperm); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . $blc . '</b> Group ID: <b>' . $mygroup . '</b></span>'; } else { $msgs[] = ' Added block access right. Block ID: <b>' . $blc . '</b> Group ID: <b>' . $mygroup . '</b>'; } unset($bperm); } } unset($blocks); unset($groups); // execute module specific install script if any $install_script = $module->getInfo('onInstall'); if (false != $install_script && trim($install_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script); if (function_exists('xoops_module_install_' . $dirname)) { $func = 'xoops_module_install_' . $dirname; if (!$func($module)) { $msgs[] = 'Failed to execute ' . $func; } else { $msgs[] = '<b>' . $func . '</b> executed successfully.'; } } } $ret = '<p><code>'; foreach ($msgs as $m) { $ret .= $m . '<br />'; } unset($msgs); unset($errs); $ret .= '</code><br />' . sprintf(_MD_AM_OKINS, "<b>" . $module->getVar('name') . "</b>") . '</p>'; unset($module); return $ret; } else { $ret = '<p>'; foreach ($errs as $er) { $ret .= ' ' . $er . '<br />'; } unset($msgs); unset($errs); $ret .= '<br />' . sprintf(_MD_AM_FAILINS, '<b>' . $dirname . '</b>') . ' ' . _MD_AM_ERRORSC . '</p>'; return $ret; } } else { return "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $dirname . "</b>") . " " . _MD_AM_ERRORSC . "<br /> " . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>"; } }
/** * Execute module's SQL file - if any * * @return bool */ function executeSQL() { $error = false; $sqlfile =& $this->getInfo('sqlfile'); if ($sqlfile != false && is_array($sqlfile)) { $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $this->getVar('dirname') . "/" . $sqlfile[XOOPS_DB_TYPE]; if (!file_exists($sql_file_path)) { $this->setErrors("SQL file not found at <b>{$sql_file_path}</b>"); $error = true; } else { $this->setMessage("SQL file found at <b>{$sql_file_path}</b>.<br /> Creating tables..."); include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $GLOBALS['xoopsDB']->prefix()); if (!$prefixed_query) { $this->setErrors("<b>{$piece}</b> is not a valid SQL!"); $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$GLOBALS['xoopsDB']->query($prefixed_query[0])) { $this->setErrors($GLOBALS['xoopsDB']->error()); $error = true; break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $this->setMessage(' Table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b> created.'); $created_tables[] = $prefixed_query[4]; } else { $this->setMessage(' Data inserted to table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b>.'); } } } else { // the table name is reserved, so halt the installation $this->setErrors('<b>' . $prefixed_query[4] . "</b> is a reserved table!"); $error = true; break; } } // if there was an error, delete the tables created so far, so the next installation will not fail if ($error == true) { foreach ($created_tables as $ct) { //echo $ct; $GLOBALS['xoopsDB']->query("DROP TABLE " . $GLOBALS['xoopsDB']->prefix($ct)); } } } } return $error; }
/** * Executes SQL file which xoops_version of $module specifies. This * function is usefull for installers, but it's impossible to control * for detail. * * @static * @param XoopsModule $module * @param Legacy_ModuleInstallLog $log * @note FOR THE CUSTOM-INSTALLER */ function installSQLAutomatically(&$module, &$log) { $sqlfileInfo =& $module->getInfo('sqlfile'); $dirname = $module->getVar('dirname'); if (!isset($sqlfileInfo[XOOPS_DB_TYPE])) { return; } $sqlfile = $sqlfileInfo[XOOPS_DB_TYPE]; $sqlfilepath = XOOPS_MODULE_PATH . "/{$dirname}/{$sqlfile}"; if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) { require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php"; $scanner = new Legacy_SQLScanner(); $scanner->setDB_PREFIX(XOOPS_DB_PREFIX); $scanner->setDirname($module->get('dirname')); if (!$scanner->loadFile($sqlfilepath)) { $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile)); return false; } $scanner->parse(); $sqls = $scanner->getSQL(); $root =& XCube_Root::getSingleton(); $db =& $root->mController->getDB(); // // TODO The following variable exists for rollback, but it is not implemented. // foreach ($sqls as $sql) { if (!$db->query($sql)) { $log->addError($db->error()); return; } } $log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED); } else { require_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications'); $root =& XCube_Root::getSingleton(); $db =& $root->mController->mDB; $sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $log->addError("{$piece} is not a valid SQL!"); return; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $log->addError($db->error()); return; } else { if (!in_array($prefixed_query[4], $created_tables)) { $log->addReport(' Table ' . $db->prefix($prefixed_query[4]) . ' created.'); $created_tables[] = $prefixed_query[4]; } else { $log->addReport(' Data inserted to table ' . $db->prefix($prefixed_query[4])); } } } else { // the table name is reserved, so halt the installation $log->addError($prefixed_query[4] . " is a reserved table!"); return; } } } }
function xoops_module_install($dirname) { global $xoopsUser, $xoopsConfig; $dirname = trim($dirname); $db =& $GLOBALS["xoopsDB"]; $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); $module_handler =& xoops_gethandler('module'); if ($module_handler->getCount(new Criteria('dirname', $dirname)) == 0) { $module =& $module_handler->create(); $module->loadInfoAsVar($dirname); $module->setVar('weight', 1); $error = false; $errs = array(); $msgs = array(); $msgs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>'; if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') { $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" />'; } $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version'); if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') { $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . trim($module->getInfo('author')); } $msgs[] = ''; $errs[] = '<h4 style="margin-bottom: 0px;border-bottom: dashed 1px #000000;">' . _MD_AM_INSTALLING . $module->getInfo('name') . '</h4>'; // Load module specific install script if any $install_script = $module->getInfo('onInstall'); if ($install_script && trim($install_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($install_script); } $func = "xoops_module_pre_install_{$dirname}"; // If pre install function is defined, execute if (function_exists($func)) { $result = $func($module); if (!$result) { $error = true; $errs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>"; $errs = array_merge($errs, $module->getErrors()); } else { $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>"; $msgs += $module->getErrors(); } } if ($error == false) { $sqlfile = $module->getInfo('sqlfile'); if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) { $sql_file_path = XOOPS_ROOT_PATH . "/modules/" . $dirname . "/" . $sqlfile[XOOPS_DB_TYPE]; if (!file_exists($sql_file_path)) { $errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>"); $error = true; } else { $msgs[] = "<p>" . sprintf(_MD_AM_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . "<br />" . _MD_AM_CREATE_TABLES; include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $errs[] = "<p>" . sprintf(_MD_AM_SQL_NOT_VALID, "<strong>" . $piece . "</strong>"); $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $errs[] = $db->error(); $error = true; break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $msgs[] = " " . sprintf(_MD_AM_TABLE_CREATED, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>"); $created_tables[] = $prefixed_query[4]; } else { $msgs[] = " " . sprintf(_MD_AM_INSERT_DATA, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>"); } } } else { // the table name is reserved, so halt the installation $errs[] = " " . sprintf(_MD_AM_TABLE_RESERVED, "<strong>" . $prefixed_query[4] . "</strong>"); $error = true; break; } } // if there was an error, delete the tables created so far, so the next installation will not fail if ($error == true) { foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } } } } } // if no error, save the module info and blocks info associated with it if ($error == false) { if (!$module_handler->insert($module)) { $errs[] = "<p>" . sprintf(_MD_AM_INSERT_DATA_FAILD, "<strong>" . $module->getVar('name') . "</strong>"); foreach ($created_tables as $ct) { $db->query("DROP TABLE " . $db->prefix($ct)); } $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<strong>" . $module->name() . "</strong>") . " " . _MD_AM_ERRORSC . "<br />"; foreach ($errs as $err) { $ret .= " - " . $err . "<br />"; } $ret .= "</p>"; unset($module); unset($created_tables); unset($errs); unset($msgs); return $ret; } else { $newmid = $module->getVar('mid'); unset($created_tables); $msgs[] = "<p>" . _MD_AM_INSERT_DATA_DONE . sprintf(_MD_AM_MODULEID, "<strong>" . $newmid . "</strong>"); $tplfile_handler =& xoops_gethandler('tplfile'); $templates = $module->getInfo('templates'); if ($templates != false) { $msgs[] = _MD_AM_TEMPLATES_ADD; foreach ($templates as $tpl) { $tplfile =& $tplfile_handler->create(); $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']); $tplfile->setVar('tpl_source', $tpldata, true); $tplfile->setVar('tpl_refid', $newmid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $tpl['file']); $tplfile->setVar('tpl_desc', $tpl['description'], true); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_ADD_ERROR, "<strong>" . $tpl['file'] . "</strong>") . "</span>"; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_ADD_DATA, "<strong>" . $tpl['file'] . "</strong>") . "(ID: <strong>" . $newtplid . "</strong>)"; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_COMPILED_FAILED, "<strong>" . $tpl['file'] . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_COMPILED, "<strong>" . $tpl['file'] . "</strong>"); } } unset($tplfile, $tpldata); } } include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($newmid); $blocks = $module->getInfo('blocks'); if ($blocks != false) { $msgs[] = _MD_AM_BLOCKS_ADD; foreach ($blocks as $blockkey => $block) { // break the loop if missing block config if (!isset($block['file']) || !isset($block['show_func'])) { break; } $options = ''; if (!empty($block['options'])) { $options = trim($block['options']); } $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq'); $edit_func = isset($block['edit_func']) ? trim($block['edit_func']) : ''; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content =& xoops_module_gettemplate($dirname, $block['template'], true); } if (empty($content)) { $content = ''; } else { $template = trim($block['template']); } $block_name = addslashes(trim($block['name'])); $sql = "INSERT INTO " . $db->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ({$newbid}, {$newmid}, " . intval($blockkey) . ", '{$options}', '" . $block_name . "','" . $block_name . "', '', 0, 0, 0, 'M', 'H', 1, '" . addslashes($dirname) . "', '" . addslashes(trim($block['file'])) . "', '" . addslashes(trim($block['show_func'])) . "', '" . addslashes($edit_func) . "', '" . $template . "', 0, " . time() . ")"; if (!$db->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_BLOCK_ADD_ERROR, "<strong>" . $block['name'] . "</strong>") . sprintf(_MD_AM_BLOCK_ADD_ERROR_DATABASE, "<strong>" . $db->error() . "</strong>") . "</span>"; } else { if (empty($newbid)) { $newbid = $db->getInsertId(); } $msgs[] = " " . sprintf(_MD_AM_BLOCK_ADD, "<strong>" . $block['name'] . "</strong>") . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $newbid . "</strong>"); $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $db->query($sql); if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template']); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_desc', $block['description'], true); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_ADD_ERROR, "<strong>" . $block['template'] . "</strong>") . "</span>"; } else { $newtplid = $tplfile->getVar('tpl_id'); $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_ADD_DATA, "<strong>" . $block['template'] . "</strong>") . " (ID: <strong>" . $newtplid . "</strong>)"; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($newtplid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_TEMPLATE_COMPILED_FAILED, "<strong>" . $block['template'] . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_TEMPLATE_COMPILED, "<strong>" . $block['template'] . "</strong>"); } } unset($tplfile); } } unset($content); } unset($blocks); } $configs = $module->getInfo('config'); if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event-specific notification options // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; } unset($events); } unset($categories); $configs[] = array('name' => 'notification_events', 'title' => '_NOT_CONFIG_EVENTS', 'description' => '_NOT_CONFIG_EVENTSDSC', 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($options), 'options' => $options); } if ($configs != false) { $msgs[] = _MD_AM_MODULE_DATA_ADD; $config_handler =& xoops_gethandler('config'); $order = 0; foreach ($configs as $config) { $confobj =& $config_handler->createConfig(); $confobj->setVar('conf_modid', $newmid); $confobj->setVar('conf_catid', 0); $confobj->setVar('conf_name', $config['name']); $confobj->setVar('conf_title', $config['title'], true); $confobj->setVar('conf_desc', $config['description'], true); $confobj->setVar('conf_formtype', $config['formtype']); $confobj->setVar('conf_valuetype', $config['valuetype']); $confobj->setConfValueForInput($config['default'], true); $confobj->setVar('conf_order', $order); $confop_msgs = ''; if (isset($config['options']) && is_array($config['options'])) { foreach ($config['options'] as $key => $value) { $confop =& $config_handler->createConfigOption(); $confop->setVar('confop_name', $key, true); $confop->setVar('confop_value', $value, true); $confobj->setConfOptions($confop); $confop_msgs .= '<br /> ' . _MD_AM_CONFIG_ADD . _MD_AM_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _MD_AM_VALUE . ' <strong>' . $value . '</strong> '; unset($confop); } } $order++; if ($config_handler->insertConfig($confobj) != false) { $msgs[] = ' ' . sprintf(_MD_AM_CONFIG_DATA_ADD, "<strong>" . $config['name'] . "</strong>") . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_CONFIG_DATA_ADD_ERROR, "<strong>" . $config['name'] . "</strong>") . "</span>"; } unset($confobj); } unset($configs); } } if ($module->getInfo('hasMain')) { $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); } else { $groups = array(XOOPS_GROUP_ADMIN); } // retrieve all block ids for this module $blocks = XoopsBlock::getByModule($newmid, false); $msgs[] = _MD_AM_GROUP_SETTINGS_ADD; $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_ADMIN_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_ACCESS_ADMIN_ADD, "<strong>" . $mygroup . "</strong>"); } unset($mperm); } $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>"; } else { $msgs[] = ' ' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>"); } unset($mperm); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">' . _MD_AM_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>'; } else { $msgs[] = ' ' . _MD_AM_BLOCK_ACCESS . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(_MD_AM_GROUP_ID, "<strong>" . $mygroup . "</strong>"); } unset($bperm); } } unset($blocks); unset($groups); // execute module specific install script if any $func = "xoops_module_install_{$dirname}"; if (function_exists($func)) { if (!($lastmsg = $func($module))) { $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_EXECUTE, $func) . "</p>"; } else { $msgs[] = "<p>" . sprintf(_MD_AM_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>"; if (is_string($lastmsg)) { $msgs[] = $lastmsg; } } } $ret = '<div>' . implode("<br />", $msgs) . '</div><br />' . sprintf(_MD_AM_OKINS, "<strong>" . $module->getVar('name') . "</strong>"); unset($msgs); unset($errs); unset($module); return $ret; } else { $ret = '<p>' . sprintf(_MD_AM_FAILINS, '<strong>' . $dirname . '</strong>') . ' ' . _MD_AM_ERRORSC . '<br />' . implode("<br />", $errs) . '</p>'; unset($msgs); unset($errs); return $ret; } } else { return "<p>" . sprintf(_MD_AM_FAILINS, "<strong>" . $dirname . "</strong>") . " " . _MD_AM_ERRORSC . "<br /> " . sprintf(_MD_AM_ALEXISTS, $dirname) . "</p>"; } }
function xpwiki_oninstall_base($module, $mydirname) { // transations on module install global $ret; // TODO :-D // for Cube 2.1 if (defined('XOOPS_CUBE_LEGACY')) { $root =& XCube_Root::getSingleton(); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'xpwiki_message_append_oninstall'); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail', 'xpwiki_message_append_oninstall'); $ret = array(); } else { if (!is_array($ret)) { $ret = array(); } } $db =& Database::getInstance(); $mid = $module->getVar('mid'); // TABLES (loading mysql.sql) $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql'; $prefix_mod = $db->prefix() . '_' . $mydirname; if (file_exists($sql_file_path)) { $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path, ENT_COMPAT, _CHARSET) . "</b>.<br /> Creating tables..."; if (is_file(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) { include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php'; $sqlutil = new OldSqlUtility(); } else { include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sqlutil = new SqlUtility(); } $sql_query = trim(file_get_contents($sql_file_path)); // [ MySQL Version >= 5 ] BLOB and TEXT columns cannot be assigned a default value. if (is_object($db->conn) && get_class($db->conn) === 'mysqli') { $mysql_ver = mysqli_get_server_info($db->conn); } else { $mysql_ver = mysql_get_server_info(); } if (@$mysql_ver[0] >= 5) { $sql_query = str_replace(' default \'\'', '', $sql_query); } // [ MySQL Version >= 4 ] ENGINE is the preferred term from MySQL 4.0.18 on and TYPE is deprecated. if (@$mysql_ver[0] >= 4) { $sql_query = str_replace(' TYPE=MyISAM', ' ENGINE=MyISAM', $sql_query); } $sqlutil->splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod); if (!$prefixed_query) { $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece, ENT_COMPAT, _CHARSET) . "</b><br />"; return false; } if (!$db->query($prefixed_query[0])) { $ret[] = '<b>' . htmlspecialchars($db->error(), ENT_COMPAT, _CHARSET) . '</b><br />'; //var_dump( $db->error() ) ; return false; } else { if (!in_array($prefixed_query[4], $created_tables)) { $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b> created.<br />'; $created_tables[] = $prefixed_query[4]; } else { $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b>.</br />'; } } } } // TEMPLATES $tplfile_handler =& xoops_gethandler('tplfile'); $tpl_path = dirname(__FILE__) . '/templates'; if ($handler = @opendir($tpl_path . '/')) { while (($file = readdir($handler)) !== false) { if (substr($file, 0, 1) == '.') { continue; } $file_path = $tpl_path . '/' . $file; if (is_file($file_path) && substr($file, -5) == '.html') { $mtime = intval(@filemtime($file_path)); $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_source', file_get_contents($file_path), true); $tplfile->setVar('tpl_refid', $mid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $mydirname . '_' . $file); $tplfile->setVar('tpl_desc', '', true); $tplfile->setVar('tpl_module', $mydirname); $tplfile->setVar('tpl_lastmodified', $mtime); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> to the database.</span><br />'; } else { $tplid = $tplfile->getVar('tpl_id'); $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($tplid)) { $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b>.</span><br />'; } else { $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> compiled.</span><br />'; } } } } closedir($handler); } include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($mid); // xpWiki original functions include_once dirname(__FILE__) . '/include/check.func.php'; $_ret = xpwikifunc_permission_check($mydirname); if (!$_ret) { $ret = array_merge($ret, xpwikifunc_defdata_check($mydirname)); } else { $GLOBALS['XpWikiMsg'] = $_ret; $ret = array_merge($ret, $_ret); return false; } return true; }
/** * @split $sqls to individual queries, add prefix to table, and query sqls * output some informations to stdout. * * @param string $sqls string of sqls. * @return boolean true if succeed * */ function xoonips_sql_queries($sqls) { global $xoopsDB; $textutil =& xoonips_getutility('text'); $pieces = array(); SqlUtility::splitMySqlFile($pieces, $sqls); $created_tables = array(); $errs = array(); $msgs = array(); $error = false; $ret = ''; foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $xoopsDB->prefix()); if (!$prefixed_query) { $errs[] = '<b>' . $piece . '</b> is not a valid SQL!'; $error = true; break; } if (!$xoopsDB->query($prefixed_query[0])) { $errs[] = $xoopsDB->error() . ' of SQL ' . $textutil->html_special_chars($prefixed_query[0]); $error = true; break; } if (strncmp('CREATE', strtoupper($prefixed_query[0]), 6) == 0 && !in_array($prefixed_query[4], $created_tables)) { $msgs[] = ' Table <b>' . $xoopsDB->prefix($prefixed_query[4]) . '</b> created.'; $created_tables[] = $prefixed_query[4]; } } if ($error) { // if there was an error, delete the tables created so far, // so the next installation will not fail foreach ($created_tables as $ct) { $xoopsDB->query('DROP TABLE ' . $xoopsDB->prefix($ct)); } // set error messages foreach ($errs as $er) { $ret .= ' ' . $er . '<br />'; } unset($msgs); unset($errs); } echo $ret; return !$error; }
protected function _addTable() { $db =& Database::getInstance(); $sqlFilePath = $this->path . '/sql/mysql.sql'; $prefix = $db->prefix() . '_' . $this->dirname; if (!file_exists($sqlFilePath)) { return; } $this->_addMessage('SQL file found at <b>' . htmlspecialchars($sqlFilePath) . '</b>.<br /> Creating tables...'); if (file_exists($this->root->cms->rootPath . '/class/database/oldsqlutility.php')) { require_once $this->root->cms->rootPath . '/class/database/oldsqlutility.php'; $sqlutil = new OldSqlUtility(); } else { require_once $this->root->cms->rootPath . '/class/database/sqlutility.php'; $sqlutil = new SqlUtility(); } $tables = array(); $createdTables = array(); $sqlQuery = trim(file_get_contents($sqlFilePath)); $sqlutil->splitMySqlFile($tables, $sqlQuery); if (!is_array($tables) or count($tables) === 0) { return; } foreach ($tables as $table) { $prefixedQuery = $sqlutil->prefixQuery($table, $prefix); if (!$prefixedQuery) { $this->_addError('Invalid SQL <b>' . htmlspecialchars($table) . '</b>'); throw new Exception(); } if (!$db->query($prefixedQuery[0])) { $this->_addError('<b>' . htmlspecialchars($db->error()) . '</b>'); throw new Exception(); } if (!in_array($prefixedQuery[4], $createdTables)) { $this->_addMessage('Table <b>' . htmlspecialchars($prefix . '_' . $prefixedQuery[4]) . '</b> created.'); $createdTables[] = $prefixedQuery[4]; } else { $this->_addMessage('Data inserted to table <b>' . htmlspecialchars($prefix . '_' . $prefixedQuery[4]) . '</b>.'); } } }
function xsns_oninstall($module, $mydirname) { global $ret; if( defined( 'XOOPS_CUBE_LEGACY' ) ) { $root =& XCube_Root::getSingleton(); $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success' , 'xsns_message_append_oninstall' ) ; $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Fail' , 'xsns_message_append_oninstall' ) ; $ret = array() ; } else{ if( !is_array($ret) ){ $ret = array() ; } } $constpref = '_MI_'.strtoupper($mydirname); if(strlen($mydirname) > 15){ $ret[] = constant($constpref.'_INSTERR').'<br />'; } $db =& Database::getInstance() ; $mid = $module->getVar('mid') ; // Tables $sql_ver = floatval(substr(mysql_get_server_info(), 0, 3)); if($sql_ver < 4){ $sql_file = 'mysql3.sql'; } elseif($sql_ver == 4.0){ $sql_file = 'mysql40.sql'; } else{ $sql_file = 'mysql.sql'; } $sql_file_path = realpath(dirname(__FILE__).'/sql/'.$sql_file); $prefix_mod = $db->prefix() . '_' . $mydirname ; if( file_exists( $sql_file_path ) ) { $ret[] = "SQL file found at <b>".htmlspecialchars($sql_file_path)."</b>.<br /> Creating tables..."; if( file_exists( XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ) ) { include_once XOOPS_ROOT_PATH.'/class/database/oldsqlutility.php' ; $sqlutil = new OldSqlUtility ; } else { include_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php' ; $sqlutil = new SqlUtility ; } $sql_query = trim( file_get_contents( $sql_file_path ) ) ; $sqlutil->splitMySqlFile( $pieces , $sql_query ) ; $created_tables = array() ; if( is_array( $pieces ) ) { foreach( $pieces as $piece ) { $prefixed_query = $sqlutil->prefixQuery( $piece , $prefix_mod ) ; if( ! $prefixed_query ) { $ret[] = "Invalid SQL <b>".htmlspecialchars($piece)."</b><br />"; return false ; } if( ! $db->query( $prefixed_query[0] ) ) { $ret[] = '<b>'.htmlspecialchars( $db->error() ).'</b><br />' ; return false ; } else { if( ! in_array( $prefixed_query[4] , $created_tables ) ) { $ret[] = 'Table <b>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</b> created.<br />'; $created_tables[] = $prefixed_query[4]; } else { $ret[] = 'Data inserted to table <b>'.htmlspecialchars($prefix_mod.'_'.$prefixed_query[4]).'</b>.</br />'; } } } } } // Templates $tplfile_handler =& xoops_gethandler( 'tplfile' ) ; $tpl_path = dirname(__FILE__).'/templates' ; if( $handler = @opendir( $tpl_path . '/' ) ) { while( ( $file = readdir( $handler ) ) !== false ) { if( substr( $file , 0 , 1 ) == '.' || !preg_match('/(\.html$)|(\.css$)/i', $file)){ continue ; } $file_path = $tpl_path . '/' . $file ; if( is_file( $file_path ) ) { $mtime = intval( @filemtime( $file_path ) ) ; $tplfile =& $tplfile_handler->create() ; $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ; $tplfile->setVar( 'tpl_refid' , $mid ) ; $tplfile->setVar( 'tpl_tplset' , 'default' ) ; $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ; $tplfile->setVar( 'tpl_desc' , '' , true ) ; $tplfile->setVar( 'tpl_module' , $mydirname ) ; $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ; $tplfile->setVar( 'tpl_lastimported' , 0 ) ; $tplfile->setVar( 'tpl_type' , 'module' ) ; if( ! $tplfile_handler->insert( $tplfile ) ) { $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span><br />'; } else { $tplid = $tplfile->getVar( 'tpl_id' ) ; $ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />'; // generate compiled file include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; include_once XOOPS_ROOT_PATH.'/class/template.php' ; if( ! xoops_template_touch( $tplid ) ) { $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span><br />'; } else { $ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span><br />'; } } } } closedir( $handler ) ; } include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; include_once XOOPS_ROOT_PATH.'/class/template.php' ; xoops_template_clear_module_cache( $mid ) ; // Set default categories $ini_category_list = array( // 小カテゴリ名, 表示順, 中カテゴリID array(constant($constpref.'_CATEGORY_1'), 1, 1), array(constant($constpref.'_CATEGORY_2'), 2, 1), array(constant($constpref.'_CATEGORY_3'), 3, 1), array(constant($constpref.'_CATEGORY_4'), 50, 1), ); $sql_values = array(); $selector_arr = array(); $id = 1; foreach($ini_category_list as $category){ $values = array(); foreach($category as $v){ $values[] = "'".$v."'"; } $sql_values[] = "(".implode(',', $values).")"; $selector_arr[] = "<a href=\"".XOOPS_URL."/modules/".$mydirname."/?cat_id=".($id++)."\">".$category[0]."<nobr><small>(0)</small></nobr></a>"; } if(count($sql_values) > 0 || count($selector_arr) > 0){ $sql = "INSERT INTO ".$db->prefix($mydirname.'_c_commu_category'). " (name,sort_order,c_commu_category_parent_id) VALUES ". implode(",", $sql_values); if($db->query($sql)){ $sql = "INSERT INTO ".$db->prefix($mydirname.'_c_commu_category_parent'). " (name,sort_order,selector) VALUES". " ('".constant($constpref.'_CATEGORY')."', '1', '".implode(" - ", $selector_arr)."')"; return $db->query($sql); } else{ return false; } } return true; }
/** * install a module * * @param string $mod module dirname * @param boolean $force force query * * @return bool|XoopsModule|XoopsObject */ public function install($mod = '', $force = false) { $xoops = Xoops::getInstance(); $module_handler = $xoops->getHandlerModule(); $mod = trim($mod); try { $cnt = $module_handler->getCount(new Criteria('dirname', $mod)); } catch (DBALException $e) { $cnt = 0; } if ($cnt == 0) { /* @var $module XoopsModule */ $module = $module_handler->create(); $module->loadInfoAsVar($mod); $module->setVar('weight', 1); $module->setVar('isactive', 1); $module->setVar('last_update', time()); $install_script = $module->getInfo('onInstall'); if ($install_script && trim($install_script) != '') { XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($install_script))); } $func = "xoops_module_pre_install_{$mod}"; // If pre install function is defined, execute if (function_exists($func)) { $result = $func($module); if (!$result) { $this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func); $this->error = array_merge($this->error, $module->getErrors()); return false; } else { $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>"); $this->trace = array_merge($this->trace, $module->getMessages()); } } // Create tables $created_tables = array(); if (count($this->error) == 0) { $schema_file = $module->getInfo('schema'); $sql_file = $module->getInfo('sqlfile'); if (!empty($schema_file)) { $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file; if (!XoopsLoad::fileExists($schema_file_path)) { $this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>"); return false; } $importer = new ImportSchema(); $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path)); $synchronizer = new SingleDatabaseSynchronizer($xoops->db()); $synchronizer->updateSchema($importSchema, true); } elseif (is_array($sql_file) && !empty($sql_file[\XoopsBaseConfig::get('db-type')])) { $xoops->deprecated('Install SQL files are deprecated since 2.6.0. Convert to portable Schemas'); $sql_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $sql_file[\XoopsBaseConfig::get('db-type')]; if (!XoopsLoad::fileExists($sql_file_path)) { $this->error[] = sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$sql_file_path}</strong>"); return false; } else { $this->trace[] = sprintf(SystemLocale::SF_SQL_FILE_FOUND, "<strong>{$sql_file_path}</strong>"); $this->trace[] = SystemLocale::MANAGING_TABLES; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $xoops->db()->prefix()); if (!$prefixed_query) { $this->error[]['sub'] = '<span class="red">' . sprintf(XoopsLocale::EF_INVALID_SQL, '<strong>' . $piece . '</strong>') . '</span>'; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $this->reservedTables) || $mod == 'system') { // not reserved, so try to create one try { $result = $xoops->db()->query($prefixed_query[0]); } catch (Exception $e) { $xoops->events()->triggerEvent('core.exception', $e); $result = false; } if (!$result) { $this->error[] = $xoops->db()->errorInfo(); break; } else { if (!in_array($prefixed_query[4], $created_tables)) { $this->trace[]['sub'] = sprintf(XoopsLocale::SF_TABLE_CREATED, '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>'); $created_tables[] = $prefixed_query[4]; } else { $this->trace[]['sub'] = sprintf(XoopsLocale::SF_DATA_INSERTED_TO_TABLE, '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>'); } } } else { // the table name is reserved, so halt the installation $this->error[]['sub'] = sprintf(SystemLocale::EF_TABLE_IS_RESERVED, '<strong>' . $prefixed_query[4] . '</strong>'); break; } } // if there was an error, delete the tables created so far, // so the next installation will not fail if (count($this->error) > 0) { foreach ($created_tables as $table) { try { $xoops->db()->query('DROP TABLE ' . $xoops->db()->prefix($table)); } catch (Exception $e) { $xoops->events()->triggerEvent('core.exception', $e); } } return false; } } } } // Save module info, blocks, templates and perms if (count($this->error) == 0) { if (!$module_handler->insertModule($module)) { $this->error[] = sprintf(XoopsLocale::EF_NOT_INSERTED_TO_DATABASE, '<strong>' . $module->getVar('name') . '</strong>'); foreach ($created_tables as $ct) { try { $xoops->db()->query('DROP TABLE ' . $xoops->db()->prefix($ct)); } catch (Exception $e) { $xoops->events()->triggerEvent('core.exception', $e); } } $this->error[] = sprintf(XoopsLocale::EF_NOT_INSTALLED, "<strong>" . $module->name() . "</strong>"); $this->error[] = XoopsLocale::C_ERRORS; unset($module); unset($created_tables); return false; } unset($created_tables); $this->trace[] = XoopsLocale::S_DATA_INSERTED . sprintf(SystemLocale::F_MODULE_ID, '<strong>' . $module->getVar('mid') . '</strong>'); $xoops->db()->beginTransaction(); // install Templates $this->installTemplates($module); $xoops->templateClearModuleCache($module->getVar('mid')); // install blocks $this->installBlocks($module); // Install Configs $this->installConfigs($module, 'add'); if ($module->getInfo('hasMain')) { $groups = array(FixedGroups::ADMIN, FixedGroups::USERS, FixedGroups::ANONYMOUS); } else { $groups = array(FixedGroups::ADMIN); } // retrieve all block ids for this module $block_handler = $xoops->getHandlerBlock(); $blocks = $block_handler->getByModule($module->getVar('mid'), false); $this->trace[] = SystemLocale::MANAGING_PERMISSIONS; $gperm_handler = $xoops->getHandlerGroupPermission(); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm = $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $module->getVar('mid')); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $this->trace[]['sub'] = '<span class="red">' . sprintf(SystemLocale::EF_GROUP_ID_ADMIN_ACCESS_RIGHT_NOT_ADDED, '<strong>' . $mygroup . '</strong>') . '</span>'; } else { $this->trace[]['sub'] = sprintf(SystemLocale::SF_GROUP_ID_ADMIN_ACCESS_RIGHT_ADDED, '<strong>' . $mygroup . '</strong>'); } unset($mperm); } $mperm = $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $module->getVar('mid')); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $this->trace[]['sub'] = '<span class="red">' . sprintf(SystemLocale::EF_GROUP_ID_USER_ACCESS_RIGHT_NOT_ADDED, '<strong>' . $mygroup . '</strong>') . '</span>'; } else { $this->trace[]['sub'] = sprintf(SystemLocale::SF_GROUP_ID_USER_ACCESS_RIGHT_ADDED, '<strong>' . $mygroup . '</strong>'); } unset($mperm); foreach ($blocks as $blc) { $bperm = $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $this->trace[]['sub'] = '<span class="red">' . SystemLocale::E_BLOCK_ACCESS_NOT_ADDED . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>'; } else { $this->trace[]['sub'] = SystemLocale::S_BLOCK_ACCESS_ADDED . sprintf(SystemLocale::F_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(SystemLocale::F_GROUP_ID, "<strong>" . $mygroup . "</strong>"); } unset($bperm); } } unset($blocks); unset($groups); // execute module specific install script if any // If pre install function is defined, execute $func = "xoops_module_install_{$mod}"; if (function_exists($func)) { $result = $func($module); if (!$result) { $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func); $this->trace = array_merge($this->trace, $module->getErrors()); } else { $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>"); $this->trace = array_merge($this->trace, $module->getMessages()); } } $this->trace[] = sprintf(XoopsLocale::SF_INSTALLED, '<strong>' . $module->getVar('name', 's') . '</strong>'); unset($blocks); $xoops->db()->commit(); XoopsPreload::getInstance()->triggerEvent('onModuleInstall', array(&$module, &$this)); return $module; } } else { $this->error[] = sprintf(XoopsLocale::EF_NOT_INSTALLED, '<strong>' . $mod . '</strong>') . " " . XoopsLocale::C_ERRORS; return false; } return false; }
$importfile = isset($_POST['importfile']) ? $_POST['importfile'] : 'nonselected'; $sql_file_path = XOOPS_ROOT_PATH . "/modules/smartsection/admin/import/" . $importfile . ".sql"; if (!file_exists($sql_file_path)) { $errs[] = "SQL file not found at <b>{$sql_file_path}</b>"; $error = true; } else { xoops_cp_header(); ss_adminMenu(-1, _AM_SS_IMPORT); $error = false; $db =& Database::getInstance(); $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'comments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups', 'groups_users_link', 'group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource'); $msgs[] = "SQL file found at <b>{$sql_file_path}</b>.<br /> Importing Q&A"; include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); $sql_query = trim($sql_query); SqlUtility::splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); if (!$prefixed_query) { $errs[] = "<b>{$piece}</b> is not a valid SQL!"; $error = true; break; } // check if the table name is reserved if (!in_array($prefixed_query[4], $reservedTables)) { // not reserved, so try to create one if (!$db->query($prefixed_query[0])) { $errs[] = $db->error();
/** * perform queries from SQL dump file in a batch * * @param string $file file path to an SQL dump file * * @return bool FALSE if failed reading SQL file or TRUE * if the file has been read and queries executed * @deprecated since version 2.6.0 - alpha 3. Switch to doctrine connector. */ public function queryFromFile($file) { $this->deprecated(); if (false !== ($fp = fopen($file, 'r'))) { $sql_queries = trim(fread($fp, filesize($file))); SqlUtility::splitMySqlFile($pieces, $sql_queries); foreach ($pieces as $query) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery(trim($query), $this->prefix()); if ($prefixed_query != false) { $this->query($prefixed_query[0]); } } return true; } return false; }
function pico_oninstall_base($module, $mydirname) { // transations on module install global $ret; // TODO :-D // for Cube 2.1 if (defined('XOOPS_CUBE_LEGACY')) { $root =& XCube_Root::getSingleton(); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success', 'pico_message_append_oninstall'); $ret = array(); } else { if (!is_array($ret)) { $ret = array(); } } $db =& Database::getInstance(); $mid = $module->getVar('mid'); // TABLES (loading mysql.sql) $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql'; $prefix_mod = $db->prefix() . '_' . $mydirname; if (file_exists($sql_file_path)) { $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path) . "</b>.<br /> Creating tables..."; if (file_exists(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) { include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php'; $sqlutil = new OldSqlUtility(); } else { include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sqlutil = new SqlUtility(); } $sql_query = trim(file_get_contents($sql_file_path)); $sqlutil->splitMySqlFile($pieces, $sql_query); $created_tables = array(); if (is_array($pieces)) { foreach ($pieces as $piece) { $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod); if (!$prefixed_query) { $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece) . "</b><br />"; return false; } if (!$db->query($prefixed_query[0])) { $ret[] = '<b>' . htmlspecialchars($db->error()) . '</b><br />'; //var_dump( $db->error() ) ; return false; } else { if (!in_array($prefixed_query[4], $created_tables)) { $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />'; $created_tables[] = $prefixed_query[4]; } else { $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b>.</br />'; } } } } } // TEMPLATES $tplfile_handler =& xoops_gethandler('tplfile'); $tpl_path = dirname(__FILE__) . '/templates'; if ($handler = @opendir($tpl_path . '/')) { while (($file = readdir($handler)) !== false) { if (substr($file, 0, 1) == '.') { continue; } $file_path = $tpl_path . '/' . $file; if (is_file($file_path)) { $mtime = intval(@filemtime($file_path)); $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_source', file_get_contents($file_path), true); $tplfile->setVar('tpl_refid', $mid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $mydirname . '_' . $file); $tplfile->setVar('tpl_desc', '', true); $tplfile->setVar('tpl_module', $mydirname); $tplfile->setVar('tpl_lastmodified', $mtime); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span><br />'; } else { $tplid = $tplfile->getVar('tpl_id'); $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br />'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($tplid)) { $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span><br />'; } else { $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span><br />'; } } } } closedir($handler); } include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($mid); return true; }
/** * perform queries from SQL dump file in a batch * * @param string $file file path to an SQL dump file * * @return bool FALSE if failed reading SQL file or TRUE if the file has been read and queries executed */ function queryFromFile($file) { if (false !== ($fp = fopen($file, 'r'))) { include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sql_queries = trim(fread($fp, filesize($file))); SqlUtility::splitMySqlFile($pieces, $sql_queries); foreach ($pieces as $query) { // [0] contains the prefixed query // [4] contains unprefixed table name $prefixed_query = SqlUtility::prefixQuery(trim($query), $this->prefix()); if ($prefixed_query != false) { $this->query($prefixed_query[0]); } } return true; } return false; }
function xpwiki_onupdate_base($module, $mydirname) { // transations on module update global $msgs; // TODO :-D // for Cube 2.1 if (defined('XOOPS_CUBE_LEGACY')) { $root =& XCube_Root::getSingleton(); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpwiki_message_append_onupdate'); $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Fail', 'xpwiki_message_append_onupdate'); $msgs = array(); } else { if (!is_array($msgs)) { $msgs = array(); } } $db =& Database::getInstance(); $mid = $module->getVar('mid'); // DB Check for db non support version $query = "SELECT * FROM " . $db->prefix($mydirname . "_pginfo"); if (!$db->query($query)) { // TABLES (loading mysql.sql) $sql_file_path = dirname(__FILE__) . '/sql/mysql.sql'; $prefix_mod = $db->prefix() . '_' . $mydirname; if (file_exists($sql_file_path)) { $ret[] = "SQL file found at <b>" . htmlspecialchars($sql_file_path, ENT_COMPAT, _CHARSET) . "</b>.<br /> Creating tables..."; if (is_file(XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php')) { include_once XOOPS_ROOT_PATH . '/class/database/oldsqlutility.php'; $sqlutil = new OldSqlUtility(); } else { include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; $sqlutil = new SqlUtility(); } $sql_query = trim(file_get_contents($sql_file_path)); $sqlutil->splitMySqlFile($pieces, $sql_query); $created_tables = array(); foreach ($pieces as $piece) { $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod); if (!$prefixed_query) { $ret[] = "Invalid SQL <b>" . htmlspecialchars($piece, ENT_COMPAT, _CHARSET) . "</b><br />"; return false; } if (!$db->query($prefixed_query[0])) { $ret[] = '<b>' . htmlspecialchars($db->error(), ENT_COMPAT, _CHARSET) . '</b><br />'; //var_dump( $db->error() ) ; return false; } else { if (!in_array($prefixed_query[4], $created_tables)) { $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b> created.<br />'; $created_tables[] = $prefixed_query[4]; } else { $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_COMPAT, _CHARSET) . '</b>.</br />'; } } } } } // TABLES (write here ALTER TABLE etc. if necessary) $query = "SELECT `reading` FROM " . $db->prefix($mydirname . "_pginfo"); if (!$db->query($query)) { $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_pginfo") . '` ADD `reading` VARCHAR( 255 ) BINARY NOT NULL'); } $query = "SELECT `name_ci` FROM " . $db->prefix($mydirname . "_pginfo"); if (!$db->query($query)) { $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD `name_ci` VARCHAR( 255 ) NOT NULL'); $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD INDEX ( `name_ci` )'); $db->query('UPDATE `' . $db->prefix($mydirname . '_pginfo') . '` SET `name_ci` = `name`'); } $query = "SELECT `pgorder` FROM " . $db->prefix($mydirname . "_pginfo"); if (!$db->query($query)) { $db->query('ALTER TABLE `' . $db->prefix($mydirname . '_pginfo') . '` ADD `pgorder` FLOAT DEFAULT \'1\' NOT NULL'); } $query = "SELECT count(*) FROM " . $db->prefix($mydirname . "_cache"); if (!$db->query($query)) { $db->query('CREATE TABLE `' . $db->prefix($mydirname . '_cache') . '` ( `key` varchar(64) NOT NULL default \'\', `plugin` varchar(100) NOT NULL default \'\', `data` mediumblob NOT NULL, `mtime` int(11) NOT NULL default \'0\', `ttl` int(11) NOT NULL default \'0\', KEY `key` (`key`), KEY `plugin` (`plugin`) ) ENGINE=MyISAM'); } $query = "SELECT count(*) FROM " . $db->prefix($mydirname . "_alias"); if (!$db->query($query)) { $db->query('CREATE TABLE `' . $db->prefix($mydirname . '_alias') . '` ( `name` varchar(255) binary NOT NULL DEFAULT \'\', `pgid` int(11) NOT NULL DEFAULT \'0\', PRIMARY KEY (`name`), KEY `pgid` (`pgid`) ) ENGINE=MyISAM'); include_once XOOPS_TRUST_PATH . "/modules/xpwiki/include.php"; $xpwiki = XpWiki::getInitedSingleton($mydirname); $xpwiki->init(); if ($xpwiki->root->page_aliases) { $query = array(); foreach ($xpwiki->root->page_aliases as $alias => $page) { if ($pgid = $xpwiki->func->get_pgid_by_name($page)) { $query[] = '(' . $db->quoteString($alias) . ',' . $pgid . ')'; } } if ($query) { $query = 'INSERT INTO `' . $db->prefix($mydirname . "_alias") . '` (`name`,`pgid`) VALUES ' . join(',', $query); if ($db->query($query)) { $inifile = $xpwiki->cont['CACHE_DIR'] . 'pukiwiki.ini.php'; $ini = file_get_contents($inifile); file_put_contents($inifile . '.alias.bak', $ini); $ini = preg_replace('#//<page_aliases>.+//<page_aliases/>\\s+#s', '', $ini); file_put_contents($inifile, $ini); } } } unset($xpwiki); } // ADD Keys $table = $db->prefix($mydirname . '_attach'); if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) { $keys = array('name' => '', 'type' => '', 'mode' => '', 'age' => ''); while ($arr = $db->fetchArray($result)) { unset($keys[$arr['Key_name']]); } foreach ($keys as $_key => $_val) { $query = 'ALTER TABLE `' . $table . '` ADD INDEX(`' . $_key . '`' . $_val . ')'; $db->query($query); //$msgs[] = $query; } } $table = $db->prefix($mydirname . '_pginfo'); if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) { $keys = array('editedtime' => '', 'freeze' => '', 'egids' => '', 'vgids' => '', 'eaids' => '(255)', 'vaids' => '(255)', 'vids' => array('vaids' => '(200)', 'vgids' => '(133)')); while ($arr = $db->fetchArray($result)) { unset($keys[$arr['Key_name']]); } foreach ($keys as $_key => $_val) { if (is_array($_val)) { $_index = array(); foreach ($_val as $__key => $__val) { $_index[] = '`' . $__key . '`' . $__val; } $_index = join(', ', $_index); } else { $_index = '`' . $_key . '`' . $_val; } $query = 'ALTER TABLE `' . $table . '` ADD INDEX `' . $_key . '`(' . $_index . ')'; $db->query($query); //$msgs[] = $query; } } $table = $db->prefix($mydirname . '_rel'); if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) { $keys = array('PRIMARY' => ''); while ($arr = $db->fetchArray($result)) { unset($keys[$arr['Key_name']]); } if ($keys) { $dels = array(); $query = 'SELECT CONCAT(pgid, \'_\', relid) as id, (count(*)-1) as count FROM `' . $table . '` GROUP BY id HAVING count >= 1'; if ($result = $db->query($query)) { while ($arr = $db->fetchRow($result)) { $dels[$arr[0]] = $arr[1]; } } foreach ($dels as $key => $limit) { $arr = explode('_', $key); $query = 'DELETE FROM ' . $table . ' WHERE pgid=' . $arr[0] . ' AND relid=' . $arr[1] . ' LIMIT ' . $limit; $db->query($query); //$msgs[] = $query; } $query = 'ALTER TABLE `' . $table . '` ADD PRIMARY KEY(`pgid`,`relid`)'; $db->query($query); //$msgs[] = $query; } } $table = $db->prefix($mydirname . '_count'); if ($result = $db->query('SHOW INDEX FROM `' . $table . '`')) { $keys = array('today' => ''); while ($arr = $db->fetchArray($result)) { unset($keys[$arr['Key_name']]); } foreach ($keys as $_key => $_val) { $query = 'ALTER TABLE `' . $table . '` ADD INDEX(`' . $_key . '`' . $_val . ')'; $db->query($query); //$msgs[] = $query; } } // TEMPLATES (all templates have been already removed by modulesadmin) $tplfile_handler =& xoops_gethandler('tplfile'); $tpl_path = dirname(__FILE__) . '/templates'; if ($handler = @opendir($tpl_path . '/')) { while (($file = readdir($handler)) !== false) { if (substr($file, 0, 1) == '.') { continue; } $file_path = $tpl_path . '/' . $file; if (is_file($file_path) && substr($file, -5) == '.html') { $mtime = intval(@filemtime($file_path)); $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_source', file_get_contents($file_path), true); $tplfile->setVar('tpl_refid', $mid); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $mydirname . '_' . $file); $tplfile->setVar('tpl_desc', '', true); $tplfile->setVar('tpl_module', $mydirname); $tplfile->setVar('tpl_lastmodified', $mtime); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_type', 'module'); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> to the database.</span>'; } else { $tplid = $tplfile->getVar('tpl_id'); $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)'; // generate compiled file include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; if (!xoops_template_touch($tplid)) { $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b>.</span>'; } else { $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_COMPAT, _CHARSET) . '</b> compiled.</span>'; } } } } closedir($handler); } include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; include_once XOOPS_ROOT_PATH . '/class/template.php'; xoops_template_clear_module_cache($mid); // xpWiki original functions include_once dirname(__FILE__) . '/include/check.func.php'; $_ret = xpwikifunc_permission_check($mydirname); if (!$_ret) { $msgs = array_merge($msgs, xpwikifunc_defdata_check($mydirname, 'update')); } else { $msgs = array_merge($msgs, $_ret); return false; } // Delete COUNTER_DIR/*.counter $msgs = array_merge($msgs, xpwikifunc_delete_counter($mydirname)); return true; }