function onJotcacheRecache($starturl, $jcplugin, $jcparams, $jcstates) { if ($jcplugin != 'recache') { return; } $params = JComponentHelper::getParams('com_jotcache'); $logging = $params->get('recachelog', 0) == 1 ? true : false; $database = JFactory::getDBO(); $sql = $database->getQuery(true); $sql->select('fname,uri,browser')->from('#__jotcache')->where("recache = 1"); $database->setQuery($sql); $rows = $database->loadObjectList(); $browsers = BrowserAgents::getBrowserAgents(); $hits = array(); $warns = 0; $delcount = 5; $delpages = array(); $runner = new RecacheRunner(); foreach ($rows as $row) { if (defined('JOTCACHE_RECACHE_BROWSER')) { if (!file_exists(JPATH_ROOT . '/cache/page/jotcache_recache_flag_tmp.php')) { return; } } $browser = array_key_exists($row->browser, $browsers) ? $browsers[$row->browser][1] : BrowserAgents::getDefaultAgent(); $agent = $browser . ' jotcache \\r\\n'; $pos = strpos(trim($row->uri), 'http'); if ($pos === 0) { $ret = $runner->getData($row->uri, $agent); } else { preg_match('#http[s]?://[^/\\n]*#', $starturl, $matches); $root = $matches[0]; $ret = $runner->getData($root . $row->uri, $agent); } if ($ret === false) { $warns++; if ($logging) { $browser_err = $row->browser == "" ? '' : '(' . $row->browser . ')'; JLog::add(sprintf('WARN uri%s `%s` was not accessed during recache', $browser_err, $row->uri), JLog::INFO, 'jotcache.recache'); } if ($warns > 9) { return array("recache", "STOPPED after 10 WARNs", $hits); } } else { if (array_key_exists($row->browser, $hits)) { $hits[$row->browser] += 1; } else { $hits[$row->browser] = 1; } } $delpages[] = $row->fname; if ($delcount === 0) { $this->clearRecacheFlags($delpages); $delcount = 6; } $delcount--; } $this->clearRecacheFlags($delpages); return array("recache", "DONE", $hits); }
private function executeRunner($app) { $main = new RecacheRunner(); $input = $app->input; $jcplugin = strtolower($input->getWord('jotcacheplugin')); $jcparams = $input->get->get('jcparams', array(), 'array'); $states = $input->post->get('jcstates', array(), 'array'); $jcstates = array(); if (count($states) > 0) { foreach ($states as $key => $value) { $curState = $app->getUserState('jotcache.' . $jcplugin . '.' . $key, null); $newState = $states[$key]; if ($curState !== $newState) { $jcstates[$key] = $newState; $app->setUserState('jotcache.' . $jcplugin . '.' . $key, $newState); } else { $jcstates[$key] = $curState; } } } $starturl = JURI::root(); if (substr($starturl, -1) == '/') { $starturl = substr($starturl, 0, strlen($starturl) - 1); } $main->doExecute($starturl, $jcplugin, $jcparams, $jcstates); }
function runRecache() { $params = JComponentHelper::getParams("com_jotcache"); $timeout = (int) $params->get('recachetimeout', 300); register_shutdown_function(array($this, 'recacheShutdown')); ini_set('max_execution_time', $timeout); $scopeAllow = array('none', 'chck', 'sel', 'all', 'direct'); $scope = JRequest::getWord('scope', ''); if (in_array($scope, $scopeAllow, TRUE)) { $this->_sql = $this->_db->getQuery(true); switch ($scope) { case 'none': return; case 'chck': $this->_sql->update($this->_db->quoteName('#__jotcache'))->set($this->_db->quoteName('recache') . ' = ' . $this->_db->quote(1))->set($this->_db->quoteName('recache_chck') . ' = ' . $this->_db->quote(0))->where("recache_chck='1'"); $sql = $this->_db->setQuery($this->_sql); $sql->query(); break; case 'sel': $search = JRequest::getString('search'); $com = JRequest::getCmd('com'); $view = JRequest::getCmd('pview'); $mark = JRequest::getInt('mark'); $params = JComponentHelper::getParams("com_jotcache"); $mode = (bool) $params->get('mode'); if ($com) { $this->_sql->where("com='{$com}'"); } if ($view) { $part = $this->_db->quoteName('view'); $this->_sql->where("{$part}='{$view}'"); } if ($mark) { $this->_sql->where("mark='{$mark}'"); } if ($search) { if ($mode) { $this->_sql->where('LOWER(uri) LIKE ' . $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%', false)); } else { $this->_sql->where('LOWER(title) LIKE ' . $this->_db->Quote('%' . $this->_db->getEscaped($search, true) . '%', false)); } } break; default: break; } if ($scope != 'direct') { $this->_sql->update($this->_db->quoteName('#__jotcache'))->set($this->_db->quoteName('recache') . ' = ' . $this->_db->quote(1)); $sql = $this->_db->setQuery($this->_sql); $sql->query(); } $this->controlRecache(1); define('JOTCACHE_RECACHE_BROWSER', true); $main = new RecacheRunner(); $jcplugin = strtolower(JRequest::getWord('jotcacheplugin')); $jcparams = JRequest::getVar('jcparams', array(), 'get', 'array'); $states = JRequest::getVar('jcstates', array(), 'post', 'array'); $jcstates = array(); if (count($states) > 0) { $app = JFactory::getApplication(); foreach ($states as $key => $value) { $cur_state = $app->getUserState('jotcache.' . $jcplugin . '.' . $key, null); $new_state = $states[$key]; if ($cur_state !== $new_state) { $jcstates[$key] = $new_state; $app->setUserState('jotcache.' . $jcplugin . '.' . $key, $new_state); } else { $jcstates[$key] = $cur_state; } } } $starturl = JURI::root(); if (substr($starturl, -1) == '/') { $starturl = substr($starturl, 0, strlen($starturl) - 1); } $main->doExecute($starturl, $jcplugin, $jcparams, $jcstates); } }