X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frssaction.php;h=faf6bec7dec4618d8ebc4888c4e55353f8aff99a;hb=968058c68b0d23e3dccc85301d78dccf8bcc0ba1;hp=9898894edd678e8fafd6a09c7d829cb2073672d2;hpb=e70a79d6ab5e9cd8894490d4fc0d3b855e807edc;p=quix0rs-gnu-social.git diff --git a/lib/rssaction.php b/lib/rssaction.php index 9898894edd..faf6bec7de 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -1,6 +1,6 @@ . * * @category Mail - * @package Laconica - * @author Evan Prodromou + * @package StatusNet + * @author Evan Prodromou * @author Earle Martin - * @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); @@ -78,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; } @@ -97,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 */ @@ -211,7 +244,7 @@ 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)); @@ -225,26 +258,27 @@ class Rss10Action extends Action $attachments = $notice->attachments(); if($attachments){ foreach($attachments as $attachment){ - if ($attachment->isEnclosure()) { + $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' => $attachment->url, - 'url' => $attachment->url, + 'rdf:resource' => $enclosure->url, + 'url' => $enclosure->url, 'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#' ); - if ($attachment->title) { - $attribs['dc:title'] = $attachment->title; + if ($enclosure->title) { + $attribs['dc:title'] = $enclosure->title; } - if ($attachment->modified) { - $attribs['dc:date'] = common_date_w3dtf($attachment->modified); + if ($enclosure->modified) { + $attribs['dc:date'] = common_date_w3dtf($enclosure->modified); } - if ($attachment->size) { - $attribs['length'] = $attachment->size; + if ($enclosure->size) { + $attribs['length'] = $enclosure->size; } - if ($attachment->mimetype) { - $attribs['type'] = $attachment->mimetype; + if ($enclosure->mimetype) { + $attribs['type'] = $enclosure->mimetype; } $this->element('enclosure', $attribs); } @@ -320,8 +354,8 @@ class Rss10Action extends Action 'http://rdfs.org/sioc/types#', 'xmlns:rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', - 'xmlns:laconica' => - 'http://laconi.ca/ont/', + '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'));