Plugin Directory

Changeset 1341412


Ignore:
Timestamp:
02/02/2016 03:15:03 PM (10 years ago)
Author:
tanng
Message:

Version 1.1

Location:
get-facebook-likes/trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • get-facebook-likes/trunk/class-gfl-main.php

    r1334749 r1341412  
    77class GFL_Main
    88{
    9     /**
    10      * Basic or Advanced Mode
    11      *
    12      * @var String
    13      */
    14     public $mode;
    159
    1610    /**
     
    2115    public function __construct()
    2216    {
    23         $this->mode = gfl_setting( 'mode' );
     17        $mode = gfl_setting( 'mode' );
    2418
    2519        /** Update likes/shares/comments each time singular pages load when in basic mode */
    26         if ( $this->mode != 'advanced' )
     20        if ( $mode != 'advanced' ) {
    2721            add_action( 'wp_head', array( $this, 'update_likes' ), 9999 );
    28 
    29         /** Update likes/shares/comments when users click on these button when in advanced mode */
    30         if ( $this->mode === 'advanced' )
    31         {
     22        }
     23        else {
    3224            add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue' ) );
    3325            add_action( 'wp_ajax_nopriv_update_likes', array( $this, 'ajax_update_likes' ) );
     
    5547        add_shortcode( 'shares', array( $this, 'shares_shortcode' ) );
    5648        add_shortcode( 'comments', array( $this, 'comments_shortcode' ) );
     49
     50        add_action( 'plugins_loaded', array( $this, 'i18n' ) );
    5751    }
    5852
     
    7872    public function add_facebook_js_sdk()
    7973    {
    80         $auto_add   = gfl_setting( 'auto_add' );
     74        $auto_add   = gfl_setting('auto_add');
    8175       
    82         if ( ! $auto_add || $this->mode != 'advanced' )
     76        if ( ! $auto_add || gfl_setting('mode') != 'advanced' )
    8377            return;
    8478
    85         $app_id     = gfl_setting( 'app_id' );
     79        $app_id     = gfl_setting('app_id');
     80
     81        $sdk_locale = gfl_setting('sdk_locale');
     82        $sdk_locale = empty( $sdk_locale ) ? 'en_US' : $sdk_locale;
    8683        ?>
    8784    <script>
     
    10198            if (d.getElementById(id)) {return;}
    10299            js = d.createElement(s); js.id = id;
    103             js.src = "//connect.facebook.net/en_US/sdk.js";
     100            js.src = "//connect.facebook.net/<?php echo $sdk_locale ?>/sdk.js";
    104101            fjs.parentNode.insertBefore(js, fjs);
    105102        }(document, 'script', 'facebook-jssdk'));
     
    295292                ?>
    296293                <h3><a href="<?php echo admin_url(); ?>post.php?post=<?php echo get_the_ID(); ?>&amp;action=edit"><?php the_title(); ?></a>
    297                 <span class="count alignright">(<?php echo gfl_facebook_count( 'fb_total_count' ); ?>)</span></h3>
     294                <span class="count alignright">(<?php echo gfl_count( 'fb_total_count' ); ?>)</span></h3>
    298295                <?php
    299296            endwhile;
     
    386383            $id = get_the_ID();
    387384
    388         return gfl_facebook_count( "fb_{$action}_count", $id );
     385        return gfl_count( "fb_{$action}_count", $id );
    389386    }
    390387
     
    410407        return $this->build_shortcode( $atts, 'comments' );
    411408    }
     409
     410    /**
     411     * Define Internationalization
     412     *
     413     * @return void
     414     */
     415    public function i18n()
     416    {
     417        load_plugin_textdomain( 'gfl', false, basename( GFL_DIR ) . '/lang/' );
     418    }
    412419}
  • get-facebook-likes/trunk/class-gfl-settings.php

    r1334749 r1341412  
    5252        $settings['app_id'] = isset( $_POST['app_id'] ) ? trim( $_POST['app_id'] ) : '';
    5353        $settings['auto_add'] = isset( $_POST['auto_add'] ) ? true : false;
     54        $settings['sdk_locale'] = trim( $_POST['sdk_locale'] );
    5455       
    5556        update_option( 'get_facebook_likes', $settings );
     
    8081
    8182                    if (autoAdd) {
    82                         $('#app_id_section').show();
     83                        $('#app_id_section, #sdk_locale_section').show();
    8384                        $('#setup-guide').hide();
    8485                    }
    8586                    else {
    86                         $('#app_id_section').hide();
     87                        $('#app_id_section, #sdk_locale_section').hide();
    8788                        $('#setup-guide').show();
    8889                    }
     
    9091                else
    9192                {
    92                     $('#setup-guide, #auto_add_section, #app_id_section').hide();
     93                    $('#setup-guide, #auto_add_section, #app_id_section, #sdk_locale_section').hide();
    9394                }
    9495            });
     
    121122            if ( isset( $_GET['success'] ) ) : ?>
    122123            <div id="message" class="updated notice is-dismissible">
    123                 <p><?php _e( 'Settings <strong>saved</strong>.', 'wud' ); ?></p>
     124                <p><?php _e( 'Settings <strong>saved</strong>.', 'gfl' ); ?></p>
    124125                <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button>
    125126            </div>
     
    135136                            <div class="postbox">
    136137                                <div class="handlediv" title="Click to toggle"> <br></div>
    137                                 <h3 class="hndle ui-sortable-handle"><?php _e( 'General Settings', 'wud' ); ?></h3>
     138                                <h3 class="hndle ui-sortable-handle"><?php _e( 'General Settings', 'gfl' ); ?></h3>
    138139                                <div class="inside">
    139140                                    <table class="form-table">
     
    142143                                            <td>
    143144                                                <div>
     145
    144146                                                    <label>
    145147                                                        <input type="radio" name="mode" value="basic" <?php if ( gfl_setting( 'mode' ) == 'basic' ) echo 'checked'; ?>> <?php _e( 'Basic', 'gfl' ); ?>
     
    156158                                                <br>
    157159                                                <section>
    158                                                 <label>
    159                                                     <input type="radio" name="mode" value="advanced" <?php if ( gfl_setting( 'mode' ) == 'advanced' ) echo 'checked'; ?>> <?php _e( 'Advanced <code>Recommended</code>' ); ?>
    160                                                 </label>
     160                                                    <label>
     161                                                        <input type="radio" name="mode" value="advanced" <?php if ( gfl_setting( 'mode' ) == 'advanced' ) echo 'checked'; ?>> <?php _e( 'Advanced', 'gfl' ); ?> <code><?php _e( 'Recommended', 'gfl' ); ?></code>
     162                                                    </label>
    161163                                                    <p class="description">
    162164                                                        <?php
     
    173175
    174176                                                    <label for="auto_add">
    175                                                     <input type="checkbox" id="auto_add" value="1" name="auto_add" <?php if ( gfl_setting( 'auto_add' ) === true ) echo 'checked'; ?>>
    176                                                     <?php _e( 'Auto add JS SDK to <code>wp_head</code>', 'gfl' ); ?>
     177                                                        <input type="checkbox" id="auto_add" value="1" name="auto_add" <?php if ( gfl_setting( 'auto_add' ) === true ) echo 'checked'; ?>>
     178                                                        <?php _e( 'Auto add JS SDK to <code>wp_head</code>', 'gfl' ); ?>
    177179                                                    </label>
    178180                                                    <p class="description">
     
    189191
    190192                                                <section id="app_id_section">
    191                                                     <label for="app_id"><?php _e( '<code>App ID</code> (Optional)', 'gfl' ); ?></label><br>
     193                                                    <label for="app_id"><code><?php _e( 'App ID', 'gfl' ); ?></code> <?php _e( 'Optional', 'gfl' ); ?></label><br>
    192194                                                    <input type="text" id="app_id" name="app_id" value="<?php echo gfl_setting( 'app_id' ); ?>">
    193                                                     <p class="description"><?php _e( 'Your Facebook App ID. Recommended.', 'gfl' ); ?></p>
     195                                                    <p class="description"><?php _e( 'Your Facebook App ID', 'gfl' ); ?> <?php _e( 'Recommended', 'gfl' ); ?></p>
    194196                                                </section>
    195                                                    
     197                                               
     198                                                <section id="sdk_locale_section">
     199                                                    <label for="sdk_locale"><code><?php _e( 'SDK Locale', 'gfl' ); ?></code> <?php _e( 'Optional', 'gfl' ); ?></label><br>
     200                                                    <input type="text" id="sdk_locale" name="sdk_locale" value="<?php echo gfl_setting('sdk_locale' ); ?>">
     201                                                    <p class="description">
     202                                                        <?php _e( 'In case you\'re using Facebook SDK in your language', 'gfl' ); ?>
     203                                                    </p>
     204                                                </section>
    196205
    197206                                                <section id="setup-guide">
     
    216225
    217226        // <?php _e( 'Add this line', 'gfl' ); ?>
     227       
    218228        GFL_Main.init();
    219229    };
  • get-facebook-likes/trunk/get-facebook-likes.php

    r1334749 r1341412  
    44Plugin URI: http://binaty.org/plugins/get-facebook-likes
    55Description: Simple, Fast and Powerful solution to get Facebook likes, shares and comments count of your content
    6 Version: 1.0
     6Version: 1.1
    77Author: Tan Nguyen
    88Author URI: http://www.binaty.org
    9 Tags: facebook, likes, comments, shares, widget, Post, page, shortcode
     9Tags: facebook, likes, comments, shares, widget, Post, posts, admin, page, shortcode, plugin, get facebook likes, custom field
    1010License: GPL2+
    1111Text Domain: gfl
  • get-facebook-likes/trunk/helpers.php

    r1334749 r1341412  
    1111        'mode'      => 'basic', // basic, advanced
    1212        'app_id'    => '',
     13        'sdk_locale'=> 'en_US',  // Set JS SDK Locale
    1314        'auto_add'  => true, // Auto add js sdk to wp_head
    1415    );
     
    6667 * @return int Total Likes/Shares/Comments
    6768 */
    68 function gfl_facebook_count( $action = 'fb_like_count', $post_id = null  )
     69function gfl_facebook_count( $action = 'fb_like_count', $post_id = null )
    6970{
    7071    if ( is_null( $post_id ) )
     
    7576    return $facebook_count;
    7677}
     78
     79/**
     80 * Alias of gfl_facebook_count
     81 *
     82 * @return int
     83 */
     84function gfl_count( $action = 'fb_like_count', $post_id = null )
     85{
     86    return gfl_facebook_count( $action, $post_id );
     87}
  • get-facebook-likes/trunk/js/gfl-main.js

    r1334749 r1341412  
     1var GFL = GFL || {};
     2
     3GFL.events = [];
     4
     5/**
     6 * Subscribe an event. Similar to WP `add_action()`
     7 *
     8 * @param  String   name  Event Name
     9 * @param  Mixed callback Function Callback
     10 *
     11 * @return void
     12 */
     13GFL.subscribe = function (name, callback) {
     14    if (typeof GFL.events[name] == 'undefined')
     15        GFL.events[name] = []
     16
     17    GFL.events[name].push(callback)
     18};
     19
     20/**
     21 * Fire an event. Similar to WP `do_action`
     22 *
     23 * @param  String name Event Name
     24 * @param  Mixed args Function args
     25 *
     26 * @return void
     27 */
     28GFL.fire = function (name, args) {
     29    if (typeof GFL.events[name] != 'undefined') {
     30        for (var i = 0; i < GFL.events[name].length; ++i) {
     31            if (GFL.events[name][i] instanceof Function) {
     32                if (typeof args != 'undefined')
     33                    GFL.events[name][i](args);
     34                else
     35                    GFL.events[name][i]();
     36            }
     37        }
     38    }
     39};
     40
    141/**
    242 * Get Facebook Like Object Class
     
    646var GFL_Main = {
    747
    8     /**
    9      * Initital Method
    10      *
    11      * @return void
    12      */
    13     init: function() {
    14         // Listening users like, share, comment event.
    15         // If users did, then send Ajax call to update post meta
    16         FB.Event.subscribe('edge.create', GFL_Main.update);
    17         FB.Event.subscribe('edge.remove', GFL_Main.update);
    18         FB.Event.subscribe('comment.create', GFL_Main.update);
    19         FB.Event.subscribe('comment.remove', GFL_Main.update);
    20     },
     48    /**
     49     * Initital Method. Runs on page load.
     50     *
     51     * @return void
     52     */
     53    init: function () {
     54       
     55        // List of Facebook Events to subscribe. We'll subscribe all of these events by default.
     56        var facebookEvents = ['edge.create', 'edge.remove', 'comment.create', 'comment.remove'];
    2157
    22     /**
    23      * Send Ajax to update Likes, Shares and Comments
    24      *
    25      * @return void
    26      */
    27     update: function(url) {
    28         jQuery.post( GFL.ajax_url, {
    29             action: 'nopriv_update_likes',
    30             url: url
    31         }, function(response) {
    32             console.log(response);
    33         });
    34     }
     58        for (var i = 0; i < facebookEvents.length; i++) {
     59            FB.Event.subscribe(facebookEvents[i], function (url) {
     60                // With each event. We'll allows other extensions to add event listener.
     61                GFL.fire(facebookEvents[i], url);
     62
     63                GFL_Main.update(url);
     64            });
     65        }
     66    },
     67
     68    /**
     69     * Send Ajax to update Likes, Shares and Comments
     70     *
     71     * @return void
     72     */
     73    update: function (url) {
     74       
     75        // Fire event before update
     76        GFL.fire('update.before');
     77
     78        jQuery.post(GFL.ajax_url, {
     79            action: 'nopriv_update_likes',
     80            url: url
     81        }, function (response) {
     82            // Fire response event. User can use response argument in their function.
     83            GFL.fire('update.response', response);
     84        });
     85
     86        // Fire event after update
     87        GFL.fire('update.after');
     88    }
    3589};
  • get-facebook-likes/trunk/readme.txt

    r1334776 r1341412  
    11=== Plugin Name ===
    22Contributors: tanng
    3 Tags: facebook, likes, comments, shares, widget, Post, page, shortcode
     3Tags: facebook, likes, comments, shares, widget, Post, posts, admin, page, shortcode, plugin, get facebook likes, custom field
    44Requires at least: 3.6
    55Tested up to: 4.4.1
    6 Stable tag: 1.0
     6Stable tag: 1.1
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1212== Description ==
    1313
    14 Get Facebook Likes interacts with Facebook Graph API and saves likes, shares, and comments count to post meta right after users hit Like/Share button or leaves a Facebook comment. Therefore you can do some awesome stuff that you think it's impossible before like order posts, order search results, vote, deeper analytics... by Facebook likes (and shares, comments too).
     14[Get Facebook Likes](http://binaty.org/plugins/get-facebook-likes) interacts with Facebook Graph API and saves likes, shares, and comments count to post meta right after users hit Like/Share buttons or leaves a Facebook comment. Therefore you can do some awesome stuff that you think it's impossible before like sort posts, order search results, vote, deeper analytics... by Facebook likes (and shares, comments too).
     15
     16Get Facebook Likes also comes with powerful event system which lets you expand and build robust addons on it.
    1517
    1618As we're both developers and end users, we're obviously love fast & ease of use plugins. Get Facebook Likes uses native Facebook JS SDK and works right after activated, no cronjob setup is required. Just a few options to tweak your script to the highest speed.
     
    1820### Features
    1921* Basic Mode which compatibility with all WP Sites
    20 * Advanced Mode which better performance and more accurate
     22* Advanced Mode which have better performance and more accurate
    2123* Use native Facebook API to listening user event and get facebook likes/shares/comments
    2224* Save likes/shares/comments to post meta for further use
    2325* Built-in shortcodes `[likes]`, `[shares]`, and `[comments]`
    24 * Likes custom column
     26* Likes custom column and sorting
    2527* Most favourite content on the Dashboard area which display top 10 posts which have most likes+shares+comments
    26 * Display likes/shares/comments to Post Editing screen if Meta Box plugin is installed
     28* Display likes/shares/comments in Post Editing screen if [Meta Box](https://wordpress.org/plugins/meta-box) plugin is installed
    2729
    2830
     
    4951
    5052
    51 
    5253== Screenshots ==
    53541. Settings Page
     
    5960== Changelog ==
    6061
    61 = 1.0 =
     62
     63= 1.1 (Feb 02, 2016) =
     64* **New** Add JS Events
     65* **New** Add I18N support
     66* **New** Allows users set JS SDK Locale
     67* **Improvement** Use `gfl_count()` instead of `gfl_facebook_count()`;
     68
     69= 1.0 (Jan, 24, 2016)=
    6270* Initial Release
Note: See TracChangeset for help on using the changeset viewer.