Changeset 1341412
- Timestamp:
- 02/02/2016 03:15:03 PM (10 years ago)
- Location:
- get-facebook-likes/trunk
- Files:
-
- 2 added
- 6 edited
-
class-gfl-main.php (modified) (8 diffs)
-
class-gfl-settings.php (modified) (10 diffs)
-
get-facebook-likes.php (modified) (1 diff)
-
helpers.php (modified) (3 diffs)
-
js/gfl-main.js (modified) (2 diffs)
-
lang (added)
-
lang/default.pot (added)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
get-facebook-likes/trunk/class-gfl-main.php
r1334749 r1341412 7 7 class GFL_Main 8 8 { 9 /**10 * Basic or Advanced Mode11 *12 * @var String13 */14 public $mode;15 9 16 10 /** … … 21 15 public function __construct() 22 16 { 23 $ this->mode = gfl_setting( 'mode' );17 $mode = gfl_setting( 'mode' ); 24 18 25 19 /** Update likes/shares/comments each time singular pages load when in basic mode */ 26 if ( $ this->mode != 'advanced' )20 if ( $mode != 'advanced' ) { 27 21 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 { 32 24 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_enqueue' ) ); 33 25 add_action( 'wp_ajax_nopriv_update_likes', array( $this, 'ajax_update_likes' ) ); … … 55 47 add_shortcode( 'shares', array( $this, 'shares_shortcode' ) ); 56 48 add_shortcode( 'comments', array( $this, 'comments_shortcode' ) ); 49 50 add_action( 'plugins_loaded', array( $this, 'i18n' ) ); 57 51 } 58 52 … … 78 72 public function add_facebook_js_sdk() 79 73 { 80 $auto_add = gfl_setting( 'auto_add');74 $auto_add = gfl_setting('auto_add'); 81 75 82 if ( ! $auto_add || $this->mode!= 'advanced' )76 if ( ! $auto_add || gfl_setting('mode') != 'advanced' ) 83 77 return; 84 78 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; 86 83 ?> 87 84 <script> … … 101 98 if (d.getElementById(id)) {return;} 102 99 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"; 104 101 fjs.parentNode.insertBefore(js, fjs); 105 102 }(document, 'script', 'facebook-jssdk')); … … 295 292 ?> 296 293 <h3><a href="<?php echo admin_url(); ?>post.php?post=<?php echo get_the_ID(); ?>&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> 298 295 <?php 299 296 endwhile; … … 386 383 $id = get_the_ID(); 387 384 388 return gfl_ facebook_count( "fb_{$action}_count", $id );385 return gfl_count( "fb_{$action}_count", $id ); 389 386 } 390 387 … … 410 407 return $this->build_shortcode( $atts, 'comments' ); 411 408 } 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 } 412 419 } -
get-facebook-likes/trunk/class-gfl-settings.php
r1334749 r1341412 52 52 $settings['app_id'] = isset( $_POST['app_id'] ) ? trim( $_POST['app_id'] ) : ''; 53 53 $settings['auto_add'] = isset( $_POST['auto_add'] ) ? true : false; 54 $settings['sdk_locale'] = trim( $_POST['sdk_locale'] ); 54 55 55 56 update_option( 'get_facebook_likes', $settings ); … … 80 81 81 82 if (autoAdd) { 82 $('#app_id_section ').show();83 $('#app_id_section, #sdk_locale_section').show(); 83 84 $('#setup-guide').hide(); 84 85 } 85 86 else { 86 $('#app_id_section ').hide();87 $('#app_id_section, #sdk_locale_section').hide(); 87 88 $('#setup-guide').show(); 88 89 } … … 90 91 else 91 92 { 92 $('#setup-guide, #auto_add_section, #app_id_section ').hide();93 $('#setup-guide, #auto_add_section, #app_id_section, #sdk_locale_section').hide(); 93 94 } 94 95 }); … … 121 122 if ( isset( $_GET['success'] ) ) : ?> 122 123 <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> 124 125 <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button> 125 126 </div> … … 135 136 <div class="postbox"> 136 137 <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> 138 139 <div class="inside"> 139 140 <table class="form-table"> … … 142 143 <td> 143 144 <div> 145 144 146 <label> 145 147 <input type="radio" name="mode" value="basic" <?php if ( gfl_setting( 'mode' ) == 'basic' ) echo 'checked'; ?>> <?php _e( 'Basic', 'gfl' ); ?> … … 156 158 <br> 157 159 <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> 161 163 <p class="description"> 162 164 <?php … … 173 175 174 176 <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' ); ?> 177 179 </label> 178 180 <p class="description"> … … 189 191 190 192 <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> 192 194 <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> 194 196 </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> 196 205 197 206 <section id="setup-guide"> … … 216 225 217 226 // <?php _e( 'Add this line', 'gfl' ); ?> 227 218 228 GFL_Main.init(); 219 229 }; -
get-facebook-likes/trunk/get-facebook-likes.php
r1334749 r1341412 4 4 Plugin URI: http://binaty.org/plugins/get-facebook-likes 5 5 Description: Simple, Fast and Powerful solution to get Facebook likes, shares and comments count of your content 6 Version: 1. 06 Version: 1.1 7 7 Author: Tan Nguyen 8 8 Author URI: http://www.binaty.org 9 Tags: facebook, likes, comments, shares, widget, Post, p age, shortcode9 Tags: facebook, likes, comments, shares, widget, Post, posts, admin, page, shortcode, plugin, get facebook likes, custom field 10 10 License: GPL2+ 11 11 Text Domain: gfl -
get-facebook-likes/trunk/helpers.php
r1334749 r1341412 11 11 'mode' => 'basic', // basic, advanced 12 12 'app_id' => '', 13 'sdk_locale'=> 'en_US', // Set JS SDK Locale 13 14 'auto_add' => true, // Auto add js sdk to wp_head 14 15 ); … … 66 67 * @return int Total Likes/Shares/Comments 67 68 */ 68 function gfl_facebook_count( $action = 'fb_like_count', $post_id = null )69 function gfl_facebook_count( $action = 'fb_like_count', $post_id = null ) 69 70 { 70 71 if ( is_null( $post_id ) ) … … 75 76 return $facebook_count; 76 77 } 78 79 /** 80 * Alias of gfl_facebook_count 81 * 82 * @return int 83 */ 84 function 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 1 var GFL = GFL || {}; 2 3 GFL.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 */ 13 GFL.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 */ 28 GFL.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 1 41 /** 2 42 * Get Facebook Like Object Class … … 6 46 var GFL_Main = { 7 47 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']; 21 57 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 } 35 89 }; -
get-facebook-likes/trunk/readme.txt
r1334776 r1341412 1 1 === Plugin Name === 2 2 Contributors: tanng 3 Tags: facebook, likes, comments, shares, widget, Post, p age, shortcode3 Tags: facebook, likes, comments, shares, widget, Post, posts, admin, page, shortcode, plugin, get facebook likes, custom field 4 4 Requires at least: 3.6 5 5 Tested up to: 4.4.1 6 Stable tag: 1. 06 Stable tag: 1.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 12 12 == Description == 13 13 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 16 Get Facebook Likes also comes with powerful event system which lets you expand and build robust addons on it. 15 17 16 18 As 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. … … 18 20 ### Features 19 21 * Basic Mode which compatibility with all WP Sites 20 * Advanced Mode which better performance and more accurate22 * Advanced Mode which have better performance and more accurate 21 23 * Use native Facebook API to listening user event and get facebook likes/shares/comments 22 24 * Save likes/shares/comments to post meta for further use 23 25 * Built-in shortcodes `[likes]`, `[shares]`, and `[comments]` 24 * Likes custom column 26 * Likes custom column and sorting 25 27 * 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 Boxplugin is installed28 * Display likes/shares/comments in Post Editing screen if [Meta Box](https://wordpress.org/plugins/meta-box) plugin is installed 27 29 28 30 … … 49 51 50 52 51 52 53 == Screenshots == 53 54 1. Settings Page … … 59 60 == Changelog == 60 61 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)= 62 70 * Initial Release
Note: See TracChangeset
for help on using the changeset viewer.