public function crawl_ajax() { JSession::checkToken() or jexit(JText::_('INVALID TOKEN')); $rights = AimySitemapRightsHelper::getRights(); if (!$rights->get('aimysitemap.crawl')) { jexit(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } header('Content-Type: application/json; charset=UTF-8'); $crawler = new AimySitemapCrawler(); $res = null; try { $res = $crawler->crawl(); } catch (Exception $e) { AimySitemapLogger::error("Crawl-Ctrl: Exception: {$e}"); error_log("{$e}"); echo json_encode(array('ok' => false, 'msg' => $e->getMessage())), "\n"; return JFactory::getApplication()->close(); } if (isset($res['url'])) { AimySitemapLogger::debug('Crawl: done' . (isset($res['msg']) ? ': ' . $res['msg'] : '')); } if (isset($res['abort']) && $res['abort']) { AimySitemapLogger::debug('Crawl: ' . (isset($res['ok']) && $res['ok'] ? 'finished' : 'aborted')); if (isset($res['ok']) && $res['ok']) { if (defined('JDEBUG') && JDEBUG) { $res = array('ok' => 1, 'abort' => 1, 'msg' => JText::_('AIMY_SM_MSG_VIEW_LOG'), 'stats' => array()); } else { require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'kvstore.php'; if (AimySitemapKVStore::get('rebuilding')) { $res = array('ok' => 1, 'msg' => JText::_('AIMY_SM_MSG_REBUILDING'), 'rebuilding' => 1); } else { AimySitemapKVStore::set('rebuilding', 1); require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'Sitemap.php'; $sm = new AimySitemapSitemap(); $res['stats'] = $sm->rebuild(); AimySitemapCrawler::delete_crawl_data(); AimySitemapKVStore::delete('rebuilding'); } } } } echo json_encode($res), "\n"; JFactory::getApplication()->close(); }