Changeset 1331

Show
Ignore:
Timestamp:
03/19/11 22:45:58 (2 years ago)
Author:
Torben Brodt
Message:

almost finished twitter 2.1 with message import

Location:
twitter
Files:
2 added
8 modified
1 moved

Legend:

Unmodified
Added
Removed
  • twitter/cronjobs.xml

    r1298 r1331  
    66                        <classPath>lib/system/cronjob/TwitterUpdateJob.class.php</classPath> 
    77                        <description><![CDATA[Twitter Update]]></description> 
    8                         <startminute>*/30</startminute> 
     8                        <startminute>23</startminute> 
    99                        <starthour>*</starthour> 
    1010                        <startdom>*</startdom> 
  • twitter/de.xml

    r1305 r1331  
    1616        <category name="wcf.twitter"> 
    1717                <item name="wcf.twitter.title"><![CDATA[Twitter]]></item> 
     18                <item name="wcf.twitter.messages"><![CDATA[Tweets]]></item> 
    1819                <item name="wcf.twitter.information"><![CDATA[Informationen]]></item> 
    1920                <item name="wcf.twitter.systemUserMissing"><![CDATA[Der Twitter Benutzer, der im Admin angegeben ist, muss noch mit einem Benutzer authentifiziert werden.]]></item> 
  • twitter/en.xml

    r1299 r1331  
    1717                <item name="wcf.twitter.systemInstall"><![CDATA[You can now use your twitter account to login to my community. Therefore i am using the plugin from http://goo.gl/IcMuG, @easycoding]]></item> 
    1818                <item name="wcf.twitter.title"><![CDATA[Twitter]]></item> 
     19                <item name="wcf.twitter.messages"><![CDATA[Tweets]]></item> 
    1920                <item name="wcf.twitter.information"><![CDATA[Informationen]]></item> 
    2021                <item name="wcf.twitter.systemUserMissing"><![CDATA[Der Twitter Username, as set in the admin panel, still has to be authenticated  by a real user.]]></item> 
  • twitter/files/lib/data/twitter/TwitterSidebar.class.php

    r1298 r1331  
    11<?php 
     2require_once(WCF_DIR.'lib/data/twitter/ViewableTwitterMessage.class.php'); 
    23 
    34/** 
     
    1617         */ 
    1718        protected $account = null; 
     19 
     20        /** 
     21         * 
     22         * @var array<ViewableTwitterMessage> 
     23         */ 
     24        protected $tweets = array(); 
    1825         
    1926        /** 
     
    3643                EventHandler::fireAction($this, 'init'); 
    3744                 
    38                  
     45                $sql = "SELECT          * 
     46                        FROM            wcf".WCF_N."_twitter_message message 
     47                        INNER JOIN      wcf".WCF_N."_twitter_account account 
     48                        ON              (message.accountID = account.accountID) 
     49                        INNER JOIN      wcf".WCF_N."_user_to_twitter ug 
     50                        ON              (account.accountID = ug.accountID) 
     51                        INNER JOIN      wcf".WCF_N."_user user_table 
     52                        ON              (user_table.userID = ug.userID) 
     53                        LEFT JOIN       wcf".WCF_N."_avatar avatar 
     54                        ON              (avatar.avatarID = user_table.avatarID)"; 
     55                $result = WCF::getDB()->sendQuery($sql, $itemsPerPage = 10); 
     56                while ($row = WCF::getDB()->fetchArray($result)) { 
     57                        $this->tweets[] = new ViewableTwitterMessage(null, $row); 
     58                } 
    3959        } 
    40          
     60 
    4161        /** 
    4262         * Assigns variables to the template engine. 
     
    4868                // assign variables 
    4969                WCF::getTPL()->assign(array( 
     70                        'tweets' => $this->tweets 
    5071                )); 
    5172        } 
  • twitter/files/lib/data/twitter/ViewableTwitterMessage.class.php

    r1290 r1331  
    1111 * @package     de.easy-coding.wcf.twitter 
    1212 */ 
    13 class ViewableTwitter extends DatabaseObject { 
     13class ViewableTwitterMessage extends DatabaseObject { 
     14 
    1415        /** 
    1516         * owner object 
     
    1718         * @var TwitterOwner 
    1819         */ 
    19         protected $owner = null; 
     20        protected $user = null; 
    2021 
    2122        /** 
    2223         * Creates a new ViewableTwitter object. 
    2324         * 
    24          * @param       integer         $twitterID 
     25         * @param       integer         $messageID 
    2526         * @param       array<mixed>    $row 
    2627         */ 
    27         public function __construct($twitterID, $row = null) { 
    28                 if ($twitterID !== null) { 
    29                         $sql = "SELECT          avatar_table.*,   
    30                                                 twitter.*, 
    31                                                 user_table.username,  
    32                                                 group_table.groupName 
    33                                 FROM            wcf".WCF_N."_twitter twitter 
    34                                 LEFT JOIN       wcf".WCF_N."_user user_table 
    35                                 ON              (user_table.userID = twitter.userID) 
    36                                 LEFT JOIN       wcf".WCF_N."_group group_table 
    37                                 ON              (group_table.groupID = twitter.groupID) 
    38                                 LEFT JOIN       wcf".WCF_N."_avatar avatar_table 
    39                                 ON              (avatar_table.avatarID = user_table.avatarID) 
    40                                 WHERE           twitter.twitterID = ".intval($twitterID)." 
    41                                 AND             (".Twitter::getStateConditions().")"; 
    42                         $row = WCF::getDB()->getFirstRow($sql); 
    43                 } 
     28        public function __construct($messageID, $row = null) { 
    4429                DatabaseObject::__construct($row); 
     30        } 
     31         
     32        /** 
     33         * @see DatabaseObject::handleData() 
     34         */ 
     35        protected function handleData($data) { 
     36                parent::handleData($data); 
     37                $this->user = new UserProfile(null, $data); 
    4538        } 
    4639         
     
    5447        } 
    5548         
     49        public function getUser() { 
     50                return $this->user; 
     51        } 
     52         
    5653        /** 
    5754         * Returns the formatted message. 
     
    6057         */ 
    6158        public function getFormattedMessage() { 
    62                 require_once(WCF_DIR.'lib/data/message/bbcode/MessageParser.class.php'); 
    63                 MessageParser::getInstance()->setOutputType('text/html'); 
    64                 require_once(WCF_DIR.'lib/data/message/bbcode/AttachmentBBCode.class.php'); 
    65                 AttachmentBBCode::setMessageID($this->twitterID); 
    66                 return MessageParser::getInstance()->parse($this->message, $this->enableSmilies, $this->enableHtml, $this->enableBBCodes, !$this->messagePreview); 
     59                require_once(WCF_DIR.'lib/data/twitter/TwitterMessageParser.class.php'); 
     60                return TwitterMessageParser::getInstance()->parse($this->message); 
    6761        } 
    6862} 
  • twitter/files/lib/system/cronjob/TwitterUpdateJob.class.php

    r1305 r1331  
    11<?php 
    22require_once(WCF_DIR.'lib/data/cronjobs/Cronjob.class.php'); 
    3 require_once(WCF_DIR.'lib/data/twitter/Twitte.class.php'); 
     3require_once(WCF_DIR.'lib/data/twitter/Twitter.class.php'); 
    44 
    55/** 
     
    1616         */ 
    1717        public function execute($data) { 
    18                 $action = 'user_timeline'; 
    19          
    2018                $sql = "SELECT          *, 
    2119                                        ta.screen_name = '".escapeString(TWITTER_USER)."' AS doSave 
    2220                        FROM            wcf".WCF_N."_twitter_account ta 
    2321                        INNER JOIN      wcf".WCF_N."_user_to_twitter utt ON utt.accountID = ta.accountID 
    24                         LEFT JOIN       wcf".WCF_N."_twitter_import ti ON ti.accountID = ta.accountID 
    25                         WHERE           (ISNULL(ti.action) OR (ti.action = '".escapeString($action)."'))"; 
    26  
     22                        INNER JOIN      wcf".WCF_N."_twitter_import ti ON ti.accountID = ta.accountID"; 
    2723                $result = WCF::getDB()->sendQuery($sql); 
    2824                while ($row = WCF::getDB()->fetchArray($result)) { 
    29                         $this->load($row, $action); 
     25                        $this->load($row); 
    3026                } 
    3127        } 
     
    3430         * 
    3531         */ 
    36         public function load($me, $action) { 
     32        public function load($me) { 
    3733                $twitterObj = Twitter::getInstance(); 
    3834                $twitterObj->setToken($me['userToken'], $me['userSecret']); 
    3935                 
    40                 $opts = array( 
    41                         'since_id' => $me['since_id'], 
    42                         'trim_user' => 1, 
    43                 ); 
     36                $opts = array(); 
     37                $opts['trim_user'] = 1; 
     38                 
     39                if($me['since_id']) { 
     40                        $opts['since_id'] = $me['since_id']; 
     41                } 
    4442 
    45                 $list = $twitterObj->get('/statuses/'.$action.'.json', $opts); 
     43                $list = $twitterObj->get('/statuses/'.$me['action'].'.json', $opts); 
     44 
     45                $maxid = 0; 
     46                foreach($list as $message) { 
     47                        $maxid = max($maxid, $message->id); 
     48 
     49                        $sql = 'INSERT IGNORE INTO  
     50                                        wcf'.WCF_N.'_twitter_message 
     51                                        (messageID, accountID, username, message, time) 
     52                                VALUES ('.intval($message->id).', '.intval($me['accountID']).',  
     53                                        "'.escapeString($me['screen_name']).'", "'.escapeString($message->text).'",  
     54                                        '.intval(strtotime($message->created_at)).')'; 
     55                        WCF::getDB()->sendQuery($sql); 
     56                } 
    4657                 
    47                 foreach($list as $message) { 
    48                         if($me['doSave']) { 
    49                                 // TODO: check column documentation 
    50                                 $sql = 'INSERT IGNORE INTO twitter_message 
    51                                                 (messageID, accountID, username, message, time) 
    52                                         VALUES ('.intval($message->id).', '.intval($me['accountID']).',  
    53                                                 "'.escapeString($me['screen_name']).'", "'.escapeString($message->text).'",  
    54                                                 '.intval($message->time).')'; 
    55                                 WCF::getDB()->sendQuery($sql); 
    56                         } 
    57                          
    58                         // TODO: check wether the list is sorted ascending or descending 
    59                         // TODO: update useroption with current status 
     58                if($maxid) { 
     59                        $sql = 'UPDATE  wcf'.WCF_N.'_twitter_import 
     60                                SET     since_id = '.intval($maxid + 1).' 
     61                                WHERE   accountID = '.intval($me['accountID']).' 
     62                                AND     action = "'.escapeString($me['action']).'"'; 
     63                        WCF::getDB()->sendQuery($sql); 
    6064                } 
    6165        } 
  • twitter/package.xml

    r1321 r1331  
    4242        <instructions type="update" fromversion="2.0.0"> 
    4343                <files>files.tar</files> 
     44                <templates>templates.tar</templates> 
     45                <sql>update.sql</sql> 
    4446                <eventlistener>eventlistener.xml</eventlistener> 
    4547                <languages languagecode="de">de.xml</languages> 
    4648                <languages languagecode="de-informal">de.xml</languages> 
     49                <languages languagecode="en">en.xml</languages> 
    4750                <useroptions>useroptions.xml</useroptions> 
    4851        </instructions> 
  • twitter/templates/twitter.tpl

    r1298 r1331  
    9595                                        </div> 
    9696                                </div> 
    97 {* 
    9897                                <div class="container-3 column second twitterSidebar"> 
    9998                                        <div class="columnInner"> 
     
    101100                                        </div> 
    102101                                </div> 
    103 *} 
    104102                        </div> 
    105103                </div> 
  • twitter/templates/twitterSidebar.tpl

    r1298 r1331  
    22<div class="contentBox"> 
    33        <div class="border">  
    4                 <div class="containerHead"> 
    5                         <h3>{lang}wcf.contest.sidebar.addcontest.title{/lang}</h3> 
    6                 </div> 
    7                 <div style="padding:10px"> 
    8                         {lang}wcf.contest.sidebar.addcontest.description{/lang} 
    9                  
    10                         <div class="largeButtons" style="width:175px;margin-top:10px; margin-left:10px"> 
    11                                 <ul> 
    12                                         <li style="float:none"><a href="index.php?form=ContestAdd{@SID_ARG_2ND}"><img src="{icon}twitterM.png{/icon}" alt="" /> <span>{lang}wcf.contest.sidebar.addcontest.submit{/lang}</span></a></li> 
    13                                 </ul> 
    14                         </div> 
    15                  
    16                 </div> 
     4                <div class="containerHead">  
     5                        <h3>{lang}wcf.twitter.messages{/lang}</h3>  
     6                </div>  
     7                <ul class="dataList"> 
     8                        {foreach from=$tweets item=tweet} 
     9                                <li class="{cycle values='container-1,container-2'}"> 
     10                                        <div class="containerIcon"> 
     11                                                {if $tweet->getUser()->getAvatar()} 
     12                                                        {assign var=x value=$tweet->getUser()->getAvatar()->setMaxSize(24, 24)} 
     13                                                        {@$tweet->getUser()->getAvatar()} 
     14                                                {else} 
     15                                                        <img src="{@RELATIVE_WCF_DIR}images/avatars/avatar-default.png" alt="" style="width: 24px; height: 24px" /> 
     16                                                {/if} 
     17                                        </div> 
     18                                        <div class="containerContent"> 
     19                                                <h4>{@$tweet->getFormattedMessage()}</h4> 
     20                                        </div> 
     21                                </li> 
     22                        {/foreach} 
     23                </ul> 
    1724        </div> 
    1825</div> 
    1926{if $additionalBoxes2|isset}{@$additionalBoxes2}{/if} 
    20  
    21 {if $todos|isset && $todos|count > 0} 
    22         <div class="contentBox"> 
    23                 <div class="border">  
    24                         <div class="containerHead">  
    25                                 <h3>{lang}wcf.contest.todo{/lang}</h3>  
    26                         </div>  
    27                           
    28                         <ul class="dataList"> 
    29                                 {foreach from=$todos item=todo} 
    30                                         <li class="{cycle values='container-1,container-2'}"> 
    31                                                 <div class="containerIcon"> 
    32                                                         {if $todo->getOwner()->getAvatar()} 
    33                                                                 {assign var=x value=$todo->getOwner()->getAvatar()->setMaxSize(24, 24)} 
    34                                                                 {@$todo->getOwner()->getAvatar()} 
    35                                                         {else} 
    36                                                                 <img src="{@RELATIVE_WCF_DIR}images/avatars/avatar-default.png" alt="" style="width: 24px; height: 24px" /> 
    37                                                         {/if} 
    38                                                 </div> 
    39                                                 <div class="containerContent"> 
    40                                                         <h4>{$todo->getMessage()}</h4> 
    41                                                 </div> 
    42                                         </li> 
    43                                 {/foreach} 
    44                         </ul> 
    45                 </div> 
    46         </div> 
    47 {/if} 
    48  
    49 {if $additionalBoxes3|isset}{@$additionalBoxes3}{/if}