Overview

Packages

  • Push

Classes

  • Horde_Push
  • Horde_Push_Cli
  • Horde_Push_Exception
  • Horde_Push_Factory_Push
  • Horde_Push_Factory_Recipients
  • Horde_Push_Recipient_Base
  • Horde_Push_Recipient_Blogger
  • Horde_Push_Recipient_Facebook
  • Horde_Push_Recipient_Mail
  • Horde_Push_Recipient_Mock
  • Horde_Push_Recipient_Twitter
  • Horde_Push_Translation

Interfaces

  • Horde_Push_Recipient
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Twitter as recipient.
 4:  *
 5:  * PHP version 5
 6:  *
 7:  * @category Horde
 8:  * @package  Push
 9:  * @author   Gunnar Wrobel <wrobel@pardus.de>
10:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
11:  * @link     http://www.horde.org/libraries/Horde_Push
12:  */
13: 
14: /**
15:  * Twitter as recipient.
16:  *
17:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18:  *
19:  * See the enclosed file COPYING for license information (LGPL). If you did not
20:  * receive this file, see http://www.horde.org/licenses/lgpl21.
21:  *
22:  * @category Horde
23:  * @package  Push
24:  * @author   Gunnar Wrobel <wrobel@pardus.de>
25:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
26:  * @link     http://www.horde.org/libraries/Horde_Push
27:  */
28: class Horde_Push_Recipient_Twitter
29: extends Horde_Push_Recipient_Base
30: {
31:     /**
32:      * The twitter client.
33:      *
34:      * @var Horde_Service_Twitter
35:      */
36:     private $_twitter;
37: 
38:     /**
39:      * A HTTP client.
40:      *
41:      * @var Horde_Http_Client
42:      */
43:     private $_client;
44: 
45:     /**
46:      * Constructor.
47:      *
48:      * @param Horde_Service_Twitter $twitter The twitter client.
49:      */
50:     public function __construct(Horde_Service_Twitter $twitter,
51:                                 $client = null)
52:     {
53:         $this->_twitter = $twitter;
54:         $this->_client = $client;
55:     }
56: 
57:     /**
58:      * Push content to the recipient.
59:      *
60:      * @param Horde_Push $content The content element.
61:      * @param array      $options Additional options.
62:      *
63:      * @return string The result description.
64:      */
65:     public function push(Horde_Push $content, $options = array())
66:     {
67:         $tweet = $content->getSummary();
68:         if ($content->hasReferences() && strlen($tweet) < 116 &&
69:             class_exists('Horde_Service_UrlShortener_Base') &&
70:             $this->_client !== null) {
71:             $shortener = new Horde_Service_UrlShortener_TinyUrl($this->_client);
72:             foreach ($content->getReferences() as $reference) {
73:                 $tweet .= ' ' . $shortener->shorten($reference);
74:                 if (strlen($tweet) > 115) {
75:                     break;
76:                 }
77:             }
78:         }
79:         if ($content->hasTags()) {
80:             foreach ($content->getTags() as $tag) {
81:                 if (strlen($tweet) + strlen($tag) < 139) {
82:                     $tweet .= ' #' . $tag;
83:                 }
84:             }
85:         }
86:         if (empty($options['pretend'])) {
87:             $this->_twitter->statuses->update($tweet);
88:             return 'Pushed tweet to twitter.';
89:         } else {
90:             return sprintf(
91:                 'Would push tweet "%s" to twitter.', $tweet
92:             );
93:         }
94:     }
95: }
96: 
API documentation generated by ApiGen