Example #1
0
function xpress_templates_make($mid, $mydirname)
{
    $msgs = array();
    // TEMPLATES
    $tplfile_handler =& xoops_gethandler('tplfile');
    $tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates';
    //copy  template file from source
    if ($handler = @opendir($tpl_path . '/source/')) {
        while (($file = readdir($handler)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            if (!is_template($file)) {
                continue;
            }
            $file_path = $tpl_path . '/source/' . $file;
            if (is_file($file_path)) {
                $target_file_name = $mydirname . '_' . $file;
                $target_file_path = $tpl_path . '/' . $target_file_name;
                $rcd = @unlink($target_file_path);
                if ($mydirname != 'xpress') {
                    //old version file delete
                    $rcd = @unlink($tpl_path . '/xpress' . $file);
                }
                //				$rcd = rename($file_path, $target_file_path);
                $rcd = copy($file_path, $target_file_path);
                if ($rcd) {
                    $msgs[] = 'Template <b>' . htmlspecialchars($target_file_path) . '</b> copy from ' . htmlspecialchars($file) . '<br />';
                } else {
                    $msgs[] = '<span style="color:#ff0000;">ERROR: Could not copy template <b>' . htmlspecialchars($target_file_name) . '</b> from ' . htmlspecialchars($file) . '(check templates directory permision (777))</span><br />';
                }
            }
        }
        closedir($handler);
    }
    // template added to the database.
    if ($handler = @opendir($tpl_path . '/')) {
        while (($file = readdir($handler)) !== false) {
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            $file_path = $tpl_path . '/' . $file;
            $file_name = $file;
            $pattern = '^' . $mydirname . '_';
            if (preg_match('/' . $pattern . '/', $file_name, $match)) {
                if (is_file($file_path)) {
                    $msgs[] = xpress_create_db_template($file_name, $file_path, $mydirname, $mid);
                }
            }
        }
        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 $msgs;
}
Example #2
0
 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) . "</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.
         $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) . "</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);
     // 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;
 }
