diff -urN 0.8.x/lib/rssaction.php 0.8.x-tobyink/lib/rssaction.php --- 0.8.x/lib/rssaction.php 2009-06-29 02:03:21.000000000 +0100 +++ 0.8.x-tobyink/lib/rssaction.php 2009-06-29 12:35:18.000000000 +0100 @@ -192,6 +192,55 @@ } } + // XXX: Surely there should be a common function to do this? + function extract_tags ($string) + { + $count = preg_match_all('/(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/', strtolower($string), $match); + if (!count) + { + return array(); + } + + $rv = array(); + foreach ($match[1] as $tag) + { + $rv[] = common_canonical_tag($tag); + } + + return array_unique($rv); + } + + // XXX: Surely there should be a common function to do this? + // A lot of this is borrowed from Notice.php. + function extract_accounts ($string, $sender) + { + $tname = false; + if (preg_match('/^T ([A-Z0-9]{1,64}) /', $string, $match)) { + $tname = $match[1]; + } + $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $string, $match); + + $names = array(); + + if ($cnt || $tname) { + $names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]); + } + + $rv = array(); + for ($i=0; $icreated); + if ($recipient && ($recipient->id != $sender->id)) { + $rv[$nickname] = User::staticGet('id', $recipient->id); + } + } + + return $rv; + } + function showItem($notice) { $profile = Profile::staticGet($notice->profile_id); @@ -212,10 +261,68 @@ $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri.'#acct')); $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl())); $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url'))); - if ($notice->reply_to) { + if (!empty($notice->reply_to)) { $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to)); $this->element('sioc:reply_to', array('rdf:resource' => $replyurl)); } + if (!empty($notice->conversation)) { + $conversationurl = common_local_url('conversation', + array('id' => $notice->conversation)); + if ($notice->conversation != $notice->id) + { + $conversationurl .= '#notice-'.$notice->id; + } + $this->element('sioc:has_discussion', array('rdf:resource' => $conversationurl)); + } + $tags = $this->extract_tags($notice->content); + if (!empty($tags)) { + foreach ($tags as $tag) + { + $this->element('ctag:tagged', array('ctag:label'=>$tag)); + } + } + // XXX: This may be too database-intensive! Should be reviewed!! + $accounts = $this->extract_accounts($notice->content, $profile); + if (!empty($accounts)) { + foreach ($accounts as $account) + { + $accounturi = $account->uri; + $this->element('laconica:addressedTo', + array('rdf:resource'=>$accounturi.'#acct')); + $this->creators[$accounturi] = $account; + } + } + $atts = new File; + $att = $atts->getAttachments($notice->id); + if (!empty($att)) { + foreach ($att as $n=>$attachment) { + // 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, + 'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#' + ); + if ($attachment->title) + { + $attribs['dc:title'] = $attachment->title; + } + if ($attachment->date) + { + $attribs['dc:date'] = common_date_w3dtf($attachment->date); + } + if ($attachment->size) + { + $attribs['length'] = $attachment->size; + } + if ($attachment->mimetype) + { + $attribs['type'] = $attachment->mimetype; + } + $this->element('enclosure', $attribs); + } + } $this->elementEnd('item'); $this->creators[$creator_uri] = $profile; } @@ -232,7 +339,10 @@ } $this->element('foaf:holdsAccount', array('rdf:resource' => $uri.'#acct')); $avatar = $profile->avatarUrl(); - $this->element('foaf:depiction', array('rdf:resource' => $avatar)); + if (!empty($avatar)) + { + $this->element('foaf:depiction', array('rdf:resource' => $avatar)); + } $this->elementEnd('foaf:Agent'); } } @@ -251,6 +361,8 @@ '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' =>