<?php /** * * ver. 0.4 add Resubmit code to Yahoo! (need Yahoo! Application ID) * ver. 0.41 Fix $this->blogid as undifined and $lastmod undifined * **/ class NP_Lastmod extends NucleusPlugin { function getName() { return 'Lastmod'; } function getAuthor() { return 'HIGUCHI, Osamu'; } function getURL() { return 'http://www.higuchi.com/'; } function getVersion() { return '0.41'; } function getDescription() { return 'Template variable for the date/time of the newest comment of an item. Also resubmits ping to Google Sitemaps.'; } function supportsFeature($what) { switch($what){ case 'SqlTablePrefix': return 1; break; default: return 0; break; } } function getMinNucleusVersion() { return 220; } function install() { $this->createBlogOption('sitemaps', 'Sitemap URLs', 'textarea', ''); $this->createBlogOption('YahooAPID','Your Yahoo! Application ID', 'text', ''); } function uninstall() { $this->deleteBlogOption('sitemaps'); $this->deleteBlogOption('YahooAPID'); } function getEventList() { return array( 'PostAddItem' ); } function sendPing($sitemaps, $blogid) //<mod by shizuki /> add $blogid on ver.0.4 { $sitemap = preg_split ("/[\s,]+/", $sitemaps); $yahooID = $this->getBlogOption($blogid, 'YahooAPID'); foreach ($sitemap as $target) { @readfile("http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($target)); // <mod by shizuki on ver.0.4> if ($yahooID != '') { $url = 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=' . $yahooID . '&url=' . urlencode($b_url . $target); $url = preg_replace('|[^a-zA-Z0-9-~+_.?#=&;,/:@%]|i', '', $url); $fp = @fopen($url, 'r'); @fclose($fp); } // </mod by shizuki on ver.0.4> } } function event_PostAddItem($data) { global $manager, $DIR_LIBS; // <mod by shizuki on ver.0.4> '$this->myBlogId' to '$myBlogId' </mod by shizuki on ver.0.4> $myBlogId = getBlogIDFromItemID(intval($data->itemid)); if ($sitemaps = $this->getBlogOption($myBlogId, 'sitemaps')) { $itemid = $data->itemid; $item =& $manager->getItem($itemid, 0, 0); if (!$item) return; // don't ping for draft & future if ($item->draft) return; // don't ping on draft items (need it?) $this->sendPing($sitemaps, $myBlogId); // <mod by shizuki on ver.0.4 /> add $myBlogid } return; } function doTemplateVar(&$item) { // <mod by shizuki on ver.0.41> global $manager; $ltime = false; $query = "SELECT MAX(UNIX_TIMESTAMP(ctime)) AS result" . " FROM " . sql_table('comment') . " WHERE citem = " . $item->itemid; $ctime = quickQuery($query); if ($ctime) { $ltime = $ctime; } elseif ($manager->pluginInstalled('NP_UpdateTime')) { $query = "SELECT UNIX_TIMESTAMP(updatetime) AS result " . " FROM " . sql_table('plugin_rectime') . " WHERE up_id=" . intval($item->itemid); $itime = quickQuery($que); if ($iteme) { $ltime = $itime; } } if (!$ltime) { $ltime = $item->timestamp; } $b = $manager->getBlog(getBlogIDFromItemID($item->itemid)); echo formatDate('utc', $ltime, '', $b); // </mod by shizuki on ver.0.41> /* <original code> $cr = sql_query("SELECT UNIX_TIMESTAMP(ctime) AS ct FROM ".sql_table('comment')." WHERE citem =" . $item->itemid . " ORDER BY ctime DESC LIMIT 1" ); if (mysql_num_rows($cr) > 0) { $lc = mysql_fetch_object($cr); $lastmod = $lc->ct; } else { // <mod by shizuki> global $manager; if ($manager->pluginInstalled('NP_UpdateTime')) { $que = "SELECT UNIX_TIMESTAMP(updatetime) AS result " . " FROM " . sql_table('plugin_rectime') . " WHERE up_id=" . intval($item->itemid); $cr = quickQuery($que); $lastmod = ($cr) ? $cr : $item->timestamp; // </mod by shizuki> /* <original code> $cr=@mysql_query("SELECT UNIX_TIMESTAMP(updatetime) AS ut FROM ".sql_table('plugin_rectime')." WHERE up_id=" . $item->itemid ); if (@mysql_num_rows($cr) > 0) { // NP_UpdateTime exists and update time recorded $lc = mysql_fetch_object($cr); $lastmod = $lc->ut; } else { $lastmod = $item->timestamp; } } echo formatDate('utc', $lastmod, '', $this->blog); /* </original code>*/ } } ?>