Example #3
0
/**
 * Remove module's cache
 *
 * @package AMS
 * @author Instant Zero (http://xoops.instant-zero.com)
 * @copyright (c) Instant Zero
*/
function AMS_updateCache()
{
    global $xoopsModule;
    if (!isset($xoopsModule) || $xoopsModule->getVar('dirname') != "AMS") {
        $mod_handler =& xoops_gethandler('module');
        $amsModule =& $mod_handler->getByDirname('AMS');
    } else {
        $amsModule =& $xoopsModule;
    }
    $folder = $amsModule->getVar('dirname');
    $tpllist = array();
    include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    $tplfile_handler =& xoops_gethandler('tplfile');
    $tpllist = $tplfile_handler->find(null, null, null, $folder);
    $xoopsTpl = new XoopsTpl();
    xoops_template_clear_module_cache($amsModule->getVar('mid'));
    // Clear module's blocks cache
    //remove RSS cache (XOOPS, ImpressCMS)
    $files_del = array();
    $files_del = glob(XOOPS_CACHE_PATH . '/*system_rss*');
    if (count($files_del) > 0) {
        foreach ($files_del as $one_file) {
            unlink($one_file);
        }
    }
    $files_del = array();
    $files_del = glob(XOOPS_COMPILE_PATH . '/*system_rss*');
    if (count($files_del) > 0) {
        foreach ($files_del as $one_file) {
            unlink($one_file);
        }
    }
    $files_del = array();
    $files_del = glob($xoopsTpl->cache_dir . '/*system_rss*');
    if (count($files_del) > 0) {
        foreach ($files_del as $one_file) {
            unlink($one_file);
        }
    }
    //remove RSS cache (XOOPS CUBE)
    $files_del = array();
    $files_del = glob(XOOPS_CACHE_PATH . '/*legacy_rss*');
    if (count($files_del) > 0) {
        foreach ($files_del as $one_file) {
            unlink($one_file);
        }
    }
    $files_del = array();
    $files_del = glob(XOOPS_COMPILE_PATH . '/*legacy_rss*');
    if (count($files_del) > 0) {
        foreach ($files_del as $one_file) {
            unlink($one_file);
        }
    }
    $files_del = array();
    $files_del = glob($xoopsTpl->cache_dir . '/*legacy_rss*');
    if (count($files_del) > 0) {
        foreach ($files_del as $one_file) {
            unlink($one_file);
        }
    }
    // Remove cache for each page.
    foreach ($tpllist as $onetemplate) {
        if ($onetemplate->getVar('tpl_type') == 'module') {
            // Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code
            $files_del = array();
            $files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*');
            if (count($files_del) > 0) {
                foreach ($files_del as $one_file) {
                    unlink($one_file);
                }
            }
            $files_del = array();
            $files_del = glob(XOOPS_COMPILE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*');
            if (count($files_del) > 0) {
                foreach ($files_del as $one_file) {
                    unlink($one_file);
                }
            }
            $files_del = array();
            $files_del = glob($xoopsTpl->cache_dir . '/*' . $onetemplate->getVar('tpl_file') . '*');
            if (count($files_del) > 0) {
                foreach ($files_del as $one_file) {
                    unlink($one_file);
                }
            }
        }
    }
}
Example #4
0
function xoops_module_deactivate($mid)
{
    global $xoopsConfig;
    $module_handler =& xoops_gethandler('module');
    $module =& $module_handler->get($mid);
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($mid);
    $module->setVar('isactive', 0);
    if ($module->getVar('dirname') == "system") {
        return "<p>" . sprintf(_MD_AM_FAILDEACT, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_SYSNO . "</p>";
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
        return "<p>" . sprintf(_MD_AM_FAILDEACT, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
    } else {
        if (!$module_handler->insert($module)) {
            $ret = "<p>" . sprintf(_MD_AM_FAILDEACT, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />" . $module->getHtmlErrors();
            return $ret . "</p>";
        }
        $blocks =& XoopsBlock::getByModule($module->getVar('mid'));
        $bcount = count($blocks);
        for ($i = 0; $i < $bcount; $i++) {
            $blocks[$i]->setVar('isactive', 0);
            $blocks[$i]->store();
        }
        return "<p>" . sprintf(_MD_AM_OKDEACT, "<b>" . $module->getVar('name') . "</b>") . "</p>";
    }
}
function icms_module_update($dirname)
{
    $dirname = trim($dirname);
    $db =& icms_db_Factory::instance();
    $module_handler = icms::handler('icms_module');
    $module =& $module_handler->getByDirname($dirname);
    // Save current version for use in the update function
    $prev_version = $module->getVar('version');
    $prev_dbversion = $module->getVar('dbversion');
    xoops_template_clear_module_cache($module->getVar('mid'));
    // we dont want to change the module name set by admin
    $temp_name = $module->getVar('name');
    $module->loadInfoAsVar($dirname);
    $module->setVar('name', $temp_name);
    if (!$module_handler->insert($module)) {
        echo '<p>Could not update ' . $module->getVar('name') . '</p>';
        echo "<br /><a href='admin.php?fct=modulesadmin'>" . _MD_AM_BTOMADMIN . "</a>";
    } else {
        $newmid = $module->getVar('mid');
        $msgs = array();
        $msgs[] = _MD_AM_MOD_DATA_UPDATED;
        $tplfile_handler =& icms::handler('icms_view_template_file');
        $deltpl =& $tplfile_handler->find('default', 'module', $module->getVar('mid'));
        $delng = array();
        if (is_array($deltpl)) {
            $xoopsDelTpl = new icms_view_Tpl();
            // clear cache files
            $xoopsDelTpl->clear_cache(null, 'mod_' . $dirname);
            // delete template file entry in db
            $dcount = count($deltpl);
            for ($i = 0; $i < $dcount; $i++) {
                if (!$tplfile_handler->delete($deltpl[$i])) {
                    $delng[] = $deltpl[$i]->getVar('tpl_file');
                }
            }
        }
        $templates = $module->getInfo('templates');
        if ($templates != false) {
            $msgs[] = _MD_AM_MOD_UP_TEM;
            foreach ($templates as $tpl) {
                $tpl['file'] = trim($tpl['file']);
                if (!in_array($tpl['file'], $delng)) {
                    $tpldata =& xoops_module_gettemplate($dirname, $tpl['file']);
                    $tplfile =& $tplfile_handler->create();
                    $tplfile->setVar('tpl_refid', $newmid);
                    $tplfile->setVar('tpl_lastimported', 0);
                    $tplfile->setVar('tpl_lastmodified', time());
                    if (preg_match("/\\.css\$/i", $tpl['file'])) {
                        $tplfile->setVar('tpl_type', 'css');
                    } else {
                        $tplfile->setVar('tpl_type', 'module');
                    }
                    $tplfile->setVar('tpl_source', $tpldata, true);
                    $tplfile->setVar('tpl_module', $dirname);
                    $tplfile->setVar('tpl_tplset', 'default');
                    $tplfile->setVar('tpl_file', $tpl['file'], true);
                    $tplfile->setVar('tpl_desc', $tpl['description'], true);
                    if (!$tplfile_handler->insert($tplfile)) {
                        $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_INSERT_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                    } else {
                        $newid = $tplfile->getVar('tpl_id');
                        $msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_INSERTED . '</span>', '<strong>' . $tpl['file'] . '</strong>', '<strong>' . $newid . '</strong>');
                        if ($icmsConfig['template_set'] == 'default') {
                            if (!icms_view_Tpl::template_touch($newid)) {
                                $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                            } else {
                                $msgs[] = sprintf('&nbsp;&nbsp;<span>' . _MD_AM_TEMPLATE_RECOMPILED . '</span>', '<strong>' . $tpl['file'] . '</strong>');
                            }
                        }
                    }
                    unset($tpldata);
                } else {
                    $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_DELETE_FAIL . '</span>', $tpl['file']);
                }
            }
        }
        $blocks = $module->getInfo('blocks');
        $msgs[] = _MD_AM_MOD_REBUILD_BLOCKS;
        if ($blocks != false) {
            $count = count($blocks);
            $showfuncs = array();
            $funcfiles = array();
            for ($i = 1; $i <= $count; $i++) {
                if (isset($blocks[$i]['show_func']) && $blocks[$i]['show_func'] != '' && isset($blocks[$i]['file']) && $blocks[$i]['file'] != '') {
                    $editfunc = isset($blocks[$i]['edit_func']) ? $blocks[$i]['edit_func'] : '';
                    $showfuncs[] = $blocks[$i]['show_func'];
                    $funcfiles[] = $blocks[$i]['file'];
                    $template = '';
                    if (isset($blocks[$i]['template']) && trim($blocks[$i]['template']) != '') {
                        $content =& xoops_module_gettemplate($dirname, $blocks[$i]['template'], true);
                    }
                    if (!$content) {
                        $content = '';
                    } else {
                        $template = $blocks[$i]['template'];
                    }
                    $options = '';
                    if (!empty($blocks[$i]['options'])) {
                        $options = $blocks[$i]['options'];
                    }
                    $sql = "SELECT bid, name FROM " . $db->prefix('newblocks') . " WHERE mid='" . (int) $module->getVar('mid') . "' AND func_num='" . (int) $i . "' AND show_func='" . addslashes($blocks[$i]['show_func']) . "' AND func_file='" . addslashes($blocks[$i]['file']) . "'";
                    $fresult = $db->query($sql);
                    $fcount = 0;
                    while ($fblock = $db->fetchArray($fresult)) {
                        $fcount++;
                        $sql = "UPDATE " . $db->prefix("newblocks") . " SET name='" . addslashes($blocks[$i]['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . " WHERE bid='" . (int) $fblock['bid'] . "'";
                        $result = $db->query($sql);
                        if (!$result) {
                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_UPDATE_FAIL, $fblock['name']);
                        } else {
                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_BLOCK_UPDATED, '<strong>' . $fblock['name'] . '</strong>', '<strong>' . icms_conv_nr2local($fblock['bid']) . '</strong>');
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->find('default', 'block', $fblock['bid']);
                                if (count($tplfile) == 0) {
                                    $tplfile_new =& $tplfile_handler->create();
                                    $tplfile_new->setVar('tpl_module', $dirname);
                                    $tplfile_new->setVar('tpl_refid', (int) $fblock['bid']);
                                    $tplfile_new->setVar('tpl_tplset', 'default');
                                    $tplfile_new->setVar('tpl_file', $blocks[$i]['template'], true);
                                    $tplfile_new->setVar('tpl_type', 'block');
                                } else {
                                    $tplfile_new = $tplfile[0];
                                }
                                $tplfile_new->setVar('tpl_source', $content, true);
                                $tplfile_new->setVar('tpl_desc', $blocks[$i]['description'], true);
                                $tplfile_new->setVar('tpl_lastmodified', time());
                                $tplfile_new->setVar('tpl_lastimported', 0);
                                if (!$tplfile_handler->insert($tplfile_new)) {
                                    $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_UPDATE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> updated.';
                                    if ($icmsConfig['template_set'] == 'default') {
                                        if (!icms_view_Tpl::template_touch($tplfile_new->getVar('tpl_id'))) {
                                            $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        } else {
                                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if ($fcount == 0) {
                        $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq');
                        $block_name = addslashes($blocks[$i]['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 ('" . (int) $newbid . "', '" . (int) $module->getVar('mid') . "', '" . (int) $i . "','" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', '1', '0', '0', 'M', 'H', '1', '" . addslashes($dirname) . "', '" . addslashes($blocks[$i]['file']) . "', '" . addslashes($blocks[$i]['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', '0', '" . time() . "')";
                        $result = $db->query($sql);
                        if (!$result) {
                            $msgs[] = '&nbsp;&nbsp;ERROR: Could not create ' . $blocks[$i]['name'];
                            echo $sql;
                        } else {
                            if (empty($newbid)) {
                                $newbid = $db->getInsertId();
                            }
                            $groups =& icms::$user->getGroups();
                            $gperm_handler = icms::handler('icms_member_groupperm');
                            foreach ($groups as $mygroup) {
                                $bperm =& $gperm_handler->create();
                                $bperm->setVar('gperm_groupid', (int) $mygroup);
                                $bperm->setVar('gperm_itemid', (int) $newbid);
                                $bperm->setVar('gperm_name', 'block_read');
                                $bperm->setVar('gperm_modid', 1);
                                if (!$gperm_handler->insert($bperm)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not add block access right. Block ID: <b>' . $newbid . '</b> Group ID: <b>' . $mygroup . '</b></span>';
                                } else {
                                    $msgs[] = '&nbsp;&nbsp;Added block access right. Block ID: <b>' . $newbid . '</b> Group ID: <b>' . $mygroup . '</b>';
                                }
                            }
                            if ($template != '') {
                                $tplfile =& $tplfile_handler->create();
                                $tplfile->setVar('tpl_module', $dirname);
                                $tplfile->setVar('tpl_refid', (int) $newbid);
                                $tplfile->setVar('tpl_source', $content, true);
                                $tplfile->setVar('tpl_tplset', 'default');
                                $tplfile->setVar('tpl_file', $blocks[$i]['template'], true);
                                $tplfile->setVar('tpl_type', 'block');
                                $tplfile->setVar('tpl_lastimported', 0);
                                $tplfile->setVar('tpl_lastmodified', time());
                                $tplfile->setVar('tpl_desc', $blocks[$i]['description'], true);
                                if (!$tplfile_handler->insert($tplfile)) {
                                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[$i]['template'] . '</b> to the database.</span>';
                                } else {
                                    $newid = $tplfile->getVar('tpl_id');
                                    $msgs[] = '&nbsp;&nbsp;Template <b>' . $blocks[$i]['template'] . '</b> added to the database.';
                                    if ($icmsConfig['template_set'] == 'default') {
                                        if (!icms_view_Tpl::template_touch($newid)) {
                                            $msgs[] = sprintf('&nbsp;&nbsp;<span style="color:#ff0000;">' . _MD_AM_TEMPLATE_RECOMPILE_FAIL . '</span>', '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        } else {
                                            $msgs[] = sprintf('&nbsp;&nbsp;' . _MD_AM_TEMPLATE_RECOMPILED, '<strong>' . $blocks[$i]['template'] . '</strong>');
                                        }
                                    }
                                }
                            }
                            $msgs[] = '&nbsp;&nbsp;Block <b>' . $blocks[$i]['name'] . '</b> created. Block ID: <b>' . $newbid . '</b>';
                            $sql = "INSERT INTO " . $db->prefix('block_module_link') . " (block_id, module_id, page_id) VALUES ('" . (int) $newbid . "', '0', '1')";
                            $db->query($sql);
                        }
                    }
                }
            }
            $icms_block_handler = icms::handler('icms_view_block');
            $block_arr = $icms_block_handler->getByModule($module->getVar('mid'));
            foreach ($block_arr as $block) {
                if (!in_array($block->getVar('show_func'), $showfuncs) || !in_array($block->getVar('func_file'), $funcfiles)) {
                    $sql = sprintf("DELETE FROM %s WHERE bid = '%u'", $db->prefix('newblocks'), (int) $block->getVar('bid'));
                    if (!$db->query($sql)) {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete block <b>' . $block->getVar('name') . '</b>. Block ID: <b>' . $block->getVar('bid') . '</b></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;Block <b>' . $block->getVar('name') . ' deleted. Block ID: <b>' . $block->getVar('bid') . '</b>';
                        if ($block->getVar('template') != '') {
                            $tplfiles =& $tplfile_handler->find(null, 'block', $block->getVar('bid'));
                            if (is_array($tplfiles)) {
                                $btcount = count($tplfiles);
                                for ($k = 0; $k < $btcount; $k++) {
                                    if (!$tplfile_handler->delete($tplfiles[$k])) {
                                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not remove deprecated block template. (ID: <b>' . $tplfiles[$k]->getVar('tpl_id') . '</b>)</span>';
                                    } else {
                                        $msgs[] = '&nbsp;&nbsp;Block template <b>' . $tplfiles[$k]->getVar('tpl_file') . '</b> deprecated.';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // first delete all config entries
        $config_handler = icms::handler('icms_config');
        $configs =& $config_handler->getConfigs(new icms_db_criteria_Item('conf_modid', $module->getVar('mid')));
        $confcount = count($configs);
        $config_delng = array();
        if ($confcount > 0) {
            $msgs[] = 'Deleting module config options...';
            for ($i = 0; $i < $confcount; $i++) {
                if (!$config_handler->deleteConfig($configs[$i])) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not delete config data from the database. Config ID: <b>' . $configs[$i]->getvar('conf_id') . '</b></span>';
                    // save the name of config failed to delete for later use
                    $config_delng[] = $configs[$i]->getvar('conf_name');
                } else {
                    $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N');
                    $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype');
                    $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype');
                    $msgs[] = '&nbsp;&nbsp;Config data deleted from the database. Config ID: <b>' . $configs[$i]->getVar('conf_id') . '</b>';
                }
            }
        }
        // now reinsert them with the new settings
        $configs = $module->getInfo('config');
        if ($configs != false) {
            if ($module->getVar('hascomments') != 0) {
                include_once ICMS_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 ICMS_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 ICMS_ROOT_PATH . '/include/notification_constants.php';
            include_once ICMS_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: for some reason the default doesn't come up properly
            //  initially is ok, but not when 'update' module..
            $options = array();
            $categories =& icms_data_notification_Handler::categoryInfo('', $module->getVar('mid'));
            foreach ($categories as $category) {
                $events =& icms_data_notification_Handler::categoryEvents($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' => icms_data_notification_Handler::generateConfig($category,$event,'name'), 'title' => icms_data_notification_Handler::generateConfig($category,$event,'title_constant'), 'description' => icms_data_notification_Handler::generateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1);
                }
            }
            $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 = icms::handler('icms_config');
            $order = 0;
            foreach ($configs as $config) {
                // only insert ones that have been deleted previously with success
                if (!in_array($config['name'], $config_delng)) {
                    $confobj =& $config_handler->createConfig();
                    $confobj->setVar('conf_modid', (int) $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']);
                    if (isset($config_old[$config['name']]['value']) && $config_old[$config['name']]['formtype'] == $config['formtype'] && $config_old[$config['name']]['valuetype'] == $config['valuetype']) {
                        // preserver the old value if any
                        // form type and value type must be the same
                        $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true);
                    } else {
                        $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 />&nbsp;&nbsp;&nbsp;&nbsp;Config option added. Name: <b>' . $key . '</b> Value: <b>' . $value . '</b>';
                            unset($confop);
                        }
                    }
                    $order++;
                    if (false != $config_handler->insertConfig($confobj)) {
                        $msgs[] = '&nbsp;&nbsp;Config <b>' . $config['name'] . '</b> added to the database.' . $confop_msgs;
                    } else {
                        $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert config <b>' . $config['name'] . '</b> to the database.</span>';
                    }
                    unset($confobj);
                }
            }
            unset($configs);
        }
        // add module specific tasks to system autotasks list
        $atasks = $module->getInfo('autotasks');
        $atasks_handler =& icms_getModuleHandler('autotasks', 'system');
        if (count($atasks) > 0) {
            $msgs[] = 'Updating autotasks...';
            $criteria = new icms_db_criteria_Compo();
            $criteria->add(new icms_db_criteria_Item('sat_type', 'addon/' . $module->getInfo('dirname')));
            $items_atasks = $atasks_handler->getObjects($criteria, false);
            foreach ($items_atasks as $task) {
                $taskID = (int) $task->getVar('sat_addon_id');
                $atasks[$taskID]['enabled'] = $task->getVar('sat_enabled');
                $atasks[$taskID]['repeat'] = $task->getVar('sat_repeat');
                $atasks[$taskID]['interval'] = $task->getVar('sat_interval');
                $atasks[$taskID]['name'] = $task->getVar('sat_name');
            }
            $atasks_handler->deleteAll($criteria);
            foreach ($atasks as $taskID => $taskData) {
                if (!isset($taskData['code']) || trim($taskData['code']) == '') {
                    continue;
                }
                $task =& $atasks_handler->create();
                if (isset($taskData['enabled'])) {
                    $task->setVar('sat_enabled', $taskData['enabled']);
                }
                if (isset($taskData['repeat'])) {
                    $task->setVar('sat_repeat', $taskData['repeat']);
                }
                if (isset($taskData['interval'])) {
                    $task->setVar('sat_interval', $taskData['interval']);
                }
                if (isset($taskData['onfinish'])) {
                    $task->setVar('sat_onfinish', $taskData['onfinish']);
                }
                $task->setVar('sat_name', $taskData['name']);
                $task->setVar('sat_code', sprintf("require ICMS_ROOT_PATH . \"/modules/%s/%s\";", $module->getInfo('dirname'), addslashes($taskData['code'])));
                $task->setVar('sat_type', 'addon/' . $module->getInfo('dirname'));
                $task->setVar('sat_addon_id', (int) $taskID);
                if (!$atasks_handler->insert($task)) {
                    $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert autotask to db. Name: <b>' . $taskData['name'] . '</b></span>';
                } else {
                    $msgs[] = '&nbsp;&nbsp;Updated task from autotasks list. Task Name: <b>' . $taskData['name'] . '</b>';
                }
            }
            unset($atasks, $atasks_handler, $task, $taskData, $criteria, $items, $taskID);
        }
        // execute module specific update script if any
        $update_script = $module->getInfo('onUpdate');
        $ModName = $module->getInfo('modname') != '' ? trim($module->getInfo('modname')) : $dirname;
        if (false != $update_script && trim($update_script) != '') {
            include_once ICMS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script);
            $is_IPF = $module->getInfo('object_items');
            if (!empty($is_IPF)) {
                $icmsDatabaseUpdater = icms_db_legacy_Factory::getDatabaseUpdater();
                $icmsDatabaseUpdater->moduleUpgrade($module, true);
                foreach ($icmsDatabaseUpdater->_messages as $msg) {
                    $msgs[] = $msg;
                }
            }
            if (function_exists('xoops_module_update_' . $ModName)) {
                $func = 'xoops_module_update_' . $ModName;
                if (!$func($module, $prev_version, $prev_dbversion)) {
                    $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
                } else {
                    $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
                }
            } elseif (function_exists('icms_module_update_' . $ModName)) {
                $func = 'icms_module_update_' . $ModName;
                if (!$func($module, $prev_version, $prev_dbversion)) {
                    $msgs[] = sprintf(_MD_AM_FAIL_EXEC, '<strong>' . $func . '</strong>');
                } else {
                    $msgs[] = sprintf(_MD_AM_FUNCT_EXEC, '<strong>' . $func . '</strong>');
                }
            }
        }
        $msgs[] = '</code><p>' . sprintf(_MD_AM_OKUPD, '<b>' . $module->getVar('name') . '</b>') . '</p>';
    }
    $ret = '<code>';
    foreach ($msgs as $msg) {
        $ret .= $msg . '<br />';
    }
    return $ret;
}
Example #6
0
/**
 * Remove module's cache
 *
 * @package News
 * @author Instant Zero (http://xoops.instant-zero.com)
 * @copyright (c) Instant Zero
*/
function nw_updateCache() {
	global $xoopsModule;
	$folder = $xoopsModule->getVar('dirname');
	$tpllist = array();
	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
	include_once XOOPS_ROOT_PATH.'/class/template.php';
	$tplfile_handler =& xoops_gethandler('tplfile');
	$tpllist = $tplfile_handler->find(null, null, null, $folder);
	$xoopsTpl = new XoopsTpl();
	xoops_template_clear_module_cache($xoopsModule->getVar('mid'));			// Clear module's blocks cache

	// Remove cache for each page.
	foreach ($tpllist as $onetemplate) {
		if( $onetemplate->getVar('tpl_type') == 'module' ) {
			// Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code
			$files_del = array();
			$files_del = glob(XOOPS_CACHE_PATH.'/*'.$onetemplate->getVar('tpl_file').'*');
			if(count($files_del) >0) {
				foreach($files_del as $one_file) {
					unlink($one_file);
				}
			}
		}
	}
}
Example #7
0
 /**
  * Updates or inserts the module's data, templates, blocks, configuration categories and items and profile fields
  *
  * @return string
  */
 function insert()
 {
     $this->setVar('last_update', time());
     $module_handler =& xoops_gethandler('module');
     if (!$module_handler->insert($this)) {
         $this->setErrors('Could not insert <b>' . $this->getVar('name') . '</b> to database.');
         $ret = "<p>" . sprintf(_MD_AM_FAILINS, "<b>" . $this->name() . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />";
         foreach ($this->getErrors() as $err) {
             $ret .= " - " . $err . "<br />";
         }
         $ret .= "</p>";
         return $ret;
     }
     $this->setMessage('Module data inserted successfully. Module ID: <b>' . $this->getVar('mid') . '</b>');
     $this->insertTemplates();
     include_once XOOPS_ROOT_PATH . '/class/template.php';
     xoops_template_clear_module_cache($this->getVar('mid'));
     $this->insertBlocks();
     $this->insertConfigCategories();
     $this->insertConfig();
     $this->insertProfileFields();
     return "";
 }
Example #8
0
/**
 * Remove module's cache
 *
 * @package News
 * @author Hervé Thouzard (www.herve-thouzard.com)
 * @copyright (c) The Xoops Project - www.xoops.org
*/
function updateCache()
{
    global $xoopsModule;
    $tpllist = array('news_item.html', 'news_archive.html', 'news_article.html', 'news_index.html', 'news_by_topic.html', 'news_by_this_author.html', 'news_ratenews.html', 'news_rss.html');
    include_once XOOPS_ROOT_PATH . "/class/xoopsblock.php";
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    // Clear blocks cache
    xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
    // Clear pages cache
    $xoopsTpl = new XoopsTpl();
    foreach ($tpllist as $onetemplate) {
        $xoopsTpl->clear_cache('db:' . $onetemplate);
    }
}
Example #9
0
function xoops_module_deactivate($mid)
{
    global $xoopsConfig;
    $module_handler =& xoops_gethandler('module');
    $module =& $module_handler->get($mid);
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($mid);
    $module->setVar('isactive', 0);
    if ($module->getVar('dirname') == "system") {
        return "<p>" . sprintf(_MD_AM_FAILDEACT, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_SYSNO . "</p>";
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
        return "<p>" . sprintf(_MD_AM_FAILDEACT, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br /> - " . _MD_AM_STRTNO . "</p>";
    } else {
        if (!$module_handler->insert($module)) {
            $ret = "<p>" . sprintf(_MD_AM_FAILDEACT, "<b>" . $module->getVar('name') . "</b>") . "&nbsp;" . _MD_AM_ERRORSC . "<br />" . $module->getHtmlErrors();
            return $ret . "</p>";
        }
        $block_handler =& xoops_gethandler('block');
        $block_handler->updateAll('isactive', 1, new Criteria('mid', $mid));
        return "<p>" . sprintf(_MD_AM_OKDEACT, "<b>" . $module->getVar('name') . "</b>") . "</p>";
    }
}
 function pico_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', 'pico_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.1 -> 0.2
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_category_permissions");
     if (!$db->query($check_sql)) {
         $db->queryF("DROP TABLE " . $db->prefix($mydirname . "_category_access"));
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_category_permissions") . " ( cat_id smallint(5) unsigned NOT NULL default 0, uid mediumint(8) default NULL, groupid smallint(5) default NULL, permissions text, UNIQUE KEY (cat_id,uid), UNIQUE KEY (cat_id,groupid), KEY (cat_id), KEY (uid), KEY (groupid)) TYPE=MyISAM");
     }
     // 0.2 -> 0.9
     $check_sql = "SELECT cat_vpath FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD   `cat_vpath` varchar(255) AFTER `cat_id`, ADD UNIQUE KEY (`cat_vpath`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD   `vpath` varchar(255) AFTER `content_id`, ADD UNIQUE KEY (`vpath`)");
     }
     // 0.9 -> 0.95
     $check_sql = "SELECT cat_vpath_mtime FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD cat_created_time int(10) NOT NULL default 0, ADD cat_modified_time int(10) NOT NULL default 0, ADD cat_vpath_mtime int(10) NOT NULL default 0");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " MODIFY weight smallint(5) NOT NULL default 0");
     }
     // 1.0 -> 1.1/1.2
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_content_histories");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_content_histories") . " ( content_history_id int(10) unsigned NOT NULL auto_increment, content_id int(10) unsigned NOT NULL default 0, vpath varchar(255), cat_id smallint(5) unsigned NOT NULL default 0, created_time int(10) NOT NULL default 0, modified_time int(10) NOT NULL default 0, poster_uid mediumint(8) unsigned NOT NULL default 0, poster_ip varchar(15) NOT NULL default '', modifier_uid mediumint(8) unsigned NOT NULL default 0, modifier_ip varchar(15) NOT NULL default '', subject varchar(255) NOT NULL default '', htmlheader mediumtext, body mediumtext, filters text, PRIMARY KEY (content_history_id), KEY (content_id), KEY (created_time), KEY (modified_time), KEY (modifier_uid) ) TYPE=MyISAM");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " MODIFY htmlheader mediumtext, MODIFY htmlheader_waiting mediumtext, MODIFY body mediumtext, MODIFY body_waiting mediumtext, MODIFY body_cached mediumtext");
     }
     // 1.1/1.2 -> 1.3/1.4
     $check_sql = "SELECT cat_redundants FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " MODIFY cat_id smallint(5) unsigned NOT NULL, ADD cat_redundants text AFTER cat_vpath_mtime");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD comments_count int(10) unsigned NOT NULL default 0 AFTER votes_count");
         $db->queryF("INSERT INTO " . $db->prefix($mydirname . "_categories") . " (cat_id,pid,cat_title) VALUES (0,0xffff,'TOP')");
     }
     // 1.3/1.4 -> 1.5/1.6
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_content_extras");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_content_extras") . " ( content_extra_id int(10) unsigned NOT NULL auto_increment, content_id int(10) unsigned NOT NULL default 0, extra_type varchar(255) NOT NULL default '', created_time int(10) NOT NULL default 0, modified_time int(10) NOT NULL default 0, data mediumtext, PRIMARY KEY (content_extra_id), KEY (content_id), KEY (extra_type), KEY (created_time) ) TYPE=MyISAM");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD `locked` tinyint(1) NOT NULL default 0 AFTER subject_waiting, ADD `redundants` text AFTER filters");
     }
     $check_sql = "SHOW CREATE TABLE " . $db->prefix($mydirname . "_content_histories");
     list(, $create_sql) = $db->fetchRow($db->queryF($check_sql));
     if (stristr($create_sql, '`body` text')) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_content_histories") . " MODIFY `htmlheader` mediumtext, MODIFY `body` mediumtext");
     }
     $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " MODIFY `cat_redundants` mediumtext");
     // 1.5/1.6 -> 1.7/1.8
     $check_sql = "SELECT cat_permission_id FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_contents") . " ADD permission_id int(10) unsigned NOT NULL default 0 AFTER `content_id`, ADD expiring_time int(10) NOT NULL default 0x7fffffff AFTER `modified_time`, ADD last_cached_time int(10) NOT NULL default 0 AFTER `modified_time`, ADD `extra_fields` mediumtext AFTER `filters`, ADD `for_search` mediumtext AFTER `redundants`, MODIFY `redundants` mediumtext, ADD `tags` text AFTER `filters`, ADD KEY (`modified_time`), ADD KEY (`expiring_time`), ADD KEY (`permission_id`)");
         $db->queryF("UPDATE " . $db->prefix($mydirname . "_contents") . " SET `expiring_time`=0x7fffffff");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_content_histories") . " ADD tags text, ADD extra_fields mediumtext");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD `cat_permission_id` int(10) unsigned NOT NULL AFTER `cat_id`, ADD KEY (`cat_permission_id`)");
         $db->queryF("UPDATE " . $db->prefix($mydirname . "_categories") . " SET `cat_permission_id`=`cat_id`");
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_tags") . " ( label varchar(255) NOT NULL default '', weight int(10) unsigned NOT NULL default 0, count int(10) unsigned NOT NULL default 0, content_ids mediumtext, created_time int(10) NOT NULL default 0, modified_time int(10) NOT NULL default 0, PRIMARY KEY (label), KEY (count), KEY (weight), KEY (created_time) ) TYPE=MyISAM");
     }
     // 1.7/1.8 -> 1.9/2.0 (1)
     $check_sql = "SELECT * FROM " . $db->prefix($mydirname . "_content_ef_sortables");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD `cat_extra_fields` mediumtext AFTER `cat_vpath_mtime`;");
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_content_ef_sortables") . " ( content_id int(10) unsigned NOT NULL default 0, ef0 char(64) NOT NULL default '', ef1 char(64) NOT NULL default '', ef2 char(64) NOT NULL default '', ef3 char(64) NOT NULL default '', ef4 char(64) NOT NULL default '', ef5 char(64) NOT NULL default '', ef6 char(64) NOT NULL default '', ef7 char(64) NOT NULL default '', ef8 char(64) NOT NULL default '', ef9 char(64) NOT NULL default '', KEY (ef0), KEY (ef1), KEY (ef2), KEY (ef3), KEY (ef4), KEY (ef5), KEY (ef6), KEY (ef7), KEY (ef8), KEY (ef9), PRIMARY KEY (content_id) ) TYPE=MyISAM");
     }
     // 1.7/1.8 -> 1.9/2.0 (2)
     // content_histories ...
     // 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)) {
                 $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) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
 function dbtheme_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', 'dbtheme_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 />';
                     }
                 }
             }
         }
     }
     // IMPORT THE SELECTED THEME AS THIS MODULE'S TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     /*************** BEGIN DBTHEME SPECIFIC PART ******************/
     // set weight=0
     $db->queryF("UPDATE " . $db->prefix("modules") . " SET weight=0 WHERE mid={$mid}");
     // set tpl_path
     $module_handler =& xoops_gethandler('module');
     $module =& $module_handler->getByDirname($mydirname);
     $config_handler =& xoops_gethandler('config');
     $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
     if (file_exists(dirname(__FILE__) . '/templates/theme.html')) {
         $tpl_path = dirname(__FILE__) . '/templates';
     } else {
         if (!empty($mod_config['base_theme'])) {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $mod_config['base_theme'];
         } else {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $GLOBALS['xoopsConfig']['theme_set'];
         }
     }
     /*************** END DBTHEME SPECIFIC PART ******************/
     // 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) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 /*************** BEGIN DBTHEME SPECIFIC PART ******************/
                 // modify the theme/css
                 $tpl_source = file_get_contents($file_path);
                 $searches = array();
                 $replacements = array();
                 if (strrchr($file, '.') == '.html') {
                     // CSS hooking
                     $searches[] = '/\\"\\<\\{\\$xoops_imageurl\\}\\>([0-9a-zA-Z_-]+)\\.(css|html|js)\\"/';
                     $replacements[] = '"<{$xoops_url}>/modules/' . $mydirname . '/?template=$1.$2' . '"';
                 } else {
                     if (strrchr($file, '.') == '.css') {
                         // url() hooking
                         $searches[] = '#url\\(\\s*([\\"\']?)([0-9a-z./]{3})#i';
                         $replacements[] = 'url($1<{$xoops_imageurl}>$2';
                     }
                 }
                 $tplfile->setVar('tpl_source', preg_replace($searches, $replacements, $tpl_source));
                 $mtime = time();
                 /*************** END DBTHEME SPECIFIC PART ******************/
                 //				$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;
 }
 function dbtheme_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', 'dbtheme_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // IMPORT THE SELECTED THEME AS THIS MODULE'S TEMPLATES
     $tplfile_handler =& xoops_gethandler('tplfile');
     /*************** BEGIN DBTHEME SPECIFIC PART ******************/
     $module_handler =& xoops_gethandler('module');
     $module =& $module_handler->getByDirname($mydirname);
     $config_handler =& xoops_gethandler('config');
     $mod_config =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
     if (file_exists(dirname(__FILE__) . '/templates/theme.html')) {
         $tpl_path = dirname(__FILE__) . '/templates';
     } else {
         if (!empty($mod_config['base_theme'])) {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $mod_config['base_theme'];
         } else {
             $tpl_path = XOOPS_ROOT_PATH . '/themes/' . $GLOBALS['xoopsConfig']['theme_set'];
         }
     }
     /*************** END DBTHEME SPECIFIC PART ******************/
     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) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = intval(@filemtime($file_path));
                 $tplfile =& $tplfile_handler->create();
                 /*************** BEGIN DBTHEME SPECIFIC PART ******************/
                 $tpl_source = file_get_contents($file_path);
                 $searches = array();
                 $replacements = array();
                 if (strrchr($file, '.') == '.html') {
                     // CSS hooking
                     $searches[] = '/\\"\\<\\{\\$xoops_imageurl\\}\\>([0-9a-zA-Z_-]+)\\.(css|html|js)\\"/';
                     $replacements[] = '"<{$xoops_url}>/modules/' . $mydirname . '/?template=$1.$2' . '"';
                 } else {
                     if (strrchr($file, '.') == '.css') {
                         // url() hooking
                         $searches[] = '#url\\(\\s*([\\"\']?)([0-9a-z./]{3})#i';
                         $replacements[] = 'url($1<{$xoops_imageurl}>$2';
                     }
                 }
                 $tplfile->setVar('tpl_source', preg_replace($searches, $replacements, $tpl_source));
                 $mtime = time();
                 /*************** END DBTHEME SPECIFIC PART ******************/
                 //				$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) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
