summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/all.php36
-rw-r--r--actions/allrss.php14
-rw-r--r--actions/api.php12
-rw-r--r--actions/avatarsettings.php38
-rw-r--r--actions/doc.php12
-rw-r--r--actions/editgroup.php6
-rw-r--r--actions/emailsettings.php7
-rw-r--r--actions/facebookinvite.php25
-rw-r--r--actions/favorited.php8
-rw-r--r--actions/finishopenidlogin.php17
-rw-r--r--actions/finishremotesubscribe.php10
-rw-r--r--actions/grouprss.php15
-rw-r--r--actions/login.php6
-rw-r--r--actions/newgroup.php6
-rw-r--r--actions/newmessage.php2
-rw-r--r--actions/newnotice.php24
-rw-r--r--actions/noticesearch.php182
-rw-r--r--actions/peoplesearch.php26
-rw-r--r--actions/peopletag.php126
-rw-r--r--actions/profilesettings.php6
-rw-r--r--actions/public.php43
-rw-r--r--actions/register.php6
-rw-r--r--actions/remotesubscribe.php3
-rw-r--r--actions/replies.php28
-rw-r--r--actions/showfavorites.php33
-rw-r--r--actions/showgroup.php27
-rw-r--r--actions/showstream.php101
-rw-r--r--actions/tag.php22
-rw-r--r--actions/tagother.php5
-rw-r--r--actions/twitapiaccount.php31
-rw-r--r--actions/twitapisearchatom.php368
-rw-r--r--actions/twitapisearchjson.php149
-rw-r--r--actions/twitapistatuses.php61
-rw-r--r--actions/twitapitrends.php90
-rw-r--r--actions/twitapiusers.php52
-rw-r--r--actions/twittersettings.php5
-rw-r--r--actions/updateprofile.php16
-rw-r--r--actions/userauthorization.php20
-rw-r--r--actions/userrss.php11
39 files changed, 1129 insertions, 520 deletions
diff --git a/actions/all.php b/actions/all.php
index d75d1b946..8e67ec0f3 100644
--- a/actions/all.php
+++ b/actions/all.php
@@ -42,9 +42,9 @@ class AllAction extends Action
if (!$this->page) {
$this->page = 1;
}
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -69,13 +69,22 @@ class AllAction extends Action
}
}
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('allrss', array('nickname' =>
- $this->user->nickname)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for friends of %s'), $this->user->nickname)));
+ return array(new Feed(Feed::RSS1,
+ common_local_url('allrss', array('nickname' =>
+ $this->user->nickname)),
+ sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
+ new Feed(Feed::RSS2,
+ common_local_url('api', array('apiaction' => 'statuses',
+ 'method' => 'friends_timeline',
+ 'argument' => $this->user->nickname.'.rss')),
+ sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
+ new Feed(Feed::ATOM,
+ common_local_url('api', array('apiaction' => 'statuses',
+ 'method' => 'friends_timeline',
+ 'argument' => $this->user->nickname.'.atom')),
+ sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname)));
}
function showLocalNav()
@@ -84,15 +93,6 @@ class AllAction extends Action
$nav->show();
}
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $this->user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'allrss')));
- }
-
function showContent()
{
$notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
@@ -110,7 +110,7 @@ class AllAction extends Action
$user =& common_current_user();
if ($user && ($user->id == $this->user->id)) {
$this->element('h1', NULL, _("You and friends"));
- } else {
+ } else {
$this->element('h1', NULL, sprintf(_('%s and friends'), $this->user->nickname));
}
}
diff --git a/actions/allrss.php b/actions/allrss.php
index 05787f3f7..0114c4396 100644
--- a/actions/allrss.php
+++ b/actions/allrss.php
@@ -53,7 +53,9 @@ class AllrssAction extends Rss10Action
/**
* Initialization.
- *
+ *
+ * @param array $args Web and URL arguments
+ *
* @return boolean false if user doesn't exist
*/
function prepare($args)
@@ -81,7 +83,7 @@ class AllrssAction extends Rss10Action
{
$user = $this->user;
$notice = $user->noticesWithFriends(0, $limit);
-
+
while ($notice->fetch()) {
$notices[] = clone($notice);
}
@@ -104,7 +106,8 @@ class AllrssAction extends Rss10Action
'link' => common_local_url('all',
array('nickname' =>
$user->nickname)),
- 'description' => sprintf(_('Feed for friends of %s'), $user->nickname));
+ 'description' => sprintf(_('Feed for friends of %s'),
+ $user->nickname));
return $c;
}
@@ -123,10 +126,5 @@ class AllrssAction extends Rss10Action
$avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
return $avatar ? $avatar->url : null;
}
-
- function isReadOnly()
- {
- return true;
- }
}
diff --git a/actions/api.php b/actions/api.php
index 21fe4eea3..c18d551b6 100644
--- a/actions/api.php
+++ b/actions/api.php
@@ -127,18 +127,20 @@ class ApiAction extends Action
'laconica/wadl');
static $bareauth = array('statuses/user_timeline',
+ 'statuses/friends_timeline',
'statuses/friends',
+ 'statuses/replies',
'statuses/followers',
'favorites/favorites');
- # If the site is "private", all API methods need authentication
-
+ $fullname = "$this->api_action/$this->api_method";
+
+ // If the site is "private", all API methods except laconica/config
+ // need authentication
if (common_config('site', 'private')) {
- return true;
+ return $fullname != 'laconica/config' || false;
}
- $fullname = "$this->api_action/$this->api_method";
-
if (in_array($fullname, $bareauth)) {
# bareauth: only needs auth if without an argument
if ($this->api_arg) {
diff --git a/actions/avatarsettings.php b/actions/avatarsettings.php
index 7dd53f6eb..c2bb35a39 100644
--- a/actions/avatarsettings.php
+++ b/actions/avatarsettings.php
@@ -145,6 +145,7 @@ class AvatarsettingsAction extends AccountSettingsAction
'height' => AVATAR_PROFILE_SIZE,
'alt' => $user->nickname));
$this->elementEnd('div');
+ $this->submit('delete', _('Delete'));
$this->elementEnd('li');
}
@@ -256,6 +257,8 @@ class AvatarsettingsAction extends AccountSettingsAction
$this->uploadAvatar();
} else if ($this->arg('crop')) {
$this->cropAvatar();
+ } else if ($this->arg('delete')) {
+ $this->deleteAvatar();
} else {
$this->showForm(_('Unexpected form submission.'));
}
@@ -321,13 +324,14 @@ class AvatarsettingsAction extends AccountSettingsAction
return;
}
- // If image is not being cropped assume pos & dimentions of original
+ $file_d = ($filedata['width'] > $filedata['height'])
+ ? $filedata['height'] : $filedata['width'];
+
$dest_x = $this->arg('avatar_crop_x') ? $this->arg('avatar_crop_x'):0;
$dest_y = $this->arg('avatar_crop_y') ? $this->arg('avatar_crop_y'):0;
- $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w'):$filedata['width'];
- $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$filedata['height'];
- $size = min($dest_w, $dest_h);
- $size = ($size > MAX_ORIGINAL) ? MAX_ORIGINAL:$size;
+ $dest_w = $this->arg('avatar_crop_w') ? $this->arg('avatar_crop_w'):$file_d;
+ $dest_h = $this->arg('avatar_crop_h') ? $this->arg('avatar_crop_h'):$file_d;
+ $size = min($dest_w, $dest_h, MAX_ORIGINAL);
$user = common_current_user();
$profile = $user->getProfile();
@@ -340,10 +344,34 @@ class AvatarsettingsAction extends AccountSettingsAction
unset($_SESSION['FILEDATA']);
$this->mode = 'upload';
$this->showForm(_('Avatar updated.'), true);
+ common_broadcast_profile($profile);
} else {
$this->showForm(_('Failed updating avatar.'));
}
}
+
+ /**
+ * Get rid of the current avatar.
+ *
+ * @return void
+ */
+
+ function deleteAvatar()
+ {
+ $user = common_current_user();
+ $profile = $user->getProfile();
+
+ $avatar = $profile->getOriginalAvatar();
+ $avatar->delete();
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ $avatar->delete();
+ $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+ $avatar->delete();
+ $avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
+ $avatar->delete();
+
+ $this->showForm(_('Avatar deleted.'), true);
+ }
/**
* Add the jCrop stylesheet
diff --git a/actions/doc.php b/actions/doc.php
index 6957659ad..ebffb7c15 100644
--- a/actions/doc.php
+++ b/actions/doc.php
@@ -50,7 +50,7 @@ class DocAction extends Action
/**
* Class handler.
- *
+ *
* @param array $args array of arguments
*
* @return nothing
@@ -59,7 +59,7 @@ class DocAction extends Action
{
parent::handle($args);
$this->title = $this->trimmed('title');
- $this->filename = INSTALLDIR.'/doc/'.$this->title;
+ $this->filename = INSTALLDIR.'/doc-src/'.$this->title;
if (!file_exists($this->filename)) {
$this->clientError(_('No such document.'));
return;
@@ -71,14 +71,14 @@ class DocAction extends Action
function showPageTitle() {
$this->element('h1', array('class' => 'entry-title'), $this->title());
}
-
+
// overrided to add hentry, and content-inner classes
function showContentBlock()
{
$this->elementStart('div', array('id' => 'content', 'class' => 'hentry'));
$this->showPageTitle();
$this->showPageNoticeBlock();
- $this->elementStart('div', array('id' => 'content_inner',
+ $this->elementStart('div', array('id' => 'content_inner',
'class' => 'entry-content'));
// show the actual content (forms, lists, whatever)
$this->showContent();
@@ -88,7 +88,7 @@ class DocAction extends Action
/**
* Display content.
- *
+ *
* @return nothing
*/
function showContent()
@@ -100,7 +100,7 @@ class DocAction extends Action
/**
* Page title.
- *
+ *
* @return page title
*/
function title()
diff --git a/actions/editgroup.php b/actions/editgroup.php
index 98ebcb87a..e7e79040a 100644
--- a/actions/editgroup.php
+++ b/actions/editgroup.php
@@ -191,13 +191,13 @@ class EditgroupAction extends Action
array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
- } else if (!is_null($fullname) && strlen($fullname) > 255) {
+ } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
- } else if (!is_null($description) && strlen($description) > 140) {
+ } else if (!is_null($description) && mb_strlen($description) > 140) {
$this->showForm(_('description is too long (max 140 chars).'));
return;
- } else if (!is_null($location) && strlen($location) > 255) {
+ } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
}
diff --git a/actions/emailsettings.php b/actions/emailsettings.php
index b84acb214..634388fdd 100644
--- a/actions/emailsettings.php
+++ b/actions/emailsettings.php
@@ -164,6 +164,11 @@ class EmailsettingsAction extends AccountSettingsAction
$user->emailnotifymsg);
$this->elementEnd('li');
$this->elementStart('li');
+ $this->checkbox('emailnotifyattn',
+ _('Send me email when someone sends me an "@-reply".'),
+ $user->emailnotifyattn);
+ $this->elementEnd('li');
+ $this->elementStart('li');
$this->checkbox('emailnotifynudge',
_('Allow friends to nudge me and send me an email.'),
$user->emailnotifynudge);
@@ -255,6 +260,7 @@ class EmailsettingsAction extends AccountSettingsAction
$emailnotifyfav = $this->boolean('emailnotifyfav');
$emailnotifymsg = $this->boolean('emailnotifymsg');
$emailnotifynudge = $this->boolean('emailnotifynudge');
+ $emailnotifyattn = $this->boolean('emailnotifyattn');
$emailmicroid = $this->boolean('emailmicroid');
$emailpost = $this->boolean('emailpost');
@@ -270,6 +276,7 @@ class EmailsettingsAction extends AccountSettingsAction
$user->emailnotifyfav = $emailnotifyfav;
$user->emailnotifymsg = $emailnotifymsg;
$user->emailnotifynudge = $emailnotifynudge;
+ $user->emailnotifyattn = $emailnotifyattn;
$user->emailmicroid = $emailmicroid;
$user->emailpost = $emailpost;
diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php
index 3c872f94b..1302064ad 100644
--- a/actions/facebookinvite.php
+++ b/actions/facebookinvite.php
@@ -71,13 +71,13 @@ class FacebookinviteAction extends FacebookAction
common_config('site', 'name')));
$this->element('p', null, _('Invitations have been sent to the following users:'));
- $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to acces the list?
+ $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to access the list?
$this->elementStart('ul', array('id' => 'facebook-friends'));
foreach ($friend_ids as $friend) {
$this->elementStart('li');
- $this->element('fb:profile-pic', array('uid' => $friend));
+ $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
$this->element('fb:name', array('uid' => $friend,
'capitalize' => 'true'));
$this->elementEnd('li');
@@ -92,6 +92,12 @@ class FacebookinviteAction extends FacebookAction
// Get a list of users who are already using the app for exclusion
$exclude_ids = $this->facebook->api_client->friends_getAppUsers();
+ $exclude_ids_csv = null;
+
+ // fbml needs these as a csv string, not an array
+ if ($exclude_ids) {
+ $exclude_ids_csv = implode(',', $exclude_ids);
+ }
$content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
@@ -103,10 +109,17 @@ class FacebookinviteAction extends FacebookAction
'content' => $content));
$this->hidden('invite', 'true');
$actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
- $this->element('fb:multi-friend-selector', array('showborder' => 'false',
- 'actiontext' => $actiontext,
- 'exclude_ids' => implode(',', $exclude_ids),
- 'bypass' => 'cancel'));
+
+ $multi_params = array('showborder' => 'false');
+ $multi_params['actiontext'] = $actiontext;
+
+ if ($exclude_ids_csv) {
+ $multi_params['exclude_ids'] = $exclude_ids_csv;
+ }
+
+ $multi_params['bypass'] = 'cancel';
+
+ $this->element('fb:multi-friend-selector', $multi_params);
$this->elementEnd('fb:request-form');
diff --git a/actions/favorited.php b/actions/favorited.php
index fd5ff413c..5082f4a4e 100644
--- a/actions/favorited.php
+++ b/actions/favorited.php
@@ -169,8 +169,14 @@ class FavoritedAction extends Action
function showContent()
{
+ if (common_config('db', 'type') == 'pgsql') {
+ $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
+ } else {
+ $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
+ }
+
$qry = 'SELECT notice.*, '.
- 'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
+ $weightexpr . ' as weight ' .
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
'GROUP BY fave.notice_id ' .
'ORDER BY weight DESC';
diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php
index bc9151120..6d92cb9aa 100644
--- a/actions/finishopenidlogin.php
+++ b/actions/finishopenidlogin.php
@@ -83,7 +83,7 @@ class FinishopenidloginAction extends Action
function showContent()
{
- if ($this->message_text) {
+ if (!empty($this->message_text)) {
$this->element('p', null, $this->message);
return;
}
@@ -232,7 +232,8 @@ class FinishopenidloginAction extends Action
return;
}
- if ($sreg['country']) {
+ $location = '';
+ if (!empty($sreg['country'])) {
if ($sreg['postcode']) {
# XXX: use postcode to get city and region
# XXX: also, store postcode somewhere -- it's valuable!
@@ -242,12 +243,16 @@ class FinishopenidloginAction extends Action
}
}
- if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
+ if (!empty($sreg['fullname']) && mb_strlen($sreg['fullname']) <= 255) {
$fullname = $sreg['fullname'];
+ } else {
+ $fullname = '';
}
- if ($sreg['email'] && Validate::email($sreg['email'], true)) {
+ if (!empty($sreg['email']) && Validate::email($sreg['email'], true)) {
$email = $sreg['email'];
+ } else {
+ $email = '';
}
# XXX: add language
@@ -328,7 +333,7 @@ class FinishopenidloginAction extends Action
# Try the passed-in nickname
- if ($sreg['nickname']) {
+ if (!empty($sreg['nickname'])) {
$nickname = $this->nicknamize($sreg['nickname']);
if ($this->isNewNickname($nickname)) {
return $nickname;
@@ -337,7 +342,7 @@ class FinishopenidloginAction extends Action
# Try the full name
- if ($sreg['fullname']) {
+ if (!empty($sreg['fullname'])) {
$fullname = $this->nicknamize($sreg['fullname']);
if ($this->isNewNickname($fullname)) {
return $fullname;
diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php
index f9094a50c..acfacbdc1 100644
--- a/actions/finishremotesubscribe.php
+++ b/actions/finishremotesubscribe.php
@@ -237,7 +237,13 @@ class FinishremotesubscribeAction extends Action
{
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
copy($url, $temp_filename);
- return $profile->setOriginal($temp_filename);
+ $imagefile = new ImageFile($profile->id, $temp_filename);
+ $filename = Avatar::filename($profile->id,
+ image_type_to_extension($imagefile->type),
+ null,
+ common_timestamp());
+ rename($temp_filename, Avatar::path($filename));
+ return $profile->setOriginal($filename);
}
function access_token($omb)
@@ -277,7 +283,7 @@ class FinishremotesubscribeAction extends Action
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
$result = $fetcher->post($req->get_normalized_http_url(),
$req->to_postdata(),
- array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
+ array('User-Agent: Laconica/' . LACONICA_VERSION));
common_debug('got result: "'.print_r($result,true).'"', __FILE__);
diff --git a/actions/grouprss.php b/actions/grouprss.php
index 1a7b858b1..de76a5960 100644
--- a/actions/grouprss.php
+++ b/actions/grouprss.php
@@ -111,13 +111,13 @@ class groupRssAction extends Rss10Action
{
$group = $this->group;
-
+
if (is_null($group)) {
return null;
}
-
+
$notice = $group->getNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit);
-
+
while ($notice->fetch()) {
$notices[] = clone($notice);
}
@@ -141,13 +141,4 @@ class groupRssAction extends Rss10Action
{
return $this->group->homepage_logo;
}
-
- # override parent to add X-SUP-ID URL
-
- function initRss($limit=0)
- {
- $url = common_local_url('sup', null, $this->group->id);
- header('X-SUP-ID: '.$url);
- parent::initRss($limit);
- }
}
diff --git a/actions/login.php b/actions/login.php
index 71e467929..b049791fb 100644
--- a/actions/login.php
+++ b/actions/login.php
@@ -108,13 +108,15 @@ class LoginAction extends Action
$nickname = common_canonical_nickname($this->trimmed('nickname'));
$password = $this->arg('password');
- if (!common_check_user($nickname, $password)) {
+ $user = common_check_user($nickname, $password);
+
+ if (!$user) {
$this->showForm(_('Incorrect username or password.'));
return;
}
// success!
- if (!common_set_user($nickname)) {
+ if (!common_set_user($user)) {
$this->serverError(_('Error setting user.'));
return;
}
diff --git a/actions/newgroup.php b/actions/newgroup.php
index 42fd380df..cbd8dfeec 100644
--- a/actions/newgroup.php
+++ b/actions/newgroup.php
@@ -142,13 +142,13 @@ class NewgroupAction extends Action
array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
- } else if (!is_null($fullname) && strlen($fullname) > 255) {
+ } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
- } else if (!is_null($description) && strlen($description) > 140) {
+ } else if (!is_null($description) && mb_strlen($description) > 140) {
$this->showForm(_('description is too long (max 140 chars).'));
return;
- } else if (!is_null($location) && strlen($location) > 255) {
+ } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
}
diff --git a/actions/newmessage.php b/actions/newmessage.php
index f83015a37..82276ff34 100644
--- a/actions/newmessage.php
+++ b/actions/newmessage.php
@@ -201,7 +201,7 @@ class NewmessageAction extends Action
function showNoticeForm()
{
- $message_form = new MessageForm($this, $this->to, $this->content);
+ $message_form = new MessageForm($this, $this->other, $this->content);
$message_form->show();
}
}
diff --git a/actions/newnotice.php b/actions/newnotice.php
index 5e7691f33..cbd04c58b 100644
--- a/actions/newnotice.php
+++ b/actions/newnotice.php
@@ -98,7 +98,12 @@ class NewnoticeAction extends Action
return;
}
- $this->saveNewNotice();
+ try {
+ $this->saveNewNotice();
+ } catch (Exception $e) {
+ $this->showForm($e->getMessage());
+ return;
+ }
} else {
$this->showForm();
}
@@ -123,15 +128,13 @@ class NewnoticeAction extends Action
$content = $this->trimmed('status_textarea');
if (!$content) {
- $this->showForm(_('No content!'));
- return;
+ $this->clientError(_('No content!'));
} else {
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
- $this->showForm(_('That\'s too long. '.
- 'Max notice size is 140 chars.'));
- return;
+ $this->clientError(_('That\'s too long. '.
+ 'Max notice size is 140 chars.'));
}
}
@@ -149,12 +152,17 @@ class NewnoticeAction extends Action
}
$replyto = $this->trimmed('inreplyto');
+ #If an ID of 0 is wrongly passed here, it will cause a database error,
+ #so override it...
+ if ($replyto == 0) {
+ $replyto = 'false';
+ }
$notice = Notice::saveNew($user->id, $content, 'web', 1,
($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
- $this->showForm($notice);
+ $this->clientError($notice);
return;
}
@@ -250,7 +258,7 @@ class NewnoticeAction extends Action
}
}
- $notice_form = new NoticeForm($this, $content);
+ $notice_form = new NoticeForm($this, '', $content);
$notice_form->show();
}
diff --git a/actions/noticesearch.php b/actions/noticesearch.php
index a5f01350c..83e59dd9a 100644
--- a/actions/noticesearch.php
+++ b/actions/noticesearch.php
@@ -57,11 +57,11 @@ class NoticesearchAction extends SearchAction
return true;
}
-
+
/**
* Get instructions
- *
- * @return string instruction text
+ *
+ * @return string instruction text
*/
function getInstructions()
{
@@ -70,7 +70,7 @@ class NoticesearchAction extends SearchAction
/**
* Get title
- *
+ *
* @return string title
*/
function title()
@@ -78,6 +78,20 @@ class NoticesearchAction extends SearchAction
return _('Text search');
}
+ function getFeeds()
+ {
+ $q = $this->trimmed('q');
+
+ if (!$q) {
+ return null;
+ }
+
+ return array(new Feed(Feed::RSS1, common_local_url('noticesearchrss',
+ array('q' => $q)),
+ sprintf(_('Search results for "%s" on %s'),
+ $q, common_config('site', 'name'))));
+ }
+
/**
* Show results
*
@@ -99,143 +113,58 @@ class NoticesearchAction extends SearchAction
} else {
$cnt = $notice->find();
}
- if ($cnt > 0) {
- $terms = preg_split('/[\s,]+/', $q);
- $this->elementStart('ul', array('class' => 'notices'));
- for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
- if ($notice->fetch()) {
- $this->showNotice($notice, $terms);
- } else {
- // shouldn't happen!
- break;
- }
- }
- $this->elementEnd('ul');
- } else {
+ if ($cnt === 0) {
$this->element('p', 'error', _('No results'));
+ return;
}
+ $terms = preg_split('/[\s,]+/', $q);
+ $nl = new SearchNoticeList($notice, $this, $terms);
- $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'noticesearch', array('q' => $q));
- }
+ $cnt = $nl->show();
- /**
- * Show header
- *
- * @param array $arr array containing the query
- *
- * @return void
- */
+ $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
+ $this->page, 'noticesearch', array('q' => $q));
+ }
+ function isReadOnly()
+ {
+ return true;
+ }
+}
- function extraHead()
+class SearchNoticeList extends NoticeList {
+ function __construct($notice, $out=null, $terms)
{
- $q = $this->trimmed('q');
- if ($q) {
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('noticesearchrss',
- array('q' => $q)),
- 'type' => 'application/rss+xml',
- 'title' => _('Search Stream Feed')));
- }
+ parent::__construct($notice, $out);
+ $this->terms = $terms;
}
- /**
- * Show notice
- *
- * @param class $notice notice
- * @param array $terms terms to highlight
- *
- * @return void
- *
- * @todo refactor and combine with StreamAction::showNotice()
- */
- function showNotice($notice, $terms)
+ function newListItem($notice)
{
- $profile = $notice->getProfile();
- if (!$profile) {
- common_log_db_error($notice, 'SELECT', __FILE__);
- $this->serverError(_('Notice without matching profile'));
- return;
- }
- // XXX: RDFa
- $this->elementStart('li', array('class' => 'hentry notice',
- 'id' => 'notice-' . $notice->id));
+ return new SearchNoticeListItem($notice, $this->out, $this->terms);
+ }
+}
- $this->elementStart('div', 'entry-title');
- $this->elementStart('span', 'vcard author');
- $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
- $this->elementStart('a', array('href' => $profile->profileurl,
- 'class' => 'url'));
- $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
- 'class' => 'avatar photo',
- 'width' => AVATAR_STREAM_SIZE,
- 'height' => AVATAR_STREAM_SIZE,
- 'alt' =>
- ($profile->fullname) ? $profile->fullname :
- $profile->nickname));
- $this->element('span', 'nickname fn', $profile->nickname);
- $this->elementEnd('a');
- $this->elementEnd('span');
+class SearchNoticeListItem extends NoticeListItem {
+ function __construct($notice, $out=null, $terms)
+ {
+ parent::__construct($notice, $out);
+ $this->terms = $terms;
+ }
+ function showContent()
+ {
// FIXME: URL, image, video, audio
- $this->elementStart('p', array('class' => 'entry-content'));
- if ($notice->rendered) {
- $this->raw($this->highlight($notice->rendered, $terms));
+ $this->out->elementStart('p', array('class' => 'entry-content'));
+ if ($this->notice->rendered) {
+ $this->out->raw($this->highlight($this->notice->rendered, $this->terms));
} else {
// XXX: may be some uncooked notices in the DB,
// we cook them right now. This should probably disappear in future
// versions (>> 0.4.x)
- $this->raw($this->highlight(common_render_content($notice->content, $notice), $terms));
- }
- $this->elementEnd('p');
- $this->elementEnd('div');
-
- $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
- $this->elementStart('div', 'entry-content');
- $this->elementStart('dl', 'timestamp');
- $this->element('dt', null, _('Published'));
- $this->elementStart('dd', null);
- $this->elementStart('a', array('rel' => 'bookmark',
- 'href' => $noticeurl));
- $dt = common_date_iso8601($notice->created);
- $this->element('abbr', array('class' => 'published',
- 'title' => $dt),
- common_date_string($notice->created));
- $this->elementEnd('a');
- $this->elementEnd('dd');
- $this->elementEnd('dl');
-
- if ($notice->reply_to) {
- $replyurl = common_local_url('shownotice',
- array('notice' => $this->notice->reply_to));
- $this->elementStart('dl', 'response');
- $this->element('dt', null, _('To'));
- $this->elementStart('dd');
- $this->element('a', array('href' => $replyurl,
- 'rel' => 'in-reply-to'),
- _('in reply to'));
- $this->elementEnd('dd');
- $this->elementEnd('dl');
+ $this->out->raw($this->highlight(common_render_content($this->notice->content, $this->notice), $this->terms));
}
- $this->elementEnd('div');
-
- $this->elementStart('div', 'notice-options');
+ $this->out->elementEnd('p');
- $reply_url = common_local_url('newnotice',
- array('replyto' => $profile->nickname));
-
- $this->elementStart('dl', 'notice_reply');
- $this->element('dt', null, _('Reply to this notice'));
- $this->elementStart('dd');
- $this->elementStart('a', array('href' => $reply_url,
- 'title' => _('Reply to this notice')));
- $this->text(_('Reply'));
- $this->element('span', 'notice_id', $notice->id);
- $this->elementEnd('a');
- $this->elementEnd('dd');
- $this->elementEnd('dl');
- $this->elementEnd('div');
- $this->elementEnd('li');
}
/**
@@ -248,7 +177,7 @@ class NoticesearchAction extends SearchAction
*/
function highlight($text, $terms)
{
- /* Highligh serach terms */
+ /* Highligh search terms */
$pattern = '/('.implode('|', array_map('htmlspecialchars', $terms)).')/i';
$result = preg_replace($pattern, '<strong>\\1</strong>', $text);
@@ -259,10 +188,5 @@ class NoticesearchAction extends SearchAction
} while ($count);
return $result;
}
-
- function isReadOnly()
- {
- return true;
- }
}
diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php
index 615201c46..14177fcf0 100644
--- a/actions/peoplesearch.php
+++ b/actions/peoplesearch.php
@@ -86,33 +86,9 @@ class PeoplesearchAction extends SearchAction
}
$profile->free();
-
+
$this->pagination($page > 1, $cnt > PROFILES_PER_PAGE,
$page, 'peoplesearch', array('q' => $q));
}
}
-class PeopleSearchResults extends ProfileList
-{
- var $terms = null;
- var $pattern = null;
-
- function __construct($profile, $terms, $action)
- {
- parent::__construct($profile, $terms, $action);
- $this->terms = array_map('preg_quote',
- array_map('htmlspecialchars', $terms));
- $this->pattern = '/('.implode('|',$terms).')/i';
- }
-
- function highlight($text)
- {
- return preg_replace($this->pattern, '<strong>\\1</strong>', htmlspecialchars($text));
- }
-
- function isReadOnly()
- {
- return true;
- }
-}
-
diff --git a/actions/peopletag.php b/actions/peopletag.php
index 3578c53fd..6b1e34f1a 100644
--- a/actions/peopletag.php
+++ b/actions/peopletag.php
@@ -1,9 +1,12 @@
<?php
-/*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+/**
+ * Laconica, the distributed open-source microblogging tool
*
- * This program is free software: you can redistribute it and/or modify
+ * Action for showing profiles self-tagged with a given tag
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
@@ -15,78 +18,131 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Action
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
*/
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('LACONICA')) {
+ exit(1);
+}
require_once INSTALLDIR.'/lib/profilelist.php';
+/**
+ * This class outputs a paginated list of profiles self-tagged with a given tag
+ *
+ * @category Output
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @see Action
+ */
+
class PeopletagAction extends Action
{
-
- var $tag = null;
+
+ var $tag = null;
var $page = null;
-
- function handle($args)
+
+ /**
+ * For initializing members of the class.
+ *
+ * @param array $argarray misc. arguments
+ *
+ * @return boolean true
+ */
+ function prepare($argarray)
{
- parent::handle($args);
-
- parent::prepare($args);
+ parent::prepare($argarray);
$this->tag = $this->trimmed('tag');
if (!common_valid_profile_tag($this->tag)) {
- $this->clientError(sprintf(_('Not a valid people tag: %s'), $this->tag));
+ $this->clientError(sprintf(_('Not a valid people tag: %s'),
+ $this->tag));
return;
}
- $this->page = $this->trimmed('page');
+ $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
- if (!$this->page) {
- $this->page = 1;
- }
-
+ common_set_returnto($this->selfUrl());
+
+ return true;
+ }
+
+ /**
+ * Handler method
+ *
+ * @param array $argarray is ignored since it's now passed in in prepare()
+ *
+ * @return boolean is read only action?
+ */
+ function handle($argarray)
+ {
+ parent::handle($argarray);
$this->showPage();
}
-
+
+ /**
+ * Whips up a query to get a list of profiles based on the provided
+ * people tag and page, initalizes a ProfileList widget, and displays
+ * it to the user.
+ *
+ * @return nothing
+ */
function showContent()
{
-
+
$profile = new Profile();
- $offset = ($page-1)*PROFILES_PER_PAGE;
- $limit = PROFILES_PER_PAGE + 1;
-
- if (common_config('db','type') == 'pgsql') {
+ $offset = ($this->page - 1) * PROFILES_PER_PAGE;
+ $limit = PROFILES_PER_PAGE + 1;
+
+ if (common_config('db', 'type') == 'pgsql') {
$lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else {
$lim = ' LIMIT ' . $offset . ', ' . $limit;
}
- # XXX: memcached this
-
+ // XXX: memcached this
+
$qry = 'SELECT profile.* ' .
'FROM profile JOIN profile_tag ' .
'ON profile.id = profile_tag.tagger ' .
'WHERE profile_tag.tagger = profile_tag.tagged ' .
'AND tag = "%s" ' .
- 'ORDER BY profile_tag.modified DESC';
-
+ 'ORDER BY profile_tag.modified DESC%s';
+
$profile->query(sprintf($qry, $this->tag, $lim));
- $pl = new ProfileList($profile, null, $this);
+ $pl = new ProfileList($profile, null, $this);
$cnt = $pl->show();
-
+
$this->pagination($this->page > 1,
$cnt > PROFILES_PER_PAGE,
$this->page,
- $this->trimmed('action'),
+ 'peopletag',
array('tag' => $this->tag));
}
-
- function title()
+
+ /**
+ * Returns the page title
+ *
+ * @return string page title
+ */
+ function title()
{
- return sprintf( _('Users self-tagged with %s - page %d'), $this->tag, $this->page);
+ return sprintf(_('Users self-tagged with %s - page %d'),
+ $this->tag, $this->page);
}
-
+
}
diff --git a/actions/profilesettings.php b/actions/profilesettings.php
index 82e6c3c82..60f7c0796 100644
--- a/actions/profilesettings.php
+++ b/actions/profilesettings.php
@@ -198,13 +198,13 @@ class ProfilesettingsAction extends AccountSettingsAction
!Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
- } else if (!is_null($fullname) && strlen($fullname) > 255) {
+ } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
- } else if (!is_null($bio) && strlen($bio) > 140) {
+ } else if (!is_null($bio) && mb_strlen($bio) > 140) {
$this->showForm(_('Bio is too long (max 140 chars).'));
return;
- } else if (!is_null($location) && strlen($location) > 255) {
+ } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
} else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
diff --git a/actions/public.php b/actions/public.php
index cc6537f74..a20ae4032 100644
--- a/actions/public.php
+++ b/actions/public.php
@@ -73,9 +73,9 @@ class PublicAction extends Action
{
parent::prepare($args);
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -119,12 +119,20 @@ class PublicAction extends Action
* @return void
*/
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('publicrss'),
- 'type' => 'application/rss+xml',
- 'title' => _('Public Stream Feed')));
+ return array(new Feed(Feed::RSS1, common_local_url('publicrss'),
+ _('Public Stream Feed (RSS 1.0)')),
+ new Feed(Feed::RSS2,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'public_timeline.rss')),
+ _('Public Stream Feed (RSS 2.0)')),
+ new Feed(Feed::ATOM,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'public_timeline.atom')),
+ _('Public Stream Feed (Atom)')));
}
/**
@@ -185,27 +193,6 @@ class PublicAction extends Action
$this->page, 'public');
}
- /**
- * Makes a list of exported feeds for this page
- *
- * @return void
- *
- * @todo I18N
- */
-
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0 => array('href' => common_local_url('publicrss'),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'publicrss'),
- 1 => array('href' => common_local_url('publicatom'),
- 'type' => 'atom',
- 'version' => 'Atom 1.0',
- 'item' => 'publicatom')));
- }
-
function showSections()
{
// $top = new TopPostersSection($this);
diff --git a/actions/register.php b/actions/register.php
index 01d94f488..5d7a8ce69 100644
--- a/actions/register.php
+++ b/actions/register.php
@@ -167,13 +167,13 @@ class RegisterAction extends Action
array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.'));
return;
- } else if (!is_null($fullname) && strlen($fullname) > 255) {
+ } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).'));
return;
- } else if (!is_null($bio) && strlen($bio) > 140) {
+ } else if (!is_null($bio) && mb_strlen($bio) > 140) {
$this->showForm(_('Bio is too long (max 140 chars).'));
return;
- } else if (!is_null($location) && strlen($location) > 255) {
+ } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).'));
return;
} else if (strlen($password) < 6) {
diff --git a/actions/remotesubscribe.php b/actions/remotesubscribe.php
index f727a63b8..7ea7acd6d 100644
--- a/actions/remotesubscribe.php
+++ b/actions/remotesubscribe.php
@@ -321,8 +321,7 @@ class RemotesubscribeAction extends Action
$result = $fetcher->post($req->get_normalized_http_url(),
$req->to_postdata(),
- array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
-
+ array('User-Agent: Laconica/' . LACONICA_VERSION));
if ($result->status != 200) {
return null;
}
diff --git a/actions/replies.php b/actions/replies.php
index 7eff74a66..4ab9b14ed 100644
--- a/actions/replies.php
+++ b/actions/replies.php
@@ -84,7 +84,7 @@ class RepliesAction extends Action
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -129,16 +129,13 @@ class RepliesAction extends Action
* @return void
*/
- function showFeeds()
+ function getFeeds()
{
$rssurl = common_local_url('repliesrss',
array('nickname' => $this->user->nickname));
$rsstitle = sprintf(_('Feed for replies to %s'), $this->user->nickname);
- $this->element('link', array('rel' => 'alternate',
- 'href' => $rssurl,
- 'type' => 'application/rss+xml',
- 'title' => $rsstitle));
+ return array(new Feed(Feed::RSS1, $rssurl, $rsstitle));
}
/**
@@ -154,25 +151,6 @@ class RepliesAction extends Action
}
/**
- * Show the replies feed links
- *
- * @return void
- */
-
- function showExportData()
- {
- $fl = new FeedList($this);
-
- $rssurl = common_local_url('repliesrss',
- array('nickname' => $this->user->nickname));
-
- $fl->show(array(0=>array('href'=> $rssurl,
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'repliesrss')));
- }
-
- /**
* Show the content
*
* A list of notices that are replies to the user, plus pagination.
diff --git a/actions/showfavorites.php b/actions/showfavorites.php
index 31479e1a7..d1c9283f0 100644
--- a/actions/showfavorites.php
+++ b/actions/showfavorites.php
@@ -113,7 +113,7 @@ class ShowfavoritesAction extends Action
}
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -136,10 +136,10 @@ class ShowfavoritesAction extends Action
/**
* Feeds for the <head> section
*
- * @return void
+ * @return array Feed objects to show
*/
- function showFeeds()
+ function getFeeds()
{
$feedurl = common_local_url('favoritesrss',
array('nickname' =>
@@ -147,10 +147,7 @@ class ShowfavoritesAction extends Action
$feedtitle = sprintf(_('Feed for favorites of %s'),
$this->user->nickname);
- $this->element('link', array('rel' => 'alternate',
- 'href' => $feedurl,
- 'type' => 'application/rss+xml',
- 'title' => $feedtitle));
+ return array(new Feed(Feed::RSS1, $feedurl, $feedtitle));
}
/**
@@ -166,28 +163,6 @@ class ShowfavoritesAction extends Action
}
/**
- * Show the replies feed links
- *
- * @return void
- */
-
- function showExportData()
- {
- $feedurl = common_local_url('favoritesrss',
- array('nickname' =>
- $this->user->nickname));
-
- $fl = new FeedList($this);
-
- // XXX: I18N
-
- $fl->show(array(0=>array('href'=> $feedurl,
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'Favorites')));
- }
-
- /**
* Show the content
*
* A list of notices that this user has marked as a favorite
diff --git a/actions/showgroup.php b/actions/showgroup.php
index 7bc68fbc6..c20941a35 100644
--- a/actions/showgroup.php
+++ b/actions/showgroup.php
@@ -244,7 +244,7 @@ class ShowgroupAction extends Action
if ($this->group->location) {
$this->elementStart('dl', 'entity_location');
$this->element('dt', null, _('Location'));
- $this->element('dd', 'location', $this->group->location);
+ $this->element('dd', 'label', $this->group->location);
$this->elementEnd('dl');
}
@@ -292,37 +292,18 @@ class ShowgroupAction extends Action
}
/**
- * Show a list of links to feeds this page produces
+ * Get a list of the feeds for this page
*
* @return void
*/
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('grouprss',
- array('nickname' => $this->group->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'notices')));
- }
-
- /**
- * Show a list of links to feeds this page produces
- *
- * @return void
- */
-
- function showFeeds()
+ function getFeeds()
{
$url =
common_local_url('grouprss',
array('nickname' => $this->group->nickname));
- $this->element('link', array('rel' => 'alternate',
- 'href' => $url,
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Notice feed for %s group'),
+ return array(new Feed(Feed::RSS1, $url, sprintf(_('Notice feed for %s group'),
$this->group->nickname)));
}
diff --git a/actions/showstream.php b/actions/showstream.php
index 28bb8453f..65482167e 100644
--- a/actions/showstream.php
+++ b/actions/showstream.php
@@ -111,7 +111,7 @@ class ShowstreamAction extends Action
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -155,58 +155,39 @@ class ShowstreamAction extends Action
return;
}
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('userrss',
- array('nickname' => $this->user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'notices'),
- 1=>array('href'=>common_local_url('usertimeline',
- array('nickname' => $this->user->nickname)),
- 'type' => 'atom',
- 'version' => 'Atom 1.0',
- 'item' => 'usertimeline'),
- 2=>array('href'=>common_local_url('foaf',
- array('nickname' => $this->user->nickname)),
- 'type' => 'rdf',
- 'version' => 'FOAF',
- 'item' => 'foaf')));
- }
-
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'type' => 'application/rss+xml',
- 'href' => common_local_url('userrss',
- array('nickname' => $this->user->nickname)),
- 'title' => sprintf(_('Notice feed for %s (RSS)'),
- $this->user->nickname)));
-
- $this->element('link',
- array('rel' => 'alternate',
- 'href' => common_local_url('api',
- array('apiaction' => 'statuses',
- 'method' => 'user_timeline.atom',
- 'argument' => $this->user->nickname)),
- 'type' => 'application/atom+xml',
- 'title' => sprintf(_('Notice feed for %s (Atom)'),
- $this->user->nickname)));
+ return array(new Feed(Feed::RSS1,
+ common_local_url('userrss',
+ array('nickname' => $this->user->nickname)),
+ sprintf(_('Notice feed for %s (RSS 1.0)'),
+ $this->user->nickname)),
+ new Feed(Feed::RSS2,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'user_timeline',
+ 'argument' => $this->user->nickname.'.rss')),
+ sprintf(_('Notice feed for %s (RSS 2.0)'),
+ $this->user->nickname)),
+ new Feed(Feed::ATOM,
+ common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'user_timeline',
+ 'argument' => $this->user->nickname.'.atom')),
+ sprintf(_('Notice feed for %s (Atom)'),
+ $this->user->nickname)),
+ new Feed(Feed::FOAF,
+ common_local_url('foaf', array('nickname' =>
+ $this->user->nickname)),
+ sprintf(_('FOAF for %s'), $this->user->nickname)));
}
function extraHead()
{
- // FOAF
- $this->element('link', array('rel' => 'meta',
- 'href' => common_local_url('foaf', array('nickname' =>
- $this->user->nickname)),
- 'type' => 'application/rdf+xml',
- 'title' => 'FOAF'));
// for remote subscriptions etc.
$this->element('meta', array('http-equiv' => 'X-XRDS-Location',
'content' => common_local_url('xrds', array('nickname' =>
- $this->user->nickname))));
+ $this->user->nickname))));
if ($this->profile->bio) {
$this->element('meta', array('name' => 'description',
@@ -248,6 +229,15 @@ class ShowstreamAction extends Action
'height' => AVATAR_PROFILE_SIZE,
'alt' => $this->profile->nickname));
$this->elementEnd('dd');
+
+ $user = User::staticGet('id', $this->profile->id);
+ $cur = common_current_user();
+ if ($cur && $cur->id == $user->id) {
+ $this->elementStart('dd');
+ $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
+ $this->elementEnd('dd');
+ }
+
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_nickname');
@@ -256,7 +246,7 @@ class ShowstreamAction extends Action
$hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
$this->element('a', array('href' => $this->profile->profileurl,
'rel' => 'me', 'class' => $hasFN),
- $this->profile->nickname);
+ $this->profile->nickname);
$this->elementEnd('dd');
$this->elementEnd('dl');
@@ -272,7 +262,7 @@ class ShowstreamAction extends Action
if ($this->profile->location) {
$this->elementStart('dl', 'entity_location');
$this->element('dt', null, _('Location'));
- $this->element('dd', 'location', $this->profile->location);
+ $this->element('dd', 'label', $this->profile->location);
$this->elementEnd('dl');
}
@@ -302,11 +292,11 @@ class ShowstreamAction extends Action
$this->elementStart('ul', 'tags xoxo');
foreach ($tags as $tag) {
$this->elementStart('li');
- $this->element('span', 'mark_hash', '#');
- $this->element('a', array('rel' => 'tag',
- 'href' => common_local_url('peopletag',
- array('tag' => $tag))),
- $tag);
+ // Avoid space by using raw output.
+ $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
+ common_local_url('peopletag', array('tag' => $tag)) .
+ '">' . $tag . '</a>';
+ $this->raw($pt);
$this->elementEnd('li');
}
$this->elementEnd('ul');
@@ -324,7 +314,7 @@ class ShowstreamAction extends Action
$this->elementStart('li', 'entity_edit');
$this->element('a', array('href' => common_local_url('profilesettings'),
'title' => _('Edit profile settings')),
- _('Edit'));
+ _('Edit'));
$this->elementEnd('li');
}
@@ -346,9 +336,8 @@ class ShowstreamAction extends Action
$this->elementEnd('li');
}
- $user = User::staticGet('id', $this->profile->id);
if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
- $this->elementStart('li', 'entity_send-a-message');
+ $this->elementStart('li', 'entity_send-a-message');
$this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
'title' => _('Send a direct message to this user')),
_('Message'));
@@ -490,7 +479,7 @@ class ShowstreamAction extends Action
$this->elementStart('dl', 'entity_member-since');
$this->element('dt', null, _('Member since'));
$this->element('dd', null, date('j M Y',
- strtotime($this->profile->created)));
+ strtotime($this->profile->created)));
$this->elementEnd('dl');
$this->elementStart('dl', 'entity_subscriptions');
diff --git a/actions/tag.php b/actions/tag.php
index 4401f892a..231f2c299 100644
--- a/actions/tag.php
+++ b/actions/tag.php
@@ -37,9 +37,9 @@ class TagAction extends Action
}
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
+
common_set_returnto($this->selfUrl());
-
+
return true;
}
@@ -61,12 +61,11 @@ class TagAction extends Action
$this->showPage();
}
- function showFeeds()
+ function getFeeds()
{
- $this->element('link', array('rel' => 'alternate',
- 'href' => common_local_url('tagrss', array('tag' => $this->tag)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for tag %s'), $this->tag)));
+ return array(new Feed(Feed::RSS1,
+ common_local_url('tagrss', array('tag' => $this->tag)),
+ sprintf(_('Feed for tag %s'), $this->tag)));
}
function showPageNotice()
@@ -74,15 +73,6 @@ class TagAction extends Action
return sprintf(_('Messages tagged "%s", most recent first'), $this->tag);
}
- function showExportData()
- {
- $fl = new FeedList($this);
- $fl->show(array(0=>array('href'=>common_local_url('tagrss', array('tag' => $this->tag)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'tagrss')));
- }
-
function showContent()
{
$notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
diff --git a/actions/tagother.php b/actions/tagother.php
index 3e8a12fd6..0d18945a0 100644
--- a/actions/tagother.php
+++ b/actions/tagother.php
@@ -110,7 +110,7 @@ class TagotherAction extends Action
if ($this->profile->location) {
$this->elementStart('dl', 'entity_location');
$this->element('dt', null, _('Location'));
- $this->element('dd', 'location', $this->profile->location);
+ $this->element('dd', 'label', $this->profile->location);
$this->elementEnd('dl');
}
if ($this->profile->homepage) {
@@ -135,7 +135,8 @@ class TagotherAction extends Action
'id' => 'form_tag_user',
'class' => 'form_settings',
'name' => 'tagother',
- 'action' => $this->selfUrl()));
+ 'action' => common_local_url('tagother', array('id' => $this->profile->id))));
+
$this->elementStart('fieldset');
$this->element('legend', null, _('Tag user'));
$this->hidden('token', common_session_token());
diff --git a/actions/twitapiaccount.php b/actions/twitapiaccount.php
index dc8e2e798..68a18cb57 100644
--- a/actions/twitapiaccount.php
+++ b/actions/twitapiaccount.php
@@ -23,23 +23,24 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiaccountAction extends TwitterapiAction
{
-
- function verify_credentials($args, $apidata)
+ function verify_credentials($args, $apidata)
{
+ parent::handle($args);
- if ($apidata['content-type'] == 'xml') {
- header('Content-Type: application/xml; charset=utf-8');
- print '<authorized>true</authorized>';
- } elseif ($apidata['content-type'] == 'json') {
- header('Content-Type: application/json; charset=utf-8');
- print '{"authorized":true}';
- } else {
- common_user_error(_('API method not found!'), $code=404);
- }
-
- }
+ switch ($apidata['content-type']) {
+ case 'xml':
+ case 'json':
+ $action_obj = new TwitapiusersAction();
+ $action_obj->prepare($args);
+ call_user_func(array($action_obj, 'show'), $args, $apidata);
+ break;
+ default:
+ header('Content-Type: text/html; charset=utf-8');
+ print 'Authorized';
+ }
+ }
- function end_session($args, $apidata)
+ function end_session($args, $apidata)
{
parent::handle($args);
$this->serverError(_('API method under construction.'), $code=501);
@@ -56,7 +57,7 @@ class TwitapiaccountAction extends TwitterapiAction
$location = trim($this->arg('location'));
- if (!is_null($location) && strlen($location) > 255) {
+ if (!is_null($location) && mb_strlen($location) > 255) {
// XXX: But Twitter just truncates and runs with it. -- Zach
$this->clientError(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']);
diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php
new file mode 100644
index 000000000..3ab82bfb6
--- /dev/null
+++ b/actions/twitapisearchatom.php
@@ -0,0 +1,368 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Action for showing Twitter-like Atom search results
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/twitterapi.php';
+
+/**
+ * Action for outputting search results in Twitter compatible Atom
+ * format.
+ *
+ * TODO: abstract Atom stuff into a ruseable base class like
+ * RSS10Action.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @see TwitterapiAction
+ */
+
+class TwitapisearchatomAction extends TwitterapiAction
+{
+
+ var $notices;
+ var $cnt;
+ var $query;
+ var $lang;
+ var $rpp;
+ var $page;
+ var $since_id;
+ var $geocode;
+
+ /**
+ * Constructor
+ *
+ * Just wraps the Action constructor.
+ *
+ * @param string $output URI to output to, default = stdout
+ * @param boolean $indent Whether to indent output, default true
+ *
+ * @see Action::__construct
+ */
+
+ function __construct($output='php://output', $indent=true)
+ {
+ parent::__construct($output, $indent);
+ }
+
+ /**
+ * Do we need to write to the database?
+ *
+ * @return boolean true
+ */
+
+ function isReadonly()
+ {
+ return true;
+ }
+
+ /**
+ * Read arguments and initialize members
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return boolean success
+ *
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $this->query = $this->trimmed('q');
+ $this->lang = $this->trimmed('lang');
+ $this->rpp = $this->trimmed('rpp');
+
+ if (!$this->rpp) {
+ $this->rpp = 15;
+ }
+
+ if ($this->rpp > 100) {
+ $this->rpp = 100;
+ }
+
+ $this->page = $this->trimmed('page');
+
+ if (!$this->page) {
+ $this->page = 1;
+ }
+
+ // TODO: Suppport since_id -- we need to tweak the backend
+ // Search classes to support it.
+
+ $this->since_id = $this->trimmed('since_id');
+ $this->geocode = $this->trimmed('geocode');
+
+ // TODO: Also, language and geocode
+
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showAtom();
+ }
+
+ /**
+ * Get the notices to output as results. This also sets some class
+ * attrs so we can use them to calculate pagination, and output
+ * since_id and max_id.
+ *
+ * @return array an array of Notice objects sorted in reverse chron
+ */
+
+ function getNotices()
+ {
+ // TODO: Support search operators like from: and to:, boolean, etc.
+
+ $notice = new Notice();
+
+ // lcase it for comparison
+ $q = strtolower($this->query);
+
+ $search_engine = $notice->getSearchEngine('identica_notices');
+ $search_engine->set_sort_mode('chron');
+ $search_engine->limit(($this->page - 1) * $this->rpp,
+ $this->rpp + 1, true);
+ $search_engine->query($q);
+ $this->cnt = $notice->find();
+
+ $cnt = 0;
+
+ while ($notice->fetch()) {
+
+ ++$cnt;
+
+ if (!$this->max_id) {
+ $this->max_id = $notice->id;
+ }
+
+ if ($cnt > $this->rpp) {
+ break;
+ }
+
+ $notices[] = clone($notice);
+ }
+
+ return $notices;
+ }
+
+ /**
+ * Output search results as an Atom feed
+ *
+ * @return void
+ */
+
+ function showAtom()
+ {
+ $notices = $this->getNotices();
+
+ $this->initAtom();
+ $this->showFeed();
+
+ foreach ($notices as $n) {
+ $this->showEntry($n);
+ }
+
+ $this->endAtom();
+ }
+
+ /**
+ * Show feed specific Atom elements
+ *
+ * @return void
+ */
+
+ function showFeed()
+ {
+ // TODO: A9 OpenSearch stuff like search.twitter.com?
+
+ $lang = common_config('site', 'language');
+ $server = common_config('site', 'server');
+ $sitename = common_config('site', 'name');
+
+ // XXX: Use xmlns:laconica instead?
+
+ $this->elementStart('feed',
+ array('xmlns' => 'http://www.w3.org/2005/Atom',
+ 'xmlns:twitter' => 'http://api.twitter.com/',
+ 'xml:lang' => $lang));
+
+ $year = date('Y');
+ $this->element('id', null, "tag:$server,$year:search/$server");
+
+ $site_uri = common_path(false);
+
+ $search_uri = $site_uri . 'api/search.atom?q=' . urlencode($this->query);
+
+ if ($this->rpp != 15) {
+ $search_uri .= '&rpp=' . $this->rpp;
+ }
+
+ // FIXME: this alternate link is not quite right because our
+ // web-based notice search doesn't support a rpp (responses per
+ // page) param yet
+
+ $this->element('link', array('type' => 'text/html',
+ 'rel' => 'alternate',
+ 'href' => $site_uri . 'search/notice?q=' .
+ urlencode($this->query)));
+
+ // self link
+
+ $self_uri = $search_uri . '&page=' . $this->page;
+
+ $this->element('link', array('type' => 'application/atom+xml',
+ 'rel' => 'self',
+ 'href' => $self_uri));
+
+ $this->element('title', null, "$this->query - $sitename Search");
+
+ // refresh link
+
+ $refresh_uri = $search_uri . "&since_id=" . $this->max_id;
+
+ $this->element('link', array('type' => 'application/atom+xml',
+ 'rel' => 'refresh',
+ 'href' => $refresh_uri));
+
+ // pagination links
+
+ if ($this->cnt > $this->rpp) {
+
+ $next_uri = $search_uri . "&max_id=" . $this->max_id .
+ '&page=' . ($this->page + 1);
+
+ $this->element('link', array('type' => 'application/atom+xml',
+ 'rel' => 'next',
+ 'href' => $next_uri));
+ }
+
+ if ($this->page > 1) {
+
+ $previous_uri = $search_uri . "&max_id=" . $this->max_id .
+ '&page=' . ($this->page - 1);
+
+ $this->element('link', array('type' => 'application/atom+xml',
+ 'rel' => 'previous',
+ 'href' => $previous_uri));
+ }
+
+ }
+
+ /**
+ * Build an Atom entry similar to search.twitter.com's based on
+ * a given notice
+ *
+ * @param Notice $notice the notice to use
+ *
+ * @return void
+ */
+
+ function showEntry($notice)
+ {
+ $server = common_config('site', 'server');
+ $profile = $notice->getProfile();
+ $nurl = common_local_url('shownotice', array('notice' => $notice->id));
+
+ $this->elementStart('entry');
+
+ $year = date('Y', strtotime($notice->created));
+
+ $this->element('id', null, "tag:$server,$year:$notice->id");
+ $this->element('published', null, common_date_w3dtf($notice->created));
+ $this->element('link', array('type' => 'text/html',
+ 'rel' => 'alternate',
+ 'href' => $nurl));
+ $this->element('title', null, common_xml_safe_str(trim($notice->content)));
+ $this->element('content', array('type' => 'text/html'), $notice->rendered);
+ $this->element('updated', null, common_date_w3dtf($notice->created));
+ $this->element('link', array('type' => 'image/png',
+ 'rel' => 'image',
+ 'href' => $profile->avatarUrl()));
+
+ // TODO: Here is where we'd put in a link to an atom feed for threads
+
+ $this->element("twitter:source", null,
+ htmlentities($this->source_link($notice->source)));
+
+ $this->elementStart('author');
+
+ $name = $profile->nickname;
+
+ if ($profile->fullname) {
+ $name .= ' (' . $profile->fullname . ')';
+ }
+
+ $this->element('name', null, $name);
+ $this->element('uri', null, common_profile_uri($profile));
+ $this->elementEnd('author');
+
+ $this->elementEnd('entry');
+ }
+
+ /**
+ * Initialize the Atom output, send headers
+ *
+ * @return void
+ */
+
+ function initAtom()
+ {
+ header('Content-Type: application/atom+xml; charset=utf-8');
+ $this->startXml();
+ }
+
+ /**
+ * End the Atom feed
+ *
+ * @return void
+ */
+
+ function endAtom()
+ {
+ $this->elementEnd('feed');
+ }
+
+}
diff --git a/actions/twitapisearchjson.php b/actions/twitapisearchjson.php
new file mode 100644
index 000000000..0f9f523a1
--- /dev/null
+++ b/actions/twitapisearchjson.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Action for showing Twitter-like JSON search results
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/twitterapi.php';
+require_once INSTALLDIR.'/lib/jsonsearchresultslist.php';
+
+/**
+ * Action handler for Twitter-compatible API search
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ * @see TwitterapiAction
+ */
+
+class TwitapisearchjsonAction extends TwitterapiAction
+{
+ var $query;
+ var $lang;
+ var $rpp;
+ var $page;
+ var $since_id;
+ var $limit;
+ var $geocode;
+
+ /**
+ * Initialization.
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return boolean true if nothing goes wrong
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $this->query = $this->trimmed('q');
+ $this->lang = $this->trimmed('lang');
+ $this->rpp = $this->trimmed('rpp');
+
+ if (!$this->rpp) {
+ $this->rpp = 15;
+ }
+
+ if ($this->rpp > 100) {
+ $this->rpp = 100;
+ }
+
+ $this->page = $this->trimmed('page');
+
+ if (!$this->page) {
+ $this->page = 1;
+ }
+
+ $this->since_id = $this->trimmed('since_id');
+ $this->geocode = $this->trimmed('geocode');
+
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showResults();
+ }
+
+ /**
+ * Show search results
+ *
+ * @return void
+ */
+
+ function showResults()
+ {
+
+ // TODO: Support search operators like from: and to:, boolean, etc.
+
+ $notice = new Notice();
+
+ // lcase it for comparison
+ $q = strtolower($this->query);
+
+ $search_engine = $notice->getSearchEngine('identica_notices');
+ $search_engine->set_sort_mode('chron');
+ $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true);
+ $search_engine->query($q);
+ $cnt = $notice->find();
+
+ // TODO: since_id, lang, geocode
+
+ $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page);
+
+ $this->init_document('json');
+ $results->show();
+ $this->end_document('json');
+ }
+
+ /**
+ * Do we need to write to the database?
+ *
+ * @return boolean true
+ */
+
+ function isReadOnly()
+ {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php
index 18e24c0f5..63e29068b 100644
--- a/actions/twitapistatuses.php
+++ b/actions/twitapistatuses.php
@@ -115,9 +115,14 @@ class TwitapistatusesAction extends TwitterapiAction
$since = strtotime($this->arg('since'));
- $user = $this->get_user(null, $apidata);
+ $user = $this->get_user($apidata['api_arg'], $apidata);
$this->auth_user = $user;
+ if (empty($user)) {
+ $this->clientError(_('No such user!'), 404, $apidata['content-type']);
+ return;
+ }
+
$profile = $user->getProfile();
$sitename = common_config('site', 'name');
@@ -204,7 +209,7 @@ class TwitapistatusesAction extends TwitterapiAction
# FriendFeed's SUP protocol
# Also added RSS and Atom feeds
- $suplink = common_local_url('sup', null, $user->id);
+ $suplink = common_local_url('sup', null, null, $user->id);
header('X-SUP-ID: '.$suplink);
# XXX: since
@@ -470,19 +475,28 @@ class TwitapistatusesAction extends TwitterapiAction
return $this->subscriptions($apidata, 'subscribed', 'subscriber');
}
- function followers($args, $apidata)
+ function friendsIDs($args, $apidata)
{
parent::handle($args);
+ return $this->subscriptions($apidata, 'subscribed', 'subscriber', true);
+ }
+ function followers($args, $apidata)
+ {
+ parent::handle($args);
return $this->subscriptions($apidata, 'subscriber', 'subscribed');
}
- function subscriptions($apidata, $other_attr, $user_attr)
+ function followersIDs($args, $apidata)
{
+ parent::handle($args);
+ return $this->subscriptions($apidata, 'subscriber', 'subscribed', true);
+ }
- # XXX: lite
+ function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false)
+ {
- $this->auth_user = $apidate['user'];
+ $this->auth_user = $apidata['user'];
$user = $this->get_user($apidata['api_arg'], $apidata);
if (!$user) {
@@ -514,7 +528,10 @@ class TwitapistatusesAction extends TwitterapiAction
}
$sub->orderBy('created DESC');
- $sub->limit(($page-1)*100, 100);
+
+ if (!$onlyIDs) {
+ $sub->limit(($page-1)*100, 100);
+ }
$others = array();
@@ -529,7 +546,13 @@ class TwitapistatusesAction extends TwitterapiAction
$type = $apidata['content-type'];
$this->init_document($type);
- $this->show_profiles($others, $type);
+
+ if ($onlyIDs) {
+ $this->showIDs($others, $type);
+ } else {
+ $this->show_profiles($others, $type);
+ }
+
$this->end_document($type);
}
@@ -555,6 +578,28 @@ class TwitapistatusesAction extends TwitterapiAction
}
}
+ function showIDs($profiles, $type)
+ {
+ switch ($type) {
+ case 'xml':
+ $this->elementStart('ids');
+ foreach ($profiles as $profile) {
+ $this->element('id', null, $profile->id);
+ }
+ $this->elementEnd('ids');
+ break;
+ case 'json':
+ $ids = array();
+ foreach ($profiles as $profile) {
+ $ids[] = (int)$profile->id;
+ }
+ print json_encode($ids);
+ break;
+ default:
+ $this->clientError(_('unsupported file type'));
+ }
+ }
+
function featured($args, $apidata)
{
parent::handle($args);
diff --git a/actions/twitapitrends.php b/actions/twitapitrends.php
new file mode 100644
index 000000000..c73d89446
--- /dev/null
+++ b/actions/twitapitrends.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * List of replies
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2008-2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+require_once INSTALLDIR.'/lib/twitterapi.php';
+
+/**
+ * Returns the top ten queries that are currently trending
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ * @see TwitterapiAction
+ */
+
+class TwitapitrendsAction extends TwitterapiAction
+{
+
+ var $callback;
+
+ /**
+ * Initialization.
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return boolean false if user doesn't exist
+ */
+ function prepare($args)
+ {
+ parent::prepare($args);
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showTrends();
+ }
+
+ /**
+ * Output the trends
+ *
+ * @return void
+ */
+ function showTrends()
+ {
+ $this->serverError(_('API method under construction.'), $code = 501);
+ }
+
+} \ No newline at end of file
diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php
index 8f16e5613..2894b7486 100644
--- a/actions/twitapiusers.php
+++ b/actions/twitapiusers.php
@@ -25,25 +25,29 @@ class TwitapiusersAction extends TwitterapiAction
{
function show($args, $apidata)
- {
+ {
parent::handle($args);
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
$this->clientError(_('API method not found!'), $code = 404);
return;
}
-
- $this->auth_user = $apidata['user'];
+
$user = null;
$email = $this->arg('email');
+ $user_id = $this->arg('user_id');
if ($email) {
$user = User::staticGet('email', $email);
+ } elseif ($user_id) {
+ $user = $this->get_user($user_id);
} elseif (isset($apidata['api_arg'])) {
$user = $this->get_user($apidata['api_arg']);
- }
-
- if (!$user) {
+ } elseif (isset($apidata['user'])) {
+ $user = $apidata['user'];
+ }
+
+ if (!$user) {
// XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
$this->client_error(_('Not found.'), 404, $apidata['content-type']);
return;
@@ -74,9 +78,12 @@ class TwitapiusersAction extends TwitterapiAction
// Other fields Twitter sends...
$twitter_user['profile_background_color'] = '';
+ $twitter_user['profile_background_image_url'] = '';
$twitter_user['profile_text_color'] = '';
$twitter_user['profile_link_color'] = '';
$twitter_user['profile_sidebar_fill_color'] = '';
+ $twitter_user['profile_sidebar_border_color'] = '';
+ $twitter_user['profile_background_tile'] = 'false';
$faves = DB_DataObject::factory('fave');
$faves->user_id = $user->id;
@@ -94,18 +101,27 @@ class TwitapiusersAction extends TwitterapiAction
$twitter_user['utc_offset'] = $t->format('Z');
$twitter_user['time_zone'] = $timezone;
- if (isset($this->auth_user)) {
+ if (isset($apidata['user'])) {
- if ($this->auth_user->isSubscribed($profile)) {
+ if ($apidata['user']->isSubscribed($profile)) {
$twitter_user['following'] = 'true';
} else {
$twitter_user['following'] = 'false';
}
-
- // Not implemented yet
- $twitter_user['notifications'] = 'false';
- }
-
+
+ // Notifications on?
+ $sub = Subscription::pkeyGet(array('subscriber' =>
+ $apidata['user']->id, 'subscribed' => $profile->id));
+
+ if ($sub) {
+ if ($sub->jabber || $sub->sms) {
+ $twitter_user['notifications'] = 'true';
+ } else {
+ $twitter_user['notifications'] = 'false';
+ }
+ }
+ }
+
if ($apidata['content-type'] == 'xml') {
$this->init_document('xml');
$this->show_twitter_xml_user($twitter_user);
@@ -114,7 +130,13 @@ class TwitapiusersAction extends TwitterapiAction
$this->init_document('json');
$this->show_json_objects($twitter_user);
$this->end_document('json');
- }
+ } else {
+
+ // This is in case 'show' was called via /account/verify_credentials
+ // without a format (xml or json).
+ header('Content-Type: text/html; charset=utf-8');
+ print 'Authorized';
+ }
}
}
diff --git a/actions/twittersettings.php b/actions/twittersettings.php
index 2d41469bb..a79859bbf 100644
--- a/actions/twittersettings.php
+++ b/actions/twittersettings.php
@@ -32,6 +32,7 @@ if (!defined('LACONICA')) {
}
require_once INSTALLDIR.'/lib/connectsettingsaction.php';
+require_once INSTALLDIR.'/lib/twitter.php';
define('SUBSCRIPTIONS', 80);
@@ -90,7 +91,7 @@ class TwittersettingsAction extends ConnectSettingsAction
$fuser = null;
- $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter
+ $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
if ($flink) {
$fuser = $flink->getForeignUser();
@@ -358,7 +359,7 @@ class TwittersettingsAction extends ConnectSettingsAction
$flink->user_id = $user->id;
$flink->foreign_id = $twit_user->id;
- $flink->service = 1; // Twitter
+ $flink->service = TWITTER_SERVICE;
$flink->credentials = $password;
$flink->created = common_sql_now();
diff --git a/actions/updateprofile.php b/actions/updateprofile.php
index c79112dac..4751a04ff 100644
--- a/actions/updateprofile.php
+++ b/actions/updateprofile.php
@@ -93,22 +93,22 @@ class UpdateprofileAction extends Action
}
# optional stuff
$fullname = $req->get_parameter('omb_listenee_fullname');
- if ($fullname && strlen($fullname) > 255) {
+ if ($fullname && mb_strlen($fullname) > 255) {
$this->clientError(_("Full name is too long (max 255 chars)."));
return false;
}
$homepage = $req->get_parameter('omb_listenee_homepage');
- if ($homepage && (!common_valid_http_url($homepage) || strlen($homepage) > 255)) {
+ if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
$this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage));
return false;
}
$bio = $req->get_parameter('omb_listenee_bio');
- if ($bio && strlen($bio) > 140) {
+ if ($bio && mb_strlen($bio) > 140) {
$this->clientError(_("Bio is too long (max 140 chars)."));
return false;
}
$location = $req->get_parameter('omb_listenee_location');
- if ($location && strlen($location) > 255) {
+ if ($location && mb_strlen($location) > 255) {
$this->clientError(_("Location is too long (max 255 chars)."));
return false;
}
@@ -162,7 +162,13 @@ class UpdateprofileAction extends Action
if ($avatar) {
$temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
copy($avatar, $temp_filename);
- if (!$profile->setOriginal($temp_filename)) {
+ $imagefile = new ImageFile($profile->id, $temp_filename);
+ $filename = Avatar::filename($profile->id,
+ image_type_to_extension($imagefile->type),
+ null,
+ common_timestamp());
+ rename($temp_filename, Avatar::path($filename));
+ if (!$profile->setOriginal($filename)) {
$this->serverError(_('Could not save avatar info'), 500);
return false;
}
diff --git a/actions/userauthorization.php b/actions/userauthorization.php
index 58fc96c0e..0566b4b70 100644
--- a/actions/userauthorization.php
+++ b/actions/userauthorization.php
@@ -105,7 +105,7 @@ class UserauthorizationAction extends Action
$this->elementStart('div', 'profile');
if ($avatar) {
$this->element('img', array('src' => $avatar,
- 'class' => 'avatar profile',
+ 'class' => 'avatar',
'width' => AVATAR_PROFILE_SIZE,
'height' => AVATAR_PROFILE_SIZE,
'alt' => $nickname));
@@ -197,7 +197,7 @@ class UserauthorizationAction extends Action
}
$parts = array();
foreach ($params as $k => $v) {
- $parts[] = $k . '=' . OAuthUtil::urlencodeRFC3986($v);
+ $parts[] = $k . '=' . OAuthUtil::urlencode_rfc3986($v);
}
$query_string = implode('&', $parts);
$parsed = parse_url($callback);
@@ -330,7 +330,13 @@ class UserauthorizationAction extends Action
{
$temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
copy($url, $temp_filename);
- return $profile->setOriginal($temp_filename);
+ $imagefile = new ImageFile($profile->id, $temp_filename);
+ $filename = Avatar::filename($profile->id,
+ image_type_to_extension($imagefile->type),
+ null,
+ common_timestamp());
+ rename($temp_filename, Avatar::path($filename));
+ return $profile->setOriginal($filename);
}
function showAcceptMessage($tok)
@@ -469,19 +475,19 @@ class UserauthorizationAction extends Action
}
# optional stuff
$fullname = $req->get_parameter('omb_listenee_fullname');
- if ($fullname && strlen($fullname) > 255) {
+ if ($fullname && mb_strlen($fullname) > 255) {
throw new OAuthException("Full name '$fullname' too long.");
}
$homepage = $req->get_parameter('omb_listenee_homepage');
- if ($homepage && (!common_valid_http_url($homepage) || strlen($homepage) > 255)) {
+ if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
throw new OAuthException("Invalid homepage '$homepage'");
}
$bio = $req->get_parameter('omb_listenee_bio');
- if ($bio && strlen($bio) > 140) {
+ if ($bio && mb_strlen($bio) > 140) {
throw new OAuthException("Bio too long '$bio'");
}
$location = $req->get_parameter('omb_listenee_location');
- if ($location && strlen($location) > 255) {
+ if ($location && mb_strlen($location) > 255) {
throw new OAuthException("Location too long '$location'");
}
$avatar = $req->get_parameter('omb_listenee_avatar');
diff --git a/actions/userrss.php b/actions/userrss.php
index 04855ccca..a3e5a3aab 100644
--- a/actions/userrss.php
+++ b/actions/userrss.php
@@ -46,13 +46,13 @@ class UserrssAction extends Rss10Action
{
$user = $this->user;
-
+
if (is_null($user)) {
return null;
}
-
+
$notice = $user->getNotices(0, ($limit == 0) ? NOTICES_PER_PAGE : $limit);
-
+
while ($notice->fetch()) {
$notices[] = clone($notice);
}
@@ -87,10 +87,10 @@ class UserrssAction extends Rss10Action
}
# override parent to add X-SUP-ID URL
-
+
function initRss($limit=0)
{
- $url = common_local_url('sup', null, $this->user->id);
+ $url = common_local_url('sup', null, null, $this->user->id);
header('X-SUP-ID: '.$url);
parent::initRss($limit);
}
@@ -100,4 +100,3 @@ class UserrssAction extends Rss10Action
return true;
}
}
-