static function publishPost($postid) { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . './inc/sitemap.php'; $schema = BaidusubmitSitemap::genSchemaByPostId($postid, $xpost); if ('publish' != $xpost->post_status || '' != $xpost->post_password) { self::deletePost($postid); return; } $xml = $schema->toXml(); $content = BaidusubmitSitemap::genPostXml($xml); //file_put_contents('/home/work/baidusubmit.log', date('[Y-m-d H:i:s]')."\n".$content, FILE_APPEND); $r = BaidusubmitSitemap::sendXml($content, 1); //file_put_contents('/home/work/baidusubmit.log', date('[Y-m-d H:i:s]')."\n".$r, FILE_APPEND); }
static function uninstall() { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'options.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sitemap.php'; $siteurl = BaidusubmitOptions::getOption('siteurl'); $token = BaidusubmitOptions::getOption('pingtoken'); $sppasswd = BaidusubmitOptions::getOption('sppasswd'); $sign = md5($siteurl . $token); BaidusubmitSitemap::submitIndex('del', BaidusubmitSitemap::TYPE_ALL, $siteurl, $sppasswd, $sign); BaidusubmitSitemap::submitIndex('del', BaidusubmitSitemap::TYPE_INC, $siteurl, $sppasswd, $sign); BaidusubmitOptions::clearAllOptions(); global $wpdb; foreach (array_keys(self::$createTableSql) as $table) { $fulltable = $wpdb->prefix . $table; $wpdb->query("DROP TABLE {$fulltable}"); } }
static function showUrlstatPage() { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'sitemap.php'; $list = BaidusubmitSitemap::getUrlStat(); self::showHeader('urlstat'); echo '<table id="urlstat">', '<tr><th>', __('Date', 'sitemap'), '</th><th>', __('Quantity', 'sitemap'), '</th><th>', __('Total', 'sitemap'), '</th></tr>'; foreach ($list as $x) { echo '<tr><td>', date('Y-m-d', $x->ctime), '</td><td>', $x->urlnum, '</td><td>', $x->urlcount, '</td></tr>'; } echo '</table>'; ?> <style type="text/css"> #urlstat { border: 1px solid #DDDDDD; border-collapse:collapse; } #urlstat th, #urlstat td { border:1px solid #DDDDDD; padding: 5px 15px; text-align: center; } </style> <?php }
if ($sp) { //计算裂变 $newStartTime = strtotime($post->post_date); //裂变步长 $stepLen = intval(($newStartTime - $startTime - 1) * 0.3); $curTime = time(); //只裂变到当前时间 $count = ceil(($curTime - $newStartTime) / $stepLen); for ($i = 0; $i < $count; $i++) { $_xstart = $newStartTime + $stepLen * $i; $_xend = $_xstart + $stepLen - 1; if ($_xend > $curTime) { $_xend = $curTime; } $url = "m=sitemapinc&start={$_xstart}"; BaidusubmitSitemap::addSitemap($url, BaidusubmitSitemap::TYPE_INC, $_xstart, $_xend); } //把最后一个加上 $nextTime = $curTime + 1; BaidusubmitSitemap::addSitemap("m=sitemapinc&start={$nextTime}", BaidusubmitSitemap::TYPE_INC, $nextTime, $endTime); $newEndTime = $newStartTime - 1; $newUrl = "m=sitemapinc&start={$startTime}"; BaidusubmitSitemap::updateSitemap($sp->sid, array('url' => $newUrl, 'start' => $startTime, 'end' => $newEndTime)); $endTime = $newEndTime; } } //记录相关数据 $timeLost = intval(1000 * (microtime(true) - __BAIDU_START_TIME__)); BaidusubmitSitemap::updateSitemap($sitemap->sid, array('item_count' => $itemCount, 'file_size' => $fileSize, 'lost_time' => $timeLost)); BaidusubmitSitemap::updateUrlStat($itemCount); }
static function genSchemaByPostId($post_id, &$post = null) { require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'schema.php'; $post = get_post($post_id); $schema = new BaidusubmitSchemaPost(); $schema->setTitle($post->post_title); $schema->setLastmod($post->post_modified); $schema->setCommentCount($post->comment_count); $schema->setPublishTime($post->post_date); $_user = WP_User::get_data_by('id', $post->post_author); $schema->setAuthor($_user->display_name); $_url = BaidusubmitSitemap::genPostUrl($post); $schema->setUrl($_url); $schema->setLoc($_url); $_term = get_the_terms($post, 'category'); if ($_term && isset($_term[0])) { $schema->setTerm($_term[0]->name); } $_tags = get_the_terms($post, 'post_tag'); if ($_tags && is_array($_tags)) { $_t = array(); foreach ($_tags as $x) { $_t[] = $x->name; } $schema->setTags($_t); } $multimedia = array(); $_content = BaidusubmitSitemap::filterContent($post, $multimedia); $schema->setContent($_content); if (!empty($multimedia['image'])) { $schema->setPictures($multimedia['image']); } if (!empty($multimedia['audio'])) { foreach ($multimedia['audio'] as $a) { $audio = new BaidusubmitSchemaAudio(); $audio->setName((string) @$a['name']); $audio->setUrl((string) @$a['url']); $schema->addAudio($audio); } unset($a, $audio); } if (!empty($multimedia['video'])) { foreach ($multimedia['video'] as $v) { $video = new BaidusubmitSchemaVideo(); $video->setCaption((string) @$v['caption']); $video->setThumbnail((string) @$v['thumbnail']); $video->setUrl((string) @$v['url']); $schema->addVideo($video); } unset($v, $video); } $commentlist = BaidusubmitSitemap::getCommentListByPostId($post->ID); if ($commentlist) { foreach ($commentlist as $c) { $comm = new BaidusubmitSchemaComment(); $comm->setText($c->comment_content); $comm->setTime($c->comment_date); $comm->setCreator($c->comment_author); $schema->addComment($comm); } $schema->setLatestCommentTime($c->comment_date); unset($c, $comm); } else { $schema->setLatestCommentTime($post->post_date); } return $schema; }
public function setTime($time) { if (!preg_match('#^\\d+$#', $time)) { $time = strtotime($time); } $this->_time = BaidusubmitSitemap::dateFormat($time, $only_date = TRUE); }