6,7c6,7 < Author: Manuel Sechi - msechi@gmail.com < Version: 0.3.0 --- > Author: Manuel Sechi - msechi@gmail.com, SignpostMarv Martin - http://blog.signpostmarv.name/ > Version: 0.4 28,29c28,29 < RewriteRule ^sitemap.xml$ /files/sitemap.xml < RewriteRule ^robots.txt$ /files/robots.txt [L] --- > RewriteRule ^(.*/)?sitemap.xml wp-content/blogs.php?file=sitemap.xml > RewriteRule ^(.*/)?robots.txt wp-content/blogs.php?file=robots.txt 50,63c50,56 < $ms_muXmlSitemap = new ms_muXmlSitemap(); < add_action('publish_post', array($ms_muXmlSitemap, 'doJob')); < add_action('delete_post', array($ms_muXmlSitemap, 'doJob')); < < < class ms_muXmlSitemap { < < private $permealinkStructure; < private $sitemap; < private $urlSitemap; < < function __construct() { < $this->permealinkStructure = $this->getPermealinkStructure(); < } --- > class mu_google_sitemaps > { > private static $urlSitemap; > private static $ping = array( > 'http://www.google.com/webmasters/sitemaps/ping?sitemap=', > 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=%s', > ); 65,67c58,59 < function __destruct() { < < } --- > const sql_getResults = 'select wpp.ID as post_id, wpp.post_date, wpp.post_name, wpp.post_type, wpc.category_nicename, wpa.user_nicename from %s as wpp left join %s as wpc on wpp.post_category = wpc.cat_ID left join wp_users as wpa on wpp.post_author = wpa.ID where post_status = "publish"'; > const sql_getPermalinkStructure = 'SELECT option_name, option_type, option_value FROM %s WHERE option_name = "permalink_structure" LIMIT 1'; 69c61 < public function doJob() { --- > public static function doJob() { 72,74c64,65 < $result = $this->getResults(); < $this->sitemap = $this->getSitemapdir()."/sitemap.xml"; < $this->writeMap($result, $this->sitemap); --- > $result = self::getResults(); > self::writeMap($result, self::getSitemapdir() . '/sitemap.xml'); 77,85c68,82 < $this->urlSitemap = $user_url."sitemap.xml"; < // ping to google < $url = "http://www.google.com/webmasters/sitemaps/ping?sitemap=".$this->urlSitemap; < $this->callService($url); < // ping to Yahoo < $url = "http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=".$this->urlSitemap; < $this->callService($url); < < $this->checkRobotsTxtFile(); --- > self::$urlSitemap = $user_url."sitemap.xml"; > self::ping(self::$urlSitemap); > self::checkRobotsTxtFile(); > } > > public static function ping($url) > { > if(empty(self::$ping) === true) > { > return; > } > foreach(self::$ping as $service) > { > self::callService(sprintf($service,$url)); > } 88c85 < private function getPermealinkStructure() { --- > private static function getPermalinkStructure() { 90,91c87,89 < $sql = "select option_name, option_type, option_value from ".$wpdb->options." where option_name = 'permalink_structure'"; < $row = $wpdb->get_row($sql); --- > $row = $wpdb->get_row(sprintf(self::sql_getPermalinkStructure, > $wpdb->options > )); 95c93 < private function getSitemapdir() { --- > private static function getSitemapdir() { 99,102c97,101 < $sitemapDir = $_SERVER['DOCUMENT_ROOT']."/wp-content/blogs.dir/$blogid/files"; < if(!is_dir($sitemapDir)) < mkdir($sitemapDir, 0777, true); < --- > $sitemapDir = ABSPATH . '/wp-content/blogs.dir/' . $blogid . '/files'; > if(is_dir($sitemapDir) === false) > { > mkdir($sitemapDir, 0755, true); > } 108,109c107,110 < $sql = "select wpp.ID as post_id, wpp.post_date, wpp.post_name, wpp.post_type, wpc.category_nicename, wpa.user_nicename from ".$wpdb->posts." as wpp left join ".$wpdb->categories." as wpc on wpp.post_category = wpc.cat_ID left join wp_users as wpa on wpp.post_author = wpa.ID where post_status = 'publish';"; < $result = $wpdb->get_results($sql); --- > $result = $wpdb->get_results(sprintf(self::sql_getResults, > $wpdb->posts, > $wpdb->categories > )); 113c114 < private function writeMap($result, $dest) { --- > private static function writeMap($result, $dest) { 116c117,118 < if(file_exists($dest)) --- > if(file_exists($dest) === true) > { 118c120 < --- > } 123c125,126 < foreach($result as $ele) { --- > foreach($result as $ele) > { 129,133c132,142 < $post_author = $ele->user_nicename; < < if($post_type == 'post') { < $loc = $user_url.$this->permealinkStructure; < $loc = $this->changePermealinkStructure($loc, $ele->post_date, $post_name, $post_category, $post_id, $post_author); --- > $post_author = $ele->user_nicename; > if($post_type == 'post') > { > $loc = self::changePermalinkStructure( > $user_url . self::getPermalinkStructure(), > $ele->post_date, > $post_name, > $post_category, > $post_id, > $post_author > ); 136,138c145,148 < $loc = $user_url."$post_name"; < < $url = $dom->createElement("url"); --- > { > $loc = $user_url . $post_name ; > } > $url = $dom->createElement('url'); 145c155 < $urlset->appendChild($url); --- > $urlset->appendChild($url); 148c158 < $dom->save($dest); --- > $dom->save($dest); 151,152c161,164 < private function callService($url) { < if (function_exists('curl_init')) { --- > private static function callService($url) > { > if (function_exists('curl_init')) > { 155c167,168 < if (flock($fp, LOCK_EX)) { --- > if (flock($fp, LOCK_EX)) > { 161c174,175 < else { --- > else > { 167c181,182 < else { --- > else > { 172c187,188 < private function changePermealinkStructure($loc, $arr_date, $post_name, $post_category, $post_id, $post_author) { --- > private static function changePermalinkStructure($loc, $arr_date, $post_name, $post_category, $post_id, $post_author) > { 188,191c204,208 < private function checkRobotsTxtFile() { < $robotsTxtFile = $this->getSitemapdir()."/robots.txt"; < < if(file_exists($robotsTxtFile)) { --- > function checkRobotsTxtFile() > { > $robotsTxtFile = self::getSitemapdir() . '/robots.txt'; > if(file_exists($robotsTxtFile) === true) > { 194c211,212 < foreach($arrFileRobotsTxt as $riga) { --- > foreach($arrFileRobotsTxt as $riga) > { 195a214 > { 196a216,217 > break; > } 198,200c219,222 < if($found === false) { < $arrFileRobotsTxt[] = "Sitemap: ".$this->urlSitemap; < $this->writeRobotsTxtFile($robotsTxtFile, $arrFileRobotsTxt); --- > if($found === false) > { > $arrFileRobotsTxt[] = 'Sitemap: ' . self::$urlSitemap; > self::writeRobotsTxtFile($robotsTxtFile, $arrFileRobotsTxt); 203,204c225,227 < else { < $this->writeRobotsTxtFile($robotsTxtFile); --- > else > { > self::writeRobotsTxtFile($robotsTxtFile); 208,218c231,242 < private function writeRobotsTxtFile($robotsTxtFile, $robotsTxtContent='') { < if(file_exists($robotsTxtFile)) < unlink($robotsTxtFile); < < $fp = fopen($robotsTxtFile, 'w'); < if(is_array($robotsTxtContent)) { < foreach ($robotsTxtContent as $riga) { < trim($riga); < if(!preg_match("/\w/", $riga)) < continue; < fwrite($fp, $riga.PHP_EOL); --- > private static function writeRobotsTxtFile($robotsTxtFile, $robotsTxtContent='') > { > if(is_array($robotsTxtContent) === true) > { > file_put_contents($robotsTxtFile,''); > foreach ($robotsTxtContent as $riga) > { > $riga = trim($riga); > if(preg_match("/\w/", $riga) === true) > { > file_put_contents($robotsTxtFile,$riga . PHP_EOL,FILE_APPEND); > } 221,223c245,247 < else { < $string = "User-agent: *".PHP_EOL."Disallow:".PHP_EOL.PHP_EOL."Sitemap: ".$this->urlSitemap; < fwrite($fp, $string); --- > else > { > file_put_contents($robotsTxtFile,'User-agent: *' . PHP_EOL . 'Disallow:' . PHP_EOL . PHP_EOL . 'Sitemap: ' . self::$urlSitemap); 225d248 < fclose($fp); 229c252,260 < ?> --- > > function ms_muXmlSitemap_doJob() > { > return mu_google_sitemaps::doJob(); > } > > add_action('publish_post', 'ms_muXmlSitemap_doJob'); > add_action('delete_post', 'ms_muXmlSitemap_doJob'); > ?> \ No newline at end of file