Пример #1
0
 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;
 }