]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/noticelist.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / lib / noticelist.php
index 273bf3a231601f0dfcb26710bfa99c94cd8ff058..317c7a3f03b8d3e290e9922e6901519f0c0fcf7b 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/lib/favorform.php';
-require_once INSTALLDIR.'/lib/disfavorform.php';
-require_once INSTALLDIR.'/lib/attachmentlist.php';
+if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
 
 /**
  * widget for displaying a list of notices
@@ -59,15 +53,41 @@ class NoticeList extends Widget
 
     var $notice = null;
 
+    protected $addressees = true;
+    protected $attachments = true;
+    protected $id_prefix = null;
+    protected $maxchars = 0;
+    protected $options = true;
+    protected $show_n = NOTICES_PER_PAGE;
+
     /**
      * constructor
      *
      * @param Notice $notice stream of notices from DB_DataObject
      */
-    function __construct($notice, $out=null)
+    function __construct(Notice $notice, Action $out=null, array $prefs=array())
     {
         parent::__construct($out);
         $this->notice = $notice;
+
+        // 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];
+            }
+        }
+        // string preferences
+        foreach(array('id_prefix') as $key) {
+            if (array_key_exists($key, $prefs)) {
+                $this->$key = $prefs[$key];
+            }
+        }
     }
 
     /**
@@ -76,26 +96,24 @@ class NoticeList extends Widget
      * "Uses up" the stream by looping through it. So, probably can't
      * be called twice on the same list.
      *
-     * @return int count of notices listed.
+     * @param integer $n    The amount of notices to show.
+     *
+     * @return int  Total amount of notices actually available.
      */
-    function show()
+    public function show()
     {
-        $this->out->elementStart('div', array('id' =>'notices_primary'));
-        // TRANS: Header in notice list.
-        $this->out->element('h2', null, _m('HEADER','Notices'));
         $this->out->elementStart('ol', array('class' => 'notices xoxo'));
 
-        $cnt = 0;
-
-        while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
-            $cnt++;
-
-            if ($cnt > NOTICES_PER_PAGE) {
-                break;
-            }
+               $notices = $this->notice->fetchAll();
+               $total   = count($notices);
+               $notices = array_slice($notices, 0, $this->show_n);
+               
+       self::prefill($notices);
+       
+       foreach ($notices as $notice) {
 
             try {
-                $item = $this->newListItem($this->notice);
+                $item = $this->newListItem($notice);
                 $item->show();
             } catch (Exception $e) {
                 // we log exceptions and continue
@@ -105,9 +123,7 @@ class NoticeList extends Widget
         }
 
         $this->out->elementEnd('ol');
-        $this->out->elementEnd('div');
-
-        return $cnt;
+        return $total;
     }
 
     /**
@@ -120,8 +136,29 @@ class NoticeList extends Widget
      *
      * @return NoticeListItem a list item for displaying the notice
      */
-    function newListItem($notice)
+    function newListItem(Notice $notice)
+    {
+        $prefs = array('addressees' => $this->addressees,
+                       'attachments' => $this->attachments,
+                       'id_prefix' => $this->id_prefix,
+                       'maxchars' => $this->maxchars,
+                       'options' => $this->options);
+        return new NoticeListItem($notice, $this->out, $prefs);
+    }
+    
+    static function prefill(array &$notices)
     {
-        return new NoticeListItem($notice, $this->out);
+        $scoped = Profile::current();
+        $notice_ids = Notice::_idsOf($notices);
+
+        if (Event::handle('StartNoticeListPrefill', array(&$notices, $notice_ids, $scoped))) {
+
+            // Prefill attachments
+            Notice::fillAttachments($notices);
+            // Prefill the profiles
+            $profiles = Notice::fillProfiles($notices);
+
+            Event::handle('EndNoticeListPrefill', array(&$notices, &$profiles, $notice_ids, $scoped));
+        }
     }
 }