| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2009-08-25 18:12:20 -04:00
										 |  |  |  * StatusNet, the distributed open-source microblogging tool | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-12-23 14:14:30 -05:00
										 |  |  |  * widget for displaying a list of notices | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |  * | 
					
						
							|  |  |  |  * PHP version 5 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * LICENCE: This program is free software: you can redistribute it and/or modify | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category  UI | 
					
						
							| 
									
										
										
										
											2009-08-25 18:12:20 -04:00
										 |  |  |  * @package   StatusNet | 
					
						
							| 
									
										
										
										
											2009-08-25 18:19:04 -04:00
										 |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @author    Sarven Capadisli <csarven@status.net> | 
					
						
							| 
									
										
										
										
											2009-08-25 18:12:20 -04:00
										 |  |  |  * @copyright 2008 StatusNet, Inc. | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 | 
					
						
							| 
									
										
										
										
											2009-08-25 18:16:46 -04:00
										 |  |  |  * @link      http://status.net/ | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-05 01:27:27 +01:00
										 |  |  | if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); } | 
					
						
							| 
									
										
										
										
											2009-01-15 23:43:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  | /** | 
					
						
							|  |  |  |  * widget for displaying a list of notices | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * There are a number of actions that display a list of notices, in | 
					
						
							|  |  |  |  * reverse chronological order. This widget abstracts out most of the | 
					
						
							|  |  |  |  * code for UI for notice lists. It's overridden to hide some | 
					
						
							|  |  |  |  * data for e.g. the profile page. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category UI | 
					
						
							| 
									
										
										
										
											2009-08-25 18:12:20 -04:00
										 |  |  |  * @package  StatusNet | 
					
						
							| 
									
										
										
										
											2009-08-25 18:19:04 -04:00
										 |  |  |  * @author   Evan Prodromou <evan@status.net> | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 | 
					
						
							| 
									
										
										
										
											2009-08-25 18:16:46 -04:00
										 |  |  |  * @link     http://status.net/ | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |  * @see      Notice | 
					
						
							|  |  |  |  * @see      NoticeListItem | 
					
						
							|  |  |  |  * @see      ProfileNoticeList | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-01-15 20:19:32 +00:00
										 |  |  | class NoticeList extends Widget | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  | { | 
					
						
							|  |  |  |     /** the current stream of notices being displayed. */ | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     var $notice = null; | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  |     protected $addressees = true; | 
					
						
							|  |  |  |     protected $attachments = true; | 
					
						
							| 
									
										
										
										
											2015-01-09 15:46:35 +01:00
										 |  |  |     protected $id_prefix = null; | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  |     protected $maxchars = 0; | 
					
						
							|  |  |  |     protected $options = true; | 
					
						
							|  |  |  |     protected $show_n = NOTICES_PER_PAGE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * constructor | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Notice $notice stream of notices from DB_DataObject | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  |     function __construct(Notice $notice, $out=null, array $prefs=array()) | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-01-19 16:35:04 +00:00
										 |  |  |         parent::__construct($out); | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |         $this->notice = $notice; | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // integer preferences
 | 
					
						
							|  |  |  |         foreach(array('show_n', 'maxchars') as $key) { | 
					
						
							|  |  |  |             if (array_key_exists($key, $prefs)) { | 
					
						
							|  |  |  |                 $this->$key = (int)$prefs[$key]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // boolean preferences
 | 
					
						
							|  |  |  |         foreach(array('addressees', 'attachments', 'options') as $key) { | 
					
						
							|  |  |  |             if (array_key_exists($key, $prefs)) { | 
					
						
							|  |  |  |                 $this->$key = (bool)$prefs[$key]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-01-09 15:46:35 +01:00
										 |  |  |         // string preferences
 | 
					
						
							|  |  |  |         foreach(array('id_prefix') as $key) { | 
					
						
							|  |  |  |             if (array_key_exists($key, $prefs)) { | 
					
						
							|  |  |  |                 $this->$key = $prefs[$key]; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * show the list of notices | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2009-11-08 23:28:51 +01:00
										 |  |  |      * "Uses up" the stream by looping through it. So, probably can't | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |      * be called twice on the same list. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  |      * @param integer $n    The amount of notices to show. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return int  Total amount of notices actually available. | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-01-08 20:19:43 +01:00
										 |  |  |     public function show() | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-05-29 02:38:38 +00:00
										 |  |  |         $this->out->elementStart('ol', array('class' => 'notices xoxo')); | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  | 		$notices = $this->notice->fetchAll(); | 
					
						
							| 
									
										
										
										
											2011-08-02 11:22:37 -04:00
										 |  |  | 		$total   = count($notices); | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  | 		$notices = array_slice($notices, 0, $this->show_n); | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-08-02 12:01:41 -04:00
										 |  |  |     	self::prefill($notices); | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  |     	 | 
					
						
							|  |  |  |     	foreach ($notices as $notice) { | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-13 10:59:01 -04:00
										 |  |  |             try { | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  |                 $item = $this->newListItem($notice); | 
					
						
							| 
									
										
										
										
											2010-07-13 10:59:01 -04:00
										 |  |  |                 $item->show(); | 
					
						
							|  |  |  |             } catch (Exception $e) { | 
					
						
							|  |  |  |                 // we log exceptions and continue
 | 
					
						
							|  |  |  |                 common_log(LOG_ERR, $e->getMessage()); | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-29 02:38:38 +00:00
										 |  |  |         $this->out->elementEnd('ol'); | 
					
						
							| 
									
										
										
										
											2011-08-02 11:22:37 -04:00
										 |  |  |         return $total; | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * returns a new list item for the current notice | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Recipe (factory?) method; overridden by sub-classes to give | 
					
						
							|  |  |  |      * a different list item class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Notice $notice the current notice | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return NoticeListItem a list item for displaying the notice | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-06-02 00:20:27 +02:00
										 |  |  |     function newListItem(Notice $notice) | 
					
						
							| 
									
										
										
										
											2008-12-23 14:08:51 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  |         $prefs = array('addressees' => $this->addressees, | 
					
						
							|  |  |  |                        'attachments' => $this->attachments, | 
					
						
							| 
									
										
										
										
											2015-01-09 15:46:35 +01:00
										 |  |  |                        'id_prefix' => $this->id_prefix, | 
					
						
							| 
									
										
										
										
											2015-01-08 20:07:10 +01:00
										 |  |  |                        'maxchars' => $this->maxchars, | 
					
						
							|  |  |  |                        'options' => $this->options); | 
					
						
							|  |  |  |         return new NoticeListItem($notice, $this->out, $prefs); | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2014-06-27 13:58:35 +02:00
										 |  |  |     static function prefill(array &$notices) | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2014-06-27 13:58:35 +02:00
										 |  |  |         $scoped = Profile::current(); | 
					
						
							|  |  |  |         $notice_ids = Notice::_idsOf($notices); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (Event::handle('StartNoticeListPrefill', array(&$notices, $notice_ids, $scoped))) { | 
					
						
							| 
									
										
										
										
											2012-03-21 09:26:35 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // Prefill attachments
 | 
					
						
							|  |  |  |             Notice::fillAttachments($notices); | 
					
						
							|  |  |  |             // Prefill repeat data
 | 
					
						
							|  |  |  |             Notice::fillRepeats($notices); | 
					
						
							|  |  |  |             // Prefill the profiles
 | 
					
						
							|  |  |  |             $profiles = Notice::fillProfiles($notices); | 
					
						
							| 
									
										
										
										
											2011-08-22 12:39:37 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 13:58:35 +02:00
										 |  |  |             if ($scoped instanceof Profile) { | 
					
						
							|  |  |  |                 Notice::pivotGet('repeat_of', $notice_ids, array('profile_id' => $scoped->id)); | 
					
						
							| 
									
										
										
										
											2012-03-21 09:26:35 -04:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-27 13:58:35 +02:00
										 |  |  |             Event::handle('EndNoticeListPrefill', array(&$notices, &$profiles, $notice_ids, $scoped)); | 
					
						
							| 
									
										
										
										
											2012-03-21 09:26:35 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-08-01 16:43:44 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2008-12-11 18:12:52 -05:00
										 |  |  | } |