Changeset 1740128
- Timestamp:
- 10/03/2017 08:11:06 AM (9 years ago)
- Location:
- step-by-step-social-count-cache/trunk
- Files:
-
- 1 added
- 2 edited
-
readme.txt (modified) (8 diffs)
-
sbs-social-count-cache.php (modified) (15 diffs)
-
screenshot-3.png (added)
Legend:
- Unmodified
- Added
- Removed
-
step-by-step-social-count-cache/trunk/readme.txt
r1647872 r1740128 4 4 Tags: cache, count, sns, social 5 5 Requires at least: 4.2.4 6 Tested up to: 4. 7.47 Stable tag: 1.6 6 Tested up to: 4.8.2 7 Stable tag: 1.6.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 17 17 投稿の最終更新日から「**1日**」「**1日~1週間**」「**1週間以降**」の3つの段階で、キャッシュの有効期限を設定することができます。 18 18 19 カウントを取得できるSNSは**Twitter**、**Facebook**、** Google+**、**はてなブックマーク**、**Pocket**、**feedly**の6つです。19 カウントを取得できるSNSは**Twitter**、**Facebook**、**はてなブックマーク**、**Pocket**、**feedly**の6つです。 20 20 (Twitterのカウントはcount.jsoon APIを利用しています。カウントを有効にするには、事前に[widgetoon.js & count.jsoon](https://jsoon.digitiminimi.com/)でサイト登録をする必要があります。) 21 21 … … 36 36 echo $socal_count["twitter"]; 37 37 echo $socal_count["facebook"]; 38 echo $socal_count["google"];39 38 echo $socal_count["hatena"]; 40 39 echo $socal_count["pocket"]; … … 47 46 echo sbs_get_twitter(); 48 47 echo sbs_get_facebook(); 49 echo sbs_get_google();50 48 echo sbs_get_hatena(); 51 49 echo sbs_get_pocket(); … … 60 58 61 59 `<?php 62 $args = array( "hatena", "twitter", " google", "facebook", "pocket", "feedly" );60 $args = array( "hatena", "twitter", "facebook", "pocket", "feedly" ); 63 61 sbs_balloon_style( $args ); 64 62 ?>` … … 67 65 68 66 `<?php 69 $args = array( "hatena", "twitter", " google", "facebook", "pocket", "feedly" );67 $args = array( "hatena", "twitter", "facebook", "pocket", "feedly" ); 70 68 sbs_square_style( $args ); 71 69 ?>` … … 79 77 sbs_get_pp_twitter( $page, $post_type ); 80 78 sbs_get_pp_facebook( $page, $post_type ); 81 sbs_get_pp_google( $page, $post_type );82 79 sbs_get_pp_hatena( $page, $post_type ); 83 80 sbs_get_pp_pocket( $page, $post_type ); … … 109 106 == Changelog == 110 107 108 1.7 109 Google+はカウントを非表示へ仕様変更したため削除。(タグは使えますが、カウントの保存・表示はされません。) 110 WordPressのプレースホルダ仕様変更により修正。 111 feedlyのSSL化へ対応。 112 111 113 1.6 112 Pocketの https化への対応。114 PocketのSSL化への対応。 113 115 キャッシュ周りの調整。 114 116 デバッグモードの実装。 -
step-by-step-social-count-cache/trunk/sbs-social-count-cache.php
r1648176 r1740128 642 642 643 643 /** 644 * googleのカウントを返す 644 * googleのカウントを返す(Googleカウント停止のためペンディング) 645 645 * 646 * @since 1.6.1 646 647 * @param str 投稿のURL 647 648 * @return int 返り値はカウント 648 649 */ 649 650 public function get_google( $url ){ 650 // xamppでhttpsにアクセスすると以下のエラーが。php.iniの最後にextension=php_openssl.dllを付けてサーバ再起動で治る 651 // Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? 651 /* 652 652 $result = wp_remote_get( "https://plusone.google.com/_/+1/fastbutton?url=" . $url, array( 'timeout' => 5 ) ); 653 654 653 if ( !is_wp_error( $result ) && $result["response"]["code"] === 200 ) { 655 654 $doc = new DOMDocument(); … … 661 660 return 0; 662 661 } 662 */ 663 return 0; 663 664 } 664 665 … … 722 723 * feedlyのカウントを返す 723 724 * 725 * since 2017/10/01 SSL化に対応 724 726 * @return int 返り値はカウント 725 727 */ … … 727 729 728 730 // デフォルトはRSS2、設定でユーザーの入力値がある場合は、そのフィードをカウントする 729 if ( $this->sbs_active_sns["rss_url"] == "" ) {731 if ( @$this->sbs_active_sns["rss_url"] == "" ) { 730 732 $feed_url = rawurlencode( get_bloginfo( 'rss2_url' ) ); 731 733 } else { … … 733 735 } 734 736 735 $result = wp_remote_get( 'http ://cloud.feedly.com/v3/feeds/feed%2F' . $feed_url );737 $result = wp_remote_get( 'https://cloud.feedly.com/v3/feeds/feed%2F' . $feed_url ); 736 738 737 739 $array = json_decode( $result["body"], true ); … … 811 813 // 取得したカウントを日時とともにデータベースへ書き込み 812 814 // ON DUPLICATE KEY UPDATEでプライマリキーのpostidをフラグに無ければINSERT、あればUPDATE 813 // $nowのプレースホルダーを''で囲むの忘れずに 814 $result2 = $wpdb->query( $wpdb->prepare( 815 "INSERT INTO {$table_name} 815 // 2017/09/29 prepareの後方参照が使えなくなった模様 対応版に変更 816 $sql = "INSERT INTO {$table_name} 816 817 (postid, day, all_count, twitter_count, facebook_count, google_count, hatena_count, pocket_count, feedly_count) 817 818 VALUES (%d, %s, %d, %d, %d, %d, %d, %d, %d) 818 ON DUPLICATE KEY UPDATE day = '%2\$s', 819 all_count = %3\$d, 820 twitter_count = %4\$d, 821 facebook_count = %5\$d, 822 google_count = %6\$d, 823 hatena_count = %7\$d, 824 pocket_count = %8\$d, 825 feedly_count = %9\$d", 819 ON DUPLICATE KEY UPDATE 820 day = %s, 821 all_count = %d, 822 twitter_count = %d, 823 facebook_count = %d, 824 google_count = %d, 825 hatena_count = %d, 826 pocket_count = %d, 827 feedly_count = %d;"; 828 829 $sql = $wpdb->prepare( 830 $sql, 826 831 $postid, 827 832 $now, … … 832 837 $socials['hatena'], 833 838 $socials['pocket'], 839 $socials['feedly'], 840 $now, 841 $socials['all'], 842 $socials['twitter'], 843 $socials['facebook'], 844 $socials['google'], 845 $socials['hatena'], 846 $socials['pocket'], 834 847 $socials['feedly'] 835 )); 848 ); 849 850 $wpdb->query($sql); 836 851 837 852 // 値を返すSNSを引数から指定 … … 989 1004 * since 1.5.2 エスケープ対応(#等を含むと正常に動作しなかった) 990 1005 */ 991 function tag_rep( $arg, $count ) {1006 function tag_rep( $arg, $count = "" ) { 992 1007 $url = get_permalink(); 993 1008 $site_title = get_bloginfo( 'name' ); … … 1006 1021 1007 1022 1023 /** 1024 * テストモード時に各パーツから受け取ったコメントを書き出す処理をまとめたもの 1025 * 書き出されたコメントはコールバック関数に渡される 1026 * @param str 各コメントの要素を受け取る 1027 * @return str コールバック関数に渡すコメント 1028 * 1029 * since 1.5.3 テストモード用に追加 1030 */ 1031 function output_testmode_comment( $buffer ) { 1032 $url = get_permalink(); 1033 $site_title = get_bloginfo( 'name' ); 1034 1035 // html_entity_decode()を挟まないと"や'が文字参照で表示されてしまうので注意 1036 $title = urlencode( html_entity_decode( get_the_title(), ENT_COMPAT, 'UTF-8' ) ); 1037 1038 $search = array( '[[url]]', '[[site_title]]', '[[title]]', '[[count]]' ); 1039 $replace = array( $url, $site_title, $title, $count ); 1040 $rep_txt = str_replace( $search, $replace, $arg ); 1041 1042 return $rep_txt; 1043 } 1044 1045 1046 1047 1048 1008 1049 } // end class 1009 1050 … … 1015 1056 // インスタンスの作成(コンストラクタの実行) 1016 1057 $SBS_SocialCountCache = new SBS_SocialCountCache(); 1058 1059 1060 1061 /** 1062 * テスト用のコールバックをグローバル変数に追加する 1063 * 1064 * @param string $key 1065 * @param mixed $callback 1066 * @return void 1067 */ 1068 function add_callback( $key, $callback ) { 1069 $GLOBALS['_sbs_callbacks'][$key] = $callback; 1070 } 1017 1071 1018 1072 … … 1051 1105 1052 1106 // デバッグモード 1053 $debug_mode = false; 1107 //$debug_mode = false; 1108 $debug_mode = true; 1054 1109 1055 1110 // デバッグモード用の配列作成 … … 1462 1517 1463 1518 // デフォルトはRSS2、設定でユーザーの入力値がある場合は、そのフィードをカウントする 1464 if ( $sbs->sbs_active_sns["rss_url"] == "" ) {1519 if ( @$sbs->sbs_active_sns["rss_url"] == "" ) { 1465 1520 $feed_url = get_bloginfo( 'rss2_url' ); 1466 1521 } else { … … 1480 1535 echo $sbs->tag_rep( $sbs->sbs_original_tag['twitter_balloon'], $socal_count['twitter'] ); 1481 1536 } elseif ( $arg == "google" ) { 1482 echo $sbs->tag_rep( $sbs->sbs_original_tag['google_balloon'], $socal_count['google']);1537 echo $sbs->tag_rep( $sbs->sbs_original_tag['google_balloon'], "―" ); 1483 1538 } elseif ( $arg == "facebook" ) { 1484 1539 echo $sbs->tag_rep( $sbs->sbs_original_tag['facebook_balloon'], $socal_count['facebook'] ); … … 1520 1575 1521 1576 // デフォルトはRSS2、設定でユーザーの入力値がある場合は、そのフィードをカウントする 1522 if ( $sbs->sbs_active_sns["rss_url"] == "" ) {1577 if ( @$sbs->sbs_active_sns["rss_url"] == "" ) { 1523 1578 $feed_url = get_bloginfo( 'rss2_url' ); 1524 1579 } else { … … 1538 1593 echo $sbs->tag_rep( $sbs->sbs_original_tag['twitter_square'], $socal_count['twitter'] ); 1539 1594 } elseif ( $arg == "google" ) { 1540 echo $sbs->tag_rep( $sbs->sbs_original_tag['google_square'] , $socal_count['google']);1595 echo $sbs->tag_rep( $sbs->sbs_original_tag['google_square'] ); 1541 1596 } elseif ( $arg == "facebook" ) { 1542 1597 echo $sbs->tag_rep( $sbs->sbs_original_tag['facebook_square'], $socal_count['facebook'] );
Note: See TracChangeset
for help on using the changeset viewer.