Changeset 372199
- Timestamp:
- 04/12/2011 10:26:16 PM (15 years ago)
- Location:
- twitter-api-shortcodes/trunk
- Files:
-
- 6 added
- 2 deleted
- 2 edited
- 1 copied
- 3 moved
-
. (modified) (1 prop)
-
chef.js (added)
-
libs/functions.php (moved) (moved from twitter-api-shortcodes/trunk/functions.php) (1 diff)
-
libs/tasforwp.class.inc.php (moved) (moved from twitter-api-shortcodes/trunk/tasforwp.class.inc.php) (4 diffs)
-
libs/twitter.api.wp.class.inc.php (moved) (moved from twitter-api-shortcodes/trunk/twitter.api.wp.class.inc.php) (1 diff)
-
phpunit.xml (modified) (1 diff)
-
tests/fixtures (added)
-
tests/fixtures/one-search-result.json (added)
-
tests/fixtures/one-status-result.json (added)
-
tests/functionsTest.php (copied) (copied from twitter-api-shortcodes/trunk/tests/unit/functionsTest.php) (2 diffs)
-
tests/integration (deleted)
-
tests/tasforwpTest.php (added)
-
tests/unit (deleted)
-
twitter-api-shortcodes.php (added)
Legend:
- Unmodified
- Added
- Removed
-
twitter-api-shortcodes/trunk
- Property svn:externals
-
old new 1 wordpress-tests http://svn.automattic.com/wordpress-tests/ 1 tests/wordpress http://svn.automattic.com/wordpress/trunk 2 tests/wp-testlib http://svn.automattic.com/wordpress-tests/wp-testlib
-
- Property svn:externals
-
twitter-api-shortcodes/trunk/libs/functions.php
r347553 r372199 18 18 return $retVal; 19 19 } 20 21 /** 22 * This takes in a json object of a status which came from either the search api or the status api and makes it 23 * all standardized to the format returned by the status api. Namely the search API doesn't include the user 24 * data, and it's "source" property is html encoded. Since it takes the json object in by reference, if you pass 25 * your object in by reference you can ignore the return value. 26 * @param $jsonObj The status json object to normalize 27 * @return The normalized json object 28 */ 29 function normalizeStatus(&$jsonObj) { 30 // See the documentation about the return value for the search API at; 31 // http://apiwiki.twitter.com/Twitter-Search-API-Method:-search 32 // If the user data isn't available, we'll make another call to go grab it! 33 if (!isset($jsonObj->user)) { 34 /* Getting the user for each one using another call is a HUGE waste, lets try a better way. 35 $twitterApi = new TwitterAPIWP; 36 $jsonObj->user = jsonGenderBender($twitterApi->usersShow(array('screen_name' => $jsonObj->from_user)));*/ 37 38 $jsonObj->user = new stdClass(); 39 $jsonObj->user->id = $jsonObj->from_user_id; 40 $jsonObj->user->screen_name = $jsonObj->from_user; 41 $jsonObj->user->profile_image_url = $jsonObj->profile_image_url; 42 } 43 44 // Again, only the search option returns an html encoded source, so we take care of that here. 45 $jsonObj->source = htmlspecialchars_decode($jsonObj->source); 46 47 // It's useful to have the created timestamp as an actual timestamp 48 $jsonObj->created_at_ts = strtotime($jsonObj->created_at); 49 50 return $jsonObj; 51 } -
twitter-api-shortcodes/trunk/libs/tasforwp.class.inc.php
r347553 r372199 1 1 <?php 2 /* 3 Plugin Name: Twitter API Shortcodes 4 Version: 0.0.3Alpha 5 Plugin URI: http://tasforwp.ryangeyer.com/ 6 Description: A plugin to add single tweets or twitter searches to your posts and pages using shortcodes 7 Author: Ryan J. Geyer 8 Author URI: http://www.nslms.com 9 */ 10 2 11 define(TAS_VERSION, '0.0.3Alpha'); 3 12 define(TAS_DB_VERSION, '0.0.3'); … … 11 20 public static $SearchTableName; 12 21 22 public static $install_hook = "TasForWP::tas_install"; 23 public static $uninstall_hook = "TasForWP::tas_uninstall"; 24 public static $cron_hook = "TasForWP::tas_cron_action"; 25 public static $options = array( 26 "tas_last_installed", "tas_db_info", "tas_last_cron", "tas_twitter_auth", "tas_update_avatars" 27 ); 28 13 29 public static function StaticInit($wpdb) 14 30 { … … 19 35 } 20 36 37 // TODO: Need to add a schedule to update author avatar URL's on cached statuses. Also need to add deactivation. 21 38 public static function tas_install() 22 39 { 23 update_option('tas_last_installed', date('c'));40 update_option('tas_last_installed', time()); 24 41 25 42 $tas_db_info = json_decode(get_option('tas_db_info')); … … 71 88 72 89 update_option('tas_db_info', json_encode($tas_db_info)); 73 wp_schedule_event(time() - 60000, 'hourly', 'tas_cron_action'); 90 wp_schedule_event(time() - 60000, 'hourly', TasForWp::$cron_hook); 91 } 92 93 public static function tas_uninstall() { 94 wp_clear_scheduled_hook(TasForWp::$cron_hook); 95 // TODO: Should we delete our tables? 96 } 97 98 public static function tas_cron() { 99 // TODO: We need to be very conscious of the 150 call limit on the twitter API 100 foreach (TasForWp::$_wpdb->get_results("SELECT * FROM `". TasForWp::$SearchTableName ."`") as $search) { 101 if ($search->archive) { 102 $nextPage = null; 103 104 $latestStatusIdCached = TasForWp::$_wpdb->get_var("SELECT max(status_id) FROM `".TasForWp::$StatusByIdTableName."` WHERE search_id = $search->id"); 105 106 do { 107 $params = array(); 108 if ($nextPage != null) { 109 // Add all of the existing params, plus the page number 110 foreach (explode('&', $nextPage) as $keyValuePair) { 111 $splodedPair = explode('=', $keyValuePair); 112 $params[$splodedPair[0]] = urldecode($splodedPair[1]); 113 } 114 } else { 115 // TODO: Should/can we specify a larger rpp? 116 $params = array('q' => $search->search_term, 'rpp' => 100); 117 } 118 $response = TwitterAPIWrapper::search($params); 119 120 foreach ($response->results as $status) { 121 if (strval($status->id) != $latestStatusIdCached) { 122 cacheStatus($status, $search->id); 123 } else { 124 $nextPage = null; 125 break 2; 126 } 127 } 128 129 $nextPage = str_replace('?', '', $response->next_page); 130 } while ($nextPage != null); 131 132 TasForWp::$_wpdb->update(TasForWp::$SearchTableName, array('last_successful_cron' => time()), array('id' => $search->id)); 133 } 134 } 135 136 // TODO: Implement the avatar updates. 137 if(get_option('tas_twitter_auth') && have_twitter_oauth_token() && get_option('tas_update_avatars')) { 138 // 139 } 140 141 update_option('tas_last_cron', time()); 142 } 143 144 // TODO: This should be private, but I have to test it externally... Hrrmn 145 public static function have_twitter_oauth_token() { 146 $tas_oauth_gw_key = get_option('tas_oauth_gw_key', ''); 147 $tas_twitter_oauth_token = get_option('tas_twitter_oauth_token', ''); 148 149 $have_twitter_auth_token = $tas_oauth_gw_key != '' | $tas_twitter_oauth_token != ''; 150 return (boolean)$have_twitter_auth_token; 74 151 } 75 152 } TasForWp::StaticInit($wpdb); // Simulate a static constructor -
twitter-api-shortcodes/trunk/libs/twitter.api.wp.class.inc.php
r347553 r372199 6 6 // Support for WP 3.x 7 7 if(!class_exists('WP_Http')) { 8 require_once(ABSPATH .WPINC.'/class-http.php');8 require_once(ABSPATH . WPINC . '/class-http.php'); 9 9 } 10 10 -
twitter-api-shortcodes/trunk/phpunit.xml
r347546 r372199 1 <phpunit >1 <phpunit bootstrap="wordpress-tests/wp-test.php"> 2 2 <logging> 3 3 <log type="coverage-html" target="./reports" charset="UTF-8" /> -
twitter-api-shortcodes/trunk/tests/functionsTest.php
r347553 r372199 1 1 <?php 2 require_once('functions.php'); 3 4 class FunctionsTest extends PHPUnit_Framework_TestCase { 2 class FunctionsTest extends WPTestCase { 5 3 protected $jsonStr = <<<EOF 6 4 {"menu": { … … 37 35 $this->assertTrue($obj == $this->jsonObj); 38 36 } 37 38 public function testStatusNormalizer() { 39 $searchJson = file_get_contents(PROJECT_ROOT.'/tests/fixtures/one-search-result.json'); 40 41 $getJson = <<<EOF 42 43 EOF; 44 45 $normSearchObj = jsonGenderBender($searchJson); 46 $this->assertNull($normSearchObj->user); 47 $this->assertNull($normSearchObj->created_at_ts); 48 $this->assertTrue($normSearchObj->source == htmlspecialchars($normSearchObj->source,ENT_COMPAT,"ISO-8859-1",false)); 49 normalizeStatus($normSearchObj); 50 $this->assertNotNull($normSearchObj->user); 51 $this->assertNotNull($normSearchObj->created_at_ts); 52 $this->assertTrue($normSearchObj->source != htmlspecialchars($normSearchObj->source,ENT_COMPAT,"ISO-8859-1",false)); 53 } 39 54 }
Note: See TracChangeset
for help on using the changeset viewer.