Example #13
0
 function gnavi_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', 'gnavi_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     $check_sql = "SELECT arrowhtml FROM " . $db->prefix("{$mydirname}_text");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_text") . " ADD arrowhtml tinyint(1) NOT NULL default '0',ADD addinfo text");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE icd icd int(5) unsigned NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE icd icd int(5) unsigned NOT NULL default '0'");
     }
     //version 0.13 -> version 0.7
     $check_sql = "SELECT * FROM " . $db->prefix("{$mydirname}_photos") . " USE INDEX(submitter)";
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " ADD INDEX (submitter)");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE lat tmp_lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE lng lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " CHANGE tmp_lat lng double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE lat tmp_lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE lng lat double(9,6) NOT NULL default '0'");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " CHANGE tmp_lat lng double(9,6) NOT NULL default '0'");
     }
     //version 0.8 -> version 0.9
     $check_sql = "SELECT mtype FROM " . $db->prefix("{$mydirname}_photos");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " ADD mtype varchar(30) NOT NULL default ''");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " ADD mtype varchar(30) NOT NULL default ''");
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_cat") . " ADD   kmlurl varchar(150) NOT NULL default ''");
     }
     //version 0.95 -> version 0.96
     $check_sql = "SELECT rss FROM " . $db->prefix("{$mydirname}_photos");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix("{$mydirname}_photos") . " ADD rss varchar(255) NOT NULL default ''");
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler =& xoops_gethandler('tplfile');
     // block templete must alldelete (for update from V2 module)
     $templates =& $tplfile_handler->find(null, 'block', null, $mydirname);
     $tcount = count($templates);
     if ($tcount > 0) {
         $ret[] = 'Deleting templates...';
         for ($i = 0; $i < $tcount; $i++) {
             if (!$tplfile_handler->delete($templates[$i])) {
                 $msgs[] = '<span style="color:#ff0000;">ERROR: Could not delete template ' . $templates[$i]->getVar('tpl_file', 's') . ' from the database. Template ID: <b>' . $templates[$i]->getVar('tpl_id', 's') . '</b></span><br />';
             } else {
                 $msgs[] = 'Template <b>' . $templates[$i]->getVar('tpl_file', 's') . '</b> deleted from the database. Template ID: <b>' . $templates[$i]->getVar('tpl_id', 's') . '</b><br />';
             }
         }
     }
     unset($templates);
     $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)) {
                     $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
Example #14
0
    function xelfinder_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', 'xelfinder_message_append_onupdate');
            $msgs = array();
        } else {
            if (!is_array($msgs)) {
                $msgs = array();
            }
        }
        $db =& Database::getInstance();
        $mid = $module->getVar('mid');
        // TABLES (write here ALTER TABLE etc. if necessary)
        $query = "SELECT `gids` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `gids` VARCHAR( 255 ) NOT NULL');
        }
        // check last update version
        $cache_dir = (defined('XOOPS_MODULE_PATH') ? XOOPS_MODULE_PATH : XOOPS_ROOT_PATH . '/modules') . '/' . $mydirname . '/cache';
        $lastupdate = 0;
        if (file_exists($cache_dir . '/lastupdate.dat')) {
            $lastupdate = @unserialize(file_get_contents($cache_dir . '/lastupdate.dat'));
        }
        if (!is_numeric($lastupdate)) {
            $lastupdate = 0;
        }
        file_put_contents($cache_dir . '/lastupdate.dat', serialize($module->getVar('version')));
        // from v 0.10
        if ($lastupdate < 10) {
            $query = "SELECT `mime_filter` FROM " . $db->prefix($mydirname . "_file");
            if (!$db->query($query)) {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `mime_filter` VARCHAR( 255 ) NOT NULL');
            }
        }
        // from v 0.13
        if ($lastupdate < 13) {
            $query = "SHOW COLUMNS FROM `" . $db->prefix($mydirname . "_file") . "` LIKE 'mime'";
            $res = $db->query($query);
            $dat = $db->fetchArray($res);
            if ($dat['Type'] !== 'varchar(255)') {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mime` `mime` varchar(255) NOT NULL DEFAULT \'unknown\'');
            }
        }
        // from v 0.17
        if ($lastupdate < 17) {
            $query = "SELECT `id` FROM " . $db->prefix($mydirname . "_userdat");
            if (!$db->query($query)) {
                $db->queryF('CREATE TABLE `' . $db->prefix($mydirname . '_userdat') . '`' . '(
				  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
				  `uid` int(10) unsigned NOT NULL,
				  `key` varchar(255) NOT NULL,
				  `data` blob NOT NULL,
				  `mtime` int(10) unsigned NOT NULL,
				  PRIMARY KEY (`id`),
				  KEY `uid_key` (`uid`,`key`)
				) ENGINE=MyISAM');
            }
        }
        //from v0.22
        if ($lastupdate < 22) {
            $query = "SELECT `local_path` FROM " . $db->prefix($mydirname . "_file");
            if (!$db->query($query)) {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `local_path` VARCHAR( 255 ) NOT NULL');
            }
        }
        //from v0.66 add default value for strict mode
        if ($lastupdate < 66) {
            $query = "SHOW COLUMNS FROM `" . $db->prefix($mydirname . "_file") . "` LIKE 'parent_id'";
            $res = $db->query($query);
            $dat = $db->fetchArray($res);
            if ($dat['Default'] === NULL) {
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `parent_id` `parent_id` INT( 10 ) UNSIGNED NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `name` `name` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `size` `size` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `ctime` `ctime` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mtime` `mtime` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `perm` `perm` varchar(3) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `uid` `uid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `gid` `gid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `home_of` `home_of` int(10) DEFAULT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `width` `width` int(11) NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `height` `height` int(11) NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `gids` `gids` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mime_filter` `mime_filter` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `local_path` `local_path` varchar(255) NOT NULL DEFAULT \'\'');
                // link
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `file_id` `file_id` int(11) NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `mid` `mid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `param` `param` varchar(25) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `val` `val` varchar(25) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_link") . '` CHANGE `title` `title` varchar(255) NOT NULL DEFAULT \'\'');
                // userdat
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_userdat") . '` CHANGE `uid` `uid` int(10) unsigned NOT NULL DEFAULT \'0\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_userdat") . '` CHANGE `key` `key` varchar(255) NOT NULL DEFAULT \'\'');
                $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_userdat") . '` CHANGE `mtime` `mtime` int(10) unsigned NOT NULL DEFAULT \'0\'');
            }
        }
        // for version < 0.99 remove unless tmb file
        if ($lastupdate < 99) {
            $msgs[] = 'checking unless tmbs (Version < 0.99)';
            $tmbdir = $cache_dir . '/tmb';
            $_res = false;
            if ($handle = opendir($tmbdir)) {
                while (false !== ($entry = readdir($handle))) {
                    if (preg_match('/^[a-zA-Z]{1,2}[0-9]{1,3}_.+\\.png$/', $entry)) {
                        //$msgs[] = $tmbdir.'/'.$entry;
                        $_res = @unlink($tmbdir . '/' . $entry);
                    }
                }
            }
            if ($_res) {
                $msgs[] = 'removed unless tmbs';
            }
        }
        if ($lastupdate < 166) {
            $msgs[] = 'ALTER TABLE file `home_of` and fix data (Version < 1.66)';
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `home_of` `home_of` INT(10) NULL DEFAULT NULL');
            $db->queryF('UPDATE `' . $db->prefix($mydirname . "_file") . '` SET `home_of` = NULL WHERE `home_of` = 0 AND `mime` != \'directory\'');
        }
        if ($lastupdate < 182) {
            $msgs[] = 'ALTER TABLE file `home_of` Add Index (Version < 1.82)';
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD INDEX home_of( home_of )');
        }
        // 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)) {
                    $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);
        return true;
    }
