Changeset 382286
- Timestamp:
- 05/08/2011 12:16:31 AM (15 years ago)
- Location:
- twounter/trunk
- Files:
-
- 3 edited
-
changelog.txt (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
twounter.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
twounter/trunk/changelog.txt
r114121 r382286 3 3 == Version 1.0.1 == 4 4 5 1. Twitter API is limited to 100 calls per hour. Twounter now caches the number of followers for 6 5 minutes. 5 1. Twitter API is limited to 100 calls per hour. Twounter now caches the number of followers for 5 minutes. 6 7 == Version 1.0.2 == 8 9 1. Added number_format to separate the number with commas. 10 2. Fixed a potential mysql bug. -
twounter/trunk/readme.txt
r114273 r382286 2 2 Contributors: isharis 3 3 Tags: twitter, sidebar, plugin 4 Requires at least: 2.7.1 5 Tested up to: 2.7.1 6 Stable tag: 1.0.1 4 Tested up to: 3.1.2 5 Stable tag: 1.0.2 7 6 8 7 Twounter returns the number of followers of a twitter user in simple text format. -
twounter/trunk/twounter.php
r114273 r382286 2 2 /* 3 3 * Plugin Name: Twounter 4 * Plugin URI: http:// themesphere.com/twitter-counter-wordpress-plugin.html4 * Plugin URI: http://mharis.net/twitter-counter-wordpress-plugin/ 5 5 * Description: Twounter returns the number of followers of a twitter user in simple text format. 6 * Version: 1.0. 17 * Author: Muhammad Haris 8 * Author URI: http:// twitter.com/mharis6 * Version: 1.0.2 7 * Author: Muhammad Haris - <a href='http://twitter.com/mharis'>@mharis</a> on twitter 8 * Author URI: http://mharis.net 9 9 */ 10 10 … … 17 17 18 18 function logger($log) { 19 global $wpdb; 20 21 $wpdb->query('INSERT into logger(log) VALUES("' . $log . '")'); 19 global $wpdb; 20 $wpdb->query('INSERT into logger(log) VALUES("' . $log . '")'); 22 21 } 23 22 … … 26 25 */ 27 26 function twounter_install() { 28 global $wpdb;29 30 $table = $wpdb->prefix . 'twounter';31 32 $sql =33 'CREATE TABLE IF NOT EXISTS ' . $table . ' (34 `ID` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY,35 `twounter_twitter_id` varchar(250) NOT NULL,36 `twounter_followers` bigint NOT NULL,37 `twounter_time` datetime NOT NULL default "0000-00-00 00:00:00",38 UNIQUE key (id),39 UNIQUE key (twounter_twitter_id)40 );';41 42 $wpdb->query($sql);27 global $wpdb; 28 29 $table = $wpdb->prefix . 'twounter'; 30 31 $sql = 32 'CREATE TABLE IF NOT EXISTS ' . $table . ' ( 33 `ID` bigint NOT NULL AUTO_INCREMENT PRIMARY KEY, 34 `twounter_twitter_id` varchar(250) NOT NULL, 35 `twounter_followers` bigint NOT NULL, 36 `twounter_time` datetime NOT NULL default "0000-00-00 00:00:00", 37 UNIQUE key (id), 38 UNIQUE key (twounter_twitter_id) 39 );'; 40 41 $wpdb->query($sql); 43 42 } 44 43 … … 47 46 */ 48 47 function twounter_uninstall() { 49 global $wpdb;50 51 $table = $wpdb->prefix . 'twounter';52 $sql = 'DROP TABLE ' . $table;53 $wpdb->query($sql);48 global $wpdb; 49 50 $table = $wpdb->prefix . 'twounter'; 51 $sql = 'DROP TABLE ' . $table; 52 $wpdb->query($sql); 54 53 } 55 54 … … 61 60 */ 62 61 function twounter_followers($username) { 63 global $wpdb; 64 65 $sql = 'SELECT * 66 FROM ' . $wpdb->prefix . 'twounter 67 WHERE twounter_twitter_id = "' . $username . '"'; 68 $followers = $wpdb->get_results($sql); 69 $now = strtotime(date('Y-m-d H:i:s')); 70 $api_call = strtotime($followers[0]->twounter_time); 71 $difference = $now - $api_call; 72 $api_time_seconds = 18000; 73 74 if(!$followers || $difference >= $api_time_seconds) { 75 $api_page = 'http://twitter.com/users/show/' . $username; 76 $xml = file_get_contents($api_page); 77 78 $profile = new SimpleXMLElement($xml); 79 80 $sql = 'INSERT into ' . $wpdb->prefix . 'twounter 81 (twounter_twitter_id, twounter_followers, twounter_time) 82 VALUES("' . $username . '", ' . $profile->followers_count . ', "' . date('Y-m-d H:i:s') . '")'; 83 $query = $wpdb->query($sql); 84 85 if(!$query) { 86 $sql = 'UPDATE ' . $wpdb->prefix . 'twounter 87 SET twounter_followers = ' . $profile->followers_count . ', 88 twounter_time = "' . date('Y-m-d H:i:s') . '" 89 WHERE twounter_twitter_id = "' . $username . '"'; 90 $query = $wpdb->query($sql); 91 } 92 } else { 93 $profile->followers_count = $followers[0]->twounter_followers; 94 } 95 return $profile->followers_count; 62 global $wpdb; 63 64 $sql = 'SELECT * 65 FROM ' . $wpdb->prefix . 'twounter 66 WHERE twounter_twitter_id = "' . $username . '"'; 67 $followers = $wpdb->get_results($sql); 68 $now = strtotime(date('Y-m-d H:i:s')); 69 $api_call = strtotime($followers[0]->twounter_time); 70 $difference = $now - $api_call; 71 $api_time_seconds = 18000; 72 73 if(!$followers || $difference >= $api_time_seconds) { 74 $api_page = 'http://twitter.com/users/show/' . $username; 75 $xml = file_get_contents($api_page); 76 77 $profile = new SimpleXMLElement($xml); 78 79 $sql = 'INSERT into ' . $wpdb->prefix . 'twounter 80 (twounter_twitter_id, twounter_followers, twounter_time) 81 VALUES("' . $username . '", ' . $profile->followers_count . ', "' . date('Y-m-d H:i:s') . '")'; 82 @$query = $wpdb->query($sql); 83 84 if(!$query) { 85 $sql = 'UPDATE ' . $wpdb->prefix . 'twounter 86 SET twounter_followers = ' . $profile->followers_count . ', 87 twounter_time = "' . date('Y-m-d H:i:s') . '" 88 WHERE twounter_twitter_id = "' . $username . '"'; 89 $query = $wpdb->query($sql); 90 } 91 } else { 92 $profile->followers_count = $followers[0]->twounter_followers; 93 } 94 95 return number_format($profile->followers_count); 96 96 } 97 97 … … 103 103 */ 104 104 function twounter($username) { 105 $followers = twounter_followers($username);106 107 return $followers;105 $followers = twounter_followers($username); 106 107 return $followers; 108 108 } 109 109 … … 115 115 */ 116 116 function twounter_formatting($content) { 117 $find_twounter = preg_match_all('/\[twounter\](.*)\[\/twounter\]/i', $content, $matches);118 119 if(!empty($matches[1])) {120 $usernames = $matches[1];121 foreach($usernames as $username) {122 $patterns[] = '/\[twounter\]' . $username . '\[\/twounter\]/i';123 $replacements[] = twounter($username);124 }125 126 $content = preg_replace($patterns, $replacements, $content);127 }128 129 return $content;117 $find_twounter = preg_match_all('/\[twounter\](.*)\[\/twounter\]/i', $content, $matches); 118 119 if(!empty($matches[1])) { 120 $usernames = $matches[1]; 121 foreach($usernames as $username) { 122 $patterns[] = '/\[twounter\]' . $username . '\[\/twounter\]/i'; 123 $replacements[] = twounter($username); 124 } 125 126 $content = preg_replace($patterns, $replacements, $content); 127 } 128 129 return $content; 130 130 }
Note: See TracChangeset
for help on using the changeset viewer.