Exemple #1
0
 public function display($tpl = null)
 {
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $app = JFactory::getApplication();
     if ($app->isSSLConnection()) {
         $msg = new AimySitemapMessageHelper();
         $msg->notice(JText::_('AIMY_SM_CRAWL_HINT_SSL_ONLY'));
     }
     if ($this->get_config($app, 'offline')) {
         $msg = new AimySitemapMessageHelper();
         $msg->error(JText::_('AIMY_SM_ERR_SITE_OFFLINE'));
         $this->addToolbar();
         return false;
     }
     if (defined('JDEBUG') && JDEBUG) {
         $msg = new AimySitemapMessageHelper();
         $msg->notice(JText::sprintf('AIMY_SM_MSG_CRAWL_DEBUG_ENABLED', AimySitemapLogger::get_path()));
     }
     $rights = AimySitemapRightsHelper::getRights();
     $this->allow_crawl = $rights->get('aimysitemap.crawl');
     $this->allow_config = $rights->get('core.admin');
     $this->addToolbar();
     if ($this->allow_crawl) {
         JFactory::getDocument()->addScript(JUri::root() . 'administrator/components/' . 'com_aimysitemap/helpers/crawl.js' . '?r=3.16.0');
     } else {
         $msg = new AimySitemapMessageHelper();
         $msg->error(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
     }
     parent::display($tpl);
 }
Exemple #2
0
 public function write_sitemap_file()
 {
     require_once JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_aimysitemap' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'message.php';
     $cfg = new AimySitemapConfigHelper();
     $msg = new AimySitemapMessageHelper();
     $rel_path = $cfg->get('xml_path');
     if (empty($rel_path)) {
         $msg->error(JText::_('AIMY_SM_MSG_XML_FILE_NOT_SET'));
         return false;
     }
     $domain = null;
     $proto = null;
     $msg->notice(JText::sprintf('AIMY_SM_MSG_CANONICAL_COMBINE', 'http://www.aimy-extensions.com/combining-aimy-canonical-and-sitemap.html'));
     if (empty($domain)) {
         $domain = self::get_current_domain();
     }
     if (empty($proto)) {
         $proto = self::get_current_protocol();
     }
     $db = JFactory::getDbo();
     $q = $db->getQuery(true);
     $q->select($db->quoteName(array('url', 'priority', 'mtime', 'changefreq')))->from($db->quoteName('#__aimysitemap'))->where($db->quoteName('state') . '=' . '1');
     $db->setQuery($q);
     $rows = $db->loadObjectList();
     $xml = array('<?xml version="1.0" encoding="UTF-8"?>', '<urlset ' . 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">');
     foreach ($rows as $row) {
         $u = new AimySitemapURI($row->url);
         $xml[] = sprintf('<url>' . '<loc>%s://%s%s</loc>' . '%s' . '<changefreq>%s</changefreq>' . '<priority>%.1f</priority>' . '</url>', $proto, $domain, $u->getResourceHref(), $row->mtime ? sprintf('<lastmod>%s</lastmod>', date('Y-m-d', $row->mtime)) : '', $row->changefreq, $row->priority);
     }
     $xml[] = '</urlset>';
     $full_path = JPATH_ROOT . '/' . $rel_path;
     $sitemap_xml = implode("\n", $xml);
     if (JFile::write($full_path, $sitemap_xml) == false) {
         $msg->error(JText::sprintf('AIMY_SM_MSG_XML_FILE_ERR_WRITE', $full_path));
         return false;
     }
     $msg->message(JText::sprintf('AIMY_SM_MSG_XML_FILE_UPDATED', $rel_path));
     return true;
 }