Plugin Directory

Changeset 372199


Ignore:
Timestamp:
04/12/2011 10:26:16 PM (15 years ago)
Author:
rgeyer
Message:

Getting caught up on some things

Location:
twitter-api-shortcodes/trunk
Files:
6 added
2 deleted
2 edited
1 copied
3 moved

Legend:

Unmodified
Added
Removed
  • twitter-api-shortcodes/trunk

    • Property svn:externals
      •  

        old new  
        1 wordpress-tests http://svn.automattic.com/wordpress-tests/
         1tests/wordpress http://svn.automattic.com/wordpress/trunk
         2tests/wp-testlib http://svn.automattic.com/wordpress-tests/wp-testlib
  • twitter-api-shortcodes/trunk/libs/functions.php

    r347553 r372199  
    1818  return $retVal;
    1919}
     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 */
     29function 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  
    11<?php
     2/*
     3Plugin Name: Twitter API Shortcodes
     4Version: 0.0.3Alpha
     5Plugin URI: http://tasforwp.ryangeyer.com/
     6Description: A plugin to add single tweets or twitter searches to your posts and pages using shortcodes
     7Author: Ryan J. Geyer
     8Author URI: http://www.nslms.com
     9*/
     10
    211define(TAS_VERSION, '0.0.3Alpha');
    312define(TAS_DB_VERSION, '0.0.3');
     
    1120  public static $SearchTableName;
    1221
     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
    1329  public static function StaticInit($wpdb)
    1430  {
     
    1935  }
    2036
     37  // TODO: Need to add a schedule to update author avatar URL's on cached statuses.  Also need to add deactivation.
    2138  public static function tas_install()
    2239  {
    23     update_option('tas_last_installed', date('c'));
     40    update_option('tas_last_installed', time());
    2441
    2542    $tas_db_info = json_decode(get_option('tas_db_info'));
     
    7188
    7289    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;
    74151  }
    75152} TasForWp::StaticInit($wpdb); // Simulate a static constructor
  • twitter-api-shortcodes/trunk/libs/twitter.api.wp.class.inc.php

    r347553 r372199  
    66// Support for WP 3.x
    77if(!class_exists('WP_Http')) {
    8   require_once(ABSPATH.WPINC.'/class-http.php');
     8  require_once(ABSPATH . WPINC . '/class-http.php');
    99}
    1010
  • twitter-api-shortcodes/trunk/phpunit.xml

    r347546 r372199  
    1 <phpunit>
     1<phpunit bootstrap="wordpress-tests/wp-test.php">
    22  <logging>
    33    <log type="coverage-html" target="./reports" charset="UTF-8" />
  • twitter-api-shortcodes/trunk/tests/functionsTest.php

    r347553 r372199  
    11<?php
    2 require_once('functions.php');
    3 
    4 class FunctionsTest extends PHPUnit_Framework_TestCase {
     2class FunctionsTest extends WPTestCase {
    53  protected $jsonStr = <<<EOF
    64{"menu": {
     
    3735    $this->assertTrue($obj == $this->jsonObj);
    3836  }
     37
     38  public function testStatusNormalizer() {
     39    $searchJson = file_get_contents(PROJECT_ROOT.'/tests/fixtures/one-search-result.json');
     40
     41    $getJson = <<<EOF
     42
     43EOF;
     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  }
    3954}
Note: See TracChangeset for help on using the changeset viewer.