WordPress.org

Plugin Directory

Changeset 182396


Ignore:
Timestamp:
12/13/09 20:37:17 (8 years ago)
Author:
infinetsoftware
Message:

Version 1.1 Updates

Location:
wp-my-twitter/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-my-twitter/trunk/readme.txt

    r85722 r182396  
    33Tags: twitter, tweets 
    44Requires at least: 2.0.2 
    5 Tested up to: 2.7 
     5Tested up to: 2.8 
    66Stable tag: trunk 
    77 
     
    1212WP My Twitter will display your recent Twitter Tweets. Works in your theme, with shortcode, or as a Widget. 
    1313 
    14 **[WP My Twitter](http://www.infinetsoftware.com/blog/40-wp-my-twitter-plugin/)** 
    15 **[infinetSoftware](http://www.infinetsoftware.com/)** 
     14== Related == 
     15*   [WP My Twitter](http://www.infinetsoftware.com/blog/40-wp-my-twitter-plugin/) 
     16*   [Sponsored Posts Plugin](http://www.wpsponsored.com/) 
    1617 
    1718== Installation == 
     
    47483.  PHP CURL support (to connect to Twitter) 
    48494.  A Twitter Account 
     50 
     51== Changelog == 
     52 
     53= 1.1 = 
     54*   Now uses WP Cron for loading and caching Tweets 
     55*   Powered by link is now optional 
     56*   Bugfix for limiting the number of tweets displayed 
  • wp-my-twitter/trunk/twitter.php

    r85721 r182396  
    44Plugin URI: http://www.infinetsoftware.com/blog/40-wp-my-twitter-plugin/ 
    55Description: WP My Twitter 
    6 Author: infinetSoftware 
    7 Version: 1.0 
    8 Author URI: http://www.infinetsoftware.com 
     6Author: WP Sponsored Posts 
     7Version: 1.1 
     8Author URI: http://www.wpsponsored.com 
    99*/ 
    1010 
     
    1212    // Initialize Plugin 
    1313    add_action('plugins_loaded', 'LoadWPTwitter'); 
     14    add_action('wptwitter_import', array($objWPTwitter, 'LoadLive')); 
    1415} 
    1516 
     
    3334    var $strService; 
    3435    var $strUser; 
    35     var $strLastLoad; 
    3636    var $strCached; 
    3737    var $strResponse; 
     38    var $strShowPowered; 
    3839 
    3940    function WPTwitter() { 
     
    4647        $this->strService = 'http://twitter.com/statuses/user_timeline.rss'; 
    4748        $this->strUser = get_option('WPTwitter_Auth'); 
    48         $this->strLastLoad = get_option('WPTwitter_LastCache'); 
    4949        $this->strCache = get_option('WPTwitter_Cache'); 
     50        $this->strShowPowered = get_option('WPTwitter_ShowPowered'); 
    5051    } 
    5152     
     
    7071            $Count = 5; 
    7172        } 
    72         $this->strService .= '?Count=' . $Count; 
     73        $this->strService; 
    7374         
    7475 
    7576        // Load from Cache 
    76         $this->strResponse = $this->strCached; 
    77  
    78         // Nothing Cached 
    79         if (empty($this->strLastLoad) || empty($this->strCached)) { 
    80             $this->LoadLive(); 
    81         } 
    82  
    83         // Cache is Expired 
    84         if (strtotime($this->strLastLoad) < strtotime('now -40minutes')) { 
    85             $this->LoadLive(); 
    86         } 
     77        $this->strResponse = $this->strCache; 
    8778 
    8879        if (empty($this->strResponse)) { 
     
    9182         
    9283        $objXML = simplexml_load_string($this->strResponse); 
     84         
     85        if (!$objXML) { 
     86            return false; 
     87        } 
    9388 
    9489        $objChannel = $objXML->channel; 
    9590        $strLink = $objChannel->link; 
    9691 
    97         $strOut = '<p><a href="' . $strLink . '">Twitter: ' . $strUsername . '</a></p><ul>'; 
     92        $strOut = '<ul>'; 
     93         
     94        $control = 0; 
     95         
     96        if (!$objChannel->item) { 
     97            return false; 
     98        } 
    9899 
    99100        foreach ($objChannel->item as $objThisItem) { 
     
    108109             
    109110            $strOut .= '<li><a href="' . $strThisLink . '" title="' . htmlspecialchars($strThisTitle) . '">' . htmlspecialchars($strThisTitle) . '</a></li>'; 
    110         } 
    111  
    112         $strOut .= '</ul><p><small>Plugin by <a href="http://www.infinetsoftware.com/">infinetSoftware</a></small></p>'; 
     111             
     112            $control++; 
     113             
     114            if ($control >= $Count) { 
     115                break; 
     116            } 
     117        } 
     118 
     119        $strOut .= '</ul>'; 
     120         
     121        if ($this->strShowPowered == 'yes') { 
     122            $strOut .= '<p><small>Plugin by <a href="http://www.wpsponsored.com/">WP Sponsored Posts</a></small></p>'; 
     123        } 
     124         
    113125        return $strOut; 
    114126    } 
    115127 
    116128    function LoadLive() { 
     129        $this->LoadOpts(); 
     130        if (empty($this->strUser)) { 
     131            return false; 
     132        } 
     133         
    117134        $strResponse = $this->CurlIt(); 
    118135        $strNow = date('Y-m-d h:i:sa'); 
    119  
    120         if ($strResponse) { 
     136         
     137        if (!empty($strResponse)) { 
    121138            $this->strResponse = $strResponse; 
    122             $this->strLastLoad = $strNow; 
    123             update_option('WPTwitter_LastCache', $strNow); 
    124139            update_option('WPTwitter_Cache', $strResponse); 
    125140        } 
    126141        else { 
    127142            $this->strResponse = ''; 
    128             $this->strLastLoad = ''; 
    129143        } 
    130144    } 
     
    147161        return $strResult; 
    148162    } 
    149  
    150  
    151163} 
    152164 
    153165function WPTwitterInstall() { 
    154166    add_option('WPTwitter_Auth', ''); 
    155     add_option('WPTwitter_LastCache', ''); 
    156167    add_option('WPTwitter_Cache', ''); 
     168    add_option('WPTwitter_ShowPowered', 'yes'); 
     169     
     170    wp_schedule_event(time(), 'hourly', 'wptwitter_import'); 
    157171} 
    158172 
     
    167181        $strUsernameVal = $_POST['Username']; 
    168182        $strPasswordVal = $_POST['Password']; 
     183        $strShowPoweredVal = $_POST['ShowPowered']; 
     184         
     185        if ($strShowPoweredVal != 'yes') { 
     186            $strShowPoweredVal = 'no'; 
     187        } 
     188         
    169189        update_option('WPTwitter_Auth', $strUsernameVal . ':' . $strPasswordVal); 
     190        update_option('WPTwitter_ShowPowered', $strShowPoweredVal); 
     191         
     192        $objWPTwitter->LoadLive(); 
    170193    } 
    171194    $objWPTwitter->LoadOpts(); 
     
    177200        } 
    178201    } 
     202    $strShowPowered = $objWPTwitter->strShowPowered; 
    179203?> 
    180204<h2>WP My Twitter</h2> 
     
    191215    <td><input type="password" name="Password" id="Password" value="<?php echo $strPasswordVal; ?>"/></td> 
    192216  </tr> 
     217  <tr> 
     218    <th scope="row">&nbsp;</th> 
     219    <td><input type="checkbox" name="ShowPowered" id="ShowPowered" value="yes" <?php if (empty($strShowPowered) || $strShowPowered == 'yes') { echo 'checked="checked"'; } ?>/> <label for="ShowPowered">Link Back</label></td> 
     220  </tr> 
    193221</table> 
    194222 
    195 <p class="submit"><input type="submit" name="Action" value="Update"/></p> 
     223<p align="center"><input type="submit" name="Action" value="Update" class="button-primary"/></p> 
    196224 
    197225</form> 
     226 
     227<h2>Tweets</h2> 
     228 
     229<?php 
     230WPTwitter_GetTweets(); 
     231?> 
     232 
    198233<?php 
    199234         
Note: See TracChangeset for help on using the changeset viewer.