Example #15
0
function xoops_module_update_mpmanager(&$module)
{
    global $xoopsConfig, $xoopsDB, $xoopsUser, $xoopsModule;
    if (file_exists(XOOPS_ROOT_PATH . "/modules/mpmanager/language/" . $xoopsConfig['language'] . "/admin.php")) {
        include XOOPS_ROOT_PATH . "/modules/mpmanager/language/" . $xoopsConfig['language'] . "/admin.php";
    } else {
        include XOOPS_ROOT_PATH . "/modules/mpmanager/language/english/admin.php";
    }
    $xoopsDB->queryF("UPDATE " . $xoopsDB->prefix('modules') . " SET weight = 0 WHERE mid = " . $module->getVar('mid') . "");
    if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
        if (!TableExists($xoopsDB->prefix('priv_msgs'))) {
            $xoopsDB->queryFromFile(XOOPS_ROOT_PATH . "/modules/mpmanager/sql/mysqlmsg.sql");
        }
        //mise ajour table message
        if (!FieldExists('msg_pid', $xoopsDB->prefix('priv_msgs'))) {
            $result = $xoopsDB->queryF("ALTER TABLE `" . $xoopsDB->prefix('priv_msgs') . "` ADD msg_pid MEDIUMINT( 8 ) UNSIGNED DEFAULT '0' NOT NULL AFTER msg_id");
        }
        if (!FieldExists('reply_msg', $xoopsDB->prefix('priv_msgs'))) {
            $sq1 = $xoopsDB->queryF("ALTER TABLE `" . $xoopsDB->prefix('priv_msgs') . "` ADD reply_msg TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL AFTER read_msg");
        }
        if (!FieldExists('anim_msg', $xoopsDB->prefix('priv_msgs'))) {
            $sq1 = $xoopsDB->queryF("ALTER TABLE `" . $xoopsDB->prefix('priv_msgs') . "` ADD anim_msg VARCHAR(100) AFTER reply_msg");
        }
        if (!FieldExists('cat_msg', $xoopsDB->prefix('priv_msgs'))) {
            $sq1 = $xoopsDB->queryF("ALTER TABLE `" . $xoopsDB->prefix('priv_msgs') . "` ADD cat_msg MEDIUMINT( 8 ) UNSIGNED DEFAULT '1' NOT NULL AFTER anim_msg");
        }
        if (!FieldExists('file_msg', $xoopsDB->prefix('priv_msgs'))) {
            $sq1 = $xoopsDB->queryF("ALTER TABLE `" . $xoopsDB->prefix('priv_msgs') . "` ADD file_msg MEDIUMINT( 8 ) UNSIGNED DEFAULT '0' NOT NULL AFTER cat_msg");
        }
        //mise a jour message
        if (TableExists($xoopsDB->prefix('priv_msgsave'))) {
            $sq2 = "SELECT * FROM " . $xoopsDB->prefix('priv_msgsave') . "";
            $result2 = $xoopsDB->query($sq2);
            while ($row = $xoopsDB->fetchArray($result2)) {
                $sql = "INSERT INTO `" . $xoopsDB->prefix("priv_msgs") . "` (msg_id, msg_image,subject,from_userid,to_userid,msg_time,msg_text,read_msg,reply_msg,anim_msg,cat_msg,file_msg) VALUES('','" . $row['msg_image'] . "','" . $row['subject'] . "','" . $row['sauv_userid'] . "','" . $row['to_userid'] . "','" . $row['msg_time'] . "','" . $row['msg_text'] . "','" . $row['read_msg'] . "','" . $row['reply_msg'] . "','" . $row['anim_msg'] . "', '3','') ";
                $result = $xoopsDB->queryF($sql);
            }
            $result = $xoopsDB->queryF("DROP TABLE `" . $xoopsDB->prefix("priv_msgsave") . "`");
        }
        //add table priv_msgscat
        if (!TableExists($xoopsDB->prefix('priv_msgscat'))) {
            $xoopsDB->queryFromFile(XOOPS_ROOT_PATH . "/modules/mpmanager/sql/mysqlcat.sql");
        }
        $sq1 = $xoopsDB->queryF("INSERT INTO `" . $xoopsDB->prefix('priv_msgscat') . "` (`cid`, `pid`, `title`, `uid`, `ver`) VALUES (1, 0, '" . _MP_BOX1 . "', NULL, 1)");
        $sq1 = $xoopsDB->queryF("INSERT INTO `" . $xoopsDB->prefix('priv_msgscat') . "` (`cid`, `pid`, `title`, `uid`, `ver`) VALUES (2, 0, '" . _MP_BOX2 . "', NULL, 1)");
        $sq1 = $xoopsDB->queryF("INSERT INTO `" . $xoopsDB->prefix('priv_msgscat') . "` (`cid`, `pid`, `title`, `uid`, `ver`) VALUES (3, 0, '" . _MP_BOX3 . "', NULL, 1)");
        //add and update priv_msgscont
        if (!TableExists($xoopsDB->prefix('priv_msgscont'))) {
            $xoopsDB->queryFromFile(XOOPS_ROOT_PATH . "/modules/mpmanager/sql/mysqlcont.sql");
        } else {
            if (!FieldExists('ct_name', $xoopsDB->prefix('priv_msgscont'))) {
                $sql = "ALTER TABLE `" . $xoopsDB->prefix("priv_msgscont") . "` ADD `ct_name` varchar(60) NOT NULL default '' AFTER `ct_contact`";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('ct_uname', $xoopsDB->prefix('priv_msgscont'))) {
                $sql = "ALTER TABLE `" . $xoopsDB->prefix("priv_msgscont") . "` ADD `ct_uname` varchar(25) NOT NULL default '' AFTER `ct_name`";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('ct_regdate', $xoopsDB->prefix('priv_msgscont'))) {
                $sql = "ALTER TABLE `" . $xoopsDB->prefix("priv_msgscont") . "` ADD `ct_regdate` int(10) NOT NULL default '0' AFTER `ct_uname`";
                $result = $xoopsDB->queryF($sql);
            }
            $sq3 = "SELECT * FROM " . $xoopsDB->prefix('priv_msgscont') . "";
            $result3 = $xoopsDB->query($sq3);
            while ($row = $xoopsDB->fetchArray($result3)) {
                $poster = new XoopsUser($row['ct_contact']);
                $sql = "UPDATE `" . $xoopsDB->prefix('priv_msgscont') . "` SET ct_name='" . $poster->getVar('name') . "', ct_uname='" . $poster->getVar('uname') . "', ct_regdate='" . $poster->getVar('user_regdate') . "' WHERE ct_contact='" . $row['ct_contact'] . "'";
                $result = $xoopsDB->queryF($sql);
            }
        }
        ////add and update tables priv_msgsopt
        if (!TableExists($xoopsDB->prefix('priv_msgsopt'))) {
            $xoopsDB->queryFromFile(XOOPS_ROOT_PATH . "/modules/mpmanager/sql/mysqlopt.sql");
        } else {
            if (!FieldExists('resend', $xoopsDB->prefix('priv_msgsopt'))) {
                $sql = "ALTER TABLE `" . $xoopsDB->prefix("priv_msgsopt") . "` ADD `resend` tinyint(1) NOT NULL default '0'";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('limite', $xoopsDB->prefix('priv_msgsopt'))) {
                $sq1 = "ALTER TABLE `" . $xoopsDB->prefix("priv_msgsopt") . "` ADD `limite` tinyint(2) default NULL";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('home', $xoopsDB->prefix('priv_msgsopt'))) {
                $sql = "ALTER TABLE " . $xoopsDB->prefix("priv_msgsopt") . " ADD `home` tinyint(2) DEFAULT '1' NOT NULL AFTER `limite`";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('sortname', $xoopsDB->prefix('priv_msgsopt'))) {
                $sql = "ALTER TABLE " . $xoopsDB->prefix("priv_msgsopt") . " ADD `sortname` varchar(15) AFTER `home`";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('sortorder', $xoopsDB->prefix('priv_msgsopt'))) {
                $sql = "ALTER TABLE " . $xoopsDB->prefix("priv_msgsopt") . " ADD `sortorder` varchar(15) AFTER `sortname`";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('vieworder', $xoopsDB->prefix('priv_msgsopt'))) {
                $sql = "ALTER TABLE " . $xoopsDB->prefix("priv_msgsopt") . " ADD `vieworder` varchar(15) AFTER `sortorder`";
                $result = $xoopsDB->queryF($sql);
            }
            if (!FieldExists('formtype', $xoopsDB->prefix('priv_msgsopt'))) {
                $sql = "ALTER TABLE " . $xoopsDB->prefix("priv_msgsopt") . " ADD `formtype` tinyint(1) AFTER `vieworder`";
                $result = $xoopsDB->queryF($sql);
            }
        }
        //add and update tables priv_msgsup
        if (!TableExists($xoopsDB->prefix('priv_msgsup'))) {
            $xoopsDB->queryFromFile(XOOPS_ROOT_PATH . "/modules/mpmanager/sql/mysqlup.sql");
            //update priv_msgsup
            $sq5 = "SELECT * FROM " . $xoopsDB->prefix('priv_msgs') . "WHERE file_msg !='' ";
            $result5 = $xoopsDB->query($sq5);
            while ($row = $xoopsDB->fetchArray($result5)) {
                $result = $xoopsDB->queryF("INSERT INTO `" . $xoopsDB->prefix("priv_msgsup") . "` (`msg_id`, `u_id`, `u_name`, `u_mimetype`, `u_file`, `u_file`, `u_weight`) VALUES ('', " . $row['msg_id'] . ", " . $row['file_msg'] . ", '', " . $row['file_msg'] . ", '')");
                $sql = "UPDATE " . $xoopsDB->prefix('priv_msgs') . " SET file_msg=1 WHERE msg_id='" . $row['msg_id'] . "'";
            }
            //update file_msg
            $sql = "ALTER TABLE " . $xoopsDB->prefix("priv_msgs") . " CHANGE `file_msg` `file_msg` MEDIUMINT(8) NOT NULL DEFAULT '0'";
            $result = $xoopsDB->queryF($sql);
        }
    }
    xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
    $tpllist = array('mp_box.html', 'mp_contbox.html', 'mp_filebox.html', 'mp_index.html', 'mp_msgbox.html', 'mp_optionbox.html', 'mp_subox.html', 'mp_viewbox.html', 'mp_block_cont.html', 'mp_block_new.html');
    $xoopsTpl = new XoopsTpl();
    foreach ($tpllist as $onetemplate) {
        $xoopsTpl->clear_cache('db:' . $onetemplate);
    }
    return true;
}
Example #16
0
/**
 * @param $mid
 *
 * @return string
 */
