exit(1);
}
-require_once INSTALLDIR.'/lib/apiprivateauth.php';
-
/**
* Action for outputting search results in Twitter compatible Atom
* format.
*
* @see ApiPrivateAuthAction
*/
-
class ApiSearchAtomAction extends ApiPrivateAuthAction
{
-
var $cnt;
var $query;
var $lang;
*
* @see Action::__construct
*/
-
function __construct($output='php://output', $indent=null)
{
parent::__construct($output, $indent);
*
* @return boolean true
*/
-
function isReadonly()
{
return true;
* @param array $args Arguments from $_REQUEST
*
* @return boolean success
- *
*/
-
- function prepare($args)
+ function prepare(array $args = array())
{
- common_debug("in apisearchatom prepare()");
-
parent::prepare($args);
-
$this->query = $this->trimmed('q');
$this->lang = $this->trimmed('lang');
$this->rpp = $this->trimmed('rpp');
$this->page = 1;
}
- // TODO: Suppport since_id -- we need to tweak the backend
+ // TODO: Suppport max_id -- we need to tweak the backend
// Search classes to support it.
$this->since_id = $this->trimmed('since_id');
*
* @return void
*/
-
- function handle($args)
+ function handle()
{
- parent::handle($args);
+ parent::handle();
common_debug("In apisearchatom handle()");
$this->showAtom();
}
*
* @return array an array of Notice objects sorted in reverse chron
*/
-
function getNotices()
{
// TODO: Support search operators like from: and to:, boolean, etc.
if ($this->cnt > 0) {
while ($notice->fetch()) {
-
++$cnt;
if (!$this->max_id) {
$this->max_id = $notice->id;
}
+ if ($this->since_id && $notice->id <= $this->since_id) {
+ break;
+ }
+
if ($cnt > $this->rpp) {
break;
}
*
* @return void
*/
-
function showAtom()
{
$notices = $this->getNotices();
$this->showFeed();
foreach ($notices as $n) {
-
$profile = $n->getProfile();
// Don't show notices from deleted users
*
* @return void
*/
-
function showFeed()
{
// TODO: A9 OpenSearch stuff like search.twitter.com?
'rel' => 'self',
'href' => $self_uri));
+ // @todo Needs i18n?
$this->element('title', null, "$this->query - $sitename Search");
$this->element('updated', null, common_date_iso8601('now'));
'rel' => 'previous',
'href' => $previous_uri));
}
-
}
/**
*
* @return void
*/
-
function showEntry($notice)
{
$server = common_config('site', 'server');
'rel' => 'alternate',
'href' => $nurl));
$this->element('title', null, common_xml_safe_str(trim($notice->content)));
- $this->element('content', array('type' => 'html'), $notice->rendered);
+ $this->element('content', array('type' => 'html'), $notice->getRendered());
$this->element('updated', null, common_date_w3dtf($notice->created));
$this->element('link', array('type' => 'image/png',
// XXX: Twitter uses rel="image" (not valid)
// @todo: Here is where we'd put in a link to an atom feed for threads
$source = null;
+ $source_link = null;
$ns = $notice->getSource();
- if ($ns) {
- if (!empty($ns->name) && !empty($ns->url)) {
- $source = '<a href="'
- . htmlspecialchars($ns->url)
- . '" rel="nofollow">'
- . htmlspecialchars($ns->name)
- . '</a>';
- } else {
- $source = $ns->code;
+ if ($ns instanceof Notice_source) {
+ $source = $ns->code;
+ if (!empty($ns->url)) {
+ $source_link = $ns->url;
+ if (!empty($ns->name)) {
+ $source = $ns->name;
+ }
}
}
$this->element("twitter:source", null, $source);
+ $this->element("twitter:source_link", null, $source_link);
$this->elementStart('author');
$name = $profile->nickname;
if ($profile->fullname) {
+ // @todo Needs proper i18n?
$name .= ' (' . $profile->fullname . ')';
}
*
* @return void
*/
-
function initAtom()
{
header('Content-Type: application/atom+xml; charset=utf-8');
*
* @return void
*/
-
function endAtom()
{
$this->elementEnd('feed');
}
-
}