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:  * A content element that will be pushed to various recipients.
  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:  * A content element that will be pushed to various recipients.
 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
 29: {
 30:     /**
 31:      * Content summary.
 32:      *
 33:      * @var string
 34:      */
 35:     private $_summary = '';
 36: 
 37:     /**
 38:      * Content.
 39:      *
 40:      * @var array
 41:      */
 42:     private $_content = array();
 43: 
 44:     /**
 45:      * Content types.
 46:      *
 47:      * @var array
 48:      */
 49:     private $_types = array();
 50: 
 51:     /**
 52:      * The recipients that will receive the content.
 53:      *
 54:      * @var array
 55:      */
 56:     private $_recipients = array();
 57: 
 58:     /**
 59:      * Reference links.
 60:      *
 61:      * @var array
 62:      */
 63:     private $_references = array();
 64: 
 65:     /**
 66:      * Tags for the push.
 67:      *
 68:      * @var array
 69:      */
 70:     private $_tags = array();
 71: 
 72:     /**
 73:      * Return the summary for this content element.
 74:      *
 75:      * @return string The summary.
 76:      */
 77:     public function getSummary()
 78:     {
 79:         return $this->_summary;
 80:     }
 81: 
 82:     /**
 83:      * Set the summary for this content element.
 84:      *
 85:      * @param string $summary The summary.
 86:      *
 87:      * @return Horde_Push This content element.
 88:      */
 89:     public function setSummary($summary)
 90:     {
 91:         $this->_summary = $summary;
 92:         return $this;
 93:     }
 94: 
 95:     /**
 96:      * Return the contents for this element.
 97:      *
 98:      * @return array The content list.
 99:      */
100:     public function getContent()
101:     {
102:         return $this->_content;
103:     }
104: 
105:     /**
106:      * Return the content at the given index as a string.
107:      *
108:      * @param int $index Index of the content part.
109:      *
110:      * @return string The content.
111:      */
112:     public function getStringContent($index)
113:     {
114:         if (is_resource($this->_content[$index]['content'])) {
115:             rewind($this->_content[$index]['content']);
116:             return stream_get_contents($this->_content[$index]['content']);
117:         } else {
118:             return $this->_content[$index]['content'];
119:         }
120:     }
121: 
122:     /**
123:      * Return the contents by MIME type for this element.
124:      *
125:      * @return array The content list ordered by MIME type.
126:      */
127:     public function getMimeTypes()
128:     {
129:         return $this->_types;
130:     }
131: 
132:     /**
133:      * Add content to this element.
134:      *
135:      * @param string|resource $content   The UTF-8 encoded content.
136:      * @param string          $mime_type The MIME type of the content.
137:      * @param array           $params    Content specific parameters.
138:      *
139:      * @return Horde_Push This content element.
140:      */
141:     public function addContent($content, $mime_type = 'text/plain',
142:                                $params = array())
143:     {
144:         $this->_types[$mime_type][] = count($this->_content);
145:         $this->_content[] = array(
146:             'content' => $content,
147:             'mime_type' => $mime_type,
148:             'params' => $params
149:         );
150:         return $this;
151:     }
152: 
153:     /**
154:      * Add a recipient for this element.
155:      *
156:      * @param Horde_Push_Recipient $recipient The recipient.
157:      *
158:      * @return Horde_Push This content element.
159:      */
160:     public function addRecipient(Horde_Push_Recipient $recipient)
161:     {
162:         $this->_recipients[] = $recipient;
163:         return $this;
164:     }
165: 
166:     /**
167:      * Add a URL reference for this element.
168:      *
169:      * @param string $reference The link.
170:      *
171:      * @return Horde_Push This content element.
172:      */
173:     public function addReference($reference)
174:     {
175:         $this->_references[] = $reference;
176:         return $this;
177:     }
178: 
179:     /**
180:      * Retrieve the URL references for this element.
181:      *
182:      * @return array The URL references.
183:      */
184:     public function getReferences()
185:     {
186:         return $this->_references;
187:     }
188: 
189:     /**
190:      * Indicate if this element has URL references.
191:      *
192:      * @return boolean True, if there have been links added to the element.
193:      */
194:     public function hasReferences()
195:     {
196:         return !empty($this->_references);
197:     }
198: 
199:     /**
200:      * Add a tag for this element.
201:      *
202:      * @param string $tag The tag.
203:      *
204:      * @return Horde_Push This content element.
205:      */
206:     public function addTag($tag)
207:     {
208:         $this->_tags[] = $tag;
209:         return $this;
210:     }
211: 
212:     /**
213:      * Retrieve the tags for this element.
214:      *
215:      * @return array The tags.
216:      */
217:     public function getTags()
218:     {
219:         return $this->_tags;
220:     }
221: 
222:     /**
223:      * Indicate if this element has tags.
224:      *
225:      * @return boolean True, if there have been tags added to the element.
226:      */
227:     public function hasTags()
228:     {
229:         return !empty($this->_tags);
230:     }
231: 
232:     /**
233:      * Push the content to the recipients.
234:      *
235:      * @param array $options Additional options.
236:      *
237:      * @return Horde_Push This content element.
238:      */
239:     public function push($options = array())
240:     {
241:         $results = array();
242:         foreach ($this->_recipients as $recipient) {
243:             $results[] = $recipient->push($this, $options);
244:         }
245:         return $results;
246:     }
247: }
248: 
API documentation generated by ApiGen