function xoops_module_deactivate($mid)
{
    global $xoopsConfig;
    // Get module handler
    $module_handler = xoops_getHandler('module');
    $module = $module_handler->get($mid);
    include_once XOOPS_ROOT_PATH . '/class/template.php';
    xoops_template_clear_module_cache($mid);
    // Display header
    $msgs[] = '<div id="xo-module-log">';
    $msgs .= xoops_module_log_header($module, _AM_SYSTEM_MODULES_DEACTIVATE);
    // Change value
    $module->setVar('isactive', 0);
    if ($module->getVar('dirname') === 'system') {
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_SYSNO . '</p>';
    } elseif ($module->getVar('dirname') == $xoopsConfig['startpage']) {
        $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br> - ' . _AM_SYSTEM_MODULES_STRTNO . '</p>';
    } else {
        if (!$module_handler->insert($module)) {
            $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . $module->getHtmlErrors() . '</p>';
        } else {
            $blocks = XoopsBlock::getByModule($module->getVar('mid'));
            $bcount = count($blocks);
            for ($i = 0; $i < $bcount; ++$i) {
                $blocks[$i]->setVar('isactive', 0);
                $blocks[$i]->store();
            }
            $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_OKDEACT, '<strong>' . $module->getVar('name') . '</strong>') . '</p>';
        }
    }
    $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>';
    $ret = implode('<br>', $msgs);
    return $ret;
}
Example #17
0
 /**
  * @param $module
  * @param $mydirname
  *
  * @return bool
  */
 function protector_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', 'protector_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = 'SHOW COLUMNS FROM ' . $db->prefix('config') . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] === 'varchar(30)') {
         $db->queryF('ALTER TABLE ' . $db->prefix('config') . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     list(, $create_string) = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $db->prefix('config')));
     foreach (explode('KEY', $create_string) as $line) {
         if (preg_match('/(\\`conf\\_title_\\d+\\`) \\(\\`conf\\_title\\`\\)/', $line, $regs)) {
             $db->query('ALTER TABLE ' . $db->prefix('config') . ' DROP KEY ' . $regs[1]);
         }
     }
     $db->query('ALTER TABLE ' . $db->prefix('config') . ' ADD KEY `conf_title` (`conf_title`)');
     // 2.x -> 3.0
     list(, $create_string) = $db->fetchRow($db->query('SHOW CREATE TABLE ' . $db->prefix($mydirname . '_log')));
     if (preg_match('/timestamp\\(/i', $create_string)) {
         $db->query('ALTER TABLE ' . $db->prefix($mydirname . '_log') . ' MODIFY `timestamp` DATETIME');
     }
     // TEMPLATES (all templates have been already removed by modulesadmin)
     $tplfile_handler = xoops_getHandler('tplfile');
     $tpl_path = __DIR__ . '/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) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) {
                 $mtime = (int) @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) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
Example #18
0
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("&nbsp;- ", $selector_arr)."')";
			return $db->query($sql);
		}
		else{
			return false;
		}
	}
	return true;
}
 function d3forum_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', 'd3forum_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;
 }
