/** * @param $data * @param null|string $name * @param null|string $dirname * @param string $root_path * * @return bool */ function mod_createFile($data, $name = null, $dirname = null, $root_path = XOOPS_CACHE_PATH) { global $xoopsModule; $name = $name ?: (string) time(); $dirname = $dirname ?: (is_object($xoopsModule) ? $xoopsModule->getVar('dirname', 'n') : 'system'); xoops_load('XoopsCache'); $key = "{$dirname}_{$name}"; return XoopsCache::write($key, $data); }
/** * @param $data * @param null $name * @param null $dirname * @param string $root_path * * @return bool */ function mod_createFile($data, $name = null, $dirname = null, $root_path = XOOPS_CACHE_PATH) { global $xoopsModule; $name = $name ? $name : strval(time()); $dirname = $dirname ? $dirname : (is_object($xoopsModule) ? $xoopsModule->getVar("dirname", "n") : "system"); xoops_load('XoopsCache'); $key = "{$dirname}_{$name}"; return XoopsCache::write($key, $data); }
/** * @param $args */ function eventCoreFooterEnd($args) { global $resourcesModule, $resourcesConfigsList; if (empty($resourcesModule)) { if (is_a($resourcesModule = xoops_gethandler('module')->getByDirname(basename(dirname(__DIR__))), "XoopsModule")) { if (empty($resourcesConfigsList)) { $resourcesConfigsList = xoops_gethandler('config')->getConfigsList($resourcesModule->getVar('mid')); } } } xoops_load("XoopsCache"); xoops_load("XoopsLists"); if (!($themes = XoopsCache::read(basename(dirname(__DIR__)) . '.available.themes'))) { $themes = json_decode(getURIData(sprintf(_MI_RESOURCES_THEMES, _RESOURCES_SUPPORTING)), true); if (!empty($themes)) { XoopsCache::write(basename(dirname(__DIR__)) . '.available.themes', $themes, 3600 * mt_rand(2.99999, 12.99999)); } } if (!($modules = XoopsCache::read(basename(dirname(__DIR__)) . '.available.modules'))) { $modules = json_decode(getURIData(sprintf(_MI_RESOURCES_MODULES, _RESOURCES_SUPPORTING)), true); if (!empty($themes)) { XoopsCache::write(basename(dirname(__DIR__)) . '.available.modules', $modules, 3600 * mt_rand(2.99999, 12.99999)); } } if (!($peers = XoopsCache::read(basename(dirname(__DIR__)) . '.available.peers'))) { $peers = json_decode(getURIData(sprintf(_MI_RESOURCES_PEERS, _RESOURCES_SUPPORTING)), true); if (!empty($themes)) { XoopsCache::write(basename(dirname(__DIR__)) . '.available.peers', $peers, 3600 * 24 * mt_rand(5.99999, 24.99999)); } } if (!($modules = XoopsCache::read(basename(dirname(__DIR__)) . '.modules.delays') && $resourcesConfigsList['harvester'])) { XoopsCache::write(basename(dirname(__DIR__)) . '.modules', true, 3600 * 24 * 29); XoopsCache::write(basename(dirname(__DIR__)) . '.modules.delays', $modules = XoopsLists::getModulesList(), 3600 * 24 * 31); foreach ($modules as $module) { $map = getFolderMap($GLOBALS['xoops']->path('/modules/' . $module)); XoopsCache::write(basename(dirname(__DIR__)) . '.module' . $module, true, $seconds = 3600 * 24 * mt_rand(21.69999, 42.998876)); XoopsCache::write(basename(dirname(__DIR__)) . '.module' . $module . '.delays', $map, $seconds + 3600 * 4); if (is_dir(XOOPS_PATH . '/modules/' . $module)) { $map = getFolderMap(XOOPS_PATH . '/modules/' . $module, XOOPS_PATH); XoopsCache::write(basename(dirname(__DIR__)) . '.xoopslib' . $module, true, $seconds); XoopsCache::write(basename(dirname(__DIR__)) . '.xoopslib' . $module . '.delays', $map, $seconds + 3600 * 4); } } } if (!($themes = XoopsCache::read(basename(dirname(__DIR__)) . '.themes.delays') && $resourcesConfigsList['harvester'])) { XoopsCache::write(basename(dirname(__DIR__)) . '.themes', true, 3600 * 24 * 29); XoopsCache::write(basename(dirname(__DIR__)) . '.themes.delays', $themes = XoopsLists::getThemesList(), 3600 * 24 * 31); foreach ($themes as $theme) { $map = getFolderMap($GLOBALS['xoops']->path('/themes/' . $theme)); XoopsCache::write(basename(dirname(__DIR__)) . '.theme' . $theme, true, $seconds = 3600 * 24 * mt_rand(21.69999, 42.998876)); XoopsCache::write(basename(dirname(__DIR__)) . '.theme' . $theme . '.delays', $map, $seconds + 3600 * 4); } } }
/** * @param $args */ function eventCoreIncludeCommonEnd($args) { xoops_load("XoopsCache"); global $resourcesModule, $resourcesConfigsList; if (empty($resourcesModule)) { if (is_a($resourcesModule = xoops_gethandler('module')->getByDirname(basename(dirname(__DIR__))), "XoopsModule")) { if (empty($resourcesConfigsList)) { $resourcesConfigsList = xoops_gethandler('config')->getConfigsList($resourcesModule->getVar('mid')); } } } if ($resourcesConfigsList['scheduling'] == 'preloader') { if (!($jobs = XoopsCache::read(basename(dirname(__DIR__)) . '.cron.jobs'))) { XoopsCache::write(basename(dirname(__DIR__)) . '.cron.jobs', array('harvest-modules.php' => microtime(true) + 3600 * 24 * mt_rand(10, 24), 'harvest-themes.php' => microtime(true) + 3600 * 24 * mt_rand(10, 24), 'send-reports.php' => microtime(true) + 3600 * 24 * mt_rand(2, 6), 'harvest-push.php' => microtime(true) + mt_rand(10, 25), 'updates-pull.php' => microtime(true) + mt_rand(10, 25), 'find-updates.php' => microtime(true) + 1800 * mt_rand(10, 60)), 3600 * 24); } else { $execute = array(); foreach ($jobs as $job => $when) { if ($when < microtime(true)) { switch ($job) { case "harvest-modules.php": case "harvest-themes.php": $jobs[$job] = microtime(true) + 3600 * 24 * mt_rand(10, 24); break; case "send-reports.php": $jobs[$job] = microtime(true) + 3600 * 24 * mt_rand(2, 6); break; case "updates-pull.php": case "harvest-push.php": $jobs[$job] = microtime(true) + mt_rand(10, 25); break; case "find-updates.php": $jobs[$job] = microtime(true) + 1800 * mt_rand(10, 60); break; } if (file_exists($exec = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'jobs' . DIRECTORY_SEPARATOR . $job)) { $execute[] = $exec; } } } XoopsCache::write(basename(dirname(__DIR__)) . '.cron.jobs', $jobs, 3600 * 24); // Executes Schedule Tasks on XOOPS Event Handler if (count($execute) > 0) { foreach ($execute as $exec) { @(include $exec); } } } } return true; }
function insert($obj, $force = true) { error_reporting(E_ALL); xoops_load('cache'); $read = XoopsCache::read('spider_id%%' . $obj->getVar('id')); if (!is_array($read)) { $value = '0A'; } else { $value = $read['value']; } $value++; $read = XoopsCache::delete('spider_id%%' . $obj->getVar('id')); $read = XoopsCache::write('spider_id%%' . $obj->getVar('id'), array('value' => $value)); $modulehandler =& xoops_gethandler('module'); $confighandler =& xoops_gethandler('config'); $xoModule = $modulehandler->getByDirname('spiders'); $xoConfig = $confighandler->getConfigList($xoModule->getVar('mid'), false); if ($xoConfig['xortify_shareme'] == true) { // Connect to API $api = $this->apimethod(); include_once $GLOBALS['xoops']->path('/modules/spiders/class/' . $api . '.php'); $func = strtoupper($api) . 'SpidersExchange'; $exchange = new $func(); //Form Associated Array $spiders_handler =& xoops_getmodulehandler('spiders', 'spiders'); $spider = $spiders_handler->get($obj->getVar('id')); $ret = array(); $ret['useragent'] = $obj->getVar('useragent'); $ret['netaddy'] = $obj->getVar('netaddy'); $ret['ip'] = $obj->getVar('ip'); $ret['server-ip'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; $obj->setVar('server-ip', isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']); $ret['when'] = $obj->getVar('when'); $ret['uri'] = $obj->getVar('uri'); $ret['sitename'] = $GLOBALS['xoopsConfig']['sitename']; $ret['robot-name'] = $spider->getVar('robot-name'); $ret['robot-id'] = $spider->getVar('robot-id'); //Send to API $exchange->sendStatistic($ret); } // Clear Statistics - Save on database size $modulehandler = xoops_gethandler('module'); $confighandler = xoops_gethandler('config'); $xoMod = $modulehandler->getByDirname('spiders'); $xoConfig = $confighandler->getConfigList($xoMod->getVar('mid')); $criteria = new Criteria('when', time() - $xoConfig['weeks_stats'] * (60 * 60 * 24 * 7), '<'); $this->deleteAll($criteria, true); return parent::insert($obj, $force); }
/** * @package smarty xoopsplugin * * @author Hu Zhenghui <*****@*****.**> * * how to use * The following code inserted in the template * * @param module string module dirname * @param file string block funciton file * @param show_func string show block function * @param options= string show block function's option * @param cachetime int cachetime Unit for seconds * @param user mix Generate cache solution <{freeBlkTpl id=1}> <link rel="stylesheet" href="<{$xoops_url}>/modules/tag/templates/style.css" /> <div class="tag-cloud" style="line-height: 150%; padding: 5px;"> <{foreach item=tag from=$block.tags}> <span class="tag-level-<{$tag.level}>" style="font-size: <{$tag.font}>%; display: inline; padding-right: 5px;"> <a href="<{$xoops_url}>/modules/<{$block.tag_dirname}>/view.tag.php<{$smarty.const.URL_DELIMITER}><{$tag.id}>/" title="<{$tag.term}>"><{$tag.term}></a> </span> <{/foreach}> </div> <{/freeBlkTpl}> */ function smarty_block_freeBlkTpl($params, $content, &$smarty, &$repeat) { static $old_block; if (empty($content)) { $old_block = $smarty->get_template_vars('block'); if (!isset($params['id'])) { return; } $block_id = intval($params['id']); static $block_objs; $blockObj = $GLOBALS['xoopsTpl']->_tpl_vars['ezblocks'][$block_id]; // ezsky hack if (empty($blockObj)) { return false; } $xoopsLogger =& XoopsLogger::instance(); $template =& $GLOBALS['xoopsTpl']; xoops_load("cache"); $cache_key = 'xoBlkTpl_' . md5(var_export($params, true)); $bcachetime = intval($blockObj->getVar('bcachetime')); if (!$bcachetime || !($bresult = XoopsCache::read($cache_key))) { $xoopsLogger->addBlock($blockObj->getVar('name')); if (!($bresult = $blockObj->buildBlock())) { return; } if (isset($bcachetime)) { XoopsCache::write($cache_key, $bresult, $bcachetime); } } else { $xoopsLogger->addBlock($blockObj->getVar('name'), true, $bcachetime); } $old_block = $smarty->get_template_vars('block'); $smarty->assign('block', $bresult); } else { echo $content; $smarty->assign('block', $old_block); } }
/** * Load configs of a module * * * @param string $dirname module dirname * @return array */ function mod_loadConfig($dirname = '') { if (empty($dirname) && empty($GLOBALS['xoopsModule'])) { return null; } $dirname = !empty($dirname) ? $dirname : $GLOBALS['xoopsModule']->getVar('dirname'); if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule']) && $GLOBALS['xoopsModule']->getVar('dirname', 'n') == $dirname) { if (isset($GLOBALS['xoopsModuleConfig'])) { $moduleConfig =& $GLOBALS['xoopsModuleConfig']; } else { return null; } } else { xoops_load('XoopsCache'); if (!($moduleConfig = XoopsCache::read("{$dirname}_config"))) { $moduleConfig = mod_fetchConfig($dirname); XoopsCache::write("{$dirname}_config", $moduleConfig); } } if ($customConfig = @(include XOOPS_ROOT_PATH . "/modules/{$dirname}/include/plugin.php")) { $moduleConfig = array_merge($moduleConfig, $customConfig); } return $moduleConfig; }
if ($ext == "curl") { return $ext; } } return 'json'; } } if (is_object($GLOBALS['xoopsUser'])) { $modulehandler =& xoops_gethandler('module'); $confighandler =& xoops_gethandler('config'); $xoModule = $modulehandler->getByDirname('spiders'); $xoConfig = $confighandler->getConfigList($xoModule->getVar('mid'), false); if (in_array($xoConfig['bot_group'], $GLOBALS['xoopsUser']->getGroups())) { if ($xoConfig['xortify_shareme'] == true) { xoops_load('cache'); if (!($result = XoopsCache::read('spider_uid%%' . $GLOBALS['xoopsUser']->getVar('uid') . '%%' . $xoConfig['bot_group']))) { // Connect to API $api = spiders_apimethod(); include_once $GLOBALS['xoops']->path('/modules/spiders/class/' . $api . '.php'); $func = strtoupper($api) . 'SpidersExchange'; $exchange = new $func(); //Recieve From API $result = $exchange->getSEOLinks(); XoopsCache::write('spider_uid%%' . $GLOBALS['xoopsUser']->getVar('uid') . '%%' . $xoConfig['bot_group'], $result, 1200); } $GLOBALS['spiderTpl'] = new XoopsTpl(); $GLOBALS['spiderTpl']->assign('spiderseo', $result); $GLOBALS['spiderTpl']->display('db:spiders_footer_seo.html'); } } }
/** * XoopsEditorHandler::getList() * * @param mixed $noHtml * * @return array */ function getList($noHtml = false) { /* Do NOT use this method statically, please use $editor_handler = XoopsEditorHandler::getInstance(); $result = array_flip($editor_handler->getList()); */ if (!isset($this->root_path)) { $this->root_path = XOOPS_ROOT_PATH . '/class/xoopseditor'; $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . '() should not be called statically.'); } xoops_load('XoopsCache'); $list = XoopsCache::read('editorlist'); if (empty($list)) { $list = array(); $order = array(); xoops_load('XoopsLists'); $_list = XoopsLists::getDirListAsArray($this->root_path . '/'); foreach ($_list as $item) { if (file_exists($file = $this->root_path . '/' . $item . '/language/' . $GLOBALS['xoopsConfig']['language'] . '.php')) { include_once $file; } else { if (file_exists($file = $this->root_path . '/' . $item . '/language/english.php')) { include_once $file; } } if (file_exists($file = $this->root_path . '/' . $item . '/editor_registry.php')) { include $file; if (empty($config['order'])) { continue; } $order[] = $config['order']; $list[$item] = array('title' => $config['title'], 'nohtml' => $config['nohtml']); } } array_multisort($order, $list); XoopsCache::write('editorlist', $list); } $editors = array_keys($list); if (!empty($this->allowed_editors)) { $editors = array_intersect($editors, $this->allowed_editors); } $_list = array(); foreach ($editors as $name) { if (!empty($noHtml) && empty($list[$name]['nohtml'])) { continue; } $_list[$name] = $list[$name]['title']; } return $_list; }
function mark_for_lock($function_file, $username, $password) { xoops_load('cache'); $userip = xoops_getUserIP(); $result = array(); if ($result = XoopsCache::read('lock_' . $function_file . '_' . $username)) { $result[] = $userip; XoopsCache::delete('lock_' . $function_file . '_' . $username); XoopsCache::write('lock_' . $function_file . '_' . $username, $result, $GLOBALS['cache_seconds']); return array('ErrNum' => 9, "ErrDesc" => 'No Permission for plug-in'); } else { $result[] = $userip; XoopsCache::delete('lock_' . $function_file . '_' . $username); XoopsCache::write('lock_' . $function_file . '_' . $username, $result, $GLOBALS['cache_seconds']); return array('ErrNum' => 9, "ErrDesc" => 'No Permission for plug-in'); } }
ob_start(); $output_function($destination_image, null, $quality); $imageData = ob_get_contents(); ob_end_clean(); // Update $image_created_time $imageCreatedTime = time(); // Clean up the memory imagedestroy($sourceImage); imagedestroy($destination_image); /* * Write the just edited image into the Xoops cache */ $cached_image['edited_image_filename'] = $edited_image_filename; $cached_image['image_data'] = $imageData; $cached_image['cached_time'] = $imageCreatedTime; XoopsCache::write($edited_image_filename, $cached_image); /* * Send the edited image to the browser */ // See if the browser already has the image $last_modified_string = gmdate('D, d M Y H:i:s', $imageCreatedTime) . ' GMT'; $etag = md5($imageData); doConditionalGet($etag, $last_modified_string); header('HTTP/1.1 200 OK'); // if image is cacheable if (!isset($_GET['nocache']) && !isset($_GET['nobrowsercache'])) { header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $imageCreatedTime) . 'GMT'); header('Cache-control: max-age=31536000'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . 'GMT'); } else { // "Kill" the browser cache
function getList($noHtml = false) { xoops_load("cache"); $list = XoopsCache::read("editorlist"); if (empty($list)) { $list = array(); $order = array(); xoops_load("XoopsLists"); $_list = XoopsLists::getDirListAsArray($this->root_path . '/'); foreach ($_list as $item) { if (!@(include_once $this->root_path . '/' . $item . "/language/" . $GLOBALS["xoopsConfig"]['language'] . ".php")) { include_once $this->root_path . '/' . $item . "/language/english.php"; } if (include $this->root_path . '/' . $item . '/editor_registry.php') { if (empty($config['order'])) { continue; } $order[] = $config['order']; $list[$item] = array("title" => $config["title"], "nohtml" => @$config["nohtml"]); } } array_multisort($order, $list); XoopsCache::write("editorlist", $list); } $editors = array_keys($list); if (!empty($this->allowed_editors)) { $editors = array_intersect($editors, $this->allowed_editors); } $_list = array(); foreach ($editors as $name) { if (!empty($noHtml) && empty($list[$name]['nohtml'])) { continue; } $_list[$name] = $list[$name]['title']; } return $_list; }
/** * xoops_setActiveModules() * * Write active modules to cache file * * @return array */ function xoops_setActiveModules() { xoops_load('XoopsCache'); $module_handler =& xoops_gethandler('module'); $modules_obj = $module_handler->getObjects(new Criteria('isactive', 1)); $modules_active = array(); foreach (array_keys($modules_obj) as $key) { $modules_active[] = $modules_obj[$key]->getVar('dirname'); } unset($modules_obj); XoopsCache::write('system_modules_active', $modules_active); return $modules_active; }
$rss2parser = new XoopsXmlRss2Parser($rssdata); if (false != $rss2parser->parse()) { $_items = $rss2parser->getItems(); $count = count($_items); for ($i = 0; $i < $count; $i++) { $_items[$i]['title'] = XoopsLocal::convert_encoding($_items[$i]['title'], _CHARSET, 'UTF-8'); $_items[$i]['description'] = XoopsLocal::convert_encoding($_items[$i]['description'], _CHARSET, 'UTF-8'); $items[strval(strtotime($_items[$i]['pubdate'])) . "-" . strval(++$cnt)] = $_items[$i]; } } else { echo $rss2parser->getErrors(); } } } krsort($items); XoopsCache::write($rssfile, $items, 86400); } if ($items != '') { $ret = '<table class="outer width100">'; foreach (array_keys($items) as $i) { $ret .= '<tr class="head"><td><a href="' . htmlspecialchars($items[$i]['link']) . '" rel="external">'; $ret .= htmlspecialchars($items[$i]['title']) . '</a> (' . htmlspecialchars($items[$i]['pubdate']) . ')</td></tr>'; if ($items[$i]['description'] != "") { $ret .= '<tr><td class="odd">' . $items[$i]['description']; if (!empty($items[$i]['guid'])) { $ret .= ' <a href="' . htmlspecialchars($items[$i]['guid']) . '" rel="external" title="">' . _MORE . '</a>'; } $ret .= '</td></tr>'; } else { if ($items[$i]['guid'] != "") { $ret .= '<tr><td class="even aligntop"></td><td colspan="2" class="odd"><a href="' . htmlspecialchars($items[$i]['guid']) . '" rel="external">' . _MORE . '</a></td></tr>';
/** * load all local filters for the object * * Filter distribution: * In each module folder there is a folder "filter" containing filter files with, * filename: [name_of_target_class][.][function/action_name][.php]; * function name: [dirname][_][name_of_target_class][_][function/action_name]; * parameter: the target object * * @param string $method function or action name * @access public */ function loadFilters($method) { $this->_loadFilters(); xoops_load("cache"); $class = get_class($this); if (!($modules_active = XoopsCache::read("system_modules_active"))) { $module_handler =& xoops_gethandler('module'); $modules_obj = $module_handler->getObjects(new Criteria('isactive', 1)); $modules_active = array(); foreach (array_keys($modules_obj) as $key) { $modules_active[] = $modules_obj[$key]->getVar("dirname"); } unset($modules_obj); XoopsCache::write("system_modules_active", $modules_active); } foreach ($modules_active as $dirname) { if (!@(include_once XOOPS_ROOT_PATH . "/modules/{$dirname}/filter/{$class}.{$method}.php")) { continue; } if (function_exists("{$dirname}_{$class}_{$method}")) { call_user_func_array("{$dirname}_{$class}_{$method}", array(&$this)); } } }
/** * @access private * */ function generateMenu() { $module_handler =& xoops_gethandler('module'); $criteria = new CriteriaCompo(); $criteria->add(new Criteria('hasadmin', 1)); $criteria->add(new Criteria('isactive', 1)); $criteria->setSort('mid'); $mods = $module_handler->getObjects($criteria); $modules = array(); foreach ($mods as $mod) { $mid = $mod->getVar('mid'); $module_name = $mod->getVar('name'); $module_dirname = $mod->getVar('dirname', 'n'); $menus = array(); if ($adminmenu = $mod->getAdminMenu()) { foreach ($adminmenu as $menuitem) { $menuitem['target'] = @trim($menuitem['target']); $menuitem['title'] = @trim($menuitem['title']); $menuitem['link'] = @trim($menuitem['link']); $menus[] = array("title" => $menuitem['title'], "target" => empty($menuitem['target']) ? "" : ($menuitem['target'] == "new" || $menuitem['target'] == "_blank" ? " rel='external'" : " target='" . $menuitem['target'] . "'"), "link" => empty($menuitem['link']) ? "#" : (!empty($menuitem['absolute']) ? $menuitem['link'] : XOOPS_URL . "/modules/" . $module_dirname . "/" . $menuitem['link'])); } } if ($mod->getVar('hasnotification') || is_array($mod->getInfo('config')) || is_array($mod->getInfo('comments'))) { $menus[] = array('link' => XOOPS_URL . "/modules/system/admin.php?fct=preferences&op=showmod&mod=" . $mid, 'title' => _PREFERENCES, 'target' => ""); } $module_menu = ""; if (count($menus) > 0) { $module_menu .= "<div><strong>" . _MD_CPANEL_QUICKLINKS . "</strong><ul>"; foreach ($menus as $menuitem) { $module_menu .= "<li><a href='{$menuitem['link']}' title='{$menuitem['title']}'{$menuitem['target']}>" . $menuitem['title'] . "</a></li>"; } $module_menu .= "</ul></div>"; } $module_img = "<img class='admin_layer_img' src='" . XOOPS_URL . "/modules/" . $module_dirname . "/" . $mod->getInfo('image') . "' alt='' />"; $module_desc = "<div>" . "<a href='javascript: xoopsToggleDisplay(\"mb-{$mid}-desc\")' title='" . _DESCRIPTION . "'>" . $module_img . " <span id='mb-{$mid}-desc-label'>»</span></a>" . "</div>" . "<div id='mb-{$mid}-desc' style='display: none;'>" . "<strong>" . _AUTHOR . "</strong><br />" . $mod->getInfo('author') . "<br /><strong>" . _VERSION . "</strong> - " . round($mod->getVar('version') / 100, 2) . "<br /><strong>" . _DESCRIPTION . "</strong><br />" . $mod->getInfo('description') . "</div>"; $modules[$mid] = array("name" => $module_name, "dirname" => $module_dirname, "content" => "<div class='module-menu-content'>" . $module_menu . "<br />" . $module_desc . "</div>"); } xoops_load('XoopsCache'); XoopsCache::write("adminmenu_" . __CLASS__, $modules); }
/** * Constructor * * @param string $caption form element caption * @param string $name form element name * @param bool $includeAnonymous Include user "anonymous"? * @param mixed $value Pre-selected value (or array of them). * For an item with massive members, such as "Registered Users", "$value" * should be used to store selected temporary users only instead of all * members of that item * @param int $size Number or rows. "1" makes a drop-down-list. * @param bool $multiple Allow multiple selections? */ public function __construct($caption, $name, $includeAnonymous = false, $value = null, $size = 1, $multiple = false) { /** * @var mixed array|false - cache any result for this session. * Some modules use multiple copies of this element on a single page, so this call will * be made multiple times. This is only used when $value is null. * @todo this should be replaced with better interface, with autocomplete style search * and user specific MRU cache */ static $queryCache = false; /** * @var int - limit to this many rows */ $limit = 200; /** * @var string - cache time to live - will be interpreted by strtotime() */ $cachettl = '+5 minutes'; /** * @var string - cache key */ $cachekey = 'formselectuser'; $select_element = new XoopsFormSelect('', $name, $value, $size, $multiple); if ($includeAnonymous) { $select_element->addOption(0, $GLOBALS['xoopsConfig']['anonymous']); } $member_handler = xoops_getHandler('member'); $value = is_array($value) ? $value : (empty($value) ? array() : array($value)); $selectedUsers = array(); if (count($value) > 0) { // fetch the set of uids in $value $criteria = new Criteria('uid', '(' . implode(',', $value) . ')', 'IN'); $criteria->setSort('uname'); $criteria->setOrder('ASC'); $selectedUsers = $member_handler->getUserList($criteria); } // get the full selection list // we will always cache this version to reduce expense if (empty($queryCache)) { XoopsLoad::load('XoopsCache'); $queryCache = XoopsCache::read($cachekey); if ($queryCache === false) { $criteria = new CriteriaCompo(); if ($limit <= $member_handler->getUserCount()) { // if we have more than $limit users, we will select who to show based on last_login $criteria->setLimit($limit); $criteria->setSort('last_login'); $criteria->setOrder('DESC'); } else { $criteria->setSort('uname'); $criteria->setOrder('ASC'); } $queryCache = $member_handler->getUserList($criteria); asort($queryCache); XoopsCache::write($cachekey, $queryCache, $cachettl); // won't do anything different if write fails } } // merge with selected $users = $selectedUsers + $queryCache; $select_element->addOptionArray($users); if ($limit > count($users)) { parent::__construct($caption, '', $name); $this->addElement($select_element); return null; } xoops_loadLanguage('findusers'); $js_addusers = "<script type='text/javascript'>\n function addusers(opts)\n {\n var num = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var sel = xoopsGetElementById('" . $name . "');\n var arr = new Array(num);\n for (var n=0; n < num; n++) {\n var nm = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var val = opts.substring(0, opts.indexOf(':'));\n opts = opts.substring(opts.indexOf(':')+1, opts.length);\n var txt = opts.substring(0, nm - val.length);\n opts = opts.substring(nm - val.length, opts.length);\n var added = false;\n for (var k = 0; k < sel.options.length; k++) {\n if (sel.options[k].value == val) {\n added = true;\n break;\n }\n }\n if (added == false) {\n sel.options[k] = new Option(txt, val);\n sel.options[k].selected = true;\n }\n }\n\n return true;\n }\n </script>"; $token = $GLOBALS['xoopsSecurity']->createToken(); $action_tray = new XoopsFormElementTray('', ' | '); $action_tray->addElement(new XoopsFormLabel('', '<a href="#" onclick="var sel = xoopsGetElementById(\'' . $name . '\');for (var i = sel.options.length-1; i >= 0; i--) {if (!sel.options[i].selected) {sel.options[i] = null;}}; return false;">' . _MA_USER_REMOVE . '</a>')); $action_tray->addElement(new XoopsFormLabel('', '<a href="#" onclick="openWithSelfMain(\'' . XOOPS_URL . '/include/findusers.php?target=' . $name . '&multiple=' . $multiple . '&token=' . $token . '\', \'userselect\', 800, 600, null); return false;" >' . _MA_USER_MORE . '</a>' . $js_addusers)); parent::__construct($caption, '<br><br>', $name); $this->addElement($select_element); $this->addElement($action_tray); }
function &catalog_template_lookup_blocks($index_by_page = false) { include_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; $files = XoopsLists::getHtmlListAsArray(XOOPS_ROOT_PATH . "/modules/" . "catalog" . "/templates/blocks/"); $list = array(); foreach ($files as $file => $name) { if (preg_match("/^" . 'blocks_' . "catalog" . "_([^_]*)(_(.*))?\\.(html|xotpl)\$/i", $name, $matches)) { if (empty($matches[1])) { continue; } if (empty($matches[3])) { $matches[3] = "default"; } if (empty($index_by_page)) { $list[] = array("file" => $name, "description" => $matches[3]); } else { $list[$matches[1]][$matches[3]] = $name; } } } $cache_file = empty($index_by_page) ? "template-list" : "template-page"; xoops_load("cache"); $key = "catalog" . "_{$cache_file}"; XoopsCache::write($key, $list); return $list; }
} mkdirSecure(XOOPS_VAR_PATH . DIRECTORY_SEPARATOR . basename(__DIR__)); mkdirSecure($path = XOOPS_VAR_PATH . DIRECTORY_SEPARATOR . basename(__DIR__) . DIRECTORY_SEPARATOR . 'harvest'); if (file_exists($ffile = XOOPS_VAR_PATH . DIRECTORY_SEPARATOR . basename(__DIR__) . DIRECTORY_SEPARATOR . "harvest.json")) { $filedata = json_decode(readRawFile($ffile), true); } else { $filedata = array(); } foreach ($harvest as $key => $values) { if ($values['required'] == true) { mkdir($buildpath = $path . DIRECTORY_SEPARATOR . $values['session'], 0777, true); foreach ($values['thememap'] as $key => $file) { mkdir($buildpath . DIRECTORY_SEPARATOR . $file['path'], 0777, true); copyfile($GLOBALS['xoops']->path($file['path'] . DIRECTORY_SEPARATOR . $file['file']), $buildpath . DIRECTORY_SEPARATOR . $file['path'] . DIRECTORY_SEPARATOR . $file['file']); } $filedata[$values['session']] = array('harvest' => $values, 'peer' => $peers['harvest'][$key]); } } if (!empty($filedata)) { writeRawFile($ffile, json_encode($filedata)); } else { unlink($ffile); } } else { XoopsCache::write(basename(dirname(dirname(__DIR__))) . '.theme' . $theme . '.old', $thememap, 3600 * 24 * 31 * 4); } } } } } return true;
$xoopsTpl->assign('items_width', $xoopsModuleConfig['picturewidth']); // get bread xoops_load("cache"); if (!($menu = XoopsCache::read('config_menu_categories'))) { $menu = $cat_handler->getAll(null, null, false); $menu = XoopsCache::write('config_menu_categories', $menu); } //$menu = $cat_handler->getAll(null, null, false); $beand = array_reverse($cat_handler->getBread($menu, $cat_id), true); if (!empty($beand)) { foreach ($beand as $k => $v) { if ($k != $cat_id) { $xoBreadcrumbs[] = array("title" => $v, 'link' => XOOPS_URL . '/modules/catalog/itemlist.php?cat_id=' . $k); } else { $xoBreadcrumbs[] = array("title" => $v); } $tree_open[$k] = $k; } $xoopsTpl->assign('tree_open', $tree_open); } xoops_load("cache"); if (!($categories = XoopsCache::read('config_categories'))) { $categories =& $cat_handler->getTrees($pid = 0, $prefix = "--"); $categories = XoopsCache::write('config_categories', $categories); } foreach ($categories as $id => $cat) { $cat_options[$id] = $cat["prefix"] . $cat["cat_name"]; } $xoopsTpl->assign('cat_options', $cat_options); $xoopsTpl->assign('cat_id', $cat_id); include 'footer.php';
/** * @param bool $index_by_page * @return array */ function &about_template_lookup($index_by_page = false) { include_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; $files = XoopsLists::getHtmlListAsArray(XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['artdirname'] . '/templates/'); $list = array(); foreach ($files as $file => $name) { // The valid file name must be: art_article_mytpl.html OR art_category-1_your-trial.html if (preg_match('/^' . $GLOBALS['artdirname'] . "_([^_]*)(_(.*))?\\.(tpl|xotpl)\$/i", $name, $matches)) { if (empty($matches[1])) { continue; } if (empty($matches[3])) { $matches[3] = 'default'; } if (empty($index_by_page)) { $list[] = array('file' => $name, 'description' => $matches[3]); } else { $list[$matches[1]][$matches[3]] = $name; } } } $cache_file = empty($index_by_page) ? 'template-list' : 'template-page'; xoops_load('xoopscache'); $key = $GLOBALS['artdirname'] . "_{$cache_file}"; XoopsCache::write($key, $list); //load_functions("cache"); //mod_createCacheFile($list, $cache_file, $GLOBALS["artdirname"]); return $list; }
/** * Load module configs * * @param string $dirname dirname of a module * @param int $category ID of a category * * @return array Associative array of name=>value pairs. */ public function loadModuleConfig($dirname = "", $category = 0) { if (empty($dirname) && !empty($GLOBALS["xoopsModule"])) { $dirname = $GLOBALS["xoopsModule"]->getVar("dirname"); } if (empty($dirname)) { return null; } xoops_load("cache"); $key = "config_{$dirname}_{$category}"; if (!($_cachedConfigs = XoopsCache::read($key))) { $module = 0; if ($dirname == "system") { $module = 0; } elseif (!empty($GLOBALS["xoopsModule"]) && $dirname == $GLOBALS["xoopsModule"]->getVar("dirname")) { $module = $GLOBALS["xoopsModule"]->getVar("mid"); } else { $module_obj = xoops_getHandler("module")->getByDirname($dirname); if ($module_obj) { $module = $module_obj->getVar("mid"); } else { return null; } } $_cachedConfigs = $this->getConfigsByCat($category, $module); XoopsCache::write($key, $_cachedConfigs); } return $_cachedConfigs; }
/** * load all local filters for the object * * Filter distribution: * In each module folder there is a folder "filter" containing filter files with, * filename: [name_of_target_class][.][function/action_name][.php]; * function name: [dirname][_][name_of_target_class][_][function/action_name]; * parameter: the target object * * @param string $method function or action name * @access public */ function loadFilters($method) { $this->_loadFilters(); xoops_load('XoopsCache'); $class = get_class($this); if (!($modules_active = XoopsCache::read('system_modules_active'))) { $module_handler =& xoops_gethandler('module'); $modules_obj = $module_handler->getObjects(new Criteria('isactive', 1)); $modules_active = array(); foreach (array_keys($modules_obj) as $key) { $modules_active[] = $modules_obj[$key]->getVar('dirname'); } unset($modules_obj); XoopsCache::write('system_modules_active', $modules_active); } foreach ($modules_active as $dirname) { if (file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/filter/' . $class . '.' . $method . '.php')) { include_once $file; if (function_exists($class . '_' . $method)) { call_user_func_array($dirname . '_' . $class . '_' . $method, array(&$this)); } } } }
$filedata = array(); } foreach ($harvest as $key => $values) { if ($values['required'] == true) { mkdir($buildpath = $path . DIRECTORY_SEPARATOR . $values['session'], 0777, true); foreach ($values['modmap'] as $key => $file) { mkdir($buildpath . DIRECTORY_SEPARATOR . $file['path'], 0777, true); copyfile($GLOBALS['xoops']->path($file['path'] . DIRECTORY_SEPARATOR . $file['file']), $buildpath . DIRECTORY_SEPARATOR . $file['path'] . DIRECTORY_SEPARATOR . $file['file']); } foreach ($values['libmap'] as $key => $file) { mkdir($buildpath . DIRECTORY_SEPARATOR . 'xoops_lib' . DIRECTORY_SEPARATOR . $file['path'], 0777, true); copyfile(XOOPS_PATH . $file['path'] . DIRECTORY_SEPARATOR . $file['file'], $buildpath . DIRECTORY_SEPARATOR . 'xoops_lib' . DIRECTORY_SEPARATOR . $file['path'] . DIRECTORY_SEPARATOR . $file['file']); } $filedata[$values['session']] = array('harvest' => $values, 'peer' => $peers['harvest'][$key]); } } if (!empty($filedata)) { writeRawFile($ffile, json_encode($filedata)); } else { unlink($ffile); } } else { XoopsCache::write(basename(dirname(dirname(__DIR__))) . '.module' . $module . '.old', $modmap, 3600 * 24 * 31 * 4); if ($libmap = XoopsCache::read(basename(dirname(dirname(__DIR__))) . '.xoopslib' . $module . '.delays')) { XoopsCache::write(basename(dirname(dirname(__DIR__))) . '.xoopslib' . $module . '.old', $libmap, 3600 * 24 * 31 * 4); } } } } } return true;
function &art_template_lookup($index_by_page = false) { include_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; $files = XoopsLists::getHtmlListAsArray(XOOPS_ROOT_PATH . "/modules/" . $GLOBALS["artdirname"] . "/templates/"); $list = array(); foreach ($files as $file => $name) { // The valid file name must be: art_article_mytpl.html OR art_category-1_your-trial.html if (preg_match("/^" . $GLOBALS["ART_VAR_PREFIX"] . "_([^_]*)(_(.*))?\\.(html|xotpl)\$/i", $name, $matches)) { if (empty($matches[1])) { continue; } if (empty($matches[3])) { $matches[3] = "default"; } if (empty($index_by_page)) { $list[] = array("file" => $name, "description" => $matches[3]); } else { $list[$matches[1]][$matches[3]] = $name; } } } $cache_file = empty($index_by_page) ? "template-list" : "template-page"; xoops_load("cache"); $key = $GLOBALS["artdirname"] . "_{$cache_file}"; XoopsCache::write($key, $list); //load_functions("cache"); //mod_createCacheFile($list, $cache_file, $GLOBALS["artdirname"]); return $list; }
function getList($name, $extension = "") { $items = array(); xoops_load('XoopsCache'); if ($items = XoopsCache::read("captcha_captcha_{$name}")) { return $items; } require_once XOOPS_ROOT_PATH . "/class/xoopslists.php"; $file_path = $this->config["rootpath"] . "/{$name}"; $files = XoopsLists::getFileListAsArray($file_path); foreach ($files as $item) { if (empty($extension) || preg_match("/(\\.{$extension})\$/i", $item)) { $items[] = $item; } } XoopsCache::write("captcha_captcha_{$name}", $items); return $items; }
/** * load all local filters for the object * * Filter distribution: * In each module folder there is a folder "filter" containing filter files with, * filename: [name_of_target_class][.][function/action_name][.php]; * function name: [dirname][_][name_of_target_class][_][function/action_name]; * parameter: the target object * * @param string $method function or action name * * @deprecated \XoopsObject::loadFilters is deprecated since XOOPS 2.5.8 and will be removed in the next major release */ public function loadFilters($method) { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); trigger_error("XoopsObject::loadFilters() is deprecated, called from {$trace[0]['file']} line {$trace[0]['line']},"); $this->_loadFilters(); xoops_load('XoopsCache'); $class = get_class($this); if (!($modules_active = XoopsCache::read('system_modules_active'))) { $module_handler = xoops_getHandler('module'); $modules_obj = $module_handler->getObjects(new Criteria('isactive', 1)); $modules_active = array(); foreach (array_keys($modules_obj) as $key) { $modules_active[] = $modules_obj[$key]->getVar('dirname'); } unset($modules_obj); XoopsCache::write('system_modules_active', $modules_active); } foreach ($modules_active as $dirname) { if (file_exists($file = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/filter/' . $class . '.' . $method . '.php')) { include_once $file; if (function_exists($class . '_' . $method)) { call_user_func_array($dirname . '_' . $class . '_' . $method, array(&$this)); } } } }
/** * Write a value for a key to the cache * * @param string $key Identifier for the data * @param mixed $value Data to be cached - anything except a resource * @param int|null $ttl Time to live in seconds * * @return bool True if the data was successfully cached, false on failure */ public function write($key, $value, $ttl = null) { return $this->cache->write($this->prefix($key), $value, $ttl); }