Plugin Directory

Changeset 1740128


Ignore:
Timestamp:
10/03/2017 08:11:06 AM (9 years ago)
Author:
oxynotes
Message:

v1.7 commit

Location:
step-by-step-social-count-cache/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • step-by-step-social-count-cache/trunk/readme.txt

    r1647872 r1740128  
    44Tags: cache, count, sns, social
    55Requires at least: 4.2.4
    6 Tested up to: 4.7.4
    7 Stable tag: 1.6
     6Tested up to: 4.8.2
     7Stable tag: 1.6.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1717投稿の最終更新日から「**1日**」「**1日~1週間**」「**1週間以降**」の3つの段階で、キャッシュの有効期限を設定することができます。
    1818
    19 カウントを取得できるSNSは**Twitter**、**Facebook**、**Google+**、**はてなブックマーク**、**Pocket**、**feedly**の6つです。
     19カウントを取得できるSNSは**Twitter**、**Facebook**、**はてなブックマーク**、**Pocket**、**feedly**の6つです。
    2020(Twitterのカウントはcount.jsoon APIを利用しています。カウントを有効にするには、事前に[widgetoon.js & count.jsoon](https://jsoon.digitiminimi.com/)でサイト登録をする必要があります。)
    2121
     
    3636    echo $socal_count["twitter"];
    3737    echo $socal_count["facebook"];
    38     echo $socal_count["google"];
    3938    echo $socal_count["hatena"];
    4039    echo $socal_count["pocket"];
     
    4746    echo sbs_get_twitter();
    4847    echo sbs_get_facebook();
    49     echo sbs_get_google();
    5048    echo sbs_get_hatena();
    5149    echo sbs_get_pocket();
     
    6058
    6159`<?php
    62     $args = array( "hatena", "twitter", "google", "facebook", "pocket", "feedly" );
     60    $args = array( "hatena", "twitter", "facebook", "pocket", "feedly" );
    6361    sbs_balloon_style( $args );
    6462?>`
     
    6765
    6866`<?php
    69     $args = array( "hatena", "twitter", "google", "facebook", "pocket", "feedly" );
     67    $args = array( "hatena", "twitter", "facebook", "pocket", "feedly" );
    7068    sbs_square_style( $args );
    7169?>`
     
    7977    sbs_get_pp_twitter( $page, $post_type );
    8078    sbs_get_pp_facebook( $page, $post_type );
    81     sbs_get_pp_google( $page, $post_type );
    8279    sbs_get_pp_hatena( $page, $post_type );
    8380    sbs_get_pp_pocket( $page, $post_type );
     
    109106== Changelog ==
    110107
     1081.7
     109Google+はカウントを非表示へ仕様変更したため削除。(タグは使えますが、カウントの保存・表示はされません。)
     110WordPressのプレースホルダ仕様変更により修正。
     111feedlyのSSL化へ対応。
     112
    1111131.6
    112 Pocketのhttps化への対応。
     114PocketのSSL化への対応。
    113115キャッシュ周りの調整。
    114116デバッグモードの実装。
  • step-by-step-social-count-cache/trunk/sbs-social-count-cache.php

    r1648176 r1740128  
    642642
    643643    /**
    644      * googleのカウントを返す
     644     * googleのカウントを返す(Googleカウント停止のためペンディング)
    645645     *
     646     * @since   1.6.1
    646647     * @param   str     投稿のURL
    647648     * @return  int     返り値はカウント
    648649     */
    649650    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/*
    652652        $result = wp_remote_get( "https://plusone.google.com/_/+1/fastbutton?url=" . $url, array( 'timeout' => 5 ) );
    653 
    654653        if ( !is_wp_error( $result ) && $result["response"]["code"] === 200 ) {
    655654            $doc = new DOMDocument();
     
    661660            return 0;
    662661        }
     662*/
     663            return 0;
    663664    }
    664665
     
    722723     * feedlyのカウントを返す
    723724     *
     725     * since    2017/10/01  SSL化に対応
    724726     * @return  int     返り値はカウント
    725727     */
     
    727729
    728730        // デフォルトはRSS2、設定でユーザーの入力値がある場合は、そのフィードをカウントする
    729         if ( $this->sbs_active_sns["rss_url"] == "" ) {
     731        if ( @$this->sbs_active_sns["rss_url"] == "" ) {
    730732            $feed_url = rawurlencode( get_bloginfo( 'rss2_url' ) );
    731733        } else {
     
    733735        }
    734736
    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 );
    736738
    737739        $array = json_decode( $result["body"], true );
     
    811813        // 取得したカウントを日時とともにデータベースへ書き込み
    812814        // 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}
    816817            (postid, day, all_count, twitter_count, facebook_count, google_count, hatena_count, pocket_count, feedly_count)
    817818            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,
    826831            $postid,
    827832            $now,
     
    832837            $socials['hatena'],
    833838            $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'],
    834847            $socials['feedly']
    835         ));
     848        );
     849
     850        $wpdb->query($sql);
    836851
    837852        // 値を返すSNSを引数から指定
     
    9891004     * since    1.5.2   エスケープ対応(#等を含むと正常に動作しなかった)
    9901005     */
    991     function tag_rep( $arg, $count ) {
     1006    function tag_rep( $arg, $count = "" ) {
    9921007        $url = get_permalink();
    9931008        $site_title = get_bloginfo( 'name' );
     
    10061021
    10071022
     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
    10081049} // end class
    10091050
     
    10151056// インスタンスの作成(コンストラクタの実行)
    10161057$SBS_SocialCountCache = new SBS_SocialCountCache();
     1058
     1059
     1060
     1061/**
     1062 * テスト用のコールバックをグローバル変数に追加する
     1063 *
     1064 * @param   string  $key
     1065 * @param   mixed   $callback
     1066 * @return  void
     1067 */
     1068function add_callback( $key, $callback ) {
     1069    $GLOBALS['_sbs_callbacks'][$key] = $callback;
     1070}
    10171071
    10181072
     
    10511105
    10521106    // デバッグモード
    1053     $debug_mode = false;
     1107    //$debug_mode = false;
     1108    $debug_mode = true;
    10541109
    10551110    // デバッグモード用の配列作成
     
    14621517
    14631518    // デフォルトはRSS2、設定でユーザーの入力値がある場合は、そのフィードをカウントする
    1464     if ( $sbs->sbs_active_sns["rss_url"] == "" ) {
     1519    if ( @$sbs->sbs_active_sns["rss_url"] == "" ) {
    14651520        $feed_url = get_bloginfo( 'rss2_url' );
    14661521    } else {
     
    14801535            echo $sbs->tag_rep( $sbs->sbs_original_tag['twitter_balloon'], $socal_count['twitter'] );
    14811536        } 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'], "―" );
    14831538        } elseif ( $arg == "facebook" ) {
    14841539            echo $sbs->tag_rep( $sbs->sbs_original_tag['facebook_balloon'], $socal_count['facebook'] );
     
    15201575
    15211576    // デフォルトはRSS2、設定でユーザーの入力値がある場合は、そのフィードをカウントする
    1522     if ( $sbs->sbs_active_sns["rss_url"] == "" ) {
     1577    if ( @$sbs->sbs_active_sns["rss_url"] == "" ) {
    15231578        $feed_url = get_bloginfo( 'rss2_url' );
    15241579    } else {
     
    15381593            echo $sbs->tag_rep( $sbs->sbs_original_tag['twitter_square'], $socal_count['twitter'] );
    15391594        } 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'] );
    15411596        } elseif ( $arg == "facebook" ) {
    15421597            echo $sbs->tag_rep( $sbs->sbs_original_tag['facebook_square'], $socal_count['facebook'] );
Note: See TracChangeset for help on using the changeset viewer.