Example #20
0
 function d3diary_onupdate_base($module, $mydirname)
 {
     // transations on module update
     global $msgs;
     // TODO :-D
     require dirname(__FILE__) . '/class/d3diaryConf.class.php';
     $d3dConf =& D3diaryConf::getInstance($mydirname, 0, "onupdate");
     $func =& $d3dConf->func;
     // for Cube 2.1
     if (defined('XOOPS_CUBE_LEGACY')) {
         $root =& XCube_Root::getSingleton();
         $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'd3diary_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT blogtype FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD blogtype tinyint(3) NOT NULL default '0' AFTER corder");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD blogurl text AFTER blogtype");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD rss text AFTER blogurl");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD openarea tinyint(3) NOT NULL AFTER rss");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT openarea FROM " . $db->prefix($mydirname . "_diary");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD openarea tinyint(3) unsigned NOT NULL AFTER create_time");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT cid FROM " . $db->prefix($mydirname . "_newentry");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " ADD cid int(10) unsigned NOT NULL default '0' AFTER uid");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " DROP PRIMARY KEY");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " ADD PRIMARY KEY (uid,cid)");
     }
     // 0.01 -> 0.01
     $check_sql = "SELECT tag_id FROM " . $db->prefix($mydirname . "_tag");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_tag") . " ( tag_id int(11) unsigned NOT NULL auto_increment, tag_name varchar(64) NOT NULL default '',\tbid int(11) unsigned NOT NULL default '0', uid mediumint(8) unsigned NOT NULL default '0',\ttag_group int(11) unsigned NOT NULL default '0', reg_unixtime int(11) unsigned NOT NULL default '0', PRIMARY KEY  (tag_id), KEY (tag_name), KEY (bid), KEY (uid) ) ENGINE=MyISAM");
     }
     // 0.01 -> 0.01
     // deleted dayly cout up
     $db->queryF("DELETE FROM " . $db->prefix($mydirname . "_cnt") . " WHERE ymd<>'1111-11-11'");
     // 0.05 -> 0.06
     // add dohtml
     $check_sql = "SELECT dohtml FROM " . $db->prefix($mydirname . "_diary");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD dohtml tinyint(1) unsigned NOT NULL AFTER openarea");
     }
     $check_sql = "SELECT dohtml FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD dohtml tinyint(1) unsigned NOT NULL AFTER openarea");
     }
     // 0.11a2 -> 0.11a3
     // add subcategory
     $check_sql = "SELECT subcat FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD subcat tinyint(1) unsigned NOT NULL default '0' AFTER corder");
     }
     // 0.11a3 -> 0.12
     // add group and personal permissions
     $check_sql = "SELECT vgids FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD vgids varchar(255) default NULL AFTER dohtml");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " ADD vpids varchar(255) default NULL AFTER vgids");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD vgids varchar(255) default NULL AFTER dohtml");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD vpids varchar(255) default NULL AFTER vgids");
     }
     // add page view
     $check_sql = "SELECT view FROM " . $db->prefix($mydirname . "_diary");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " ADD view int(10) unsigned NOT NULL default '0' AFTER vpids");
     }
     // 0.12b2 -> 0.12b3
     // add photo info
     $check_sql = "SELECT info FROM " . $db->prefix($mydirname . "_photo");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_photo") . " ADD info text AFTER tstamp");
     }
     // 0.13c -> 0.14
     // cppy tag registered unixtime from each diary's create_time
     $sql = "SELECT t.tag_id, d.create_time FROM " . $db->prefix($mydirname . "_tag") . " t \n\t\t\t\tINNER JOIN " . $db->prefix($mydirname . "_diary") . " d USING(bid) \n\t\t\t\tWHERE t.bid=d.bid AND t.reg_unixtime='0'";
     if ($result = $db->query($sql)) {
         while ($dbdat = $db->fetchArray($result)) {
             $ctime = preg_split("/[-: ]/", $dbdat['create_time']);
             $tstamp = mktime($ctime[3], $ctime[4], $ctime[5], $ctime[1], $ctime[2], $ctime[0]);
             $sql = "UPDATE " . $db->prefix($mydirname . "_tag") . " SET \n\t\t\t\t\treg_unixtime='" . $tstamp . "' WHERE tag_id='" . $dbdat['tag_id'] . "'";
             $irs = $db->query($sql);
         }
     }
     // 0.15 -> 0.16
     // add mail post
     $check_sql = "SELECT mailpost FROM " . $db->prefix($mydirname . "_config");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `mailpost` tinyint(1) unsigned NOT NULL default '0' AFTER openarea");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `address` varchar(255) NOT NULL default '' AFTER mailpost");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `keep` tinyint(1) NOT NULL default '0' AFTER address");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `uptime` int(10) unsigned NOT NULL default '0' AFTER keep");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD `updated` int(10) unsigned NOT NULL default '0' AFTER uptime");
     }
     // 0.18
     // modify photo `tstamp` column data type from timestamp to datetime
     $result = $db->query("SELECT `tstamp` FROM " . $db->prefix($mydirname . "_photo"));
     static $link = null;
     if (is_null($link)) {
         //$db = XoopsDatabaseFactory::getDatabaseConnection();
         $link = is_object($db->conn) && get_class($db->conn) === 'mysqli' ? $db->conn : false;
     }
     if ($link) {
         $field_info = mysqli_fetch_field_direct($result, 0);
         $field_type = $field_info->type;
     } else {
         $field_type = mysql_field_type($result, 0);
     }
     if ($field_type == "timestamp") {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_photo") . " modify `tstamp` datetime NOT NULL");
         // for NULL tstamp, copy from diary's create_time
         $sql = "UPDATE " . $db->prefix($mydirname . "_photo") . " p \n\t\t\t\tINNER JOIN " . $db->prefix($mydirname . "_diary") . " d USING(bid) \n\t\t\t\tSET p.tstamp=d.create_time WHERE (p.tstamp IS NULL) OR (p.tstamp = '0000-00-00 00:00:00')";
         $result = $db->queryF($sql);
     }
     // 0.28 -> 0.29
     // add indexes for tables
     $check_sql = "SHOW INDEX FROM " . $db->prefix($mydirname . "_category") . " WHERE Key_name='idx_uid'";
     $result = $db->query($check_sql);
     $dbdat = $db->fetchArray($result);
     if (!$dbdat) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " \n\t\t\tADD KEY idx_uid (`uid`,`cid`,`blogtype`,`openarea`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_config") . " \n\t\t\tADD KEY idx_uid (`uid`,`blogtype`,`openarea`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_diary") . " \n\t\t\tADD KEY idx_uid (`uid`,`cid`,`openarea`,`create_time`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_newentry") . " \n\t\t\tADD KEY idx_uid (`uid`,`cid`,`blogtype`,`create_time`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_photo") . " \n\t\t\tADD KEY idx_uid (`uid`)");
     }
     $check_sql = "SHOW INDEX FROM " . $db->prefix($mydirname . "_cnt_ip") . " WHERE Column_name='acctime'";
     $result = $db->query($check_sql);
     $dbdat = $db->fetchArray($result);
     if (!$dbdat) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_cnt_ip") . " \n\t\t\tADD KEY `acctime` (`acctime`)");
     }
     // 0.44 -> 0.45
     // add show whole detail on the index page
     $check_sql = "SELECT showoption FROM " . $db->prefix($mydirname . "_category");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_category") . " \n\t\t\tADD `showoption` tinyint(1) unsigned NOT NULL default '0' AFTER openarea");
     }
     // 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)) {
                 $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>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</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>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . $func->htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
Example #21
0
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[] = '&nbsp;&nbsp;Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4]) . '</b> created.<br />';
                    $created_tables[] = $prefixed_query[4];
                } else {
                    $ret[] = '&nbsp;&nbsp;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;
}
Example #22
0
    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) . "</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) . "</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 />';
                        }
                    }
                }
            }
        }
        // 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`)
)');
        }
        // 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) . '</b> to the database.</span>';
                    } else {
                        $tplid = $tplfile->getVar('tpl_id');
                        $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                        } else {
                            $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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;
    }
Example #23
0
 function attachfile_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', 'attachfile_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // non
     // 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)) {
                 $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) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
 function d3forum_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', 'd3forum_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.1x -> 0.2x
     $check_sql = "SELECT cat_unique_path FROM " . $db->prefix($mydirname . "_categories");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_categories") . " ADD cat_unique_path text NOT NULL default '' AFTER cat_path_in_tree");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_forums") . " ADD forum_external_link_format varchar(255) NOT NULL default '' AFTER cat_id");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_topics") . " ADD topic_external_link_id int(10) unsigned NOT NULL default 0 AFTER forum_id, ADD KEY (`topic_external_link_id`)");
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_posts") . " ADD path_in_tree text NOT NULL default '' AFTER order_in_tree , ADD unique_path text NOT NULL default '' AFTER order_in_tree");
     }
     // 0.3x -> 0.4x
     $check_sql = "SELECT subject_waiting FROM " . $db->prefix($mydirname . "_posts");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_posts") . " ADD subject_waiting varchar(255) NOT NULL default '' AFTER `subject`, ADD post_text_waiting text NOT NULL AFTER `post_text`, ADD uid_hidden mediumint(8) unsigned NOT NULL default 0 AFTER `uid`, DROP hide_uid");
     }
     // 0.4x/0.6x -> 0.7x
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix($mydirname . "_topics") . " LIKE 'topic_external_link_id'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && substr(@$myrow['Type'], 0, 3) == 'int') {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_topics") . " MODIFY topic_external_link_id varchar(255) NOT NULL default ''");
     }
     $check_sql = "SELECT COUNT(*) FROM " . $db->prefix($mydirname . "_post_histories");
     if (!$db->query($check_sql)) {
         $db->queryF("CREATE TABLE " . $db->prefix($mydirname . "_post_histories") . " ( history_id int(10) unsigned NOT NULL auto_increment, post_id int(10) unsigned NOT NULL default 0, history_time int(10) NOT NULL default 0, data text, PRIMARY KEY (history_id), KEY (post_id) ) TYPE=MyISAM");
     }
     // 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)) {
                 $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) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                     } else {
                         $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
     return true;
 }
Example #25
0
function dbcss_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', 'dbcss_message_append_onupdate' ) ;
		$msgs = array() ;
	} else {
		if( ! is_array( $msgs ) ) $msgs = array() ;
	}

	$db =& Database::getInstance() ;
	$mid = $module->getVar('mid') ;

	// TABLES (write here ALTER TABLE etc. if necessary)

	// 0.6 -> 0.7
	$check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_metalink") ;
	if( ! $db->query( $check_sql ) ) {
		$db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_metalink")." (lid int(10) NOT NULL default '0', metakey text NOT NULL, metadesc text NOT NULL, robots varchar(100) NOT NULL default '', rating varchar(100) NOT NULL default '', author varchar(255) NOT NULL default '', UNIQUE KEY lid (lid)) TYPE=MyISAM" ) ;
	}

	// 0.8 -> 0.9
	$check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_scriptbody") ;
	if( ! $db->query( $check_sql ) ) {
		$db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_scriptbody")." (lid mediumint(5) unsigned NOT NULL auto_increment, title varchar(255) NOT NULL default '', created int(10) NOT NULL default '0', body text NOT NULL, css text NOT NULL, UNIQUE KEY lid (lid)) TYPE=MyISAM;" ) ;
	}

	// 0.9 -> 1.0
	$check_sql = "SELECT COUNT(*) FROM ".$db->prefix($mydirname."_cssexport") ;
	if( ! $db->query( $check_sql ) ) {
		$db->queryF( "CREATE TABLE ".$db->prefix($mydirname."_cssexport")." (lid int(10) NOT NULL default '0', exportdir varchar(255) NOT NULL default '', UNIQUE KEY lid (lid)
) TYPE=MyISAM;" ) ;
	}

	// configs (Though I know it is not a recommended way...)
	$check_sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
	if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && @$myrow['Type'] == 'varchar(30)' ) {
		$db->queryF( "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''" ) ;
	}

	// configs (Though I know it is not a recommended way...)
	$check_sql = "SHOW COLUMNS FROM ".$db->prefix("config")." LIKE 'conf_title'" ;
	if( ( $result = $db->query( $check_sql ) ) && ( $myrow = $db->fetchArray( $result ) ) && @$myrow['Type'] == 'varchar(30)' ) {
		$db->queryF( "ALTER TABLE ".$db->prefix("config")." MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''" ) ;
	}

	// TEMPLATES (all templates have been already removed by modulesadmin)
	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
	include_once XOOPS_ROOT_PATH.'/class/template.php' ;

	$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 ) ) {
					$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
				} else {
					$tplid = $tplfile->getVar( 'tpl_id' ) ;
					$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
					// generate compiled file
					if( ! xoops_template_touch( $tplid ) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
					} else {
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
					}
				}
			}
		}
		closedir( $handler ) ;
	}

	/*************** BEGIN DBCSS SPECIFIC PART ******************/
	// CSS TEMPLATES
	if( file_exists( XOOPS_TRUST_PATH.'/uploads/'.$mydirname ) ) {
		$CSS_path = XOOPS_TRUST_PATH.'/uploads/'.$mydirname ;

		if( $handler = @opendir( $CSS_path . '/' ) ) {
			while( ( $file = readdir( $handler ) ) !== false ) {
				if( substr( $file , 0 , 1 ) == '.' ) continue ;
				$file_path = $CSS_path . '/' . $file ;
				if ( is_file( $file_path ) && substr( $file , -4 ) == '.css'){
					$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).'</b> to the database.</span>';
					} else {
						$tplid = $tplfile->getVar( 'tpl_id' ) ;
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
						// generate compiled file
						if( ! xoops_template_touch( $tplid ) ) {
							$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
						} else {
							$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
						}
					}
				}
			}
		}
		closedir( $handler ) ;
	}
	xoops_template_clear_module_cache( $mid ) ;
	/*************** END DBCSS SPECIFIC PART ******************/

	return true ;
}
Example #26
0
	xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
	redirect_header("index.php",1,_AM_DBUPDATED);
	exit();
}

