Category
- 1/43 Car's (246)
- Bouldering (14)
- Camera (32)
- Computer (41)
- Everyday (134)
- Goods (12)
- Linux (49)
- Music (32)
- Photo (65)
- Plant (33)
- Plastic Model (58)
- Trekking (43)
- WordPress (35)
It's blog written about Trekking ,1/43 MiniCar , Plastic Model , Photo , Computing.
RSS先日からGoogle+の投稿をブログに取り込むGoogle+ Crosspostingを使っていますが、
・再共有が取り込めない
不満点がありましたので、またまたソースをちょこちょこっと改修させていただきました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
function g_crossposting_post_new($activities) { // go through all given activities and post them $latest_activity_id = null; foreach ($activities as $activity) { // store ID of latest activity so that we know what was posted already if ($latest_activity_id == null) { $latest_activity_id = $activity->id; update_option('g_crossposting_last_activity_id' , $latest_activity_id); } //変更 投稿以外は無視していたのをコメントアウトする // currently, we only post posts and not shares :-) # if ($activity->verb != 'post') { # continue; # } // get options to configure way how activities get imported $options = g_crossposting_get_settings(); // prepare data for new post $post_time = strtotime($activity->published); $post_time_gm = gmdate('Y-m-d H:i:s', $post_time); //追加 GMTに+9hしてJSTを作り出す $post_time = strtotime($activity->published)+9*60*60; $post_time = date('Y-m-d H:i:s', $post_time); //追加 投稿と再共有で本文の内容を変更する //再共有の場合は共有元のユーザー表示と引用で表示する様にする switch($activity->verb) { case 'post': $post_content = $activity->object->content; break; case 'share': $post_content = $activity->annotation; $post_content .= "<br /><blockquote>この投稿はGoogle+の<a href='{$activity->object->actor->url}'>{$activity->object->actor->displayName}</a>さんの投稿を再共有しています<br /><br />"; $post_content .= "{$activity->object->content}</blockquote>"; break; } $att_photo = null; $att_title = null; $att_article = null; $att_url = null; if ($activity->object->attachments) { foreach ($activity->object->attachments as $attachment) { switch ($attachment->objectType) { case 'article': $att_title = $attachment->displayName; $att_article = $attachment->content; $att_url = $attachment->url; break; case 'photo': $att_photo = $attachment->image->url; break; case 'video': $att_title = $attachment->displayName; $att_article = substr($attachment->content, 0, 100); $att_photo = $attachment->image->url; $att_url = $activity->url; break; } } $post_content .= '<div class="g-crossposting-att">'; $post_content .= "<div class=\"g-crossposting-att-title\"><a href=\"{$att_url}\" target=\"_blank\">{$att_title}</a></div>"; if ($att_photo) { //追加 画像の表示サイズを縦100から320に変更 $att_photo = str_replace("&resize_h=100", "&resize_h=320", $att_photo); $post_content .= '<div class="g-crossposting-att-img" style="float:center;">'; //変更 写真をクリックした時、Google+の投稿を表示するように変更 $post_content .= "<a href=\"{$activity->url}\" target=\"_blank\">"; $post_content .= "<img src=\"{$att_photo}\" />"; $post_content .= '</a></div>'; } $post_content .= '<div class="g-crossposting-att-txt">'.$att_article.'</div>'; $post_content .= '</div>'; } $post_content .= '<br /><div class="g-crossposting-backlink"><a href="'.$activity->url.'" target="_blank">この投稿はGoogle+から発信しました…</a></div><br />'; // set title for post if ($activity->title) { $post_title = $activity->title; } else if ($att_title) { $post_title = $att_title; } else { $post_title = 'Google+ post: No title available…'; } //追加 投稿と再共有で採用するタイトルの取り込みを変える switch($activity->verb) { case 'post': $post_title = $activity->object->content; break; case 'share': $post_title = $activity->annotation; break; } //追加 コメントの先頭から改行までをタイトルとして取り出す $pos = strpos($post_title , '<br'); if( $pos != false ){ $post_title = substr($post_title , 0 , $pos); } // shorten post title if required if ($options['titlelen'] > 0 && strlen($post_title) > $options['titlelen']) { $post_title = substr($post_title, 0, $options['titlelen']).'…'; } // set comment status for post $post_comment = 'closed'; if ($options['comment'] == true) { $post_comment = 'open'; } // create post array $new_post = array( 'post_title' => $post_title, 'post_content' => $post_content, 'post_status' => 'publish', 'post_author' => $options['author'], 'post_date_gmt' => $post_time_gm, //変更 JSTをpost_dataにセットする 'post_date' => $post_time, 'post_type' => 'post', 'post_category' => array($options['category']), 'ping_status' => 'closed', 'comment_status' => $post_comment, ); // create post and add some meta information we might need later $post_id = wp_insert_post($new_post); if ($post_id) { add_post_meta($post_id, 'g_crossposting_posturl', $activity->url, TRUE); add_post_meta($post_id, 'g_crossposting_postid', $activity->id, TRUE); } } } |