OSDN Git Service

サイトマッププロトコル0.9対応
authorshizuki <shizuki@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Tue, 16 Jan 2007 14:08:15 +0000 (14:08 +0000)
committershizuki <shizuki@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Tue, 16 Jan 2007 14:08:15 +0000 (14:08 +0000)
<lastmod>を「最後にコメントがあったとき」に変更
<lastmod>の変更時刻をNP_UpdateTime に対応
RORサイトマップ出力に対応

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@521 1ca29b6e-896d-4ea0-84a5-967f57386b96

trunk/NP_GoogleSitemap/NP_GoogleSitemap.php

index d18a59c..09599a2 100644 (file)
@@ -1,30 +1,47 @@
 <?php
 
 <?php
 
-class NP_GoogleSitemap extends NucleusPlugin
-{
+/** ============================================================================
+  * GoogleSitemap for Nucleus
+  *
+  * Copyright 2005 by Niels Leenheer
+  * ============================================================================
+  * This program is free software and open source software; you can redistribute
+  * it and/or modify it under the terms of the GNU General Public License as
+  * published by the Free Software Foundation; either version 2 of the License,
+  * or (at your option) any later version.
+  *
+  * This program is distributed in the hope that it will be useful, but WITHOUT
+  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  * more details.
+  *
+  * You should have received a copy of the GNU General Public License along
+  * with this program; if not, write to the Free Software Foundation, Inc.,
+  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
+  * http://www.gnu.org/licenses/gpl.html
+  * ============================================================================
+  **/
 
 
-   /* ==========================================================================================
-       * GoogleSitemap for Nucleus
-       *
-       * Copyright 2005 by Niels Leenheer
-       * ==========================================================================================
-       * This program is free software and open source software; you can redistribute
-       * it and/or modify it under the terms of the GNU General Public License as
-       * published by the Free Software Foundation; either version 2 of the License,
-       * or (at your option) any later version.
-       *
-       * This program is distributed in the hope that it will be useful, but WITHOUT
-       * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-       * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-       * more details.
-       *
-       * You should have received a copy of the GNU General Public License along
-       * with this program; if not, write to the Free Software Foundation, Inc.,
-       * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
-       * http://www.gnu.org/licenses/gpl.html
-       * ==========================================================================================
-       */
+/**
+  * History
+  *  0.7    modified release by shizuki
+  *             Generate URL modified from
+  *               'http://example.com/action.php?action=plugin&name=Sitemap' to
+  *               'http://example.com/sitemap.xml' and,or
+  *               'http://example.com/index.php?virtualpath=sitemap.xml'
+  *             Add 'lastmod' attribute
+  *  0.9    SitemapProtocol updated release
+  *             SitemapProtocol ver.0.9 as common for Google, Yahoo! and MSN(Live! Search)
+  *  1.0    Add Sitemap type and chage 'lastmod' generate
+  *             Add 'ROR Sitemap' format
+  *               For details about the ROR format, go to www.rorweb.com
+  *             Modify 'lastmod' attribute
+  *               item posted time or comment posted time or item update time
+  *               item update time generate by NP_UpdateTime
+  **/
 
 
+class NP_GoogleSitemap extends NucleusPlugin
+{
 
        function getName()
        {
 
        function getName()
        {
@@ -43,7 +60,7 @@ class NP_GoogleSitemap extends NucleusPlugin
 
        function getVersion()
        {
 
        function getVersion()
        {
-               return '0.7';
+               return '1.0';
        }
 
        function getDescription()
        }
 
        function getDescription()
@@ -54,8 +71,8 @@ class NP_GoogleSitemap extends NucleusPlugin
        function getEventList()
        {
                return array(
        function getEventList()
        {
                return array(
-                                       'PostAddItem',
-                                       'PreSendContentType'
+                                        'PostAddItem',
+                                        'PreSendContentType'
                                        );
        }
        
                                        );
        }
        
@@ -73,16 +90,31 @@ class NP_GoogleSitemap extends NucleusPlugin
        {
                global $CONF, $manager, $blogid;
 
        {
                global $CONF, $manager, $blogid;
 
+               $mcategories = $this->pluginCheck('MultipleCategories');
+               if ($mcategories) {
+                       if (method_exists($mcategories, 'getRequestName')) {
+                               $subReq = $mcategories->getRequestName();
+                       } else {
+                               $subReq = 'subcatid';
+                       }
+               }
+               $npUpdateTime = $this->pluginCheck('UpdateTime');
+
                if (!$blogid) {
                        $blogid = $CONF['DefaultBlog'];
                } else {
                if (!$blogid) {
                        $blogid = $CONF['DefaultBlog'];
                } else {
-                       $blogid = (is_numeric($blogid)) ? intval($blogid) : intval(getBlogIDFromName($blogid));
+                       if (is_numeric($blogid)) {
+                               $blogid = intval($blogid);
+                       } else {
+                               $blogid = intval(getBlogIDFromName($blogid));
+                       }
                }
 
                $b =& $manager->getBlog($blogid);
                $BlogURL = $b->getURL();
 
                }
 
                $b =& $manager->getBlog($blogid);
                $BlogURL = $b->getURL();
 
-               if (substr($BlogURL, -1) != '/' && substr($BlogURL, -4) != '.php') {
+               if ( substr($BlogURL, -1) != '/'
+                 && substr($BlogURL, -4) != '.php') {
                        $BlogURL .= '/';
                }
 
                        $BlogURL .= '/';
                }
 
@@ -94,187 +126,386 @@ class NP_GoogleSitemap extends NucleusPlugin
                        return;
                }
 
                        return;
                }
 
-               $path_arr = explode('/', $info);
-               $PcMap = $this->getBlogOption($blogid, 'PcSitemap');
+               $path_arr  = explode('/', $info);
+               $PcMap     = $this->getBlogOption($blogid, 'PcSitemap');
                $MobileMap = $this->getBlogOption($blogid, 'MobileSitemap');
                $MobileMap = $this->getBlogOption($blogid, 'MobileSitemap');
-               if (end($path_arr) == $PcMap || (!empty($MobileMap) && end($path_arr) == $MobileMap)) {
+               if ( end($path_arr) == $PcMap
+                 || end($path_arr) == 'ror.xml'
+                 || (!empty($MobileMap) && end($path_arr) == $MobileMap) ) {
                        $sitemap = array();
                        $sitemap = array();
-                       if ($this->getOption('AllBlogMap') == 'yes' && $blogid == $CONF['DefaultBlog']) {
-                               $blog_query = 'SELECT * FROM %s ORDER BY bnumber';
-                               $blog_res = sql_query(sprintf($blog_query, sql_table('blog')));
+                       if ( $this->getOption('AllBlogMap') == 'yes'
+                         && $blogid == $CONF['DefaultBlog']) {
+                               $blogQuery  = 'SELECT * '
+                                                       . 'FROM %s '
+                                                       . 'ORDER BY bnumber';
+                               $blogQuery  = sprintf($blogQuery, sql_table('blog'));
+                               $blogResult = sql_query($blogQuery);
                        } else {
                        } else {
-                               $blog_query = 'SELECT * FROM %s WHERE bnumber = %d';
-                               $blog_res = sql_query(sprintf($blog_query, sql_table('blog'), $blogid));
-                               $current_blog = TRUE;
+                               $blogQuery   = 'SELECT * '
+                                                        . 'FROM %s '
+                                                        . 'WHERE bnumber = %d';
+                               $blogQuery   = sprintf($blogQuery, sql_table('blog'), $blogid);
+                               $blogResult  = sql_query($blogQuery);
+                               $currentBlog = TRUE;
                        }
                        }
-                       while ($blogs = mysql_fetch_array($blog_res)) {
+                       while ($blogs = mysql_fetch_array($blogResult)) {
                                $blog_id = intval($blogs['bnumber']);
                                $blog_id = intval($blogs['bnumber']);
-                               if ($this->getBlogOption($blog_id, 'IncludeSitemap') == 'yes' || !empty($current_blog)) {
-                                       $temp_b =& $manager->getBlog($blog_id);
-                                       $TempURL = $temp_b->getURL();
-                                       $SelfURL = $TempURL;
+                               if (  $this->getBlogOption($blog_id, 'IncludeSitemap') == 'yes'
+                                  || !empty($currentBlog)) {
+                                       $temp_b  =& $manager->getBlog($blog_id);
+                                       $TempURL =  $temp_b->getURL();
+                                       $SelfURL =  $TempURL;
 
                                        $URLMode = $CONF['URLMode'];
 
                                        $URLMode = $CONF['URLMode'];
-                                       if (substr($TempURL, -4) == '.php') $CONF['URLMode'] = 'normal';
+                                       if (substr($TempURL, -4) == '.php') {
+                                               $CONF['URLMode'] = 'normal';
+                                       }
 
                                        $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
 
                                        if (substr($SelfURL, -1) == '/') {
 
                                        $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
 
                                        if (substr($SelfURL, -1) == '/') {
-                                               $SelfURL = ($usePathInfo) ? substr($SelfURL, 0, -1) : $SelfURL . 'index.php';
+
+                                               if ($usePathInfo) {
+                                                       $SelfURL = substr($SelfURL, 0, -1);
+                                               } else {
+                                                       $SelfURL = $SelfURL . 'index.php';
+                                               }
+
                                        } elseif (substr($SelfURL, -4) != '.php') {
                                        } elseif (substr($SelfURL, -4) != '.php') {
-                                               $SelfURL = ($usePathInfo) ? $SelfURL : $SelfURL . '/index.php';
+
+                                               if ($usePathInfo) {
+                                                       $SelfURL = $SelfURL;
+                                               } else {
+                                                       $SelfURL = $SelfURL . '/index.php';
+                                               }
+
                                        }
 
                                        }
 
-                                       $CONF['ItemURL'] = $SelfURL;
+                                       $CONF['ItemURL']     = $SelfURL;
                                        $CONF['CategoryURL'] = $SelfURL;
 
                                        $CONF['CategoryURL'] = $SelfURL;
 
-                                       if (substr($TempURL, -1) != '/' && substr($TempURL, -4) != '.php') {
+                                       if ( substr($TempURL, -1) != '/'
+                                         && substr($TempURL, -4) != '.php') {
                                                $TempURL .= '/';
                                        }
 
                                        $patternURL = '/^' . preg_replace('/\//', '\/', $BlogURL) . '/';
 
                                        if (preg_match($patternURL, $TempURL)) {
                                                $TempURL .= '/';
                                        }
 
                                        $patternURL = '/^' . preg_replace('/\//', '\/', $BlogURL) . '/';
 
                                        if (preg_match($patternURL, $TempURL)) {
-                                               $sitemap[] = array(
-                                                       'loc'   => $this->_prepareLink($SelfURL, $TempURL),
-                                                       'priority' => '1.0',
-                                                       'changefreq' => 'daily'
-                                               );
-                                               
-                                               $cat_query = 'SELECT * FROM %s WHERE cblog = %d ORDER BY catid';
-                                               $cat_res = sql_query(sprintf($cat_query, sql_table('category'), $blog_id));
-                                               $mcategories = $this->pluginCheck('MultipleCategories');
-                                               while ($cat = mysql_fetch_array($cat_res)) {
-                                                       $cat_id = intval($cat['catid']);
-                                                       $Link = createCategoryLink($cat_id);
+
+                                               if (end($path_arr) == 'ror.xml') {
+                                                       $rorTitleURL  = $this->_prepareLink($SelfURL, $TempURL);
+                                                       $rooTitleURL  = htmlspecialchars($rooTitleURL, ENT_QUOTES, _CHARSET);
+                                                       $sitemapTitle = "     <title>ROR Sitemap for " . $rorTitleURL . "</title>\n"
+                                                                                 . "     <link>" . $rorTitleURL . "</link>\n"
+                                                                                 . "     <item>\n"
+                                                                                 . "     <title>ROR Sitemap for " . $rorTitleURL . "</title>\n"
+                                                                                 . "     <link>" . $rorTitleURL . "</link>\n"
+                                                                                 . "     <ror:about>sitemap</ror:about>\n"
+                                                                                 . "     <ror:type>SiteMap</ror:type>\n"
+                                                                                 . "     </item>\n";
+                                               } else {
                                                        $sitemap[] = array(
                                                        $sitemap[] = array(
-                                                               'loc' => $this->_prepareLink($SelfURL, $Link),
-                                                               'priority' => '1.0',
+                                                               'loc'        => $this->_prepareLink($SelfURL, $TempURL),
+                                                               'priority'   => '1.0',
                                                                'changefreq' => 'daily'
                                                        );
                                                                'changefreq' => 'daily'
                                                        );
+                                               }
+
+                                               $catQuery  = 'SELECT * '
+                                                                  . 'FROM %s '
+                                                                  . 'WHERE cblog = %d '
+                                                                  . 'ORDER BY catid';
+                                               $catTable  = sql_table('category');
+                                               $catQuery  = sprintf($catQuery, $catTable, $blog_id);
+                                               $catResult = sql_query($catQuery);
+
+                                               while ($cat = mysql_fetch_array($catResult)) {
+
+                                                       $cat_id = intval($cat['catid']);
+                                                       $Link   = createCategoryLink($cat_id);
+                                                       $catLoc =$this->_prepareLink($SelfURL, $Link);
+
+                                                       if (end($path_arr) != 'ror.xml') {
+                                                               $sitemap[] = array(
+                                                                       'loc'        => $catLoc,
+                                                                       'priority'   => '1.0',
+                                                                       'changefreq' => 'daily'
+                                                               );
+                                                       }
+
                                                        if ($mcategories) {
                                                        if ($mcategories) {
-                                                               $subrequest = $mcategories->getRequestName();
-                                                               $scat_query = 'SELECT * FROM %s WHERE catid = %d ORDER BY scatid';
-                                                               $scat_table = sql_table('plug_multiple_categories_sub');
-                                                               $scat_res = sql_query(sprintf($scat_query, $scat_table, $cat_id));
-                                                               while ($scat = mysql_fetch_array($scat_res)) {
+                                                               $scatQuery  = 'SELECT * '
+                                                                                       . 'FROM %s '
+                                                                                       . 'WHERE catid = %d '
+//                                                                                     . 'ORDER BY scatid';
+                                                                                       . 'ORDER BY ordid';
+                                                               $scatTable  = sql_table('plug_multiple_categories_sub');
+                                                               $scatQuery  = sprintf($scatQuery, $scatTable, $cat_id);
+                                                               $scatResult = sql_query($scatQuery);
+
+                                                               while ($scat = mysql_fetch_array($scatResult)) {
+
                                                                        $scat_id = intval($scat['scatid']);
                                                                        $scat_id = intval($scat['scatid']);
-                                                                       $params = array($subrequest => $scat_id);
-                                                                       $Link = createCategoryLink($cat_id, $params);
-                                                                       $sitemap[] = array(
-                                                                               'loc' => $this->_prepareLink($SelfURL, $Link),
-                                                                               'priority' => '1.0',
-                                                                               'changefreq' => 'daily'
-                                                                       );
+                                                                       $params  = array($subReq => $scat_id);
+                                                                       $Link    = createCategoryLink($cat_id, $params);
+                                                                       $scatLoc = $this->_prepareLink($SelfURL, $Link);
+
+                                                                       if (end($path_arr) != 'ror.xml') {
+                                                                               $sitemap[] = array(
+                                                                                       'loc'        => $scatLoc,
+                                                                                       'priority'   => '1.0',
+                                                                                       'changefreq' => 'daily'
+                                                                               );
+                                                                       }
+
                                                                }
                                                                }
+
                                                        }
                                                        }
+
                                                }
                                                }
-                                               
-                                               $item_query = 'SELECT *, UNIX_TIMESTAMP(itime) AS timestamp ' .
-                                                                       'FROM %s WHERE iblog = %d AND idraft = 0 ORDER BY itime DESC';
-                                               $item_res = sql_query(sprintf($item_query, sql_table('item'), $blog_id));
-                                               
-                                               while ($item = mysql_fetch_array($item_res)) {
+
+                                               $itemQuery  = 'SELECT *, '
+                                                                       . '       UNIX_TIMESTAMP(itime) AS timestamp '
+                                                                       . 'FROM %s '
+                                                                       . 'WHERE iblog  = %d '
+                                                                       . 'AND   idraft = 0 '
+                                                                       . 'ORDER BY itime DESC';
+                                               $itemTable  = sql_table('item');
+                                               $itemQuery  = sprintf($itemQuery, $itemTable, $blog_id);
+                                               $itemResult = sql_query($itemQuery);
+                                               while ($item = mysql_fetch_array($itemResult)) {
+
                                                        $item_id = intval($item['inumber']);
                                                        $item_id = intval($item['inumber']);
-                                                       $tz = date('O', $item['timestamp']);
-                                                       $tz = substr($tz, 0, 3) . ':' . substr($tz, 3, 2);      
-                                                       
-                                                       if (time() - $item['timestamp'] < 86400 * 2) {
+                                                       $Link    = createItemLink($item_id);
+                                                       $tz      = date('O', $item['timestamp']);
+                                                       $tz      = substr($tz, 0, 3) . ':' . substr($tz, 3, 2);
+                                                       $itemLoc = $this->_prepareLink($SelfURL, $Link);
+
+                                                       $mdQuery = 'SELECT'
+                                                                        . '   UNIX_TIMESTAMP(ctime) AS timestamp'
+                                                                        . ' FROM '
+                                                                        .     sql_table('comment')
+                                                                        . ' WHERE'
+                                                                        . '   citem = ' . $item_id
+                                                                        . ' ORDER BY'
+                                                                        . '   ctime DESC'
+                                                                        . ' LIMIT'
+                                                                        . '   1';
+                                                       $modTime = sql_query($mdQuery);
+                                                       if (mysql_num_rows($modTime) > 0) {
+                                                               $lastMod  = mysql_fetch_object($modTime);
+                                                               $itemTime = $lastMod->timestamp;
+                                                       } elseif ($npUpdateTime) { // NP_UpdateTime exists
+                                                               $mdQuery = 'SELECT'
+                                                                                . '   UNIX_TIMESTAMP(ctime) AS timestamp'
+                                                                                . ' FROM '
+                                                                                .     sql_table('plugin_rectime')
+                                                                                . ' WHERE'
+                                                                                . '   up_id = ' . $item_id;
+                                                               $modTime = sql_query($mdQuery);
+                                                               if (mysql_num_rows($modTime) > 0) { 
+                                                                       $lastMod  = mysql_fetch_object($modTime);
+                                                                       $itemTime = $lastMod->timestamp;
+                                                               }
+                                                       } else {
+                                                               $itemTime = $item['timestamp'];
+                                                       }
+
+/*                                                     if (time() - $itemTime < 86400 * 2) {
                                                                $fq = 'hourly';
                                                                $fq = 'hourly';
-                                                       } elseif (time() - $item['timestamp'] < 86400 * 14) {
+                                                       } elseif (time() - $itemTime < 86400 * 14) {
                                                                $fq = 'daily'; 
                                                                $fq = 'daily'; 
-                                                       } elseif (time() - $item['timestamp'] < 86400 * 62) {
+                                                       } elseif (time() - $itemTime < 86400 * 62) {
                                                                $fq = 'weekly';
                                                        } else {
                                                                $fq = 'monthly';
                                                                $fq = 'weekly';
                                                        } else {
                                                                $fq = 'monthly';
+                                                       }*/
+                                                       if ($itemTime < strtotime('-1 month')) {
+                                                               $fq = 'monthly';
+                                                       } elseif ($itemTime < strtotime('-1 week')) {
+                                                               $fq = 'weekly';
+                                                       } elseif ($itemTime < strtotime('-1 day')) {
+                                                               $fq = 'daily'; 
+                                                       } else {
+                                                               $fq = 'hourly';
                                                        }
                                                        }
-                                                       $sitemap[] = array(
-                                                               'loc' => $this->_prepareLink($SelfURL, createItemLink($item_id)),
-                                                               'lastmod' => gmdate('Y-m-d\TH:i:s', $item['timestamp']) . $tz,
-                                                               'priority' => '1.0',
-                                                               'changefreq' => $fq
-                                                       );
+                                                       $lastmod = gmdate('Y-m-d\TH:i:s', $itemTime) . $tz;
+
+                                                       if (end($path_arr) != 'ror.xml') {
+                                                               $sitemap[] = array(
+                                                                       'loc'        => $itemLoc,
+                                                                       'lastmod'    => $lastmod,
+                                                                       'priority'   => '1.0',
+                                                                       'changefreq' => $fq
+                                                               );
+                                                       } else {
+                                                               $iTitle = $item['ititle'];
+                                                               if (_CHARSET != 'UTF-8') {
+                                                                       $iTitle = mb_conbert_encoding($iTitle, 'UTF-8', _CHARSET);
+                                                               }
+                                                               $sitemap[] = array(
+                                                                       'title'            => $iTitle,
+                                                                       'link'             => $itemLoc,
+                                                                       'ror:updated'      => $lastmod,
+                                                                       'ror:updatePeriod' => 'day',
+                                                                       'ror:sortOrder'    => '0',
+                                                                       'ror:resourceOf'   => 'sitemap',
+                                                               );
+                                                       }
+
                                                }
                                                }
+
                                        }
                                        }
+
                                }
                                }
-                               if ($CONF['URLMode'] != $URLMode) $CONF['URLMode'] = $URLMode;
+
+                               if ($CONF['URLMode'] != $URLMode) {
+                                       $CONF['URLMode'] = $URLMode;
+                               }
+
                        }
                        }
-                       
+
                        $manager->notify('SiteMap', array ('sitemap' => & $sitemap));
                        $manager->notify('SiteMap', array ('sitemap' => & $sitemap));
-                       
+
                        header ("Content-type: application/xml");
                        header ("Content-type: application/xml");
-                       echo "<" . "?xml version='1.0' encoding='UTF-8'?" . ">\n\n";
-                       echo "\t<urlset" . ' xmlns="http://www.google.com/schemas/sitemap/0.84"' . "\n";
-                       echo "\t" . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n";
-                       echo "\t" . 'xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84' . "\n";
-                       echo "\t" . '        http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">' . "\n";
-                       
-                       while (list(,$url) = each($sitemap)) {
-                               echo "\t<url>\n";
-                               
-                               while (list($key,$value) = each($url)) {
+
+                       if (end($path_arr) == 'ror.xml') {
+
+                       // ror sitemap feed
+                       $sitemapHeader ="<" . "?xml version='1.0' encoding='UTF-8'?" . ">\n\n"
+                                                  . "<!--  This file is a ROR Sitemap for describing this website to the search engines. "
+                                                  . "For details about the ROR format, go to www.rorweb.com.   -->\n"
+                                                  . '<rss version="2.0" xmlns:ror="http://rorweb.com/0.1/" >' . "\n"
+                                                  . "<channel>\n";
+
+                       } else {
+
+                       // old Google sitemap protocol ver.0.84
+//                     $sitemapHeader  = "<" . "?xml version='1.0' encoding='UTF-8'?" . ">\n\n";
+//                                                     . "\t<urlset" . ' xmlns="http://www.google.com/schemas/sitemap/0.84"' . "\n";
+//                                                     . "\t" . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n";
+//                                                     . "\t" . 'xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84' . "\n";
+//                                                     . "\t" . '        http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">' . "\n";
+
+                       // new sitemap common protocol ver 0.9
+                       $sitemapHeader  = "<" . "?xml version='1.0' encoding='UTF-8'?" . ">\n\n"
+                                                       . '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n"
+                                                       . '         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n"
+                                                       . '         http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"' . "\n"
+                                                       . '         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
+                       // uncomment and edit next line when you need "example_schema"
+//                     $sitemapHeader .= '         xmlns:example="http://www.example.com/schemas/example_schema"';
+                       $sitemapHeader .= '>';
+
+                       }
+
+                       echo $sitemapHeader;
+                       if (end($path_arr) == 'ror.xml') {
+                               echo $sitemapTitle;
+                       }
+
+                       while (list(, $url) = each($sitemap)) {
+
+                               if (end($path_arr) == 'ror.xml') {
+                                       echo "\t<item>\n";
+                               } else {
+                                       echo "\t<url>\n";
+                               }
+
+                               while (list($key, $value) = each($url)) {
                                        if ($key == 'loc') {
                                                $value = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $value);
                                        if ($key == 'loc') {
                                                $value = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $value);
-                                               echo "\t\t<" . $key . ">" . htmlspecialchars($value, ENT_QUOTES) . "</" . $key . ">\n";
+                                               $data  = "\t\t<" . $key . ">"
+                                                          . htmlspecialchars($value, ENT_QUOTES, _CHARSET)
+                                                          . "</" . $key . ">\n";
                                        } else {
                                        } else {
-                                               echo "\t\t<" . $key . ">" . htmlspecialchars($value, ENT_QUOTES) . "</" . $key . ">\n";
+                                               $data  = "\t\t<" . $key . ">"
+                                                          . htmlspecialchars($value, ENT_QUOTES, _CHARSET)
+                                                          . "</" . $key . ">\n";
                                        }
                                        }
+                                       echo $data;
                                }
                                }
-                               
-                               echo "\t</url>\n";
+
+                               if (end($path_arr) == 'ror.xml') {
+                                       echo "\t</item>\n";
+                               } else {
+                                       echo "\t</url>\n";
+                               }
+
+                       }
+
+                       if (end($path_arr) == 'ror.xml') {
+                               echo "</channel>\n</rss>\n";
+                       } else {
+                               echo "</urlset>\n";
                        }
                        }
-                       
-                       echo "</urlset>\n";
+//                     echo "</urlset>\n";
                        exit;
                        exit;
+
                }
        }
 
        function pluginCheck($pluginName)
        {
                global $manager;
                }
        }
 
        function pluginCheck($pluginName)
        {
                global $manager;
-               if (!$manager->pluginInstalled('NP_'.$pluginName)) return;
-               $plugin =& $manager->getPlugin('NP_'.$pluginName);
-               return $plugin;
+               if (!$manager->pluginInstalled('NP_' . $pluginName)) {
+                       return;
+               } else {
+                       $plugin =& $manager->getPlugin('NP_' . $pluginName);
+                       return $plugin;
+               }
        }
 
        function _prepareLink($base, $url) {
        }
 
        function _prepareLink($base, $url) {
-               if (substr($url, 0, 7) == 'http://')
+               if (substr($url, 0, 7) == 'http://') {
                        return $url;
                        return $url;
-               else
+               } else {
                        return $base . $url;
                        return $base . $url;
+               }
        }
 
        function event_PostAddItem(&$data)
        {
                global $manager, $CONF;
        }
 
        function event_PostAddItem(&$data)
        {
                global $manager, $CONF;
-               $blog_id = getBlogIDFromItemID($data['itemid']);
+
+               $item_id = intval($data['itemid']);
+               $blog_id = intval(getBlogIDFromItemID($item_id));
+
                if ($this->getBlogOption($blog_id, 'PingGoogle') == 'yes') {
                if ($this->getBlogOption($blog_id, 'PingGoogle') == 'yes') {
-                       $b =& $manager->getBlog($blog_id);
-                       $b_url = $b->getURL();
+
+                       $b     =& $manager->getBlog($blog_id);
+                       $b_url =  $b->getURL();
 
                        if (substr($b_url, -4) == '.php') $CONF['URLMode'] = 'normal';
                        $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
 
                        if (substr($b_url, -1) == '/') {
 
                        if (substr($b_url, -4) == '.php') $CONF['URLMode'] = 'normal';
                        $usePathInfo = ($CONF['URLMode'] == 'pathinfo');
 
                        if (substr($b_url, -1) == '/') {
-                               if (!$usePathInfo) $b_url .= 'index.php?virtualpath=';
+                               if (!$usePathInfo) {
+                                       $b_url .= 'index.php?virtualpath=';
+                               }
                        } elseif (substr($b_url, -4) == '.php') {
                                $b_url .= '?virtualpath=';
                        } else {
                        } elseif (substr($b_url, -4) == '.php') {
                                $b_url .= '?virtualpath=';
                        } else {
-                               $b_url = ($usePathInfo) ? $b_url . '/' : $b_url . '/index.php?virtualpath=';
+                               if ($usePathInfo) {
+                                       $b_url = $b_url . '/';
+                               } else {
+                                       $b_url = $b_url . '/index.php?virtualpath=';
+                               }
                        }
 
                        $siteMap = $this->getBlogOption($blog_id, 'PcSitemap');
                        }
 
                        $siteMap = $this->getBlogOption($blog_id, 'PcSitemap');
-                       $url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap=' .
-                                  urlencode($b_url . $siteMap);
-                       $url = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $url);
-                       $fp = @fopen($url, 'r');
+                       $url     = 'http://www.google.com/webmasters/sitemaps/ping?sitemap='
+                                    . urlencode($b_url . $siteMap);
+                       $url     = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $url);
+                       $fp      = @fopen($url, 'r');
                        @fclose($fp);
                        $MobileMap = $this->getBlogOption($blog_id, 'MobileSitemap');
                        if (!empty($MobileMap)) {
                        @fclose($fp);
                        $MobileMap = $this->getBlogOption($blog_id, 'MobileSitemap');
                        if (!empty($MobileMap)) {
-                               $url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap=' .
-                                          urlencode($b_url . $MobileMap);
+                               $url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap='
+                                        . urlencode($b_url . $MobileMap);
                                $url = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $url);
                                $url = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $url);
-                               $fp = @fopen($url, 'r');
+                               $fp  = @fopen($url, 'r');
                                @fclose($fp);
                        }
                }
                                @fclose($fp);
                        }
                }
