Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/iatax.com.au/public_html/application/libraries/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * Sitemap Class * Copyright (c) 2008 - 2013 All Rights Reserved. * * Props to Mike's Imagination for the approach * http://www.mikesimagination.net/blog/post/29-Aug-12/Codeigniter-auto-XML-sitemap * * Generates sitemap */ class Sitemap { // CI instance property protected $ci; /** * Constructor */ public function __construct() { // Get the CI instance by reference to make the CI superobject available in this library $this->ci =& get_instance(); $this->ci->load->database(); } /** * Generate sitemap */ public function create() { // Begin assembling the sitemap starting with the header $sitemap = "<\x3Fxml version=\"1.0\" encoding=\"UTF-8\"\x3F>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; // Add static pages not in database to sitemap // Home page $sitemap .= "\t<url>\n\t\t<loc>" . site_url() . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>1.00</priority>\n\t</url>\n\n"; // About page $sitemap .= "\t<url>\n\t\t<loc>" . site_url('about') . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>0.80</priority>\n\t</url>\n\n"; // Our Team page $sitemap .= "\t<url>\n\t\t<loc>" . site_url('our-team') . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>0.80</priority>\n\t</url>\n\n"; // Services page $sitemap .= "\t<url>\n\t\t<loc>" . site_url('services') . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>0.80</priority>\n\t</url>\n\n"; // Blog page $sitemap .= "\t<url>\n\t\t<loc>" . site_url('blog') . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>0.80</priority>\n\t</url>\n\n"; // Resources page $sitemap .= "\t<url>\n\t\t<loc>" . site_url('resources') . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>0.80</priority>\n\t</url>\n\n"; // Contact page $sitemap .= "\t<url>\n\t\t<loc>" . site_url('contact') . "</loc>\n\t\t<lastmod>2021-12-17T06:50:42+00:00</lastmod>\n\t\t<priority>0.80</priority>\n\t</url>\n\n"; // Get all blog (records) from database. Load (or autoload) the model // $this->load->database(); $services = $this->ci->db->select('*')->from('services')->where('status', '1')->order_by('priority', 'asc')->get()->result(); $blogs = $this->ci->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC')->get()->result(); // Add each recipe URL to the sitemap while enclosing the URL in the XML <url> tags // Since my database tracks the last updated date, I am including that as well - but with the date only in YYYY-MM-DD format foreach($services as $service) { $sitemap .= "\t<url>\n\t\t<loc>" . site_url('services/' . $service->slug) . "</loc>\n"; $sitemap .= "\t\t<lastmod><lastmod>2021-12-17T06:50:42+00:00</lastmod></lastmod>\n"; $sitemap .= "\t\t<priority>0.80</priority>\n \t</url>\n\n"; } foreach($blogs as $blog) { $sitemap .= "\t<url>\n\t\t<loc>" . site_url('blog/' . $blog->alias_en) . "</loc>\n"; $sitemap .= "\t\t<lastmod>" . date('c' ,strtotime($blog->updated_at)) . "</lastmod>\n"; $sitemap .= "\t\t<priority>0.64</priority>\n \t</url>\n\n"; } // If you have other records you wish to include, get those and continue to append URL's to the sitemap. // Close with the footer $sitemap .= "</urlset>\n"; // Write the sitemap string to file. Make sure you have permissions to write to this file. $file = fopen('sitemap.xml', 'w'); fwrite($file, $sitemap); fclose($file); // If this is the production instance, attempt to update Google with the new sitemap. // (The instance is set in the index.php file) if(ENVIRONMENT === 'production') { // Ping Google via http request with the encoded sitemap URL $sitemap_url = site_url('sitemap.xml'); $google_url = "http://www.google.com/webmasters/tools/ping?sitemap=".urlencode($sitemap_url); $ch = curl_init(); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,2); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt ($ch, CURLOPT_URL, $google_url); $response = curl_exec($ch); $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Log error if update fails if (substr($http_status, 0, 1) != 2) { log_message('error', 'Ping Google with updated sitemap failed. Status: ' . $http_status); log_message('error', ' ' . $google_url); } } return; } }