[ptwix~ptwix-source-code-repository:2] Implements new features for version 1.1

  • From: Fireantology@kenai.com
  • To: commits@ptwix.kenai.com
  • Subject: [ptwix~ptwix-source-code-repository:2] Implements new features for version 1.1
  • Date: Sun, 30 Aug 2009 10:10:50 +0000

Project:    ptwix
Repository: ptwix-source-code-repository
Revision:   2
Author:     Fireantology
Date:       2009-08-30 10:09:56 UTC
Link:       

Log Message:
------------
Implements new features for version 1.1


Revisions:
----------
2


Modified Paths:
---------------
as/PtwiX_reader.php
core/PtwiX.php
readme.txt


Diffs:
------
diff -r 007764ce80ab -r 7ed1d18143bb as/PtwiX_reader.php
--- a/as/PtwiX_reader.php       Sat Jul 25 16:24:42 2009 +0200
+++ b/as/PtwiX_reader.php       Sun Aug 30 12:09:56 2009 +0200
@@ -25,6 +25,7 @@
 
 include_once '../core/PtwiX.php';
 $PtwiX=new 
PtwiX($_POST['instance_name'],$username,$password,$url_path,$abs_path, 
$_POST['timeline'],$_POST['theme']);
+$PtwiX->setSearchString($_POST['search_string']);
 echo $PtwiX->getData($_POST['timeline']);
 ?>    
   

diff -r 007764ce80ab -r 7ed1d18143bb core/PtwiX.php
--- a/core/PtwiX.php    Sat Jul 25 16:24:42 2009 +0200
+++ b/core/PtwiX.php    Sun Aug 30 12:09:56 2009 +0200
@@ -22,8 +22,9 @@
 /**
  * Implements a Twitter grabber
  */
