Update of /cvsroot/phpwebsite-comm/modules/twitter/class
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22967/class
Modified Files:
Twitter_Admin.php Twitter_Runtime.php
Log Message:
Now have one query function to Twitter. Allows to cache all requests.
Index: Twitter_Admin.php
===================================================================
RCS file: /cvsroot/phpwebsite-comm/modules/twitter/class/Twitter_Admin.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Twitter_Admin.php 1 Jun 2008 16:47:58 -0000 1.1.1.1
--- Twitter_Admin.php 2 Jun 2008 02:27:03 -0000 1.2
***************
*** 103,106 ****
--- 103,108 ----
function postSettings()
{
+ PHPWS_Core::initModClass('twitter', 'Twitter_Runtime.php');
+
$success_msg = dgettext('twitter', 'Your settings have been successfully saved.');
$error_saving_msg = dgettext('twitter', 'Error saving the settings. Check error log for details.');
***************
*** 125,131 ****
if (isset($_POST['enabled']))
{
! $full_xml_array = PHPWS_Text::xml2php("http://twitter.com/statuses/user_timeline/$twitter_username.xml", 1);
!
! if (!empty($full_xml_array))
{
PHPWS_Settings::set('twitter', 'enabled', 1);
--- 127,132 ----
if (isset($_POST['enabled']))
{
! $test = Twitter_Runtime::query($twitter_username);
! if (!empty($test))
{
PHPWS_Settings::set('twitter', 'enabled', 1);
Index: Twitter_Runtime.php
===================================================================
RCS file: /cvsroot/phpwebsite-comm/modules/twitter/class/Twitter_Runtime.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Twitter_Runtime.php 2 Jun 2008 01:36:33 -0000 1.3
--- Twitter_Runtime.php 2 Jun 2008 02:27:03 -0000 1.4
***************
*** 34,51 ****
{
$user = PHPWS_Settings::get('twitter', 'twitter_username');
! $cache_key = 'twitter_' . $user;
!
! $statuses = PHPWS_Cache::get($cache_key);
! if (empty($statuses))
! {
! $full_xml_array = PHPWS_Text::xml2php("http://twitter.com/statuses/user_timeline/$user.xml", 1);
! $tagged_xml_array = PHPWS_Text::tagXML($full_xml_array);
! $statuses = serialize($tagged_xml_array['STATUS']);
! PHPWS_Cache::save($cache_key, $statuses);
! }
- $statuses = unserialize($statuses);
if (!empty($statuses))
{
$title = PHPWS_Settings::get('twitter', 'status_box_title');
$tags['TITLE'] = empty($title) ? NULL : $title;
--- 34,43 ----
{
$user = PHPWS_Settings::get('twitter', 'twitter_username');
! $statuses = Twitter_Runtime::query($user);
if (!empty($statuses))
{
+ $statuses = unserialize($statuses);
+
$title = PHPWS_Settings::get('twitter', 'status_box_title');
$tags['TITLE'] = empty($title) ? NULL : $title;
***************
*** 70,73 ****
--- 62,90 ----
/**
+ * Query Twitter
+ *
+ * @param string Twitter username
+ */
+ function query($username)
+ {
+ $cache_key = 'twitter_' . $username;
+
+ $statuses = PHPWS_Cache::get($cache_key);
+ if (empty($statuses))
+ {
+ $full_xml_array = PHPWS_Text::xml2php("http://twitter.com/statuses/user_timeline/$username.xml", 1);
+
+ if (!empty($full_xml_array))
+ {
+ $tagged_xml_array = PHPWS_Text::tagXML($full_xml_array);
+ $statuses = serialize($tagged_xml_array['STATUS']);
+ PHPWS_Cache::save($cache_key, $statuses);
+ }
+ }
+
+ return $statuses;
+ }
+
+ /**
* Convert a Twitter time string into a timestamp.
*
|