@@ -293,11 +524,10 @@ class NP_GoogleSitemap extends NucleusPlugin
 
        function install()
        {
 
        function install()
        {
-               $this->createOption('AllBlogMap',                       _G_SITEMAP_ALLB,        'yesno',        'yes');
-               $this->createBlogOption('PingGoogle',           _G_SITEMAP_PING,        'yesno',        'yes');
-               $this->createBlogOption('IncludeSitemap',       _G_SITEMAP_INC,         'yesno',        'yes');
-               $this->createBlogOption('PcSitemap',            _G_SITEMAP_PCSM,        'text',         'sitemap.xml');
-               $this->createBlogOption('MobileSitemap',        _G_SITEMAP_MBSM,        'text',         '');
+               $this->createOption('AllBlogMap',         _G_SITEMAP_ALLB, 'yesno', 'yes');
+               $this->createBlogOption('PingGoogle',     _G_SITEMAP_PING, 'yesno', 'yes');
+               $this->createBlogOption('IncludeSitemap', _G_SITEMAP_INC,  'yesno', 'yes');
+               $this->createBlogOption('PcSitemap',      _G_SITEMAP_PCSM, 'text',  'sitemap.xml');
+               $this->createBlogOption('MobileSitemap',  _G_SITEMAP_MBSM, 'text',  '');
        }
 }
        }
 }
-?>
\ No newline at end of file