if ( $op == "log" ) {
	xoops_cp_header();
	echo "<h4>"._AM_POLLCONF."</h4>";
	echo "<br>View Log<br> Sorry, not yet. ;-)";
	xoops_cp_footer();
	exit();
}

if ( $op == "quickupdate" ) {
	$count = count($poll_id);
	for ( $i = 0; $i < $count; $i++ ) {
		$display[$i] = empty($display[$i]) ? 0 : 1;
		$weight[$i] = empty($weight[$i]) ? 0 : $weight[$i];
		if ( $display[$i] != $old_display[$i] || $weight[$i] != $old_weight[$i] ) {
			$poll = new XoopsPoll($poll_id[$i]);
			$poll->setVar("display", $display[$i]);
			$poll->setVar("weight", intval($weight[$i]));
			$poll->store();
		}
	}
	include_once XOOPS_ROOT_PATH.'/class/template.php';
	xoops_template_clear_module_cache($xoopsModule->getVar('mid'));
	redirect_header("index.php",1,_AM_DBUPDATED);
	exit();
}
?>
Example #27
0
    function xelfinder_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', 'xelfinder_message_append_onupdate');
            $msgs = array();
        } else {
            if (!is_array($msgs)) {
                $msgs = array();
            }
        }
        $db =& Database::getInstance();
        $mid = $module->getVar('mid');
        // TABLES (write here ALTER TABLE etc. if necessary)
        $query = "SELECT `gids` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `gids` VARCHAR( 255 ) NOT NULL');
        }
        // from v 0.10
        $query = "SELECT `mime_filter` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `mime_filter` VARCHAR( 255 ) NOT NULL');
        }
        // from v 0.13
        $query = "SHOW COLUMNS FROM `" . $db->prefix($mydirname . "_file") . "` LIKE 'mime'";
        $res = $db->query($query);
        $dat = $db->fetchArray($res);
        if ($dat['Type'] !== 'varchar(255)') {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` CHANGE `mime` `mime` varchar(255) NOT NULL DEFAULT \'unknown\'');
        }
        // from v 0.17
        $query = "SELECT `id` FROM " . $db->prefix($mydirname . "_userdat");
        if (!$db->query($query)) {
            $db->queryF('CREATE TABLE `' . $db->prefix($mydirname . '_userdat') . '`' . '(
				  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
				  `uid` int(10) unsigned NOT NULL,
				  `key` varchar(255) NOT NULL,
				  `data` blob NOT NULL,
				  `mtime` int(10) unsigned NOT NULL,
				  PRIMARY KEY (`id`),
				  KEY `uid_key` (`uid`,`key`)
				) ENGINE=MyISAM');
        }
        //from v0.22
        $query = "SELECT `local_path` FROM " . $db->prefix($mydirname . "_file");
        if (!$db->query($query)) {
            $db->queryF('ALTER TABLE `' . $db->prefix($mydirname . "_file") . '` ADD `local_path` VARCHAR( 255 ) NOT NULL');
        }
        // 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)) {
                    $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) . '</b> to the database.</span>';
                    } else {
                        $tplid = $tplfile->getVar('tpl_id');
                        $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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) . '</b>.</span>';
                        } else {
                            $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</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);
        return true;
    }
 function d3pipes_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', 'd3pipes_message_append_onupdate');
         $msgs = array();
     } else {
         if (!is_array($msgs)) {
             $msgs = array();
         }
     }
     $db =& Database::getInstance();
     $mid = $module->getVar('mid');
     // TABLES (write here ALTER TABLE etc. if necessary)
     // configs (Though I know it is not a recommended way...)
     $check_sql = "SHOW COLUMNS FROM " . $db->prefix("config") . " LIKE 'conf_title'";
     if (($result = $db->query($check_sql)) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] == 'varchar(30)') {
         $db->queryF("ALTER TABLE " . $db->prefix("config") . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''");
     }
     // 0.2 -> 0.3
     $check_sql = "SELECT comments_count FROM " . $db->prefix($mydirname . "_clippings");
     if (!$db->query($check_sql)) {
         $db->queryF("ALTER TABLE " . $db->prefix($mydirname . "_clippings") . " ADD comments_count smallint NOT NULL default 0 AFTER `weight`");
     }
     // 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)) {
                 $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) . '</b> to the database.</span>';
                 } else {
                     $tplid = $tplfile->getVar('tpl_id');
                     $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)';
                     require_once XOOPS_TRUST_PATH . '/libs/altsys/include/altsys_functions.php';
                     altsys_clear_templates_c();
                     // 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).'</b>.</span>';
                     		} else {
                     			$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</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);
     return true;
 }
Example #29
0
function bulletin_onupdate_base( $module, $prev_version , $mydirname )
{
	global $msgs, $xoopsDB, $xoopsUser, $xoopsConfig ;

	// for Cube 2.1
	if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
		$isCube = true ;
		$root =& XCube_Root::getSingleton();
		$root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'bulletin_message_append_onupdate' ) ;
		$msgs = array() ;
	} else {
		$isCube = false ;
		if( ! is_array( $msgs ) ) $msgs = array() ;
	}

	$db =& Database::getInstance() ;
	$mid = $module->getVar('mid') ;


	// transations on module update
	// TABLES (write here ALTER TABLE etc. if necessary)
	if( $prev_version < 200 ){

		$msgs[] = 'Executing compatible programs... (ver '. $prev_version / 100 .' to 2.x)';

		$sql = sprintf("SHOW TABLES LIKE '%s'", $xoopsDB->prefix("{$mydirname}_relation") );
		list($result) = $xoopsDB->fetchRow($xoopsDB->query($sql));
		if( empty($result) ){
			$sql = "CREATE TABLE `".$xoopsDB->prefix("{$mydirname}_relation")."` (  `storyid` int(8) NOT NULL default '0',  `linkedid` int(8) NOT NULL default '0',  `dirname` varchar(25) NOT NULL default '') ENGINE=MyISAM;";
			if( $xoopsDB->query($sql) ){
				$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($xoopsDB->prefix("{$mydirname}_relation")).'</b> created.';
			}else{
				$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
			}
		}else{
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Table <b>'.htmlspecialchars($result).'</b> already exsits.</span>';
		}

		$sql = sprintf("SHOW COLUMNS FROM %s LIKE 'block'", $xoopsDB->prefix("{$mydirname}_stories") );
		list($result) = $xoopsDB->fetchRow($xoopsDB->query($sql));
		if( empty($result) ){
			$sql = sprintf("ALTER TABLE %s ADD `block` TINYINT( 1 ) DEFAULT '1'", $xoopsDB->prefix("{$mydirname}_stories") );
			if( $xoopsDB->query($sql) ){
				$msgs[] = '&nbsp;&nbsp;Column <b>block</b> added.';
			}else{
				$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
			}
		}else{
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Column <b>block</b> already exsits.</span>';
		}

		// This is Duplication V2 compatibility...
		if( preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ){
			$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;

			$sql = sprintf("SHOW TABLES LIKE '%s%%'", str_replace('_','\_',$xoopsDB->prefix("bulletin{$mydirnumber}_")) );
			$result = $xoopsDB->query($sql);
			while(list($table) = $xoopsDB->fetchRow($result)){
				$sql = "SELECT * FROM ".$xoopsDB->prefix('modules')." WHERE dirname = 'bulletin{$mydirnumber}'";

				list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
				if($count == 0){
					$renamed = preg_replace('/^' .$xoopsDB->prefix("bulletin{$mydirnumber}"). '/i', $xoopsDB->prefix($mydirname), $table);
					$sql = "ALTER TABLE `".addslashes($table)."` RENAME `".addslashes($renamed)."` ";
					if( $xoopsDB->query($sql) ){
						$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($table).'</b> is renamed into <b>'.htmlspecialchars($renamed).'</b>.';
					}else{
						$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Failed to rename table <b>'.htmlspecialchars($table).'</b></span>';
					}
				}
			}
		}
	}
	// update table structure from 2.04
	$check_rs = $db->query( "SELECT topic_created FROM ".$db->prefix($mydirname.'_topics') ) ;
	if( empty( $check_rs ) ) {
		$db->queryF( "ALTER TABLE ".$db->prefix($mydirname.'_topics')." ADD `topic_created` int(10) unsigned NOT NULL default 0, ADD `topic_modified` int(10) unsigned NOT NULL default 0, MODIFY `topic_imgurl` varchar(255) NOT NULL default '', MODIFY `topic_title` varchar(255) NOT NULL default ''" ) ;
		$db->queryF( "ALTER TABLE ".$db->prefix($mydirname.'_stories')." MODIFY `uid` mediumint(8) unsigned NOT NULL default 0" ) ;
		$db->queryF( "ALTER TABLE ".$db->prefix($mydirname.'_relation')." ADD KEY (`storyid`), ADD PRIMARY KEY (`storyid`,`linkedid`,`dirname`)" ) ;
	}
//ver2.22->ver3.0
	$sql = sprintf("SHOW TABLES LIKE '%s'", $db->prefix("{$mydirname}_topic_access") );
	list($result) = $db->fetchRow($db->query($sql));
	if( empty($result) ){
		$sql ="CREATE TABLE ".$db->prefix("{$mydirname}_topic_access")." (
		topic_id smallint(5) unsigned NOT NULL default 0,
		uid mediumint(8) default NULL,
		groupid smallint(5) default NULL,
		can_post tinyint(1) NOT NULL default 0,
		can_edit tinyint(1) NOT NULL default 0,
		can_delete tinyint(1) NOT NULL default 0,
		post_auto_approved tinyint(1) NOT NULL default 0,
		UNIQUE KEY (topic_id,uid),
		UNIQUE KEY (topic_id,groupid),
		KEY (topic_id),
		KEY (uid),
		KEY (groupid),
		KEY (can_post)
		) ENGINE=MyISAM;
		";
		if( $db->query($sql) ){
			$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($db->prefix("{$mydirname}_topic_access")).'</b> created.';
		}else{
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
		}
//ver2.22->ver3.0  creat data to topic_access
		$can_groups = array();
		$can_read_topic_id = array();
		$topic_access_data = "";
		$sql = "SELECT gperm_groupid FROM ".$db->prefix('group_permission');
		$sql .= " WHERE gperm_itemid = ".$mid;
		$sql .= " AND gperm_modid = 1";
		$sql .= " AND gperm_name = 'module_read'";
		$result = $db->query($sql);
		if (empty($result)){
			$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
		}else{
			while ($myrow = $db->fetchArray($result)) {
				$can_groups[$myrow['gperm_groupid']]['can_read'] = 1;
				$can_groups[$myrow['gperm_groupid']]['can_post'] = 0;
				$can_groups[$myrow['gperm_groupid']]['can_edit'] = 0;
				$can_groups[$myrow['gperm_groupid']]['can_delete'] = 0;
				$can_groups[$myrow['gperm_groupid']]['post_auto_approved'] = 0;
			}
			if (!empty($can_groups)){
				//ca_post,post_auto_approved
				$sql = "SELECT * FROM ".$db->prefix('group_permission');
				$sql .= " WHERE gperm_modid = ".$mid;
				$sql .= " AND gperm_name = 'bulletin_permit'";
				$result = $db->query($sql);
				if (empty($result)){
					$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
				}else{
					while ($myrow = $db->fetchArray($result)) {
						if(isset($can_groups[$myrow['gperm_groupid']])){
							switch ($myrow['gperm_itemid']) {
							case 1:
								$can_groups[$myrow['gperm_groupid']]['can_post'] = 1;
								break;
							case 2:
								$can_groups[$myrow['gperm_groupid']]['post_auto_approved'] = 1;
								break;
							}
						}
					}
					$sql = "SELECT gperm_groupid FROM ".$db->prefix('group_permission');
					$sql .= " WHERE gperm_itemid = ".$mid;
					$sql .= " AND gperm_modid = 1";
					$sql .= " AND gperm_name = 'module_admin'";
					$result = $db->query($sql);
					if (empty($result)){
						$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
					}else{
						while ($myrow = $db->fetchArray($result)) {
							if(isset($can_groups[$myrow['gperm_groupid']])){
								$can_groups[$myrow['gperm_groupid']]['can_post'] = 1;
								$can_groups[$myrow['gperm_groupid']]['can_edit'] = 1;
								$can_groups[$myrow['gperm_groupid']]['can_delete'] = 1;
								$can_groups[$myrow['gperm_groupid']]['post_auto_approved'] = 1;
							}
						}
						$sql = "SELECT topic_id FROM ".$db->prefix("{$mydirname}_topics");
						$result = $db->query($sql);
						if (empty($result)){
							$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
						}else{
							while ($myrow = $db->fetchArray($result)) {
								$can_read_topic_id[] = $myrow['topic_id'];
							}
							if (!empty($can_read_topic_id)){
								foreach ($can_read_topic_id as $topic_id) {
									foreach ($can_groups as $groupid => $value) {
										$sql = "INSERT INTO `".$db->prefix("{$mydirname}_topic_access")."`";
										$sql .= " (`topic_id`, `uid`, `groupid`, `can_post`, `can_edit`, `can_delete`, `post_auto_approved`)";
										$sql .= " VALUES (".$topic_id.", NULL, ".$groupid.", ".$value['can_post'].", ".$value['can_edit'].", ".$value['can_delete'].", ".$value['post_auto_approved'].")";
										if ($db->query($sql)){
											$msgs[] = '&nbsp;&nbsp;Table <b>'.htmlspecialchars($db->prefix("{$mydirname}_topic_access")).'</b> add '.$topic_id.' for group '.$groupid ;
										}else{
											$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">Invalid SQL <b>'.htmlspecialchars($sql).'</b></span>';
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	// 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).'</b> to the database.</span>';
				} else {
					$tplid = $tplfile->getVar( 'tpl_id' ) ;
					$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</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).'</b>.</span>';
					} else {
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</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 ) ;

	// 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;
				$tpl_source = file_get_contents( $file_path );
				$sql = "SELECT tpl_id, tpl_refid FROM ".$db->prefix('tplfile')." WHERE tpl_module='$mydirname' AND tpl_file='".mysql_escape_string($tpl_file)."'";
				list($tpl_id, $block_id) = $db->fetchRow($db->query($sql));
				if( empty($tpl_id) && empty($block_id)){
					$blocks_info = $module->getInfo('blocks');
					$show_func = '';
					foreach($blocks_info as $oneblock){
						if($tpl_file == $oneblock['template']){
							$show_func = $oneblock['show_func'];
							break;
						}
					}
					if( $show_func != ''){
						$sql = sprintf("SELECT bid FROM %s WHERE dirname=%s AND show_func=%s", $db->prefix("newblocks"), $db->quoteString($mydirname), $db->quoteString($show_func) ) ;
						list($block_id) = $xoopsDB->fetchRow($xoopsDB->query($sql));
						if($block_id){
							$tplfile =& $tplfile_handler->create();
							$tplfile->setVar('tpl_module', $mydirname);
							$tplfile->setVar('tpl_refid', $block_id);
							$tplfile->setVar('tpl_source', $tpl_source, true);
							$tplfile->setVar('tpl_tplset', 'default');
							$tplfile->setVar('tpl_file', $tpl_file, true);
							$tplfile->setVar('tpl_type', 'block');
							$tplfile->setVar('tpl_lastimported', 0);
							$tplfile->setVar('tpl_lastmodified', time());
							$tplfile->setVar('tpl_desc', '', true);
							if (!$tplfile_handler->insert($tplfile)) {
								$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Could not insert template <b>'.$tpl_file.'</b> to the database.</span>';
							} else {
								$newid = $tplfile->getVar('tpl_id');
								$msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl_file.'</b> added to the database.';
								if ($xoopsConfig['template_set'] == 'default') {
									if (!xoops_template_touch($block_id)) {
										$msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">ERROR: Template <b>'.$tpl_file.'</b> recompile failed.</span>';
									} else {
										$msgs[] = '&nbsp;&nbsp;Template <b>'.$tpl_file.'</b> recompiled.';
									}
								}
							}
							$sql = "UPDATE ".$db->prefix("newblocks")." SET template='".mysql_escape_string($tpl_file)."', last_modified=".time()." WHERE bid=".$block_id;
							if( !$result = $db->query($sql) ) {
								$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
							}else{
								$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$newid.'</b>)';
							}
						}
					}
				}
				elseif (!empty($tpl_id) && isset($tpl_source) && $tpl_source != '') {
					$sql = "SELECT COUNT(*) FROM ".$db->prefix('tplsource')." WHERE tpl_id='$tpl_id'";
					list($count) = $xoopsDB->fetchRow($xoopsDB->query($sql));
					if($count==0){
						$sql = sprintf("INSERT INTO %s (tpl_id, tpl_source) VALUES (%u, %s)", $db->prefix('tplsource'), $tpl_id, $db->quoteString($tpl_source));
					}else{
						$sql = "UPDATE ".$db->prefix("tplsource")." SET tpl_source='".mysql_escape_string($tpl_source)."' WHERE tpl_id=".$tpl_id;
					}
					if( !$result = $db->query($sql) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
					} else {
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tpl_id.'</b>)';
						// generate compiled file
						include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
						include_once XOOPS_ROOT_PATH.'/class/template.php';
						if( ! xoops_template_touch( $tpl_id ) ) {
							$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
						} else {
							$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
						}
					}
					$sql = "UPDATE ".$db->prefix("newblocks")." SET template='".mysql_escape_string($tpl_file)."', last_modified=".time()." WHERE bid=".$block_id;
					if( !$result = $db->query($sql) ) {
						$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
					}else{
						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tpl_id.'</b>)';
					}
				}
			}
		}
		closedir( $handler ) ;
	}

	return true ;
}
Example #30
0
function modules_install_function($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);
        $module->setVar('isactive', 1);
        $module->setVar('last_update', time());
        $error = false;
        $errs = array();
        $msgs = array();
        $msgs[] = '<div id="xo-module-log"><div class="header">';
        $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . $module->getInfo('name', 's') . '</h4>';
        if ($module->getInfo('image') != false && trim($module->getInfo('image')) != '') {
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim($module->getInfo('image')) . '" alt="" /></a>';
        }
        $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . '&nbsp;' . $module->getInfo('module_status');
        if ($module->getInfo('author') != false && trim($module->getInfo('author')) != '') {
            $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim($module->getInfo('author')));
        }
        $msgs[] = '</div><div class="logger">';
        // 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(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>';
                $errs = array_merge($errs, $module->getErrors());
            } else {
                $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_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(_AM_SYSTEM_MODULES_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
                    $error = true;
                } else {
                    $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . "<br  />" . _AM_SYSTEM_MODULES_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(_AM_SYSTEM_MODULES_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[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_TABLE_CREATED, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
                                    $created_tables[] = $prefixed_query[4];
                                } else {
                                    $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA, "<strong>" . $db->prefix($prefixed_query[4]) . "</strong>");
                                }
                            }
                        } else {
                            // the table name is reserved, so halt the installation
                            $errs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_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(_AM_SYSTEM_MODULES_INSERT_DATA_FAILD, "<strong>" . $module->getVar('name') . "</strong>");
                foreach ($created_tables as $ct) {
                    $db->query("DROP TABLE " . $db->prefix($ct));
                }
                $ret = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILINS, "<strong>" . $module->name() . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_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>" . _AM_SYSTEM_MODULES_INSERT_DATA_DONE . sprintf(_AM_SYSTEM_MODULES_MODULEID, "<strong>" . $newmid . "</strong>");
                $tplfile_handler =& xoops_gethandler('tplfile');
                $templates = $module->getInfo('templates');
                if ($templates != false) {
                    $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_ADD;
                    foreach ($templates as $tpl) {
                        $tplfile =& $tplfile_handler->create();
                        $type = isset($tpl['type']) ? $tpl['type'] : 'module';
                        $tpldata =& xoops_module_gettemplate($dirname, $tpl['file'], $type);
                        $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', time());
                        $tplfile->setVar('tpl_type', $type);
                        if (!$tplfile_handler->insert($tplfile)) {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>" . $tpl['file'] . "</strong>") . "</span>";
                        } else {
                            $newtplid = $tplfile->getVar('tpl_id');
                            $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, "<strong>" . $tpl['file'] . "</strong>") . "</span>";
                            } else {
                                $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_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[] = _AM_SYSTEM_MODULES_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']) && is_string($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'], 'blocks');
                        }
                        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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR, "<strong>" . $block['name'] . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR_DATABASE, "<strong>" . $db->error() . "</strong>") . "</span>";
                        } else {
                            if (empty($newbid)) {
                                $newbid = $db->getInsertId();
                            }
                            $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD, "<strong>" . $block['name'] . "</strong>") . sprintf(_AM_SYSTEM_MODULES_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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, "<strong>" . $block['template'] . "</strong>") . "</span>";
                                } else {
                                    $newtplid = $tplfile->getVar('tpl_id');
                                    $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, "<strong>" . $block['template'] . "</strong>") . "</span>";
                                    } else {
                                        $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_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 &quot;
                    $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[] = _AM_SYSTEM_MODULES_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', isset($config['description']) ? $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 />&nbsp;&nbsp;&nbsp;&nbsp; ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> ';
                                unset($confop);
                            }
                        }
                        $order++;
                        if ($config_handler->insertConfig($confobj) != false) {
                            $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, "<strong>" . $config['name'] . "</strong>") . $confop_msgs;
                        } else {
                            $msgs[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_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[] = _AM_SYSTEM_MODULES_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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>";
                    } else {
                        $msgs[] = "&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>";
                } else {
                    $msgs[] = '&nbsp;&nbsp;' . sprintf(_AM_SYSTEM_MODULES_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[] = '&nbsp;&nbsp;<span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
                    } else {
                        $msgs[] = '&nbsp;&nbsp;' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(_AM_SYSTEM_MODULES_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(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . "</p>";
                } else {
                    $msgs[] = "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . "</p>";
                    if (is_string($lastmsg)) {
                        $msgs[] = $lastmsg;
                    }
                }
            }
            $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKINS, '<strong>' . $module->getVar('name', 's') . '</strong>');
            $msgs[] = '</div></div>';
            $blocks = $module->getInfo('blocks');
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> |
                        <a href="admin.php?fct=modulesadmin&op=installlist">' . _AM_SYSTEM_MODULES_TOINSTALL . '</a> | ';
            $msgs[] = '<br /><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . $module->getInfo('name') . ': </span></div>';
            if ($blocks != false) {
                $msgs[] = '<div class="center"><a href="admin.php?fct=blocksadmin&op=list&filter=1&selgen=' . $newmid . '&selmod=-2&selgrp=-1&selvis=-1&filsave=1">' . _AM_SYSTEM_BLOCKS . '</a></div>';
            }
            $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>';
            $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a>';
            $testdataDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata';
            if (file_exists($testdataDirectory)) {
                $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata/index.php' . '">' . _AM_SYSTEM_MODULES_INSTALL_TESTDATA . '</a></div>';
            } else {
                $msgs[] = '</div>';
            }
            $ret = implode('<br />', $msgs);
            unset($blocks);
            unset($msgs);
            unset($errs);
            unset($module);
            return $ret;
        } else {
            $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . '&nbsp;' . _AM_SYSTEM_MODULES_ERRORSC . '<br />' . implode("<br />", $errs) . '</p>';
            unset($msgs);
            unset($errs);
            return $ret;
        }
    } else {
        return "<p>" . sprintf(_AM_SYSTEM_MODULES_FAILINS, "<strong>" . $dirname . "</strong>") . "&nbsp;" . _AM_SYSTEM_MODULES_ERRORSC . "<br />&nbsp;&nbsp;" . sprintf(_AM_SYSTEM_MODULES_ALEXISTS, $dirname) . "</p>";
    }
}