function update_block_permissions($old_gid, $new_gid) { // get handlers $gperm_handler =& xoops_gethandler('groupperm'); $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname('xoonips'); $mid = $module->getVar('mid'); $block_objs =& XoopsBlock::getByModule($mid); foreach ($block_objs as $block_obj) { // find moderator menu block if ($block_obj->getVar('show_func') == 'b_xoonips_moderator_show') { $bid = $block_obj->getVar('bid'); // if old_gid don't have module admin right, // delete the right to access from old_gid. if (!$gperm_handler->checkRight('module_admin', $mid, $old_gid)) { $criteria = new CriteriaCompo(); $criteria->add(new Criteria('gperm_groupid', $old_gid)); $criteria->add(new Criteria('gperm_itemid', $bid)); $criteria->add(new Criteria('gperm_name', 'block_read')); $gperm_handler->deleteAll($criteria); } // if there is no right to access moderator block in new_gid, // the right gives new_gid. if (!$gperm_handler->checkRight('block_read', $bid, $new_gid)) { $gperm_handler->addRight('block_read', $bid, $new_gid); } break; } } }
function xoops_module_install_sysutil(&$module) { $gperm_handler =& xoops_gethandler('groupperm'); $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', XOOPS_GROUP_ANONYMOUS); $mperm->setVar('gperm_itemid', $module->getVar('mid')); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); $gperm_handler->insert($mperm); unset($mperm); $blocks =& XoopsBlock::getByModule($module->getVar('mid'), false); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', XOOPS_GROUP_ANONYMOUS); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); $gperm_handler->insert($bperm); unset($bperm); } unset($blocks); $module_handler =& xoops_gethandler('module'); $module->setVar('weight', 0); $module->unsetNew(); $module_handler->insert($module); return true; }
function get_block_title($mid, $fname, $sfunc) { $block_objs =& XoopsBlock::getByModule($mid); $block_title = ''; foreach ($block_objs as $block_obj) { $func_file = $block_obj->getVar('func_file', 'n'); $show_func = $block_obj->getVar('show_func', 'n'); if ($func_file == $fname && $show_func == $sfunc) { // found $block_title = $block_obj->getVar('title', 's'); break; } } return $block_title; }
foreach ($group_defs as $def) { if (strstr($def, '_AM_ACCESSRIGHTS') || strstr($def, '_AM_ACTIVERIGHTS')) { eval($def); } } // check $xoopsModule if (!is_object($xoopsModule)) { redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); } // check access right (needs system_admin of BLOCK) $sysperm_handler =& xoops_gethandler('groupperm'); if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) { redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); } // get blocks owned by the module $block_arr =& XoopsBlock::getByModule($xoopsModule->mid()); function list_blocks() { global $block_arr; // cachetime options $cachetimes = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH); // displaying TH echo "\r\n\t<form action='admin.php' name='blockadmin' method='post'>\r\n\t\t<table width='90%' class='outer' cellpadding='4' cellspacing='1'>\r\n\t\t<tr valign='middle'>\r\n\t\t\t<th>" . _AM_TITLE . "</th>\r\n\t\t\t<th align='center' nowrap='nowrap'>" . _AM_SIDE . "</th>\r\n\t\t\t<th align='center'>" . _AM_WEIGHT . "</th>\r\n\t\t\t<th align='center'>" . _AM_VISIBLEIN . "</th>\r\n\t\t\t<th align='center'>" . _AM_BCACHETIME . "</th>\r\n\t\t\t<th align='right'>" . _AM_ACTION . "</th>\r\n\t\t</tr>\n"; // blocks displaying loop $class = 'even'; foreach (array_keys($block_arr) as $i) { $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = ""; $weight = $block_arr[$i]->getVar("weight"); $title = $block_arr[$i]->getVar("title"); $name = $block_arr[$i]->getVar("name"); $bcachetime = $block_arr[$i]->getVar("bcachetime");
$tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_desc', $blocks[$i]['description'], true); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not insert template <b>' . $blocks[$i]['template'] . '</b> to the database.</span>'; } else { $msgs[] = ' Template <b>' . $blocks[$i]['template'] . '</b> inserted to the database.'; } } $msgs[] = ' Block <b>' . $blocks[$i]['name'] . '</b> created. Block ID: <b>' . $newbid . '</b>'; } } } } } $block_arr = XoopsBlock::getByModule($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", $xoopsDB->prefix('newblocks'), $block->getVar('bid')); if (!$xoopsDB->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">ERROR: Could not delete block <b>' . $block->getVar('name') . '</b>. Block ID: <b>' . $block->getVar('bid') . '</b></span>'; } else { $msgs[] = ' Block <b>' . $block->getVar('name') . ' deleted. Block ID: <b>' . $block->getVar('bid') . '</b>'; } } } $configs = $modules[$mid]->getInfo('config'); if ($configs != false) { if ($modules[$mid]->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_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)));
/** * Clear the module cache * * @deprecated * * @param int $mid Module ID * @return **/ function xoops_template_clear_module_cache($mid) { $block_arr =& XoopsBlock::getByModule($mid); $count = count($block_arr); if ($count > 0) { $xoopsTpl = new XoopsTpl(); $xoopsTpl->xoops_setCaching(2); for ($i = 0; $i < $count; $i++) { if ($block_arr[$i]->getVar('template') != '') { $xoopsTpl->clear_cache('db:' . $block_arr[$i]->getVar('template'), 'blk_' . $block_arr[$i]->getVar('bid')); } } } }
function &_get_block_object_bymodule_id($mid, $asobject = true) { if (defined('ICMS_VERSION_BUILD') && ICMS_VERSION_BUILD > 27) { /* ImpressCMS 1.2+ */ $block_handler =& xoops_gethandler('block'); $objs =& $block_handler->getByModule($mid, $asobject); } else { /* legacy support */ $objs =& XoopsBlock::getByModule($mid, $asobject); /* from class/xoopsblock.php */ } return $objs; }
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>") . " " . _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>") . " " . _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>") . " " . _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 xoops_module_update($dirname) { global $xoopsConfig, $xoopsDB; $dirname = trim($dirname); $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname($dirname); // Save current version for use in the update function $prev_version = $module->getVar('version'); include_once XOOPS_ROOT_PATH . '/class/template.php'; $xoopsTpl = new XoopsTpl(); $xoopsTpl->clearCache($dirname); //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); $log = ''; if (!$module_handler->insert($module)) { $log .= sprintf(__('Could not update %s', 'rmcommon'), $module->getVar('name')); } else { $newmid = $module->getVar('mid'); $msgs = array(); $msgs[] = sprintf(__('Updating module %s', 'rmcommon'), $module->getVar('name')); $tplfile_handler =& xoops_gethandler('tplfile'); $deltpl = $tplfile_handler->find('default', 'module', $module->getVar('mid')); $delng = array(); if (is_array($deltpl)) { // 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[] = __('Updating templates...', 'rmcommon'); 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[] = ' <span style="color:#ff0000;">' . sprintf(__('Template %s could not be inserted!', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } else { $newid = $tplfile->getVar('tpl_id'); $msgs[] = ' ' . sprintf(__('Template %s inserted to the database.', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>"); if ($xoopsConfig['template_set'] == 'default') { if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not recompile template %s', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } else { $msgs[] = ' <span>' . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } } } unset($tpldata); } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not delete old template %s. Aborting update of this file.', 'rmcommon'), "<strong>" . $tpl['file'] . "</strong>") . '</span>'; } } } $blocks = $module->getInfo('blocks'); $msgs[] = __('Rebuilding blocks...', 'rmcommon'); if ($blocks != false) { $showfuncs = array(); $funcfiles = array(); foreach ($blocks as $i => $block) { if (isset($block['show_func']) && $block['show_func'] != '' && isset($block['file']) && $block['file'] != '') { $editfunc = isset($block['edit_func']) ? $block['edit_func'] : ''; $showfuncs[] = $block['show_func']; $funcfiles[] = $block['file']; $template = ''; if (isset($block['template']) && trim($block['template']) != '') { $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks'); } if (!$content) { $content = ''; } else { $template = $block['template']; } $options = ''; if (!empty($block['options'])) { $options = $block['options']; } $sql = "SELECT bid, name FROM " . $xoopsDB->prefix('newblocks') . " WHERE mid=" . $module->getVar('mid') . " AND func_num=" . $i . " AND show_func='" . addslashes($block['show_func']) . "' AND func_file='" . addslashes($block['file']) . "'"; $fresult = $xoopsDB->query($sql); $fcount = 0; while ($fblock = $xoopsDB->fetchArray($fresult)) { $fcount++; $sql = "UPDATE " . $xoopsDB->prefix("newblocks") . " SET name='" . addslashes($block['name']) . "', edit_func='" . addslashes($editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . " WHERE bid=" . $fblock['bid']; $result = $xoopsDB->query($sql); if (!$result) { $msgs[] = " " . sprintf(__('ERROR: Could not update %s'), $fblock['name']); } else { $msgs[] = " " . sprintf(__('Block %s updated.', 'rmcommon'), $fblock['name']) . sprintf(__('Block ID: %s', 'rmcommon'), "<strong>" . $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', $fblock['bid']); $tplfile_new->setVar('tpl_tplset', 'default'); $tplfile_new->setVar('tpl_file', $block['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', $block['description'], true); $tplfile_new->setVar('tpl_lastmodified', time()); $tplfile_new->setVar('tpl_lastimported', 0); if (!$tplfile_handler->insert($tplfile_new)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not update %s template.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = " " . sprintf(__('Template %s updated.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); if ($xoopsConfig['template_set'] == 'default') { if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not recompile template %s', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = " " . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); } } } } } } if ($fcount == 0) { $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq'); $block_name = addslashes($block['name']); $block_type = $module->getVar('dirname') == 'system' ? 'S' : 'M'; $sql = "INSERT INTO " . $xoopsDB->prefix("newblocks") . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (" . $newbid . ", " . $module->getVar('mid') . ", " . $i . ",'" . addslashes($options) . "','" . $block_name . "', '" . $block_name . "', '', 0, 0, 0, '{$block_type}', 1, '" . addslashes($dirname) . "', '" . addslashes($block['file']) . "', '" . addslashes($block['show_func']) . "', '" . addslashes($editfunc) . "', '" . $template . "', " . time() . ")"; $result = $xoopsDB->query($sql); if (!$result) { $msgs[] = ' ' . sprintf(_('ERROR: Could not create %s', 'rmcommon'), $block['name']); $log .= $sql; } else { if (empty($newbid)) { $newbid = $xoopsDB->getInsertId(); } if ($module->getInfo('hasMain')) { $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); } else { $groups = array(XOOPS_GROUP_ADMIN); } $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $newbid); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">' . __('ERROR: Could not add block access right', 'rmcommon') . ' ' . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>") . ' ' . sprintf(__('Group ID: %s', 'rmcommon'), "<strong>" . $mygroup . "</strong>") . '</span>'; } else { $msgs[] = ' ' . __('Added block access right', 'rmcommon') . ' ' . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>") . ' ' . sprintf(__('Group ID: %s', 'rmcommon'), "<strong>" . $mygroup . "</strong>"); } } if ($template != '') { $tplfile =& $tplfile_handler->create(); $tplfile->setVar('tpl_module', $dirname); $tplfile->setVar('tpl_refid', $newbid); $tplfile->setVar('tpl_source', $content, true); $tplfile->setVar('tpl_tplset', 'default'); $tplfile->setVar('tpl_file', $block['template'], true); $tplfile->setVar('tpl_type', 'block'); $tplfile->setVar('tpl_lastimported', 0); $tplfile->setVar('tpl_lastmodified', time()); $tplfile->setVar('tpl_desc', $block['description'], true); if (!$tplfile_handler->insert($tplfile)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not insert template %s to the database.', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $newid = $tplfile->getVar('tpl_id'); $msgs[] = ' ' . sprintf(__('Template %s added to the database', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); if ($xoopsConfig['template_set'] == 'default') { if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Template %s recompile failed', 'rmcommon'), "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = ' ' . sprintf(__('Template %s recompiled', 'rmcommon'), "<strong>" . $block['template'] . "</strong>"); } } } } $msgs[] = ' ' . sprintf(__('Block %s created', 'rmcommon'), "<strong>" . $block['name'] . "</strong>") . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $newbid . "</strong>"); $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $xoopsDB->query($sql); } } } } $block_arr = XoopsBlock::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", $xoopsDB->prefix('newblocks'), $block->getVar('bid')); if (!$xoopsDB->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not delete block %s', 'rmcommon'), "<strong>" . $block->getVar('name') . "</strong>") . sprintf(__("Block ID: %s", 'rmcommon'), "<strong>" . $block->getVar('bid') . "</strong>") . '</span>'; } else { $msgs[] = ' Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>'; 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[] = ' <span style="color:#ff0000;">' . __('ERROR: Could not remove deprecated block template.', 'rmcommon') . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>'; } else { $msgs[] = ' ' . sprintf(__('Block template %s deprecated', 'rmcommon'), "<strong>" . $tplfiles[$k]->getVar('tpl_file') . "</strong>"); } } } } } } } } // reset compile_id $xoopsTpl->setCompileId(); // first delete all config entries $config_handler =& xoops_gethandler('config'); $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid'))); $confcount = count($configs); $config_delng = array(); if ($confcount > 0) { $msgs[] = __('Deleting module config options...', 'rmcommon'); for ($i = 0; $i < $confcount; $i++) { if (!$config_handler->deleteConfig($configs[$i])) { $msgs[] = ' <span style="color:#ff0000;">' . __('ERROR: Could not delete config data from the database', 'rmcommon') . sprintf(__('Config ID: %s', 'rmcommon'), "<strong>" . $configs[$i]->getvar('conf_id') . "</strong>") . '</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[] = " " . __('Config data deleted from the database.', 'rmcommon') . ' ' . sprintf(__('Config ID: %s', 'rmcommon'), "<strong>" . $configs[$i]->getVar('conf_id') . "</strong>"); } } } // now reinsert them with the new settings $configs = $module->getInfo('config'); // Include if ($configs != false) { if ($module->getVar('hascomments') != 0) { include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; array_push($configs, array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN))); array_push($configs, array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0)); } } else { if ($module->getVar('hascomments') != 0) { $configs = array(); include_once XOOPS_ROOT_PATH . '/include/comment_constants.php'; $configs[] = array('name' => 'com_rule', 'title' => '_CM_COMRULES', 'description' => '', 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN)); $configs[] = array('name' => 'com_anonpost', 'title' => '_CM_COMANONPOST', 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 0); } } // RMV-NOTIFY if ($module->getVar('hasnotification') != 0) { if (empty($configs)) { $configs = array(); } // Main notification options include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; include_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $options = array(); $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); $configs[] = array('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLE', 'description' => '_NOT_CONFIG_ENABLEDSC', 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $options); // Event specific notification options // FIXME: for some reason the default doesn't come up properly // initially is ok, but not when 'update' module.. $options = array(); $categories =& notificationCategoryInfo('', $module->getVar('mid')); foreach ($categories as $category) { $events =& notificationEvents($category['name'], false, $module->getVar('mid')); foreach ($events as $event) { if (!empty($event['invisible'])) { continue; } $option_name = $category['title'] . ' : ' . $event['title']; $option_value = $category['name'] . '-' . $event['name']; $options[$option_name] = $option_value; //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($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 =& xoops_gethandler('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', $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 /> ' . __('Config option added', 'rmcommon') . ' ' . __('Name:', 'rmcommon') . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . __('Value:', 'rmcommon') . ' <strong>' . $value . '</strong> '; unset($confop); } } $order++; if (false != $config_handler->insertConfig($confobj)) { //$msgs[] = ' Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs; $msgs[] = " " . sprintf(__('Config %s added to the database', 'rmcommon'), "<strong>" . $config['name'] . "</strong>") . $confop_msgs; } else { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(__('ERROR: Could not insert config %s to the database.', 'rmcommon'), "<strong>" . $config['name'] . "</strong>") . '</span>'; } unset($confobj); } } unset($configs); } // execute module specific update script if any $update_script = $module->getInfo('onUpdate'); if (false != $update_script && trim($update_script) != '') { include_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim($update_script); if (function_exists('xoops_module_update_' . $dirname)) { $func = 'xoops_module_update_' . $dirname; if (!$func($module, $prev_version)) { $msgs[] = "<p>" . sprintf(__('Failed to execute %s', 'rmcommon'), $func) . "</p>"; } else { $msgs[] = "<p>" . sprintf(__('%s executed successfully.', 'rmcommon'), "<strong>" . $func . "</strong>") . "</p>"; } } } foreach ($msgs as $msg) { $log .= $msg . '<br />'; } $log .= "<p>" . sprintf(__('Module %s updated successfully!', 'rmcommon'), "<strong>" . $module->getVar('name') . "</strong>") . "</p>"; } // Flush cache files for cpanel GUIs xoops_load("cpanel", "system"); XoopsSystemCpanel::flush(); return $log; }
if (!xoops_template_touch($newid)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, "<strong>" . $block['template'] . "</strong>") . '</span>'; } else { $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, "<strong>" . $block['template'] . "</strong>"); } } } } $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, "<strong>" . $block['name'] . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $newbid . "</strong>"); $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; $xoopsDB->query($sql); } } } } $block_arr = XoopsBlock::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", $xoopsDB->prefix('newblocks'), $block->getVar('bid')); if (!$xoopsDB->query($sql)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, "<strong>" . $block->getVar('name') . "</strong>") . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, "<strong>" . $block->getVar('bid') . "</strong>") . '</span>'; } else { $msgs[] = ' Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>'; 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[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>'; } else {
/** * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ * @license http://www.fsf.org/copyleft/gpl.html GNU public license * @package Shoutbox * @author Alphalogic <*****@*****.**> * @author tank <*****@*****.**> * @author trabis <*****@*****.**> * @version $Id: module.php 0 2010-01-29 18:47:04Z trabis $ */ function xoops_module_install_shoutbox(&$module) { $newmid = $module->getVar('mid'); $groups = array(XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS); // retrieve all block ids for this module $blocks = XoopsBlock::getByModule($newmid, false); $msgs[] = _MD_AM_GROUP_SETTINGS_ADD; $gperm_handler =& xoops_gethandler('groupperm'); foreach ($groups as $mygroup) { if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) { $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_admin'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_ADMIN_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>"; } else { $msgs[] = " " . sprintf(_MD_AM_ACCESS_ADMIN_ADD, "<strong>" . $mygroup . "</strong>"); } unset($mperm); } $mperm =& $gperm_handler->create(); $mperm->setVar('gperm_groupid', $mygroup); $mperm->setVar('gperm_itemid', $newmid); $mperm->setVar('gperm_name', 'module_read'); $mperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($mperm)) { $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>") . "</span>"; } else { $msgs[] = ' ' . sprintf(_MD_AM_ACCESS_USER_ADD_ERROR, "<strong>" . $mygroup . "</strong>"); } unset($mperm); foreach ($blocks as $blc) { $bperm =& $gperm_handler->create(); $bperm->setVar('gperm_groupid', $mygroup); $bperm->setVar('gperm_itemid', $blc); $bperm->setVar('gperm_name', 'block_read'); $bperm->setVar('gperm_modid', 1); if (!$gperm_handler->insert($bperm)) { $msgs[] = ' <span style="color:#ff0000;">' . _MD_AM_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>'; } else { $msgs[] = ' ' . _MD_AM_BLOCK_ACCESS . sprintf(_MD_AM_BLOCK_ID, "<strong>" . $blc . "</strong>") . sprintf(_MD_AM_GROUP_ID, "<strong>" . $mygroup . "</strong>"); } unset($bperm); } } unset($blocks); unset($groups); $cacheDir = XOOPS_ROOT_PATH . '/uploads/shoutbox'; $cacheFile = $cacheDir . '/shout.csv'; if (!file_exists($cacheFile)) { if (!is_dir($cacheDir)) { if (!mkdir($cacheDir)) { //$msgs[] = "Failed to create dir!"; return false; } else { //$msgs[] = " Dir /uploads/shoutbox/ succesfully created!"; chmod($cacheDir, 0777); } } if ($file = fopen($cacheFile, 'w')) { if (!fwrite($file, "Shoutbox|Welcome to the Shoutbox v4.x for Xoops|1|111.111.111.111|guest\n")) { //$msgs[] = " Could not put content in file /uploads/shoutbox/shout.cvs! Please create <i>manually</i>."; } fclose($file); chmod($cacheFile, 0777); //$msgs[] = " File /uploads/shoutbox/shout.cvs succesfully created!"; return true; } else { //$msgs[] = " Could not create file /uploads/shoutbox/shout.cvs! Please create <i>manually</i>."; return false; } } else { return true; } }
$target_mid = 0; $target_mname = ''; $query4redirect = '?mid=0'; } else { $target_mid = $xoopsModule->getVar('mid'); $target_mname = $xoopsModule->getVar('name'); $query4redirect = ''; } } // check access right (needs system_admin of BLOCK) $sysperm_handler =& xoops_gethandler('groupperm'); if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) { redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); } // get blocks owned by the module $block_arr =& XoopsBlock::getByModule($target_mid); function list_blocks() { global $query4redirect, $block_arr, $xoopsGTicket; // cachetime options $cachetimes = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH); // displaying TH echo "\r\n\t<form action='admin.php' name='blockadmin' method='post'>\r\n\t\t<table width='90%' class='outer' cellpadding='4' cellspacing='1'>\r\n\t\t<tr valign='middle'>\r\n\t\t\t<th>" . _AM_TITLE . "</th>\r\n\t\t\t<th align='center' nowrap='nowrap'>" . _AM_SIDE . "</th>\r\n\t\t\t<th align='center'>" . _AM_WEIGHT . "</th>\r\n\t\t\t<th align='center'>" . _AM_VISIBLEIN . "</th>\r\n\t\t\t<th align='center'>" . _AM_BCACHETIME . "</th>\r\n\t\t\t<th align='right'>" . _AM_ACTION . "</th>\r\n\t\t</tr>\n"; // blocks displaying loop $class = 'even'; $block_configs = get_block_configs(); foreach (array_keys($block_arr) as $i) { $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = ""; $weight = $block_arr[$i]->getVar("weight"); $title = $block_arr[$i]->getVar("title"); $name = $block_arr[$i]->getVar("name");
/** * @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>') . ' ' . _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>') . ' ' . _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>') . ' ' . _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; }
} xoops_header(false); ?> </head> <body> <table border="0" cellspacing="5" cellpadding="0"> <tr> <td id="leftcolumn"> <?php $xoopsConfig['nocommon'] = ''; include XOOPS_ROOT_PATH . '/header.php'; require_once '../../class/template.php'; require_once 'blocks/xoonips_blocks.php'; $xoopsModule =& XoopsModule::getByDirname("xoonips"); //print_r($xoopsModule); $mod_blocks =& XoopsBlock::getByModule($xoopsModule->getVar('mid')); //print_r($blocks); $blocks = array(); //copy only necessary block from mod_block to blocks. foreach ($mod_blocks as $b) { if ($b->getVar('mid') == $xoopsModule->getVar('mid')) { if ($b->getVar('show_func') == 'b_xoonips_quick_search_show' || $b->getVar('show_func') == 'b_xoonips_tree_show') { $blocks[$b->getVar('show_func')] = $b; } } } ?> <div class="blockTitle"><?php echo $blocks['b_xoonips_tree_show']->getVar('title'); ?> </div>
// Call Footer xoops_cp_footer(); break; case 'display': // Get module handler $module_handler = xoops_getHandler('module'); $module_id = system_CleanVars($_POST, 'mid', 0, 'int'); if ($module_id > 0) { $module = $module_handler->get($module_id); $old = $module->getVar('isactive'); // Set value $module->setVar('isactive', !$old); if (!$module_handler->insert($module)) { $error = true; } $blocks = XoopsBlock::getByModule($module_id); $bcount = count($blocks); for ($i = 0; $i < $bcount; ++$i) { $blocks[$i]->setVar('isactive', !$old); $blocks[$i]->store(); } //Set active modules in cache folder xoops_setActiveModules(); } break; case 'display_in_menu': // Get module handler $module_handler = xoops_getHandler('module'); $module_id = system_CleanVars($_POST, 'mid', 0, 'int'); if ($module_id > 0) { $module = $module_handler->get($module_id);
function xoonips_ranking_show($is_arrival) { global $xoopsUser; // load xoonips config handler $xconfig_handler =& xoonips_getormhandler('xoonips', 'config'); // hide block if user is guest and public index viewing policy is 'platform' if (!is_object($xoopsUser)) { $target_user = $xconfig_handler->getValue('public_item_target_user'); if ($target_user != 'all') { // 'platform' return false; } } $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid', 'n') : UID_GUEST; // hide block if user is invalid xoonips user $xsession_handler =& xoonips_getormhandler('xoonips', 'session'); if (!$xsession_handler->validateUser($uid, false)) { return false; } // load utility class $textutil =& xoonips_getutility('text'); $etc = '...'; // decide maximum string length by block position if (defined('XOOPS_CUBE_LEGACY')) { // get xoonips module id $mydirname = basename(dirname(__DIR__)); $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname($mydirname); $mid = $module->getVar('mid', 's'); // get block array $block_arr =& XoopsBlock::getByModule($mid); } else { global $block_arr; } $myfunc = $is_arrival ? 'b_xoonips_ranking_new_show' : 'b_xoonips_ranking_show'; $maxlen = 56; // default foreach ($block_arr as $b) { $func = $b->getVar('show_func', 'n'); if ($func == $myfunc) { $side = $b->getVar('side', 'n'); if ($side == XOOPS_SIDEBLOCK_LEFT || $side == XOOPS_SIDEBLOCK_RIGHT) { $maxlen = 16; break; } else { if ($side == XOOPS_CENTERBLOCK_LEFT || $side == XOOPS_CENTERBLOCK_RIGHT) { $maxlen = 24; break; } } } } // get configs $config_names = array('num_rows', 'visible', 'order'); $new_str = $is_arrival ? 'new_' : ''; foreach ($config_names as $name) { $config[$name] = $xconfig_handler->getValue('ranking_' . $new_str . $name); } $config['visible'] = explode(',', $config['visible']); $config['order'] = explode(',', $config['order']); // update rankings $ranking_handler =& xoonips_gethandler('xoonips', 'ranking'); $ranking_handler->update(); // get rankings from database // - set item permission criteria and join criteria $iperm_criteria = new CriteriaCompo(); $iperm_criteria->add(new Criteria('title_id', 0, '=', 'tt')); $iperm_criteria->add(new Criteria('open_level', OL_PUBLIC, '=', 'tx')); $iperm_criteria->add(new Criteria('certify_state', CERTIFIED, '=', 'txil')); $iperm_join = new XooNIpsJoinCriteria('xoonips_item_basic', 'item_id', 'item_id', 'INNER', 'tb'); $iperm_join->cascade(new XooNIpsJoinCriteria('xoonips_item_title', 'item_id', 'item_id', 'INNER', 'tt')); $iperm_join->cascade(new XooNIpsJoinCriteria('xoonips_index_item_link', 'item_id', 'item_id', 'INNER', 'txil')); $iperm_join->cascade(new XooNIpsJoinCriteria('xoonips_index', 'index_id', 'index_id', 'INNER', 'tx'), 'txil', true); // - set ranking number label $rank_tmp = explode(',', _MB_XOONIPS_RANKING_RANK_STR); $rank_str = array(); for ($i = 0; $i < $config['num_rows']; $i++) { $rank_str[] = $i + 1 . $rank_tmp[min($i, count($rank_tmp) - 1)]; } $block['rankings'] = array(); if ($is_arrival) { // new arrival block // ranking new item if ($config['visible'][0]) { $table = 'ranking_new_item'; $label = _MB_XOONIPS_RANKING_NEW_ITEM; $fields = 'tb.item_id, tt.title, DATE_FORMAT(timestamp,\'%m/%d\'), tb.doi'; $criteria = $iperm_criteria; $criteria->setGroupby('tb.item_id'); $criteria->setLimit($config['num_rows']); $criteria->setSort('timestamp'); $criteria->setOrder('DESC'); $join = $iperm_join; $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, false, $join); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $item_id = $obj->getVar('item_id', 'n'); $title = $textutil->html_special_chars($obj->getExtraVar('title')); $title = $textutil->truncate($title, $maxlen, $etc); $count = $textutil->html_special_chars($obj->getExtraVar('DATE_FORMAT(timestamp,\'%m/%d\')')); $doi = $textutil->html_special_chars($obj->getExtraVar('doi')); $id = $doi == '' && XNP_CONFIG_DOI_FIELD_PARAM_NAME != '' ? 'item_id=' . $item_id : XNP_CONFIG_DOI_FIELD_PARAM_NAME . '=' . urlencode($doi); $url = XOOPS_URL . '/modules/xoonips/detail.php?' . $id; $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][0]] = array('items' => $items, 'title' => $label); unset($items); } // ranking new group if ($config['visible'][1]) { $table = 'ranking_new_group'; $label = _MB_XOONIPS_RANKING_NEW_GROUP; $fields = 'tg.gid, tg.gname, DATE_FORMAT(timestamp,\'%m/%d\')'; $criteria = new CriteriaElement(); $criteria->setLimit($config['num_rows']); $criteria->setSort('timestamp'); $criteria->setOrder('DESC'); $join = new XooNIpsJoinCriteria('xoonips_groups', 'gid', 'gid', 'INNER', 'tg'); $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, false, $join); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $gid = $obj->getVar('gid', 'n'); $title = $textutil->html_special_chars($obj->getExtraVar('gname')); $title = $textutil->truncate($title, $maxlen, $etc); $count = $textutil->html_special_chars($obj->getExtraVar('DATE_FORMAT(timestamp,\'%m/%d\')')); $url = XOOPS_URL . '/modules/xoonips/groups.php'; $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][1]] = array('items' => $items, 'title' => $label); unset($items); } } else { // ranking block // ranking viewed item if ($config['visible'][0]) { $table = 'ranking_viewed_item'; $label = _MB_XOONIPS_RANKING_VIEWED_ITEM; $fields = 'tb.item_id, tt.title, count'; $criteria = $iperm_criteria; $criteria->add(new Criteria('count', 0, '<>')); $criteria->setLimit($config['num_rows']); $criteria->setSort('count'); $criteria->setOrder('DESC'); $join = $iperm_join; $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, true, $join); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $item_id = $obj->getVar('item_id', 'n'); $title = $textutil->html_special_chars($obj->getExtraVar('title')); $title = $textutil->truncate($title, $maxlen, $etc); $count = $obj->getVar('count', 'n'); $doi = $textutil->html_special_chars($obj->getExtraVar('doi')); $id = $doi == '' && XNP_CONFIG_DOI_FIELD_PARAM_NAME != '' ? 'item_id=' . $item_id : XNP_CONFIG_DOI_FIELD_PARAM_NAME . '=' . urlencode($doi); $url = XOOPS_URL . '/modules/xoonips/detail.php?' . $id; $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][0]] = array('items' => $items, 'title' => $label); unset($items); } // ranking downloaded item if ($config['visible'][1]) { $table = 'ranking_downloaded_item'; $label = _MB_XOONIPS_RANKING_DOWNLOADED_ITEM; $fields = 'tb.item_id, tt.title, count'; $criteria = $iperm_criteria; $criteria->add(new Criteria('count', 0, '<>')); $criteria->setLimit($config['num_rows']); $criteria->setSort('count'); $criteria->setOrder('DESC'); $join = $iperm_join; $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, true, $join); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $item_id = $obj->getVar('item_id', 'n'); $title = $textutil->html_special_chars($obj->getExtraVar('title')); $title = $textutil->truncate($title, $maxlen, $etc); $count = $obj->getVar('count', 'n'); $doi = $textutil->html_special_chars($obj->getExtraVar('doi')); $id = $doi == '' && XNP_CONFIG_DOI_FIELD_PARAM_NAME != '' ? 'item_id=' . $item_id : XNP_CONFIG_DOI_FIELD_PARAM_NAME . '=' . urlencode($doi); $url = XOOPS_URL . '/modules/xoonips/detail.php?' . $id; $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][1]] = array('items' => $items, 'title' => $label); unset($items); } // ranking contiributing user if ($config['visible'][2]) { $table = 'ranking_contributing_user'; $label = _MB_XOONIPS_RANKING_CONTRIBUTING_USER; $fields = 'tu.uid, tu.uname, COUNT(*) AS count'; $criteria = new CriteriaElement(); $criteria->setLimit($config['num_rows']); $criteria->setSort('count'); $criteria->setOrder('DESC'); $criteria->setGroupby('tu.uid'); $join = new XooNIpsJoinCriteria('users', 'uid', 'uid', 'INNER', 'tu'); $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, true, $join); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $uid = $obj->getVar('uid', 'n'); $title = $textutil->html_special_chars($obj->getExtraVar('uname')); $title = $textutil->truncate($title, $maxlen, $etc); $count = intval($obj->getExtraVar('count')); $url = XOOPS_URL . '/modules/xoonips/showusers.php?uid=' . $uid; $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][2]] = array('items' => $items, 'title' => $label); unset($items); } // ranking searched keyword if ($config['visible'][3]) { $table = 'ranking_searched_keyword'; $label = _MB_XOONIPS_RANKING_SEARCHED_KEYWORD; $fields = 'keyword, count'; $criteria = new CriteriaCompo(new Criteria('count', 0, '<>')); $criteria->add(new Criteria('keyword', '', '!=')); // ignore empty $criteria->setLimit($config['num_rows']); $criteria->setSort('count'); $criteria->setOrder('DESC'); $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, true); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $keyword = $obj->getVar('keyword', 'n'); $title = $textutil->html_special_chars($keyword); $title = preg_replace('/[\\x00-\\x20]/se', 'urlencode("\\0")', $title); $title = $textutil->truncate($title, $maxlen, $etc); $count = $obj->getVar('count', 'n'); $url = XOOPS_URL . '/modules/xoonips/itemselect.php?op=quicksearch&search_itemtype=all&keyword=' . urlencode($keyword); $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][3]] = array('items' => $items, 'title' => $label); unset($items); } if ($config['visible'][4]) { // ranking active group $table = 'ranking_active_group'; $label = _MB_XOONIPS_RANKING_CONTRIBUTED_GROUP; $fields = 'tg.gid, tg.gname, count'; $criteria = new Criteria('count', 0, '<>'); $criteria->setLimit($config['num_rows']); $criteria->setSort('count'); $criteria->setOrder('DESC'); $join = new XooNIpsJoinCriteria('xoonips_groups', 'gid', 'gid', 'INNER', 'tg'); $handler =& xoonips_getormhandler('xoonips', $table); $res =& $handler->open($criteria, $fields, false, $join); $items = array(); $i = 0; while ($obj =& $handler->getNext($res)) { $gid = $obj->getVar('gid', 'n'); $title = $textutil->html_special_chars($obj->getExtraVar('gname')); $title = $textutil->truncate($title, $maxlen, $etc); $count = $obj->getVar('count', 'n'); $url = XOOPS_URL . '/modules/xoonips/groups.php'; $items[] = array('title' => $title, 'url' => $url, 'num' => $count, 'rank_str' => $rank_str[$i]); $i++; } $handler->close($res); $block['rankings'][$config['order'][4]] = array('items' => $items, 'title' => $label); unset($items); } } ksort($block['rankings']); return $block; }