google_sitemap.php (4308B)
1 <?php 2 class ControllerExtensionFeedGoogleSitemap extends Controller { 3 public function index() { 4 if ($this->config->get('feed_google_sitemap_status')) { 5 $output = '<?xml version="1.0" encoding="UTF-8"?>'; 6 $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'; 7 8 $this->load->model('catalog/product'); 9 $this->load->model('tool/image'); 10 11 $products = $this->model_catalog_product->getProducts(); 12 13 foreach ($products as $product) { 14 if ($product['image']) { 15 $output .= '<url>'; 16 $output .= ' <loc>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</loc>'; 17 $output .= ' <changefreq>weekly</changefreq>'; 18 $output .= ' <lastmod>' . date('Y-m-d\TH:i:sP', strtotime($product['date_modified'])) . '</lastmod>'; 19 $output .= ' <priority>1.0</priority>'; 20 $output .= ' <image:image>'; 21 $output .= ' <image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height')) . '</image:loc>'; 22 $output .= ' <image:caption>' . $product['name'] . '</image:caption>'; 23 $output .= ' <image:title>' . $product['name'] . '</image:title>'; 24 $output .= ' </image:image>'; 25 $output .= '</url>'; 26 } 27 } 28 29 $this->load->model('catalog/category'); 30 31 $output .= $this->getCategories(0); 32 33 $this->load->model('catalog/manufacturer'); 34 35 $manufacturers = $this->model_catalog_manufacturer->getManufacturers(); 36 37 foreach ($manufacturers as $manufacturer) { 38 $output .= '<url>'; 39 $output .= ' <loc>' . $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufacturer['manufacturer_id']) . '</loc>'; 40 $output .= ' <changefreq>weekly</changefreq>'; 41 $output .= ' <priority>0.7</priority>'; 42 $output .= '</url>'; 43 44 $products = $this->model_catalog_product->getProducts(array('filter_manufacturer_id' => $manufacturer['manufacturer_id'])); 45 46 foreach ($products as $product) { 47 $output .= '<url>'; 48 $output .= ' <loc>' . $this->url->link('product/product', 'manufacturer_id=' . $manufacturer['manufacturer_id'] . '&product_id=' . $product['product_id']) . '</loc>'; 49 $output .= ' <changefreq>weekly</changefreq>'; 50 $output .= ' <priority>1.0</priority>'; 51 $output .= '</url>'; 52 } 53 } 54 55 $this->load->model('catalog/information'); 56 57 $informations = $this->model_catalog_information->getInformations(); 58 59 foreach ($informations as $information) { 60 $output .= '<url>'; 61 $output .= ' <loc>' . $this->url->link('information/information', 'information_id=' . $information['information_id']) . '</loc>'; 62 $output .= ' <changefreq>weekly</changefreq>'; 63 $output .= ' <priority>0.5</priority>'; 64 $output .= '</url>'; 65 } 66 67 $output .= '</urlset>'; 68 69 $this->response->addHeader('Content-Type: application/xml'); 70 $this->response->setOutput($output); 71 } 72 } 73 74 protected function getCategories($parent_id, $current_path = '') { 75 $output = ''; 76 77 $results = $this->model_catalog_category->getCategories($parent_id); 78 79 foreach ($results as $result) { 80 if (!$current_path) { 81 $new_path = $result['category_id']; 82 } else { 83 $new_path = $current_path . '_' . $result['category_id']; 84 } 85 86 $output .= '<url>'; 87 $output .= ' <loc>' . $this->url->link('product/category', 'path=' . $new_path) . '</loc>'; 88 $output .= ' <changefreq>weekly</changefreq>'; 89 $output .= ' <priority>0.7</priority>'; 90 $output .= '</url>'; 91 92 $products = $this->model_catalog_product->getProducts(array('filter_category_id' => $result['category_id'])); 93 94 foreach ($products as $product) { 95 $output .= '<url>'; 96 $output .= ' <loc>' . $this->url->link('product/product', 'path=' . $new_path . '&product_id=' . $product['product_id']) . '</loc>'; 97 $output .= ' <changefreq>weekly</changefreq>'; 98 $output .= ' <priority>1.0</priority>'; 99 $output .= '</url>'; 100 } 101 102 $output .= $this->getCategories($result['category_id'], $new_path); 103 } 104 105 return $output; 106 } 107 }