Exemple #1
0
 public function getItems()
 {
     $items = parent::getItems();
     if (!empty($items)) {
         foreach ($items as $item) {
             $u = new AimySitemapURI($item->url);
             $item->url = $u->getResourceHTML();
             $item->href = $u->getResourceHref();
         }
     }
     return $items;
 }
Exemple #2
0
 private static function get_via_http()
 {
     require_once JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_aimysitemap' . DIRECTORY_SEPARATOR . 'HttpClient.php';
     try {
         $u = new AimySitemapURI(JURI::root());
         $u->setPath('/robots.txt');
         $r = AimySitemapHttpClient::get_url($u);
         if (is_array($r) && $r['head']['code'] == 200) {
             return $r['body'];
         }
     } catch (Exception $e) {
     }
     return null;
 }
Exemple #3
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;
 }