]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/rss10action.php
Reworked File->getUrl to throw exception
[quix0rs-gnu-social.git] / lib / rss10action.php
index bb4fa12b74f63ead117d254591ff73637648ca7d..6940ab4319590d34af19d63cea6edb7641e6b843 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 define('DEFAULT_RSS_LIMIT', 48);
 
-class Rss10Action extends Action
+class Rss10Action extends ManagedAction
 {
     // This will contain the details of each feed item's author and be used to generate SIOC data.
 
@@ -41,47 +41,16 @@ class Rss10Action extends Action
     var $notices = null;
     var $tags_already_output = array();
 
-    /**
-     * Constructor
-     *
-     * Just wraps the Action constructor.
-     *
-     * @param string  $output URI to output to, default = stdout
-     * @param boolean $indent Whether to indent output, default true
-     *
-     * @see Action::__construct
-     */
-
-    function __construct($output='php://output', $indent=null)
-    {
-        parent::__construct($output, $indent);
-    }
-
-    /**
-     * Do we need to write to the database?
-     *
-     * @return boolean true
-     */
-
-    function isReadonly()
+    public function isReadOnly($args)
     {
         return true;
     }
 
-    /**
-     * Read arguments and initialize members
-     *
-     * @param array $args Arguments from $_REQUEST
-     * @return boolean success
-     */
-
-    protected function prepare(array $args=array())
+    protected function doPreparation()
     {
-        parent::prepare($args);
+        $this->limit = $this->int('limit');
 
-        $this->limit = (int) $this->trimmed('limit');
-
-        if ($this->limit == 0) {
+        if (empty($this->limit)) {
             $this->limit = DEFAULT_RSS_LIMIT;
         }
 
@@ -93,7 +62,7 @@ class Rss10Action extends Action
 
                 // If the user hits cancel -- bam!
                 $this->show_basic_auth_error();
-                return;
+                // the above calls 'exit'
             } else {
                 $nickname = $_SERVER['PHP_AUTH_USER'];
                 $password = $_SERVER['PHP_AUTH_PW'];
@@ -104,27 +73,19 @@ class Rss10Action extends Action
 
                     common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = $nickname, proxy = $proxy, ip = $ip.");
                     $this->show_basic_auth_error();
-                    return;
+                    // the above calls 'exit'
                 }
             }
         }
 
-        return true;
-    }
+        $this->doStreamPreparation();
 
-    /**
-     * Handle a request
-     *
-     * @param array $args Arguments from $_REQUEST
-     *
-     * @return void
-     */
+        $this->notices = $this->getNotices($this->limit);
+    }
 
-    protected function handle()
+    protected function doStreamPreparation()
     {
-        // Parent handling, including cache check
-        parent::handle();
-        $this->showRss();
+        // for example if we need to set $this->target or something
     }
 
     function show_basic_auth_error()
@@ -137,6 +98,7 @@ class Rss10Action extends Action
         $this->element('request', null, $_SERVER['REQUEST_URI']);
         $this->elementEnd('hash');
         $this->endXML();
+        exit;
     }
 
     /**
@@ -145,7 +107,7 @@ class Rss10Action extends Action
      * @return array an array of Notice objects sorted in reverse chron
      */
 
-    function getNotices()
+    protected function getNotices()
     {
         return array();
     }
@@ -170,7 +132,7 @@ class Rss10Action extends Action
         return null;
     }
 
-    function showRss()
+    function showPage()
     {
         $this->initRss();
         $this->showChannel();
@@ -247,22 +209,26 @@ class Rss10Action extends Action
         $this->element('title', null, $title);
         $this->element('link', null, $nurl);
         $this->element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created));
-        if ($notice->rendered) {
-            $this->element('content:encoded', null, common_xml_safe_str($notice->rendered));
+        if ($notice->getRendered()) {
+            $this->element('content:encoded', null, common_xml_safe_str($notice->getRendered()));
         }
         $this->element('dc:date', null, common_date_w3dtf($notice->created));
         $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
         $this->element('foaf:maker', array('rdf:resource' => $creator_uri));
         $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct'));
-        $location = $notice->getLocation();
-        if ($location && isset($location->lat) && isset($location->lon)) {
-            $location_uri = $location->getRdfURL();
-            $attrs = array('geo:lat' => $location->lat,
-                'geo:long' => $location->lon);
-            if (strlen($location_uri)) {
-                $attrs['rdf:resource'] = $location_uri;
+        try {
+            $location = Notice_location::locFromStored($notice);
+            if (isset($location->lat) && isset($location->lon)) {
+                $location_uri = $location->getRdfURL();
+                $attrs = array('geo:lat' => $location->lat,
+                               'geo:long' => $location->lon);
+                if (strlen($location_uri)) {
+                    $attrs['rdf:resource'] = $location_uri;
+                }
+                $this->element('statusnet:origin', $attrs);
             }
-            $this->element('statusnet:origin', $attrs);
+        } catch (ServerException $e) {
+            // No result, so no location data
         }
         $this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
         $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));