-class PtwiX{
+class PtwiX {
     public  $twitter_base  = 'http://twitter.com/statuses/';
+    private $twitter_base_search  = 'http://search.twitter.com/search.json?';
     private $preurl_user="http://twitter.com/";;
     private $preurl_tag="http://search.twitter.com/search?q=";;
     private $instance_name;
@@ -37,9 +38,13 @@
     private $height;
     private $async_filename;
     private $useCurl=true;
+    private $string_to_search="q=ptwix";
+    private $showFollowMe=true;
+    private $searchTitle="";
 
     public static $USER_TIMELINE=0;
     public static $FRIENDS_TIMELINE=1;
+    public static $SEARCH=2;
 
     /**
      * Create a Twitter grabber
@@ -52,7 +57,7 @@
      * @param $theme Theme folder name
      */
 
-    public function  __construct($instance_name,$username, $password, $path, 
$cache_folder, $timeline=1, $theme="gray-blue"){
+    public function  __construct($instance_name,$username, $password, $path, 
$cache_folder, $timeline=1, $theme="gray-blue") {
 
         if(!$this->validateParameter($theme)) die("The theme name must 
contains only [a-zA-Z0-9_-] ");
         if(!$this->validateParameter($instance_name)) die("The instance name 
must contains only [a-zA-Z0-9_-] ");
@@ -74,42 +79,69 @@
      * @param $height box height
      */
 
-    public function setDimension($width, $height){
+    public function setDimension($width, $height) {
         $this->width=$width;
         $this->height=$height;
     }
 
-     /**
-     * Avtivate or Deactivate curl request
+    /**
+     * Activate or Deactivate curl request
      * @param $boolean true for Using curl function
      */
 
-    public function useCurl($boolean){
-       $this->useCurl=$boolean;
+    public function useCurl($boolean) {
+        $this->useCurl=$boolean;
     }
 
-     /**
+    /**
+     * Hide the follow me button
+     */
+
+    public function hideFollowMe() {
+        $this->showFollowMe=false;
+    }
+
+
+    /**
+     * Setting a string for twitter search
+     * @param $string the search string (q=twitter&rpp=20)
+     */
+
+    public function setSearchString($string) {
+        $this->string_to_search=$string;
+    }
+
+    /**
+     * Setting a title for the search box
+     * @param $string the title
+     */
+
+    public function setSearchTitle($string) {
+        $this->searchTitle=$string;
+    }
+
+    /**
      * Set asichronous file
      * @param $name asynchronous file name
      */
 
-    public function setAsyncFileName($name){
+    public function setAsyncFileName($name) {
         $this->async_filename=$name;
     }
 
-    private function validateParameter($string){
+    private function validateParameter($string) {
         return preg_match("/^[a-zA-Z0-9_-]+$/",$string);
     }
 
-        /**
+    /**
      * Print html code for css include
      */
 
-    public function printCssRef(){
+    public function printCssRef() {
         echo '<link href="'.$this->path.'themes/'.$this->theme.'/PtwiX.css" 
rel="stylesheet" type="text/css" />';
     }
 
-    private function parseText($text){
+    private function parseText($text) {
         $text.=" ";
         $text=preg_replace("/http:\/\/([^ ]+) /", "<a href=\"http://$1\" ;
target=\"_blank\">http://$1</a> ", $text);
         $text=preg_replace("/@([a-zA-z0-9_]+)/", "@<a 
href=\"".$this->preurl_user."$1\" target=\"_blank\">$1</a> ", $text);
@@ -118,7 +150,7 @@
     }
 
 
-    private function dateFormatting($date){
+    private function dateFormatting($date) {
         $temp=strtotime($date);
         $date=date("d M Y H:i", $temp);
         return $date;
@@ -130,27 +162,56 @@
      * @return string post html code
      */
 
-    public function  getData($timeline){
+    public function  getData($timeline) {
         $messages="";
-        $response=$this->readXml($timeline);
+        $response=$this->buildMessagesArray($timeline);
         foreach ($response as $status) {
             $messages.= '<div id="item_Ptwix">';
 
-            $messages.= '<div id="text_Ptwix"><img 
src="'.$status->user->profile_image_url.'"><a 
href="'.$this->preurl_user.$status->user->screen_name.'" target="_blank"><b>' 
. $status->user->screen_name . '</b></a>: '.$this->parseText($status->text);
-            $messages.= '<div id="date_Ptwix"><em>on ' . 
$this->dateFormatting($status->created_at);
-            if($status->in_reply_to_screen_name!="")
-            $messages.= ' in reply to <a 
href="'.$this->preurl_user.$status->in_reply_to_screen_name.'" 
target="_blank">'.$status->in_reply_to_screen_name.'</a>';
+            $messages.= '<div id="text_Ptwix"><img 
src="'.$status['profile_image_url'].'"><a 
href="'.$this->preurl_user.$status['user_screen_name'].'" 
target="_blank"><b>' . $status['user_screen_name'] . '</b></a>: 
'.$this->parseText($status['text']);
+            $messages.= '<div id="date_Ptwix"><em>on ' . 
$this->dateFormatting($status['created_at']);
+            if($status['in_reply_to_screen_name']!="")
+                $messages.= ' in reply to <a 
href="'.$this->preurl_user.$status['in_reply_to_screen_name'].'" 
target="_blank">'.$status['in_reply_to_screen_name'].'</a>';
             $messages.="</em></div><div style=\"clear: both; display: 
block;\"> </div></div><div style=\"clear: both; display: block;\"> 
</div></div>";
         }
 
         return $messages;
     }
 
+    private function buildMessagesArray($timeline) {
+        $messages_array=array();
+        if($timeline==self::$SEARCH) {
+            
$json_object=json_decode(file_get_contents($this->readFile($timeline)));
+            foreach ($json_object->{'results'} as $message) {
+                $temp=array();
+                $temp['profile_image_url']=$message->{'profile_image_url'};
+                $temp['user_screen_name']=$message->{'from_user'};
+                $temp['text']=$message->{'text'};
+                $temp['created_at']=$message->{'created_at'};
+                $temp['in_reply_to_screen_name']=$message->{'to_user'};
+                $messages_array[]=$temp;
+            }
+        }
+        else {
+            $xml_object=$XML=simplexml_load_file($this->readFile($timeline));
+            foreach ($xml_object as $message) {
+                $temp=array();
+                $temp['profile_image_url']=$message->user->profile_image_url;
+                $temp['user_screen_name']=$message->user->screen_name;
+                $temp['text']=$message->text;
+                $temp['created_at']=$message->created_at;
+                
$temp['in_reply_to_screen_name']=$message->in_reply_to_screen_name;
+                $messages_array[]=$temp;
+            }
+        }
+        return $messages_array;
+    }
+
     /**
      * Print html/javascript PtiwX box
      */
 
-    public function printBox(){
+    public function printBox() {
         echo "<script type=\"text/Javascript\">";
         echo $this->returnJs();
         echo "</script>";
@@ -158,9 +219,14 @@
         echo " <div id=\"top_Ptwix\">
             <div id=\"center_Ptwix\">
             <div id=\"left_Ptwix\"><a href=\"http://ptwix.toforge.com\" ;
target=\"_blank\"><img 
src=\"".$this->path."themes/".$this->theme."/images/top_left.png\" 
border=\"0\"></a></div>
-            <div id=\"text_Ptwix\">
-            <a href=\"".$this->preurl_user.$this->username."\"><img 
align=\"absmiddle\" 
src=\"".$this->path."themes/".$this->theme."/images/followme.png\" 
border=\"0\"></a>&nbsp; <a 
href=\"".$this->preurl_user.$this->username."\">Follow me on twitter 
</a>&nbsp;&nbsp;
-            <a href=\"javascript:void(0)\" 
onclick=\"".$this->instance_name."PtwiXdoLoad()\"><img align=\"absmiddle\" 
src=\"".$this->path."themes/".$this->theme."/images/refresh.png\" 
border=\"0\"></a>&nbsp;<a href=\"javascript:void(0)\" 
onclick=\"".$this->instance_name."PtwiXdoLoad()\">Update</a></div>
+            <div id=\"text_Ptwix\">";
+        if($this->showFollowMe && $this->timeline!=self::$SEARCH) {
+            echo "<a href=\"".$this->preurl_user.$this->username."\"><img 
align=\"absmiddle\" 
src=\"".$this->path."themes/".$this->theme."/images/followme.png\" 
border=\"0\"></a>&nbsp; <a 
href=\"".$this->preurl_user.$this->username."\">Follow me on twitter 
</a>&nbsp;&nbsp;";
+        }
+        if($this->timeline==self::$SEARCH) {
+            echo "<b>".$this->searchTitle."</b>&nbsp;&nbsp;";
+        }
+        echo "<a href=\"javascript:void(0)\" 
onclick=\"".$this->instance_name."PtwiXdoLoad()\"><img align=\"absmiddle\" 
src=\"".$this->path."themes/".$this->theme."/images/refresh.png\" 
border=\"0\"></a>&nbsp;<a href=\"javascript:void(0)\" 
onclick=\"".$this->instance_name."PtwiXdoLoad()\">Update</a></div>
             <div id=\"right_Ptwix\"><img 
src=\"".$this->path."themes/".$this->theme."/images/top_right.png\" 
border=\"0\"></div>
             </div>
             </div>
@@ -174,11 +240,13 @@
         echo "</div>";
     }
 
+
+
     /**
      * Get JS code for PtwiX interface handler
      */
 
-    function returnJS(){
+    function returnJS() {
         $js=' function 
'.$this->instance_name.'PtwiXCreateXmlHttpReq(handler) {
 
         var xmlhttp = null;
@@ -227,36 +295,43 @@
         myRequest = 
'.$this->instance_name.'PtwiXCreateXmlHttpReq('.$this->instance_name.'PtwiXHandler);
         myRequest.open("POST","'.$this->path.'as/'.$this->async_filename.'");
         
myRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
-        
myRequest.send("&theme='.$this->theme.'&timeline='.$this->timeline.'&instance_name='.$this->instance_name.'");
+        
myRequest.send("&theme='.$this->theme.'&timeline='.$this->timeline.'&instance_name='.$this->instance_name.'&search_string='.$this->string_to_search.'");
 
 
     }';
         return $js;
     }
 
-    private function readXml($timeline){
+    private function readFile($timeline) {
         $file_date=$this->cache_folder.$this->instance_name."date.dat";
         $fd = @fopen($file_date, 'r');
-        if(!$fd) $this->writeXML($timeline);
-        else{
+        if(!$fd) $this->writeFile($timeline);
+        else {
             $date = fread($fd, filesize($file_date));
             fclose($fd);
-            if(time()-$date>60)  $this->writeXML($timeline);
+            if(time()-$date>60)  $this->writeFile($timeline);
         }
         $cache_file=$this->cache_folder.$this->instance_name."cache.xml";
-        $XML=simplexml_load_file($cache_file);
-        return $XML;
+        return $cache_file;
     }
 
-    private function writeXML($timeline){
+    private function writeFile($timeline) {
         $messages=$this->requestStatuses($timeline);
-        $XML=new SimpleXMLElement($messages);
-        if($XML[0]->error){
-            
$file_log=fopen($this->cache_folder.$this->instance_name."Error.log", "w");
-            fwrite($file_log, date("Y-m-d H:i:s")."\n".$messages);
-            fclose($file_log);
+
+        if($timeline!=self::$SEARCH) {
+            $XML=new SimpleXMLElement($messages);
+            if($XML[0]->error) {
+                
$file_log=fopen($this->cache_folder.$this->instance_name."Error.log", "w");
+                fwrite($file_log, date("Y-m-d H:i:s")."\n".$messages);
+                fclose($file_log);
+            }
+            else {
+                
$file=fopen($this->cache_folder.$this->instance_name."cache.xml", "w");
+                fwrite($file, $messages);
+                fclose($file);
+            }
         }
-        else{
+        else {
             
$file=fopen($this->cache_folder.$this->instance_name."cache.xml", "w");
             fwrite($file, $messages);
             fclose($file);
@@ -269,24 +344,25 @@
 
     private function requestStatuses($timeline) {
         $string_timeline="";
-       $xml="";
-        if($timeline==self::$FRIENDS_TIMELINE){ $string_timeline = 
"friends_timeline/"; }
-        else if($timeline==self::$USER_TIMELINE){ $string_timeline = 
"user_timeline/";  }
-       if($this->useCurl){
-               $handler_curl = curl_init();
-               curl_setopt($handler_curl, CURLOPT_URL, $this -> twitter_base 
. $string_timeline . $this -> username . '.xml?count=20');
-               curl_setopt($handler_curl, CURLOPT_RETURNTRANSFER, 1);
-               curl_setopt($handler_curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
-               curl_setopt($handler_curl, CURLOPT_USERPWD, 
$this->username.':'.$this->password);
-               $xml= curl_exec($handler_curl);
-               curl_close($handler_curl);
-               unset($handler_curl);
-       }
-       else{
-               $xml = file_get_contents($this -> twitter_base . 
"user_timeline/". $this -> username . '.xml?count=20');
-       }
+        $xml="";
+        if($timeline==self::$FRIENDS_TIMELINE) { $string_timeline = $this -> 
twitter_base . "friends_timeline/" . $this -> username . '.xml?count=20'; }
+        else if($timeline==self::$USER_TIMELINE) { $string_timeline = $this 
-> twitter_base . "user_timeline/" . $this -> username . '.xml?count=20';  }
+            else if($timeline==self::$SEARCH) { $string_timeline = $this -> 
twitter_base_search . $this->string_to_search;  }
+        if($this->useCurl) {
+            $handler_curl = curl_init();
+            curl_setopt($handler_curl, CURLOPT_URL, $string_timeline);
+            curl_setopt($handler_curl, CURLOPT_RETURNTRANSFER, 1);
+            curl_setopt($handler_curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
+            curl_setopt($handler_curl, CURLOPT_USERPWD, 
$this->username.':'.$this->password);
+            $xml= curl_exec($handler_curl);
+            curl_close($handler_curl);
+            unset($handler_curl);
+        }
+        else {
+            $xml = file_get_contents($string_timeline);
+        }
         return $xml;
     }
 
 }
-?>
+?>
\ No newline at end of file

diff -r 007764ce80ab -r 7ed1d18143bb readme.txt
--- a/readme.txt        Sat Jul 25 16:24:42 2009 +0200
+++ b/readme.txt        Sun Aug 30 12:09:56 2009 +0200
@@ -1,4 +1,14 @@
+PTWIX Version 1.1
 Copyright (C) 2009 Mauro Rocco "fireantology@gmail.com"
 Ptwix is released under GNU GPL
 
 For info and installation guide visit http://ptwix.toforge.com
+
+Release Notes - ptwix - Version 1.1
+
+New Feature
+- [PTWIX-3] - Implements the twitter advanced search
+- [PTWIX-5] - User can hide the follow me button
+
+Sub-task
+- [PTWIX-4] - User can set a title for the search
\ No newline at end of file






[ptwix~ptwix-source-code-repository:2] Implements new features for version 1.1

Fireantology 08/30/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close