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)
{
- 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)
{
parent::handle($args);
*
* @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');
if ($ns) {
if (!empty($ns->name) && !empty($ns->url)) {
$source = '<a href="'
- . htmlspecialchars($ns->url)
- . '" rel="nofollow">'
- . htmlspecialchars($ns->name)
- . '</a>';
+ . htmlspecialchars($ns->url)
+ . '" rel="nofollow">'
+ . htmlspecialchars($ns->name)
+ . '</a>';
} else {
$source = $ns->code;
}
$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');
}
-
}