]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/rssaction.php
Merge branch '0.8.x' into 0.9.x
[quix0rs-gnu-social.git] / lib / rssaction.php
index eafdbf131d6d00d3801adb87729e49928a024598..faf6bec7dec4618d8ebc4888c4e55353f8aff99a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Base class for RSS 1.0 feed actions
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Mail
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
  * @author    Earle Martin <earle@downlode.org>
- * @copyright 2008-9 Control Yourself, Inc.
+ * @copyright 2008-9 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')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 define('DEFAULT_RSS_LIMIT', 48);
 
@@ -39,6 +39,7 @@ class Rss10Action extends Action
     var $creators = array();
     var $limit = DEFAULT_RSS_LIMIT;
     var $notices = null;
+    var $tags_already_output = array();
 
     /**
      * Constructor
@@ -77,10 +78,37 @@ class Rss10Action extends Action
     function prepare($args)
     {
         parent::prepare($args);
+
         $this->limit = (int) $this->trimmed('limit');
+
         if ($this->limit == 0) {
             $this->limit = DEFAULT_RSS_LIMIT;
         }
+
+        if (common_config('site', 'private')) {
+            if (!isset($_SERVER['PHP_AUTH_USER'])) {
+
+                # This header makes basic auth go
+                header('WWW-Authenticate: Basic realm="StatusNet RSS"');
+
+                # If the user hits cancel -- bam!
+                $this->show_basic_auth_error();
+                return;
+            } else {
+                $nickname = $_SERVER['PHP_AUTH_USER'];
+                $password = $_SERVER['PHP_AUTH_PW'];
+
+                if (!common_check_user($nickname, $password)) {
+                    # basic authentication failed
+                    list($proxy, $ip) = common_client_ip();
+
+                    common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = $nickname, proxy = $proxy, ip = $ip.");
+                    $this->show_basic_auth_error();
+                    return;
+                }
+            }
+        }
+
         return true;
     }
 
@@ -96,17 +124,23 @@ class Rss10Action extends Action
     {
         // Parent handling, including cache check
         parent::handle($args);
-        // Get the list of notices
-        if (empty($this->tag)) {
-            $this->notices = $this->getNotices($this->limit);
-        } else {
-            $this->notices = $this->getTaggedNotices($this->tag, $this->limit);
-        }
         $this->showRss();
     }
 
+    function show_basic_auth_error()
+    {
+        header('HTTP/1.1 401 Unauthorized');
+        header('Content-Type: application/xml; charset=utf-8');
+        $this->startXML();
+        $this->elementStart('hash');
+        $this->element('error', null, 'Could not authenticate you.');
+        $this->element('request', null, $_SERVER['REQUEST_URI']);
+        $this->elementEnd('hash');
+        $this->endXML();
+    }
+
     /**
-     * Get the notices to output in this stream
+     * Get the notices to output in this stream.
      *
      * @return array an array of Notice objects sorted in reverse chron
      */
@@ -210,8 +244,71 @@ class Rss10Action extends Action
         $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'));
-        $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl()));
+        $this->element('statusnet:postIcon', array('rdf:resource' => $profile->avatarUrl()));
         $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
+        if ($notice->reply_to) {
+            $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
+            $this->element('sioc:reply_of', array('rdf:resource' => $replyurl));
+        }
+        if (!empty($notice->conversation)) {
+            $conversationurl = common_local_url('conversation',
+                                         array('id' => $notice->conversation));
+            $this->element('sioc:has_discussion', array('rdf:resource' => $conversationurl));
+        }
+        $attachments = $notice->attachments();
+        if($attachments){
+            foreach($attachments as $attachment){
+                $enclosure=$attachment->getEnclosure();
+                if ($enclosure) {
+                    // DO NOT move xmlns declaration to root element. Making it
+                    // the default namespace here improves compatibility with
+                    // real-world feed readers.
+                    $attribs = array(
+                        'rdf:resource' => $enclosure->url,
+                        'url' => $enclosure->url,
+                        'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#'
+                        );
+                    if ($enclosure->title) {
+                        $attribs['dc:title'] = $enclosure->title;
+                    }
+                    if ($enclosure->modified) {
+                        $attribs['dc:date'] = common_date_w3dtf($enclosure->modified);
+                    }
+                    if ($enclosure->size) {
+                        $attribs['length'] = $enclosure->size;
+                    }
+                    if ($enclosure->mimetype) {
+                        $attribs['type'] = $enclosure->mimetype;
+                    }
+                    $this->element('enclosure', $attribs);
+                }
+                $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
+            }
+        }
+
+        $tag = new Notice_tag();
+        $tag->notice_id = $notice->id;
+        if ($tag->find()) {
+            $entry['tags']=array();
+            while ($tag->fetch()) {
+                $tagpage = common_local_url('tag', array('tag' => $tag->tag));
+
+                if ( in_array($tag, $this->tags_already_output) ) {
+                    $this->element('ctag:tagged', array('rdf:resource'=>$tagpage.'#concept'));
+                    continue;
+                }
+
+                $tagrss  = common_local_url('tagrss', array('tag' => $tag->tag));
+                $this->elementStart('ctag:tagged');
+                $this->elementStart('ctag:Tag', array('rdf:about'=>$tagpage.'#concept', 'ctag:label'=>$tag->tag));
+                $this->element('foaf:page', array('rdf:resource'=>$tagpage));
+                $this->element('rdfs:seeAlso', array('rdf:resource'=>$tagrss));
+                $this->elementEnd('ctag:Tag');
+                $this->elementEnd('ctag:tagged');
+
+                $this->tags_already_output[] = $tag->tag;
+            }
+        }
         $this->elementEnd('item');
         $this->creators[$creator_uri] = $profile;
     }
@@ -247,14 +344,18 @@ class Rss10Action extends Action
                                               'http://creativecommons.org/ns#',
                                               'xmlns:content' =>
                                               'http://purl.org/rss/1.0/modules/content/',
+                                              'xmlns:ctag' =>
+                                              'http://commontag.org/ns#',
                                               'xmlns:foaf' =>
                                               'http://xmlns.com/foaf/0.1/',
                                               'xmlns:sioc' =>
                                               'http://rdfs.org/sioc/ns#',
                                               'xmlns:sioct' =>
                                               'http://rdfs.org/sioc/types#',
-                                              'xmlns:laconica' =>
-                                              'http://laconi.ca/ont/',
+                                              'xmlns:rdfs' =>
+                                              'http://www.w3.org/2000/01/rdf-schema#',
+                                              'xmlns:statusnet' =>
+                                              'http://status.net/ont/',
                                               'xmlns' => 'http://purl.org/rss/1.0/'));
         $this->elementStart('sioc:Site', array('rdf:about' => common_root_url()));
         $this->element('sioc:name', null, common_config('site', 'name'));