Exemplo n.º 1
0
 public function action_index()
 {
     $cache_key = 'sourcemap-sitemap';
     $ttl = 60 * 60 * 24;
     if ($cached = Cache::instance()->get($cache_key)) {
         $xml = $cached;
     } else {
         // Sitemap instance.
         $sitemap = new Sitemap();
         // basics
         $urls = array('home' => array('', 0.9, 'daily', time()), 'register' => array('register/', 0.6, 'yearly'), 'browse' => array('browse/', 0.7, 'daily', time()), 'login' => array('auth/login', 0.5, 'yearly'), 'about' => array('info/', 0.7, 'monthly'), 'api' => array('info/api', 0.7, 'monthly'), 'contact' => array('info/contact', 0.8, 'monthly'));
         // categories
         $cats = Sourcemap_Taxonomy::arr();
         $nms = array();
         foreach ($cats as $i => $cat) {
             $slug = Sourcemap_Taxonomy::slugify($cat->name);
             $urls['browse-' . $cat->name] = array('browse/' . $slug . '/', 0.7);
         }
         // public maps
         $o = 0;
         $l = 100;
         while (($results = Sourcemap_Search::find(array('o' => $o, 'l' => $l))) && $results->hits_ret) {
             foreach ($results->results as $i => $r) {
                 $urls['sc-' . $r->id] = array('view/' . $r->id, 0.5, 'daily', $r->modified);
             }
             $o += $l;
         }
         $defaults = array(false, 0.5, 'daily', false);
         foreach ($urls as $k => $urld) {
             foreach ($defaults as $i => $d) {
                 if (!isset($urld[$i])) {
                     $urld[$i] = $d;
                 }
             }
             list($loc, $priority, $freq, $lastmod) = $urld;
             $new_url = new Sitemap_URL();
             $new_url->set_loc(URL::site($loc, true))->set_priority($priority)->set_change_frequency($freq);
             if ($lastmod) {
                 $new_url->set_last_mod($lastmod);
             }
             $sitemap->add($new_url);
         }
         $xml = $sitemap->render();
         Cache::instance()->set($cache_key, $xml, $ttl);
     }
     header('Content-Type: application/xml');
     $this->response = $xml;
     die($this->response);
 }
Exemplo n.º 2
0
 protected function _generate()
 {
     $_common_set = array();
     $this->pages_uris = Helper_Page::parse_to_base_uri(ORM::factory('page')->find_all());
     $pages = $this->get_pages();
     foreach ($pages as $item) {
         $item = $this->set_default_values($item);
         $_set = array();
         if ($item['type'] == 'static') {
             $_set[] = $this->_page_item($item);
         } elseif ($item['type'] == 'module') {
             switch ($item['data']) {
                 case 'cities':
                 case 'contacts':
                 case 'chart':
                 case 'feedback':
                 case 'playlist':
                 case 'search':
                     $_set[] = $this->_page_item($item);
                     break;
                 case 'news':
                     $_set = $this->_news_items($item);
                     break;
                 case 'programs':
                     $_set = $this->_programs_items($item);
                     break;
                 case 'staff':
                     $_set = $this->_staff_items($item);
                     break;
             }
         }
         if ($item['sm_separate_file'] == 1 and !empty($_set)) {
             $sitemap = new Sitemap();
             foreach ($_set as $_item) {
                 $sitemap_url = new Sitemap_URL();
                 $sitemap_url->set_loc($_item['loc'])->set_change_frequency($_item['changefreq'])->set_priority(str_replace(',', '.', $_item['priority']));
                 if (!empty($_item['lastmod'])) {
                     $_unix_time = strtotime($_item['lastmod']);
                     $sitemap_url->set_last_mod($_unix_time);
                 }
                 $sitemap->add($sitemap_url);
                 unset($sitemap_url);
             }
             $this->write_to_file($this->sitemap_directory . DIRECTORY_SEPARATOR . 'part_' . uniqid() . '.xml', $sitemap->render());
             unset($sitemap);
         } else {
             $_common_set = array_merge($_common_set, $_set);
         }
     }
     if (!empty($_common_set)) {
         $sitemap = new Sitemap();
         foreach ($_common_set as $_item) {
             $sitemap_url = new Sitemap_URL();
             $sitemap_url->set_loc($_item['loc'])->set_change_frequency($_item['changefreq'])->set_priority(str_replace(',', '.', $_item['priority']));
             if (!empty($_item['lastmod'])) {
                 $_unix_time = strtotime($_item['lastmod']);
                 $sitemap_url->set_last_mod($_unix_time);
             }
             $sitemap->add($sitemap_url);
             unset($sitemap_url);
         }
         $this->write_to_file($this->sitemap_directory . DIRECTORY_SEPARATOR . uniqid('common_') . '.xml', $sitemap->render());
         unset($sitemap);
     }
 }
Exemplo n.º 3
0
 /**
  * @test
  * @group sitemap
  * @dataProvider provider_set_last_mod
  * @param mixed $time
  * @param boolean $raise_exception
  */
 public function test_set_last_mod($time, $raise_exception = FALSE)
 {
     $instance = new Sitemap_URL();
     if ($raise_exception) {
         try {
             $instance->set_last_mod($time);
         } catch (InvalidArgumentException $e) {
             return;
         }
         $this->fail('The InvalidArgumentException was not raised');
     } else {
         $return = $instance->set_last_mod($time);
         $this->assertSame($instance, $return);
     }
 }