]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/shownotice.php
Revert "Added bit about being incompatible with file attachment virtual server"
[quix0rs-gnu-social.git] / actions / shownotice.php
index 52faba93ef76dae9ce63fdc8bd27b0c31d705ca1..3bc52b2dbc7bae3fef45a4bf7cedc24df156bc38 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Show a single notice
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Personal
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2008-2009 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
@@ -39,13 +39,13 @@ require_once INSTALLDIR.'/lib/feedlist.php';
  * Show a single notice
  *
  * @category Personal
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  */
 
-class ShownoticeAction extends Action
+class ShownoticeAction extends OwnerDesignAction
 {
     /**
      * Notice object to show
@@ -83,19 +83,26 @@ class ShownoticeAction extends Action
 
         $this->notice = Notice::staticGet($id);
 
-        if (!$this->notice) {
+        if (empty($this->notice)) {
             $this->clientError(_('No such notice.'), 404);
             return false;
         }
 
         $this->profile = $this->notice->getProfile();
 
-        if (!$this->profile) {
+        if (empty($this->profile)) {
             $this->serverError(_('Notice has no profile'), 500);
             return false;
         }
 
-        $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
+        $this->user = User::staticGet('id', $this->profile->id);
+
+        if (! $this->notice->is_local) {
+            common_redirect($this->notice->uri);
+            return false;
+        }
+
+        $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
 
         return true;
     }
@@ -106,7 +113,7 @@ class ShownoticeAction extends Action
      * @return boolean true
      */
 
-    function isReadOnly()
+    function isReadOnly($args)
     {
         return true;
     }
@@ -122,7 +129,7 @@ class ShownoticeAction extends Action
 
     function lastModified()
     {
-        return max(strtotime($this->notice->created),
+        return max(strtotime($this->notice->modified),
                    strtotime($this->profile->modified),
                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
     }
@@ -158,8 +165,14 @@ class ShownoticeAction extends Action
 
     function title()
     {
+        if (!empty($this->profile->fullname)) {
+            $base = $this->profile->fullname . ' (' . $this->user->nickname . ') ';
+        } else {
+            $base = $this->user->nickname;
+        }
+
         return sprintf(_('%1$s\'s status on %2$s'),
-                       $this->profile->nickname,
+                       $base,
                        common_exact_date($this->notice->created));
     }
 
@@ -177,7 +190,25 @@ class ShownoticeAction extends Action
     {
         parent::handle($args);
 
-        $this->showPage();
+        if ($this->notice->is_local == Notice::REMOTE_OMB) {
+            if (!empty($this->notice->url)) {
+                common_redirect($this->notice->url, 301);
+            } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
+                common_redirect($this->notice->uri, 301);
+            }
+        } else {
+            $this->showPage();
+        }
+    }
+
+    /**
+     * Don't show local navigation
+     *
+     * @return void
+     */
+
+    function showLocalNavBlock()
+    {
     }
 
     /**
@@ -190,10 +221,29 @@ class ShownoticeAction extends Action
 
     function showContent()
     {
-        $this->elementStart('ul', array('id' => 'notices'));
-        $nli = new NoticeListItem($this->notice, $this);
+        $this->elementStart('ol', array('class' => 'notices xoxo'));
+        $nli = new SingleNoticeItem($this->notice, $this);
         $nli->show();
-        $this->elementEnd('ul');
+        $this->elementEnd('ol');
+    }
+
+    /**
+     * Don't show page notice
+     *
+     * @return void
+     */
+
+    function showPageNoticeBlock()
+    {
+    }
+
+    /**
+     * Don't show aside
+     *
+     * @return void
+     */
+
+    function showAside() {
     }
 
     /**
@@ -225,5 +275,45 @@ class ShownoticeAction extends Action
             $this->element('meta', array('name' => 'microid',
                                          'content' => $id->toString()));
         }
+        $this->element('link',array('rel'=>'alternate',
+            'type'=>'application/json+oembed',
+            'href'=>common_local_url(
+                'oembed',
+                array(),
+                array('format'=>'json','url'=>$this->notice->uri)),
+            'title'=>'oEmbed'),null);
+        $this->element('link',array('rel'=>'alternate',
+            'type'=>'text/xml+oembed',
+            'href'=>common_local_url(
+                'oembed',
+                array(),
+                array('format'=>'xml','url'=>$this->notice->uri)),
+            'title'=>'oEmbed'),null);
+    }
+}
+
+class SingleNoticeItem extends NoticeListItem
+{
+    /**
+     * recipe function for displaying a single notice.
+     *
+     * We overload to show attachments.
+     *
+     * @return void
+     */
+
+    function show()
+    {
+        $this->showStart();
+        $this->showNotice();
+        $this->showNoticeAttachments();
+        $this->showNoticeInfo();
+        $this->showNoticeOptions();
+        $this->showEnd();
+    }
+
+    function showNoticeAttachments() {
+        $al = new AttachmentList($this->notice, $this->out);
+        $al->show();
     }
 }