Пример #1
0
 public function index_onSave()
 {
     try {
         $config = new Sitemap_Params();
         $config = $config->load();
         $config->save(post($this->form_model_class, array()), $this->formGetEditSessionKey());
         echo Backend_Html::flash_message('Sitemap configuration has been successfully saved.');
     } catch (Exception $ex) {
         Phpr::$response->ajaxReportException($ex, true, true);
     }
     //save pages
     $page_list = Cms_Page::create()->find_all();
     foreach ($page_list as $id => $page) {
         $visible = 0;
         if (isset($_POST['pages'][$page->id])) {
             $visible = 1;
         }
         Db_DbHelper::query('update pages set sitemap_visible=:visible where id=:id', array('visible' => $visible, 'id' => $page->id));
     }
 }
 public function generate()
 {
     $this->params = Sitemap_Params::create();
     $this->xml = new DOMDocument();
     $this->xml->encoding = 'UTF-8';
     $this->urlset = $this->xml->createElement('urlset');
     $this->urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     $this->urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $this->urlset->setAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');
     try {
         $active_theme = false;
         if (Cms_Theme::is_theming_enabled()) {
             $active_theme = Cms_Theme::get_active_theme();
         }
         if ($this->params->include_navigation_hidden) {
             $page_list = Cms_Page::create()->where('is_published=1')->where('sitemap_visible=1')->where('security_mode_id <> "customers"');
         } else {
             $page_list = Cms_Page::create()->where('is_published=1')->where('sitemap_visible=1')->where('navigation_visible=1')->where('security_mode_id <> "customers"');
         }
         if ($active_theme) {
             $page_list->where('theme_id = ?', $active_theme->id);
         }
         $page_list = $page_list->find_all();
         if (count($page_list)) {
             foreach ($page_list as $page) {
                 $page_url = site_url($page->url);
                 if (substr($page_url, -1) != '/') {
                     $page_url .= '/';
                 }
                 $this->add_url_element($page_url, date('c', strtotime($page->updated_at ? $page->updated_at : $page->created_at)), 'weekly', '0.7');
             }
         }
         if ($this->url_count < self::max_urls && $this->params->include_categories) {
             if ($this->params->include_hidden_categories) {
                 $category_list = Shop_Category::create()->limit(self::max_generated)->order('shop_categories.updated_at desc')->find_all();
             } else {
                 $category_list = Shop_Category::create()->limit(self::max_generated)->order('shop_categories.updated_at desc')->where('category_is_hidden is not true')->find_all();
             }
             foreach ($category_list as $category) {
                 $category_url = site_url($category->page_url($this->params->categories_path));
                 if (substr($category_url, -1) != '/') {
                     $category_url .= '/';
                 }
                 $this->add_url_element($category_url, date('c', strtotime($category->updated_at ? $category->updated_at : $category->created_at)), $this->params->categories_changefreq, $this->params->categories_priority);
             }
         }
         if ($this->url_count < self::max_urls && $this->params->include_products) {
             $include_not_visible_catalog = $this->params->include_products_not_visible_catalog ? true : false;
             $include_not_visible_search = $this->params->include_products_not_visible_search ? true : false;
             if ($include_not_visible_catalog) {
                 //traceLog("include_not_visible_catalog = true");
             } else {
                 //traceLog("include_not_visible_catalog = false");
             }
             if ($include_not_visible_search) {
                 //traceLog("include_not_visible_search = true");
             } else {
                 //traceLog("include_not_visible_search = false");
             }
             $root_url = Phpr::$request->getRootUrl();
             $lssalestracking_installed = Core_ModuleManager::findById('lssalestracking');
             //$lssalestracking_installed = Db_DbHelper::scalar('select count(*) from core_install_history where moduleId = ?', 'lssalestracking');
             if ($lssalestracking_installed && class_exists('LsSalesTracking_ProductManager')) {
                 $product_list = new Shop_Product(null, array('no_column_init' => true, 'no_validation' => true));
                 $product_list = $product_list->apply_filters()->where('enabled=1');
                 if (!$include_not_visible_catalog) {
                     $product_list->where('visibility_catalog = 1');
                 }
                 if (!$include_not_visible_search) {
                     $product_list->where('visibility_search = 1');
                 }
                 $product_list->limit(self::max_generated)->order('shop_products.updated_at desc')->find_all();
             } else {
                 //traceLog("lssalestracking NOT installed");
                 $product_list_sql = 'select sp.url_name, sp.updated_at, sp.created_at, sp.id, p.url, p.is_published from shop_products sp left outer join pages p on (sp.page_id = p.id) where sp.enabled is true and (sp.grouped is null or sp.grouped = 0) ';
                 if (!$include_not_visible_catalog) {
                     $product_list_sql .= 'and visibility_catalog = 1 ';
                 }
                 if (!$include_not_visible_search) {
                     $product_list_sql .= 'and visibility_search = 1 ';
                 }
                 $product_list_sql .= 'order by updated_at limit ' . self::max_generated;
                 //traceLog($product_list_sql);
                 $product_list = Db_DbHelper::objectArray($product_list_sql);
             }
             foreach ($product_list as $product) {
                 if ($lssalestracking_installed && class_exists('LsSalesTracking_ProductManager')) {
                     $product_url = site_url($this->params->products_path . LsSalesTracking_ProductManager::get_marketplace_product_url($product));
                 } else {
                     //$product_url = $root_url.$product->page_url($this->params->products_path);
                     $product->url = $this->get_product_url($product->id, $product->url);
                     if ($product->url != '' && $product->is_published == 1) {
                         $page = $product->url;
                     } else {
                         $page = $this->params->products_path;
                     }
                     $product_url = site_url($page . '/' . $product->url_name);
                 }
                 if (substr($product_url, -1) != '/') {
                     $product_url .= '/';
                 }
                 $this->add_url_element($product_url, date('c', strtotime($product->updated_at ? $product->updated_at : $product->created_at)), $this->params->products_changefreq, $this->params->products_priority);
             }
         }
         if ($this->url_count < self::max_urls && $this->params->include_blogposts) {
             $blog_post_list = Blog_Post::create()->limit(self::max_generated)->order('blog_posts.updated_at desc')->find_all();
             foreach ($blog_post_list as $blog_post) {
                 $blogpost_url = site_url($this->params->blogposts_path . '/' . $blog_post->url_title);
                 if (substr($blogpost_url, -1) != '/') {
                     $blogpost_url .= '/';
                 }
                 $this->add_url_element($blogpost_url, date('c', strtotime($blog_post->published_date)), $this->params->blogposts_changefreq, $this->params->blogposts_priority);
             }
         }
         $wiki_installed = Core_ModuleManager::findById('wiki');
         if ($this->url_count < self::max_urls && $wiki_installed && $this->params->include_wiki && class_exists('Wiki_Page')) {
             $wiki_page_list = Wiki_Page::create()->limit(self::max_generated)->where('is_published=1')->order('wiki_pages.updated_at desc')->find_all();
             foreach ($wiki_page_list as $wiki_page) {
                 $wiki_url = site_url($this->params->wiki_path . '/' . $wiki_page->url_title);
                 if (substr($wiki_url, -1) != '/') {
                     $wiki_url .= '/';
                 }
                 $this->add_url_element($wiki_url, date('c', strtotime($wiki_page->updated_at ? $wiki_page->updated_at : $wiki_page->created_at)), $this->params->wiki_changefreq, $this->params->wiki_priority);
             }
         }
         Backend::$events->fireEvent('sitemap:onGenerateSitemap', $this, $this->params);
     } catch (Sitemap_Generator_Exception $ex) {
     }
     $this->xml->appendChild($this->urlset);
 }