summaryrefslogtreecommitdiff
path: root/_darcs/pristine
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-12-23 14:19:07 -0500
committerEvan Prodromou <evan@prodromou.name>2008-12-23 14:19:07 -0500
commitedbc0c665cc65875b4d14b79939233b1c9c06bb6 (patch)
tree4daaacb5bb4c52db9131624b4339bd9a60b205dd /_darcs/pristine
parent17ece0777b22b15c60b27b32f0f7e24ecc447661 (diff)
replace all tabs with four spaces
The PEAR coding standards decree: no tabs, but indent by four spaces. I've done a global search-and-replace on all tabs, replacing them by four spaces. This is a huge change, but it will go a long way to getting us towards phpcs-compliance. And that means better code readability, and that means more participation. darcs-hash:20081223191907-84dde-21e8efe210e6d5d54e935a22d0cee5c7bbfc007d.gz
Diffstat (limited to '_darcs/pristine')
-rw-r--r--_darcs/pristine/actions/accesstoken.php34
-rw-r--r--_darcs/pristine/actions/all.php94
-rw-r--r--_darcs/pristine/actions/allrss.php84
-rw-r--r--_darcs/pristine/actions/api.php322
-rw-r--r--_darcs/pristine/actions/avatarbynickname.php76
-rw-r--r--_darcs/pristine/actions/block.php12
-rw-r--r--_darcs/pristine/actions/confirmaddress.php38
-rw-r--r--_darcs/pristine/actions/deletenotice.php136
-rw-r--r--_darcs/pristine/actions/deleteprofile.php246
-rw-r--r--_darcs/pristine/actions/disfavor.php94
-rw-r--r--_darcs/pristine/actions/doc.php28
-rw-r--r--_darcs/pristine/actions/emailsettings.php590
-rw-r--r--_darcs/pristine/actions/facebookhome.php140
-rw-r--r--_darcs/pristine/actions/facebookinvite.php26
-rw-r--r--_darcs/pristine/actions/facebookremove.php58
-rw-r--r--_darcs/pristine/actions/facebooksettings.php34
-rw-r--r--_darcs/pristine/actions/favor.php134
-rw-r--r--_darcs/pristine/actions/favorited.php102
-rw-r--r--_darcs/pristine/actions/favoritesrss.php72
-rw-r--r--_darcs/pristine/actions/featured.php108
-rw-r--r--_darcs/pristine/actions/finishaddopenid.php154
-rw-r--r--_darcs/pristine/actions/finishimmediate.php62
-rw-r--r--_darcs/pristine/actions/finishopenidlogin.php742
-rw-r--r--_darcs/pristine/actions/finishremotesubscribe.php402
-rw-r--r--_darcs/pristine/actions/foaf.php348
-rw-r--r--_darcs/pristine/actions/imsettings.php468
-rw-r--r--_darcs/pristine/actions/invite.php342
-rw-r--r--_darcs/pristine/actions/login.php236
-rw-r--r--_darcs/pristine/actions/logout.php32
-rw-r--r--_darcs/pristine/actions/microsummary.php38
-rw-r--r--_darcs/pristine/actions/newmessage.php224
-rw-r--r--_darcs/pristine/actions/newnotice.php254
-rw-r--r--_darcs/pristine/actions/noticesearch.php244
-rw-r--r--_darcs/pristine/actions/noticesearchrss.php56
-rw-r--r--_darcs/pristine/actions/nudge.php86
-rw-r--r--_darcs/pristine/actions/openidlogin.php122
-rw-r--r--_darcs/pristine/actions/openidsettings.php258
-rw-r--r--_darcs/pristine/actions/opensearch.php70
-rw-r--r--_darcs/pristine/actions/othersettings.php228
-rw-r--r--_darcs/pristine/actions/peoplesearch.php76
-rw-r--r--_darcs/pristine/actions/peopletag.php132
-rw-r--r--_darcs/pristine/actions/postnotice.php114
-rw-r--r--_darcs/pristine/actions/profilesettings.php824
-rw-r--r--_darcs/pristine/actions/public.php136
-rw-r--r--_darcs/pristine/actions/publicrss.php58
-rw-r--r--_darcs/pristine/actions/publicxrds.php82
-rw-r--r--_darcs/pristine/actions/recoverpassword.php590
-rw-r--r--_darcs/pristine/actions/register.php474
-rw-r--r--_darcs/pristine/actions/remotesubscribe.php604
-rw-r--r--_darcs/pristine/actions/replies.php96
-rw-r--r--_darcs/pristine/actions/repliesrss.php84
-rw-r--r--_darcs/pristine/actions/requesttoken.php34
-rw-r--r--_darcs/pristine/actions/showfavorites.php102
-rw-r--r--_darcs/pristine/actions/showmessage.php140
-rw-r--r--_darcs/pristine/actions/shownotice.php132
-rw-r--r--_darcs/pristine/actions/showstream.php736
-rw-r--r--_darcs/pristine/actions/smssettings.php590
-rw-r--r--_darcs/pristine/actions/subedit.php10
-rw-r--r--_darcs/pristine/actions/subscribe.php76
-rw-r--r--_darcs/pristine/actions/subscribers.php48
-rw-r--r--_darcs/pristine/actions/subscriptions.php44
-rw-r--r--_darcs/pristine/actions/sup.php110
-rw-r--r--_darcs/pristine/actions/tag.php270
-rw-r--r--_darcs/pristine/actions/tagother.php330
-rw-r--r--_darcs/pristine/actions/tagrss.php58
-rw-r--r--_darcs/pristine/actions/twitapiaccount.php104
-rw-r--r--_darcs/pristine/actions/twitapiblocks.php28
-rw-r--r--_darcs/pristine/actions/twitapidirect_messages.php516
-rw-r--r--_darcs/pristine/actions/twitapifavorites.php296
-rw-r--r--_darcs/pristine/actions/twitapifriendships.php192
-rw-r--r--_darcs/pristine/actions/twitapihelp.php50
-rw-r--r--_darcs/pristine/actions/twitapinotifications.php16
-rw-r--r--_darcs/pristine/actions/twitapistatuses.php1042
-rw-r--r--_darcs/pristine/actions/twitapiusers.php44
-rw-r--r--_darcs/pristine/actions/twittersettings.php596
-rw-r--r--_darcs/pristine/actions/unblock.php10
-rw-r--r--_darcs/pristine/actions/unsubscribe.php72
-rw-r--r--_darcs/pristine/actions/updateprofile.php286
-rw-r--r--_darcs/pristine/actions/userauthorization.php1104
-rw-r--r--_darcs/pristine/actions/userbyid.php30
-rw-r--r--_darcs/pristine/actions/userrss.php108
-rw-r--r--_darcs/pristine/actions/xrds.php212
-rw-r--r--_darcs/pristine/classes/Avatar.php106
-rw-r--r--_darcs/pristine/classes/Channel.php316
-rw-r--r--_darcs/pristine/classes/Command.php584
-rw-r--r--_darcs/pristine/classes/CommandInterpreter.php334
-rw-r--r--_darcs/pristine/classes/Fave.php28
-rw-r--r--_darcs/pristine/classes/Foreign_link.php86
-rw-r--r--_darcs/pristine/classes/Foreign_user.php86
-rw-r--r--_darcs/pristine/classes/Memcached_DataObject.php274
-rw-r--r--_darcs/pristine/classes/Message.php78
-rw-r--r--_darcs/pristine/classes/Notice.php804
-rw-r--r--_darcs/pristine/classes/NoticeWrapper.php42
-rw-r--r--_darcs/pristine/classes/Notice_tag.php34
-rw-r--r--_darcs/pristine/classes/Profile.php216
-rw-r--r--_darcs/pristine/classes/Profile_tag.php152
-rw-r--r--_darcs/pristine/classes/Queue_item.php60
-rw-r--r--_darcs/pristine/classes/Sms_carrier.php8
-rw-r--r--_darcs/pristine/classes/Subscription.php8
-rw-r--r--_darcs/pristine/classes/User.php592
-rw-r--r--_darcs/pristine/lib/common.php162
-rw-r--r--_darcs/pristine/lib/deleteaction.php74
-rw-r--r--_darcs/pristine/lib/facebookaction.php516
-rw-r--r--_darcs/pristine/lib/oauthstore.php218
-rw-r--r--_darcs/pristine/lib/omb.php378
-rw-r--r--_darcs/pristine/lib/openid.php316
-rw-r--r--_darcs/pristine/lib/personal.php366
-rw-r--r--_darcs/pristine/lib/profilelist.php260
-rw-r--r--_darcs/pristine/lib/queuehandler.php194
-rw-r--r--_darcs/pristine/lib/rssaction.php322
-rw-r--r--_darcs/pristine/lib/search_engines.php4
-rw-r--r--_darcs/pristine/lib/searchaction.php154
-rw-r--r--_darcs/pristine/lib/settingsaction.php100
-rw-r--r--_darcs/pristine/lib/stream.php34
-rw-r--r--_darcs/pristine/lib/subs.php122
-rw-r--r--_darcs/pristine/lib/theme.php18
-rw-r--r--_darcs/pristine/lib/twitter.php216
-rw-r--r--_darcs/pristine/lib/twitterapi.php1224
-rw-r--r--_darcs/pristine/lib/xmppqueuehandler.php112
-rw-r--r--_darcs/pristine/scripts/enjitqueuehandler.php86
-rw-r--r--_darcs/pristine/scripts/fixup_hashtags.php12
-rw-r--r--_darcs/pristine/scripts/fixup_inboxes.php58
-rw-r--r--_darcs/pristine/scripts/fixup_notices_rendered.php20
-rw-r--r--_darcs/pristine/scripts/getpiddir.php4
-rw-r--r--_darcs/pristine/scripts/inbox_users.php122
-rw-r--r--_darcs/pristine/scripts/jabberqueuehandler.php28
-rw-r--r--_darcs/pristine/scripts/maildaemon.php344
-rw-r--r--_darcs/pristine/scripts/ombqueuehandler.php52
-rw-r--r--_darcs/pristine/scripts/publicqueuehandler.php30
-rw-r--r--_darcs/pristine/scripts/sitemap.php538
-rw-r--r--_darcs/pristine/scripts/smsqueuehandler.php32
-rw-r--r--_darcs/pristine/scripts/synctwitterfriends.php28
-rw-r--r--_darcs/pristine/scripts/update_translations.php98
-rw-r--r--_darcs/pristine/scripts/xmppconfirmhandler.php192
-rw-r--r--_darcs/pristine/scripts/xmppdaemon.php504
135 files changed, 14098 insertions, 14098 deletions
diff --git a/_darcs/pristine/actions/accesstoken.php b/_darcs/pristine/actions/accesstoken.php
index 4907749ce..a468c33a6 100644
--- a/_darcs/pristine/actions/accesstoken.php
+++ b/_darcs/pristine/actions/accesstoken.php
@@ -22,21 +22,21 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/omb.php');
class AccesstokenAction extends Action {
- function handle($args) {
- parent::handle($args);
- try {
- common_debug('getting request from env variables', __FILE__);
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
- common_debug('getting a server', __FILE__);
- $server = omb_oauth_server();
- common_debug('fetching the access token', __FILE__);
- $token = $server->fetch_access_token($req);
- common_debug('got this token: "'.print_r($token,TRUE).'"', __FILE__);
- common_debug('printing the access token', __FILE__);
- print $token;
- } catch (OAuthException $e) {
- common_server_error($e->getMessage());
- }
- }
+ function handle($args) {
+ parent::handle($args);
+ try {
+ common_debug('getting request from env variables', __FILE__);
+ common_remove_magic_from_request();
+ $req = OAuthRequest::from_request();
+ common_debug('getting a server', __FILE__);
+ $server = omb_oauth_server();
+ common_debug('fetching the access token', __FILE__);
+ $token = $server->fetch_access_token($req);
+ common_debug('got this token: "'.print_r($token,TRUE).'"', __FILE__);
+ common_debug('printing the access token', __FILE__);
+ print $token;
+ } catch (OAuthException $e) {
+ common_server_error($e->getMessage());
+ }
+ }
}
diff --git a/_darcs/pristine/actions/all.php b/_darcs/pristine/actions/all.php
index 2a26e48d4..066ee77bf 100644
--- a/_darcs/pristine/actions/all.php
+++ b/_darcs/pristine/actions/all.php
@@ -23,71 +23,71 @@ require_once(INSTALLDIR.'/actions/showstream.php');
class AllAction extends StreamAction {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- $nickname = common_canonical_nickname($this->arg('nickname'));
- $user = User::staticGet('nickname', $nickname);
+ $nickname = common_canonical_nickname($this->arg('nickname'));
+ $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- $this->client_error(_('No such user.'));
- return;
- }
+ if (!$user) {
+ $this->client_error(_('No such user.'));
+ return;
+ }
- $profile = $user->getProfile();
+ $profile = $user->getProfile();
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
- # Looks like we're good; show the header
+ # Looks like we're good; show the header
- common_show_header(sprintf(_("%s and friends"), $profile->nickname),
- array($this, 'show_header'), $user,
- array($this, 'show_top'));
+ common_show_header(sprintf(_("%s and friends"), $profile->nickname),
+ array($this, 'show_header'), $user,
+ array($this, 'show_top'));
- $this->show_notices($user);
+ $this->show_notices($user);
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_header($user) {
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('allrss', array('nickname' =>
- $user->nickname)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for friends of %s'), $user->nickname)));
- }
+ function show_header($user) {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('allrss', array('nickname' =>
+ $user->nickname)),
+ 'type' => 'application/rss+xml',
+ 'title' => sprintf(_('Feed for friends of %s'), $user->nickname)));
+ }
- function show_top($user) {
- $cur = common_current_user();
+ function show_top($user) {
+ $cur = common_current_user();
- if ($cur && $cur->id == $user->id) {
- common_notice_form('all');
- }
+ if ($cur && $cur->id == $user->id) {
+ common_notice_form('all');
+ }
- $this->views_menu();
+ $this->views_menu();
- $this->show_feeds_list(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'allrss')));
- }
+ $this->show_feeds_list(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $user->nickname)),
+ 'type' => 'rss',
+ 'version' => 'RSS 1.0',
+ 'item' => 'allrss')));
+ }
- function show_notices($user) {
+ function show_notices($user) {
- $page = $this->trimmed('page');
- if (!$page) {
- $page = 1;
- }
+ $page = $this->trimmed('page');
+ if (!$page) {
+ $page = 1;
+ }
- $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$cnt = $this->show_notice_list($notice);
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'all', array('nickname' => $user->nickname));
- }
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'all', array('nickname' => $user->nickname));
+ }
}
diff --git a/_darcs/pristine/actions/allrss.php b/_darcs/pristine/actions/allrss.php
index e49ac5540..d28fcea49 100644
--- a/_darcs/pristine/actions/allrss.php
+++ b/_darcs/pristine/actions/allrss.php
@@ -25,53 +25,53 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class AllrssAction extends Rss10Action {
- var $user = NULL;
+ var $user = NULL;
- function init() {
- $nickname = $this->trimmed('nickname');
- $this->user = User::staticGet('nickname', $nickname);
+ function init() {
+ $nickname = $this->trimmed('nickname');
+ $this->user = User::staticGet('nickname', $nickname);
- if (!$this->user) {
- common_user_error(_('No such user.'));
- return false;
- } else {
- return true;
- }
- }
+ if (!$this->user) {
+ common_user_error(_('No such user.'));
+ return false;
+ } else {
+ return true;
+ }
+ }
- function get_notices($limit=0) {
+ function get_notices($limit=0) {
- $user = $this->user;
-
- $notice = $user->noticesWithFriends(0, $limit);
-
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
+ $user = $this->user;
+
+ $notice = $user->noticesWithFriends(0, $limit);
+
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
- return $notices;
- }
+ return $notices;
+ }
- function get_channel() {
- $user = $this->user;
- $c = array('url' => common_local_url('allrss',
- array('nickname' =>
- $user->nickname)),
- 'title' => sprintf(_('%s and friends'), $user->nickname),
- 'link' => common_local_url('all',
- array('nickname' =>
- $user->nickname)),
- 'description' => sprintf(_('Feed for friends of %s'), $user->nickname));
- return $c;
- }
+ function get_channel() {
+ $user = $this->user;
+ $c = array('url' => common_local_url('allrss',
+ array('nickname' =>
+ $user->nickname)),
+ 'title' => sprintf(_('%s and friends'), $user->nickname),
+ 'link' => common_local_url('all',
+ array('nickname' =>
+ $user->nickname)),
+ 'description' => sprintf(_('Feed for friends of %s'), $user->nickname));
+ return $c;
+ }
- function get_image() {
- $user = $this->user;
- $profile = $user->getProfile();
- if (!$profile) {
- return NULL;
- }
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- return ($avatar) ? $avatar->url : NULL;
- }
+ function get_image() {
+ $user = $this->user;
+ $profile = $user->getProfile();
+ if (!$profile) {
+ return NULL;
+ }
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ return ($avatar) ? $avatar->url : NULL;
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/api.php b/_darcs/pristine/actions/api.php
index 919a515ce..e03961e21 100644
--- a/_darcs/pristine/actions/api.php
+++ b/_darcs/pristine/actions/api.php
@@ -10,115 +10,115 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
class ApiAction extends Action {
- var $user;
- var $content_type;
- var $api_arg;
- var $api_method;
- var $api_action;
-
- function handle($args) {
- parent::handle($args);
-
- $this->api_action = $this->arg('apiaction');
- $method = $this->arg('method');
- $argument = $this->arg('argument');
-
- if (isset($argument)) {
- $cmdext = explode('.', $argument);
- $this->api_arg = $cmdext[0];
- $this->api_method = $method;
- $this->content_type = strtolower($cmdext[1]);
- } else {
-
- # Requested format / content-type will be an extension on the method
- $cmdext = explode('.', $method);
- $this->api_method = $cmdext[0];
- $this->content_type = strtolower($cmdext[1]);
- }
-
- if ($this->requires_auth()) {
- if (!isset($_SERVER['PHP_AUTH_USER'])) {
-
- # This header makes basic auth go
- header('WWW-Authenticate: Basic realm="Laconica API"');
-
- # If the user hits cancel -- bam!
- $this->show_basic_auth_error();
- } else {
- $nickname = $_SERVER['PHP_AUTH_USER'];
- $password = $_SERVER['PHP_AUTH_PW'];
- $user = common_check_user($nickname, $password);
-
- if ($user) {
- $this->user = $user;
- $this->process_command();
- } else {
- # basic authentication failed
- $this->show_basic_auth_error();
- }
- }
- } else {
-
- # Look for the user in the session
- if (common_logged_in()) {
- $this->user = common_current_user();
- }
-
- $this->process_command();
- }
- }
-
- function process_command() {
- $action = "twitapi$this->api_action";
- $actionfile = INSTALLDIR."/actions/$action.php";
-
- if (file_exists($actionfile)) {
- require_once($actionfile);
- $action_class = ucfirst($action)."Action";
- $action_obj = new $action_class();
+ var $user;
+ var $content_type;
+ var $api_arg;
+ var $api_method;
+ var $api_action;
+
+ function handle($args) {
+ parent::handle($args);
+
+ $this->api_action = $this->arg('apiaction');
+ $method = $this->arg('method');
+ $argument = $this->arg('argument');
+
+ if (isset($argument)) {
+ $cmdext = explode('.', $argument);
+ $this->api_arg = $cmdext[0];
+ $this->api_method = $method;
+ $this->content_type = strtolower($cmdext[1]);
+ } else {
+
+ # Requested format / content-type will be an extension on the method
+ $cmdext = explode('.', $method);
+ $this->api_method = $cmdext[0];
+ $this->content_type = strtolower($cmdext[1]);
+ }
+
+ if ($this->requires_auth()) {
+ if (!isset($_SERVER['PHP_AUTH_USER'])) {
+
+ # This header makes basic auth go
+ header('WWW-Authenticate: Basic realm="Laconica API"');
+
+ # If the user hits cancel -- bam!
+ $this->show_basic_auth_error();
+ } else {
+ $nickname = $_SERVER['PHP_AUTH_USER'];
+ $password = $_SERVER['PHP_AUTH_PW'];
+ $user = common_check_user($nickname, $password);
+
+ if ($user) {
+ $this->user = $user;
+ $this->process_command();
+ } else {
+ # basic authentication failed
+ $this->show_basic_auth_error();
+ }
+ }
+ } else {
+
+ # Look for the user in the session
+ if (common_logged_in()) {
+ $this->user = common_current_user();
+ }
+
+ $this->process_command();
+ }
+ }
+
+ function process_command() {
+ $action = "twitapi$this->api_action";
+ $actionfile = INSTALLDIR."/actions/$action.php";
+
+ if (file_exists($actionfile)) {
+ require_once($actionfile);
+ $action_class = ucfirst($action)."Action";
+ $action_obj = new $action_class();
if (!$action_obj->prepare($this->args)) {
return;
}
- if (method_exists($action_obj, $this->api_method)) {
- $apidata = array( 'content-type' => $this->content_type,
- 'api_method' => $this->api_method,
- 'api_arg' => $this->api_arg,
- 'user' => $this->user);
-
- call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
- } else {
- common_user_error("API method not found!", $code=404);
- }
- } else {
- common_user_error("API method not found!", $code=404);
- }
- }
-
- # Whitelist of API methods that don't need authentication
- function requires_auth() {
- static $noauth = array( 'statuses/public_timeline',
- 'statuses/show',
- 'users/show',
- 'help/test',
- 'help/downtime_schedule');
-
- static $bareauth = array('statuses/user_timeline',
- 'statuses/friends',
- 'statuses/followers',
- 'favorites/favorites');
+ if (method_exists($action_obj, $this->api_method)) {
+ $apidata = array( 'content-type' => $this->content_type,
+ 'api_method' => $this->api_method,
+ 'api_arg' => $this->api_arg,
+ 'user' => $this->user);
+
+ call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
+ } else {
+ common_user_error("API method not found!", $code=404);
+ }
+ } else {
+ common_user_error("API method not found!", $code=404);
+ }
+ }
+
+ # Whitelist of API methods that don't need authentication
+ function requires_auth() {
+ static $noauth = array( 'statuses/public_timeline',
+ 'statuses/show',
+ 'users/show',
+ 'help/test',
+ 'help/downtime_schedule');
+
+ static $bareauth = array('statuses/user_timeline',
+ 'statuses/friends',
+ 'statuses/followers',
+ 'favorites/favorites');
# If the site is "private", all API methods need authentication
@@ -126,71 +126,71 @@ class ApiAction extends Action {
return true;
}
- $fullname = "$this->api_action/$this->api_method";
-
- if (in_array($fullname, $bareauth)) {
- # bareauth: only needs auth if without an argument
- if ($this->api_arg) {
- return false;
- } else {
- return true;
- }
- } else if (in_array($fullname, $noauth)) {
- # noauth: never needs auth
- return false;
- } else {
- # everybody else needs auth
- return true;
- }
- }
-
- function show_basic_auth_error() {
- header('HTTP/1.1 401 Unauthorized');
- $msg = 'Could not authenticate you.';
-
- if ($this->content_type == 'xml') {
- header('Content-Type: application/xml; charset=utf-8');
- common_start_xml();
- common_element_start('hash');
- common_element('error', NULL, $msg);
- common_element('request', NULL, $_SERVER['REQUEST_URI']);
- common_element_end('hash');
- common_end_xml();
- } else if ($this->content_type == 'json') {
- header('Content-Type: application/json; charset=utf-8');
- $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
- print(json_encode($error_array));
- } else {
- header('Content-type: text/plain');
- print "$msg\n";
- }
- }
-
- function is_readonly() {
- # NOTE: before handle(), can't use $this->arg
- $apiaction = $_REQUEST['apiaction'];
- $method = $_REQUEST['method'];
- list($cmdtext, $fmt) = explode('.', $method);
-
- static $write_methods = array(
- 'account' => array('update_location', 'update_delivery_device', 'end_session'),
- 'blocks' => array('create', 'destroy'),
- 'direct_messages' => array('create', 'destroy'),
- 'favorites' => array('create', 'destroy'),
- 'friendships' => array('create', 'destroy'),
- 'help' => array(),
- 'notifications' => array('follow', 'leave'),
- 'statuses' => array('update', 'destroy'),
- 'users' => array()
- );
-
- if (array_key_exists($apiaction, $write_methods)) {
- if (!in_array($cmdtext, $write_methods[$apiaction])) {
- return true;
- }
- }
-
- return 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) {
+ return false;
+ } else {
+ return true;
+ }
+ } else if (in_array($fullname, $noauth)) {
+ # noauth: never needs auth
+ return false;
+ } else {
+ # everybody else needs auth
+ return true;
+ }
+ }
+
+ function show_basic_auth_error() {
+ header('HTTP/1.1 401 Unauthorized');
+ $msg = 'Could not authenticate you.';
+
+ if ($this->content_type == 'xml') {
+ header('Content-Type: application/xml; charset=utf-8');
+ common_start_xml();
+ common_element_start('hash');
+ common_element('error', NULL, $msg);
+ common_element('request', NULL, $_SERVER['REQUEST_URI']);
+ common_element_end('hash');
+ common_end_xml();
+ } else if ($this->content_type == 'json') {
+ header('Content-Type: application/json; charset=utf-8');
+ $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
+ print(json_encode($error_array));
+ } else {
+ header('Content-type: text/plain');
+ print "$msg\n";
+ }
+ }
+
+ function is_readonly() {
+ # NOTE: before handle(), can't use $this->arg
+ $apiaction = $_REQUEST['apiaction'];
+ $method = $_REQUEST['method'];
+ list($cmdtext, $fmt) = explode('.', $method);
+
+ static $write_methods = array(
+ 'account' => array('update_location', 'update_delivery_device', 'end_session'),
+ 'blocks' => array('create', 'destroy'),
+ 'direct_messages' => array('create', 'destroy'),
+ 'favorites' => array('create', 'destroy'),
+ 'friendships' => array('create', 'destroy'),
+ 'help' => array(),
+ 'notifications' => array('follow', 'leave'),
+ 'statuses' => array('update', 'destroy'),
+ 'users' => array()
+ );
+
+ if (array_key_exists($apiaction, $write_methods)) {
+ if (!in_array($cmdtext, $write_methods[$apiaction])) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
diff --git a/_darcs/pristine/actions/avatarbynickname.php b/_darcs/pristine/actions/avatarbynickname.php
index b33cababf..2ca861a66 100644
--- a/_darcs/pristine/actions/avatarbynickname.php
+++ b/_darcs/pristine/actions/avatarbynickname.php
@@ -24,45 +24,45 @@ class AvatarbynicknameAction extends Action {
parent::handle($args);
$nickname = $this->trimmed('nickname');
if (!$nickname) {
- $this->client_error(_('No nickname.'));
- return;
- }
- $size = $this->trimmed('size');
+ $this->client_error(_('No nickname.'));
+ return;
+ }
+ $size = $this->trimmed('size');
if (!$size) {
- $this->client_error(_('No size.'));
- return;
- }
- $size = strtolower($size);
- if (!in_array($size, array('original', '96', '48', '24'))) {
- $this->client_error(_('Invalid size.'));
- return;
- }
+ $this->client_error(_('No size.'));
+ return;
+ }
+ $size = strtolower($size);
+ if (!in_array($size, array('original', '96', '48', '24'))) {
+ $this->client_error(_('Invalid size.'));
+ return;
+ }
- $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- $this->client_error(_('No such user.'));
- return;
- }
- $profile = $user->getProfile();
- if (!$profile) {
- $this->client_error(_('User has no profile.'));
- return;
- }
- if ($size == 'original') {
- $avatar = $profile->getOriginal();
- } else {
- $avatar = $profile->getAvatar($size+0);
- }
+ $user = User::staticGet('nickname', $nickname);
+ if (!$user) {
+ $this->client_error(_('No such user.'));
+ return;
+ }
+ $profile = $user->getProfile();
+ if (!$profile) {
+ $this->client_error(_('User has no profile.'));
+ return;
+ }
+ if ($size == 'original') {
+ $avatar = $profile->getOriginal();
+ } else {
+ $avatar = $profile->getAvatar($size+0);
+ }
- if ($avatar) {
- $url = $avatar->url;
- } else {
- if ($size == 'original') {
- $url = common_default_avatar(AVATAR_PROFILE_SIZE);
- } else {
- $url = common_default_avatar($size+0);
- }
- }
- common_redirect($url, 302);
- }
+ if ($avatar) {
+ $url = $avatar->url;
+ } else {
+ if ($size == 'original') {
+ $url = common_default_avatar(AVATAR_PROFILE_SIZE);
+ } else {
+ $url = common_default_avatar($size+0);
+ }
+ }
+ common_redirect($url, 302);
+ }
}
diff --git a/_darcs/pristine/actions/block.php b/_darcs/pristine/actions/block.php
index e6d2b7e49..20ba81edb 100644
--- a/_darcs/pristine/actions/block.php
+++ b/_darcs/pristine/actions/block.php
@@ -32,12 +32,12 @@ class BlockAction extends Action {
return false;
}
- $token = $this->trimmed('token');
+ $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
$id = $this->trimmed('blockto');
@@ -75,7 +75,7 @@ class BlockAction extends Action {
$id = $this->profile->id;
- common_show_header(_('Block user'));
+ common_show_header(_('Block user'));
common_element('p', NULL,
_('Are you sure you want to block this user? '.
diff --git a/_darcs/pristine/actions/confirmaddress.php b/_darcs/pristine/actions/confirmaddress.php
index 44280e08a..9d97c8205 100644
--- a/_darcs/pristine/actions/confirmaddress.php
+++ b/_darcs/pristine/actions/confirmaddress.php
@@ -43,44 +43,44 @@ class ConfirmaddressAction extends Action {
$this->client_error(_('That confirmation code is not for you!'));
return;
}
- $type = $confirm->address_type;
- if (!in_array($type, array('email', 'jabber', 'sms'))) {
- $this->server_error(sprintf(_('Unrecognized address type %s'), $type));
- return;
- }
+ $type = $confirm->address_type;
+ if (!in_array($type, array('email', 'jabber', 'sms'))) {
+ $this->server_error(sprintf(_('Unrecognized address type %s'), $type));
+ return;
+ }
if ($cur->$type == $confirm->address) {
$this->client_error(_('That address has already been confirmed.'));
- return;
- }
+ return;
+ }
$cur->query('BEGIN');
$orig_user = clone($cur);
- $cur->$type = $confirm->address;
+ $cur->$type = $confirm->address;
- if ($type == 'sms') {
- $cur->carrier = ($confirm->address_extra)+0;
- $carrier = Sms_carrier::staticGet($cur->carrier);
- $cur->smsemail = $carrier->toEmailAddress($cur->sms);
- }
+ if ($type == 'sms') {
+ $cur->carrier = ($confirm->address_extra)+0;
+ $carrier = Sms_carrier::staticGet($cur->carrier);
+ $cur->smsemail = $carrier->toEmailAddress($cur->sms);
+ }
- $result = $cur->updateKeys($orig_user);
+ $result = $cur->updateKeys($orig_user);
if (!$result) {
- common_log_db_error($cur, 'UPDATE', __FILE__);
+ common_log_db_error($cur, 'UPDATE', __FILE__);
$this->server_error(_('Couldn\'t update user.'));
return;
}
- if ($type == 'email') {
- $cur->emailChanged();
- }
+ if ($type == 'email') {
+ $cur->emailChanged();
+ }
$result = $confirm->delete();
if (!$result) {
- common_log_db_error($confirm, 'DELETE', __FILE__);
+ common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
return;
}
diff --git a/_darcs/pristine/actions/deletenotice.php b/_darcs/pristine/actions/deletenotice.php
index 64746283a..ba348c5fa 100644
--- a/_darcs/pristine/actions/deletenotice.php
+++ b/_darcs/pristine/actions/deletenotice.php
@@ -22,80 +22,80 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/deleteaction.php');
class DeletenoticeAction extends DeleteAction {
- function handle($args) {
- parent::handle($args);
- # XXX: Ajax!
+ function handle($args) {
+ parent::handle($args);
+ # XXX: Ajax!
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->delete_notice();
- } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
- $this->show_form();
- }
- }
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->delete_notice();
+ } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
+ $this->show_form();
+ }
+ }
- function get_instructions() {
- return _('You are about to permanently delete a notice. Once this is done, it cannot be undone.');
- }
+ function get_instructions() {
+ return _('You are about to permanently delete a notice. Once this is done, it cannot be undone.');
+ }
- function get_title() {
- return _('Delete notice');
- }
+ function get_title() {
+ return _('Delete notice');
+ }
- function show_form($error=NULL) {
- $user = common_current_user();
+ function show_form($error=NULL) {
+ $user = common_current_user();
- common_show_header($this->get_title(), array($this, 'show_header'), $error,
- array($this, 'show_top'));
- common_element_start('form', array('id' => 'notice_delete_form',
- 'method' => 'post',
- 'action' => common_local_url('deletenotice')));
- common_hidden('token', common_session_token());
- common_hidden('notice', $this->trimmed('notice'));
- common_element_start('p');
- common_element('span', array('id' => 'confirmation_text'), _('Are you sure you want to delete this notice?'));
+ common_show_header($this->get_title(), array($this, 'show_header'), $error,
+ array($this, 'show_top'));
+ common_element_start('form', array('id' => 'notice_delete_form',
+ 'method' => 'post',
+ 'action' => common_local_url('deletenotice')));
+ common_hidden('token', common_session_token());
+ common_hidden('notice', $this->trimmed('notice'));
+ common_element_start('p');
+ common_element('span', array('id' => 'confirmation_text'), _('Are you sure you want to delete this notice?'));
- common_element('input', array('id' => 'submit_no',
- 'name' => 'submit',
- 'type' => 'submit',
- 'value' => _('No')));
- common_element('input', array('id' => 'submit_yes',
- 'name' => 'submit',
- 'type' => 'submit',
- 'value' => _('Yes')));
- common_element_end('p');
- common_element_end('form');
- common_show_footer();
- }
+ common_element('input', array('id' => 'submit_no',
+ 'name' => 'submit',
+ 'type' => 'submit',
+ 'value' => _('No')));
+ common_element('input', array('id' => 'submit_yes',
+ 'name' => 'submit',
+ 'type' => 'submit',
+ 'value' => _('Yes')));
+ common_element_end('p');
+ common_element_end('form');
+ common_show_footer();
+ }
- function delete_notice() {
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
- $url = common_get_returnto();
- $confirmed = $this->trimmed('submit');
- if ($confirmed == _('Yes')) {
- $user = common_current_user();
- $notice_id = $this->trimmed('notice');
- $notice = Notice::staticGet($notice_id);
- $replies = new Reply;
- $replies->get('notice_id', $notice_id);
+ function delete_notice() {
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+ $url = common_get_returnto();
+ $confirmed = $this->trimmed('submit');
+ if ($confirmed == _('Yes')) {
+ $user = common_current_user();
+ $notice_id = $this->trimmed('notice');
+ $notice = Notice::staticGet($notice_id);
+ $replies = new Reply;
+ $replies->get('notice_id', $notice_id);
- common_dequeue_notice($notice);
- if (common_config('memcached', 'enabled')) {
- $notice->blowSubsCache();
- }
- $replies->delete();
- $notice->delete();
- } else {
- if ($url) {
- common_set_returnto(NULL);
- } else {
- $url = common_local_url('public');
- }
- }
- common_redirect($url);
- }
+ common_dequeue_notice($notice);
+ if (common_config('memcached', 'enabled')) {
+ $notice->blowSubsCache();
+ }
+ $replies->delete();
+ $notice->delete();
+ } else {
+ if ($url) {
+ common_set_returnto(NULL);
+ } else {
+ $url = common_local_url('public');
+ }
+ }
+ common_redirect($url);
+ }
}
diff --git a/_darcs/pristine/actions/deleteprofile.php b/_darcs/pristine/actions/deleteprofile.php
index 418ac998d..29797bc76 100644
--- a/_darcs/pristine/actions/deleteprofile.php
+++ b/_darcs/pristine/actions/deleteprofile.php
@@ -32,101 +32,101 @@ class DeleteprofileAction extends Action {
}
}
- function get_instructions() {
- return _('Export and delete your user information.');
- }
-
- function form_header($title, $msg=NULL, $success=false) {
- common_show_header($title,
- NULL,
- array($msg, $success),
- array($this, 'show_top'));
- }
-
- function show_feeds_list($feeds) {
- common_element_start('div', array('class' => 'feedsdel'));
- common_element('p', null, 'Feeds:');
- common_element_start('ul', array('class' => 'xoxo'));
-
- foreach ($feeds as $key => $value) {
- $this->common_feed_item($feeds[$key]);
- }
- common_element_end('ul');
- common_element_end('div');
- }
+ function get_instructions() {
+ return _('Export and delete your user information.');
+ }
+
+ function form_header($title, $msg=NULL, $success=false) {
+ common_show_header($title,
+ NULL,
+ array($msg, $success),
+ array($this, 'show_top'));
+ }
+
+ function show_feeds_list($feeds) {
+ common_element_start('div', array('class' => 'feedsdel'));
+ common_element('p', null, 'Feeds:');
+ common_element_start('ul', array('class' => 'xoxo'));
+
+ foreach ($feeds as $key => $value) {
+ $this->common_feed_item($feeds[$key]);
+ }
+ common_element_end('ul');
+ common_element_end('div');
+ }
//TODO move to common.php (and retrace its origin)
- function common_feed_item($feed) {
+ function common_feed_item($feed) {
+ $user = common_current_user();
+ $nickname = $user->nickname;
+
+ switch($feed['item']) {
+ case 'notices': default:
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's ".$feed['version']." notice feed";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'foaf':
+ $feed_classname = "foaf";
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's FOAF file";
+ $feed['textContent'] = "FOAF";
+ break;
+ }
+ common_element_start('li');
+ common_element('a', array('href' => $feed['href'],
+ 'class' => $feed_classname,
+ 'type' => $feed_mimetype,
+ 'title' => $feed_title),
+ $feed['textContent']);
+ common_element_end('li');
+ }
+
+ function show_form($msg=NULL, $success=false) {
+ $this->form_header(_('Delete my account'), $msg, $success);
+ common_element('h2', NULL, _('Delete my account confirmation'));
+ $this->show_confirm_delete_form();
+ common_show_footer();
+ }
+
+ function show_confirm_delete_form() {
$user = common_current_user();
- $nickname = $user->nickname;
-
- switch($feed['item']) {
- case 'notices': default:
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's ".$feed['version']." notice feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'foaf':
- $feed_classname = "foaf";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's FOAF file";
- $feed['textContent'] = "FOAF";
- break;
- }
- common_element_start('li');
- common_element('a', array('href' => $feed['href'],
- 'class' => $feed_classname,
- 'type' => $feed_mimetype,
- 'title' => $feed_title),
- $feed['textContent']);
- common_element_end('li');
- }
-
- function show_form($msg=NULL, $success=false) {
- $this->form_header(_('Delete my account'), $msg, $success);
- common_element('h2', NULL, _('Delete my account confirmation'));
- $this->show_confirm_delete_form();
- common_show_footer();
- }
-
- function show_confirm_delete_form() {
- $user = common_current_user();
$notices = DB_DataObject::factory('notice');
$notices->profile_id = $user->id;
$notice_count = (int) $notices->count();
- common_element_start('form', array('method' => 'POST',
- 'id' => 'delete',
- 'action' =>
- common_local_url('deleteprofile')));
+ common_element_start('form', array('method' => 'POST',
+ 'id' => 'delete',
+ 'action' =>
+ common_local_url('deleteprofile')));
- common_hidden('token', common_session_token());
+ common_hidden('token', common_session_token());
common_element('p', null, "Last chance to copy your notices and contacts by saving the two links below before deleting your account. Be careful, this operation cannot be undone.");
- $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'notices'),
- 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
- 'type' => 'rdf',
- 'version' => 'FOAF',
- 'item' => 'foaf')));
+ $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
+ 'type' => 'rss',
+ 'version' => 'RSS 1.0',
+ 'item' => 'notices'),
+ 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
+ 'type' => 'rdf',
+ 'version' => 'FOAF',
+ 'item' => 'foaf')));
common_checkbox('confirmation', _('Check if you are sure you want to delete your account.'));
- common_submit('deleteaccount', _('Delete my account'));
- common_element_end('form');
+ common_submit('deleteaccount', _('Delete my account'));
+ common_element_end('form');
}
- function handle_post() {
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ function handle_post() {
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
if ($this->arg('deleteaccount') && $this->arg('confirmation')) {
$this->delete_account();
@@ -134,9 +134,9 @@ class DeleteprofileAction extends Action {
$this->show_form();
}
- function delete_account() {
- $user = common_current_user();
- assert(!is_null($user)); # should already be checked
+ function delete_account() {
+ $user = common_current_user();
+ assert(!is_null($user)); # should already be checked
// deleted later through the profile
/*
@@ -219,53 +219,53 @@ class DeleteprofileAction extends Action {
common_redirect(common_local_url('public'));
}
- function show_top($arr) {
- $msg = $arr[0];
- $success = $arr[1];
- if ($msg) {
- $this->message($msg, $success);
- } else {
- $inst = $this->get_instructions();
- $output = common_markup_to_html($inst);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
- $this->settings_menu();
- }
+ function show_top($arr) {
+ $msg = $arr[0];
+ $success = $arr[1];
+ if ($msg) {
+ $this->message($msg, $success);
+ } else {
+ $inst = $this->get_instructions();
+ $output = common_markup_to_html($inst);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+ $this->settings_menu();
+ }
function settings_menu() {
# action => array('prompt', 'title')
- $menu =
- array('profilesettings' =>
- array(_('Profile'),
- _('Change your profile settings')),
- 'emailsettings' =>
- array(_('Email'),
- _('Change email handling')),
- 'openidsettings' =>
- array(_('OpenID'),
- _('Add or remove OpenIDs')),
- 'smssettings' =>
- array(_('SMS'),
- _('Updates by SMS')),
- 'imsettings' =>
- array(_('IM'),
- _('Updates by instant messenger (IM)')),
- 'twittersettings' =>
- array(_('Twitter'),
- _('Twitter integration options')),
- 'othersettings' =>
- array(_('Other'),
- _('Other options')));
+ $menu =
+ array('profilesettings' =>
+ array(_('Profile'),
+ _('Change your profile settings')),
+ 'emailsettings' =>
+ array(_('Email'),
+ _('Change email handling')),
+ 'openidsettings' =>
+ array(_('OpenID'),
+ _('Add or remove OpenIDs')),
+ 'smssettings' =>
+ array(_('SMS'),
+ _('Updates by SMS')),
+ 'imsettings' =>
+ array(_('IM'),
+ _('Updates by instant messenger (IM)')),
+ 'twittersettings' =>
+ array(_('Twitter'),
+ _('Twitter integration options')),
+ 'othersettings' =>
+ array(_('Other'),
+ _('Other options')));
$action = $this->trimmed('action');
common_element_start('ul', array('id' => 'nav_views'));
foreach ($menu as $menuaction => $menudesc) {
- if ($menuaction == 'imsettings' &&
- !common_config('xmpp', 'enabled')) {
- continue;
- }
+ if ($menuaction == 'imsettings' &&
+ !common_config('xmpp', 'enabled')) {
+ continue;
+ }
common_menu_item(common_local_url($menuaction),
$menudesc[0],
$menudesc[1],
diff --git a/_darcs/pristine/actions/disfavor.php b/_darcs/pristine/actions/disfavor.php
index be208f65a..e47e68a8c 100644
--- a/_darcs/pristine/actions/disfavor.php
+++ b/_darcs/pristine/actions/disfavor.php
@@ -21,63 +21,63 @@ if (!defined('LACONICA')) { exit(1); }
class DisfavorAction extends Action {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- return;
- }
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ return;
+ }
- $user = common_current_user();
+ $user = common_current_user();
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
- return;
- }
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
+ return;
+ }
- $id = $this->trimmed('notice');
+ $id = $this->trimmed('notice');
- $notice = Notice::staticGet($id);
+ $notice = Notice::staticGet($id);
- $token = $this->trimmed('token-'.$notice->id);
+ $token = $this->trimmed('token-'.$notice->id);
- if (!$token || $token != common_session_token()) {
- $this->client_error(_("There was a problem with your session token. Try again, please."));
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_("There was a problem with your session token. Try again, please."));
+ return;
+ }
- $fave = new Fave();
- $fave->user_id = $this->id;
- $fave->notice_id = $notice->id;
- if (!$fave->find(true)) {
- $this->client_error(_('This notice is not a favorite!'));
- return;
- }
+ $fave = new Fave();
+ $fave->user_id = $this->id;
+ $fave->notice_id = $notice->id;
+ if (!$fave->find(true)) {
+ $this->client_error(_('This notice is not a favorite!'));
+ return;
+ }
- $result = $fave->delete();
+ $result = $fave->delete();
- if (!$result) {
- common_log_db_error($fave, 'DELETE', __FILE__);
- $this->server_error(_('Could not delete favorite.'));
- return;
- }
-
- $user->blowFavesCache();
+ if (!$result) {
+ common_log_db_error($fave, 'DELETE', __FILE__);
+ $this->server_error(_('Could not delete favorite.'));
+ return;
+ }
+
+ $user->blowFavesCache();
- if ($this->boolean('ajax')) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Add to favorites'));
- common_element_end('head');
- common_element_start('body');
- common_favor_form($notice);
- common_element_end('body');
- common_element_end('html');
- } else {
- common_redirect(common_local_url('showfavorites',
- array('nickname' => $user->nickname)));
- }
- }
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Add to favorites'));
+ common_element_end('head');
+ common_element_start('body');
+ common_favor_form($notice);
+ common_element_end('body');
+ common_element_end('html');
+ } else {
+ common_redirect(common_local_url('showfavorites',
+ array('nickname' => $user->nickname)));
+ }
+ }
}
diff --git a/_darcs/pristine/actions/doc.php b/_darcs/pristine/actions/doc.php
index f3327048f..0cf665d68 100644
--- a/_darcs/pristine/actions/doc.php
+++ b/_darcs/pristine/actions/doc.php
@@ -21,18 +21,18 @@ if (!defined('LACONICA')) { exit(1); }
class DocAction extends Action {
- function handle($args) {
- parent::handle($args);
- $title = $this->trimmed('title');
- $filename = INSTALLDIR.'/doc/'.$title;
- if (!file_exists($filename)) {
- common_user_error(_('No such document.'));
- return;
- }
- $c = file_get_contents($filename);
- $output = common_markup_to_html($c);
- common_show_header(_(ucfirst($title)));
- common_raw($output);
- common_show_footer();
- }
+ function handle($args) {
+ parent::handle($args);
+ $title = $this->trimmed('title');
+ $filename = INSTALLDIR.'/doc/'.$title;
+ if (!file_exists($filename)) {
+ common_user_error(_('No such document.'));
+ return;
+ }
+ $c = file_get_contents($filename);
+ $output = common_markup_to_html($c);
+ common_show_header(_(ucfirst($title)));
+ common_raw($output);
+ common_show_footer();
+ }
}
diff --git a/_darcs/pristine/actions/emailsettings.php b/_darcs/pristine/actions/emailsettings.php
index b35b4d28e..b77817c8e 100644
--- a/_darcs/pristine/actions/emailsettings.php
+++ b/_darcs/pristine/actions/emailsettings.php
@@ -23,308 +23,308 @@ require_once(INSTALLDIR.'/lib/settingsaction.php');
class EmailsettingsAction extends SettingsAction {
- function get_instructions() {
- return _('Manage how you get email from %%site.name%%.');
- }
-
- function show_form($msg=NULL, $success=false) {
- $user = common_current_user();
- $this->form_header(_('Email Settings'), $msg, $success);
- common_element_start('form', array('method' => 'post',
- 'id' => 'emailsettings',
- 'action' =>
- common_local_url('emailsettings')));
- common_hidden('token', common_session_token());
-
- common_element('h2', NULL, _('Address'));
-
- if ($user->email) {
- common_element_start('p');
- common_element('span', 'address confirmed', $user->email);
- common_element('span', 'input_instructions',
- _('Current confirmed email address.'));
- common_hidden('email', $user->email);
- common_element_end('p');
- common_submit('remove', _('Remove'));
- } else {
- $confirm = $this->get_confirmation();
- if ($confirm) {
- common_element_start('p');
- common_element('span', 'address unconfirmed', $confirm->address);
- common_element('span', 'input_instructions',
- _('Awaiting confirmation on this address. Check your inbox (and spam box!) for a message with further instructions.'));
- common_hidden('email', $confirm->address);
- common_element_end('p');
- common_submit('cancel', _('Cancel'));
- } else {
- common_input('email', _('Email Address'),
- ($this->arg('email')) ? $this->arg('email') : NULL,
- _('Email address, like "UserName@example.org"'));
- common_submit('add', _('Add'));
- }
- }
-
- if ($user->email) {
- common_element('h2', NULL, _('Incoming email'));
-
- if ($user->incomingemail) {
- common_element_start('p');
- common_element('span', 'address', $user->incomingemail);
- common_element('span', 'input_instructions',
- _('Send email to this address to post new notices.'));
- common_element_end('p');
- common_submit('removeincoming', _('Remove'));
- }
-
- common_element_start('p');
- common_element('span', 'input_instructions',
- _('Make a new email address for posting to; cancels the old one.'));
- common_element_end('p');
- common_submit('newincoming', _('New'));
- }
-
- common_element('h2', NULL, _('Preferences'));
-
- common_checkbox('emailnotifysub',
- _('Send me notices of new subscriptions through email.'),
- $user->emailnotifysub);
- common_checkbox('emailnotifyfav',
- _('Send me email when someone adds my notice as a favorite.'),
- $user->emailnotifyfav);
- common_checkbox('emailnotifymsg',
- _('Send me email when someone sends me a private message.'),
- $user->emailnotifymsg);
- common_checkbox('emailnotifynudge',
- _('Allow friends to nudge me and send me an email.'),
- $user->emailnotifynudge);
- common_checkbox('emailpost',
- _('I want to post notices by email.'),
- $user->emailpost);
- common_checkbox('emailmicroid',
- _('Publish a MicroID for my email address.'),
- $user->emailmicroid);
-
- common_submit('save', _('Save'));
-
- common_element_end('form');
- common_show_footer();
- }
-
- function get_confirmation() {
- $user = common_current_user();
- $confirm = new Confirm_address();
- $confirm->user_id = $user->id;
- $confirm->address_type = 'email';
- if ($confirm->find(TRUE)) {
- return $confirm;
- } else {
- return NULL;
- }
- }
-
- function handle_post() {
-
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- if ($this->arg('save')) {
- $this->save_preferences();
- } else if ($this->arg('add')) {
- $this->add_address();
- } else if ($this->arg('cancel')) {
- $this->cancel_confirmation();
- } else if ($this->arg('remove')) {
- $this->remove_address();
- } else if ($this->arg('removeincoming')) {
- $this->remove_incoming();
- } else if ($this->arg('newincoming')) {
- $this->new_incoming();
- } else {
- $this->show_form(_('Unexpected form submission.'));
- }
- }
-
- function save_preferences() {
-
- $emailnotifysub = $this->boolean('emailnotifysub');
- $emailnotifyfav = $this->boolean('emailnotifyfav');
- $emailnotifymsg = $this->boolean('emailnotifymsg');
- $emailnotifynudge = $this->boolean('emailnotifynudge');
- $emailmicroid = $this->boolean('emailmicroid');
- $emailpost = $this->boolean('emailpost');
-
- $user = common_current_user();
-
- assert(!is_null($user)); # should already be checked
-
- $user->query('BEGIN');
-
- $original = clone($user);
-
- $user->emailnotifysub = $emailnotifysub;
- $user->emailnotifyfav = $emailnotifyfav;
- $user->emailnotifymsg = $emailnotifymsg;
- $user->emailnotifynudge = $emailnotifynudge;
- $user->emailmicroid = $emailmicroid;
- $user->emailpost = $emailpost;
-
- $result = $user->update($original);
-
- if ($result === FALSE) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
-
- $user->query('COMMIT');
-
- $this->show_form(_('Preferences saved.'), true);
- }
-
- function add_address() {
-
- $user = common_current_user();
-
- $email = $this->trimmed('email');
-
- # Some validation
-
- if (!$email) {
- $this->show_form(_('No email address.'));
- return;
- }
-
- $email = common_canonical_email($email);
-
- if (!$email) {
- $this->show_form(_('Cannot normalize that email address'));
- return;
- }
- if (!Validate::email($email, true)) {
- $this->show_form(_('Not a valid email address'));
- return;
- } else if ($user->email == $email) {
- $this->show_form(_('That is already your email address.'));
- return;
- } else if ($this->email_exists($email)) {
- $this->show_form(_('That email address already belongs to another user.'));
- return;
- }
-
- $confirm = new Confirm_address();
- $confirm->address = $email;
- $confirm->address_type = 'email';
- $confirm->user_id = $user->id;
- $confirm->code = common_confirmation_code(64);
-
- $result = $confirm->insert();
-
- if ($result === FALSE) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
- common_server_error(_('Couldn\'t insert confirmation code.'));
- return;
- }
-
- mail_confirm_address($user, $confirm->code, $user->nickname, $email);
-
- $msg = _('A confirmation code was sent to the email address you added. Check your inbox (and spam box!) for the code and instructions on how to use it.');
-
- $this->show_form($msg, TRUE);
- }
-
- function cancel_confirmation() {
- $email = $this->arg('email');
- $confirm = $this->get_confirmation();
- if (!$confirm) {
- $this->show_form(_('No pending confirmation to cancel.'));
- return;
- }
- if ($confirm->address != $email) {
- $this->show_form(_('That is the wrong IM address.'));
- return;
- }
+ function get_instructions() {
+ return _('Manage how you get email from %%site.name%%.');
+ }
+
+ function show_form($msg=NULL, $success=false) {
+ $user = common_current_user();
+ $this->form_header(_('Email Settings'), $msg, $success);
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'emailsettings',
+ 'action' =>
+ common_local_url('emailsettings')));
+ common_hidden('token', common_session_token());
+
+ common_element('h2', NULL, _('Address'));
+
+ if ($user->email) {
+ common_element_start('p');
+ common_element('span', 'address confirmed', $user->email);
+ common_element('span', 'input_instructions',
+ _('Current confirmed email address.'));
+ common_hidden('email', $user->email);
+ common_element_end('p');
+ common_submit('remove', _('Remove'));
+ } else {
+ $confirm = $this->get_confirmation();
+ if ($confirm) {
+ common_element_start('p');
+ common_element('span', 'address unconfirmed', $confirm->address);
+ common_element('span', 'input_instructions',
+ _('Awaiting confirmation on this address. Check your inbox (and spam box!) for a message with further instructions.'));
+ common_hidden('email', $confirm->address);
+ common_element_end('p');
+ common_submit('cancel', _('Cancel'));
+ } else {
+ common_input('email', _('Email Address'),
+ ($this->arg('email')) ? $this->arg('email') : NULL,
+ _('Email address, like "UserName@example.org"'));
+ common_submit('add', _('Add'));
+ }
+ }
+
+ if ($user->email) {
+ common_element('h2', NULL, _('Incoming email'));
+
+ if ($user->incomingemail) {
+ common_element_start('p');
+ common_element('span', 'address', $user->incomingemail);
+ common_element('span', 'input_instructions',
+ _('Send email to this address to post new notices.'));
+ common_element_end('p');
+ common_submit('removeincoming', _('Remove'));
+ }
+
+ common_element_start('p');
+ common_element('span', 'input_instructions',
+ _('Make a new email address for posting to; cancels the old one.'));
+ common_element_end('p');
+ common_submit('newincoming', _('New'));
+ }
+
+ common_element('h2', NULL, _('Preferences'));
+
+ common_checkbox('emailnotifysub',
+ _('Send me notices of new subscriptions through email.'),
+ $user->emailnotifysub);
+ common_checkbox('emailnotifyfav',
+ _('Send me email when someone adds my notice as a favorite.'),
+ $user->emailnotifyfav);
+ common_checkbox('emailnotifymsg',
+ _('Send me email when someone sends me a private message.'),
+ $user->emailnotifymsg);
+ common_checkbox('emailnotifynudge',
+ _('Allow friends to nudge me and send me an email.'),
+ $user->emailnotifynudge);
+ common_checkbox('emailpost',
+ _('I want to post notices by email.'),
+ $user->emailpost);
+ common_checkbox('emailmicroid',
+ _('Publish a MicroID for my email address.'),
+ $user->emailmicroid);
+
+ common_submit('save', _('Save'));
+
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function get_confirmation() {
+ $user = common_current_user();
+ $confirm = new Confirm_address();
+ $confirm->user_id = $user->id;
+ $confirm->address_type = 'email';
+ if ($confirm->find(TRUE)) {
+ return $confirm;
+ } else {
+ return NULL;
+ }
+ }
+
+ function handle_post() {
+
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ if ($this->arg('save')) {
+ $this->save_preferences();
+ } else if ($this->arg('add')) {
+ $this->add_address();
+ } else if ($this->arg('cancel')) {
+ $this->cancel_confirmation();
+ } else if ($this->arg('remove')) {
+ $this->remove_address();
+ } else if ($this->arg('removeincoming')) {
+ $this->remove_incoming();
+ } else if ($this->arg('newincoming')) {
+ $this->new_incoming();
+ } else {
+ $this->show_form(_('Unexpected form submission.'));
+ }
+ }
+
+ function save_preferences() {
+
+ $emailnotifysub = $this->boolean('emailnotifysub');
+ $emailnotifyfav = $this->boolean('emailnotifyfav');
+ $emailnotifymsg = $this->boolean('emailnotifymsg');
+ $emailnotifynudge = $this->boolean('emailnotifynudge');
+ $emailmicroid = $this->boolean('emailmicroid');
+ $emailpost = $this->boolean('emailpost');
+
+ $user = common_current_user();
+
+ assert(!is_null($user)); # should already be checked
+
+ $user->query('BEGIN');
+
+ $original = clone($user);
+
+ $user->emailnotifysub = $emailnotifysub;
+ $user->emailnotifyfav = $emailnotifyfav;
+ $user->emailnotifymsg = $emailnotifymsg;
+ $user->emailnotifynudge = $emailnotifynudge;
+ $user->emailmicroid = $emailmicroid;
+ $user->emailpost = $emailpost;
+
+ $result = $user->update($original);
+
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
+
+ $user->query('COMMIT');
+
+ $this->show_form(_('Preferences saved.'), true);
+ }
+
+ function add_address() {
+
+ $user = common_current_user();
+
+ $email = $this->trimmed('email');
+
+ # Some validation
+
+ if (!$email) {
+ $this->show_form(_('No email address.'));
+ return;
+ }
+
+ $email = common_canonical_email($email);
+
+ if (!$email) {
+ $this->show_form(_('Cannot normalize that email address'));
+ return;
+ }
+ if (!Validate::email($email, true)) {
+ $this->show_form(_('Not a valid email address'));
+ return;
+ } else if ($user->email == $email) {
+ $this->show_form(_('That is already your email address.'));
+ return;
+ } else if ($this->email_exists($email)) {
+ $this->show_form(_('That email address already belongs to another user.'));
+ return;
+ }
+
+ $confirm = new Confirm_address();
+ $confirm->address = $email;
+ $confirm->address_type = 'email';
+ $confirm->user_id = $user->id;
+ $confirm->code = common_confirmation_code(64);
+
+ $result = $confirm->insert();
+
+ if ($result === FALSE) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_server_error(_('Couldn\'t insert confirmation code.'));
+ return;
+ }
+
+ mail_confirm_address($user, $confirm->code, $user->nickname, $email);
+
+ $msg = _('A confirmation code was sent to the email address you added. Check your inbox (and spam box!) for the code and instructions on how to use it.');
+
+ $this->show_form($msg, TRUE);
+ }
+
+ function cancel_confirmation() {
+ $email = $this->arg('email');
+ $confirm = $this->get_confirmation();
+ if (!$confirm) {
+ $this->show_form(_('No pending confirmation to cancel.'));
+ return;
+ }
+ if ($confirm->address != $email) {
+ $this->show_form(_('That is the wrong IM address.'));
+ return;
+ }
$result = $confirm->delete();
if (!$result) {
- common_log_db_error($confirm, 'DELETE', __FILE__);
+ common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
return;
}
$this->show_form(_('Confirmation cancelled.'), TRUE);
- }
-
- function remove_address() {
-
- $user = common_current_user();
- $email = $this->arg('email');
-
- # Maybe an old tab open...?
-
- if ($user->email != $email) {
- $this->show_form(_('That is not your email address.'));
- return;
- }
-
- $user->query('BEGIN');
- $original = clone($user);
- $user->email = NULL;
- $result = $user->updateKeys($original);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
- $user->query('COMMIT');
-
- $this->show_form(_('The address was removed.'), TRUE);
- }
-
- function remove_incoming() {
- $user = common_current_user();
-
- if (!$user->incomingemail) {
- $this->show_form(_('No incoming email address.'));
- return;
- }
-
- $orig = clone($user);
- $user->incomingemail = NULL;
-
- if (!$user->updateKeys($orig)) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- $this->server_error(_("Couldn't update user record."));
- }
-
- $this->show_form(_('Incoming email address removed.'), TRUE);
- }
-
- function new_incoming() {
- $user = common_current_user();
-
- $orig = clone($user);
- $user->incomingemail = mail_new_incoming_address();
-
- if (!$user->updateKeys($orig)) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- $this->server_error(_("Couldn't update user record."));
- }
-
- $this->show_form(_('New incoming email address added.'), TRUE);
- }
-
- function email_exists($email) {
- $user = common_current_user();
- $other = User::staticGet('email', $email);
- if (!$other) {
- return false;
- } else {
- return $other->id != $user->id;
- }
- }
+ }
+
+ function remove_address() {
+
+ $user = common_current_user();
+ $email = $this->arg('email');
+
+ # Maybe an old tab open...?
+
+ if ($user->email != $email) {
+ $this->show_form(_('That is not your email address.'));
+ return;
+ }
+
+ $user->query('BEGIN');
+ $original = clone($user);
+ $user->email = NULL;
+ $result = $user->updateKeys($original);
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
+ $user->query('COMMIT');
+
+ $this->show_form(_('The address was removed.'), TRUE);
+ }
+
+ function remove_incoming() {
+ $user = common_current_user();
+
+ if (!$user->incomingemail) {
+ $this->show_form(_('No incoming email address.'));
+ return;
+ }
+
+ $orig = clone($user);
+ $user->incomingemail = NULL;
+
+ if (!$user->updateKeys($orig)) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ $this->server_error(_("Couldn't update user record."));
+ }
+
+ $this->show_form(_('Incoming email address removed.'), TRUE);
+ }
+
+ function new_incoming() {
+ $user = common_current_user();
+
+ $orig = clone($user);
+ $user->incomingemail = mail_new_incoming_address();
+
+ if (!$user->updateKeys($orig)) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ $this->server_error(_("Couldn't update user record."));
+ }
+
+ $this->show_form(_('New incoming email address added.'), TRUE);
+ }
+
+ function email_exists($email) {
+ $user = common_current_user();
+ $other = User::staticGet('email', $email);
+ if (!$other) {
+ return false;
+ } else {
+ return $other->id != $user->id;
+ }
+ }
}
diff --git a/_darcs/pristine/actions/facebookhome.php b/_darcs/pristine/actions/facebookhome.php
index 8ee2d4cd3..c964f451a 100644
--- a/_darcs/pristine/actions/facebookhome.php
+++ b/_darcs/pristine/actions/facebookhome.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,110 +23,110 @@ require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebookhomeAction extends FacebookAction {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $this->login();
- }
+ $this->login();
+ }
- function login() {
+ function login() {
- $user = null;
+ $user = null;
- $facebook = $this->get_facebook();
- $fbuid = $facebook->require_login();
+ $facebook = $this->get_facebook();
+ $fbuid = $facebook->require_login();
- # check to see whether there's already a Facebook link for this user
- $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
+ # check to see whether there's already a Facebook link for this user
+ $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
- if ($flink) {
+ if ($flink) {
- $user = $flink->getUser();
- $this->show_home($facebook, $fbuid, $user);
+ $user = $flink->getUser();
+ $this->show_home($facebook, $fbuid, $user);
- } else {
+ } else {
- # Make the user put in her Laconica creds
- $nickname = common_canonical_nickname($this->trimmed('nickname'));
- $password = $this->arg('password');
+ # Make the user put in her Laconica creds
+ $nickname = common_canonical_nickname($this->trimmed('nickname'));
+ $password = $this->arg('password');
- if ($nickname) {
+ if ($nickname) {
- if (common_check_user($nickname, $password)) {
+ if (common_check_user($nickname, $password)) {
- $user = User::staticGet('nickname', $nickname);
+ $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- echo '<fb:error message="Coudln\'t get user!" />';
- $this->show_login_form();
- }
+ if (!$user) {
+ echo '<fb:error message="Coudln\'t get user!" />';
+ $this->show_login_form();
+ }
- $flink = DB_DataObject::factory('foreign_link');
- $flink->user_id = $user->id;
- $flink->foreign_id = $fbuid;
- $flink->service = 2; # Facebook
- $flink->created = common_sql_now();
+ $flink = DB_DataObject::factory('foreign_link');
+ $flink->user_id = $user->id;
+ $flink->foreign_id = $fbuid;
+ $flink->service = 2; # Facebook
+ $flink->created = common_sql_now();
- # $this->set_flags($flink, $noticesync, $replysync, $friendsync);
+ # $this->set_flags($flink, $noticesync, $replysync, $friendsync);
- $flink_id = $flink->insert();
+ $flink_id = $flink->insert();
- if ($flink_id) {
- echo '<fb:success message="You can now use the Identi.ca from Facebook!" />';
- }
+ if ($flink_id) {
+ echo '<fb:success message="You can now use the Identi.ca from Facebook!" />';
+ }
- $this->show_home($facebook, $fbuid, $user);
+ $this->show_home($facebook, $fbuid, $user);
- return;
- } else {
- echo '<fb:error message="Incorrect username or password." />';
- }
- }
+ return;
+ } else {
+ echo '<fb:error message="Incorrect username or password." />';
+ }
+ }
- $this->show_login_form();
- }
+ $this->show_login_form();
+ }
- }
+ }
- function show_home($facebook, $fbuid, $user) {
+ function show_home($facebook, $fbuid, $user) {
- $this->show_header('Home');
+ $this->show_header('Home');
- echo $this->show_notices($user);
- $this->update_profile_box($facebook, $fbuid, $user);
+ echo $this->show_notices($user);
+ $this->update_profile_box($facebook, $fbuid, $user);
- $this->show_footer();
- }
+ $this->show_footer();
+ }
- function show_notices($user) {
+ function show_notices($user) {
- $page = $this->trimmed('page');
- if (!$page) {
- $page = 1;
- }
+ $page = $this->trimmed('page');
+ if (!$page) {
+ $page = 1;
+ }
- $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
- echo '<ul id="notices">';
+ echo '<ul id="notices">';
- $cnt = 0;
+ $cnt = 0;
- while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
- $cnt++;
+ while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
+ $cnt++;
- if ($cnt > NOTICES_PER_PAGE) {
- break;
- }
+ if ($cnt > NOTICES_PER_PAGE) {
+ break;
+ }
- echo $this->render_notice($notice);
- }
+ echo $this->render_notice($notice);
+ }
- echo '<ul>';
+ echo '<ul>';
- $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'index.php', array('nickname' => $user->nickname));
+ $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'index.php', array('nickname' => $user->nickname));
- }
+ }
}
diff --git a/_darcs/pristine/actions/facebookinvite.php b/_darcs/pristine/actions/facebookinvite.php
index 68b351fb9..3a85a7c5c 100644
--- a/_darcs/pristine/actions/facebookinvite.php
+++ b/_darcs/pristine/actions/facebookinvite.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,24 +23,24 @@ require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebookinviteAction extends FacebookAction {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $this->display();
- }
+ $this->display();
+ }
- function display() {
+ function display() {
- $facebook = $this->get_facebook();
+ $facebook = $this->get_facebook();
- $fbuid = $facebook->require_login();
+ $fbuid = $facebook->require_login();
- $this->show_header('Invite');
+ $this->show_header('Invite');
- echo '<h2>Coming soon...</h2>';
+ echo '<h2>Coming soon...</h2>';
- $this->show_footer();
+ $this->show_footer();
- }
+ }
}
diff --git a/_darcs/pristine/actions/facebookremove.php b/_darcs/pristine/actions/facebookremove.php
index 2a7bdd03e..1215f6622 100644
--- a/_darcs/pristine/actions/facebookremove.php
+++ b/_darcs/pristine/actions/facebookremove.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,43 +23,43 @@ require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebookremoveAction extends FacebookAction {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $secret = common_config('facebook', 'secret');
+ $secret = common_config('facebook', 'secret');
- $sig = '';
+ $sig = '';
- ksort($_POST);
+ ksort($_POST);
- foreach ($_POST as $key => $val) {
- if (substr($key, 0, 7) == 'fb_sig_') {
- $sig .= substr($key, 7) . '=' . $val;
- }
- }
+ foreach ($_POST as $key => $val) {
+ if (substr($key, 0, 7) == 'fb_sig_') {
+ $sig .= substr($key, 7) . '=' . $val;
+ }
+ }
- $sig .= $secret;
- $verify = md5($sig);
+ $sig .= $secret;
+ $verify = md5($sig);
- if ($verify == $this->arg('fb_sig')) {
+ if ($verify == $this->arg('fb_sig')) {
- $flink = Foreign_link::getByForeignID($this->arg('fb_sig_user'), 2);
+ $flink = Foreign_link::getByForeignID($this->arg('fb_sig_user'), 2);
- common_debug("Removing foreign link to Facebook - local user ID: $flink->user_id, Facebook ID: $flink->foreign_id");
+ common_debug("Removing foreign link to Facebook - local user ID: $flink->user_id, Facebook ID: $flink->foreign_id");
- $result = $flink->delete();
+ $result = $flink->delete();
- if (!$result) {
- common_log_db_error($flink, 'DELETE', __FILE__);
- common_server_error(_('Couldn\'t remove Facebook user.'));
- return;
- }
+ if (!$result) {
+ common_log_db_error($flink, 'DELETE', __FILE__);
+ common_server_error(_('Couldn\'t remove Facebook user.'));
+ return;
+ }
- } else {
- # Someone bad tried to remove facebook link?
- common_log(LOG_ERR, "Someone from $_SERVER[REMOTE_ADDR] " .
- 'unsuccessfully tried to remove a foreign link to Facebook!');
- }
- }
+ } else {
+ # Someone bad tried to remove facebook link?
+ common_log(LOG_ERR, "Someone from $_SERVER[REMOTE_ADDR] " .
+ 'unsuccessfully tried to remove a foreign link to Facebook!');
+ }
+ }
}
diff --git a/_darcs/pristine/actions/facebooksettings.php b/_darcs/pristine/actions/facebooksettings.php
index 4d7000d60..a5ad9d07a 100644
--- a/_darcs/pristine/actions/facebooksettings.php
+++ b/_darcs/pristine/actions/facebooksettings.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,30 +23,30 @@ require_once(INSTALLDIR.'/lib/facebookaction.php');
class FacebooksettingsAction extends FacebookAction {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $this->display();
- }
+ $this->display();
+ }
- function display() {
+ function display() {
- $facebook = $this->get_facebook();
+ $facebook = $this->get_facebook();
- $fbuid = $facebook->require_login();
+ $fbuid = $facebook->require_login();
- $fbml = '<fb:if-section-not-added section="profile">'
- .'<h2>Add an Identi.ca box to your profile!</h2>'
- .'<fb:add-section-button section="profile"/>'
- .'</fb:if-section-not-added>';
+ $fbml = '<fb:if-section-not-added section="profile">'
+ .'<h2>Add an Identi.ca box to your profile!</h2>'
+ .'<fb:add-section-button section="profile"/>'
+ .'</fb:if-section-not-added>';
- $this->show_header('Settings');
+ $this->show_header('Settings');
- echo $fbml;
+ echo $fbml;
- $this->show_footer();
+ $this->show_footer();
- }
+ }
}
diff --git a/_darcs/pristine/actions/favor.php b/_darcs/pristine/actions/favor.php
index aede32902..c0b0324b5 100644
--- a/_darcs/pristine/actions/favor.php
+++ b/_darcs/pristine/actions/favor.php
@@ -23,72 +23,72 @@ require_once(INSTALLDIR.'/lib/mail.php');
class FavorAction extends Action {
- function handle($args) {
- parent::handle($args);
-
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- return;
- }
-
- $user = common_current_user();
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
- return;
- }
-
- $id = $this->trimmed('notice');
-
- $notice = Notice::staticGet($id);
-
- # CSRF protection
-
- $token = $this->trimmed('token-'.$notice->id);
- if (!$token || $token != common_session_token()) {
- $this->client_error(_("There was a problem with your session token. Try again, please."));
- return;
- }
-
- if ($user->hasFave($notice)) {
- $this->client_error(_('This notice is already a favorite!'));
- return;
- }
-
- $fave = Fave::addNew($user, $notice);
-
- if (!$fave) {
- $this->server_error(_('Could not create favorite.'));
- return;
- }
-
- $this->notify($fave, $notice, $user);
- $user->blowFavesCache();
-
- if ($this->boolean('ajax')) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Disfavor favorite'));
- common_element_end('head');
- common_element_start('body');
- common_disfavor_form($notice);
- common_element_end('body');
- common_element_end('html');
- } else {
- common_redirect(common_local_url('showfavorites',
- array('nickname' => $user->nickname)));
- }
- }
-
- function notify($fave, $notice, $user) {
- $other = User::staticGet('id', $notice->profile_id);
- if ($other && $other->id != $user->id) {
- if ($other->email && $other->emailnotifyfav) {
- mail_notify_fave($other, $user, $notice);
- }
- # XXX: notify by IM
- # XXX: notify by SMS
- }
- }
+ function handle($args) {
+ parent::handle($args);
+
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ return;
+ }
+
+ $user = common_current_user();
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
+ return;
+ }
+
+ $id = $this->trimmed('notice');
+
+ $notice = Notice::staticGet($id);
+
+ # CSRF protection
+
+ $token = $this->trimmed('token-'.$notice->id);
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_("There was a problem with your session token. Try again, please."));
+ return;
+ }
+
+ if ($user->hasFave($notice)) {
+ $this->client_error(_('This notice is already a favorite!'));
+ return;
+ }
+
+ $fave = Fave::addNew($user, $notice);
+
+ if (!$fave) {
+ $this->server_error(_('Could not create favorite.'));
+ return;
+ }
+
+ $this->notify($fave, $notice, $user);
+ $user->blowFavesCache();
+
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Disfavor favorite'));
+ common_element_end('head');
+ common_element_start('body');
+ common_disfavor_form($notice);
+ common_element_end('body');
+ common_element_end('html');
+ } else {
+ common_redirect(common_local_url('showfavorites',
+ array('nickname' => $user->nickname)));
+ }
+ }
+
+ function notify($fave, $notice, $user) {
+ $other = User::staticGet('id', $notice->profile_id);
+ if ($other && $other->id != $user->id) {
+ if ($other->email && $other->emailnotifyfav) {
+ mail_notify_fave($other, $user, $notice);
+ }
+ # XXX: notify by IM
+ # XXX: notify by SMS
+ }
+ }
}
diff --git a/_darcs/pristine/actions/favorited.php b/_darcs/pristine/actions/favorited.php
index dc8070d06..6a465df96 100644
--- a/_darcs/pristine/actions/favorited.php
+++ b/_darcs/pristine/actions/favorited.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,77 +23,77 @@ require_once(INSTALLDIR.'/lib/stream.php');
class FavoritedAction extends StreamAction {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+ $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
- common_show_header(_('Popular notices'),
- array($this, 'show_header'), NULL,
- array($this, 'show_top'));
+ common_show_header(_('Popular notices'),
+ array($this, 'show_header'), NULL,
+ array($this, 'show_top'));
- $this->show_notices($page);
+ $this->show_notices($page);
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_top() {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- $this->public_views_menu();
- }
+ function show_top() {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ $this->public_views_menu();
+ }
- function show_header() {
+ function show_header() {
return;
- }
+ }
- function get_instructions() {
- return _('Showing recently popular notices');
- }
+ function get_instructions() {
+ return _('Showing recently popular notices');
+ }
- function show_notices($page) {
+ function show_notices($page) {
- $qry = 'SELECT notice.*, sum(exp(-(now() - fave.modified) / %s)) as weight ' .
- 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
- 'GROUP BY fave.notice_id ' .
- 'ORDER BY weight DESC';
+ $qry = 'SELECT notice.*, sum(exp(-(now() - fave.modified) / %s)) as weight ' .
+ 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
+ 'GROUP BY fave.notice_id ' .
+ 'ORDER BY weight DESC';
- $offset = ($page - 1) * NOTICES_PER_PAGE;
- $limit = NOTICES_PER_PAGE + 1;
+ $offset = ($page - 1) * NOTICES_PER_PAGE;
+ $limit = NOTICES_PER_PAGE + 1;
- if (common_config('db','type') == 'pgsql') {
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
- } else {
- $qry .= ' LIMIT ' . $offset . ', ' . $limit;
- }
+ if (common_config('db','type') == 'pgsql') {
+ $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+ } else {
+ $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+ }
- # Figure out how to cache this query
+ # Figure out how to cache this query
- $notice = new Notice;
- $notice->query(sprintf($qry, common_config('popular', 'dropoff')));
+ $notice = new Notice;
+ $notice->query(sprintf($qry, common_config('popular', 'dropoff')));
- common_element_start('ul', array('id' => 'notices'));
+ common_element_start('ul', array('id' => 'notices'));
- $cnt = 0;
+ $cnt = 0;
- while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
- $cnt++;
+ while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
+ $cnt++;
- if ($cnt > NOTICES_PER_PAGE) {
- break;
- }
+ if ($cnt > NOTICES_PER_PAGE) {
+ break;
+ }
$item = new NoticeListItem($notice);
$item->show();
- }
+ }
- common_element_end('ul');
+ common_element_end('ul');
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'favorited');
- }
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'favorited');
+ }
}
diff --git a/_darcs/pristine/actions/favoritesrss.php b/_darcs/pristine/actions/favoritesrss.php
index 25dd3861f..642d4f880 100644
--- a/_darcs/pristine/actions/favoritesrss.php
+++ b/_darcs/pristine/actions/favoritesrss.php
@@ -25,49 +25,49 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class FavoritesrssAction extends Rss10Action {
- var $user = NULL;
-
- function init() {
- $nickname = $this->trimmed('nickname');
- $this->user = User::staticGet('nickname', $nickname);
+ var $user = NULL;
+
+ function init() {
+ $nickname = $this->trimmed('nickname');
+ $this->user = User::staticGet('nickname', $nickname);
- if (!$this->user) {
- common_user_error(_('No such user.'));
- return false;
- } else {
- return true;
- }
- }
+ if (!$this->user) {
+ common_user_error(_('No such user.'));
+ return false;
+ } else {
+ return true;
+ }
+ }
- function get_notices($limit=0) {
+ function get_notices($limit=0) {
- $user = $this->user;
+ $user = $this->user;
- $notice = $user->favoriteNotices(0, $limit);
+ $notice = $user->favoriteNotices(0, $limit);
- $notices = array();
+ $notices = array();
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
- return $notices;
- }
+ return $notices;
+ }
- function get_channel() {
- $user = $this->user;
- $c = array('url' => common_local_url('favoritesrss',
- array('nickname' =>
- $user->nickname)),
- 'title' => sprintf(_("%s favorite notices"), $user->nickname),
- 'link' => common_local_url('showfavorites',
- array('nickname' =>
- $user->nickname)),
- 'description' => sprintf(_('Feed of favorite notices of %s'), $user->nickname));
- return $c;
- }
+ function get_channel() {
+ $user = $this->user;
+ $c = array('url' => common_local_url('favoritesrss',
+ array('nickname' =>
+ $user->nickname)),
+ 'title' => sprintf(_("%s favorite notices"), $user->nickname),
+ 'link' => common_local_url('showfavorites',
+ array('nickname' =>
+ $user->nickname)),
+ 'description' => sprintf(_('Feed of favorite notices of %s'), $user->nickname));
+ return $c;
+ }
- function get_image() {
- return NULL;
- }
+ function get_image() {
+ return NULL;
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/featured.php b/_darcs/pristine/actions/featured.php
index 96fbd89ab..2ff4f7745 100644
--- a/_darcs/pristine/actions/featured.php
+++ b/_darcs/pristine/actions/featured.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -24,79 +24,79 @@ require_once(INSTALLDIR.'/lib/profilelist.php');
class FeaturedAction extends StreamAction {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+ $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
- common_show_header(_('Featured users'),
- array($this, 'show_header'), NULL,
- array($this, 'show_top'));
+ common_show_header(_('Featured users'),
+ array($this, 'show_header'), NULL,
+ array($this, 'show_top'));
- $this->show_notices($page);
+ $this->show_notices($page);
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_top() {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- $this->public_views_menu();
- }
+ function show_top() {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ $this->public_views_menu();
+ }
- function show_header() {
- }
+ function show_header() {
+ }
- function get_instructions() {
- return _('Featured users');
- }
+ function get_instructions() {
+ return _('Featured users');
+ }
- function show_notices($page) {
+ function show_notices($page) {
- // XXX: Note I'm doing it this two-stage way because a raw query
- // with a JOIN was *not* working. --Zach
+ // XXX: Note I'm doing it this two-stage way because a raw query
+ // with a JOIN was *not* working. --Zach
- $featured_nicks = common_config('nickname', 'featured');
+ $featured_nicks = common_config('nickname', 'featured');
- if (count($featured_nicks) > 0) {
+ if (count($featured_nicks) > 0) {
- $quoted = array();
+ $quoted = array();
- foreach ($featured_nicks as $nick) {
- $quoted[] = "'$nick'";
- }
+ foreach ($featured_nicks as $nick) {
+ $quoted[] = "'$nick'";
+ }
- $user = new User;
- $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
- $user->limit(($page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
- $user->orderBy('user.nickname ASC');
+ $user = new User;
+ $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
+ $user->limit(($page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
+ $user->orderBy('user.nickname ASC');
- $user->find();
+ $user->find();
- $profile_ids = array();
+ $profile_ids = array();
- while ($user->fetch()) {
- $profile_ids[] = $user->id;
- }
+ while ($user->fetch()) {
+ $profile_ids[] = $user->id;
+ }
- $profile = new Profile;
- $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
- $profile->orderBy('nickname ASC');
+ $profile = new Profile;
+ $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
+ $profile->orderBy('nickname ASC');
- $cnt = $profile->find();
+ $cnt = $profile->find();
- if ($cnt > 0) {
- $featured = new ProfileList($profile);
- $featured->show_list();
- }
+ if ($cnt > 0) {
+ $featured = new ProfileList($profile);
+ $featured->show_list();
+ }
- $profile->free();
+ $profile->free();
- common_pagination($page > 1, $cnt > PROFILES_PER_PAGE, $page, 'featured');
- }
- }
+ common_pagination($page > 1, $cnt > PROFILES_PER_PAGE, $page, 'featured');
+ }
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/finishaddopenid.php b/_darcs/pristine/actions/finishaddopenid.php
index 54d81b0b4..07024e091 100644
--- a/_darcs/pristine/actions/finishaddopenid.php
+++ b/_darcs/pristine/actions/finishaddopenid.php
@@ -23,81 +23,81 @@ require_once(INSTALLDIR.'/lib/openid.php');
class FinishaddopenidAction extends Action {
- function handle($args) {
- parent::handle($args);
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- } else {
- $this->try_login();
- }
- }
-
- function try_login() {
-
- $consumer =& oid_consumer();
-
- $response = $consumer->complete(common_local_url('finishaddopenid'));
-
- if ($response->status == Auth_OpenID_CANCEL) {
- $this->message(_('OpenID authentication cancelled.'));
- return;
- } else if ($response->status == Auth_OpenID_FAILURE) {
- // Authentication failed; display the error message.
- $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
- } else if ($response->status == Auth_OpenID_SUCCESS) {
-
- $display = $response->getDisplayIdentifier();
- $canonical = ($response->endpoint && $response->endpoint->canonicalID) ?
- $response->endpoint->canonicalID : $display;
-
- $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
-
- if ($sreg_resp) {
- $sreg = $sreg_resp->contents();
- }
-
- $cur =& common_current_user();
- $other = oid_get_user($canonical);
-
- if ($other) {
- if ($other->id == $cur->id) {
- $this->message(_('You already have this OpenID!'));
- } else {
- $this->message(_('Someone else already has this OpenID.'));
- }
- return;
- }
-
- # start a transaction
-
- $cur->query('BEGIN');
-
- $result = oid_link_user($cur->id, $canonical, $display);
-
- if (!$result) {
- $this->message(_('Error connecting user.'));
- return;
- }
- if ($sreg) {
- if (!oid_update_user($cur, $sreg)) {
- $this->message(_('Error updating profile'));
- return;
- }
- }
-
- # success!
-
- $cur->query('COMMIT');
-
- oid_set_last($display);
-
- common_redirect(common_local_url('openidsettings'));
- }
- }
-
- function message($msg) {
- common_show_header(_('OpenID Login'));
- common_element('p', NULL, $msg);
- common_show_footer();
- }
+ function handle($args) {
+ parent::handle($args);
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ } else {
+ $this->try_login();
+ }
+ }
+
+ function try_login() {
+
+ $consumer =& oid_consumer();
+
+ $response = $consumer->complete(common_local_url('finishaddopenid'));
+
+ if ($response->status == Auth_OpenID_CANCEL) {
+ $this->message(_('OpenID authentication cancelled.'));
+ return;
+ } else if ($response->status == Auth_OpenID_FAILURE) {
+ // Authentication failed; display the error message.
+ $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
+ } else if ($response->status == Auth_OpenID_SUCCESS) {
+
+ $display = $response->getDisplayIdentifier();
+ $canonical = ($response->endpoint && $response->endpoint->canonicalID) ?
+ $response->endpoint->canonicalID : $display;
+
+ $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
+
+ if ($sreg_resp) {
+ $sreg = $sreg_resp->contents();
+ }
+
+ $cur =& common_current_user();
+ $other = oid_get_user($canonical);
+
+ if ($other) {
+ if ($other->id == $cur->id) {
+ $this->message(_('You already have this OpenID!'));
+ } else {
+ $this->message(_('Someone else already has this OpenID.'));
+ }
+ return;
+ }
+
+ # start a transaction
+
+ $cur->query('BEGIN');
+
+ $result = oid_link_user($cur->id, $canonical, $display);
+
+ if (!$result) {
+ $this->message(_('Error connecting user.'));
+ return;
+ }
+ if ($sreg) {
+ if (!oid_update_user($cur, $sreg)) {
+ $this->message(_('Error updating profile'));
+ return;
+ }
+ }
+
+ # success!
+
+ $cur->query('COMMIT');
+
+ oid_set_last($display);
+
+ common_redirect(common_local_url('openidsettings'));
+ }
+ }
+
+ function message($msg) {
+ common_show_header(_('OpenID Login'));
+ common_element('p', NULL, $msg);
+ common_show_footer();
+ }
}
diff --git a/_darcs/pristine/actions/finishimmediate.php b/_darcs/pristine/actions/finishimmediate.php
index 6dbaa3d1c..ea711f5c5 100644
--- a/_darcs/pristine/actions/finishimmediate.php
+++ b/_darcs/pristine/actions/finishimmediate.php
@@ -23,43 +23,43 @@ require_once(INSTALLDIR.'/lib/openid.php');
class FinishimmediateAction extends Action {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- $consumer = oid_consumer();
+ $consumer = oid_consumer();
- $response = $consumer->complete(common_local_url('finishimmediate'));
+ $response = $consumer->complete(common_local_url('finishimmediate'));
- if ($response->status == Auth_OpenID_SUCCESS) {
- $display = $response->getDisplayIdentifier();
- $canonical = ($response->endpoint->canonicalID) ?
- $response->endpoint->canonicalID : $response->getDisplayIdentifier();
+ if ($response->status == Auth_OpenID_SUCCESS) {
+ $display = $response->getDisplayIdentifier();
+ $canonical = ($response->endpoint->canonicalID) ?
+ $response->endpoint->canonicalID : $response->getDisplayIdentifier();
- $user = oid_get_user($canonical);
+ $user = oid_get_user($canonical);
- if ($user) {
- oid_update_user($user, $sreg);
- oid_set_last($display); # refresh for another year
- common_set_user($user->nickname);
- $this->go_backto();
- return;
- }
- }
+ if ($user) {
+ oid_update_user($user, $sreg);
+ oid_set_last($display); # refresh for another year
+ common_set_user($user->nickname);
+ $this->go_backto();
+ return;
+ }
+ }
- # Failure! Clear openid so we don't try it again
+ # Failure! Clear openid so we don't try it again
- oid_clear_last();
- $this->go_backto();
- return;
- }
+ oid_clear_last();
+ $this->go_backto();
+ return;
+ }
- function go_backto() {
- common_ensure_session();
- $backto = $_SESSION['openid_immediate_backto'];
- if (!$backto) {
- # gar. Well, push them to the public page
- $backto = common_local_url('public');
- }
- common_redirect($backto);
- }
+ function go_backto() {
+ common_ensure_session();
+ $backto = $_SESSION['openid_immediate_backto'];
+ if (!$backto) {
+ # gar. Well, push them to the public page
+ $backto = common_local_url('public');
+ }
+ common_redirect($backto);
+ }
}
diff --git a/_darcs/pristine/actions/finishopenidlogin.php b/_darcs/pristine/actions/finishopenidlogin.php
index 766a08b20..a2a778f31 100644
--- a/_darcs/pristine/actions/finishopenidlogin.php
+++ b/_darcs/pristine/actions/finishopenidlogin.php
@@ -23,414 +23,414 @@ require_once(INSTALLDIR.'/lib/openid.php');
class FinishopenidloginAction extends Action {
- function handle($args) {
- parent::handle($args);
- if (common_logged_in()) {
- common_user_error(_('Already logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
- if ($this->arg('create')) {
- if (!$this->boolean('license')) {
- $this->show_form(_('You can\'t register if you don\'t agree to the license.'),
- $this->trimmed('newname'));
- return;
- }
- $this->create_new_user();
- } else if ($this->arg('connect')) {
- $this->connect_user();
- } else {
- common_debug(print_r($this->args, true), __FILE__);
- $this->show_form(_('Something weird happened.'),
- $this->trimmed('newname'));
- }
- } else {
- $this->try_login();
- }
- }
-
- function show_top($error=NULL) {
- if ($error) {
- common_element('div', array('class' => 'error'), $error);
- } else {
- global $config;
- common_element('div', 'instructions',
- sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), $config['site']['name']));
- }
- }
-
- function show_form($error=NULL, $username=NULL) {
- common_show_header(_('OpenID Account Setup'), NULL, $error,
- array($this, 'show_top'));
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'account_connect',
- 'action' => common_local_url('finishopenidlogin')));
- common_hidden('token', common_session_token());
- common_element('h2', NULL,
- _('Create new account'));
- common_element('p', NULL,
- _('Create a new user with this nickname.'));
- common_input('newname', _('New nickname'),
- ($username) ? $username : '',
- _('1-64 lowercase letters or numbers, no punctuation or spaces'));
- common_element_start('p');
- common_element('input', array('type' => 'checkbox',
- 'id' => 'license',
- 'name' => 'license',
- 'value' => 'true'));
- common_text(_('My text and files are available under '));
- common_element('a', array(href => common_config('license', 'url')),
- common_config('license', 'title'));
- common_text(_(' except this private data: password, email address, IM address, phone number.'));
- common_element_end('p');
- common_submit('create', _('Create'));
- common_element('h2', NULL,
- _('Connect existing account'));
- common_element('p', NULL,
- _('If you already have an account, login with your username and password to connect it to your OpenID.'));
- common_input('nickname', _('Existing nickname'));
- common_password('password', _('Password'));
- common_submit('connect', _('Connect'));
- common_element_end('form');
- common_show_footer();
- }
-
- function try_login() {
-
- $consumer = oid_consumer();
-
- $response = $consumer->complete(common_local_url('finishopenidlogin'));
-
- if ($response->status == Auth_OpenID_CANCEL) {
- $this->message(_('OpenID authentication cancelled.'));
- return;
- } else if ($response->status == Auth_OpenID_FAILURE) {
- // Authentication failed; display the error message.
- $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
- } else if ($response->status == Auth_OpenID_SUCCESS) {
- // This means the authentication succeeded; extract the
- // identity URL and Simple Registration data (if it was
- // returned).
- $display = $response->getDisplayIdentifier();
- $canonical = ($response->endpoint->canonicalID) ?
- $response->endpoint->canonicalID : $response->getDisplayIdentifier();
-
- $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
-
- if ($sreg_resp) {
- $sreg = $sreg_resp->contents();
- }
-
- $user = oid_get_user($canonical);
-
- if ($user) {
- oid_set_last($display);
- # XXX: commented out at @edd's request until better
- # control over how data flows from OpenID provider.
- # oid_update_user($user, $sreg);
- common_set_user($user);
- common_real_login(true);
- if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
- common_rememberme($user);
- }
+ function handle($args) {
+ parent::handle($args);
+ if (common_logged_in()) {
+ common_user_error(_('Already logged in.'));
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+ if ($this->arg('create')) {
+ if (!$this->boolean('license')) {
+ $this->show_form(_('You can\'t register if you don\'t agree to the license.'),
+ $this->trimmed('newname'));
+ return;
+ }
+ $this->create_new_user();
+ } else if ($this->arg('connect')) {
+ $this->connect_user();
+ } else {
+ common_debug(print_r($this->args, true), __FILE__);
+ $this->show_form(_('Something weird happened.'),
+ $this->trimmed('newname'));
+ }
+ } else {
+ $this->try_login();
+ }
+ }
+
+ function show_top($error=NULL) {
+ if ($error) {
+ common_element('div', array('class' => 'error'), $error);
+ } else {
+ global $config;
+ common_element('div', 'instructions',
+ sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), $config['site']['name']));
+ }
+ }
+
+ function show_form($error=NULL, $username=NULL) {
+ common_show_header(_('OpenID Account Setup'), NULL, $error,
+ array($this, 'show_top'));
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'account_connect',
+ 'action' => common_local_url('finishopenidlogin')));
+ common_hidden('token', common_session_token());
+ common_element('h2', NULL,
+ _('Create new account'));
+ common_element('p', NULL,
+ _('Create a new user with this nickname.'));
+ common_input('newname', _('New nickname'),
+ ($username) ? $username : '',
+ _('1-64 lowercase letters or numbers, no punctuation or spaces'));
+ common_element_start('p');
+ common_element('input', array('type' => 'checkbox',
+ 'id' => 'license',
+ 'name' => 'license',
+ 'value' => 'true'));
+ common_text(_('My text and files are available under '));
+ common_element('a', array(href => common_config('license', 'url')),
+ common_config('license', 'title'));
+ common_text(_(' except this private data: password, email address, IM address, phone number.'));
+ common_element_end('p');
+ common_submit('create', _('Create'));
+ common_element('h2', NULL,
+ _('Connect existing account'));
+ common_element('p', NULL,
+ _('If you already have an account, login with your username and password to connect it to your OpenID.'));
+ common_input('nickname', _('Existing nickname'));
+ common_password('password', _('Password'));
+ common_submit('connect', _('Connect'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function try_login() {
+
+ $consumer = oid_consumer();
+
+ $response = $consumer->complete(common_local_url('finishopenidlogin'));
+
+ if ($response->status == Auth_OpenID_CANCEL) {
+ $this->message(_('OpenID authentication cancelled.'));
+ return;
+ } else if ($response->status == Auth_OpenID_FAILURE) {
+ // Authentication failed; display the error message.
+ $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
+ } else if ($response->status == Auth_OpenID_SUCCESS) {
+ // This means the authentication succeeded; extract the
+ // identity URL and Simple Registration data (if it was
+ // returned).
+ $display = $response->getDisplayIdentifier();
+ $canonical = ($response->endpoint->canonicalID) ?
+ $response->endpoint->canonicalID : $response->getDisplayIdentifier();
+
+ $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
+
+ if ($sreg_resp) {
+ $sreg = $sreg_resp->contents();
+ }
+
+ $user = oid_get_user($canonical);
+
+ if ($user) {
+ oid_set_last($display);
+ # XXX: commented out at @edd's request until better
+ # control over how data flows from OpenID provider.
+ # oid_update_user($user, $sreg);
+ common_set_user($user);
+ common_real_login(true);
+ if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
+ common_rememberme($user);
+ }
unset($_SESSION['openid_rememberme']);
- $this->go_home($user->nickname);
- } else {
- $this->save_values($display, $canonical, $sreg);
- $this->show_form(NULL, $this->best_new_nickname($display, $sreg));
- }
- }
- }
-
- function message($msg) {
- common_show_header(_('OpenID Login'));
- common_element('p', NULL, $msg);
- common_show_footer();
- }
-
- function save_values($display, $canonical, $sreg) {
- common_ensure_session();
- $_SESSION['openid_display'] = $display;
- $_SESSION['openid_canonical'] = $canonical;
- $_SESSION['openid_sreg'] = $sreg;
- }
-
- function get_saved_values() {
- return array($_SESSION['openid_display'],
- $_SESSION['openid_canonical'],
- $_SESSION['openid_sreg']);
- }
-
- function create_new_user() {
+ $this->go_home($user->nickname);
+ } else {
+ $this->save_values($display, $canonical, $sreg);
+ $this->show_form(NULL, $this->best_new_nickname($display, $sreg));
+ }
+ }
+ }
+
+ function message($msg) {
+ common_show_header(_('OpenID Login'));
+ common_element('p', NULL, $msg);
+ common_show_footer();
+ }
+
+ function save_values($display, $canonical, $sreg) {
+ common_ensure_session();
+ $_SESSION['openid_display'] = $display;
+ $_SESSION['openid_canonical'] = $canonical;
+ $_SESSION['openid_sreg'] = $sreg;
+ }
+
+ function get_saved_values() {
+ return array($_SESSION['openid_display'],
+ $_SESSION['openid_canonical'],
+ $_SESSION['openid_sreg']);
+ }
+
+ function create_new_user() {
# FIXME: save invite code before redirect, and check here
- if (common_config('site', 'closed') || common_config('site', 'inviteonly')) {
- common_user_error(_('Registration not allowed.'));
+ if (common_config('site', 'closed') || common_config('site', 'inviteonly')) {
+ common_user_error(_('Registration not allowed.'));
return;
}
- $nickname = $this->trimmed('newname');
+ $nickname = $this->trimmed('newname');
- if (!Validate::string($nickname, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- $this->show_form(_('Nickname must have only lowercase letters and numbers and no spaces.'));
- return;
- }
+ if (!Validate::string($nickname, array('min_length' => 1,
+ 'max_length' => 64,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+ $this->show_form(_('Nickname must have only lowercase letters and numbers and no spaces.'));
+ return;
+ }
- if (!User::allowed_nickname($nickname)) {
- $this->show_form(_('Nickname not allowed.'));
- return;
- }
+ if (!User::allowed_nickname($nickname)) {
+ $this->show_form(_('Nickname not allowed.'));
+ return;
+ }
- if (User::staticGet('nickname', $nickname)) {
- $this->show_form(_('Nickname already in use. Try another one.'));
- return;
- }
+ if (User::staticGet('nickname', $nickname)) {
+ $this->show_form(_('Nickname already in use. Try another one.'));
+ return;
+ }
- list($display, $canonical, $sreg) = $this->get_saved_values();
+ list($display, $canonical, $sreg) = $this->get_saved_values();
- if (!$display || !$canonical) {
- common_server_error(_('Stored OpenID not found.'));
- return;
- }
+ if (!$display || !$canonical) {
+ common_server_error(_('Stored OpenID not found.'));
+ return;
+ }
- # Possible race condition... let's be paranoid
+ # Possible race condition... let's be paranoid
- $other = oid_get_user($canonical);
+ $other = oid_get_user($canonical);
- if ($other) {
- common_server_error(_('Creating new account for OpenID that already has a user.'));
- return;
- }
+ if ($other) {
+ common_server_error(_('Creating new account for OpenID that already has a user.'));
+ return;
+ }
- if ($sreg['country']) {
- if ($sreg['postcode']) {
- # XXX: use postcode to get city and region
- # XXX: also, store postcode somewhere -- it's valuable!
- $location = $sreg['postcode'] . ', ' . $sreg['country'];
- } else {
- $location = $sreg['country'];
- }
- }
+ if ($sreg['country']) {
+ if ($sreg['postcode']) {
+ # XXX: use postcode to get city and region
+ # XXX: also, store postcode somewhere -- it's valuable!
+ $location = $sreg['postcode'] . ', ' . $sreg['country'];
+ } else {
+ $location = $sreg['country'];
+ }
+ }
- if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
- $fullname = $sreg['fullname'];
- }
+ if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
+ $fullname = $sreg['fullname'];
+ }
- if ($sreg['email'] && Validate::email($sreg['email'], true)) {
- $email = $sreg['email'];
- }
+ if ($sreg['email'] && Validate::email($sreg['email'], true)) {
+ $email = $sreg['email'];
+ }
- # XXX: add language
- # XXX: add timezone
+ # XXX: add language
+ # XXX: add timezone
- $user = User::register(array('nickname' => $nickname,
- 'email' => $email,
- 'fullname' => $fullname,
- 'location' => $location));
+ $user = User::register(array('nickname' => $nickname,
+ 'email' => $email,
+ 'fullname' => $fullname,
+ 'location' => $location));
- $result = oid_link_user($user->id, $canonical, $display);
+ $result = oid_link_user($user->id, $canonical, $display);
- oid_set_last($display);
- common_set_user($user);
- common_real_login(true);
+ oid_set_last($display);
+ common_set_user($user);
+ common_real_login(true);
if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
- common_rememberme($user);
- }
+ common_rememberme($user);
+ }
unset($_SESSION['openid_rememberme']);
- common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)));
- }
+ common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)));
+ }
- function connect_user() {
+ function connect_user() {
- $nickname = $this->trimmed('nickname');
- $password = $this->trimmed('password');
+ $nickname = $this->trimmed('nickname');
+ $password = $this->trimmed('password');
- if (!common_check_user($nickname, $password)) {
- $this->show_form(_('Invalid username or password.'));
- return;
- }
+ if (!common_check_user($nickname, $password)) {
+ $this->show_form(_('Invalid username or password.'));
+ return;
+ }
- # They're legit!
+ # They're legit!
- $user = User::staticGet('nickname', $nickname);
+ $user = User::staticGet('nickname', $nickname);
- list($display, $canonical, $sreg) = $this->get_saved_values();
+ list($display, $canonical, $sreg) = $this->get_saved_values();
- if (!$display || !$canonical) {
- common_server_error(_('Stored OpenID not found.'));
- return;
- }
+ if (!$display || !$canonical) {
+ common_server_error(_('Stored OpenID not found.'));
+ return;
+ }
- $result = oid_link_user($user->id, $canonical, $display);
+ $result = oid_link_user($user->id, $canonical, $display);
- if (!$result) {
- common_server_error(_('Error connecting user to OpenID.'));
- return;
- }
+ if (!$result) {
+ common_server_error(_('Error connecting user to OpenID.'));
+ return;
+ }
- oid_update_user($user, $sreg);
- oid_set_last($display);
- common_set_user($user);
- common_real_login(true);
+ oid_update_user($user, $sreg);
+ oid_set_last($display);
+ common_set_user($user);
+ common_real_login(true);
if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) {
- common_rememberme($user);
- }
- unset($_SESSION['openid_rememberme']);
- $this->go_home($user->nickname);
- }
-
- function go_home($nickname) {
- $url = common_get_returnto();
- if ($url) {
- # We don't have to return to it again
- common_set_returnto(NULL);
- } else {
- $url = common_local_url('all',
- array('nickname' =>
- $nickname));
- }
- common_redirect($url);
- }
-
- function best_new_nickname($display, $sreg) {
-
- # Try the passed-in nickname
-
- if ($sreg['nickname']) {
- $nickname = $this->nicknamize($sreg['nickname']);
- if ($this->is_new_nickname($nickname)) {
- return $nickname;
- }
- }
-
- # Try the full name
-
- if ($sreg['fullname']) {
- $fullname = $this->nicknamize($sreg['fullname']);
- if ($this->is_new_nickname($fullname)) {
- return $fullname;
- }
- }
-
- # Try the URL
-
- $from_url = $this->openid_to_nickname($display);
-
- if ($from_url && $this->is_new_nickname($from_url)) {
- return $from_url;
- }
-
- # XXX: others?
-
- return NULL;
- }
-
- function is_new_nickname($str) {
- if (!Validate::string($str, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- return false;
- }
- if (!User::allowed_nickname($str)) {
- return false;
- }
- if (User::staticGet('nickname', $str)) {
- return false;
- }
- return true;
- }
-
- function openid_to_nickname($openid) {
+ common_rememberme($user);
+ }
+ unset($_SESSION['openid_rememberme']);
+ $this->go_home($user->nickname);
+ }
+
+ function go_home($nickname) {
+ $url = common_get_returnto();
+ if ($url) {
+ # We don't have to return to it again
+ common_set_returnto(NULL);
+ } else {
+ $url = common_local_url('all',
+ array('nickname' =>
+ $nickname));
+ }
+ common_redirect($url);
+ }
+
+ function best_new_nickname($display, $sreg) {
+
+ # Try the passed-in nickname
+
+ if ($sreg['nickname']) {
+ $nickname = $this->nicknamize($sreg['nickname']);
+ if ($this->is_new_nickname($nickname)) {
+ return $nickname;
+ }
+ }
+
+ # Try the full name
+
+ if ($sreg['fullname']) {
+ $fullname = $this->nicknamize($sreg['fullname']);
+ if ($this->is_new_nickname($fullname)) {
+ return $fullname;
+ }
+ }
+
+ # Try the URL
+
+ $from_url = $this->openid_to_nickname($display);
+
+ if ($from_url && $this->is_new_nickname($from_url)) {
+ return $from_url;
+ }
+
+ # XXX: others?
+
+ return NULL;
+ }
+
+ function is_new_nickname($str) {
+ if (!Validate::string($str, array('min_length' => 1,
+ 'max_length' => 64,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+ return false;
+ }
+ if (!User::allowed_nickname($str)) {
+ return false;
+ }
+ if (User::staticGet('nickname', $str)) {
+ return false;
+ }
+ return true;
+ }
+
+ function openid_to_nickname($openid) {
if (Auth_Yadis_identifierScheme($openid) == 'XRI') {
- return $this->xri_to_nickname($openid);
- } else {
- return $this->url_to_nickname($openid);
- }
- }
+ return $this->xri_to_nickname($openid);
+ } else {
+ return $this->url_to_nickname($openid);
+ }
+ }
- # We try to use an OpenID URL as a legal Laconica user name in this order
- # 1. Plain hostname, like http://evanp.myopenid.com/
- # 2. One element in path, like http://profile.typekey.com/EvanProdromou/
- # or http://getopenid.com/evanprodromou
+ # We try to use an OpenID URL as a legal Laconica user name in this order
+ # 1. Plain hostname, like http://evanp.myopenid.com/
+ # 2. One element in path, like http://profile.typekey.com/EvanProdromou/
+ # or http://getopenid.com/evanprodromou
function url_to_nickname($openid) {
- static $bad = array('query', 'user', 'password', 'port', 'fragment');
-
- $parts = parse_url($openid);
-
- # If any of these parts exist, this won't work
-
- foreach ($bad as $badpart) {
- if (array_key_exists($badpart, $parts)) {
- return NULL;
- }
- }
-
- # We just have host and/or path
-
- # If it's just a host...
- if (array_key_exists('host', $parts) &&
- (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
- {
- $hostparts = explode('.', $parts['host']);
-
- # Try to catch common idiom of nickname.service.tld
-
- if ((count($hostparts) > 2) &&
- (strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
- (strcmp($hostparts[0], 'www') != 0))
- {
- return $this->nicknamize($hostparts[0]);
- } else {
- # Do the whole hostname
- return $this->nicknamize($parts['host']);
- }
- } else {
- if (array_key_exists('path', $parts)) {
- # Strip starting, ending slashes
- $path = preg_replace('@/$@', '', $parts['path']);
- $path = preg_replace('@^/@', '', $path);
- if (strpos($path, '/') === false) {
- return $this->nicknamize($path);
- }
- }
- }
-
- return NULL;
- }
-
- function xri_to_nickname($xri) {
- $base = $this->xri_base($xri);
-
- if (!$base) {
- return NULL;
- } else {
- # =evan.prodromou
- # or @gratis*evan.prodromou
- $parts = explode('*', substr($base, 1));
- return $this->nicknamize(array_pop($parts));
- }
- }
-
- function xri_base($xri) {
- if (substr($xri, 0, 6) == 'xri://') {
- return substr($xri, 6);
- } else {
- return $xri;
- }
- }
-
- # Given a string, try to make it work as a nickname
-
- function nicknamize($str) {
- $str = preg_replace('/\W/', '', $str);
- return strtolower($str);
- }
+ static $bad = array('query', 'user', 'password', 'port', 'fragment');
+
+ $parts = parse_url($openid);
+
+ # If any of these parts exist, this won't work
+
+ foreach ($bad as $badpart) {
+ if (array_key_exists($badpart, $parts)) {
+ return NULL;
+ }
+ }
+
+ # We just have host and/or path
+
+ # If it's just a host...
+ if (array_key_exists('host', $parts) &&
+ (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
+ {
+ $hostparts = explode('.', $parts['host']);
+
+ # Try to catch common idiom of nickname.service.tld
+
+ if ((count($hostparts) > 2) &&
+ (strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
+ (strcmp($hostparts[0], 'www') != 0))
+ {
+ return $this->nicknamize($hostparts[0]);
+ } else {
+ # Do the whole hostname
+ return $this->nicknamize($parts['host']);
+ }
+ } else {
+ if (array_key_exists('path', $parts)) {
+ # Strip starting, ending slashes
+ $path = preg_replace('@/$@', '', $parts['path']);
+ $path = preg_replace('@^/@', '', $path);
+ if (strpos($path, '/') === false) {
+ return $this->nicknamize($path);
+ }
+ }
+ }
+
+ return NULL;
+ }
+
+ function xri_to_nickname($xri) {
+ $base = $this->xri_base($xri);
+
+ if (!$base) {
+ return NULL;
+ } else {
+ # =evan.prodromou
+ # or @gratis*evan.prodromou
+ $parts = explode('*', substr($base, 1));
+ return $this->nicknamize(array_pop($parts));
+ }
+ }
+
+ function xri_base($xri) {
+ if (substr($xri, 0, 6) == 'xri://') {
+ return substr($xri, 6);
+ } else {
+ return $xri;
+ }
+ }
+
+ # Given a string, try to make it work as a nickname
+
+ function nicknamize($str) {
+ $str = preg_replace('/\W/', '', $str);
+ return strtolower($str);
+ }
}
diff --git a/_darcs/pristine/actions/finishremotesubscribe.php b/_darcs/pristine/actions/finishremotesubscribe.php
index 58040683f..c3387cf02 100644
--- a/_darcs/pristine/actions/finishremotesubscribe.php
+++ b/_darcs/pristine/actions/finishremotesubscribe.php
@@ -23,174 +23,174 @@ require_once(INSTALLDIR.'/lib/omb.php');
class FinishremotesubscribeAction extends Action {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- if (common_logged_in()) {
- common_user_error(_('You can use the local subscription!'));
- return;
- }
+ if (common_logged_in()) {
+ common_user_error(_('You can use the local subscription!'));
+ return;
+ }
+
+ $omb = $_SESSION['oauth_authorization_request'];
+
+ if (!$omb) {
+ common_user_error(_('Not expecting this response!'));
+ return;
+ }
+
+ common_debug('stored request: '.print_r($omb,true), __FILE__);
+
+ common_remove_magic_from_request();
+ $req = OAuthRequest::from_request();
- $omb = $_SESSION['oauth_authorization_request'];
+ $token = $req->get_parameter('oauth_token');
- if (!$omb) {
- common_user_error(_('Not expecting this response!'));
- return;
- }
+ # I think this is the success metric
- common_debug('stored request: '.print_r($omb,true), __FILE__);
+ if ($token != $omb['token']) {
+ common_user_error(_('Not authorized.'));
+ return;
+ }
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
+ $version = $req->get_parameter('omb_version');
+
+ if ($version != OMB_VERSION_01) {
+ common_user_error(_('Unknown version of OMB protocol.'));
+ return;
+ }
- $token = $req->get_parameter('oauth_token');
+ $nickname = $req->get_parameter('omb_listener_nickname');
- # I think this is the success metric
+ if (!$nickname) {
+ common_user_error(_('No nickname provided by remote server.'));
+ return;
+ }
- if ($token != $omb['token']) {
- common_user_error(_('Not authorized.'));
- return;
- }
-
- $version = $req->get_parameter('omb_version');
-
- if ($version != OMB_VERSION_01) {
- common_user_error(_('Unknown version of OMB protocol.'));
- return;
- }
-
- $nickname = $req->get_parameter('omb_listener_nickname');
-
- if (!$nickname) {
- common_user_error(_('No nickname provided by remote server.'));
- return;
- }
-
- $profile_url = $req->get_parameter('omb_listener_profile');
-
- if (!$profile_url) {
- common_user_error(_('No profile URL returned by server.'));
- return;
- }
-
- if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
- common_user_error(_('Invalid profile URL returned by server.'));
- return;
- }
-
- if ($profile_url == common_local_url('showstream', array('nickname' => $nickname))) {
- common_user_error(_('You can use the local subscription!'));
- return;
- }
-
- common_debug('listenee: "'.$omb['listenee'].'"', __FILE__);
-
- $user = User::staticGet('nickname', $omb['listenee']);
-
- if (!$user) {
- common_user_error(_('User being listened to doesn\'t exist.'));
- return;
- }
-
- $other = User::staticGet('uri', $omb['listener']);
-
- if ($other) {
- common_user_error(_('You can use the local subscription!'));
- return;
- }
-
- $fullname = $req->get_parameter('omb_listener_fullname');
- $homepage = $req->get_parameter('omb_listener_homepage');
- $bio = $req->get_parameter('omb_listener_bio');
- $location = $req->get_parameter('omb_listener_location');
- $avatar_url = $req->get_parameter('omb_listener_avatar');
-
- list($newtok, $newsecret) = $this->access_token($omb);
-
- if (!$newtok || !$newsecret) {
- common_user_error(_('Couldn\'t convert request tokens to access tokens.'));
- return;
- }
-
- # XXX: possible attack point; subscribe and return someone else's profile URI
-
- $remote = Remote_profile::staticGet('uri', $omb['listener']);
-
- if ($remote) {
- $exists = true;
- $profile = Profile::staticGet($remote->id);
- $orig_remote = clone($remote);
- $orig_profile = clone($profile);
- # XXX: compare current postNotice and updateProfile URLs to the ones
- # stored in the DB to avoid (possibly...) above attack
- } else {
- $exists = false;
- $remote = new Remote_profile();
- $remote->uri = $omb['listener'];
- $profile = new Profile();
- }
-
- $profile->nickname = $nickname;
- $profile->profileurl = $profile_url;
-
- if ($fullname) {
- $profile->fullname = $fullname;
- }
- if ($homepage) {
- $profile->homepage = $homepage;
- }
- if ($bio) {
- $profile->bio = $bio;
- }
- if ($location) {
- $profile->location = $location;
- }
-
- if ($exists) {
- $profile->update($orig_profile);
- } else {
- $profile->created = DB_DataObject_Cast::dateTime(); # current time
- $id = $profile->insert();
- if (!$id) {
- common_server_error(_('Error inserting new profile'));
- return;
- }
- $remote->id = $id;
- }
-
- if ($avatar_url) {
- if (!$this->add_avatar($profile, $avatar_url)) {
- common_server_error(_('Error inserting avatar'));
- return;
- }
- }
-
- $remote->postnoticeurl = $omb['post_notice_url'];
- $remote->updateprofileurl = $omb['update_profile_url'];
-
- if ($exists) {
- if (!$remote->update($orig_remote)) {
- common_server_error(_('Error updating remote profile'));
- return;
- }
- } else {
- $remote->created = DB_DataObject_Cast::dateTime(); # current time
- if (!$remote->insert()) {
- common_server_error(_('Error inserting remote profile'));
- return;
- }
- }
+ $profile_url = $req->get_parameter('omb_listener_profile');
+
+ if (!$profile_url) {
+ common_user_error(_('No profile URL returned by server.'));
+ return;
+ }
+
+ if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
+ common_user_error(_('Invalid profile URL returned by server.'));
+ return;
+ }
+
+ if ($profile_url == common_local_url('showstream', array('nickname' => $nickname))) {
+ common_user_error(_('You can use the local subscription!'));
+ return;
+ }
+
+ common_debug('listenee: "'.$omb['listenee'].'"', __FILE__);
+
+ $user = User::staticGet('nickname', $omb['listenee']);
+
+ if (!$user) {
+ common_user_error(_('User being listened to doesn\'t exist.'));
+ return;
+ }
+
+ $other = User::staticGet('uri', $omb['listener']);
+
+ if ($other) {
+ common_user_error(_('You can use the local subscription!'));
+ return;
+ }
+
+ $fullname = $req->get_parameter('omb_listener_fullname');
+ $homepage = $req->get_parameter('omb_listener_homepage');
+ $bio = $req->get_parameter('omb_listener_bio');
+ $location = $req->get_parameter('omb_listener_location');
+ $avatar_url = $req->get_parameter('omb_listener_avatar');
+
+ list($newtok, $newsecret) = $this->access_token($omb);
+
+ if (!$newtok || !$newsecret) {
+ common_user_error(_('Couldn\'t convert request tokens to access tokens.'));
+ return;
+ }
+
+ # XXX: possible attack point; subscribe and return someone else's profile URI
+
+ $remote = Remote_profile::staticGet('uri', $omb['listener']);
+
+ if ($remote) {
+ $exists = true;
+ $profile = Profile::staticGet($remote->id);
+ $orig_remote = clone($remote);
+ $orig_profile = clone($profile);
+ # XXX: compare current postNotice and updateProfile URLs to the ones
+ # stored in the DB to avoid (possibly...) above attack
+ } else {
+ $exists = false;
+ $remote = new Remote_profile();
+ $remote->uri = $omb['listener'];
+ $profile = new Profile();
+ }
+
+ $profile->nickname = $nickname;
+ $profile->profileurl = $profile_url;
+
+ if ($fullname) {
+ $profile->fullname = $fullname;
+ }
+ if ($homepage) {
+ $profile->homepage = $homepage;
+ }
+ if ($bio) {
+ $profile->bio = $bio;
+ }
+ if ($location) {
+ $profile->location = $location;
+ }
+
+ if ($exists) {
+ $profile->update($orig_profile);
+ } else {
+ $profile->created = DB_DataObject_Cast::dateTime(); # current time
+ $id = $profile->insert();
+ if (!$id) {
+ common_server_error(_('Error inserting new profile'));
+ return;
+ }
+ $remote->id = $id;
+ }
+
+ if ($avatar_url) {
+ if (!$this->add_avatar($profile, $avatar_url)) {
+ common_server_error(_('Error inserting avatar'));
+ return;
+ }
+ }
+
+ $remote->postnoticeurl = $omb['post_notice_url'];
+ $remote->updateprofileurl = $omb['update_profile_url'];
+
+ if ($exists) {
+ if (!$remote->update($orig_remote)) {
+ common_server_error(_('Error updating remote profile'));
+ return;
+ }
+ } else {
+ $remote->created = DB_DataObject_Cast::dateTime(); # current time
+ if (!$remote->insert()) {
+ common_server_error(_('Error inserting remote profile'));
+ return;
+ }
+ }
if ($user->hasBlocked($profile)) {
$this->client_error(_('That user has blocked you from subscribing.'));
return;
}
- $sub = new Subscription();
+ $sub = new Subscription();
- $sub->subscriber = $remote->id;
- $sub->subscribed = $user->id;
+ $sub->subscriber = $remote->id;
+ $sub->subscribed = $user->id;
$sub_exists = false;
@@ -202,8 +202,8 @@ class FinishremotesubscribeAction extends Action {
$sub->created = DB_DataObject_Cast::dateTime(); # current time
}
- $sub->token = $newtok;
- $sub->secret = $newsecret;
+ $sub->token = $newtok;
+ $sub->secret = $newsecret;
if ($sub_exists) {
$result = $sub->update($orig_sub);
@@ -211,78 +211,78 @@ class FinishremotesubscribeAction extends Action {
$result = $sub->insert();
}
- if (!$result) {
+ if (!$result) {
common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
- common_user_error(_('Couldn\'t insert new subscription.'));
- return;
- }
+ common_user_error(_('Couldn\'t insert new subscription.'));
+ return;
+ }
- # Notify user, if necessary
+ # Notify user, if necessary
- mail_subscribe_notify_profile($user, $profile);
+ mail_subscribe_notify_profile($user, $profile);
- # Clear the data
- unset($_SESSION['oauth_authorization_request']);
+ # Clear the data
+ unset($_SESSION['oauth_authorization_request']);
- # If we show subscriptions in reverse chron order, this should
- # show up close to the top of the page
+ # If we show subscriptions in reverse chron order, this should
+ # show up close to the top of the page
- common_redirect(common_local_url('subscribers', array('nickname' =>
- $user->nickname)));
- }
+ common_redirect(common_local_url('subscribers', array('nickname' =>
+ $user->nickname)));
+ }
- function add_avatar($profile, $url) {
- $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
- copy($url, $temp_filename);
- return $profile->setOriginal($temp_filename);
- }
+ function add_avatar($profile, $url) {
+ $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
+ copy($url, $temp_filename);
+ return $profile->setOriginal($temp_filename);
+ }
- function access_token($omb) {
+ function access_token($omb) {
- common_debug('starting request for access token', __FILE__);
+ common_debug('starting request for access token', __FILE__);
- $con = omb_oauth_consumer();
- $tok = new OAuthToken($omb['token'], $omb['secret']);
+ $con = omb_oauth_consumer();
+ $tok = new OAuthToken($omb['token'], $omb['secret']);
- common_debug('using request token "'.$tok.'"', __FILE__);
+ common_debug('using request token "'.$tok.'"', __FILE__);
- $url = $omb['access_token_url'];
+ $url = $omb['access_token_url'];
- common_debug('using access token url "'.$url.'"', __FILE__);
+ common_debug('using access token url "'.$url.'"', __FILE__);
- # XXX: Is this the right thing to do? Strip off GET params and make them
- # POST params? Seems wrong to me.
+ # XXX: Is this the right thing to do? Strip off GET params and make them
+ # POST params? Seems wrong to me.
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
+ $parsed = parse_url($url);
+ $params = array();
+ parse_str($parsed['query'], $params);
- $req = OAuthRequest::from_consumer_and_token($con, $tok, "POST", $url, $params);
+ $req = OAuthRequest::from_consumer_and_token($con, $tok, "POST", $url, $params);
- $req->set_parameter('omb_version', OMB_VERSION_01);
+ $req->set_parameter('omb_version', OMB_VERSION_01);
- # XXX: test to see if endpoint accepts this signature method
+ # XXX: test to see if endpoint accepts this signature method
- $req->sign_request(omb_hmac_sha1(), $con, $tok);
+ $req->sign_request(omb_hmac_sha1(), $con, $tok);
- # We re-use this tool's fetcher, since it's pretty good
+ # We re-use this tool's fetcher, since it's pretty good
- common_debug('posting to access token url "'.$req->get_normalized_http_url().'"', __FILE__);
- common_debug('posting request data "'.$req->to_postdata().'"', __FILE__);
+ common_debug('posting to access token url "'.$req->get_normalized_http_url().'"', __FILE__);
+ common_debug('posting request data "'.$req->to_postdata().'"', __FILE__);
- $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
- $result = $fetcher->post($req->get_normalized_http_url(),
- $req->to_postdata(),
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+ $result = $fetcher->post($req->get_normalized_http_url(),
+ $req->to_postdata(),
array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
- common_debug('got result: "'.print_r($result,TRUE).'"', __FILE__);
+ common_debug('got result: "'.print_r($result,TRUE).'"', __FILE__);
- if ($result->status != 200) {
- return NULL;
- }
+ if ($result->status != 200) {
+ return NULL;
+ }
- parse_str($result->body, $return);
+ parse_str($result->body, $return);
- return array($return['oauth_token'], $return['oauth_token_secret']);
- }
+ return array($return['oauth_token'], $return['oauth_token_secret']);
+ }
}
diff --git a/_darcs/pristine/actions/foaf.php b/_darcs/pristine/actions/foaf.php
index 6811fc05a..310ba2c19 100644
--- a/_darcs/pristine/actions/foaf.php
+++ b/_darcs/pristine/actions/foaf.php
@@ -25,178 +25,178 @@ define('BOTH', 0);
class FoafAction extends Action {
- function is_readonly() {
- return true;
- }
-
- function handle($args) {
- parent::handle($args);
-
- $nickname = $this->trimmed('nickname');
-
- $user = User::staticGet('nickname', $nickname);
-
- if (!$user) {
- common_user_error(_('No such user.'), 404);
- return;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'), 500);
- return;
- }
-
- header('Content-Type: application/rdf+xml');
-
- common_start_xml();
- common_element_start('rdf:RDF', array('xmlns:rdf' =>
- 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
- 'xmlns:rdfs' =>
- 'http://www.w3.org/2000/01/rdf-schema#',
- 'xmlns:geo' =>
- 'http://www.w3.org/2003/01/geo/wgs84_pos#',
- 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
-
- # This is the document about the user
-
- $this->show_ppd('', $user->uri);
-
- # XXX: might not be a person
- common_element_start('Person', array('rdf:about' =>
- $user->uri));
- common_element('mbox_sha1sum', NULL, sha1('mailto:' . $user->email));
- if ($profile->fullname) {
- common_element('name', NULL, $profile->fullname);
- }
- if ($profile->homepage) {
- common_element('homepage', array('rdf:resource' => $profile->homepage));
- }
- if ($profile->bio) {
- common_element('rdfs:comment', NULL, $profile->bio);
- }
- # XXX: more structured location data
- if ($profile->location) {
- common_element_start('based_near');
- common_element_start('geo:SpatialThing');
- common_element('name', NULL, $profile->location);
- common_element_end('geo:SpatialThing');
- common_element_end('based_near');
- }
-
- $this->show_microblogging_account($profile, common_root_url());
-
- $avatar = $profile->getOriginalAvatar();
-
- if ($avatar) {
- common_element_start('img');
- common_element_start('Image', array('rdf:about' => $avatar->url));
- foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
- $scaled = $profile->getAvatar($size);
- if (!$scaled->original) { # sometimes the original has one of our scaled sizes
- common_element_start('thumbnail');
- common_element('Image', array('rdf:about' => $scaled->url));
- common_element_end('thumbnail');
- }
- }
- common_element_end('Image');
- common_element_end('img');
- }
-
- # Get people user is subscribed to
-
- $person = array();
-
- $sub = new Subscription();
- $sub->subscriber = $profile->id;
- $sub->whereAdd('subscriber != subscribed');
-
- if ($sub->find()) {
- while ($sub->fetch()) {
- if ($sub->token) {
- $other = Remote_profile::staticGet('id', $sub->subscribed);
- } else {
- $other = User::staticGet('id', $sub->subscribed);
- }
- if (!$other) {
- common_debug('Got a bad subscription: '.print_r($sub,TRUE));
- continue;
- }
- common_element('knows', array('rdf:resource' => $other->uri));
- $person[$other->uri] = array(LISTENEE, $other);
- }
- }
-
- # Get people who subscribe to user
-
- $sub = new Subscription();
- $sub->subscribed = $profile->id;
- $sub->whereAdd('subscriber != subscribed');
-
- if ($sub->find()) {
- while ($sub->fetch()) {
- if ($sub->token) {
- $other = Remote_profile::staticGet('id', $sub->subscriber);
- } else {
- $other = User::staticGet('id', $sub->subscriber);
- }
- if (!$other) {
- common_debug('Got a bad subscription: '.print_r($sub,TRUE));
- continue;
- }
- if (array_key_exists($other->uri, $person)) {
- $person[$other->uri][0] = BOTH;
- } else {
- $person[$other->uri] = array(LISTENER, $other);
- }
- }
- }
-
- common_element_end('Person');
-
- foreach ($person as $uri => $p) {
- $foaf_url = NULL;
- if ($p[1] instanceof User) {
- $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname));
- }
- $profile = Profile::staticGet($p[1]->id);
- common_element_start('Person', array('rdf:about' => $uri));
- if ($p[0] == LISTENER || $p[0] == BOTH) {
- common_element('knows', array('rdf:resource' => $user->uri));
- }
- $this->show_microblogging_account($profile, ($p[1] instanceof User) ?
- common_root_url() : NULL);
- if ($foaf_url) {
- common_element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
- }
- common_element_end('Person');
- if ($foaf_url) {
- $this->show_ppd($foaf_url, $uri);
- }
- }
-
- common_element_end('rdf:RDF');
- }
-
- function show_ppd($foaf_url, $person_uri) {
- common_element_start('PersonalProfileDocument', array('rdf:about' => $foaf_url));
- common_element('maker', array('rdf:resource' => $person_uri));
- common_element('primaryTopic', array('rdf:resource' => $person_uri));
- common_element_end('PersonalProfileDocument');
- }
-
- function show_microblogging_account($profile, $service=NULL) {
- # Their account
- common_element_start('holdsAccount');
- common_element_start('OnlineAccount');
- if ($service) {
- common_element('accountServiceHomepage', array('rdf:resource' =>
- $service));
- }
- common_element('accountName', NULL, $profile->nickname);
- common_element('homepage', array('rdf:resource' => $profile->profileurl));
- common_element_end('OnlineAccount');
- common_element_end('holdsAccount');
- }
+ function is_readonly() {
+ return true;
+ }
+
+ function handle($args) {
+ parent::handle($args);
+
+ $nickname = $this->trimmed('nickname');
+
+ $user = User::staticGet('nickname', $nickname);
+
+ if (!$user) {
+ common_user_error(_('No such user.'), 404);
+ return;
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'), 500);
+ return;
+ }
+
+ header('Content-Type: application/rdf+xml');
+
+ common_start_xml();
+ common_element_start('rdf:RDF', array('xmlns:rdf' =>
+ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+ 'xmlns:rdfs' =>
+ 'http://www.w3.org/2000/01/rdf-schema#',
+ 'xmlns:geo' =>
+ 'http://www.w3.org/2003/01/geo/wgs84_pos#',
+ 'xmlns' => 'http://xmlns.com/foaf/0.1/'));
+
+ # This is the document about the user
+
+ $this->show_ppd('', $user->uri);
+
+ # XXX: might not be a person
+ common_element_start('Person', array('rdf:about' =>
+ $user->uri));
+ common_element('mbox_sha1sum', NULL, sha1('mailto:' . $user->email));
+ if ($profile->fullname) {
+ common_element('name', NULL, $profile->fullname);
+ }
+ if ($profile->homepage) {
+ common_element('homepage', array('rdf:resource' => $profile->homepage));
+ }
+ if ($profile->bio) {
+ common_element('rdfs:comment', NULL, $profile->bio);
+ }
+ # XXX: more structured location data
+ if ($profile->location) {
+ common_element_start('based_near');
+ common_element_start('geo:SpatialThing');
+ common_element('name', NULL, $profile->location);
+ common_element_end('geo:SpatialThing');
+ common_element_end('based_near');
+ }
+
+ $this->show_microblogging_account($profile, common_root_url());
+
+ $avatar = $profile->getOriginalAvatar();
+
+ if ($avatar) {
+ common_element_start('img');
+ common_element_start('Image', array('rdf:about' => $avatar->url));
+ foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
+ $scaled = $profile->getAvatar($size);
+ if (!$scaled->original) { # sometimes the original has one of our scaled sizes
+ common_element_start('thumbnail');
+ common_element('Image', array('rdf:about' => $scaled->url));
+ common_element_end('thumbnail');
+ }
+ }
+ common_element_end('Image');
+ common_element_end('img');
+ }
+
+ # Get people user is subscribed to
+
+ $person = array();
+
+ $sub = new Subscription();
+ $sub->subscriber = $profile->id;
+ $sub->whereAdd('subscriber != subscribed');
+
+ if ($sub->find()) {
+ while ($sub->fetch()) {
+ if ($sub->token) {
+ $other = Remote_profile::staticGet('id', $sub->subscribed);
+ } else {
+ $other = User::staticGet('id', $sub->subscribed);
+ }
+ if (!$other) {
+ common_debug('Got a bad subscription: '.print_r($sub,TRUE));
+ continue;
+ }
+ common_element('knows', array('rdf:resource' => $other->uri));
+ $person[$other->uri] = array(LISTENEE, $other);
+ }
+ }
+
+ # Get people who subscribe to user
+
+ $sub = new Subscription();
+ $sub->subscribed = $profile->id;
+ $sub->whereAdd('subscriber != subscribed');
+
+ if ($sub->find()) {
+ while ($sub->fetch()) {
+ if ($sub->token) {
+ $other = Remote_profile::staticGet('id', $sub->subscriber);
+ } else {
+ $other = User::staticGet('id', $sub->subscriber);
+ }
+ if (!$other) {
+ common_debug('Got a bad subscription: '.print_r($sub,TRUE));
+ continue;
+ }
+ if (array_key_exists($other->uri, $person)) {
+ $person[$other->uri][0] = BOTH;
+ } else {
+ $person[$other->uri] = array(LISTENER, $other);
+ }
+ }
+ }
+
+ common_element_end('Person');
+
+ foreach ($person as $uri => $p) {
+ $foaf_url = NULL;
+ if ($p[1] instanceof User) {
+ $foaf_url = common_local_url('foaf', array('nickname' => $p[1]->nickname));
+ }
+ $profile = Profile::staticGet($p[1]->id);
+ common_element_start('Person', array('rdf:about' => $uri));
+ if ($p[0] == LISTENER || $p[0] == BOTH) {
+ common_element('knows', array('rdf:resource' => $user->uri));
+ }
+ $this->show_microblogging_account($profile, ($p[1] instanceof User) ?
+ common_root_url() : NULL);
+ if ($foaf_url) {
+ common_element('rdfs:seeAlso', array('rdf:resource' => $foaf_url));
+ }
+ common_element_end('Person');
+ if ($foaf_url) {
+ $this->show_ppd($foaf_url, $uri);
+ }
+ }
+
+ common_element_end('rdf:RDF');
+ }
+
+ function show_ppd($foaf_url, $person_uri) {
+ common_element_start('PersonalProfileDocument', array('rdf:about' => $foaf_url));
+ common_element('maker', array('rdf:resource' => $person_uri));
+ common_element('primaryTopic', array('rdf:resource' => $person_uri));
+ common_element_end('PersonalProfileDocument');
+ }
+
+ function show_microblogging_account($profile, $service=NULL) {
+ # Their account
+ common_element_start('holdsAccount');
+ common_element_start('OnlineAccount');
+ if ($service) {
+ common_element('accountServiceHomepage', array('rdf:resource' =>
+ $service));
+ }
+ common_element('accountName', NULL, $profile->nickname);
+ common_element('homepage', array('rdf:resource' => $profile->profileurl));
+ common_element_end('OnlineAccount');
+ common_element_end('holdsAccount');
+ }
}
diff --git a/_darcs/pristine/actions/imsettings.php b/_darcs/pristine/actions/imsettings.php
index 0aa7631dc..d0c47f7fd 100644
--- a/_darcs/pristine/actions/imsettings.php
+++ b/_darcs/pristine/actions/imsettings.php
@@ -24,247 +24,247 @@ require_once(INSTALLDIR.'/lib/jabber.php');
class ImsettingsAction extends SettingsAction {
- function get_instructions() {
- return _('You can send and receive notices through Jabber/GTalk [instant messages](%%doc.im%%). Configure your address and settings below.');
- }
-
- function show_form($msg=NULL, $success=false) {
- $user = common_current_user();
- $this->form_header(_('IM Settings'), $msg, $success);
- common_element_start('form', array('method' => 'post',
- 'id' => 'imsettings',
- 'action' =>
- common_local_url('imsettings')));
- common_hidden('token', common_session_token());
-
- common_element('h2', NULL, _('Address'));
-
- if ($user->jabber) {
- common_element_start('p');
- common_element('span', 'address confirmed', $user->jabber);
- common_element('span', 'input_instructions',
- _('Current confirmed Jabber/GTalk address.'));
- common_hidden('jabber', $user->jabber);
- common_element_end('p');
- common_submit('remove', _('Remove'));
- } else {
- $confirm = $this->get_confirmation();
- if ($confirm) {
- common_element_start('p');
- common_element('span', 'address unconfirmed', $confirm->address);
- common_element('span', 'input_instructions',
- sprintf(_('Awaiting confirmation on this address. Check your Jabber/GTalk account for a message with further instructions. (Did you add %s to your buddy list?)'), jabber_daemon_address()));
- common_hidden('jabber', $confirm->address);
- common_element_end('p');
- common_submit('cancel', _('Cancel'));
- } else {
- common_input('jabber', _('IM Address'),
- ($this->arg('jabber')) ? $this->arg('jabber') : NULL,
- sprintf(_('Jabber or GTalk address, like "UserName@example.org". First, make sure to add %s to your buddy list in your IM client or on GTalk.'), jabber_daemon_address()));
- common_submit('add', _('Add'));
- }
- }
-
- common_element('h2', NULL, _('Preferences'));
-
- common_checkbox('jabbernotify',
- _('Send me notices through Jabber/GTalk.'),
- $user->jabbernotify);
- common_checkbox('updatefrompresence',
- _('Post a notice when my Jabber/GTalk status changes.'),
- $user->updatefrompresence);
- common_checkbox('jabberreplies',
- _('Send me replies through Jabber/GTalk from people I\'m not subscribed to.'),
- $user->jabberreplies);
- common_checkbox('jabbermicroid',
- _('Publish a MicroID for my Jabber/GTalk address.'),
- $user->jabbermicroid);
- common_submit('save', _('Save'));
-
- common_element_end('form');
- common_show_footer();
- }
-
- function get_confirmation() {
- $user = common_current_user();
- $confirm = new Confirm_address();
- $confirm->user_id = $user->id;
- $confirm->address_type = 'jabber';
- if ($confirm->find(TRUE)) {
- return $confirm;
- } else {
- return NULL;
- }
- }
-
- function handle_post() {
-
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- if ($this->arg('save')) {
- $this->save_preferences();
- } else if ($this->arg('add')) {
- $this->add_address();
- } else if ($this->arg('cancel')) {
- $this->cancel_confirmation();
- } else if ($this->arg('remove')) {
- $this->remove_address();
- } else {
- $this->show_form(_('Unexpected form submission.'));
- }
- }
-
- function save_preferences() {
-
- $jabbernotify = $this->boolean('jabbernotify');
- $updatefrompresence = $this->boolean('updatefrompresence');
- $jabberreplies = $this->boolean('jabberreplies');
- $jabbermicroid = $this->boolean('jabbermicroid');
-
- $user = common_current_user();
-
- assert(!is_null($user)); # should already be checked
-
- $user->query('BEGIN');
-
- $original = clone($user);
-
- $user->jabbernotify = $jabbernotify;
- $user->updatefrompresence = $updatefrompresence;
- $user->jabberreplies = $jabberreplies;
- $user->jabbermicroid = $jabbermicroid;
-
- $result = $user->update($original);
-
- if ($result === FALSE) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
-
- $user->query('COMMIT');
-
- $this->show_form(_('Preferences saved.'), true);
- }
-
- function add_address() {
-
- $user = common_current_user();
-
- $jabber = $this->trimmed('jabber');
-
- # Some validation
-
- if (!$jabber) {
- $this->show_form(_('No Jabber ID.'));
- return;
- }
-
- $jabber = jabber_normalize_jid($jabber);
-
- if (!$jabber) {
- $this->show_form(_('Cannot normalize that Jabber ID'));
- return;
- }
- if (!jabber_valid_base_jid($jabber)) {
- $this->show_form(_('Not a valid Jabber ID'));
- return;
- } else if ($user->jabber == $jabber) {
- $this->show_form(_('That is already your Jabber ID.'));
- return;
- } else if ($this->jabber_exists($jabber)) {
- $this->show_form(_('Jabber ID already belongs to another user.'));
- return;
- }
-
- $confirm = new Confirm_address();
- $confirm->address = $jabber;
- $confirm->address_type = 'jabber';
- $confirm->user_id = $user->id;
- $confirm->code = common_confirmation_code(64);
-
- $result = $confirm->insert();
-
- if ($result === FALSE) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
- common_server_error(_('Couldn\'t insert confirmation code.'));
- return;
- }
-
- if (!common_config('queue', 'enabled')) {
- jabber_confirm_address($confirm->code,
- $user->nickname,
- $jabber);
- }
-
- $msg = sprintf(_('A confirmation code was sent to the IM address you added. You must approve %s for sending messages to you.'), jabber_daemon_address());
-
- $this->show_form($msg, TRUE);
- }
-
- function cancel_confirmation() {
- $jabber = $this->arg('jabber');
- $confirm = $this->get_confirmation();
- if (!$confirm) {
- $this->show_form(_('No pending confirmation to cancel.'));
- return;
- }
- if ($confirm->address != $jabber) {
- $this->show_form(_('That is the wrong IM address.'));
- return;
- }
+ function get_instructions() {
+ return _('You can send and receive notices through Jabber/GTalk [instant messages](%%doc.im%%). Configure your address and settings below.');
+ }
+
+ function show_form($msg=NULL, $success=false) {
+ $user = common_current_user();
+ $this->form_header(_('IM Settings'), $msg, $success);
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'imsettings',
+ 'action' =>
+ common_local_url('imsettings')));
+ common_hidden('token', common_session_token());
+
+ common_element('h2', NULL, _('Address'));
+
+ if ($user->jabber) {
+ common_element_start('p');
+ common_element('span', 'address confirmed', $user->jabber);
+ common_element('span', 'input_instructions',
+ _('Current confirmed Jabber/GTalk address.'));
+ common_hidden('jabber', $user->jabber);
+ common_element_end('p');
+ common_submit('remove', _('Remove'));
+ } else {
+ $confirm = $this->get_confirmation();
+ if ($confirm) {
+ common_element_start('p');
+ common_element('span', 'address unconfirmed', $confirm->address);
+ common_element('span', 'input_instructions',
+ sprintf(_('Awaiting confirmation on this address. Check your Jabber/GTalk account for a message with further instructions. (Did you add %s to your buddy list?)'), jabber_daemon_address()));
+ common_hidden('jabber', $confirm->address);
+ common_element_end('p');
+ common_submit('cancel', _('Cancel'));
+ } else {
+ common_input('jabber', _('IM Address'),
+ ($this->arg('jabber')) ? $this->arg('jabber') : NULL,
+ sprintf(_('Jabber or GTalk address, like "UserName@example.org". First, make sure to add %s to your buddy list in your IM client or on GTalk.'), jabber_daemon_address()));
+ common_submit('add', _('Add'));
+ }
+ }
+
+ common_element('h2', NULL, _('Preferences'));
+
+ common_checkbox('jabbernotify',
+ _('Send me notices through Jabber/GTalk.'),
+ $user->jabbernotify);
+ common_checkbox('updatefrompresence',
+ _('Post a notice when my Jabber/GTalk status changes.'),
+ $user->updatefrompresence);
+ common_checkbox('jabberreplies',
+ _('Send me replies through Jabber/GTalk from people I\'m not subscribed to.'),
+ $user->jabberreplies);
+ common_checkbox('jabbermicroid',
+ _('Publish a MicroID for my Jabber/GTalk address.'),
+ $user->jabbermicroid);
+ common_submit('save', _('Save'));
+
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function get_confirmation() {
+ $user = common_current_user();
+ $confirm = new Confirm_address();
+ $confirm->user_id = $user->id;
+ $confirm->address_type = 'jabber';
+ if ($confirm->find(TRUE)) {
+ return $confirm;
+ } else {
+ return NULL;
+ }
+ }
+
+ function handle_post() {
+
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ if ($this->arg('save')) {
+ $this->save_preferences();
+ } else if ($this->arg('add')) {
+ $this->add_address();
+ } else if ($this->arg('cancel')) {
+ $this->cancel_confirmation();
+ } else if ($this->arg('remove')) {
+ $this->remove_address();
+ } else {
+ $this->show_form(_('Unexpected form submission.'));
+ }
+ }
+
+ function save_preferences() {
+
+ $jabbernotify = $this->boolean('jabbernotify');
+ $updatefrompresence = $this->boolean('updatefrompresence');
+ $jabberreplies = $this->boolean('jabberreplies');
+ $jabbermicroid = $this->boolean('jabbermicroid');
+
+ $user = common_current_user();
+
+ assert(!is_null($user)); # should already be checked
+
+ $user->query('BEGIN');
+
+ $original = clone($user);
+
+ $user->jabbernotify = $jabbernotify;
+ $user->updatefrompresence = $updatefrompresence;
+ $user->jabberreplies = $jabberreplies;
+ $user->jabbermicroid = $jabbermicroid;
+
+ $result = $user->update($original);
+
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
+
+ $user->query('COMMIT');
+
+ $this->show_form(_('Preferences saved.'), true);
+ }
+
+ function add_address() {
+
+ $user = common_current_user();
+
+ $jabber = $this->trimmed('jabber');
+
+ # Some validation
+
+ if (!$jabber) {
+ $this->show_form(_('No Jabber ID.'));
+ return;
+ }
+
+ $jabber = jabber_normalize_jid($jabber);
+
+ if (!$jabber) {
+ $this->show_form(_('Cannot normalize that Jabber ID'));
+ return;
+ }
+ if (!jabber_valid_base_jid($jabber)) {
+ $this->show_form(_('Not a valid Jabber ID'));
+ return;
+ } else if ($user->jabber == $jabber) {
+ $this->show_form(_('That is already your Jabber ID.'));
+ return;
+ } else if ($this->jabber_exists($jabber)) {
+ $this->show_form(_('Jabber ID already belongs to another user.'));
+ return;
+ }
+
+ $confirm = new Confirm_address();
+ $confirm->address = $jabber;
+ $confirm->address_type = 'jabber';
+ $confirm->user_id = $user->id;
+ $confirm->code = common_confirmation_code(64);
+
+ $result = $confirm->insert();
+
+ if ($result === FALSE) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_server_error(_('Couldn\'t insert confirmation code.'));
+ return;
+ }
+
+ if (!common_config('queue', 'enabled')) {
+ jabber_confirm_address($confirm->code,
+ $user->nickname,
+ $jabber);
+ }
+
+ $msg = sprintf(_('A confirmation code was sent to the IM address you added. You must approve %s for sending messages to you.'), jabber_daemon_address());
+
+ $this->show_form($msg, TRUE);
+ }
+
+ function cancel_confirmation() {
+ $jabber = $this->arg('jabber');
+ $confirm = $this->get_confirmation();
+ if (!$confirm) {
+ $this->show_form(_('No pending confirmation to cancel.'));
+ return;
+ }
+ if ($confirm->address != $jabber) {
+ $this->show_form(_('That is the wrong IM address.'));
+ return;
+ }
$result = $confirm->delete();
if (!$result) {
- common_log_db_error($confirm, 'DELETE', __FILE__);
+ common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
return;
}
$this->show_form(_('Confirmation cancelled.'), TRUE);
- }
-
- function remove_address() {
-
- $user = common_current_user();
- $jabber = $this->arg('jabber');
-
- # Maybe an old tab open...?
-
- if ($user->jabber != $jabber) {
- $this->show_form(_('That is not your Jabber ID.'));
- return;
- }
-
- $user->query('BEGIN');
- $original = clone($user);
- $user->jabber = NULL;
- $result = $user->updateKeys($original);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
- $user->query('COMMIT');
-
- # XXX: unsubscribe to the old address
-
- $this->show_form(_('The address was removed.'), TRUE);
- }
-
- function jabber_exists($jabber) {
- $user = common_current_user();
- $other = User::staticGet('jabber', $jabber);
- if (!$other) {
- return false;
- } else {
- return $other->id != $user->id;
- }
- }
+ }
+
+ function remove_address() {
+
+ $user = common_current_user();
+ $jabber = $this->arg('jabber');
+
+ # Maybe an old tab open...?
+
+ if ($user->jabber != $jabber) {
+ $this->show_form(_('That is not your Jabber ID.'));
+ return;
+ }
+
+ $user->query('BEGIN');
+ $original = clone($user);
+ $user->jabber = NULL;
+ $result = $user->updateKeys($original);
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
+ $user->query('COMMIT');
+
+ # XXX: unsubscribe to the old address
+
+ $this->show_form(_('The address was removed.'), TRUE);
+ }
+
+ function jabber_exists($jabber) {
+ $user = common_current_user();
+ $other = User::staticGet('jabber', $jabber);
+ if (!$other) {
+ return false;
+ } else {
+ return $other->id != $user->id;
+ }
+ }
}
diff --git a/_darcs/pristine/actions/invite.php b/_darcs/pristine/actions/invite.php
index c7d92085c..e5cc6ad01 100644
--- a/_darcs/pristine/actions/invite.php
+++ b/_darcs/pristine/actions/invite.php
@@ -21,179 +21,179 @@ if (!defined('LACONICA')) { exit(1); }
class InviteAction extends Action {
- function is_readonly() {
- return false;
- }
+ function is_readonly() {
+ return false;
+ }
function handle($args) {
parent::handle($args);
- if (!common_logged_in()) {
- $this->client_error(sprintf(_('You must be logged in to invite other users to use %s'),
- common_config('site', 'name')));
- return;
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->send_invitations();
- } else {
- $this->show_form();
- }
- }
-
- function send_invitations() {
-
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $user = common_current_user();
- $profile = $user->getProfile();
-
- $bestname = $profile->getBestName();
- $sitename = common_config('site', 'name');
- $personal = $this->trimmed('personal');
-
- $addresses = explode("\n", $this->trimmed('addresses'));
-
- foreach ($addresses as $email) {
- $email = trim($email);
- if (!Validate::email($email, true)) {
- $this->show_form(sprintf(_('Invalid email address: %s'), $email));
- return;
- }
- }
-
- $already = array();
- $subbed = array();
-
- foreach ($addresses as $email) {
- $email = common_canonical_email($email);
- $other = User::staticGet('email', $email);
- if ($other) {
- if ($user->isSubscribed($other)) {
- $already[] = $other;
- } else {
- subs_subscribe_to($user, $other);
- $subbed[] = $other;
- }
- } else {
- $sent[] = $email;
- $this->send_invitation($email, $user, $personal);
- }
- }
-
- common_show_header(_('Invitation(s) sent'));
- if ($already) {
- common_element('p', NULL, _('You are already subscribed to these users:'));
- common_element_start('ul');
- foreach ($already as $other) {
- common_element('li', NULL, sprintf(_('%s (%s)'), $other->nickname, $other->email));
- }
- common_element_end('ul');
- }
- if ($subbed) {
- common_element('p', NULL, _('These people are already users and you were automatically subscribed to them:'));
- common_element_start('ul');
- foreach ($subbed as $other) {
- common_element('li', NULL, sprintf(_('%s (%s)'), $other->nickname, $other->email));
- }
- common_element_end('ul');
- }
- if ($sent) {
- common_element('p', NULL, _('Invitation(s) sent to the following people:'));
- common_element_start('ul');
- foreach ($sent as $other) {
- common_element('li', NULL, $other);
- }
- common_element_end('ul');
- common_element('p', NULL, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!'));
- }
- common_show_footer();
- }
-
- function show_top($error=NULL) {
- if ($error) {
- common_element('p', 'error', $error);
- } else {
- common_element_start('div', 'instructions');
- common_element('p', NULL,
- _('Use this form to invite your friends and colleagues to use this service.'));
- common_element_end('div');
- }
- }
-
- function show_form($error=NULL) {
-
- global $config;
-
- common_show_header(_('Invite new users'), NULL, $error, array($this, 'show_top'));
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'invite',
- 'action' => common_local_url('invite')));
- common_hidden('token', common_session_token());
-
- common_textarea('addresses', _('Email addresses'),
- $this->trimmed('addresses'),
- _('Addresses of friends to invite (one per line)'));
-
- common_textarea('personal', _('Personal message'),
- $this->trimmed('personal'),
- _('Optionally add a personal message to the invitation.'));
-
- common_submit('send', _('Send'));
-
- common_element_end('form');
-
- common_show_footer();
- }
-
- function send_invitation($email, $user, $personal) {
-
- $profile = $user->getProfile();
- $bestname = $profile->getBestName();
-
- $sitename = common_config('site', 'name');
-
- $invite = new Invitation();
-
- $invite->address = $email;
- $invite->address_type = 'email';
- $invite->code = common_confirmation_code(128);
- $invite->user_id = $user->id;
- $invite->created = common_sql_now();
-
- if (!$invite->insert()) {
- common_log_db_error($invite, 'INSERT', __FILE__);
- return false;
- }
-
- $recipients = array($email);
-
- $headers['From'] = mail_notify_from();
- $headers['To'] = $email;
- $headers['Subject'] = sprintf(_('%1$s has invited you to join them on %2$s'), $bestname, $sitename);
-
- $body = sprintf(_("%1\$s has invited you to join them on %2\$s (%3\$s).\n\n".
- "%2\$s is a micro-blogging service that lets you keep up-to-date with people you know and people who interest you.\n\n".
- "You can also share news about yourself, your thoughts, or your life online with people who know about you. ".
- "It's also great for meeting new people who share your interests.\n\n".
- "%1\$s said:\n\n%4\$s\n\n".
- "You can see %1\$s's profile page on %2\$s here:\n\n".
- "%5\$s\n\n".
- "If you'd like to try the service, click on the link below to accept the invitation.\n\n".
- "%6\$s\n\n".
- "If not, you can ignore this message. Thanks for your patience and your time.\n\n".
- "Sincerely, %2\$s\n"),
- $bestname,
- $sitename,
- common_root_url(),
- $personal,
- common_local_url('showstream', array('nickname' => $user->nickname)),
- common_local_url('register', array('code' => $invite->code)));
-
- mail_send($recipients, $headers, $body);
- }
+ if (!common_logged_in()) {
+ $this->client_error(sprintf(_('You must be logged in to invite other users to use %s'),
+ common_config('site', 'name')));
+ return;
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->send_invitations();
+ } else {
+ $this->show_form();
+ }
+ }
+
+ function send_invitations() {
+
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $user = common_current_user();
+ $profile = $user->getProfile();
+
+ $bestname = $profile->getBestName();
+ $sitename = common_config('site', 'name');
+ $personal = $this->trimmed('personal');
+
+ $addresses = explode("\n", $this->trimmed('addresses'));
+
+ foreach ($addresses as $email) {
+ $email = trim($email);
+ if (!Validate::email($email, true)) {
+ $this->show_form(sprintf(_('Invalid email address: %s'), $email));
+ return;
+ }
+ }
+
+ $already = array();
+ $subbed = array();
+
+ foreach ($addresses as $email) {
+ $email = common_canonical_email($email);
+ $other = User::staticGet('email', $email);
+ if ($other) {
+ if ($user->isSubscribed($other)) {
+ $already[] = $other;
+ } else {
+ subs_subscribe_to($user, $other);
+ $subbed[] = $other;
+ }
+ } else {
+ $sent[] = $email;
+ $this->send_invitation($email, $user, $personal);
+ }
+ }
+
+ common_show_header(_('Invitation(s) sent'));
+ if ($already) {
+ common_element('p', NULL, _('You are already subscribed to these users:'));
+ common_element_start('ul');
+ foreach ($already as $other) {
+ common_element('li', NULL, sprintf(_('%s (%s)'), $other->nickname, $other->email));
+ }
+ common_element_end('ul');
+ }
+ if ($subbed) {
+ common_element('p', NULL, _('These people are already users and you were automatically subscribed to them:'));
+ common_element_start('ul');
+ foreach ($subbed as $other) {
+ common_element('li', NULL, sprintf(_('%s (%s)'), $other->nickname, $other->email));
+ }
+ common_element_end('ul');
+ }
+ if ($sent) {
+ common_element('p', NULL, _('Invitation(s) sent to the following people:'));
+ common_element_start('ul');
+ foreach ($sent as $other) {
+ common_element('li', NULL, $other);
+ }
+ common_element_end('ul');
+ common_element('p', NULL, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!'));
+ }
+ common_show_footer();
+ }
+
+ function show_top($error=NULL) {
+ if ($error) {
+ common_element('p', 'error', $error);
+ } else {
+ common_element_start('div', 'instructions');
+ common_element('p', NULL,
+ _('Use this form to invite your friends and colleagues to use this service.'));
+ common_element_end('div');
+ }
+ }
+
+ function show_form($error=NULL) {
+
+ global $config;
+
+ common_show_header(_('Invite new users'), NULL, $error, array($this, 'show_top'));
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'invite',
+ 'action' => common_local_url('invite')));
+ common_hidden('token', common_session_token());
+
+ common_textarea('addresses', _('Email addresses'),
+ $this->trimmed('addresses'),
+ _('Addresses of friends to invite (one per line)'));
+
+ common_textarea('personal', _('Personal message'),
+ $this->trimmed('personal'),
+ _('Optionally add a personal message to the invitation.'));
+
+ common_submit('send', _('Send'));
+
+ common_element_end('form');
+
+ common_show_footer();
+ }
+
+ function send_invitation($email, $user, $personal) {
+
+ $profile = $user->getProfile();
+ $bestname = $profile->getBestName();
+
+ $sitename = common_config('site', 'name');
+
+ $invite = new Invitation();
+
+ $invite->address = $email;
+ $invite->address_type = 'email';
+ $invite->code = common_confirmation_code(128);
+ $invite->user_id = $user->id;
+ $invite->created = common_sql_now();
+
+ if (!$invite->insert()) {
+ common_log_db_error($invite, 'INSERT', __FILE__);
+ return false;
+ }
+
+ $recipients = array($email);
+
+ $headers['From'] = mail_notify_from();
+ $headers['To'] = $email;
+ $headers['Subject'] = sprintf(_('%1$s has invited you to join them on %2$s'), $bestname, $sitename);
+
+ $body = sprintf(_("%1\$s has invited you to join them on %2\$s (%3\$s).\n\n".
+ "%2\$s is a micro-blogging service that lets you keep up-to-date with people you know and people who interest you.\n\n".
+ "You can also share news about yourself, your thoughts, or your life online with people who know about you. ".
+ "It's also great for meeting new people who share your interests.\n\n".
+ "%1\$s said:\n\n%4\$s\n\n".
+ "You can see %1\$s's profile page on %2\$s here:\n\n".
+ "%5\$s\n\n".
+ "If you'd like to try the service, click on the link below to accept the invitation.\n\n".
+ "%6\$s\n\n".
+ "If not, you can ignore this message. Thanks for your patience and your time.\n\n".
+ "Sincerely, %2\$s\n"),
+ $bestname,
+ $sitename,
+ common_root_url(),
+ $personal,
+ common_local_url('showstream', array('nickname' => $user->nickname)),
+ common_local_url('register', array('code' => $invite->code)));
+
+ mail_send($recipients, $headers, $body);
+ }
}
diff --git a/_darcs/pristine/actions/login.php b/_darcs/pristine/actions/login.php
index ccec9cf8a..5e4d45149 100644
--- a/_darcs/pristine/actions/login.php
+++ b/_darcs/pristine/actions/login.php
@@ -21,132 +21,132 @@ if (!defined('LACONICA')) { exit(1); }
class LoginAction extends Action {
- function is_readonly() {
- return true;
- }
+ function is_readonly() {
+ return true;
+ }
- function handle($args) {
- parent::handle($args);
- if (common_is_real_login()) {
- common_user_error(_('Already logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->check_login();
- } else {
- $this->show_form();
- }
- }
+ function handle($args) {
+ parent::handle($args);
+ if (common_is_real_login()) {
+ common_user_error(_('Already logged in.'));
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->check_login();
+ } else {
+ $this->show_form();
+ }
+ }
- function check_login() {
- # XXX: login throttle
+ function check_login() {
+ # XXX: login throttle
- # CSRF protection - token set in common_notice_form()
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ # CSRF protection - token set in common_notice_form()
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
- $nickname = common_canonical_nickname($this->trimmed('nickname'));
- $password = $this->arg('password');
- if (common_check_user($nickname, $password)) {
- # success!
- if (!common_set_user($nickname)) {
- common_server_error(_('Error setting user.'));
- return;
- }
- common_real_login(true);
- if ($this->boolean('rememberme')) {
- common_debug('Adding rememberme cookie for ' . $nickname);
- common_rememberme();
- }
- # success!
- $url = common_get_returnto();
- if ($url) {
- # We don't have to return to it again
- common_set_returnto(NULL);
- } else {
- $url = common_local_url('all',
- array('nickname' =>
- $nickname));
- }
- common_redirect($url);
- } else {
- $this->show_form(_('Incorrect username or password.'));
- return;
- }
+ $nickname = common_canonical_nickname($this->trimmed('nickname'));
+ $password = $this->arg('password');
+ if (common_check_user($nickname, $password)) {
+ # success!
+ if (!common_set_user($nickname)) {
+ common_server_error(_('Error setting user.'));
+ return;
+ }
+ common_real_login(true);
+ if ($this->boolean('rememberme')) {
+ common_debug('Adding rememberme cookie for ' . $nickname);
+ common_rememberme();
+ }
+ # success!
+ $url = common_get_returnto();
+ if ($url) {
+ # We don't have to return to it again
+ common_set_returnto(NULL);
+ } else {
+ $url = common_local_url('all',
+ array('nickname' =>
+ $nickname));
+ }
+ common_redirect($url);
+ } else {
+ $this->show_form(_('Incorrect username or password.'));
+ return;
+ }
- # success!
- if (!common_set_user($user)) {
- common_server_error(_('Error setting user.'));
- return;
- }
+ # success!
+ if (!common_set_user($user)) {
+ common_server_error(_('Error setting user.'));
+ return;
+ }
- common_real_login(true);
+ common_real_login(true);
- if ($this->boolean('rememberme')) {
- common_debug('Adding rememberme cookie for ' . $nickname);
- common_rememberme($user);
- }
- # success!
- $url = common_get_returnto();
- if ($url) {
- # We don't have to return to it again
- common_set_returnto(NULL);
- } else {
- $url = common_local_url('all',
- array('nickname' =>
- $nickname));
- }
- common_redirect($url);
- }
+ if ($this->boolean('rememberme')) {
+ common_debug('Adding rememberme cookie for ' . $nickname);
+ common_rememberme($user);
+ }
+ # success!
+ $url = common_get_returnto();
+ if ($url) {
+ # We don't have to return to it again
+ common_set_returnto(NULL);
+ } else {
+ $url = common_local_url('all',
+ array('nickname' =>
+ $nickname));
+ }
+ common_redirect($url);
+ }
- function show_form($error=NULL) {
- common_show_header(_('Login'), NULL, $error, array($this, 'show_top'));
- common_element_start('form', array('method' => 'post',
- 'id' => 'login',
- 'action' => common_local_url('login')));
- common_input('nickname', _('Nickname'));
- common_password('password', _('Password'));
- common_checkbox('rememberme', _('Remember me'), false,
- _('Automatically login in the future; ' .
- 'not for shared computers!'));
- common_submit('submit', _('Login'));
- common_hidden('token', common_session_token());
- common_element_end('form');
- common_element_start('p');
- common_element('a', array('href' => common_local_url('recoverpassword')),
- _('Lost or forgotten password?'));
- common_element_end('p');
- common_show_footer();
- }
+ function show_form($error=NULL) {
+ common_show_header(_('Login'), NULL, $error, array($this, 'show_top'));
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'login',
+ 'action' => common_local_url('login')));
+ common_input('nickname', _('Nickname'));
+ common_password('password', _('Password'));
+ common_checkbox('rememberme', _('Remember me'), false,
+ _('Automatically login in the future; ' .
+ 'not for shared computers!'));
+ common_submit('submit', _('Login'));
+ common_hidden('token', common_session_token());
+ common_element_end('form');
+ common_element_start('p');
+ common_element('a', array('href' => common_local_url('recoverpassword')),
+ _('Lost or forgotten password?'));
+ common_element_end('p');
+ common_show_footer();
+ }
- function get_instructions() {
- if (common_logged_in() &&
- !common_is_real_login() &&
- common_get_returnto())
- {
- # rememberme logins have to reauthenticate before
- # changing any profile settings (cookie-stealing protection)
- return _('For security reasons, please re-enter your ' .
- 'user name and password ' .
- 'before changing your settings.');
- } else {
- return _('Login with your username and password. ' .
- 'Don\'t have a username yet? ' .
- '[Register](%%action.register%%) a new account, or ' .
- 'try [OpenID](%%action.openidlogin%%). ');
- }
- }
+ function get_instructions() {
+ if (common_logged_in() &&
+ !common_is_real_login() &&
+ common_get_returnto())
+ {
+ # rememberme logins have to reauthenticate before
+ # changing any profile settings (cookie-stealing protection)
+ return _('For security reasons, please re-enter your ' .
+ 'user name and password ' .
+ 'before changing your settings.');
+ } else {
+ return _('Login with your username and password. ' .
+ 'Don\'t have a username yet? ' .
+ '[Register](%%action.register%%) a new account, or ' .
+ 'try [OpenID](%%action.openidlogin%%). ');
+ }
+ }
- function show_top($error=NULL) {
- if ($error) {
- common_element('p', 'error', $error);
- } else {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
- }
+ function show_top($error=NULL) {
+ if ($error) {
+ common_element('p', 'error', $error);
+ } else {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+ }
}
diff --git a/_darcs/pristine/actions/logout.php b/_darcs/pristine/actions/logout.php
index f00fa0ba7..5f7b9d502 100644
--- a/_darcs/pristine/actions/logout.php
+++ b/_darcs/pristine/actions/logout.php
@@ -22,20 +22,20 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/openid.php');
class LogoutAction extends Action {
-
- function is_readonly() {
- return true;
- }
-
- function handle($args) {
- parent::handle($args);
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- } else {
- common_set_user(NULL);
- common_real_login(false); # not logged in
- common_forgetme(); # don't log back in!
- common_redirect(common_local_url('public'));
- }
- }
+
+ function is_readonly() {
+ return true;
+ }
+
+ function handle($args) {
+ parent::handle($args);
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ } else {
+ common_set_user(NULL);
+ common_real_login(false); # not logged in
+ common_forgetme(); # don't log back in!
+ common_redirect(common_local_url('public'));
+ }
+ }
}
diff --git a/_darcs/pristine/actions/microsummary.php b/_darcs/pristine/actions/microsummary.php
index 104467d29..ced4b0d1e 100644
--- a/_darcs/pristine/actions/microsummary.php
+++ b/_darcs/pristine/actions/microsummary.php
@@ -21,26 +21,26 @@ if (!defined('LACONICA')) { exit(1); }
class MicrosummaryAction extends Action {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- $nickname = common_canonical_nickname($this->arg('nickname'));
- $user = User::staticGet('nickname', $nickname);
+ $nickname = common_canonical_nickname($this->arg('nickname'));
+ $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- $this->client_error(_('No such user'), 404);
- return;
- }
-
- $notice = $user->getCurrentNotice();
-
- if (!$notice) {
- $this->client_error(_('No current status'), 404);
- }
-
- header('Content-Type: text/plain');
-
- print $user->nickname . ': ' . $notice->content;
- }
+ if (!$user) {
+ $this->client_error(_('No such user'), 404);
+ return;
+ }
+
+ $notice = $user->getCurrentNotice();
+
+ if (!$notice) {
+ $this->client_error(_('No current status'), 404);
+ }
+
+ header('Content-Type: text/plain');
+
+ print $user->nickname . ': ' . $notice->content;
+ }
}
diff --git a/_darcs/pristine/actions/newmessage.php b/_darcs/pristine/actions/newmessage.php
index da48fc7e7..121fc4246 100644
--- a/_darcs/pristine/actions/newmessage.php
+++ b/_darcs/pristine/actions/newmessage.php
@@ -20,116 +20,116 @@
if (!defined('LACONICA')) { exit(1); }
class NewmessageAction extends Action {
-
- function handle($args) {
- parent::handle($args);
-
- if (!common_logged_in()) {
- $this->client_error(_('Not logged in.'), 403);
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->save_new_message();
- } else {
- $this->show_form();
- }
- }
-
- function save_new_message() {
- $user = common_current_user();
- assert($user); # XXX: maybe an error instead...
-
- # CSRF protection
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $content = $this->trimmed('content');
- $to = $this->trimmed('to');
-
- if (!$content) {
- $this->show_form(_('No content!'));
- return;
- } else {
- $content_shortened = common_shorten_links($content);
-
- if (mb_strlen($content_shortened) > 140) {
- common_debug("Content = '$content_shortened'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
- $this->show_form(_('That\'s too long. Max message size is 140 chars.'));
- return;
- }
- }
-
- $other = User::staticGet('id', $to);
-
- if (!$other) {
- $this->show_form(_('No recipient specified.'));
- return;
- } else if (!$user->mutuallySubscribed($other)) {
- $this->client_error(_('You can\'t send a message to this user.'), 404);
- return;
- } else if ($user->id == $other->id) {
- $this->client_error(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'), 403);
- return;
- }
-
- $message = Message::saveNew($user->id, $other->id, $content, 'web');
-
- if (is_string($message)) {
- $this->show_form($message);
- return;
- }
-
- $this->notify($user, $other, $message);
-
- $url = common_local_url('outbox', array('nickname' => $user->nickname));
-
- common_redirect($url, 303);
- }
-
- function show_top($params) {
-
- list($content, $user, $to) = $params;
-
- assert(!is_null($user));
-
- common_message_form($content, $user, $to);
- }
-
- function show_form($msg=NULL) {
-
- $content = $this->trimmed('content');
- $user = common_current_user();
-
- $to = $this->trimmed('to');
-
- $other = User::staticGet('id', $to);
-
- if (!$other) {
- $this->client_error(_('No such user'), 404);
- return;
- }
-
- if (!$user->mutuallySubscribed($other)) {
- $this->client_error(_('You can\'t send a message to this user.'), 404);
- return;
- }
-
- common_show_header(_('New message'), NULL,
- array($content, $user, $other),
- array($this, 'show_top'));
-
- if ($msg) {
- common_element('p', array('id'=>'error'), $msg);
- }
-
- common_show_footer();
- }
-
- function notify($from, $to, $message) {
- mail_notify_message($message, $from, $to);
- # XXX: Jabber, SMS notifications... probably queued
- }
+
+ function handle($args) {
+ parent::handle($args);
+
+ if (!common_logged_in()) {
+ $this->client_error(_('Not logged in.'), 403);
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->save_new_message();
+ } else {
+ $this->show_form();
+ }
+ }
+
+ function save_new_message() {
+ $user = common_current_user();
+ assert($user); # XXX: maybe an error instead...
+
+ # CSRF protection
+
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $content = $this->trimmed('content');
+ $to = $this->trimmed('to');
+
+ if (!$content) {
+ $this->show_form(_('No content!'));
+ return;
+ } else {
+ $content_shortened = common_shorten_links($content);
+
+ if (mb_strlen($content_shortened) > 140) {
+ common_debug("Content = '$content_shortened'", __FILE__);
+ common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
+ $this->show_form(_('That\'s too long. Max message size is 140 chars.'));
+ return;
+ }
+ }
+
+ $other = User::staticGet('id', $to);
+
+ if (!$other) {
+ $this->show_form(_('No recipient specified.'));
+ return;
+ } else if (!$user->mutuallySubscribed($other)) {
+ $this->client_error(_('You can\'t send a message to this user.'), 404);
+ return;
+ } else if ($user->id == $other->id) {
+ $this->client_error(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'), 403);
+ return;
+ }
+
+ $message = Message::saveNew($user->id, $other->id, $content, 'web');
+
+ if (is_string($message)) {
+ $this->show_form($message);
+ return;
+ }
+
+ $this->notify($user, $other, $message);
+
+ $url = common_local_url('outbox', array('nickname' => $user->nickname));
+
+ common_redirect($url, 303);
+ }
+
+ function show_top($params) {
+
+ list($content, $user, $to) = $params;
+
+ assert(!is_null($user));
+
+ common_message_form($content, $user, $to);
+ }
+
+ function show_form($msg=NULL) {
+
+ $content = $this->trimmed('content');
+ $user = common_current_user();
+
+ $to = $this->trimmed('to');
+
+ $other = User::staticGet('id', $to);
+
+ if (!$other) {
+ $this->client_error(_('No such user'), 404);
+ return;
+ }
+
+ if (!$user->mutuallySubscribed($other)) {
+ $this->client_error(_('You can\'t send a message to this user.'), 404);
+ return;
+ }
+
+ common_show_header(_('New message'), NULL,
+ array($content, $user, $other),
+ array($this, 'show_top'));
+
+ if ($msg) {
+ common_element('p', array('id'=>'error'), $msg);
+ }
+
+ common_show_footer();
+ }
+
+ function notify($from, $to, $message) {
+ mail_notify_message($message, $from, $to);
+ # XXX: Jabber, SMS notifications... probably queued
+ }
}
diff --git a/_darcs/pristine/actions/newnotice.php b/_darcs/pristine/actions/newnotice.php
index 42b48923f..7c3ad8815 100644
--- a/_darcs/pristine/actions/newnotice.php
+++ b/_darcs/pristine/actions/newnotice.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,132 +23,132 @@ require_once INSTALLDIR . '/lib/noticelist.php';
class NewnoticeAction extends Action {
- function handle($args) {
- parent::handle($args);
-
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-
- # CSRF protection - token set in common_notice_form()
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $this->save_new_notice();
- } else {
- $this->show_form();
- }
- }
-
- function save_new_notice() {
-
- $user = common_current_user();
- assert($user); # XXX: maybe an error instead...
- $content = $this->trimmed('status_textarea');
-
- if (!$content) {
- $this->show_form(_('No content!'));
- return;
- } else {
- $content_shortened = common_shorten_links($content);
-
- if (mb_strlen($content_shortened) > 140) {
- common_debug("Content = '$content_shortened'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
- $this->show_form(_('That\'s too long. Max notice size is 140 chars.'));
- return;
- }
- }
-
- $inter = new CommandInterpreter();
-
- $cmd = $inter->handle_command($user, $content_shortened);
-
- if ($cmd) {
- if ($this->boolean('ajax')) {
- $cmd->execute(new AjaxWebChannel());
- } else {
- $cmd->execute(new WebChannel());
- }
- return;
- }
-
- $replyto = $this->trimmed('inreplyto');
-
- $notice = Notice::saveNew($user->id, $content, 'web', 1, ($replyto == 'false') ? NULL : $replyto);
-
- if (is_string($notice)) {
- $this->show_form($notice);
- return;
- }
-
- common_broadcast_notice($notice);
-
- if ($this->boolean('ajax')) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Notice posted'));
- common_element_end('head');
- common_element_start('body');
- $this->show_notice($notice);
- common_element_end('body');
- common_element_end('html');
- } else {
- $returnto = $this->trimmed('returnto');
-
- if ($returnto) {
- $url = common_local_url($returnto,
- array('nickname' => $user->nickname));
- } else {
- $url = common_local_url('shownotice',
- array('notice' => $notice->id));
- }
- common_redirect($url, 303);
- }
- }
-
- function ajax_error_msg($msg) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Ajax Error'));
- common_element_end('head');
- common_element_start('body');
- common_element('p', array('id' => 'error'), $msg);
- common_element_end('body');
- common_element_end('html');
- }
-
- function show_top($content=NULL) {
- common_notice_form(NULL, $content);
- }
-
- function show_form($msg=NULL) {
- if ($msg && $this->boolean('ajax')) {
- $this->ajax_error_msg($msg);
- return;
- }
- $content = $this->trimmed('status_textarea');
- if (!$content) {
- $replyto = $this->trimmed('replyto');
- $profile = Profile::staticGet('nickname', $replyto);
- if ($profile) {
- $content = '@' . $profile->nickname . ' ';
- }
- }
- common_show_header(_('New notice'), NULL, $content,
- array($this, 'show_top'));
- if ($msg) {
- common_element('p', array('id' => 'error'), $msg);
- }
- common_show_footer();
- }
-
- function show_notice($notice) {
+ function handle($args) {
+ parent::handle($args);
+
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+
+ # CSRF protection - token set in common_notice_form()
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $this->save_new_notice();
+ } else {
+ $this->show_form();
+ }
+ }
+
+ function save_new_notice() {
+
+ $user = common_current_user();
+ assert($user); # XXX: maybe an error instead...
+ $content = $this->trimmed('status_textarea');
+
+ if (!$content) {
+ $this->show_form(_('No content!'));
+ return;
+ } else {
+ $content_shortened = common_shorten_links($content);
+
+ if (mb_strlen($content_shortened) > 140) {
+ common_debug("Content = '$content_shortened'", __FILE__);
+ common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
+ $this->show_form(_('That\'s too long. Max notice size is 140 chars.'));
+ return;
+ }
+ }
+
+ $inter = new CommandInterpreter();
+
+ $cmd = $inter->handle_command($user, $content_shortened);
+
+ if ($cmd) {
+ if ($this->boolean('ajax')) {
+ $cmd->execute(new AjaxWebChannel());
+ } else {
+ $cmd->execute(new WebChannel());
+ }
+ return;
+ }
+
+ $replyto = $this->trimmed('inreplyto');
+
+ $notice = Notice::saveNew($user->id, $content, 'web', 1, ($replyto == 'false') ? NULL : $replyto);
+
+ if (is_string($notice)) {
+ $this->show_form($notice);
+ return;
+ }
+
+ common_broadcast_notice($notice);
+
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Notice posted'));
+ common_element_end('head');
+ common_element_start('body');
+ $this->show_notice($notice);
+ common_element_end('body');
+ common_element_end('html');
+ } else {
+ $returnto = $this->trimmed('returnto');
+
+ if ($returnto) {
+ $url = common_local_url($returnto,
+ array('nickname' => $user->nickname));
+ } else {
+ $url = common_local_url('shownotice',
+ array('notice' => $notice->id));
+ }
+ common_redirect($url, 303);
+ }
+ }
+
+ function ajax_error_msg($msg) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Ajax Error'));
+ common_element_end('head');
+ common_element_start('body');
+ common_element('p', array('id' => 'error'), $msg);
+ common_element_end('body');
+ common_element_end('html');
+ }
+
+ function show_top($content=NULL) {
+ common_notice_form(NULL, $content);
+ }
+
+ function show_form($msg=NULL) {
+ if ($msg && $this->boolean('ajax')) {
+ $this->ajax_error_msg($msg);
+ return;
+ }
+ $content = $this->trimmed('status_textarea');
+ if (!$content) {
+ $replyto = $this->trimmed('replyto');
+ $profile = Profile::staticGet('nickname', $replyto);
+ if ($profile) {
+ $content = '@' . $profile->nickname . ' ';
+ }
+ }
+ common_show_header(_('New notice'), NULL, $content,
+ array($this, 'show_top'));
+ if ($msg) {
+ common_element('p', array('id' => 'error'), $msg);
+ }
+ common_show_footer();
+ }
+
+ function show_notice($notice) {
$nli = new NoticeListItem($notice);
$nli->show();
- }
+ }
}
diff --git a/_darcs/pristine/actions/noticesearch.php b/_darcs/pristine/actions/noticesearch.php
index 96e4d777f..53d78e199 100644
--- a/_darcs/pristine/actions/noticesearch.php
+++ b/_darcs/pristine/actions/noticesearch.php
@@ -25,140 +25,140 @@ require_once(INSTALLDIR.'/lib/searchaction.php');
class NoticesearchAction extends SearchAction {
- function get_instructions() {
- return _('Search for notices on %%site.name%% by their contents. Separate search terms by spaces; they must be 3 characters or more.');
- }
+ function get_instructions() {
+ return _('Search for notices on %%site.name%% by their contents. Separate search terms by spaces; they must be 3 characters or more.');
+ }
- function get_title() {
- return _('Text search');
- }
+ function get_title() {
+ return _('Text search');
+ }
- function show_results($q, $page) {
+ function show_results($q, $page) {
- $notice = new Notice();
+ $notice = new Notice();
- # lcase it for comparison
- $q = strtolower($q);
+ # lcase it for comparison
+ $q = strtolower($q);
$search_engine = $notice->getSearchEngine('identica_notices');
$search_engine->set_sort_mode('chron');
- # Ask for an extra to see if there's more.
- $search_engine->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
+ # Ask for an extra to see if there's more.
+ $search_engine->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
if (false === $search_engine->query($q)) {
$cnt = 0;
}
else {
- $cnt = $notice->find();
+ $cnt = $notice->find();
}
- if ($cnt > 0) {
- $terms = preg_split('/[\s,]+/', $q);
- common_element_start('ul', array('id' => 'notices'));
- for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
- if ($notice->fetch()) {
- $this->show_notice($notice, $terms);
- } else {
- // shouldn't happen!
- break;
- }
- }
- common_element_end('ul');
- } else {
- common_element('p', 'error', _('No results'));
- }
-
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'noticesearch', array('q' => $q));
- }
-
- function show_header($arr) {
- if ($arr) {
- $q = $arr[0];
- }
- if ($q) {
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('noticesearchrss',
- array('q' => $q)),
- 'type' => 'application/rss+xml',
- 'title' => _('Search Stream Feed')));
- }
- }
-
- # XXX: refactor and combine with StreamAction::show_notice()
-
- function show_notice($notice, $terms) {
- $profile = $notice->getProfile();
- if (!$profile) {
- common_log_db_error($notice, 'SELECT', __FILE__);
- $this->server_error(_('Notice without matching profile'));
- return;
- }
- # XXX: RDFa
- common_element_start('li', array('class' => 'notice_single',
- 'id' => 'notice-' . $notice->id));
- $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
- common_element_start('a', array('href' => $profile->profileurl));
- common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
- 'class' => 'avatar stream',
- 'width' => AVATAR_STREAM_SIZE,
- 'height' => AVATAR_STREAM_SIZE,
- 'alt' =>
- ($profile->fullname) ? $profile->fullname :
- $profile->nickname));
- common_element_end('a');
- common_element('a', array('href' => $profile->profileurl,
- 'class' => 'nickname'),
- $profile->nickname);
- # FIXME: URL, image, video, audio
- common_element_start('p', array('class' => 'content'));
- if ($notice->rendered) {
- common_raw($this->highlight($notice->rendered, $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)
- common_raw($this->highlight(common_render_content($notice->content, $notice), $terms));
- }
- common_element_end('p');
- $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
- common_element_start('p', 'time');
- common_element('a', array('class' => 'permalink',
- 'href' => $noticeurl,
- 'title' => common_exact_date($notice->created)),
- common_date_string($notice->created));
- if ($notice->reply_to) {
- $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
- common_text(' (');
- common_element('a', array('class' => 'inreplyto',
- 'href' => $replyurl),
- _('in reply to...'));
- common_text(')');
- }
- common_element_start('a',
- array('href' => common_local_url('newnotice',
- array('replyto' => $profile->nickname)),
- 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
- 'title' => _('reply'),
- 'class' => 'replybutton'));
- common_hidden('posttoken', common_session_token());
-
- common_raw('&rarr;');
- common_element_end('a');
- common_element_end('p');
- common_element_end('li');
- }
-
- function highlight($text, $terms) {
- /* Highligh serach terms */
- $pattern = '/('.implode('|',array_map('htmlspecialchars', $terms)).')/i';
- $result = preg_replace($pattern, '<strong>\\1</strong>', $text);
-
- /* Remove highlighting from inside links, loop incase multiple highlights in links */
- $pattern = '/(href="[^"]*)<strong>('.implode('|',array_map('htmlspecialchars', $terms)).')<\/strong>([^"]*")/iU';
- do {
- $result = preg_replace($pattern, '\\1\\2\\3', $result, -1, $count);
- } while ($count);
- return $result;
- }
+ if ($cnt > 0) {
+ $terms = preg_split('/[\s,]+/', $q);
+ common_element_start('ul', array('id' => 'notices'));
+ for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) {
+ if ($notice->fetch()) {
+ $this->show_notice($notice, $terms);
+ } else {
+ // shouldn't happen!
+ break;
+ }
+ }
+ common_element_end('ul');
+ } else {
+ common_element('p', 'error', _('No results'));
+ }
+
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'noticesearch', array('q' => $q));
+ }
+
+ function show_header($arr) {
+ if ($arr) {
+ $q = $arr[0];
+ }
+ if ($q) {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('noticesearchrss',
+ array('q' => $q)),
+ 'type' => 'application/rss+xml',
+ 'title' => _('Search Stream Feed')));
+ }
+ }
+
+ # XXX: refactor and combine with StreamAction::show_notice()
+
+ function show_notice($notice, $terms) {
+ $profile = $notice->getProfile();
+ if (!$profile) {
+ common_log_db_error($notice, 'SELECT', __FILE__);
+ $this->server_error(_('Notice without matching profile'));
+ return;
+ }
+ # XXX: RDFa
+ common_element_start('li', array('class' => 'notice_single',
+ 'id' => 'notice-' . $notice->id));
+ $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+ common_element_start('a', array('href' => $profile->profileurl));
+ common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
+ 'class' => 'avatar stream',
+ 'width' => AVATAR_STREAM_SIZE,
+ 'height' => AVATAR_STREAM_SIZE,
+ 'alt' =>
+ ($profile->fullname) ? $profile->fullname :
+ $profile->nickname));
+ common_element_end('a');
+ common_element('a', array('href' => $profile->profileurl,
+ 'class' => 'nickname'),
+ $profile->nickname);
+ # FIXME: URL, image, video, audio
+ common_element_start('p', array('class' => 'content'));
+ if ($notice->rendered) {
+ common_raw($this->highlight($notice->rendered, $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)
+ common_raw($this->highlight(common_render_content($notice->content, $notice), $terms));
+ }
+ common_element_end('p');
+ $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
+ common_element_start('p', 'time');
+ common_element('a', array('class' => 'permalink',
+ 'href' => $noticeurl,
+ 'title' => common_exact_date($notice->created)),
+ common_date_string($notice->created));
+ if ($notice->reply_to) {
+ $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
+ common_text(' (');
+ common_element('a', array('class' => 'inreplyto',
+ 'href' => $replyurl),
+ _('in reply to...'));
+ common_text(')');
+ }
+ common_element_start('a',
+ array('href' => common_local_url('newnotice',
+ array('replyto' => $profile->nickname)),
+ 'onclick' => 'doreply("'.$profile->nickname.'"); return false',
+ 'title' => _('reply'),
+ 'class' => 'replybutton'));
+ common_hidden('posttoken', common_session_token());
+
+ common_raw('&rarr;');
+ common_element_end('a');
+ common_element_end('p');
+ common_element_end('li');
+ }
+
+ function highlight($text, $terms) {
+ /* Highligh serach terms */
+ $pattern = '/('.implode('|',array_map('htmlspecialchars', $terms)).')/i';
+ $result = preg_replace($pattern, '<strong>\\1</strong>', $text);
+
+ /* Remove highlighting from inside links, loop incase multiple highlights in links */
+ $pattern = '/(href="[^"]*)<strong>('.implode('|',array_map('htmlspecialchars', $terms)).')<\/strong>([^"]*")/iU';
+ do {
+ $result = preg_replace($pattern, '\\1\\2\\3', $result, -1, $count);
+ } while ($count);
+ return $result;
+ }
}
diff --git a/_darcs/pristine/actions/noticesearchrss.php b/_darcs/pristine/actions/noticesearchrss.php
index 0f38515a0..a7df62ca0 100644
--- a/_darcs/pristine/actions/noticesearchrss.php
+++ b/_darcs/pristine/actions/noticesearchrss.php
@@ -25,46 +25,46 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class NoticesearchrssAction extends Rss10Action {
- function init() {
- return true;
- }
+ function init() {
+ return true;
+ }
- function get_notices($limit=0) {
+ function get_notices($limit=0) {
- $q = $this->trimmed('q');
- $notices = array();
+ $q = $this->trimmed('q');
+ $notices = array();
- $notice = new Notice();
+ $notice = new Notice();
- # lcase it for comparison
- $q = strtolower($q);
+ # lcase it for comparison
+ $q = strtolower($q);
$search_engine = $notice->getSearchEngine('identica_notices');
$search_engine->set_sort_mode('chron');
- if (!$limit) $limit = 20;
+ if (!$limit) $limit = 20;
$search_engine->limit(0, $limit, true);
$search_engine->query($q);
- $notice->find();
+ $notice->find();
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
- return $notices;
- }
+ return $notices;
+ }
- function get_channel() {
- global $config;
- $q = $this->trimmed('q');
- $c = array('url' => common_local_url('noticesearchrss', array('q' => $q)),
- 'title' => $config['site']['name'] . sprintf(_(' Search Stream for "%s"'), $q),
- 'link' => common_local_url('noticesearch', array('q' => $q)),
- 'description' => sprintf(_('All updates matching search term "%s"'), $q));
- return $c;
- }
+ function get_channel() {
+ global $config;
+ $q = $this->trimmed('q');
+ $c = array('url' => common_local_url('noticesearchrss', array('q' => $q)),
+ 'title' => $config['site']['name'] . sprintf(_(' Search Stream for "%s"'), $q),
+ 'link' => common_local_url('noticesearch', array('q' => $q)),
+ 'description' => sprintf(_('All updates matching search term "%s"'), $q));
+ return $c;
+ }
- function get_image() {
- return NULL;
- }
+ function get_image() {
+ return NULL;
+ }
}
diff --git a/_darcs/pristine/actions/nudge.php b/_darcs/pristine/actions/nudge.php
index 677f58800..6f3b4c95c 100644
--- a/_darcs/pristine/actions/nudge.php
+++ b/_darcs/pristine/actions/nudge.php
@@ -23,62 +23,62 @@ require_once(INSTALLDIR.'/lib/mail.php');
class NudgeAction extends Action {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- if (!common_logged_in()) {
- $this->client_error(_('Not logged in.'));
- return;
- }
+ if (!common_logged_in()) {
+ $this->client_error(_('Not logged in.'));
+ return;
+ }
- $user = common_current_user();
- $other = User::staticGet('nickname', $this->arg('nickname'));
+ $user = common_current_user();
+ $other = User::staticGet('nickname', $this->arg('nickname'));
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- common_redirect(common_local_url('showstream', array('nickname' => $other->nickname)));
- return;
- }
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ common_redirect(common_local_url('showstream', array('nickname' => $other->nickname)));
+ return;
+ }
- # CSRF protection
+ # CSRF protection
- $token = $this->trimmed('token');
-
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ $token = $this->trimmed('token');
+
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
if (!$other->email || !$other->emailnotifynudge) {
$this->client_error(_('This user doesn\'t allow nudges or hasn\'t confirmed or set his email yet.'));
return;
}
- $this->notify($user, $other);
+ $this->notify($user, $other);
- if ($this->boolean('ajax')) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Nudge sent'));
- common_element_end('head');
- common_element_start('body');
- common_nudge_response();
- common_element_end('body');
- common_element_end('html');
- } else {
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Nudge sent'));
+ common_element_end('head');
+ common_element_start('body');
+ common_nudge_response();
+ common_element_end('body');
+ common_element_end('html');
+ } else {
// display a confirmation to the user
- common_redirect(common_local_url('showstream',
- array('nickname' => $other->nickname)));
- }
- }
+ common_redirect(common_local_url('showstream',
+ array('nickname' => $other->nickname)));
+ }
+ }
- function notify($user, $other) {
- if ($other->id != $user->id) {
- if ($other->email && $other->emailnotifynudge) {
- mail_notify_nudge($user, $other);
- }
- # XXX: notify by IM
- # XXX: notify by SMS
- }
- }
+ function notify($user, $other) {
+ if ($other->id != $user->id) {
+ if ($other->email && $other->emailnotifynudge) {
+ mail_notify_nudge($user, $other);
+ }
+ # XXX: notify by IM
+ # XXX: notify by SMS
+ }
+ }
}
diff --git a/_darcs/pristine/actions/openidlogin.php b/_darcs/pristine/actions/openidlogin.php
index 1b289dbea..6192dfc34 100644
--- a/_darcs/pristine/actions/openidlogin.php
+++ b/_darcs/pristine/actions/openidlogin.php
@@ -23,70 +23,70 @@ require_once(INSTALLDIR.'/lib/openid.php');
class OpenidloginAction extends Action {
- function handle($args) {
- parent::handle($args);
- if (common_logged_in()) {
- common_user_error(_('Already logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $openid_url = $this->trimmed('openid_url');
+ function handle($args) {
+ parent::handle($args);
+ if (common_logged_in()) {
+ common_user_error(_('Already logged in.'));
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $openid_url = $this->trimmed('openid_url');
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'), $openid_url);
- return;
- }
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'), $openid_url);
+ return;
+ }
- $rememberme = $this->boolean('rememberme');
-
- common_ensure_session();
-
- $_SESSION['openid_rememberme'] = $rememberme;
-
- $result = oid_authenticate($openid_url,
- 'finishopenidlogin');
-
- if (is_string($result)) { # error message
- unset($_SESSION['openid_rememberme']);
- $this->show_form($result, $openid_url);
- }
- } else {
- $openid_url = oid_get_last();
- $this->show_form(NULL, $openid_url);
- }
- }
+ $rememberme = $this->boolean('rememberme');
+
+ common_ensure_session();
+
+ $_SESSION['openid_rememberme'] = $rememberme;
+
+ $result = oid_authenticate($openid_url,
+ 'finishopenidlogin');
+
+ if (is_string($result)) { # error message
+ unset($_SESSION['openid_rememberme']);
+ $this->show_form($result, $openid_url);
+ }
+ } else {
+ $openid_url = oid_get_last();
+ $this->show_form(NULL, $openid_url);
+ }
+ }
- function get_instructions() {
- return _('Login with an [OpenID](%%doc.openid%%) account.');
- }
+ function get_instructions() {
+ return _('Login with an [OpenID](%%doc.openid%%) account.');
+ }
- function show_top($error=NULL) {
- if ($error) {
- common_element('div', array('class' => 'error'), $error);
- } else {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
- }
+ function show_top($error=NULL) {
+ if ($error) {
+ common_element('div', array('class' => 'error'), $error);
+ } else {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+ }
- function show_form($error=NULL, $openid_url) {
- common_show_header(_('OpenID Login'), NULL, $error, array($this, 'show_top'));
- $formaction = common_local_url('openidlogin');
- common_element_start('form', array('method' => 'post',
- 'id' => 'openidlogin',
- 'action' => $formaction));
- common_hidden('token', common_session_token());
- common_input('openid_url', _('OpenID URL'),
- $openid_url,
- _('Your OpenID URL'));
- common_checkbox('rememberme', _('Remember me'), false,
- _('Automatically login in the future; ' .
- 'not for shared computers!'));
- common_submit('submit', _('Login'));
- common_element_end('form');
- common_show_footer();
- }
+ function show_form($error=NULL, $openid_url) {
+ common_show_header(_('OpenID Login'), NULL, $error, array($this, 'show_top'));
+ $formaction = common_local_url('openidlogin');
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'openidlogin',
+ 'action' => $formaction));
+ common_hidden('token', common_session_token());
+ common_input('openid_url', _('OpenID URL'),
+ $openid_url,
+ _('Your OpenID URL'));
+ common_checkbox('rememberme', _('Remember me'), false,
+ _('Automatically login in the future; ' .
+ 'not for shared computers!'));
+ common_submit('submit', _('Login'));
+ common_element_end('form');
+ common_show_footer();
+ }
}
diff --git a/_darcs/pristine/actions/openidsettings.php b/_darcs/pristine/actions/openidsettings.php
index f539d111f..dd575bb73 100644
--- a/_darcs/pristine/actions/openidsettings.php
+++ b/_darcs/pristine/actions/openidsettings.php
@@ -24,133 +24,133 @@ require_once(INSTALLDIR.'/lib/openid.php');
class OpenidsettingsAction extends SettingsAction {
- function get_instructions() {
- return _('[OpenID](%%doc.openid%%) lets you log into many sites ' .
- ' with the same user account. '.
- ' Manage your associated OpenIDs from here.');
- }
-
- function show_form($msg=NULL, $success=false) {
-
- $user = common_current_user();
-
- $this->form_header(_('OpenID settings'), $msg, $success);
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'openidadd',
- 'action' =>
- common_local_url('openidsettings')));
- common_hidden('token', common_session_token());
- common_element('h2', NULL, _('Add OpenID'));
- common_element('p', NULL,
- _('If you want to add an OpenID to your account, ' .
- 'enter it in the box below and click "Add".'));
- common_element_start('p');
- common_element('label', array('for' => 'openid_url'),
- _('OpenID URL'));
- common_element('input', array('name' => 'openid_url',
- 'type' => 'text',
- 'id' => 'openid_url'));
- common_element('input', array('type' => 'submit',
- 'id' => 'add',
- 'name' => 'add',
- 'class' => 'submit',
- 'value' => _('Add')));
- common_element_end('p');
- common_element_end('form');
-
- $oid = new User_openid();
- $oid->user_id = $user->id;
-
- $cnt = $oid->find();
-
- if ($cnt > 0) {
-
- common_element('h2', NULL, _('Remove OpenID'));
-
- if ($cnt == 1 && !$user->password) {
-
- common_element('p', NULL,
- _('Removing your only OpenID would make it impossible to log in! ' .
- 'If you need to remove it, add another OpenID first.'));
-
- if ($oid->fetch()) {
- common_element_start('p');
- common_element('a', array('href' => $oid->canonical),
- $oid->display);
- common_element_end('p');
- }
-
- } else {
-
- common_element('p', NULL,
- _('You can remove an OpenID from your account '.
- 'by clicking the button marked "Remove".'));
- $idx = 0;
-
- while ($oid->fetch()) {
- common_element_start('form', array('method' => 'POST',
- 'id' => 'openiddelete' . $idx,
- 'action' =>
- common_local_url('openidsettings')));
- common_element_start('p');
- common_hidden('token', common_session_token());
- common_element('a', array('href' => $oid->canonical),
- $oid->display);
- common_element('input', array('type' => 'hidden',
- 'id' => 'openid_url'.$idx,
- 'name' => 'openid_url',
- 'value' => $oid->canonical));
- common_element('input', array('type' => 'submit',
- 'id' => 'remove'.$idx,
- 'name' => 'remove',
- 'class' => 'submit',
- 'value' => _('Remove')));
- common_element_end('p');
- common_element_end('form');
- $idx++;
- }
- }
- }
-
- common_show_footer();
- }
-
- function handle_post() {
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- if ($this->arg('add')) {
- $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
- if (is_string($result)) { # error message
- $this->show_form($result);
- }
- } else if ($this->arg('remove')) {
- $this->remove_openid();
- } else {
- $this->show_form(_('Something weird happened.'));
- }
- }
-
- function remove_openid() {
-
- $openid_url = $this->trimmed('openid_url');
- $oid = User_openid::staticGet('canonical', $openid_url);
- if (!$oid) {
- $this->show_form(_('No such OpenID.'));
- return;
- }
- $cur = common_current_user();
- if (!$cur || $oid->user_id != $cur->id) {
- $this->show_form(_('That OpenID does not belong to you.'));
- return;
- }
- $oid->delete();
- $this->show_form(_('OpenID removed.'), true);
- return;
- }
+ function get_instructions() {
+ return _('[OpenID](%%doc.openid%%) lets you log into many sites ' .
+ ' with the same user account. '.
+ ' Manage your associated OpenIDs from here.');
+ }
+
+ function show_form($msg=NULL, $success=false) {
+
+ $user = common_current_user();
+
+ $this->form_header(_('OpenID settings'), $msg, $success);
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'openidadd',
+ 'action' =>
+ common_local_url('openidsettings')));
+ common_hidden('token', common_session_token());
+ common_element('h2', NULL, _('Add OpenID'));
+ common_element('p', NULL,
+ _('If you want to add an OpenID to your account, ' .
+ 'enter it in the box below and click "Add".'));
+ common_element_start('p');
+ common_element('label', array('for' => 'openid_url'),
+ _('OpenID URL'));
+ common_element('input', array('name' => 'openid_url',
+ 'type' => 'text',
+ 'id' => 'openid_url'));
+ common_element('input', array('type' => 'submit',
+ 'id' => 'add',
+ 'name' => 'add',
+ 'class' => 'submit',
+ 'value' => _('Add')));
+ common_element_end('p');
+ common_element_end('form');
+
+ $oid = new User_openid();
+ $oid->user_id = $user->id;
+
+ $cnt = $oid->find();
+
+ if ($cnt > 0) {
+
+ common_element('h2', NULL, _('Remove OpenID'));
+
+ if ($cnt == 1 && !$user->password) {
+
+ common_element('p', NULL,
+ _('Removing your only OpenID would make it impossible to log in! ' .
+ 'If you need to remove it, add another OpenID first.'));
+
+ if ($oid->fetch()) {
+ common_element_start('p');
+ common_element('a', array('href' => $oid->canonical),
+ $oid->display);
+ common_element_end('p');
+ }
+
+ } else {
+
+ common_element('p', NULL,
+ _('You can remove an OpenID from your account '.
+ 'by clicking the button marked "Remove".'));
+ $idx = 0;
+
+ while ($oid->fetch()) {
+ common_element_start('form', array('method' => 'POST',
+ 'id' => 'openiddelete' . $idx,
+ 'action' =>
+ common_local_url('openidsettings')));
+ common_element_start('p');
+ common_hidden('token', common_session_token());
+ common_element('a', array('href' => $oid->canonical),
+ $oid->display);
+ common_element('input', array('type' => 'hidden',
+ 'id' => 'openid_url'.$idx,
+ 'name' => 'openid_url',
+ 'value' => $oid->canonical));
+ common_element('input', array('type' => 'submit',
+ 'id' => 'remove'.$idx,
+ 'name' => 'remove',
+ 'class' => 'submit',
+ 'value' => _('Remove')));
+ common_element_end('p');
+ common_element_end('form');
+ $idx++;
+ }
+ }
+ }
+
+ common_show_footer();
+ }
+
+ function handle_post() {
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ if ($this->arg('add')) {
+ $result = oid_authenticate($this->trimmed('openid_url'), 'finishaddopenid');
+ if (is_string($result)) { # error message
+ $this->show_form($result);
+ }
+ } else if ($this->arg('remove')) {
+ $this->remove_openid();
+ } else {
+ $this->show_form(_('Something weird happened.'));
+ }
+ }
+
+ function remove_openid() {
+
+ $openid_url = $this->trimmed('openid_url');
+ $oid = User_openid::staticGet('canonical', $openid_url);
+ if (!$oid) {
+ $this->show_form(_('No such OpenID.'));
+ return;
+ }
+ $cur = common_current_user();
+ if (!$cur || $oid->user_id != $cur->id) {
+ $this->show_form(_('That OpenID does not belong to you.'));
+ return;
+ }
+ $oid->delete();
+ $this->show_form(_('OpenID removed.'), true);
+ return;
+ }
}
diff --git a/_darcs/pristine/actions/opensearch.php b/_darcs/pristine/actions/opensearch.php
index 0f366be4c..707e929fb 100644
--- a/_darcs/pristine/actions/opensearch.php
+++ b/_darcs/pristine/actions/opensearch.php
@@ -21,39 +21,39 @@ if (!defined('LACONICA')) { exit(1); }
class OpensearchAction extends Action {
- function handle($args) {
-
- parent::handle($args);
-
- $type = $this->trimmed('type');
-
- $short_name = '';
- if ($type == 'people') {
- $type = 'peoplesearch';
- $short_name = _('People Search');
- } else {
- $short_name = _('Notice Search');
- $type = 'noticesearch';
- }
-
- header('Content-Type: text/html');
-
- common_start_xml();
- common_element_start('OpenSearchDescription', array('xmlns' => 'http://a9.com/-/spec/opensearch/1.1/'));
-
- $short_name = common_config('site', 'name').' '.$short_name;
- common_element('ShortName', NULL, $short_name);
- common_element('Contact', NULL, common_config('site', 'email'));
- common_element('Url', array('type' => 'text/html', 'method' => 'get',
- 'template' => str_replace('---', '{searchTerms}', common_local_url($type, array('q' => '---')))));
- common_element('Image', array('height' => 16, 'width' => 16, 'type' => 'image/vnd.microsoft.icon'), common_path('favicon.ico'));
- common_element('Image', array('height' => 50, 'width' => 50, 'type' => 'image/png'), theme_path('logo.png'));
- common_element('AdultContent', NULL, 'false');
- common_element('Language', NULL, common_language());
- common_element('OutputEncoding', NULL, 'UTF-8');
- common_element('InputEncoding', NULL, 'UTF-8');
-
- common_element_end('OpenSearchDescription');
- common_end_xml();
- }
+ function handle($args) {
+
+ parent::handle($args);
+
+ $type = $this->trimmed('type');
+
+ $short_name = '';
+ if ($type == 'people') {
+ $type = 'peoplesearch';
+ $short_name = _('People Search');
+ } else {
+ $short_name = _('Notice Search');
+ $type = 'noticesearch';
+ }
+
+ header('Content-Type: text/html');
+
+ common_start_xml();
+ common_element_start('OpenSearchDescription', array('xmlns' => 'http://a9.com/-/spec/opensearch/1.1/'));
+
+ $short_name = common_config('site', 'name').' '.$short_name;
+ common_element('ShortName', NULL, $short_name);
+ common_element('Contact', NULL, common_config('site', 'email'));
+ common_element('Url', array('type' => 'text/html', 'method' => 'get',
+ 'template' => str_replace('---', '{searchTerms}', common_local_url($type, array('q' => '---')))));
+ common_element('Image', array('height' => 16, 'width' => 16, 'type' => 'image/vnd.microsoft.icon'), common_path('favicon.ico'));
+ common_element('Image', array('height' => 50, 'width' => 50, 'type' => 'image/png'), theme_path('logo.png'));
+ common_element('AdultContent', NULL, 'false');
+ common_element('Language', NULL, common_language());
+ common_element('OutputEncoding', NULL, 'UTF-8');
+ common_element('InputEncoding', NULL, 'UTF-8');
+
+ common_element_end('OpenSearchDescription');
+ common_end_xml();
+ }
}
diff --git a/_darcs/pristine/actions/othersettings.php b/_darcs/pristine/actions/othersettings.php
index eccf90e91..9b824cea2 100644
--- a/_darcs/pristine/actions/othersettings.php
+++ b/_darcs/pristine/actions/othersettings.php
@@ -23,159 +23,159 @@ require_once(INSTALLDIR.'/lib/settingsaction.php');
class OthersettingsAction extends SettingsAction {
- function get_instructions() {
- return _('Manage various other options.');
- }
+ function get_instructions() {
+ return _('Manage various other options.');
+ }
- function show_form($msg=NULL, $success=false) {
- $user = common_current_user();
+ function show_form($msg=NULL, $success=false) {
+ $user = common_current_user();
- $this->form_header(_('Other Settings'), $msg, $success);
+ $this->form_header(_('Other Settings'), $msg, $success);
- common_element('h2', NULL, _('URL Auto-shortening'));
- common_element_start('form', array('method' => 'post',
- 'id' => 'othersettings',
- 'action' =>
- common_local_url('othersettings')));
- common_hidden('token', common_session_token());
+ common_element('h2', NULL, _('URL Auto-shortening'));
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'othersettings',
+ 'action' =>
+ common_local_url('othersettings')));
+ common_hidden('token', common_session_token());
- $services = array(
- '' => 'None',
+ $services = array(
+ '' => 'None',
'ur1.ca' => 'ur1.ca (free service)',
'2tu.us' => '2tu.us (free service)',
'ptiturl.com' => 'ptiturl.com',
'bit.ly' => 'bit.ly',
- 'tinyurl.com' => 'tinyurl.com',
- 'is.gd' => 'is.gd',
- 'snipr.com' => 'snipr.com',
- 'metamark.net' => 'metamark.net'
- );
+ 'tinyurl.com' => 'tinyurl.com',
+ 'is.gd' => 'is.gd',
+ 'snipr.com' => 'snipr.com',
+ 'metamark.net' => 'metamark.net'
+ );
- common_dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), FALSE, $user->urlshorteningservice);
+ common_dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), FALSE, $user->urlshorteningservice);
- common_submit('save', _('Save'));
+ common_submit('save', _('Save'));
- common_element_end('form');
+ common_element_end('form');
-// common_element('h2', NULL, _('Delete my account'));
-// $this->show_delete_form();
+// common_element('h2', NULL, _('Delete my account'));
+// $this->show_delete_form();
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_feeds_list($feeds) {
- common_element_start('div', array('class' => 'feedsdel'));
- common_element('p', null, 'Feeds:');
- common_element_start('ul', array('class' => 'xoxo'));
+ function show_feeds_list($feeds) {
+ common_element_start('div', array('class' => 'feedsdel'));
+ common_element('p', null, 'Feeds:');
+ common_element_start('ul', array('class' => 'xoxo'));
- foreach ($feeds as $key => $value) {
- $this->common_feed_item($feeds[$key]);
- }
- common_element_end('ul');
- common_element_end('div');
- }
+ foreach ($feeds as $key => $value) {
+ $this->common_feed_item($feeds[$key]);
+ }
+ common_element_end('ul');
+ common_element_end('div');
+ }
//TODO move to common.php (and retrace its origin)
- function common_feed_item($feed) {
+ function common_feed_item($feed) {
$user = common_current_user();
- $nickname = $user->nickname;
-
- switch($feed['item']) {
- case 'notices': default:
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's ".$feed['version']." notice feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'foaf':
- $feed_classname = "foaf";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's FOAF file";
- $feed['textContent'] = "FOAF";
- break;
- }
- common_element_start('li');
- common_element('a', array('href' => $feed['href'],
- 'class' => $feed_classname,
- 'type' => $feed_mimetype,
- 'title' => $feed_title),
- $feed['textContent']);
- common_element_end('li');
- }
-
-// function show_delete_form() {
-// $user = common_current_user();
+ $nickname = $user->nickname;
+
+ switch($feed['item']) {
+ case 'notices': default:
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's ".$feed['version']." notice feed";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'foaf':
+ $feed_classname = "foaf";
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's FOAF file";
+ $feed['textContent'] = "FOAF";
+ break;
+ }
+ common_element_start('li');
+ common_element('a', array('href' => $feed['href'],
+ 'class' => $feed_classname,
+ 'type' => $feed_mimetype,
+ 'title' => $feed_title),
+ $feed['textContent']);
+ common_element_end('li');
+ }
+
+// function show_delete_form() {
+// $user = common_current_user();
// $notices = DB_DataObject::factory('notice');
// $notices->profile_id = $user->id;
// $notice_count = (int) $notices->count();
//
-// common_element_start('form', array('method' => 'POST',
-// 'id' => 'delete',
-// 'action' =>
-// common_local_url('deleteprofile')));
+// common_element_start('form', array('method' => 'POST',
+// 'id' => 'delete',
+// 'action' =>
+// common_local_url('deleteprofile')));
//
-// common_hidden('token', common_session_token());
+// common_hidden('token', common_session_token());
// common_element('p', null, "You can copy your notices and contacts by saving the two links below before deleting your account. Be careful, this operation cannot be undone.");
//
-// $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
-// 'type' => 'rss',
-// 'version' => 'RSS 1.0',
-// 'item' => 'notices'),
-// 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
-// 'type' => 'rdf',
-// 'version' => 'FOAF',
-// 'item' => 'foaf')));
+// $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('limit' => $notice_count, 'nickname' => $user->nickname)),
+// 'type' => 'rss',
+// 'version' => 'RSS 1.0',
+// 'item' => 'notices'),
+// 1=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
+// 'type' => 'rdf',
+// 'version' => 'FOAF',
+// 'item' => 'foaf')));
//
-// common_submit('deleteaccount', _('Delete my account'));
-// common_element_end('form');
-// }
+// common_submit('deleteaccount', _('Delete my account'));
+// common_element_end('form');
+// }
- function handle_post() {
+ function handle_post() {
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
- if ($this->arg('save')) {
- $this->save_preferences();
- }else {
- $this->show_form(_('Unexpected form submission.'));
- }
- }
+ if ($this->arg('save')) {
+ $this->save_preferences();
+ }else {
+ $this->show_form(_('Unexpected form submission.'));
+ }
+ }
- function save_preferences() {
+ function save_preferences() {
- $urlshorteningservice = $this->trimmed('urlshorteningservice');
+ $urlshorteningservice = $this->trimmed('urlshorteningservice');
- if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
- $this->show_form(_('URL shortening service is too long (max 50 chars).'));
- return;
- }
+ if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) {
+ $this->show_form(_('URL shortening service is too long (max 50 chars).'));
+ return;
+ }
- $user = common_current_user();
+ $user = common_current_user();
- assert(!is_null($user)); # should already be checked
+ assert(!is_null($user)); # should already be checked
- $user->query('BEGIN');
+ $user->query('BEGIN');
- $original = clone($user);
+ $original = clone($user);
- $user->urlshorteningservice = $urlshorteningservice;
+ $user->urlshorteningservice = $urlshorteningservice;
- $result = $user->update($original);
+ $result = $user->update($original);
- if ($result === FALSE) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
- $user->query('COMMIT');
+ $user->query('COMMIT');
- $this->show_form(_('Preferences saved.'), true);
- }
+ $this->show_form(_('Preferences saved.'), true);
+ }
}
diff --git a/_darcs/pristine/actions/peoplesearch.php b/_darcs/pristine/actions/peoplesearch.php
index 2e54233ec..f89de53f7 100644
--- a/_darcs/pristine/actions/peoplesearch.php
+++ b/_darcs/pristine/actions/peoplesearch.php
@@ -24,61 +24,61 @@ require_once(INSTALLDIR.'/lib/profilelist.php');
class PeoplesearchAction extends SearchAction {
- function get_instructions() {
- return _('Search for people on %%site.name%% by their name, location, or interests. ' .
- 'Separate the terms by spaces; they must be 3 characters or more.');
- }
+ function get_instructions() {
+ return _('Search for people on %%site.name%% by their name, location, or interests. ' .
+ 'Separate the terms by spaces; they must be 3 characters or more.');
+ }
- function get_title() {
- return _('People search');
- }
+ function get_title() {
+ return _('People search');
+ }
- function show_results($q, $page) {
+ function show_results($q, $page) {
- $profile = new Profile();
+ $profile = new Profile();
- # lcase it for comparison
- $q = strtolower($q);
+ # lcase it for comparison
+ $q = strtolower($q);
$search_engine = $profile->getSearchEngine('identica_people');
$search_engine->set_sort_mode('chron');
- # Ask for an extra to see if there's more.
+ # Ask for an extra to see if there's more.
$search_engine->limit((($page-1)*PROFILES_PER_PAGE), PROFILES_PER_PAGE + 1);
if (false === $search_engine->query($q)) {
$cnt = 0;
}
else {
- $cnt = $profile->find();
+ $cnt = $profile->find();
+ }
+ if ($cnt > 0) {
+ $terms = preg_split('/[\s,]+/', $q);
+ $results = new PeopleSearchResults($profile, $terms);
+ $results->show_list();
+ } else {
+ common_element('p', 'error', _('No results'));
}
- if ($cnt > 0) {
- $terms = preg_split('/[\s,]+/', $q);
- $results = new PeopleSearchResults($profile, $terms);
- $results->show_list();
- } else {
- common_element('p', 'error', _('No results'));
- }
- $profile->free();
-
- common_pagination($page > 1, $cnt > PROFILES_PER_PAGE,
- $page, 'peoplesearch', array('q' => $q));
- }
+ $profile->free();
+
+ common_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) {
- parent::__construct($profile);
- $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));
- }
+ var $terms = NULL;
+ var $pattern = NULL;
+
+ function __construct($profile, $terms) {
+ parent::__construct($profile);
+ $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));
+ }
}
diff --git a/_darcs/pristine/actions/peopletag.php b/_darcs/pristine/actions/peopletag.php
index c508e0594..f03a3c8af 100644
--- a/_darcs/pristine/actions/peopletag.php
+++ b/_darcs/pristine/actions/peopletag.php
@@ -22,82 +22,82 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/profilelist.php');
class PeopletagAction extends Action {
-
- function handle($args) {
+
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- $tag = $this->trimmed('tag');
-
- if (!common_valid_profile_tag($tag)) {
- $this->client_error(sprintf(_('Not a valid people tag: %s'), $tag));
- return;
- }
+ $tag = $this->trimmed('tag');
+
+ if (!common_valid_profile_tag($tag)) {
+ $this->client_error(sprintf(_('Not a valid people tag: %s'), $tag));
+ return;
+ }
- $page = $this->trimmed('page');
-
- if (!$page) {
- $page = 1;
- }
-
- # Looks like we're good; show the header
+ $page = $this->trimmed('page');
+
+ if (!$page) {
+ $page = 1;
+ }
+
+ # Looks like we're good; show the header
- common_show_header(sprintf(_('Users self-tagged with %s - page %d'), $tag, $page),
- NULL, $tag, array($this, 'show_top'));
+ common_show_header(sprintf(_('Users self-tagged with %s - page %d'), $tag, $page),
+ NULL, $tag, array($this, 'show_top'));
- $this->show_people($tag, $page);
+ $this->show_people($tag, $page);
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_people($tag, $page) {
-
- $profile = new Profile();
+ function show_people($tag, $page) {
+
+ $profile = new Profile();
- $offset = ($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;
- }
+ $offset = ($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
-
- $profile->query(sprintf('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 ' .
- $lim, $tag));
+ # XXX: memcached this
+
+ $profile->query(sprintf('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 ' .
+ $lim, $tag));
- $pl = new ProfileList($profile);
- $cnt = $pl->show_list();
-
- common_pagination($page > 1,
- $cnt > PROFILES_PER_PAGE,
- $page,
- $this->trimmed('action'),
- array('tag' => $tag));
- }
-
- function show_top($tag) {
- $instr = sprintf(_('These are users who have tagged themselves "%s" ' .
- 'to show a common interest, characteristic, hobby or job.'), $tag);
- common_element_start('div', 'instructions');
- common_element_start('p');
- common_text($instr);
- common_element_end('p');
- common_element_end('div');
- }
+ $pl = new ProfileList($profile);
+ $cnt = $pl->show_list();
+
+ common_pagination($page > 1,
+ $cnt > PROFILES_PER_PAGE,
+ $page,
+ $this->trimmed('action'),
+ array('tag' => $tag));
+ }
+
+ function show_top($tag) {
+ $instr = sprintf(_('These are users who have tagged themselves "%s" ' .
+ 'to show a common interest, characteristic, hobby or job.'), $tag);
+ common_element_start('div', 'instructions');
+ common_element_start('p');
+ common_text($instr);
+ common_element_end('p');
+ common_element_end('div');
+ }
- function get_title() {
- return NULL;
- }
+ function get_title() {
+ return NULL;
+ }
- function show_header($arr) {
- return;
- }
+ function show_header($arr) {
+ return;
+ }
}
diff --git a/_darcs/pristine/actions/postnotice.php b/_darcs/pristine/actions/postnotice.php
index 243081f12..66e4dc806 100644
--- a/_darcs/pristine/actions/postnotice.php
+++ b/_darcs/pristine/actions/postnotice.php
@@ -22,67 +22,67 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/omb.php');
class PostnoticeAction extends Action {
- function handle($args) {
- parent::handle($args);
- try {
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
- # Note: server-to-server function!
- $server = omb_oauth_server();
- list($consumer, $token) = $server->verify_request($req);
- if ($this->save_notice($req, $consumer, $token)) {
- print "omb_version=".OMB_VERSION_01;
- }
- } catch (OAuthException $e) {
- common_server_error($e->getMessage());
- return;
- }
- }
+ function handle($args) {
+ parent::handle($args);
+ try {
+ common_remove_magic_from_request();
+ $req = OAuthRequest::from_request();
+ # Note: server-to-server function!
+ $server = omb_oauth_server();
+ list($consumer, $token) = $server->verify_request($req);
+ if ($this->save_notice($req, $consumer, $token)) {
+ print "omb_version=".OMB_VERSION_01;
+ }
+ } catch (OAuthException $e) {
+ common_server_error($e->getMessage());
+ return;
+ }
+ }
- function save_notice(&$req, &$consumer, &$token) {
- $version = $req->get_parameter('omb_version');
- if ($version != OMB_VERSION_01) {
- common_user_error(_('Unsupported OMB version'), 400);
- return false;
- }
- # First, check to see
- $listenee = $req->get_parameter('omb_listenee');
- $remote_profile = Remote_profile::staticGet('uri', $listenee);
- if (!$remote_profile) {
- common_user_error(_('Profile unknown'), 403);
- return false;
- }
- $sub = Subscription::staticGet('token', $token->key);
- if (!$sub) {
- common_user_error(_('No such subscription'), 403);
- return false;
- }
- $content = $req->get_parameter('omb_notice_content');
+ function save_notice(&$req, &$consumer, &$token) {
+ $version = $req->get_parameter('omb_version');
+ if ($version != OMB_VERSION_01) {
+ common_user_error(_('Unsupported OMB version'), 400);
+ return false;
+ }
+ # First, check to see
+ $listenee = $req->get_parameter('omb_listenee');
+ $remote_profile = Remote_profile::staticGet('uri', $listenee);
+ if (!$remote_profile) {
+ common_user_error(_('Profile unknown'), 403);
+ return false;
+ }
+ $sub = Subscription::staticGet('token', $token->key);
+ if (!$sub) {
+ common_user_error(_('No such subscription'), 403);
+ return false;
+ }
+ $content = $req->get_parameter('omb_notice_content');
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
common_user_error(_('Invalid notice content'), 400);
return false;
}
- $notice_uri = $req->get_parameter('omb_notice');
- if (!Validate::uri($notice_uri) &&
- !common_valid_tag($notice_uri)) {
- common_user_error(_('Invalid notice uri'), 400);
- return false;
- }
- $notice_url = $req->get_parameter('omb_notice_url');
- if ($notice_url && !common_valid_http_url($notice_url)) {
- common_user_error(_('Invalid notice url'), 400);
- return false;
- }
- $notice = Notice::staticGet('uri', $notice_uri);
- if (!$notice) {
- $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, 0, $notice_uri);
- if (is_string($notice)) {
- common_server_serror($notice, 500);
- return false;
- }
- common_broadcast_notice($notice, true);
- }
- return true;
- }
+ $notice_uri = $req->get_parameter('omb_notice');
+ if (!Validate::uri($notice_uri) &&
+ !common_valid_tag($notice_uri)) {
+ common_user_error(_('Invalid notice uri'), 400);
+ return false;
+ }
+ $notice_url = $req->get_parameter('omb_notice_url');
+ if ($notice_url && !common_valid_http_url($notice_url)) {
+ common_user_error(_('Invalid notice url'), 400);
+ return false;
+ }
+ $notice = Notice::staticGet('uri', $notice_uri);
+ if (!$notice) {
+ $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, 0, $notice_uri);
+ if (is_string($notice)) {
+ common_server_serror($notice, 500);
+ return false;
+ }
+ common_broadcast_notice($notice, true);
+ }
+ return true;
+ }
}
diff --git a/_darcs/pristine/actions/profilesettings.php b/_darcs/pristine/actions/profilesettings.php
index ed2623c9b..3d92161ab 100644
--- a/_darcs/pristine/actions/profilesettings.php
+++ b/_darcs/pristine/actions/profilesettings.php
@@ -23,417 +23,417 @@ require_once(INSTALLDIR.'/lib/settingsaction.php');
class ProfilesettingsAction extends SettingsAction {
- function get_instructions() {
- return _('You can update your personal profile info here '.
- 'so people know more about you.');
- }
-
- function show_form($msg=NULL, $success=false) {
- $this->form_header(_('Profile settings'), $msg, $success);
- $this->show_settings_form();
- common_element('h2', NULL, _('Avatar'));
- $this->show_avatar_form();
- common_element('h2', NULL, _('Change password'));
- $this->show_password_form();
-// common_element('h2', NULL, _('Delete my account'));
-// $this->show_delete_form();
- common_show_footer();
- }
-
- function handle_post() {
-
- # CSRF protection
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- if ($this->arg('save')) {
- $this->save_profile();
- } else if ($this->arg('upload')) {
- $this->upload_avatar();
- } else if ($this->arg('changepass')) {
- $this->change_password();
- }
-
- }
-
- function show_settings_form() {
-
- $user = common_current_user();
- $profile = $user->getProfile();
-
- common_element_start('form', array('method' => 'POST',
- 'id' => 'profilesettings',
- 'action' =>
- common_local_url('profilesettings')));
- common_hidden('token', common_session_token());
-
- # too much common patterns here... abstractable?
-
- common_input('nickname', _('Nickname'),
- ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname,
- _('1-64 lowercase letters or numbers, no punctuation or spaces'));
- common_input('fullname', _('Full name'),
- ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname);
- common_input('homepage', _('Homepage'),
- ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage,
- _('URL of your homepage, blog, or profile on another site'));
- common_textarea('bio', _('Bio'),
- ($this->arg('bio')) ? $this->arg('bio') : $profile->bio,
- _('Describe yourself and your interests in 140 chars'));
- common_input('location', _('Location'),
- ($this->arg('location')) ? $this->arg('location') : $profile->location,
- _('Where you are, like "City, State (or Region), Country"'));
- common_input('tags', _('Tags'),
- ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()),
- _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated'));
-
- $language = common_language();
- common_dropdown('language', _('Language'), get_nice_language_list(), _('Preferred language'), TRUE, $language);
- $timezone = common_timezone();
- $timezones = array();
- foreach(DateTimeZone::listIdentifiers() as $k => $v) {
- $timezones[$v] = $v;
- }
- common_dropdown('timezone', _('Timezone'), $timezones, _('What timezone are you normally in?'), TRUE, $timezone);
-
- common_checkbox('autosubscribe', _('Automatically subscribe to whoever subscribes to me (best for non-humans)'),
- ($this->arg('autosubscribe')) ? $this->boolean('autosubscribe') : $user->autosubscribe);
-
- common_submit('save', _('Save'));
-
- common_element_end('form');
-
-
- }
-
- function show_avatar_form() {
-
- $user = common_current_user();
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_log_db_error($user, 'SELECT', __FILE__);
- $this->server_error(_('User without matching profile'));
- return;
- }
-
- $original = $profile->getOriginalAvatar();
-
-
- common_element_start('form', array('enctype' => 'multipart/form-data',
- 'method' => 'POST',
- 'id' => 'avatar',
- 'action' =>
- common_local_url('profilesettings')));
- common_hidden('token', common_session_token());
-
- if ($original) {
- common_element('img', array('src' => $original->url,
- 'class' => 'avatar original',
- 'width' => $original->width,
- 'height' => $original->height,
- 'alt' => $user->nickname));
- }
-
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
-
- if ($avatar) {
- common_element('img', array('src' => $avatar->url,
- 'class' => 'avatar profile',
- 'width' => AVATAR_PROFILE_SIZE,
- 'height' => AVATAR_PROFILE_SIZE,
- 'alt' => $user->nickname));
- }
-
-
- common_element('input', array('name' => 'MAX_FILE_SIZE',
- 'type' => 'hidden',
- 'id' => 'MAX_FILE_SIZE',
- 'value' => MAX_AVATAR_SIZE));
-
- common_element_start('p');
-
-
- common_element('input', array('name' => 'avatarfile',
- 'type' => 'file',
- 'id' => 'avatarfile'));
- common_element_end('p');
-
- common_submit('upload', _('Upload'));
- common_element_end('form');
-
- }
-
- function show_password_form() {
-
- $user = common_current_user();
- common_element_start('form', array('method' => 'POST',
- 'id' => 'password',
- 'action' =>
- common_local_url('profilesettings')));
-
- common_hidden('token', common_session_token());
-
- # Users who logged in with OpenID won't have a pwd
- if ($user->password) {
- common_password('oldpassword', _('Old password'));
- }
- common_password('newpassword', _('New password'),
- _('6 or more characters'));
- common_password('confirm', _('Confirm'),
- _('same as password above'));
- common_submit('changepass', _('Change'));
- common_element_end('form');
- }
-
- function save_profile() {
- $nickname = $this->trimmed('nickname');
- $fullname = $this->trimmed('fullname');
- $homepage = $this->trimmed('homepage');
- $bio = $this->trimmed('bio');
- $location = $this->trimmed('location');
- $autosubscribe = $this->boolean('autosubscribe');
- $language = $this->trimmed('language');
- $timezone = $this->trimmed('timezone');
- $tagstring = $this->trimmed('tags');
-
- # Some validation
-
- if (!Validate::string($nickname, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- $this->show_form(_('Nickname must have only lowercase letters and numbers and no spaces.'));
- return;
- } else if (!User::allowed_nickname($nickname)) {
- $this->show_form(_('Not a valid nickname.'));
- return;
- } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
- !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
- $this->show_form(_('Homepage is not a valid URL.'));
- return;
- } else if (!is_null($fullname) && strlen($fullname) > 255) {
- $this->show_form(_('Full name is too long (max 255 chars).'));
- return;
- } else if (!is_null($bio) && strlen($bio) > 140) {
- $this->show_form(_('Bio is too long (max 140 chars).'));
- return;
- } else if (!is_null($location) && strlen($location) > 255) {
- $this->show_form(_('Location is too long (max 255 chars).'));
- return;
- } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
- $this->show_form(_('Timezone not selected.'));
- return;
- } else if ($this->nickname_exists($nickname)) {
- $this->show_form(_('Nickname already in use. Try another one.'));
- return;
+ function get_instructions() {
+ return _('You can update your personal profile info here '.
+ 'so people know more about you.');
+ }
+
+ function show_form($msg=NULL, $success=false) {
+ $this->form_header(_('Profile settings'), $msg, $success);
+ $this->show_settings_form();
+ common_element('h2', NULL, _('Avatar'));
+ $this->show_avatar_form();
+ common_element('h2', NULL, _('Change password'));
+ $this->show_password_form();
+// common_element('h2', NULL, _('Delete my account'));
+// $this->show_delete_form();
+ common_show_footer();
+ }
+
+ function handle_post() {
+
+ # CSRF protection
+
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ if ($this->arg('save')) {
+ $this->save_profile();
+ } else if ($this->arg('upload')) {
+ $this->upload_avatar();
+ } else if ($this->arg('changepass')) {
+ $this->change_password();
+ }
+
+ }
+
+ function show_settings_form() {
+
+ $user = common_current_user();
+ $profile = $user->getProfile();
+
+ common_element_start('form', array('method' => 'POST',
+ 'id' => 'profilesettings',
+ 'action' =>
+ common_local_url('profilesettings')));
+ common_hidden('token', common_session_token());
+
+ # too much common patterns here... abstractable?
+
+ common_input('nickname', _('Nickname'),
+ ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname,
+ _('1-64 lowercase letters or numbers, no punctuation or spaces'));
+ common_input('fullname', _('Full name'),
+ ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname);
+ common_input('homepage', _('Homepage'),
+ ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage,
+ _('URL of your homepage, blog, or profile on another site'));
+ common_textarea('bio', _('Bio'),
+ ($this->arg('bio')) ? $this->arg('bio') : $profile->bio,
+ _('Describe yourself and your interests in 140 chars'));
+ common_input('location', _('Location'),
+ ($this->arg('location')) ? $this->arg('location') : $profile->location,
+ _('Where you are, like "City, State (or Region), Country"'));
+ common_input('tags', _('Tags'),
+ ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()),
+ _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated'));
+
+ $language = common_language();
+ common_dropdown('language', _('Language'), get_nice_language_list(), _('Preferred language'), TRUE, $language);
+ $timezone = common_timezone();
+ $timezones = array();
+ foreach(DateTimeZone::listIdentifiers() as $k => $v) {
+ $timezones[$v] = $v;
+ }
+ common_dropdown('timezone', _('Timezone'), $timezones, _('What timezone are you normally in?'), TRUE, $timezone);
+
+ common_checkbox('autosubscribe', _('Automatically subscribe to whoever subscribes to me (best for non-humans)'),
+ ($this->arg('autosubscribe')) ? $this->boolean('autosubscribe') : $user->autosubscribe);
+
+ common_submit('save', _('Save'));
+
+ common_element_end('form');
+
+
+ }
+
+ function show_avatar_form() {
+
+ $user = common_current_user();
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_log_db_error($user, 'SELECT', __FILE__);
+ $this->server_error(_('User without matching profile'));
+ return;
+ }
+
+ $original = $profile->getOriginalAvatar();
+
+
+ common_element_start('form', array('enctype' => 'multipart/form-data',
+ 'method' => 'POST',
+ 'id' => 'avatar',
+ 'action' =>
+ common_local_url('profilesettings')));
+ common_hidden('token', common_session_token());
+
+ if ($original) {
+ common_element('img', array('src' => $original->url,
+ 'class' => 'avatar original',
+ 'width' => $original->width,
+ 'height' => $original->height,
+ 'alt' => $user->nickname));
+ }
+
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+
+ if ($avatar) {
+ common_element('img', array('src' => $avatar->url,
+ 'class' => 'avatar profile',
+ 'width' => AVATAR_PROFILE_SIZE,
+ 'height' => AVATAR_PROFILE_SIZE,
+ 'alt' => $user->nickname));
+ }
+
+
+ common_element('input', array('name' => 'MAX_FILE_SIZE',
+ 'type' => 'hidden',
+ 'id' => 'MAX_FILE_SIZE',
+ 'value' => MAX_AVATAR_SIZE));
+
+ common_element_start('p');
+
+
+ common_element('input', array('name' => 'avatarfile',
+ 'type' => 'file',
+ 'id' => 'avatarfile'));
+ common_element_end('p');
+
+ common_submit('upload', _('Upload'));
+ common_element_end('form');
+
+ }
+
+ function show_password_form() {
+
+ $user = common_current_user();
+ common_element_start('form', array('method' => 'POST',
+ 'id' => 'password',
+ 'action' =>
+ common_local_url('profilesettings')));
+
+ common_hidden('token', common_session_token());
+
+ # Users who logged in with OpenID won't have a pwd
+ if ($user->password) {
+ common_password('oldpassword', _('Old password'));
+ }
+ common_password('newpassword', _('New password'),
+ _('6 or more characters'));
+ common_password('confirm', _('Confirm'),
+ _('same as password above'));
+ common_submit('changepass', _('Change'));
+ common_element_end('form');
+ }
+
+ function save_profile() {
+ $nickname = $this->trimmed('nickname');
+ $fullname = $this->trimmed('fullname');
+ $homepage = $this->trimmed('homepage');
+ $bio = $this->trimmed('bio');
+ $location = $this->trimmed('location');
+ $autosubscribe = $this->boolean('autosubscribe');
+ $language = $this->trimmed('language');
+ $timezone = $this->trimmed('timezone');
+ $tagstring = $this->trimmed('tags');
+
+ # Some validation
+
+ if (!Validate::string($nickname, array('min_length' => 1,
+ 'max_length' => 64,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+ $this->show_form(_('Nickname must have only lowercase letters and numbers and no spaces.'));
+ return;
+ } else if (!User::allowed_nickname($nickname)) {
+ $this->show_form(_('Not a valid nickname.'));
+ return;
+ } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
+ !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
+ $this->show_form(_('Homepage is not a valid URL.'));
+ return;
+ } else if (!is_null($fullname) && strlen($fullname) > 255) {
+ $this->show_form(_('Full name is too long (max 255 chars).'));
+ return;
+ } else if (!is_null($bio) && strlen($bio) > 140) {
+ $this->show_form(_('Bio is too long (max 140 chars).'));
+ return;
+ } else if (!is_null($location) && strlen($location) > 255) {
+ $this->show_form(_('Location is too long (max 255 chars).'));
+ return;
+ } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
+ $this->show_form(_('Timezone not selected.'));
+ return;
+ } else if ($this->nickname_exists($nickname)) {
+ $this->show_form(_('Nickname already in use. Try another one.'));
+ return;
} else if (!is_null($language) && strlen($language) > 50) {
- $this->show_form(_('Language is too long (max 50 chars).'));
- return;
- }
-
- if ($tagstring) {
- $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $tagstring));
- } else {
- $tags = array();
- }
-
- foreach ($tags as $tag) {
- if (!common_valid_profile_tag($tag)) {
- $this->show_form(sprintf(_('Invalid tag: "%s"'), $tag));
- return;
- }
- }
-
- $user = common_current_user();
-
- $user->query('BEGIN');
-
- if ($user->nickname != $nickname ||
- $user->language != $language ||
- $user->timezone != $timezone) {
-
- common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname,
- __FILE__);
- common_debug('Updating user language from ' . $user->language . ' to ' . $language,
- __FILE__);
- common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone,
- __FILE__);
-
- $original = clone($user);
-
- $user->nickname = $nickname;
- $user->language = $language;
- $user->timezone = $timezone;
-
- $result = $user->updateKeys($original);
-
- if ($result === FALSE) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- } else {
- # Re-initialize language environment if it changed
- common_init_language();
- }
- }
-
- # XXX: XOR
-
- if ($user->autosubscribe ^ $autosubscribe) {
-
- $original = clone($user);
-
- $user->autosubscribe = $autosubscribe;
-
- $result = $user->update($original);
-
- if ($result === FALSE) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user for autosubscribe.'));
- return;
- }
- }
-
- $profile = $user->getProfile();
-
- $orig_profile = clone($profile);
-
- $profile->nickname = $user->nickname;
- $profile->fullname = $fullname;
- $profile->homepage = $homepage;
- $profile->bio = $bio;
- $profile->location = $location;
- $profile->profileurl = common_profile_url($nickname);
-
- common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
- common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
-
- $result = $profile->update($orig_profile);
-
- if (!$result) {
- common_log_db_error($profile, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t save profile.'));
- return;
- }
-
- # Set the user tags
-
- $result = $user->setSelfTags($tags);
-
- if (!$result) {
- common_server_error(_('Couldn\'t save tags.'));
- return;
- }
-
- $user->query('COMMIT');
-
- common_broadcast_profile($profile);
-
- $this->show_form(_('Settings saved.'), TRUE);
- }
-
-
- function upload_avatar() {
- switch ($_FILES['avatarfile']['error']) {
- case UPLOAD_ERR_OK: # success, jump out
- break;
- case UPLOAD_ERR_INI_SIZE:
- case UPLOAD_ERR_FORM_SIZE:
- $this->show_form(_('That file is too big.'));
- return;
- case UPLOAD_ERR_PARTIAL:
- @unlink($_FILES['avatarfile']['tmp_name']);
- $this->show_form(_('Partial upload.'));
- return;
- default:
- $this->show_form(_('System error uploading file.'));
- return;
- }
-
- $info = @getimagesize($_FILES['avatarfile']['tmp_name']);
-
- if (!$info) {
- @unlink($_FILES['avatarfile']['tmp_name']);
- $this->show_form(_('Not an image or corrupt file.'));
- return;
- }
-
- switch ($info[2]) {
- case IMAGETYPE_GIF:
- case IMAGETYPE_JPEG:
- case IMAGETYPE_PNG:
- break;
- default:
- $this->show_form(_('Unsupported image file format.'));
- return;
- }
-
- $user = common_current_user();
- $profile = $user->getProfile();
-
- if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
- $this->show_form(_('Avatar updated.'), true);
- } else {
- $this->show_form(_('Failed updating avatar.'));
- }
-
- @unlink($_FILES['avatarfile']['tmp_name']);
- }
-
- function nickname_exists($nickname) {
- $user = common_current_user();
- $other = User::staticGet('nickname', $nickname);
- if (!$other) {
- return false;
- } else {
- return $other->id != $user->id;
- }
- }
-
- function change_password() {
-
- $user = common_current_user();
- assert(!is_null($user)); # should already be checked
-
- # FIXME: scrub input
-
- $newpassword = $this->arg('newpassword');
- $confirm = $this->arg('confirm');
- $token = $this->arg('token');
-
- if (0 != strcmp($newpassword, $confirm)) {
- $this->show_form(_('Passwords don\'t match.'));
- return;
- }
-
- if ($user->password) {
- $oldpassword = $this->arg('oldpassword');
-
- if (!common_check_user($user->nickname, $oldpassword)) {
- $this->show_form(_('Incorrect old password'));
- return;
- }
- }
-
- $original = clone($user);
-
- $user->password = common_munge_password($newpassword, $user->id);
-
- $val = $user->validate();
- if ($val !== TRUE) {
- $this->show_form(_('Error saving user; invalid.'));
- return;
- }
-
- if (!$user->update($original)) {
- common_server_error(_('Can\'t save new password.'));
- return;
- }
-
- $this->show_form(_('Password saved.'), true);
- }
+ $this->show_form(_('Language is too long (max 50 chars).'));
+ return;
+ }
+
+ if ($tagstring) {
+ $tags = array_map('common_canonical_tag', preg_split('/[\s,]+/', $tagstring));
+ } else {
+ $tags = array();
+ }
+
+ foreach ($tags as $tag) {
+ if (!common_valid_profile_tag($tag)) {
+ $this->show_form(sprintf(_('Invalid tag: "%s"'), $tag));
+ return;
+ }
+ }
+
+ $user = common_current_user();
+
+ $user->query('BEGIN');
+
+ if ($user->nickname != $nickname ||
+ $user->language != $language ||
+ $user->timezone != $timezone) {
+
+ common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname,
+ __FILE__);
+ common_debug('Updating user language from ' . $user->language . ' to ' . $language,
+ __FILE__);
+ common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone,
+ __FILE__);
+
+ $original = clone($user);
+
+ $user->nickname = $nickname;
+ $user->language = $language;
+ $user->timezone = $timezone;
+
+ $result = $user->updateKeys($original);
+
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ } else {
+ # Re-initialize language environment if it changed
+ common_init_language();
+ }
+ }
+
+ # XXX: XOR
+
+ if ($user->autosubscribe ^ $autosubscribe) {
+
+ $original = clone($user);
+
+ $user->autosubscribe = $autosubscribe;
+
+ $result = $user->update($original);
+
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user for autosubscribe.'));
+ return;
+ }
+ }
+
+ $profile = $user->getProfile();
+
+ $orig_profile = clone($profile);
+
+ $profile->nickname = $user->nickname;
+ $profile->fullname = $fullname;
+ $profile->homepage = $homepage;
+ $profile->bio = $bio;
+ $profile->location = $location;
+ $profile->profileurl = common_profile_url($nickname);
+
+ common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
+ common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
+
+ $result = $profile->update($orig_profile);
+
+ if (!$result) {
+ common_log_db_error($profile, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t save profile.'));
+ return;
+ }
+
+ # Set the user tags
+
+ $result = $user->setSelfTags($tags);
+
+ if (!$result) {
+ common_server_error(_('Couldn\'t save tags.'));
+ return;
+ }
+
+ $user->query('COMMIT');
+
+ common_broadcast_profile($profile);
+
+ $this->show_form(_('Settings saved.'), TRUE);
+ }
+
+
+ function upload_avatar() {
+ switch ($_FILES['avatarfile']['error']) {
+ case UPLOAD_ERR_OK: # success, jump out
+ break;
+ case UPLOAD_ERR_INI_SIZE:
+ case UPLOAD_ERR_FORM_SIZE:
+ $this->show_form(_('That file is too big.'));
+ return;
+ case UPLOAD_ERR_PARTIAL:
+ @unlink($_FILES['avatarfile']['tmp_name']);
+ $this->show_form(_('Partial upload.'));
+ return;
+ default:
+ $this->show_form(_('System error uploading file.'));
+ return;
+ }
+
+ $info = @getimagesize($_FILES['avatarfile']['tmp_name']);
+
+ if (!$info) {
+ @unlink($_FILES['avatarfile']['tmp_name']);
+ $this->show_form(_('Not an image or corrupt file.'));
+ return;
+ }
+
+ switch ($info[2]) {
+ case IMAGETYPE_GIF:
+ case IMAGETYPE_JPEG:
+ case IMAGETYPE_PNG:
+ break;
+ default:
+ $this->show_form(_('Unsupported image file format.'));
+ return;
+ }
+
+ $user = common_current_user();
+ $profile = $user->getProfile();
+
+ if ($profile->setOriginal($_FILES['avatarfile']['tmp_name'])) {
+ $this->show_form(_('Avatar updated.'), true);
+ } else {
+ $this->show_form(_('Failed updating avatar.'));
+ }
+
+ @unlink($_FILES['avatarfile']['tmp_name']);
+ }
+
+ function nickname_exists($nickname) {
+ $user = common_current_user();
+ $other = User::staticGet('nickname', $nickname);
+ if (!$other) {
+ return false;
+ } else {
+ return $other->id != $user->id;
+ }
+ }
+
+ function change_password() {
+
+ $user = common_current_user();
+ assert(!is_null($user)); # should already be checked
+
+ # FIXME: scrub input
+
+ $newpassword = $this->arg('newpassword');
+ $confirm = $this->arg('confirm');
+ $token = $this->arg('token');
+
+ if (0 != strcmp($newpassword, $confirm)) {
+ $this->show_form(_('Passwords don\'t match.'));
+ return;
+ }
+
+ if ($user->password) {
+ $oldpassword = $this->arg('oldpassword');
+
+ if (!common_check_user($user->nickname, $oldpassword)) {
+ $this->show_form(_('Incorrect old password'));
+ return;
+ }
+ }
+
+ $original = clone($user);
+
+ $user->password = common_munge_password($newpassword, $user->id);
+
+ $val = $user->validate();
+ if ($val !== TRUE) {
+ $this->show_form(_('Error saving user; invalid.'));
+ return;
+ }
+
+ if (!$user->update($original)) {
+ common_server_error(_('Can\'t save new password.'));
+ return;
+ }
+
+ $this->show_form(_('Password saved.'), true);
+ }
}
diff --git a/_darcs/pristine/actions/public.php b/_darcs/pristine/actions/public.php
index 218f80194..422e4bc98 100644
--- a/_darcs/pristine/actions/public.php
+++ b/_darcs/pristine/actions/public.php
@@ -23,77 +23,77 @@ require_once(INSTALLDIR.'/lib/stream.php');
class PublicAction extends StreamAction {
- function handle($args) {
- parent::handle($args);
-
- $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
- header('X-XRDS-Location: '. common_local_url('publicxrds'));
-
- common_show_header(_('Public timeline'),
- array($this, 'show_header'), NULL,
- array($this, 'show_top'));
-
- # XXX: Public sidebar here?
-
- $this->show_notices($page);
-
- common_show_footer();
- }
-
- function show_top() {
- if (common_logged_in()) {
- common_notice_form('public');
- } else {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
-
- $this->public_views_menu();
-
- $this->show_feeds_list(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 get_instructions() {
- return _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
- 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
- '[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ([Read more](%%doc.help%%))');
- }
-
- function show_header() {
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('publicrss'),
- 'type' => 'application/rss+xml',
- 'title' => _('Public Stream Feed')));
- # for client side of OpenID authentication
- common_element('meta', array('http-equiv' => 'X-XRDS-Location',
- 'content' => common_local_url('publicxrds')));
- }
-
- function show_notices($page) {
-
- $cnt = 0;
- $notice = Notice::publicStream(($page-1)*NOTICES_PER_PAGE,
- NOTICES_PER_PAGE + 1);
-
- if (!$notice) {
+ function handle($args) {
+ parent::handle($args);
+
+ $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+
+ header('X-XRDS-Location: '. common_local_url('publicxrds'));
+
+ common_show_header(_('Public timeline'),
+ array($this, 'show_header'), NULL,
+ array($this, 'show_top'));
+
+ # XXX: Public sidebar here?
+
+ $this->show_notices($page);
+
+ common_show_footer();
+ }
+
+ function show_top() {
+ if (common_logged_in()) {
+ common_notice_form('public');
+ } else {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+
+ $this->public_views_menu();
+
+ $this->show_feeds_list(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 get_instructions() {
+ return _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
+ 'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
+ '[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ([Read more](%%doc.help%%))');
+ }
+
+ function show_header() {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('publicrss'),
+ 'type' => 'application/rss+xml',
+ 'title' => _('Public Stream Feed')));
+ # for client side of OpenID authentication
+ common_element('meta', array('http-equiv' => 'X-XRDS-Location',
+ 'content' => common_local_url('publicxrds')));
+ }
+
+ function show_notices($page) {
+
+ $cnt = 0;
+ $notice = Notice::publicStream(($page-1)*NOTICES_PER_PAGE,
+ NOTICES_PER_PAGE + 1);
+
+ if (!$notice) {
$this->server_error(_('Could not retrieve public stream.'));
return;
- }
+ }
$cnt = $this->show_notice_list($notice);
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'public');
- }
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'public');
+ }
}
diff --git a/_darcs/pristine/actions/publicrss.php b/_darcs/pristine/actions/publicrss.php
index 1ab6a8be0..fa86de1d9 100644
--- a/_darcs/pristine/actions/publicrss.php
+++ b/_darcs/pristine/actions/publicrss.php
@@ -25,33 +25,33 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class PublicrssAction extends Rss10Action {
- function init() {
- return true;
- }
-
- function get_notices($limit=0) {
-
- $notices = array();
-
- $notice = Notice::publicStream(0, ($limit == 0) ? 48 : $limit);
-
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
-
- return $notices;
- }
-
- function get_channel() {
- global $config;
- $c = array('url' => common_local_url('publicrss'),
- 'title' => sprintf(_('%s Public Stream'), $config['site']['name']),
- 'link' => common_local_url('public'),
- 'description' => sprintf(_('All updates for %s'), $config['site']['name']));
- return $c;
- }
-
- function get_image() {
- return NULL;
- }
+ function init() {
+ return true;
+ }
+
+ function get_notices($limit=0) {
+
+ $notices = array();
+
+ $notice = Notice::publicStream(0, ($limit == 0) ? 48 : $limit);
+
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
+
+ return $notices;
+ }
+
+ function get_channel() {
+ global $config;
+ $c = array('url' => common_local_url('publicrss'),
+ 'title' => sprintf(_('%s Public Stream'), $config['site']['name']),
+ 'link' => common_local_url('public'),
+ 'description' => sprintf(_('All updates for %s'), $config['site']['name']));
+ return $c;
+ }
+
+ function get_image() {
+ return NULL;
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/publicxrds.php b/_darcs/pristine/actions/publicxrds.php
index 951434c87..ffd65c8c9 100644
--- a/_darcs/pristine/actions/publicxrds.php
+++ b/_darcs/pristine/actions/publicxrds.php
@@ -25,55 +25,55 @@ require_once(INSTALLDIR.'/lib/openid.php');
class PublicxrdsAction extends Action {
- function is_readonly() {
- return true;
- }
+ function is_readonly() {
+ return true;
+ }
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- header('Content-Type: application/xrds+xml');
+ header('Content-Type: application/xrds+xml');
- common_start_xml();
- common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
+ common_start_xml();
+ common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
- common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
- 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
- 'version' => '2.0'));
+ common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+ 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+ 'version' => '2.0'));
- common_element('Type', NULL, 'xri://$xrds*simple');
+ common_element('Type', NULL, 'xri://$xrds*simple');
- foreach (array('finishopenidlogin', 'finishaddopenid', 'finishimmediate') as $finish) {
- $this->show_service(Auth_OpenID_RP_RETURN_TO_URL_TYPE,
- common_local_url($finish));
- }
+ foreach (array('finishopenidlogin', 'finishaddopenid', 'finishimmediate') as $finish) {
+ $this->show_service(Auth_OpenID_RP_RETURN_TO_URL_TYPE,
+ common_local_url($finish));
+ }
- common_element_end('XRD');
+ common_element_end('XRD');
- common_element_end('XRDS');
- common_end_xml();
- }
+ common_element_end('XRDS');
+ common_end_xml();
+ }
- function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
- common_element_start('Service');
- if ($uri) {
- common_element('URI', NULL, $uri);
- }
- common_element('Type', NULL, $type);
- if ($params) {
- foreach ($params as $param) {
- common_element('Type', NULL, $param);
- }
- }
- if ($sigs) {
- foreach ($sigs as $sig) {
- common_element('Type', NULL, $sig);
- }
- }
- if ($localId) {
- common_element('LocalID', NULL, $localId);
- }
- common_element_end('Service');
- }
+ function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
+ common_element_start('Service');
+ if ($uri) {
+ common_element('URI', NULL, $uri);
+ }
+ common_element('Type', NULL, $type);
+ if ($params) {
+ foreach ($params as $param) {
+ common_element('Type', NULL, $param);
+ }
+ }
+ if ($sigs) {
+ foreach ($sigs as $sig) {
+ common_element('Type', NULL, $sig);
+ }
+ }
+ if ($localId) {
+ common_element('LocalID', NULL, $localId);
+ }
+ common_element_end('Service');
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/recoverpassword.php b/_darcs/pristine/actions/recoverpassword.php
index 38c42f41d..1263fee9b 100644
--- a/_darcs/pristine/actions/recoverpassword.php
+++ b/_darcs/pristine/actions/recoverpassword.php
@@ -28,304 +28,304 @@ class RecoverpasswordAction extends Action {
function handle($args) {
parent::handle($args);
if (common_logged_in()) {
- $this->client_error(_('You are already logged in!'));
+ $this->client_error(_('You are already logged in!'));
return;
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if ($this->arg('recover')) {
- $this->recover_password();
+ if ($this->arg('recover')) {
+ $this->recover_password();
} else if ($this->arg('reset')) {
- $this->reset_password();
- } else {
- $this->client_error(_('Unexpected form submission.'));
- }
- } else {
- if ($this->trimmed('code')) {
- $this->check_code();
- } else {
- $this->show_form();
- }
- }
- }
-
- function check_code() {
-
- $code = $this->trimmed('code');
- $confirm = Confirm_address::staticGet('code', $code);
-
- if (!$confirm) {
- $this->client_error(_('No such recovery code.'));
- return;
- }
- if ($confirm->address_type != 'recover') {
- $this->client_error(_('Not a recovery code.'));
- return;
- }
-
- $user = User::staticGet($confirm->user_id);
-
- if (!$user) {
- $this->server_error(_('Recovery code for unknown user.'));
- return;
- }
-
- $touched = strtotime($confirm->modified);
- $email = $confirm->address;
-
- # Burn this code
-
- $result = $confirm->delete();
-
- if (!$result) {
- common_log_db_error($confirm, 'DELETE', __FILE__);
- common_server_error(_('Error with confirmation code.'));
- return;
- }
-
- # These should be reaped, but for now we just check mod time
- # Note: it's still deleted; let's avoid a second attempt!
-
- if ((time() - $touched) > MAX_RECOVERY_TIME) {
- common_log(LOG_WARNING,
- 'Attempted redemption on recovery code ' .
- 'that is ' . $touched . ' seconds old. ');
- $this->client_error(_('This confirmation code is too old. ' .
- 'Please start again.'));
- return;
- }
-
- # If we used an outstanding confirmation to send the email,
- # it's been confirmed at this point.
-
- if (!$user->email) {
- $orig = clone($user);
- $user->email = $email;
- $result = $user->updateKeys($orig);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- $this->server_error(_('Could not update user with confirmed email address.'));
- return;
- }
- }
-
- # Success!
-
- $this->set_temp_user($user);
- $this->show_password_form();
- }
-
- function set_temp_user(&$user) {
- common_ensure_session();
- $_SESSION['tempuser'] = $user->id;
- }
-
- function get_temp_user() {
- common_ensure_session();
- $user_id = $_SESSION['tempuser'];
- if ($user_id) {
- $user = User::staticGet($user_id);
- }
- return $user;
- }
-
- function clear_temp_user() {
- common_ensure_session();
- unset($_SESSION['tempuser']);
- }
-
- function show_top($msg=NULL) {
- if ($msg) {
+ $this->reset_password();
+ } else {
+ $this->client_error(_('Unexpected form submission.'));
+ }
+ } else {
+ if ($this->trimmed('code')) {
+ $this->check_code();
+ } else {
+ $this->show_form();
+ }
+ }
+ }
+
+ function check_code() {
+
+ $code = $this->trimmed('code');
+ $confirm = Confirm_address::staticGet('code', $code);
+
+ if (!$confirm) {
+ $this->client_error(_('No such recovery code.'));
+ return;
+ }
+ if ($confirm->address_type != 'recover') {
+ $this->client_error(_('Not a recovery code.'));
+ return;
+ }
+
+ $user = User::staticGet($confirm->user_id);
+
+ if (!$user) {
+ $this->server_error(_('Recovery code for unknown user.'));
+ return;
+ }
+
+ $touched = strtotime($confirm->modified);
+ $email = $confirm->address;
+
+ # Burn this code
+
+ $result = $confirm->delete();
+
+ if (!$result) {
+ common_log_db_error($confirm, 'DELETE', __FILE__);
+ common_server_error(_('Error with confirmation code.'));
+ return;
+ }
+
+ # These should be reaped, but for now we just check mod time
+ # Note: it's still deleted; let's avoid a second attempt!
+
+ if ((time() - $touched) > MAX_RECOVERY_TIME) {
+ common_log(LOG_WARNING,
+ 'Attempted redemption on recovery code ' .
+ 'that is ' . $touched . ' seconds old. ');
+ $this->client_error(_('This confirmation code is too old. ' .
+ 'Please start again.'));
+ return;
+ }
+
+ # If we used an outstanding confirmation to send the email,
+ # it's been confirmed at this point.
+
+ if (!$user->email) {
+ $orig = clone($user);
+ $user->email = $email;
+ $result = $user->updateKeys($orig);
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ $this->server_error(_('Could not update user with confirmed email address.'));
+ return;
+ }
+ }
+
+ # Success!
+
+ $this->set_temp_user($user);
+ $this->show_password_form();
+ }
+
+ function set_temp_user(&$user) {
+ common_ensure_session();
+ $_SESSION['tempuser'] = $user->id;
+ }
+
+ function get_temp_user() {
+ common_ensure_session();
+ $user_id = $_SESSION['tempuser'];
+ if ($user_id) {
+ $user = User::staticGet($user_id);
+ }
+ return $user;
+ }
+
+ function clear_temp_user() {
+ common_ensure_session();
+ unset($_SESSION['tempuser']);
+ }
+
+ function show_top($msg=NULL) {
+ if ($msg) {
common_element('div', 'error', $msg);
- } else {
- common_element_start('div', 'instructions');
- common_element('p', NULL,
- _('If you\'ve forgotten or lost your' .
- ' password, you can get a new one sent to' .
- ' the email address you have stored ' .
- ' in your account.'));
- common_element_end('div');
- }
- }
-
- function show_password_top($msg=NULL) {
- if ($msg) {
+ } else {
+ common_element_start('div', 'instructions');
+ common_element('p', NULL,
+ _('If you\'ve forgotten or lost your' .
+ ' password, you can get a new one sent to' .
+ ' the email address you have stored ' .
+ ' in your account.'));
+ common_element_end('div');
+ }
+ }
+
+ function show_password_top($msg=NULL) {
+ if ($msg) {
common_element('div', 'error', $msg);
- } else {
- common_element('div', 'instructions',
- _('You\'ve been identified. Enter a ' .
- ' new password below. '));
- }
- }
-
- function show_form($msg=NULL) {
-
- common_show_header(_('Recover password'), NULL,
- $msg, array($this, 'show_top'));
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'recoverpassword',
- 'action' => common_local_url('recoverpassword')));
- common_input('nicknameoremail', _('Nickname or email'),
- $this->trimmed('nicknameoremail'),
- _('Your nickname on this server, ' .
- 'or your registered email address.'));
- common_submit('recover', _('Recover'));
- common_element_end('form');
- common_show_footer();
- }
-
- function show_password_form($msg=NULL) {
-
- common_show_header(_('Reset password'), NULL,
- $msg, array($this, 'show_password_top'));
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'recoverpassword',
- 'action' => common_local_url('recoverpassword')));
- common_hidden('token', common_session_token());
- common_password('newpassword', _('New password'),
- _('6 or more characters, and don\'t forget it!'));
- common_password('confirm', _('Confirm'),
- _('Same as password above'));
- common_submit('reset', _('Reset'));
- common_element_end('form');
- common_show_footer();
- }
-
- function recover_password() {
- $nore = $this->trimmed('nicknameoremail');
- if (!$nore) {
- $this->show_form(_('Enter a nickname or email address.'));
- return;
- }
-
- $user = User::staticGet('email', common_canonical_email($nore));
-
- if (!$user) {
- $user = User::staticGet('nickname', common_canonical_nickname($nore));
- }
-
- # See if it's an unconfirmed email address
-
- if (!$user) {
- $confirm_email = Confirm_address::staticGet('address', common_canonical_email($nore));
- if ($confirm_email && $confirm_email->address_type == 'email') {
- $user = User::staticGet($confirm_email->user_id);
- }
- }
-
- if (!$user) {
- $this->show_form(_('No user with that email address or username.'));
- return;
- }
-
- # Try to get an unconfirmed email address if they used a user name
-
- if (!$user->email && !$confirm_email) {
- $confirm_email = Confirm_address::staticGet('user_id', $user->id);
- if ($confirm_email && $confirm_email->address_type != 'email') {
- # Skip non-email confirmations
- $confirm_email = NULL;
- }
- }
-
- if (!$user->email && !$confirm_email) {
- $this->client_error(_('No registered email address for that user.'));
- return;
- }
-
- # Success! We have a valid user and a confirmed or unconfirmed email address
-
- $confirm = new Confirm_address();
- $confirm->code = common_confirmation_code(128);
- $confirm->address_type = 'recover';
- $confirm->user_id = $user->id;
- $confirm->address = (isset($user->email)) ? $user->email : $confirm_email->address;
-
- if (!$confirm->insert()) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
- $this->server_error(_('Error saving address confirmation.'));
- return;
- }
-
- $body = "Hey, $user->nickname.";
- $body .= "\n\n";
- $body .= 'Someone just asked for a new password ' .
- 'for this account on ' . common_config('site', 'name') . '.';
- $body .= "\n\n";
- $body .= 'If it was you, and you want to confirm, use the URL below:';
- $body .= "\n\n";
- $body .= "\t".common_local_url('recoverpassword',
- array('code' => $confirm->code));
- $body .= "\n\n";
- $body .= 'If not, just ignore this message.';
- $body .= "\n\n";
- $body .= 'Thanks for your time, ';
- $body .= "\n";
- $body .= common_config('site', 'name');
- $body .= "\n";
-
- mail_to_user($user, _('Password recovery requested'), $body, $confirm->address);
-
- common_show_header(_('Password recovery requested'));
- common_element('p', NULL,
- _('Instructions for recovering your password ' .
- 'have been sent to the email address registered to your ' .
- 'account.'));
- common_show_footer();
- }
-
- function reset_password() {
-
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $user = $this->get_temp_user();
-
- if (!$user) {
- $this->client_error(_('Unexpected password reset.'));
- return;
- }
-
- $newpassword = $this->trimmed('newpassword');
- $confirm = $this->trimmed('confirm');
-
- if (!$newpassword || strlen($newpassword) < 6) {
- $this->show_password_form(_('Password must be 6 chars or more.'));
- return;
- }
- if ($newpassword != $confirm) {
- $this->show_password_form(_('Password and confirmation do not match.'));
- return;
- }
-
- # OK, we're ready to go
-
- $original = clone($user);
-
- $user->password = common_munge_password($newpassword, $user->id);
-
- if (!$user->update($original)) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Can\'t save new password.'));
- return;
- }
-
- $this->clear_temp_user();
-
- if (!common_set_user($user->nickname)) {
- common_server_error(_('Error setting user.'));
- return;
- }
-
- common_real_login(true);
-
- common_show_header(_('Password saved.'));
- common_element('p', NULL, _('New password successfully saved. ' .
- 'You are now logged in.'));
- common_show_footer();
- }
+ } else {
+ common_element('div', 'instructions',
+ _('You\'ve been identified. Enter a ' .
+ ' new password below. '));
+ }
+ }
+
+ function show_form($msg=NULL) {
+
+ common_show_header(_('Recover password'), NULL,
+ $msg, array($this, 'show_top'));
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'recoverpassword',
+ 'action' => common_local_url('recoverpassword')));
+ common_input('nicknameoremail', _('Nickname or email'),
+ $this->trimmed('nicknameoremail'),
+ _('Your nickname on this server, ' .
+ 'or your registered email address.'));
+ common_submit('recover', _('Recover'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function show_password_form($msg=NULL) {
+
+ common_show_header(_('Reset password'), NULL,
+ $msg, array($this, 'show_password_top'));
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'recoverpassword',
+ 'action' => common_local_url('recoverpassword')));
+ common_hidden('token', common_session_token());
+ common_password('newpassword', _('New password'),
+ _('6 or more characters, and don\'t forget it!'));
+ common_password('confirm', _('Confirm'),
+ _('Same as password above'));
+ common_submit('reset', _('Reset'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function recover_password() {
+ $nore = $this->trimmed('nicknameoremail');
+ if (!$nore) {
+ $this->show_form(_('Enter a nickname or email address.'));
+ return;
+ }
+
+ $user = User::staticGet('email', common_canonical_email($nore));
+
+ if (!$user) {
+ $user = User::staticGet('nickname', common_canonical_nickname($nore));
+ }
+
+ # See if it's an unconfirmed email address
+
+ if (!$user) {
+ $confirm_email = Confirm_address::staticGet('address', common_canonical_email($nore));
+ if ($confirm_email && $confirm_email->address_type == 'email') {
+ $user = User::staticGet($confirm_email->user_id);
+ }
+ }
+
+ if (!$user) {
+ $this->show_form(_('No user with that email address or username.'));
+ return;
+ }
+
+ # Try to get an unconfirmed email address if they used a user name
+
+ if (!$user->email && !$confirm_email) {
+ $confirm_email = Confirm_address::staticGet('user_id', $user->id);
+ if ($confirm_email && $confirm_email->address_type != 'email') {
+ # Skip non-email confirmations
+ $confirm_email = NULL;
+ }
+ }
+
+ if (!$user->email && !$confirm_email) {
+ $this->client_error(_('No registered email address for that user.'));
+ return;
+ }
+
+ # Success! We have a valid user and a confirmed or unconfirmed email address
+
+ $confirm = new Confirm_address();
+ $confirm->code = common_confirmation_code(128);
+ $confirm->address_type = 'recover';
+ $confirm->user_id = $user->id;
+ $confirm->address = (isset($user->email)) ? $user->email : $confirm_email->address;
+
+ if (!$confirm->insert()) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ $this->server_error(_('Error saving address confirmation.'));
+ return;
+ }
+
+ $body = "Hey, $user->nickname.";
+ $body .= "\n\n";
+ $body .= 'Someone just asked for a new password ' .
+ 'for this account on ' . common_config('site', 'name') . '.';
+ $body .= "\n\n";
+ $body .= 'If it was you, and you want to confirm, use the URL below:';
+ $body .= "\n\n";
+ $body .= "\t".common_local_url('recoverpassword',
+ array('code' => $confirm->code));
+ $body .= "\n\n";
+ $body .= 'If not, just ignore this message.';
+ $body .= "\n\n";
+ $body .= 'Thanks for your time, ';
+ $body .= "\n";
+ $body .= common_config('site', 'name');
+ $body .= "\n";
+
+ mail_to_user($user, _('Password recovery requested'), $body, $confirm->address);
+
+ common_show_header(_('Password recovery requested'));
+ common_element('p', NULL,
+ _('Instructions for recovering your password ' .
+ 'have been sent to the email address registered to your ' .
+ 'account.'));
+ common_show_footer();
+ }
+
+ function reset_password() {
+
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $user = $this->get_temp_user();
+
+ if (!$user) {
+ $this->client_error(_('Unexpected password reset.'));
+ return;
+ }
+
+ $newpassword = $this->trimmed('newpassword');
+ $confirm = $this->trimmed('confirm');
+
+ if (!$newpassword || strlen($newpassword) < 6) {
+ $this->show_password_form(_('Password must be 6 chars or more.'));
+ return;
+ }
+ if ($newpassword != $confirm) {
+ $this->show_password_form(_('Password and confirmation do not match.'));
+ return;
+ }
+
+ # OK, we're ready to go
+
+ $original = clone($user);
+
+ $user->password = common_munge_password($newpassword, $user->id);
+
+ if (!$user->update($original)) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Can\'t save new password.'));
+ return;
+ }
+
+ $this->clear_temp_user();
+
+ if (!common_set_user($user->nickname)) {
+ common_server_error(_('Error setting user.'));
+ return;
+ }
+
+ common_real_login(true);
+
+ common_show_header(_('Password saved.'));
+ common_element('p', NULL, _('New password successfully saved. ' .
+ 'You are now logged in.'));
+ common_show_footer();
+ }
}
diff --git a/_darcs/pristine/actions/register.php b/_darcs/pristine/actions/register.php
index a22ffca28..011aa3f09 100644
--- a/_darcs/pristine/actions/register.php
+++ b/_darcs/pristine/actions/register.php
@@ -21,242 +21,242 @@ if (!defined('LACONICA')) { exit(1); }
class RegisterAction extends Action {
- function handle($args) {
- parent::handle($args);
-
- if (common_config('site', 'closed')) {
- common_user_error(_('Registration not allowed.'));
- } else if (common_logged_in()) {
- common_user_error(_('Already logged in.'));
- } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->try_register();
- } else {
- $this->show_form();
- }
- }
-
- function try_register() {
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $nickname = $this->trimmed('nickname');
- $email = $this->trimmed('email');
- $fullname = $this->trimmed('fullname');
- $homepage = $this->trimmed('homepage');
- $bio = $this->trimmed('bio');
- $location = $this->trimmed('location');
-
- # We don't trim these... whitespace is OK in a password!
-
- $password = $this->arg('password');
- $confirm = $this->arg('confirm');
-
- # invitation code, if any
-
- $code = $this->trimmed('code');
-
- if ($code) {
- $invite = Invitation::staticGet($code);
- }
-
- if (common_config('site', 'inviteonly') && !($code && $invite)) {
- $this->client_error(_('Sorry, only invited people can register.'));
- return;
- }
-
- # Input scrubbing
-
- $nickname = common_canonical_nickname($nickname);
- $email = common_canonical_email($email);
-
- if (!$this->boolean('license')) {
- $this->show_form(_('You can\'t register if you don\'t agree to the license.'));
- } else if ($email && !Validate::email($email, true)) {
- $this->show_form(_('Not a valid email address.'));
- } else if (!Validate::string($nickname, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- $this->show_form(_('Nickname must have only lowercase letters and numbers and no spaces.'));
- } else if ($this->nickname_exists($nickname)) {
- $this->show_form(_('Nickname already in use. Try another one.'));
- } else if (!User::allowed_nickname($nickname)) {
- $this->show_form(_('Not a valid nickname.'));
- } else if ($this->email_exists($email)) {
- $this->show_form(_('Email address already exists.'));
- } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
- !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
- $this->show_form(_('Homepage is not a valid URL.'));
- return;
- } else if (!is_null($fullname) && strlen($fullname) > 255) {
- $this->show_form(_('Full name is too long (max 255 chars).'));
- return;
- } else if (!is_null($bio) && strlen($bio) > 140) {
- $this->show_form(_('Bio is too long (max 140 chars).'));
- return;
- } else if (!is_null($location) && strlen($location) > 255) {
- $this->show_form(_('Location is too long (max 255 chars).'));
- return;
- } else if (strlen($password) < 6) {
- $this->show_form(_('Password must be 6 or more characters.'));
- return;
- } else if ($password != $confirm) {
- $this->show_form(_('Passwords don\'t match.'));
- } else if ($user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email,
- 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio,
- 'location' => $location, 'code' => $code))) {
- if (!$user) {
- $this->show_form(_('Invalid username or password.'));
- return;
- }
- # success!
- if (!common_set_user($user)) {
- common_server_error(_('Error setting user.'));
- return;
- }
- # this is a real login
- common_real_login(true);
- if ($this->boolean('rememberme')) {
- common_debug('Adding rememberme cookie for ' . $nickname);
- common_rememberme($user);
- }
- # Re-init language env in case it changed (not yet, but soon)
- common_init_language();
- $this->show_success();
- } else {
- $this->show_form(_('Invalid username or password.'));
- }
- }
-
- # checks if *CANONICAL* nickname exists
-
- function nickname_exists($nickname) {
- $user = User::staticGet('nickname', $nickname);
- return ($user !== false);
- }
-
- # checks if *CANONICAL* email exists
-
- function email_exists($email) {
- $email = common_canonical_email($email);
- if (!$email || strlen($email) == 0) {
- return false;
- }
- $user = User::staticGet('email', $email);
- return ($user !== false);
- }
-
- function show_top($error=NULL) {
- if ($error) {
- common_element('p', 'error', $error);
- } else {
- $instr = common_markup_to_html(_('With this form you can create a new account. ' .
- 'You can then post notices and link up to friends and colleagues. '.
- '(Have an [OpenID](http://openid.net/)? ' .
- 'Try our [OpenID registration](%%action.openidlogin%%)!)'));
-
- common_element_start('div', 'instructions');
- common_raw($instr);
- common_element_end('div');
- }
- }
-
- function show_form($error=NULL) {
- global $config;
-
- $code = $this->trimmed('code');
-
- if ($code) {
- $invite = Invitation::staticGet($code);
- }
-
- if (common_config('site', 'inviteonly') && !($code && $invite)) {
- $this->client_error(_('Sorry, only invited people can register.'));
- return;
- }
-
- common_show_header(_('Register'), NULL, $error, array($this, 'show_top'));
- common_element_start('form', array('method' => 'post',
- 'id' => 'login',
- 'action' => common_local_url('register')));
-
- common_hidden('token', common_session_token());
-
- if ($code) {
- common_hidden('code', $code);
- }
-
- common_input('nickname', _('Nickname'), $this->trimmed('nickname'),
- _('1-64 lowercase letters or numbers, no punctuation or spaces. Required.'));
- common_password('password', _('Password'),
- _('6 or more characters. Required.'));
- common_password('confirm', _('Confirm'),
- _('Same as password above. Required.'));
- if ($invite && $invite->address_type == 'email') {
- common_input('email', _('Email'), $invite->address,
- _('Used only for updates, announcements, and password recovery'));
- } else {
- common_input('email', _('Email'), $this->trimmed('email'),
- _('Used only for updates, announcements, and password recovery'));
- }
- common_input('fullname', _('Full name'),
- $this->trimmed('fullname'),
- _('Longer name, preferably your "real" name'));
- common_input('homepage', _('Homepage'),
- $this->trimmed('homepage'),
- _('URL of your homepage, blog, or profile on another site'));
- common_textarea('bio', _('Bio'),
- $this->trimmed('bio'),
- _('Describe yourself and your interests in 140 chars'));
- common_input('location', _('Location'),
- $this->trimmed('location'),
- _('Where you are, like "City, State (or Region), Country"'));
- common_checkbox('rememberme', _('Remember me'),
- $this->boolean('rememberme'),
- _('Automatically login in the future; not for shared computers!'));
- common_element_start('p');
- $attrs = array('type' => 'checkbox',
- 'id' => 'license',
- 'name' => 'license',
- 'value' => 'true');
- if ($this->boolean('license')) {
- $attrs['checked'] = 'checked';
- }
- common_element('input', $attrs);
- common_text(_('My text and files are available under '));
- common_element('a', array('href' => $config['license']['url']),
- $config['license']['title']);
- common_text(_(' except this private data: password, email address, IM address, phone number.'));
- common_element_end('p');
- common_submit('submit', _('Register'));
- common_element_end('form');
- common_show_footer();
- }
-
- function show_success() {
- $nickname = $this->arg('nickname');
- common_show_header(_('Registration successful'));
- common_element_start('div', 'success');
- $instr = sprintf(_('Congratulations, %s! And welcome to %%%%site.name%%%%. From here, you may want to...'. "\n\n" .
- '* Go to [your profile](%s) and post your first message.' . "\n" .
- '* Add a [Jabber/GTalk address](%%%%action.imsettings%%%%) so you can send notices through instant messages.' . "\n" .
- '* [Search for people](%%%%action.peoplesearch%%%%) that you may know or that share your interests. ' . "\n" .
- '* Update your [profile settings](%%%%action.profilesettings%%%%) to tell others more about you. ' . "\n" .
- '* Read over the [online docs](%%%%doc.help%%%%) for features you may have missed. ' . "\n\n" .
- 'Thanks for signing up and we hope you enjoy using this service.'),
- $nickname, common_local_url('showstream', array('nickname' => $nickname)));
- common_raw(common_markup_to_html($instr));
- $have_email = $this->trimmed('email');
- if ($have_email) {
- $emailinstr = _('(You should receive a message by email momentarily, with ' .
- 'instructions on how to confirm your email address.)');
- common_raw(common_markup_to_html($emailinstr));
- }
- common_element_end('div');
- common_show_footer();
- }
+ function handle($args) {
+ parent::handle($args);
+
+ if (common_config('site', 'closed')) {
+ common_user_error(_('Registration not allowed.'));
+ } else if (common_logged_in()) {
+ common_user_error(_('Already logged in.'));
+ } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->try_register();
+ } else {
+ $this->show_form();
+ }
+ }
+
+ function try_register() {
+
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $nickname = $this->trimmed('nickname');
+ $email = $this->trimmed('email');
+ $fullname = $this->trimmed('fullname');
+ $homepage = $this->trimmed('homepage');
+ $bio = $this->trimmed('bio');
+ $location = $this->trimmed('location');
+
+ # We don't trim these... whitespace is OK in a password!
+
+ $password = $this->arg('password');
+ $confirm = $this->arg('confirm');
+
+ # invitation code, if any
+
+ $code = $this->trimmed('code');
+
+ if ($code) {
+ $invite = Invitation::staticGet($code);
+ }
+
+ if (common_config('site', 'inviteonly') && !($code && $invite)) {
+ $this->client_error(_('Sorry, only invited people can register.'));
+ return;
+ }
+
+ # Input scrubbing
+
+ $nickname = common_canonical_nickname($nickname);
+ $email = common_canonical_email($email);
+
+ if (!$this->boolean('license')) {
+ $this->show_form(_('You can\'t register if you don\'t agree to the license.'));
+ } else if ($email && !Validate::email($email, true)) {
+ $this->show_form(_('Not a valid email address.'));
+ } else if (!Validate::string($nickname, array('min_length' => 1,
+ 'max_length' => 64,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+ $this->show_form(_('Nickname must have only lowercase letters and numbers and no spaces.'));
+ } else if ($this->nickname_exists($nickname)) {
+ $this->show_form(_('Nickname already in use. Try another one.'));
+ } else if (!User::allowed_nickname($nickname)) {
+ $this->show_form(_('Not a valid nickname.'));
+ } else if ($this->email_exists($email)) {
+ $this->show_form(_('Email address already exists.'));
+ } else if (!is_null($homepage) && (strlen($homepage) > 0) &&
+ !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
+ $this->show_form(_('Homepage is not a valid URL.'));
+ return;
+ } else if (!is_null($fullname) && strlen($fullname) > 255) {
+ $this->show_form(_('Full name is too long (max 255 chars).'));
+ return;
+ } else if (!is_null($bio) && strlen($bio) > 140) {
+ $this->show_form(_('Bio is too long (max 140 chars).'));
+ return;
+ } else if (!is_null($location) && strlen($location) > 255) {
+ $this->show_form(_('Location is too long (max 255 chars).'));
+ return;
+ } else if (strlen($password) < 6) {
+ $this->show_form(_('Password must be 6 or more characters.'));
+ return;
+ } else if ($password != $confirm) {
+ $this->show_form(_('Passwords don\'t match.'));
+ } else if ($user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email,
+ 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio,
+ 'location' => $location, 'code' => $code))) {
+ if (!$user) {
+ $this->show_form(_('Invalid username or password.'));
+ return;
+ }
+ # success!
+ if (!common_set_user($user)) {
+ common_server_error(_('Error setting user.'));
+ return;
+ }
+ # this is a real login
+ common_real_login(true);
+ if ($this->boolean('rememberme')) {
+ common_debug('Adding rememberme cookie for ' . $nickname);
+ common_rememberme($user);
+ }
+ # Re-init language env in case it changed (not yet, but soon)
+ common_init_language();
+ $this->show_success();
+ } else {
+ $this->show_form(_('Invalid username or password.'));
+ }
+ }
+
+ # checks if *CANONICAL* nickname exists
+
+ function nickname_exists($nickname) {
+ $user = User::staticGet('nickname', $nickname);
+ return ($user !== false);
+ }
+
+ # checks if *CANONICAL* email exists
+
+ function email_exists($email) {
+ $email = common_canonical_email($email);
+ if (!$email || strlen($email) == 0) {
+ return false;
+ }
+ $user = User::staticGet('email', $email);
+ return ($user !== false);
+ }
+
+ function show_top($error=NULL) {
+ if ($error) {
+ common_element('p', 'error', $error);
+ } else {
+ $instr = common_markup_to_html(_('With this form you can create a new account. ' .
+ 'You can then post notices and link up to friends and colleagues. '.
+ '(Have an [OpenID](http://openid.net/)? ' .
+ 'Try our [OpenID registration](%%action.openidlogin%%)!)'));
+
+ common_element_start('div', 'instructions');
+ common_raw($instr);
+ common_element_end('div');
+ }
+ }
+
+ function show_form($error=NULL) {
+ global $config;
+
+ $code = $this->trimmed('code');
+
+ if ($code) {
+ $invite = Invitation::staticGet($code);
+ }
+
+ if (common_config('site', 'inviteonly') && !($code && $invite)) {
+ $this->client_error(_('Sorry, only invited people can register.'));
+ return;
+ }
+
+ common_show_header(_('Register'), NULL, $error, array($this, 'show_top'));
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'login',
+ 'action' => common_local_url('register')));
+
+ common_hidden('token', common_session_token());
+
+ if ($code) {
+ common_hidden('code', $code);
+ }
+
+ common_input('nickname', _('Nickname'), $this->trimmed('nickname'),
+ _('1-64 lowercase letters or numbers, no punctuation or spaces. Required.'));
+ common_password('password', _('Password'),
+ _('6 or more characters. Required.'));
+ common_password('confirm', _('Confirm'),
+ _('Same as password above. Required.'));
+ if ($invite && $invite->address_type == 'email') {
+ common_input('email', _('Email'), $invite->address,
+ _('Used only for updates, announcements, and password recovery'));
+ } else {
+ common_input('email', _('Email'), $this->trimmed('email'),
+ _('Used only for updates, announcements, and password recovery'));
+ }
+ common_input('fullname', _('Full name'),
+ $this->trimmed('fullname'),
+ _('Longer name, preferably your "real" name'));
+ common_input('homepage', _('Homepage'),
+ $this->trimmed('homepage'),
+ _('URL of your homepage, blog, or profile on another site'));
+ common_textarea('bio', _('Bio'),
+ $this->trimmed('bio'),
+ _('Describe yourself and your interests in 140 chars'));
+ common_input('location', _('Location'),
+ $this->trimmed('location'),
+ _('Where you are, like "City, State (or Region), Country"'));
+ common_checkbox('rememberme', _('Remember me'),
+ $this->boolean('rememberme'),
+ _('Automatically login in the future; not for shared computers!'));
+ common_element_start('p');
+ $attrs = array('type' => 'checkbox',
+ 'id' => 'license',
+ 'name' => 'license',
+ 'value' => 'true');
+ if ($this->boolean('license')) {
+ $attrs['checked'] = 'checked';
+ }
+ common_element('input', $attrs);
+ common_text(_('My text and files are available under '));
+ common_element('a', array('href' => $config['license']['url']),
+ $config['license']['title']);
+ common_text(_(' except this private data: password, email address, IM address, phone number.'));
+ common_element_end('p');
+ common_submit('submit', _('Register'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function show_success() {
+ $nickname = $this->arg('nickname');
+ common_show_header(_('Registration successful'));
+ common_element_start('div', 'success');
+ $instr = sprintf(_('Congratulations, %s! And welcome to %%%%site.name%%%%. From here, you may want to...'. "\n\n" .
+ '* Go to [your profile](%s) and post your first message.' . "\n" .
+ '* Add a [Jabber/GTalk address](%%%%action.imsettings%%%%) so you can send notices through instant messages.' . "\n" .
+ '* [Search for people](%%%%action.peoplesearch%%%%) that you may know or that share your interests. ' . "\n" .
+ '* Update your [profile settings](%%%%action.profilesettings%%%%) to tell others more about you. ' . "\n" .
+ '* Read over the [online docs](%%%%doc.help%%%%) for features you may have missed. ' . "\n\n" .
+ 'Thanks for signing up and we hope you enjoy using this service.'),
+ $nickname, common_local_url('showstream', array('nickname' => $nickname)));
+ common_raw(common_markup_to_html($instr));
+ $have_email = $this->trimmed('email');
+ if ($have_email) {
+ $emailinstr = _('(You should receive a message by email momentarily, with ' .
+ 'instructions on how to confirm your email address.)');
+ common_raw(common_markup_to_html($emailinstr));
+ }
+ common_element_end('div');
+ common_show_footer();
+ }
}
diff --git a/_darcs/pristine/actions/remotesubscribe.php b/_darcs/pristine/actions/remotesubscribe.php
index c3a09bcfc..14e8cb068 100644
--- a/_darcs/pristine/actions/remotesubscribe.php
+++ b/_darcs/pristine/actions/remotesubscribe.php
@@ -23,364 +23,364 @@ require_once(INSTALLDIR.'/lib/omb.php');
class RemotesubscribeAction extends Action {
- function handle($args) {
-
- parent::handle($args);
-
- if (common_logged_in()) {
- common_user_error(_('You can use the local subscription!'));
- return;
- }
-
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $this->remote_subscription();
- } else {
- $this->show_form();
- }
- }
-
- function get_instructions() {
- return _('To subscribe, you can [login](%%action.login%%),' .
- ' or [register](%%action.register%%) a new ' .
- ' account. If you already have an account ' .
- ' on a [compatible microblogging site](%%doc.openmublog%%), ' .
- ' enter your profile URL below.');
- }
-
- function show_top($err=NULL) {
- if ($err) {
- common_element('div', 'error', $err);
- } else {
- $instructions = $this->get_instructions();
- $output = common_markup_to_html($instructions);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('p');
- }
- }
-
- function show_form($err=NULL) {
- $nickname = $this->trimmed('nickname');
- $profile = $this->trimmed('profile_url');
- common_show_header(_('Remote subscribe'), NULL, $err,
- array($this, 'show_top'));
- # id = remotesubscribe conflicts with the
- # button on profile page
- common_element_start('form', array('id' => 'remsub', 'method' => 'post',
- 'action' => common_local_url('remotesubscribe')));
- common_hidden('token', common_session_token());
- common_input('nickname', _('User nickname'), $nickname,
- _('Nickname of the user you want to follow'));
- common_input('profile_url', _('Profile URL'), $profile,
- _('URL of your profile on another compatible microblogging service'));
- common_submit('submit', _('Subscribe'));
- common_element_end('form');
- common_show_footer();
- }
-
- function remote_subscription() {
- $user = $this->get_user();
-
- if (!$user) {
- $this->show_form(_('No such user.'));
- return;
- }
-
- $profile = $this->trimmed('profile_url');
-
- if (!$profile) {
- $this->show_form(_('No such user.'));
- return;
- }
-
- if (!Validate::uri($profile, array('allowed_schemes' => array('http', 'https')))) {
- $this->show_form(_('Invalid profile URL (bad format)'));
- return;
- }
-
- $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
- $yadis = Auth_Yadis_Yadis::discover($profile, $fetcher);
-
- if (!$yadis || $yadis->failed) {
- $this->show_form(_('Not a valid profile URL (no YADIS document).'));
- return;
- }
-
- # XXX: a little liberal for sites that accidentally put whitespace before the xml declaration
+ function handle($args) {
+
+ parent::handle($args);
+
+ if (common_logged_in()) {
+ common_user_error(_('You can use the local subscription!'));
+ return;
+ }
+
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $this->remote_subscription();
+ } else {
+ $this->show_form();
+ }
+ }
+
+ function get_instructions() {
+ return _('To subscribe, you can [login](%%action.login%%),' .
+ ' or [register](%%action.register%%) a new ' .
+ ' account. If you already have an account ' .
+ ' on a [compatible microblogging site](%%doc.openmublog%%), ' .
+ ' enter your profile URL below.');
+ }
+
+ function show_top($err=NULL) {
+ if ($err) {
+ common_element('div', 'error', $err);
+ } else {
+ $instructions = $this->get_instructions();
+ $output = common_markup_to_html($instructions);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('p');
+ }
+ }
+
+ function show_form($err=NULL) {
+ $nickname = $this->trimmed('nickname');
+ $profile = $this->trimmed('profile_url');
+ common_show_header(_('Remote subscribe'), NULL, $err,
+ array($this, 'show_top'));
+ # id = remotesubscribe conflicts with the
+ # button on profile page
+ common_element_start('form', array('id' => 'remsub', 'method' => 'post',
+ 'action' => common_local_url('remotesubscribe')));
+ common_hidden('token', common_session_token());
+ common_input('nickname', _('User nickname'), $nickname,
+ _('Nickname of the user you want to follow'));
+ common_input('profile_url', _('Profile URL'), $profile,
+ _('URL of your profile on another compatible microblogging service'));
+ common_submit('submit', _('Subscribe'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function remote_subscription() {
+ $user = $this->get_user();
+
+ if (!$user) {
+ $this->show_form(_('No such user.'));
+ return;
+ }
+
+ $profile = $this->trimmed('profile_url');
+
+ if (!$profile) {
+ $this->show_form(_('No such user.'));
+ return;
+ }
+
+ if (!Validate::uri($profile, array('allowed_schemes' => array('http', 'https')))) {
+ $this->show_form(_('Invalid profile URL (bad format)'));
+ return;
+ }
+
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+ $yadis = Auth_Yadis_Yadis::discover($profile, $fetcher);
+
+ if (!$yadis || $yadis->failed) {
+ $this->show_form(_('Not a valid profile URL (no YADIS document).'));
+ return;
+ }
+
+ # XXX: a little liberal for sites that accidentally put whitespace before the xml declaration
$xrds =& Auth_Yadis_XRDS::parseXRDS(trim($yadis->response_text));
- if (!$xrds) {
- $this->show_form(_('Not a valid profile URL (no XRDS defined).'));
- return;
- }
+ if (!$xrds) {
+ $this->show_form(_('Not a valid profile URL (no XRDS defined).'));
+ return;
+ }
- $omb = $this->getOmb($xrds);
+ $omb = $this->getOmb($xrds);
- if (!$omb) {
- $this->show_form(_('Not a valid profile URL (incorrect services).'));
- return;
- }
+ if (!$omb) {
+ $this->show_form(_('Not a valid profile URL (incorrect services).'));
+ return;
+ }
- if (omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]) ==
- common_local_url('requesttoken'))
- {
- $this->show_form(_('That\'s a local profile! Login to subscribe.'));
- return;
- }
-
- if (User::staticGet('uri', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]))) {
- $this->show_form(_('That\'s a local profile! Login to subscribe.'));
- return;
- }
-
- list($token, $secret) = $this->request_token($omb);
-
- if (!$token || !$secret) {
- $this->show_form(_('Couldn\'t get a request token.'));
- return;
- }
-
- $this->request_authorization($user, $omb, $token, $secret);
- }
-
- function get_user() {
- $user = NULL;
- $nickname = $this->trimmed('nickname');
- if ($nickname) {
- $user = User::staticGet('nickname', $nickname);
- }
- return $user;
- }
-
- function getOmb($xrds) {
-
- static $omb_endpoints = array(OMB_ENDPOINT_UPDATEPROFILE, OMB_ENDPOINT_POSTNOTICE);
- static $oauth_endpoints = array(OAUTH_ENDPOINT_REQUEST, OAUTH_ENDPOINT_AUTHORIZE,
- OAUTH_ENDPOINT_ACCESS);
- $omb = array();
-
- # XXX: the following code could probably be refactored to eliminate dupes
-
- $oauth_services = omb_get_services($xrds, OAUTH_DISCOVERY);
-
- if (!$oauth_services) {
- return NULL;
- }
-
- $oauth_service = $oauth_services[0];
-
- $oauth_xrd = $this->getXRD($oauth_service, $xrds);
+ if (omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]) ==
+ common_local_url('requesttoken'))
+ {
+ $this->show_form(_('That\'s a local profile! Login to subscribe.'));
+ return;
+ }
+
+ if (User::staticGet('uri', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]))) {
+ $this->show_form(_('That\'s a local profile! Login to subscribe.'));
+ return;
+ }
+
+ list($token, $secret) = $this->request_token($omb);
+
+ if (!$token || !$secret) {
+ $this->show_form(_('Couldn\'t get a request token.'));
+ return;
+ }
+
+ $this->request_authorization($user, $omb, $token, $secret);
+ }
+
+ function get_user() {
+ $user = NULL;
+ $nickname = $this->trimmed('nickname');
+ if ($nickname) {
+ $user = User::staticGet('nickname', $nickname);
+ }
+ return $user;
+ }
+
+ function getOmb($xrds) {
+
+ static $omb_endpoints = array(OMB_ENDPOINT_UPDATEPROFILE, OMB_ENDPOINT_POSTNOTICE);
+ static $oauth_endpoints = array(OAUTH_ENDPOINT_REQUEST, OAUTH_ENDPOINT_AUTHORIZE,
+ OAUTH_ENDPOINT_ACCESS);
+ $omb = array();
+
+ # XXX: the following code could probably be refactored to eliminate dupes
+
+ $oauth_services = omb_get_services($xrds, OAUTH_DISCOVERY);
+
+ if (!$oauth_services) {
+ return NULL;
+ }
+
+ $oauth_service = $oauth_services[0];
+
+ $oauth_xrd = $this->getXRD($oauth_service, $xrds);
- if (!$oauth_xrd) {
- return NULL;
- }
+ if (!$oauth_xrd) {
+ return NULL;
+ }
- if (!$this->addServices($oauth_xrd, $oauth_endpoints, $omb)) {
- return NULL;
- }
+ if (!$this->addServices($oauth_xrd, $oauth_endpoints, $omb)) {
+ return NULL;
+ }
- $omb_services = omb_get_services($xrds, OMB_NAMESPACE);
+ $omb_services = omb_get_services($xrds, OMB_NAMESPACE);
- if (!$omb_services) {
- return NULL;
- }
+ if (!$omb_services) {
+ return NULL;
+ }
- $omb_service = $omb_services[0];
+ $omb_service = $omb_services[0];
- $omb_xrd = $this->getXRD($omb_service, $xrds);
+ $omb_xrd = $this->getXRD($omb_service, $xrds);
- if (!$omb_xrd) {
- return NULL;
- }
+ if (!$omb_xrd) {
+ return NULL;
+ }
- if (!$this->addServices($omb_xrd, $omb_endpoints, $omb)) {
- return NULL;
- }
+ if (!$this->addServices($omb_xrd, $omb_endpoints, $omb)) {
+ return NULL;
+ }
- # XXX: check that we got all the services we needed
+ # XXX: check that we got all the services we needed
- foreach (array_merge($omb_endpoints, $oauth_endpoints) as $type) {
- if (!array_key_exists($type, $omb) || !$omb[$type]) {
- return NULL;
- }
- }
+ foreach (array_merge($omb_endpoints, $oauth_endpoints) as $type) {
+ if (!array_key_exists($type, $omb) || !$omb[$type]) {
+ return NULL;
+ }
+ }
- if (!omb_local_id($omb[OAUTH_ENDPOINT_REQUEST])) {
- return NULL;
- }
+ if (!omb_local_id($omb[OAUTH_ENDPOINT_REQUEST])) {
+ return NULL;
+ }
- return $omb;
- }
+ return $omb;
+ }
- function getXRD($main_service, $main_xrds) {
- $uri = omb_service_uri($main_service);
- if (strpos($uri, "#") !== 0) {
- # FIXME: more rigorous handling of external service definitions
- return NULL;
- }
- $id = substr($uri, 1);
- $nodes = $main_xrds->allXrdNodes;
- $parser = $main_xrds->parser;
- foreach ($nodes as $node) {
- $attrs = $parser->attributes($node);
- if (array_key_exists('xml:id', $attrs) &&
- $attrs['xml:id'] == $id) {
- # XXX: trick the constructor into thinking this is the only node
- $bogus_nodes = array($node);
- return new Auth_Yadis_XRDS($parser, $bogus_nodes);
- }
- }
- return NULL;
- }
+ function getXRD($main_service, $main_xrds) {
+ $uri = omb_service_uri($main_service);
+ if (strpos($uri, "#") !== 0) {
+ # FIXME: more rigorous handling of external service definitions
+ return NULL;
+ }
+ $id = substr($uri, 1);
+ $nodes = $main_xrds->allXrdNodes;
+ $parser = $main_xrds->parser;
+ foreach ($nodes as $node) {
+ $attrs = $parser->attributes($node);
+ if (array_key_exists('xml:id', $attrs) &&
+ $attrs['xml:id'] == $id) {
+ # XXX: trick the constructor into thinking this is the only node
+ $bogus_nodes = array($node);
+ return new Auth_Yadis_XRDS($parser, $bogus_nodes);
+ }
+ }
+ return NULL;
+ }
- function addServices($xrd, $types, &$omb) {
- foreach ($types as $type) {
- $matches = omb_get_services($xrd, $type);
- if ($matches) {
- $omb[$type] = $matches[0];
- } else {
- # no match for type
- return false;
- }
- }
- return true;
- }
+ function addServices($xrd, $types, &$omb) {
+ foreach ($types as $type) {
+ $matches = omb_get_services($xrd, $type);
+ if ($matches) {
+ $omb[$type] = $matches[0];
+ } else {
+ # no match for type
+ return false;
+ }
+ }
+ return true;
+ }
- function request_token($omb) {
- $con = omb_oauth_consumer();
+ function request_token($omb) {
+ $con = omb_oauth_consumer();
- $url = omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]);
+ $url = omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]);
- # XXX: Is this the right thing to do? Strip off GET params and make them
- # POST params? Seems wrong to me.
+ # XXX: Is this the right thing to do? Strip off GET params and make them
+ # POST params? Seems wrong to me.
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
+ $parsed = parse_url($url);
+ $params = array();
+ parse_str($parsed['query'], $params);
- $req = OAuthRequest::from_consumer_and_token($con, NULL, "POST", $url, $params);
+ $req = OAuthRequest::from_consumer_and_token($con, NULL, "POST", $url, $params);
- $listener = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]);
+ $listener = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]);
- if (!$listener) {
- return NULL;
- }
+ if (!$listener) {
+ return NULL;
+ }
- $req->set_parameter('omb_listener', $listener);
- $req->set_parameter('omb_version', OMB_VERSION_01);
+ $req->set_parameter('omb_listener', $listener);
+ $req->set_parameter('omb_version', OMB_VERSION_01);
- # XXX: test to see if endpoint accepts this signature method
+ # XXX: test to see if endpoint accepts this signature method
- $req->sign_request(omb_hmac_sha1(), $con, NULL);
+ $req->sign_request(omb_hmac_sha1(), $con, NULL);
- # We re-use this tool's fetcher, since it's pretty good
+ # We re-use this tool's fetcher, since it's pretty good
- $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
- $result = $fetcher->post($req->get_normalized_http_url(),
- $req->to_postdata(),
+ $result = $fetcher->post($req->get_normalized_http_url(),
+ $req->to_postdata(),
array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
- if ($result->status != 200) {
- return NULL;
- }
+ if ($result->status != 200) {
+ return NULL;
+ }
- parse_str($result->body, $return);
+ parse_str($result->body, $return);
- return array($return['oauth_token'], $return['oauth_token_secret']);
- }
+ return array($return['oauth_token'], $return['oauth_token_secret']);
+ }
- function request_authorization($user, $omb, $token, $secret) {
- global $config; # for license URL
+ function request_authorization($user, $omb, $token, $secret) {
+ global $config; # for license URL
- $con = omb_oauth_consumer();
- $tok = new OAuthToken($token, $secret);
+ $con = omb_oauth_consumer();
+ $tok = new OAuthToken($token, $secret);
- $url = omb_service_uri($omb[OAUTH_ENDPOINT_AUTHORIZE]);
+ $url = omb_service_uri($omb[OAUTH_ENDPOINT_AUTHORIZE]);
- # XXX: Is this the right thing to do? Strip off GET params and make them
- # POST params? Seems wrong to me.
+ # XXX: Is this the right thing to do? Strip off GET params and make them
+ # POST params? Seems wrong to me.
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
+ $parsed = parse_url($url);
+ $params = array();
+ parse_str($parsed['query'], $params);
- $req = OAuthRequest::from_consumer_and_token($con, $tok, 'GET', $url, $params);
+ $req = OAuthRequest::from_consumer_and_token($con, $tok, 'GET', $url, $params);
- # We send over a ton of information. This lets the other
- # server store info about our user, and it lets the current
- # user decide if they really want to authorize the subscription.
+ # We send over a ton of information. This lets the other
+ # server store info about our user, and it lets the current
+ # user decide if they really want to authorize the subscription.
- $req->set_parameter('omb_version', OMB_VERSION_01);
- $req->set_parameter('omb_listener', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]));
- $req->set_parameter('omb_listenee', $user->uri);
- $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname));
- $req->set_parameter('omb_listenee_nickname', $user->nickname);
- $req->set_parameter('omb_listenee_license', $config['license']['url']);
+ $req->set_parameter('omb_version', OMB_VERSION_01);
+ $req->set_parameter('omb_listener', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]));
+ $req->set_parameter('omb_listenee', $user->uri);
+ $req->set_parameter('omb_listenee_profile', common_profile_url($user->nickname));
+ $req->set_parameter('omb_listenee_nickname', $user->nickname);
+ $req->set_parameter('omb_listenee_license', $config['license']['url']);
- $profile = $user->getProfile();
- if (!$profile) {
- common_log_db_error($user, 'SELECT', __FILE__);
- $this->server_error(_('User without matching profile'));
- return;
- }
+ $profile = $user->getProfile();
+ if (!$profile) {
+ common_log_db_error($user, 'SELECT', __FILE__);
+ $this->server_error(_('User without matching profile'));
+ return;
+ }
- if ($profile->fullname) {
- $req->set_parameter('omb_listenee_fullname', $profile->fullname);
- }
- if ($profile->homepage) {
- $req->set_parameter('omb_listenee_homepage', $profile->homepage);
- }
- if ($profile->bio) {
- $req->set_parameter('omb_listenee_bio', $profile->bio);
- }
- if ($profile->location) {
- $req->set_parameter('omb_listenee_location', $profile->location);
- }
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- if ($avatar) {
- $req->set_parameter('omb_listenee_avatar', $avatar->url);
- }
+ if ($profile->fullname) {
+ $req->set_parameter('omb_listenee_fullname', $profile->fullname);
+ }
+ if ($profile->homepage) {
+ $req->set_parameter('omb_listenee_homepage', $profile->homepage);
+ }
+ if ($profile->bio) {
+ $req->set_parameter('omb_listenee_bio', $profile->bio);
+ }
+ if ($profile->location) {
+ $req->set_parameter('omb_listenee_location', $profile->location);
+ }
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ if ($avatar) {
+ $req->set_parameter('omb_listenee_avatar', $avatar->url);
+ }
- # XXX: add a nonce to prevent replay attacks
+ # XXX: add a nonce to prevent replay attacks
- $req->set_parameter('oauth_callback', common_local_url('finishremotesubscribe'));
+ $req->set_parameter('oauth_callback', common_local_url('finishremotesubscribe'));
- # XXX: test to see if endpoint accepts this signature method
+ # XXX: test to see if endpoint accepts this signature method
- $req->sign_request(omb_hmac_sha1(), $con, $tok);
+ $req->sign_request(omb_hmac_sha1(), $con, $tok);
- # store all our info here
+ # store all our info here
- $omb['listenee'] = $user->nickname;
- $omb['listener'] = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]);
- $omb['token'] = $token;
- $omb['secret'] = $secret;
- # call doesn't work after bounce back so we cache; maybe serialization issue...?
- $omb['access_token_url'] = omb_service_uri($omb[OAUTH_ENDPOINT_ACCESS]);
- $omb['post_notice_url'] = omb_service_uri($omb[OMB_ENDPOINT_POSTNOTICE]);
- $omb['update_profile_url'] = omb_service_uri($omb[OMB_ENDPOINT_UPDATEPROFILE]);
+ $omb['listenee'] = $user->nickname;
+ $omb['listener'] = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]);
+ $omb['token'] = $token;
+ $omb['secret'] = $secret;
+ # call doesn't work after bounce back so we cache; maybe serialization issue...?
+ $omb['access_token_url'] = omb_service_uri($omb[OAUTH_ENDPOINT_ACCESS]);
+ $omb['post_notice_url'] = omb_service_uri($omb[OMB_ENDPOINT_POSTNOTICE]);
+ $omb['update_profile_url'] = omb_service_uri($omb[OMB_ENDPOINT_UPDATEPROFILE]);
- common_ensure_session();
+ common_ensure_session();
- $_SESSION['oauth_authorization_request'] = $omb;
+ $_SESSION['oauth_authorization_request'] = $omb;
- # Redirect to authorization service
+ # Redirect to authorization service
- common_redirect($req->to_url());
- return;
- }
+ common_redirect($req->to_url());
+ return;
+ }
- function make_nonce() {
- return common_good_rand(16);
- }
+ function make_nonce() {
+ return common_good_rand(16);
+ }
}
diff --git a/_darcs/pristine/actions/replies.php b/_darcs/pristine/actions/replies.php
index 835871ffc..be80fae79 100644
--- a/_darcs/pristine/actions/replies.php
+++ b/_darcs/pristine/actions/replies.php
@@ -23,72 +23,72 @@ require_once(INSTALLDIR.'/actions/showstream.php');
class RepliesAction extends StreamAction {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- $nickname = common_canonical_nickname($this->arg('nickname'));
- $user = User::staticGet('nickname', $nickname);
+ $nickname = common_canonical_nickname($this->arg('nickname'));
+ $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- $this->no_such_user();
- return;
- }
+ if (!$user) {
+ $this->no_such_user();
+ return;
+ }
- $profile = $user->getProfile();
+ $profile = $user->getProfile();
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
- # Looks like we're good; show the header
+ # Looks like we're good; show the header
- common_show_header(sprintf(_("Replies to %s"), $profile->nickname),
- array($this, 'show_header'), $user,
- array($this, 'show_top'));
+ common_show_header(sprintf(_("Replies to %s"), $profile->nickname),
+ array($this, 'show_header'), $user,
+ array($this, 'show_top'));
- $this->show_replies($user);
+ $this->show_replies($user);
- common_show_footer();
- }
+ common_show_footer();
+ }
- function no_such_user() {
- common_user_error(_('No such user.'));
- }
+ function no_such_user() {
+ common_user_error(_('No such user.'));
+ }
- function show_header($user) {
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('repliesrss', array('nickname' =>
- $user->nickname)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for replies to %s'), $user->nickname)));
- }
+ function show_header($user) {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('repliesrss', array('nickname' =>
+ $user->nickname)),
+ 'type' => 'application/rss+xml',
+ 'title' => sprintf(_('Feed for replies to %s'), $user->nickname)));
+ }
- function show_top($user) {
- $cur = common_current_user();
+ function show_top($user) {
+ $cur = common_current_user();
- if ($cur && $cur->id == $user->id) {
- common_notice_form('replies');
- }
+ if ($cur && $cur->id == $user->id) {
+ common_notice_form('replies');
+ }
- $this->views_menu();
+ $this->views_menu();
- $this->show_feeds_list(array(0=>array('href'=>common_local_url('repliesrss', array('nickname' => $user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'repliesrss')));
- }
+ $this->show_feeds_list(array(0=>array('href'=>common_local_url('repliesrss', array('nickname' => $user->nickname)),
+ 'type' => 'rss',
+ 'version' => 'RSS 1.0',
+ 'item' => 'repliesrss')));
+ }
- function show_replies($user) {
+ function show_replies($user) {
- $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+ $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
- $notice = $user->getReplies(($page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ $notice = $user->getReplies(($page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
- $cnt = $this->show_notice_list($notice);
+ $cnt = $this->show_notice_list($notice);
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'replies', array('nickname' => $user->nickname));
- }
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'replies', array('nickname' => $user->nickname));
+ }
}
diff --git a/_darcs/pristine/actions/repliesrss.php b/_darcs/pristine/actions/repliesrss.php
index 7369db5e0..3689ea1f8 100644
--- a/_darcs/pristine/actions/repliesrss.php
+++ b/_darcs/pristine/actions/repliesrss.php
@@ -25,55 +25,55 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class RepliesrssAction extends Rss10Action {
- var $user = NULL;
+ var $user = NULL;
- function init() {
- $nickname = $this->trimmed('nickname');
- $this->user = User::staticGet('nickname', $nickname);
+ function init() {
+ $nickname = $this->trimmed('nickname');
+ $this->user = User::staticGet('nickname', $nickname);
- if (!$this->user) {
- common_user_error(_('No such user.'));
- return false;
- } else {
- return true;
- }
- }
+ if (!$this->user) {
+ common_user_error(_('No such user.'));
+ return false;
+ } else {
+ return true;
+ }
+ }
- function get_notices($limit=0) {
+ function get_notices($limit=0) {
- $user = $this->user;
+ $user = $this->user;
- $notice = $user->getReplies(0, ($limit == 0) ? 48 : $limit);
+ $notice = $user->getReplies(0, ($limit == 0) ? 48 : $limit);
- $notices = array();
-
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
+ $notices = array();
+
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
- return $notices;
- }
+ return $notices;
+ }
- function get_channel() {
- $user = $this->user;
- $c = array('url' => common_local_url('repliesrss',
- array('nickname' =>
- $user->nickname)),
- 'title' => sprintf(_("Replies to %s"), $user->nickname),
- 'link' => common_local_url('replies',
- array('nickname' =>
- $user->nickname)),
- 'description' => sprintf(_('Feed for replies to %s'), $user->nickname));
- return $c;
- }
+ function get_channel() {
+ $user = $this->user;
+ $c = array('url' => common_local_url('repliesrss',
+ array('nickname' =>
+ $user->nickname)),
+ 'title' => sprintf(_("Replies to %s"), $user->nickname),
+ 'link' => common_local_url('replies',
+ array('nickname' =>
+ $user->nickname)),
+ 'description' => sprintf(_('Feed for replies to %s'), $user->nickname));
+ return $c;
+ }
- function get_image() {
- $user = $this->user;
- $profile = $user->getProfile();
- if (!$profile) {
- return NULL;
- }
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- return ($avatar) ? $avatar->url : NULL;
- }
+ function get_image() {
+ $user = $this->user;
+ $profile = $user->getProfile();
+ if (!$profile) {
+ return NULL;
+ }
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ return ($avatar) ? $avatar->url : NULL;
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/requesttoken.php b/_darcs/pristine/actions/requesttoken.php
index 76019a929..4950d93c0 100644
--- a/_darcs/pristine/actions/requesttoken.php
+++ b/_darcs/pristine/actions/requesttoken.php
@@ -22,21 +22,21 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/omb.php');
class RequesttokenAction extends Action {
-
- function is_readonly() {
- return false;
- }
-
- function handle($args) {
- parent::handle($args);
- try {
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
- $server = omb_oauth_server();
- $token = $server->fetch_request_token($req);
- print $token;
- } catch (OAuthException $e) {
- common_server_error($e->getMessage());
- }
- }
+
+ function is_readonly() {
+ return false;
+ }
+
+ function handle($args) {
+ parent::handle($args);
+ try {
+ common_remove_magic_from_request();
+ $req = OAuthRequest::from_request();
+ $server = omb_oauth_server();
+ $token = $server->fetch_request_token($req);
+ print $token;
+ } catch (OAuthException $e) {
+ common_server_error($e->getMessage());
+ }
+ }
}
diff --git a/_darcs/pristine/actions/showfavorites.php b/_darcs/pristine/actions/showfavorites.php
index 4de4b1271..2fd1e586d 100644
--- a/_darcs/pristine/actions/showfavorites.php
+++ b/_darcs/pristine/actions/showfavorites.php
@@ -23,75 +23,75 @@ require_once(INSTALLDIR.'/actions/showstream.php');
class ShowfavoritesAction extends StreamAction {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- $nickname = common_canonical_nickname($this->arg('nickname'));
- $user = User::staticGet('nickname', $nickname);
+ $nickname = common_canonical_nickname($this->arg('nickname'));
+ $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- $this->client_error(_('No such user.'));
- return;
- }
+ if (!$user) {
+ $this->client_error(_('No such user.'));
+ return;
+ }
- $profile = $user->getProfile();
+ $profile = $user->getProfile();
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
- # Looks like we're good; show the header
+ # Looks like we're good; show the header
- common_show_header(sprintf(_("%s favorite notices"), $profile->nickname),
- array($this, 'show_header'), $user,
- array($this, 'show_top'));
+ common_show_header(sprintf(_("%s favorite notices"), $profile->nickname),
+ array($this, 'show_header'), $user,
+ array($this, 'show_top'));
- $this->show_notices($user);
+ $this->show_notices($user);
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_header($user) {
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('favoritesrss', array('nickname' =>
- $user->nickname)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for favorites of %s'), $user->nickname)));
- }
+ function show_header($user) {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('favoritesrss', array('nickname' =>
+ $user->nickname)),
+ 'type' => 'application/rss+xml',
+ 'title' => sprintf(_('Feed for favorites of %s'), $user->nickname)));
+ }
- function show_top($user) {
- $cur = common_current_user();
+ function show_top($user) {
+ $cur = common_current_user();
- if ($cur && $cur->id == $user->id) {
- common_notice_form('all');
- }
+ if ($cur && $cur->id == $user->id) {
+ common_notice_form('all');
+ }
- $this->show_feeds_list(array(0=>array('href'=>common_local_url('favoritesrss', array('nickname' => $user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'Favorites')));
- $this->views_menu();
- }
+ $this->show_feeds_list(array(0=>array('href'=>common_local_url('favoritesrss', array('nickname' => $user->nickname)),
+ 'type' => 'rss',
+ 'version' => 'RSS 1.0',
+ 'item' => 'Favorites')));
+ $this->views_menu();
+ }
- function show_notices($user) {
+ function show_notices($user) {
- $page = $this->trimmed('page');
- if (!$page) {
- $page = 1;
- }
+ $page = $this->trimmed('page');
+ if (!$page) {
+ $page = 1;
+ }
- $notice = $user->favoriteNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ $notice = $user->favoriteNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
- if (!$notice) {
- $this->server_error(_('Could not retrieve favorite notices.'));
- return;
- }
+ if (!$notice) {
+ $this->server_error(_('Could not retrieve favorite notices.'));
+ return;
+ }
$cnt = $this->show_notice_list($notice);
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'showfavorites', array('nickname' => $user->nickname));
- }
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'showfavorites', array('nickname' => $user->nickname));
+ }
}
diff --git a/_darcs/pristine/actions/showmessage.php b/_darcs/pristine/actions/showmessage.php
index c171ffe0b..f35f3eede 100644
--- a/_darcs/pristine/actions/showmessage.php
+++ b/_darcs/pristine/actions/showmessage.php
@@ -23,78 +23,78 @@ require_once(INSTALLDIR.'/lib/mailbox.php');
class ShowmessageAction extends MailboxAction {
- function handle($args) {
+ function handle($args) {
- Action::handle($args);
+ Action::handle($args);
- $message = $this->get_message();
+ $message = $this->get_message();
- if (!$message) {
- $this->client_error(_('No such message.'), 404);
- return;
- }
-
- $cur = common_current_user();
-
- if ($cur && ($cur->id == $message->from_profile || $cur->id == $message->to_profile)) {
- $this->show_page($cur, 1);
- } else {
- $this->client_error(_('Only the sender and recipient may read this message.'), 403);
- return;
- }
- }
-
- function get_message() {
- $id = $this->trimmed('message');
- $message = Message::staticGet('id', $id);
- return $message;
- }
-
- function get_title($user, $page) {
- $message = $this->get_message();
- if (!$message) {
- return NULL;
- }
-
- if ($user->id == $message->from_profile) {
- $to = $message->getTo();
- $title = sprintf(_("Message to %1\$s on %2\$s"),
- $to->nickname,
- common_exact_date($message->created));
- } else if ($user->id == $message->to_profile) {
- $from = $message->getFrom();
- $title = sprintf(_("Message from %1\$s on %2\$s"),
- $from->nickname,
- common_exact_date($message->created));
- }
- return $title;
- }
+ if (!$message) {
+ $this->client_error(_('No such message.'), 404);
+ return;
+ }
+
+ $cur = common_current_user();
+
+ if ($cur && ($cur->id == $message->from_profile || $cur->id == $message->to_profile)) {
+ $this->show_page($cur, 1);
+ } else {
+ $this->client_error(_('Only the sender and recipient may read this message.'), 403);
+ return;
+ }
+ }
+
+ function get_message() {
+ $id = $this->trimmed('message');
+ $message = Message::staticGet('id', $id);
+ return $message;
+ }
+
+ function get_title($user, $page) {
+ $message = $this->get_message();
+ if (!$message) {
+ return NULL;
+ }
+
+ if ($user->id == $message->from_profile) {
+ $to = $message->getTo();
+ $title = sprintf(_("Message to %1\$s on %2\$s"),
+ $to->nickname,
+ common_exact_date($message->created));
+ } else if ($user->id == $message->to_profile) {
+ $from = $message->getFrom();
+ $title = sprintf(_("Message from %1\$s on %2\$s"),
+ $from->nickname,
+ common_exact_date($message->created));
+ }
+ return $title;
+ }
- function get_messages($user, $page) {
- $message = new Message();
- $message->id = $this->trimmed('message');
- $message->find();
- return $message;
- }
-
- function get_message_profile($message) {
- $user = common_current_user();
- if ($user->id == $message->from_profile) {
- return $message->getTo();
- } else if ($user->id == $message->to_profile) {
- return $message->getFrom();
- } else {
- # This shouldn't happen
- return NULL;
- }
- }
-
- function get_instructions() {
- return '';
- }
-
- function views_menu() {
- return;
- }
+ function get_messages($user, $page) {
+ $message = new Message();
+ $message->id = $this->trimmed('message');
+ $message->find();
+ return $message;
+ }
+
+ function get_message_profile($message) {
+ $user = common_current_user();
+ if ($user->id == $message->from_profile) {
+ return $message->getTo();
+ } else if ($user->id == $message->to_profile) {
+ return $message->getFrom();
+ } else {
+ # This shouldn't happen
+ return NULL;
+ }
+ }
+
+ function get_instructions() {
+ return '';
+ }
+
+ function views_menu() {
+ return;
+ }
}
- \ No newline at end of file
+ \ No newline at end of file
diff --git a/_darcs/pristine/actions/shownotice.php b/_darcs/pristine/actions/shownotice.php
index 6dea6d7bb..74d197ed1 100644
--- a/_darcs/pristine/actions/shownotice.php
+++ b/_darcs/pristine/actions/shownotice.php
@@ -23,94 +23,94 @@ require_once(INSTALLDIR.'/lib/stream.php');
class ShownoticeAction extends StreamAction {
- var $notice = NULL;
- var $profile = NULL;
- var $avatar = NULL;
+ var $notice = NULL;
+ var $profile = NULL;
+ var $avatar = NULL;
- function prepare($args) {
+ function prepare($args) {
- parent::prepare($args);
+ parent::prepare($args);
- $id = $this->arg('notice');
- $this->notice = Notice::staticGet($id);
+ $id = $this->arg('notice');
+ $this->notice = Notice::staticGet($id);
- if (!$this->notice) {
- $this->client_error(_('No such notice.'), 404);
- return false;
- }
+ if (!$this->notice) {
+ $this->client_error(_('No such notice.'), 404);
+ return false;
+ }
- $this->profile = $this->notice->getProfile();
+ $this->profile = $this->notice->getProfile();
- if (!$this->profile) {
- $this->server_error(_('Notice has no profile'), 500);
- return false;
- }
+ if (!$this->profile) {
+ $this->server_error(_('Notice has no profile'), 500);
+ return false;
+ }
- $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
+ $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
- return true;
- }
+ return true;
+ }
- function last_modified() {
- return max(strtotime($this->notice->created),
- strtotime($this->profile->modified),
- ($this->avatar) ? strtotime($this->avatar->modified) : 0);
- }
+ function last_modified() {
+ return max(strtotime($this->notice->created),
+ strtotime($this->profile->modified),
+ ($this->avatar) ? strtotime($this->avatar->modified) : 0);
+ }
- function etag() {
- return 'W/"' . implode(':', array($this->arg('action'),
- common_language(),
- $this->notice->id,
- strtotime($this->notice->created),
- strtotime($this->profile->modified),
- ($this->avatar) ? strtotime($this->avatar->modified) : 0)) . '"';
- }
+ function etag() {
+ return 'W/"' . implode(':', array($this->arg('action'),
+ common_language(),
+ $this->notice->id,
+ strtotime($this->notice->created),
+ strtotime($this->profile->modified),
+ ($this->avatar) ? strtotime($this->avatar->modified) : 0)) . '"';
+ }
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
- common_show_header(sprintf(_('%1$s\'s status on %2$s'),
- $this->profile->nickname,
- common_exact_date($this->notice->created)),
- array($this, 'show_header'), NULL,
- array($this, 'show_top'));
+ common_show_header(sprintf(_('%1$s\'s status on %2$s'),
+ $this->profile->nickname,
+ common_exact_date($this->notice->created)),
+ array($this, 'show_header'), NULL,
+ array($this, 'show_top'));
- common_element_start('ul', array('id' => 'notices'));
+ common_element_start('ul', array('id' => 'notices'));
$nli = new NoticeListItem($this->notice);
$nli->show();
- common_element_end('ul');
+ common_element_end('ul');
- common_show_footer();
- }
+ common_show_footer();
+ }
- function show_header() {
+ function show_header() {
- $user = User::staticGet($this->profile->id);
+ $user = User::staticGet($this->profile->id);
- if (!$user) {
- return;
- }
+ if (!$user) {
+ return;
+ }
- if ($user->emailmicroid && $user->email && $this->notice->uri) {
- common_element('meta', array('name' => 'microid',
- 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($this->notice->uri))));
- }
+ if ($user->emailmicroid && $user->email && $this->notice->uri) {
+ common_element('meta', array('name' => 'microid',
+ 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($this->notice->uri))));
+ }
- if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
- common_element('meta', array('name' => 'microid',
- 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($this->notice->uri))));
- }
- }
+ if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
+ common_element('meta', array('name' => 'microid',
+ 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($this->notice->uri))));
+ }
+ }
- function show_top() {
- $cur = common_current_user();
- if ($cur && $cur->id == $this->profile->id) {
- common_notice_form();
- }
- }
+ function show_top() {
+ $cur = common_current_user();
+ if ($cur && $cur->id == $this->profile->id) {
+ common_notice_form();
+ }
+ }
- function no_such_notice() {
- common_user_error(_('No such notice.'));
- }
+ function no_such_notice() {
+ common_user_error(_('No such notice.'));
+ }
}
diff --git a/_darcs/pristine/actions/showstream.php b/_darcs/pristine/actions/showstream.php
index 61fdec3fe..f8525348d 100644
--- a/_darcs/pristine/actions/showstream.php
+++ b/_darcs/pristine/actions/showstream.php
@@ -26,12 +26,12 @@ define('SUBSCRIPTIONS', 80);
class ShowstreamAction extends StreamAction {
- function handle($args) {
+ function handle($args) {
- parent::handle($args);
+ parent::handle($args);
$nickname_arg = $this->arg('nickname');
- $nickname = common_canonical_nickname($nickname_arg);
+ $nickname = common_canonical_nickname($nickname_arg);
# Permanent redirect on non-canonical nickname
@@ -44,163 +44,163 @@ class ShowstreamAction extends StreamAction {
return;
}
- $user = User::staticGet('nickname', $nickname);
-
- if (!$user) {
- $this->no_such_user();
- return;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- # Looks like we're good; start output
-
- # For YADIS discovery, we also have a <meta> tag
-
- header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
- $user->nickname)));
-
- common_show_header($profile->nickname,
- array($this, 'show_header'), $user,
- array($this, 'show_top'));
-
- $this->show_profile($profile);
-
- $this->show_notices($user);
-
- common_show_footer();
- }
-
- function show_top($user) {
- $cur = common_current_user();
-
- if ($cur && $cur->id == $user->id) {
- common_notice_form('showstream');
- }
-
- $this->views_menu();
-
- $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('nickname' => $user->nickname)),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'notices'),
- 1=>array('href'=>common_local_url('usertimeline', array('nickname' => $user->nickname)),
- 'type' => 'atom',
- 'version' => 'Atom 1.0',
- 'item' => 'usertimeline'),
-
- 2=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
- 'type' => 'rdf',
- 'version' => 'FOAF',
- 'item' => 'foaf')));
- }
-
- function show_header($user) {
- # Feeds
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('api',
- array('apiaction' => 'statuses',
- 'method' => 'user_timeline.rss',
- 'argument' => $user->nickname)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
- common_element('link', array('rel' => 'alternate feed',
- 'href' => common_local_url('api',
- array('apiaction' => 'statuses',
- 'method' => 'user_timeline.atom',
- 'argument' => $user->nickname)),
- 'type' => 'application/atom+xml',
- 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('userrss', array('nickname' =>
- $user->nickname)),
- 'type' => 'application/rdf+xml',
- 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
- # FOAF
- common_element('link', array('rel' => 'meta',
- 'href' => common_local_url('foaf', array('nickname' =>
- $user->nickname)),
- 'type' => 'application/rdf+xml',
- 'title' => 'FOAF'));
- # for remote subscriptions etc.
- common_element('meta', array('http-equiv' => 'X-XRDS-Location',
- 'content' => common_local_url('xrds', array('nickname' =>
- $user->nickname))));
- $profile = $user->getProfile();
- if ($profile->bio) {
- common_element('meta', array('name' => 'description',
- 'content' => $profile->bio));
- }
-
- if ($user->emailmicroid && $user->email && $profile->profileurl) {
- common_element('meta', array('name' => 'microid',
- 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($profile->profileurl))));
- }
- if ($user->jabbermicroid && $user->jabber && $profile->profileurl) {
- common_element('meta', array('name' => 'microid',
- 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($profile->profileurl))));
- }
-
- # See https://wiki.mozilla.org/Microsummaries
-
- common_element('link', array('rel' => 'microsummary',
- 'href' => common_local_url('microsummary',
- array('nickname' => $profile->nickname))));
- }
-
- function no_such_user() {
- $this->client_error(_('No such user.'), 404);
- }
-
- function show_profile($profile) {
-
- common_element_start('div', array('id' => 'profile', 'class' => 'vcard'));
-
- $this->show_personal($profile);
-
- $this->show_last_notice($profile);
-
- $cur = common_current_user();
-
- $this->show_subscriptions($profile);
-
- common_element_end('div');
- }
-
- function show_personal($profile) {
-
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- common_element_start('div', array('id' => 'profile_avatar'));
- common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
- 'class' => 'avatar profile photo',
- 'width' => AVATAR_PROFILE_SIZE,
- 'height' => AVATAR_PROFILE_SIZE,
- 'alt' => $profile->nickname));
+ $user = User::staticGet('nickname', $nickname);
+
+ if (!$user) {
+ $this->no_such_user();
+ return;
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
+
+ # Looks like we're good; start output
+
+ # For YADIS discovery, we also have a <meta> tag
+
+ header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
+ $user->nickname)));
+
+ common_show_header($profile->nickname,
+ array($this, 'show_header'), $user,
+ array($this, 'show_top'));
+
+ $this->show_profile($profile);
+
+ $this->show_notices($user);
+
+ common_show_footer();
+ }
+
+ function show_top($user) {
+ $cur = common_current_user();
+
+ if ($cur && $cur->id == $user->id) {
+ common_notice_form('showstream');
+ }
+
+ $this->views_menu();
+
+ $this->show_feeds_list(array(0=>array('href'=>common_local_url('userrss', array('nickname' => $user->nickname)),
+ 'type' => 'rss',
+ 'version' => 'RSS 1.0',
+ 'item' => 'notices'),
+ 1=>array('href'=>common_local_url('usertimeline', array('nickname' => $user->nickname)),
+ 'type' => 'atom',
+ 'version' => 'Atom 1.0',
+ 'item' => 'usertimeline'),
+
+ 2=>array('href'=>common_local_url('foaf',array('nickname' => $user->nickname)),
+ 'type' => 'rdf',
+ 'version' => 'FOAF',
+ 'item' => 'foaf')));
+ }
+
+ function show_header($user) {
+ # Feeds
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'user_timeline.rss',
+ 'argument' => $user->nickname)),
+ 'type' => 'application/rss+xml',
+ 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
+ common_element('link', array('rel' => 'alternate feed',
+ 'href' => common_local_url('api',
+ array('apiaction' => 'statuses',
+ 'method' => 'user_timeline.atom',
+ 'argument' => $user->nickname)),
+ 'type' => 'application/atom+xml',
+ 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('userrss', array('nickname' =>
+ $user->nickname)),
+ 'type' => 'application/rdf+xml',
+ 'title' => sprintf(_('Notice feed for %s'), $user->nickname)));
+ # FOAF
+ common_element('link', array('rel' => 'meta',
+ 'href' => common_local_url('foaf', array('nickname' =>
+ $user->nickname)),
+ 'type' => 'application/rdf+xml',
+ 'title' => 'FOAF'));
+ # for remote subscriptions etc.
+ common_element('meta', array('http-equiv' => 'X-XRDS-Location',
+ 'content' => common_local_url('xrds', array('nickname' =>
+ $user->nickname))));
+ $profile = $user->getProfile();
+ if ($profile->bio) {
+ common_element('meta', array('name' => 'description',
+ 'content' => $profile->bio));
+ }
+
+ if ($user->emailmicroid && $user->email && $profile->profileurl) {
+ common_element('meta', array('name' => 'microid',
+ 'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($profile->profileurl))));
+ }
+ if ($user->jabbermicroid && $user->jabber && $profile->profileurl) {
+ common_element('meta', array('name' => 'microid',
+ 'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($profile->profileurl))));
+ }
+
+ # See https://wiki.mozilla.org/Microsummaries
+
+ common_element('link', array('rel' => 'microsummary',
+ 'href' => common_local_url('microsummary',
+ array('nickname' => $profile->nickname))));
+ }
+
+ function no_such_user() {
+ $this->client_error(_('No such user.'), 404);
+ }
+
+ function show_profile($profile) {
+
+ common_element_start('div', array('id' => 'profile', 'class' => 'vcard'));
+
+ $this->show_personal($profile);
+
+ $this->show_last_notice($profile);
+
+ $cur = common_current_user();
+
+ $this->show_subscriptions($profile);
+
+ common_element_end('div');
+ }
+
+ function show_personal($profile) {
+
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ common_element_start('div', array('id' => 'profile_avatar'));
+ common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
+ 'class' => 'avatar profile photo',
+ 'width' => AVATAR_PROFILE_SIZE,
+ 'height' => AVATAR_PROFILE_SIZE,
+ 'alt' => $profile->nickname));
common_element_start('ul', array('id' => 'profile_actions'));
common_element_start('li', array('id' => 'profile_subscribe'));
- $cur = common_current_user();
- if ($cur) {
- if ($cur->id != $profile->id) {
- if ($cur->isSubscribed($profile)) {
- common_unsubscribe_form($profile);
- } else {
- common_subscribe_form($profile);
- }
- }
- } else {
- $this->show_remote_subscribe_link($profile);
- }
+ $cur = common_current_user();
+ if ($cur) {
+ if ($cur->id != $profile->id) {
+ if ($cur->isSubscribed($profile)) {
+ common_unsubscribe_form($profile);
+ } else {
+ common_subscribe_form($profile);
+ }
+ }
+ } else {
+ $this->show_remote_subscribe_link($profile);
+ }
common_element_end('li');
- $user = User::staticGet('id', $profile->id);
- common_profile_new_message_nudge($cur, $user, $profile);
+ $user = User::staticGet('id', $profile->id);
+ common_profile_new_message_nudge($cur, $user, $profile);
if ($cur && $cur->id != $profile->id) {
$blocked = $cur->hasBlocked($profile);
@@ -215,224 +215,224 @@ class ShowstreamAction extends StreamAction {
common_element_end('li');
}
- common_element_end('ul');
-
- common_element_end('div');
-
- common_element_start('div', array('id' => 'profile_information'));
-
- if ($profile->fullname) {
- common_element('h1', array('class' => 'fn'), $profile->fullname . ' (' . $profile->nickname . ')');
- } else {
- common_element('h1', array('class' => 'fn nickname'), $profile->nickname);
- }
-
- if ($profile->location) {
- common_element('p', 'location', $profile->location);
- }
- if ($profile->bio) {
- common_element('p', 'description note', $profile->bio);
- }
- if ($profile->homepage) {
- common_element_start('p', 'website');
- common_element('a', array('href' => $profile->homepage,
- 'rel' => 'me', 'class' => 'url'),
- $profile->homepage);
- common_element_end('p');
- }
-
- $this->show_statistics($profile);
-
- common_element_end('div');
- }
-
- function show_remote_subscribe_link($profile) {
- $url = common_local_url('remotesubscribe',
- array('nickname' => $profile->nickname));
- common_element('a', array('href' => $url,
- 'id' => 'remotesubscribe'),
- _('Subscribe'));
- }
-
- function show_unsubscribe_form($profile) {
- common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
- 'action' => common_local_url('unsubscribe')));
- common_hidden('token', common_session_token());
- common_element('input', array('id' => 'unsubscribeto',
- 'name' => 'unsubscribeto',
- 'type' => 'hidden',
- 'value' => $profile->nickname));
- common_element('input', array('type' => 'submit',
- 'class' => 'submit',
- 'value' => _('Unsubscribe')));
- common_element_end('form');
- }
-
- function show_subscriptions($profile) {
- global $config;
-
- $subs = DB_DataObject::factory('subscription');
- $subs->subscriber = $profile->id;
- $subs->whereAdd('subscribed != ' . $profile->id);
-
- $subs->orderBy('created DESC');
-
- # We ask for an extra one to know if we need to do another page
-
- $subs->limit(0, SUBSCRIPTIONS + 1);
-
- $subs_count = $subs->find();
-
- common_element_start('div', array('id' => 'subscriptions'));
-
- common_element('h2', NULL, _('Subscriptions'));
-
- if ($subs_count > 0) {
-
- common_element_start('ul', array('id' => 'subscriptions_avatars'));
-
- for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
-
- if (!$subs->fetch()) {
- common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
- break;
- }
-
- $other = Profile::staticGet($subs->subscribed);
-
- if (!$other) {
- common_log_db_error($subs, 'SELECT', __FILE__);
- continue;
- }
-
- common_element_start('li', 'vcard');
- common_element_start('a', array('title' => ($other->fullname) ?
- $other->fullname :
- $other->nickname,
- 'href' => $other->profileurl,
- 'rel' => 'contact',
- 'class' => 'subscription fn url'));
- $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
- common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
- 'width' => AVATAR_MINI_SIZE,
- 'height' => AVATAR_MINI_SIZE,
- 'class' => 'avatar mini photo',
- 'alt' => ($other->fullname) ?
- $other->fullname :
- $other->nickname));
- common_element_end('a');
- common_element_end('li');
- }
-
- common_element_end('ul');
- }
-
- if ($subs_count > SUBSCRIPTIONS) {
- common_element_start('p', array('id' => 'subscriptions_viewall'));
-
- common_element('a', array('href' => common_local_url('subscriptions',
- array('nickname' => $profile->nickname)),
- 'class' => 'moresubscriptions'),
- _('All subscriptions'));
- common_element_end('p');
- }
-
- common_element_end('div');
- }
-
- function show_statistics($profile) {
-
- // XXX: WORM cache this
- $subs = DB_DataObject::factory('subscription');
- $subs->subscriber = $profile->id;
- $subs_count = (int) $subs->count() - 1;
-
- $subbed = DB_DataObject::factory('subscription');
- $subbed->subscribed = $profile->id;
- $subbed_count = (int) $subbed->count() - 1;
-
- $notices = DB_DataObject::factory('notice');
- $notices->profile_id = $profile->id;
- $notice_count = (int) $notices->count();
-
- common_element_start('div', 'statistics');
- common_element('h2', 'statistics', _('Statistics'));
-
- # Other stats...?
- common_element_start('dl', 'statistics');
- common_element('dt', 'membersince', _('Member since'));
- common_element('dd', 'membersince', date('j M Y',
- strtotime($profile->created)));
-
- common_element_start('dt', 'subscriptions');
- common_element('a', array('href' => common_local_url('subscriptions',
- array('nickname' => $profile->nickname))),
- _('Subscriptions'));
- common_element_end('dt');
- common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
- common_element_start('dt', 'subscribers');
- common_element('a', array('href' => common_local_url('subscribers',
- array('nickname' => $profile->nickname))),
- _('Subscribers'));
- common_element_end('dt');
- common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
- common_element('dt', 'notices', _('Notices'));
- common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
- # XXX: link these to something
- common_element('dt', 'tags', _('Tags'));
- common_element_start('dd', 'tags');
- $tags = Profile_tag::getTags($profile->id, $profile->id);
-
- common_element_start('ul', 'tags xoxo');
- foreach ($tags as $tag) {
- common_element_start('li');
- common_element('a', array('rel' => 'bookmark tag',
- 'href' => common_local_url('peopletag',
- array('tag' => $tag))),
- $tag);
- common_element_end('li');
- }
- common_element_end('ul');
- common_element_end('dd');
-
- common_element_end('dl');
-
- common_element_end('div');
- }
-
- function show_notices($user) {
-
- $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
- $notice = $user->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ common_element_end('ul');
+
+ common_element_end('div');
+
+ common_element_start('div', array('id' => 'profile_information'));
+
+ if ($profile->fullname) {
+ common_element('h1', array('class' => 'fn'), $profile->fullname . ' (' . $profile->nickname . ')');
+ } else {
+ common_element('h1', array('class' => 'fn nickname'), $profile->nickname);
+ }
+
+ if ($profile->location) {
+ common_element('p', 'location', $profile->location);
+ }
+ if ($profile->bio) {
+ common_element('p', 'description note', $profile->bio);
+ }
+ if ($profile->homepage) {
+ common_element_start('p', 'website');
+ common_element('a', array('href' => $profile->homepage,
+ 'rel' => 'me', 'class' => 'url'),
+ $profile->homepage);
+ common_element_end('p');
+ }
+
+ $this->show_statistics($profile);
+
+ common_element_end('div');
+ }
+
+ function show_remote_subscribe_link($profile) {
+ $url = common_local_url('remotesubscribe',
+ array('nickname' => $profile->nickname));
+ common_element('a', array('href' => $url,
+ 'id' => 'remotesubscribe'),
+ _('Subscribe'));
+ }
+
+ function show_unsubscribe_form($profile) {
+ common_element_start('form', array('id' => 'unsubscribe', 'method' => 'post',
+ 'action' => common_local_url('unsubscribe')));
+ common_hidden('token', common_session_token());
+ common_element('input', array('id' => 'unsubscribeto',
+ 'name' => 'unsubscribeto',
+ 'type' => 'hidden',
+ 'value' => $profile->nickname));
+ common_element('input', array('type' => 'submit',
+ 'class' => 'submit',
+ 'value' => _('Unsubscribe')));
+ common_element_end('form');
+ }
+
+ function show_subscriptions($profile) {
+ global $config;
+
+ $subs = DB_DataObject::factory('subscription');
+ $subs->subscriber = $profile->id;
+ $subs->whereAdd('subscribed != ' . $profile->id);
+
+ $subs->orderBy('created DESC');
+
+ # We ask for an extra one to know if we need to do another page
+
+ $subs->limit(0, SUBSCRIPTIONS + 1);
+
+ $subs_count = $subs->find();
+
+ common_element_start('div', array('id' => 'subscriptions'));
+
+ common_element('h2', NULL, _('Subscriptions'));
+
+ if ($subs_count > 0) {
+
+ common_element_start('ul', array('id' => 'subscriptions_avatars'));
+
+ for ($i = 0; $i < min($subs_count, SUBSCRIPTIONS); $i++) {
+
+ if (!$subs->fetch()) {
+ common_debug('Weirdly, broke out of subscriptions loop early', __FILE__);
+ break;
+ }
+
+ $other = Profile::staticGet($subs->subscribed);
+
+ if (!$other) {
+ common_log_db_error($subs, 'SELECT', __FILE__);
+ continue;
+ }
+
+ common_element_start('li', 'vcard');
+ common_element_start('a', array('title' => ($other->fullname) ?
+ $other->fullname :
+ $other->nickname,
+ 'href' => $other->profileurl,
+ 'rel' => 'contact',
+ 'class' => 'subscription fn url'));
+ $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
+ common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
+ 'width' => AVATAR_MINI_SIZE,
+ 'height' => AVATAR_MINI_SIZE,
+ 'class' => 'avatar mini photo',
+ 'alt' => ($other->fullname) ?
+ $other->fullname :
+ $other->nickname));
+ common_element_end('a');
+ common_element_end('li');
+ }
+
+ common_element_end('ul');
+ }
+
+ if ($subs_count > SUBSCRIPTIONS) {
+ common_element_start('p', array('id' => 'subscriptions_viewall'));
+
+ common_element('a', array('href' => common_local_url('subscriptions',
+ array('nickname' => $profile->nickname)),
+ 'class' => 'moresubscriptions'),
+ _('All subscriptions'));
+ common_element_end('p');
+ }
+
+ common_element_end('div');
+ }
+
+ function show_statistics($profile) {
+
+ // XXX: WORM cache this
+ $subs = DB_DataObject::factory('subscription');
+ $subs->subscriber = $profile->id;
+ $subs_count = (int) $subs->count() - 1;
+
+ $subbed = DB_DataObject::factory('subscription');
+ $subbed->subscribed = $profile->id;
+ $subbed_count = (int) $subbed->count() - 1;
+
+ $notices = DB_DataObject::factory('notice');
+ $notices->profile_id = $profile->id;
+ $notice_count = (int) $notices->count();
+
+ common_element_start('div', 'statistics');
+ common_element('h2', 'statistics', _('Statistics'));
+
+ # Other stats...?
+ common_element_start('dl', 'statistics');
+ common_element('dt', 'membersince', _('Member since'));
+ common_element('dd', 'membersince', date('j M Y',
+ strtotime($profile->created)));
+
+ common_element_start('dt', 'subscriptions');
+ common_element('a', array('href' => common_local_url('subscriptions',
+ array('nickname' => $profile->nickname))),
+ _('Subscriptions'));
+ common_element_end('dt');
+ common_element('dd', 'subscriptions', (is_int($subs_count)) ? $subs_count : '0');
+ common_element_start('dt', 'subscribers');
+ common_element('a', array('href' => common_local_url('subscribers',
+ array('nickname' => $profile->nickname))),
+ _('Subscribers'));
+ common_element_end('dt');
+ common_element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
+ common_element('dt', 'notices', _('Notices'));
+ common_element('dd', 'notices', (is_int($notice_count)) ? $notice_count : '0');
+ # XXX: link these to something
+ common_element('dt', 'tags', _('Tags'));
+ common_element_start('dd', 'tags');
+ $tags = Profile_tag::getTags($profile->id, $profile->id);
+
+ common_element_start('ul', 'tags xoxo');
+ foreach ($tags as $tag) {
+ common_element_start('li');
+ common_element('a', array('rel' => 'bookmark tag',
+ 'href' => common_local_url('peopletag',
+ array('tag' => $tag))),
+ $tag);
+ common_element_end('li');
+ }
+ common_element_end('ul');
+ common_element_end('dd');
+
+ common_element_end('dl');
+
+ common_element_end('div');
+ }
+
+ function show_notices($user) {
+
+ $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+
+ $notice = $user->getNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$pnl = new ProfileNoticeList($notice);
$cnt = $pnl->show();
- common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
- 'showstream', array('nickname' => $user->nickname));
- }
-
- function show_last_notice($profile) {
-
- common_element('h2', NULL, _('Currently'));
-
- $notice = $profile->getCurrentNotice();
-
- if ($notice) {
- # FIXME: URL, image, video, audio
- common_element_start('p', array('class' => 'notice_current'));
- if ($notice->rendered) {
- common_raw($notice->rendered);
- } else {
- # XXX: may be some uncooked notices in the DB,
- # we cook them right now. This can probably disappear in future
- # versions (>> 0.4.x)
- common_raw(common_render_content($notice->content, $notice));
- }
- common_element_end('p');
- }
- }
+ common_pagination($page>1, $cnt>NOTICES_PER_PAGE, $page,
+ 'showstream', array('nickname' => $user->nickname));
+ }
+
+ function show_last_notice($profile) {
+
+ common_element('h2', NULL, _('Currently'));
+
+ $notice = $profile->getCurrentNotice();
+
+ if ($notice) {
+ # FIXME: URL, image, video, audio
+ common_element_start('p', array('class' => 'notice_current'));
+ if ($notice->rendered) {
+ common_raw($notice->rendered);
+ } else {
+ # XXX: may be some uncooked notices in the DB,
+ # we cook them right now. This can probably disappear in future
+ # versions (>> 0.4.x)
+ common_raw(common_render_content($notice->content, $notice));
+ }
+ common_element_end('p');
+ }
+ }
}
# We don't show the author for a profile, since we already know who it is!
diff --git a/_darcs/pristine/actions/smssettings.php b/_darcs/pristine/actions/smssettings.php
index 5db26730a..506801e97 100644
--- a/_darcs/pristine/actions/smssettings.php
+++ b/_darcs/pristine/actions/smssettings.php
@@ -24,308 +24,308 @@ require_once(INSTALLDIR.'/actions/emailsettings.php');
class SmssettingsAction extends EmailsettingsAction {
- function get_instructions() {
- return _('You can receive SMS messages through email from %%site.name%%.');
- }
-
- function show_form($msg=NULL, $success=false) {
- $user = common_current_user();
- $this->form_header(_('SMS Settings'), $msg, $success);
- common_element_start('form', array('method' => 'post',
- 'id' => 'smssettings',
- 'action' =>
- common_local_url('smssettings')));
- common_hidden('token', common_session_token());
- common_element('h2', NULL, _('Address'));
-
- if ($user->sms) {
- common_element_start('p');
- $carrier = $user->getCarrier();
- common_element('span', 'address confirmed', $user->sms . ' (' . $carrier->name . ')');
- common_element('span', 'input_instructions',
- _('Current confirmed SMS-enabled phone number.'));
- common_hidden('sms', $user->sms);
- common_hidden('carrier', $user->carrier);
- common_element_end('p');
- common_submit('remove', _('Remove'));
- } else {
- $confirm = $this->get_confirmation();
- if ($confirm) {
- $carrier = Sms_carrier::staticGet($confirm->address_extra);
- common_element_start('p');
- common_element('span', 'address unconfirmed', $confirm->address . ' (' . $carrier->name . ')');
- common_element('span', 'input_instructions',
- _('Awaiting confirmation on this phone number.'));
- common_hidden('sms', $confirm->address);
- common_hidden('carrier', $confirm->address_extra);
- common_element_end('p');
- common_submit('cancel', _('Cancel'));
- common_input('code', _('Confirmation code'), NULL,
- _('Enter the code you received on your phone.'));
- common_submit('confirm', _('Confirm'));
- } else {
- common_input('sms', _('SMS Phone number'),
- ($this->arg('sms')) ? $this->arg('sms') : NULL,
- _('Phone number, no punctuation or spaces, with area code'));
- $this->carrier_select();
- common_submit('add', _('Add'));
- }
- }
-
- if ($user->sms) {
- common_element('h2', NULL, _('Incoming email'));
-
- if ($user->incomingemail) {
- common_element_start('p');
- common_element('span', 'address', $user->incomingemail);
- common_element('span', 'input_instructions',
- _('Send email to this address to post new notices.'));
- common_element_end('p');
- common_submit('removeincoming', _('Remove'));
- }
-
- common_element_start('p');
- common_element('span', 'input_instructions',
- _('Make a new email address for posting to; cancels the old one.'));
- common_element_end('p');
- common_submit('newincoming', _('New'));
- }
-
- common_element('h2', NULL, _('Preferences'));
-
- common_checkbox('smsnotify',
- _('Send me notices through SMS; I understand I may incur exorbitant charges from my carrier.'),
- $user->smsnotify);
-
- common_submit('save', _('Save'));
-
- common_element_end('form');
- common_show_footer();
- }
-
- function get_confirmation() {
- $user = common_current_user();
- $confirm = new Confirm_address();
- $confirm->user_id = $user->id;
- $confirm->address_type = 'sms';
- if ($confirm->find(TRUE)) {
- return $confirm;
- } else {
- return NULL;
- }
- }
-
- function handle_post() {
-
- # CSRF protection
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- if ($this->arg('save')) {
- $this->save_preferences();
- } else if ($this->arg('add')) {
- $this->add_address();
- } else if ($this->arg('cancel')) {
- $this->cancel_confirmation();
- } else if ($this->arg('remove')) {
- $this->remove_address();
- } else if ($this->arg('removeincoming')) {
- $this->remove_incoming();
- } else if ($this->arg('newincoming')) {
- $this->new_incoming();
- } else if ($this->arg('confirm')) {
- $this->confirm_code();
- } else {
- $this->show_form(_('Unexpected form submission.'));
- }
- }
-
- function save_preferences() {
-
- $smsnotify = $this->boolean('smsnotify');
-
- $user = common_current_user();
-
- assert(!is_null($user)); # should already be checked
-
- $user->query('BEGIN');
-
- $original = clone($user);
-
- $user->smsnotify = $smsnotify;
-
- $result = $user->update($original);
-
- if ($result === FALSE) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
-
- $user->query('COMMIT');
-
- $this->show_form(_('Preferences saved.'), true);
- }
-
- function add_address() {
-
- $user = common_current_user();
-
- $sms = $this->trimmed('sms');
- $carrier_id = $this->trimmed('carrier');
-
- # Some validation
-
- if (!$sms) {
- $this->show_form(_('No phone number.'));
- return;
- }
-
- if (!$carrier_id) {
- $this->show_form(_('No carrier selected.'));
- return;
- }
-
- $sms = common_canonical_sms($sms);
-
- if ($user->sms == $sms) {
- $this->show_form(_('That is already your phone number.'));
- return;
- } else if ($this->sms_exists($sms)) {
- $this->show_form(_('That phone number already belongs to another user.'));
- return;
- }
-
- $confirm = new Confirm_address();
- $confirm->address = $sms;
- $confirm->address_extra = $carrier_id;
- $confirm->address_type = 'sms';
- $confirm->user_id = $user->id;
- $confirm->code = common_confirmation_code(40);
-
- $result = $confirm->insert();
-
- if ($result === FALSE) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
- common_server_error(_('Couldn\'t insert confirmation code.'));
- return;
- }
-
- $carrier = Sms_carrier::staticGet($carrier_id);
-
- mail_confirm_sms($confirm->code,
- $user->nickname,
- $carrier->toEmailAddress($sms));
-
- $msg = _('A confirmation code was sent to the phone number you added. Check your inbox (and spam box!) for the code and instructions on how to use it.');
-
- $this->show_form($msg, TRUE);
- }
-
- function cancel_confirmation() {
-
- $sms = $this->trimmed('sms');
- $carrier = $this->trimmed('carrier');
-
- $confirm = $this->get_confirmation();
-
- if (!$confirm) {
- $this->show_form(_('No pending confirmation to cancel.'));
- return;
- }
- if ($confirm->address != $sms) {
- $this->show_form(_('That is the wrong confirmation number.'));
- return;
- }
+ function get_instructions() {
+ return _('You can receive SMS messages through email from %%site.name%%.');
+ }
+
+ function show_form($msg=NULL, $success=false) {
+ $user = common_current_user();
+ $this->form_header(_('SMS Settings'), $msg, $success);
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'smssettings',
+ 'action' =>
+ common_local_url('smssettings')));
+ common_hidden('token', common_session_token());
+ common_element('h2', NULL, _('Address'));
+
+ if ($user->sms) {
+ common_element_start('p');
+ $carrier = $user->getCarrier();
+ common_element('span', 'address confirmed', $user->sms . ' (' . $carrier->name . ')');
+ common_element('span', 'input_instructions',
+ _('Current confirmed SMS-enabled phone number.'));
+ common_hidden('sms', $user->sms);
+ common_hidden('carrier', $user->carrier);
+ common_element_end('p');
+ common_submit('remove', _('Remove'));
+ } else {
+ $confirm = $this->get_confirmation();
+ if ($confirm) {
+ $carrier = Sms_carrier::staticGet($confirm->address_extra);
+ common_element_start('p');
+ common_element('span', 'address unconfirmed', $confirm->address . ' (' . $carrier->name . ')');
+ common_element('span', 'input_instructions',
+ _('Awaiting confirmation on this phone number.'));
+ common_hidden('sms', $confirm->address);
+ common_hidden('carrier', $confirm->address_extra);
+ common_element_end('p');
+ common_submit('cancel', _('Cancel'));
+ common_input('code', _('Confirmation code'), NULL,
+ _('Enter the code you received on your phone.'));
+ common_submit('confirm', _('Confirm'));
+ } else {
+ common_input('sms', _('SMS Phone number'),
+ ($this->arg('sms')) ? $this->arg('sms') : NULL,
+ _('Phone number, no punctuation or spaces, with area code'));
+ $this->carrier_select();
+ common_submit('add', _('Add'));
+ }
+ }
+
+ if ($user->sms) {
+ common_element('h2', NULL, _('Incoming email'));
+
+ if ($user->incomingemail) {
+ common_element_start('p');
+ common_element('span', 'address', $user->incomingemail);
+ common_element('span', 'input_instructions',
+ _('Send email to this address to post new notices.'));
+ common_element_end('p');
+ common_submit('removeincoming', _('Remove'));
+ }
+
+ common_element_start('p');
+ common_element('span', 'input_instructions',
+ _('Make a new email address for posting to; cancels the old one.'));
+ common_element_end('p');
+ common_submit('newincoming', _('New'));
+ }
+
+ common_element('h2', NULL, _('Preferences'));
+
+ common_checkbox('smsnotify',
+ _('Send me notices through SMS; I understand I may incur exorbitant charges from my carrier.'),
+ $user->smsnotify);
+
+ common_submit('save', _('Save'));
+
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function get_confirmation() {
+ $user = common_current_user();
+ $confirm = new Confirm_address();
+ $confirm->user_id = $user->id;
+ $confirm->address_type = 'sms';
+ if ($confirm->find(TRUE)) {
+ return $confirm;
+ } else {
+ return NULL;
+ }
+ }
+
+ function handle_post() {
+
+ # CSRF protection
+
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ if ($this->arg('save')) {
+ $this->save_preferences();
+ } else if ($this->arg('add')) {
+ $this->add_address();
+ } else if ($this->arg('cancel')) {
+ $this->cancel_confirmation();
+ } else if ($this->arg('remove')) {
+ $this->remove_address();
+ } else if ($this->arg('removeincoming')) {
+ $this->remove_incoming();
+ } else if ($this->arg('newincoming')) {
+ $this->new_incoming();
+ } else if ($this->arg('confirm')) {
+ $this->confirm_code();
+ } else {
+ $this->show_form(_('Unexpected form submission.'));
+ }
+ }
+
+ function save_preferences() {
+
+ $smsnotify = $this->boolean('smsnotify');
+
+ $user = common_current_user();
+
+ assert(!is_null($user)); # should already be checked
+
+ $user->query('BEGIN');
+
+ $original = clone($user);
+
+ $user->smsnotify = $smsnotify;
+
+ $result = $user->update($original);
+
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
+
+ $user->query('COMMIT');
+
+ $this->show_form(_('Preferences saved.'), true);
+ }
+
+ function add_address() {
+
+ $user = common_current_user();
+
+ $sms = $this->trimmed('sms');
+ $carrier_id = $this->trimmed('carrier');
+
+ # Some validation
+
+ if (!$sms) {
+ $this->show_form(_('No phone number.'));
+ return;
+ }
+
+ if (!$carrier_id) {
+ $this->show_form(_('No carrier selected.'));
+ return;
+ }
+
+ $sms = common_canonical_sms($sms);
+
+ if ($user->sms == $sms) {
+ $this->show_form(_('That is already your phone number.'));
+ return;
+ } else if ($this->sms_exists($sms)) {
+ $this->show_form(_('That phone number already belongs to another user.'));
+ return;
+ }
+
+ $confirm = new Confirm_address();
+ $confirm->address = $sms;
+ $confirm->address_extra = $carrier_id;
+ $confirm->address_type = 'sms';
+ $confirm->user_id = $user->id;
+ $confirm->code = common_confirmation_code(40);
+
+ $result = $confirm->insert();
+
+ if ($result === FALSE) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_server_error(_('Couldn\'t insert confirmation code.'));
+ return;
+ }
+
+ $carrier = Sms_carrier::staticGet($carrier_id);
+
+ mail_confirm_sms($confirm->code,
+ $user->nickname,
+ $carrier->toEmailAddress($sms));
+
+ $msg = _('A confirmation code was sent to the phone number you added. Check your inbox (and spam box!) for the code and instructions on how to use it.');
+
+ $this->show_form($msg, TRUE);
+ }
+
+ function cancel_confirmation() {
+
+ $sms = $this->trimmed('sms');
+ $carrier = $this->trimmed('carrier');
+
+ $confirm = $this->get_confirmation();
+
+ if (!$confirm) {
+ $this->show_form(_('No pending confirmation to cancel.'));
+ return;
+ }
+ if ($confirm->address != $sms) {
+ $this->show_form(_('That is the wrong confirmation number.'));
+ return;
+ }
$result = $confirm->delete();
if (!$result) {
- common_log_db_error($confirm, 'DELETE', __FILE__);
+ common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.'));
return;
}
$this->show_form(_('Confirmation cancelled.'), TRUE);
- }
-
- function remove_address() {
-
- $user = common_current_user();
- $sms = $this->arg('sms');
- $carrier = $this->arg('carrier');
-
- # Maybe an old tab open...?
-
- if ($user->sms != $sms) {
- $this->show_form(_('That is not your phone number.'));
- return;
- }
-
- $user->query('BEGIN');
- $original = clone($user);
- $user->sms = NULL;
- $user->carrier = NULL;
- $user->smsemail = NULL;
- $result = $user->updateKeys($original);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t update user.'));
- return;
- }
- $user->query('COMMIT');
-
- $this->show_form(_('The address was removed.'), TRUE);
- }
-
- function sms_exists($sms) {
- $user = common_current_user();
- $other = User::staticGet('sms', $sms);
- if (!$other) {
- return false;
- } else {
- return $other->id != $user->id;
- }
- }
-
- function carrier_select() {
- $carrier = new Sms_carrier();
- $cnt = $carrier->find();
-
- common_element_start('p');
- common_element('label', array('for' => 'carrier'));
- common_element_start('select', array('name' => 'carrier',
- 'id' => 'carrier'));
- common_element('option', array('value' => 0),
- _('Select a carrier'));
- while ($carrier->fetch()) {
- common_element('option', array('value' => $carrier->id),
- $carrier->name);
- }
- common_element_end('select');
- common_element_end('p');
- common_element('span', 'input_instructions',
- sprintf(_('Mobile carrier for your phone. '.
- 'If you know a carrier that accepts ' .
- 'SMS over email but isn\'t listed here, ' .
- 'send email to let us know at %s.'),
- common_config('site', 'email')));
- }
-
- function confirm_code() {
-
- $code = $this->trimmed('code');
-
- if (!$code) {
- $this->show_form(_('No code entered'));
- return;
- }
-
- common_redirect(common_local_url('confirmaddress',
- array('code' => $code)));
- }
+ }
+
+ function remove_address() {
+
+ $user = common_current_user();
+ $sms = $this->arg('sms');
+ $carrier = $this->arg('carrier');
+
+ # Maybe an old tab open...?
+
+ if ($user->sms != $sms) {
+ $this->show_form(_('That is not your phone number.'));
+ return;
+ }
+
+ $user->query('BEGIN');
+ $original = clone($user);
+ $user->sms = NULL;
+ $user->carrier = NULL;
+ $user->smsemail = NULL;
+ $result = $user->updateKeys($original);
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t update user.'));
+ return;
+ }
+ $user->query('COMMIT');
+
+ $this->show_form(_('The address was removed.'), TRUE);
+ }
+
+ function sms_exists($sms) {
+ $user = common_current_user();
+ $other = User::staticGet('sms', $sms);
+ if (!$other) {
+ return false;
+ } else {
+ return $other->id != $user->id;
+ }
+ }
+
+ function carrier_select() {
+ $carrier = new Sms_carrier();
+ $cnt = $carrier->find();
+
+ common_element_start('p');
+ common_element('label', array('for' => 'carrier'));
+ common_element_start('select', array('name' => 'carrier',
+ 'id' => 'carrier'));
+ common_element('option', array('value' => 0),
+ _('Select a carrier'));
+ while ($carrier->fetch()) {
+ common_element('option', array('value' => $carrier->id),
+ $carrier->name);
+ }
+ common_element_end('select');
+ common_element_end('p');
+ common_element('span', 'input_instructions',
+ sprintf(_('Mobile carrier for your phone. '.
+ 'If you know a carrier that accepts ' .
+ 'SMS over email but isn\'t listed here, ' .
+ 'send email to let us know at %s.'),
+ common_config('site', 'email')));
+ }
+
+ function confirm_code() {
+
+ $code = $this->trimmed('code');
+
+ if (!$code) {
+ $this->show_form(_('No code entered'));
+ return;
+ }
+
+ common_redirect(common_local_url('confirmaddress',
+ array('code' => $code)));
+ }
}
diff --git a/_darcs/pristine/actions/subedit.php b/_darcs/pristine/actions/subedit.php
index e7505e3fe..1d095ab9a 100644
--- a/_darcs/pristine/actions/subedit.php
+++ b/_darcs/pristine/actions/subedit.php
@@ -32,12 +32,12 @@ class SubeditAction extends Action {
return false;
}
- $token = $this->trimmed('token');
+ $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
$id = $this->trimmed('profile');
diff --git a/_darcs/pristine/actions/subscribe.php b/_darcs/pristine/actions/subscribe.php
index 64abda004..c94c4d7eb 100644
--- a/_darcs/pristine/actions/subscribe.php
+++ b/_darcs/pristine/actions/subscribe.php
@@ -21,58 +21,58 @@ if (!defined('LACONICA')) { exit(1); }
class SubscribeAction extends Action {
- function handle($args) {
- parent::handle($args);
+ function handle($args) {
+ parent::handle($args);
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- return;
- }
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ return;
+ }
- $user = common_current_user();
+ $user = common_current_user();
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)));
- return;
- }
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)));
+ return;
+ }
- # CSRF protection
+ # CSRF protection
- $token = $this->trimmed('token');
+ $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
- $other_id = $this->arg('subscribeto');
+ $other_id = $this->arg('subscribeto');
$other = User::staticGet('id', $other_id);
if (!$other) {
- $this->client_error(_('Not a local user.'));
- return;
+ $this->client_error(_('Not a local user.'));
+ return;
}
- $result = subs_subscribe_to($user, $other);
+ $result = subs_subscribe_to($user, $other);
- if($result != true) {
- common_user_error($result);
- return;
- }
+ if($result != true) {
+ common_user_error($result);
+ return;
+ }
- if ($this->boolean('ajax')) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Subscribed'));
- common_element_end('head');
- common_element_start('body');
- common_unsubscribe_form($other->getProfile());
- common_element_end('body');
- common_element_end('html');
- } else {
- common_redirect(common_local_url('subscriptions', array('nickname' =>
- $user->nickname)));
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Subscribed'));
+ common_element_end('head');
+ common_element_start('body');
+ common_unsubscribe_form($other->getProfile());
+ common_element_end('body');
+ common_element_end('html');
+ } else {
+ common_redirect(common_local_url('subscriptions', array('nickname' =>
+ $user->nickname)));
}
- }
+ }
}
diff --git a/_darcs/pristine/actions/subscribers.php b/_darcs/pristine/actions/subscribers.php
index ae52526e1..b9ca92af3 100644
--- a/_darcs/pristine/actions/subscribers.php
+++ b/_darcs/pristine/actions/subscribers.php
@@ -23,30 +23,30 @@ require_once(INSTALLDIR.'/lib/gallery.php');
class SubscribersAction extends GalleryAction {
- function gallery_type() {
- return _('Subscribers');
- }
-
- function get_instructions(&$profile) {
- $user =& common_current_user();
- if ($user && ($user->id == $profile->id)) {
- return _('These are the people who listen to your notices.');
- } else {
- return sprintf(_('These are the people who listen to %s\'s notices.'), $profile->nickname);
- }
- }
-
- function fields() {
- return array('subscriber', 'subscribed');
- }
-
- function div_class() {
- return 'subscribers';
- }
-
- function get_other(&$subs) {
- return $subs->subscriber;
- }
+ function gallery_type() {
+ return _('Subscribers');
+ }
+
+ function get_instructions(&$profile) {
+ $user =& common_current_user();
+ if ($user && ($user->id == $profile->id)) {
+ return _('These are the people who listen to your notices.');
+ } else {
+ return sprintf(_('These are the people who listen to %s\'s notices.'), $profile->nickname);
+ }
+ }
+
+ function fields() {
+ return array('subscriber', 'subscribed');
+ }
+
+ function div_class() {
+ return 'subscribers';
+ }
+
+ function get_other(&$subs) {
+ return $subs->subscriber;
+ }
function profile_list_class() {
return 'SubscribersList';
diff --git a/_darcs/pristine/actions/subscriptions.php b/_darcs/pristine/actions/subscriptions.php
index f518a1f92..c24f23a07 100644
--- a/_darcs/pristine/actions/subscriptions.php
+++ b/_darcs/pristine/actions/subscriptions.php
@@ -23,30 +23,30 @@ require_once(INSTALLDIR.'/lib/gallery.php');
class SubscriptionsAction extends GalleryAction {
- function gallery_type() {
- return _('Subscriptions');
- }
+ function gallery_type() {
+ return _('Subscriptions');
+ }
- function get_instructions(&$profile) {
- $user =& common_current_user();
- if ($user && ($user->id == $profile->id)) {
- return _('These are the people whose notices you listen to.');
- } else {
- return sprintf(_('These are the people whose notices %s listens to.'), $profile->nickname);
- }
- }
+ function get_instructions(&$profile) {
+ $user =& common_current_user();
+ if ($user && ($user->id == $profile->id)) {
+ return _('These are the people whose notices you listen to.');
+ } else {
+ return sprintf(_('These are the people whose notices %s listens to.'), $profile->nickname);
+ }
+ }
- function fields() {
- return array('subscribed', 'subscriber');
- }
+ function fields() {
+ return array('subscribed', 'subscriber');
+ }
- function div_class() {
- return 'subscriptions';
- }
+ function div_class() {
+ return 'subscriptions';
+ }
- function get_other(&$subs) {
- return $subs->subscribed;
- }
+ function get_other(&$subs) {
+ return $subs->subscribed;
+ }
function profile_list_class() {
return 'SubscriptionsList';
@@ -57,8 +57,8 @@ class SubscriptionsList extends ProfileList {
function show_owner_controls($profile) {
- $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
- 'subscribed' => $profile->id));
+ $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
+ 'subscribed' => $profile->id));
if (!$sub) {
return;
}
diff --git a/_darcs/pristine/actions/sup.php b/_darcs/pristine/actions/sup.php
index 887017b2a..3c9cbea2c 100644
--- a/_darcs/pristine/actions/sup.php
+++ b/_darcs/pristine/actions/sup.php
@@ -20,62 +20,62 @@
if (!defined('LACONICA')) { exit(1); }
class SupAction extends Action {
-
- function handle($args) {
-
- parent::handle($args);
-
- $seconds = $this->trimmed('seconds');
-
- if (!$seconds) {
- $seconds = 15;
- }
+
+ function handle($args) {
+
+ parent::handle($args);
+
+ $seconds = $this->trimmed('seconds');
+
+ if (!$seconds) {
+ $seconds = 15;
+ }
- $updates = $this->get_updates($seconds);
-
- header('Content-Type: application/json; charset=utf-8');
-
- print json_encode(array('updated_time' => date('c'),
- 'since_time' => date('c', time() - $seconds),
- 'available_periods' => $this->available_periods(),
- 'period' => $seconds,
- 'updates' => $updates));
- }
-
- function available_periods() {
- static $periods = array(86400, 43200, 21600, 7200,
- 3600, 1800, 600, 300, 120,
- 60, 30, 15);
- $available = array();
- foreach ($periods as $period) {
- $available[$period] = common_local_url('sup',
- array('seconds' => $period));
- }
-
- return $available;
- }
-
- function get_updates($seconds) {
- $notice = new Notice();
+ $updates = $this->get_updates($seconds);
+
+ header('Content-Type: application/json; charset=utf-8');
+
+ print json_encode(array('updated_time' => date('c'),
+ 'since_time' => date('c', time() - $seconds),
+ 'available_periods' => $this->available_periods(),
+ 'period' => $seconds,
+ 'updates' => $updates));
+ }
+
+ function available_periods() {
+ static $periods = array(86400, 43200, 21600, 7200,
+ 3600, 1800, 600, 300, 120,
+ 60, 30, 15);
+ $available = array();
+ foreach ($periods as $period) {
+ $available[$period] = common_local_url('sup',
+ array('seconds' => $period));
+ }
+
+ return $available;
+ }
+
+ function get_updates($seconds) {
+ $notice = new Notice();
- # XXX: cache this. Depends on how big this protocol becomes;
- # Re-doing this query every 15 seconds isn't the end of the world.
+ # XXX: cache this. Depends on how big this protocol becomes;
+ # Re-doing this query every 15 seconds isn't the end of the world.
- $notice->query('SELECT profile_id, max(id) AS max_id ' .
- 'FROM notice ' .
- 'WHERE created > (now() - ' . $seconds . ') ' .
- 'GROUP BY profile_id');
-
- $updates = array();
-
- while ($notice->fetch()) {
- $updates[] = array($notice->profile_id, $notice->max_id);
- }
-
- return $updates;
- }
-
- function is_readonly() {
- return true;
- }
+ $notice->query('SELECT profile_id, max(id) AS max_id ' .
+ 'FROM notice ' .
+ 'WHERE created > (now() - ' . $seconds . ') ' .
+ 'GROUP BY profile_id');
+
+ $updates = array();
+
+ while ($notice->fetch()) {
+ $updates[] = array($notice->profile_id, $notice->max_id);
+ }
+
+ return $updates;
+ }
+
+ function is_readonly() {
+ return true;
+ }
}
diff --git a/_darcs/pristine/actions/tag.php b/_darcs/pristine/actions/tag.php
index 25cc853c4..1325b85a5 100644
--- a/_darcs/pristine/actions/tag.php
+++ b/_darcs/pristine/actions/tag.php
@@ -24,142 +24,142 @@ define('TAGS_PER_PAGE', 100);
class TagAction extends StreamAction {
- function handle($args) {
-
- parent::handle($args);
-
- # Looks like we're good; show the header
-
- if (isset($args['tag']) && $args['tag']) {
- $tag = $args['tag'];
- common_show_header(sprintf(_("Notices tagged with %s"), $tag),
- array($this, 'show_header'), $tag,
- array($this, 'show_top'));
- $this->show_notices($tag);
- } else {
- common_show_header(_("Tags"),
- array($this, 'show_header'), '',
- array($this, 'show_top'));
- $this->show_tags();
- }
-
- common_show_footer();
- }
-
- function show_header($tag = false) {
- if ($tag) {
- common_element('link', array('rel' => 'alternate',
- 'href' => common_local_url('tagrss', array('tag' => $tag)),
- 'type' => 'application/rss+xml',
- 'title' => sprintf(_('Feed for tag %s'), $tag)));
- }
- }
-
- function get_instructions() {
- return _('Showing most popular tags from the last week');
- }
-
- function show_top($tag = false) {
- if (!$tag) {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- $this->public_views_menu();
- }
- else {
- $this->show_feeds_list(array(0=>array('href'=>common_local_url('tagrss'),
- 'type' => 'rss',
- 'version' => 'RSS 1.0',
- 'item' => 'tagrss')));
- }
- }
-
- function show_tags()
- {
- # This should probably be cached rather than recalculated
- $tags = DB_DataObject::factory('Notice_tag');
-
- #Need to clear the selection and then only re-add the field
- #we are grouping by, otherwise it's not a valid 'group by'
- #even though MySQL seems to let it slide...
- $tags->selectAdd();
- $tags->selectAdd('tag');
-
- #Add the aggregated columns...
- $tags->selectAdd('max(notice_id) as last_notice_id');
- if(common_config('db','type')=='pgsql') {
- $calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight';
- } else {
- $calc='sum(exp(-(now() - created)/%s)) as weight';
- }
- $tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff')));
- $tags->groupBy('tag');
- $tags->orderBy('weight DESC');
-
- # $tags->whereAdd('created > "' . strftime('%Y-%m-%d %H:%M:%S', strtotime('-1 MONTH')) . '"');
-
- $tags->limit(TAGS_PER_PAGE);
-
- $cnt = $tags->find();
-
- if ($cnt > 0) {
- common_element_start('p', 'tagcloud');
-
- $tw = array();
- $sum = 0;
- while ($tags->fetch()) {
- $tw[$tags->tag] = $tags->weight;
- $sum += $tags->weight;
- }
-
- ksort($tw);
-
- foreach ($tw as $tag => $weight) {
- $this->show_tag($tag, $weight, $weight/$sum);
- }
-
- common_element_end('p');
- }
- }
-
- function show_tag($tag, $weight, $relative) {
-
- # XXX: these should probably tune to the size of the site
- if ($relative > 0.1) {
- $cls = 'largest';
- } else if ($relative > 0.05) {
- $cls = 'verylarge';
- } else if ($relative > 0.02) {
- $cls = 'large';
- } else if ($relative > 0.01) {
- $cls = 'medium';
- } else if ($relative > 0.005) {
- $cls = 'small';
- } else if ($relative > 0.002) {
- $cls = 'verysmall';
- } else {
- $cls = 'smallest';
- }
-
- common_element('a', array('class' => "$cls weight-$weight relative-$relative",
- 'href' => common_local_url('tag', array('tag' => $tag))),
- $tag);
- common_text(' ');
- }
-
- function show_notices($tag) {
-
- $cnt = 0;
-
- $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
-
- $notice = Notice_tag::getStream($tag, (($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
+ function handle($args) {
+
+ parent::handle($args);
+
+ # Looks like we're good; show the header
+
+ if (isset($args['tag']) && $args['tag']) {
+ $tag = $args['tag'];
+ common_show_header(sprintf(_("Notices tagged with %s"), $tag),
+ array($this, 'show_header'), $tag,
+ array($this, 'show_top'));
+ $this->show_notices($tag);
+ } else {
+ common_show_header(_("Tags"),
+ array($this, 'show_header'), '',
+ array($this, 'show_top'));
+ $this->show_tags();
+ }
+
+ common_show_footer();
+ }
+
+ function show_header($tag = false) {
+ if ($tag) {
+ common_element('link', array('rel' => 'alternate',
+ 'href' => common_local_url('tagrss', array('tag' => $tag)),
+ 'type' => 'application/rss+xml',
+ 'title' => sprintf(_('Feed for tag %s'), $tag)));
+ }
+ }
+
+ function get_instructions() {
+ return _('Showing most popular tags from the last week');
+ }
+
+ function show_top($tag = false) {
+ if (!$tag) {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ $this->public_views_menu();
+ }
+ else {
+ $this->show_feeds_list(array(0=>array('href'=>common_local_url('tagrss'),
+ 'type' => 'rss',
+ 'version' => 'RSS 1.0',
+ 'item' => 'tagrss')));
+ }
+ }
+
+ function show_tags()
+ {
+ # This should probably be cached rather than recalculated
+ $tags = DB_DataObject::factory('Notice_tag');
+
+ #Need to clear the selection and then only re-add the field
+ #we are grouping by, otherwise it's not a valid 'group by'
+ #even though MySQL seems to let it slide...
+ $tags->selectAdd();
+ $tags->selectAdd('tag');
+
+ #Add the aggregated columns...
+ $tags->selectAdd('max(notice_id) as last_notice_id');
+ if(common_config('db','type')=='pgsql') {
+ $calc='sum(exp(-extract(epoch from (now()-created))/%s)) as weight';
+ } else {
+ $calc='sum(exp(-(now() - created)/%s)) as weight';
+ }
+ $tags->selectAdd(sprintf($calc, common_config('tag', 'dropoff')));
+ $tags->groupBy('tag');
+ $tags->orderBy('weight DESC');
+
+ # $tags->whereAdd('created > "' . strftime('%Y-%m-%d %H:%M:%S', strtotime('-1 MONTH')) . '"');
+
+ $tags->limit(TAGS_PER_PAGE);
+
+ $cnt = $tags->find();
+
+ if ($cnt > 0) {
+ common_element_start('p', 'tagcloud');
+
+ $tw = array();
+ $sum = 0;
+ while ($tags->fetch()) {
+ $tw[$tags->tag] = $tags->weight;
+ $sum += $tags->weight;
+ }
+
+ ksort($tw);
+
+ foreach ($tw as $tag => $weight) {
+ $this->show_tag($tag, $weight, $weight/$sum);
+ }
+
+ common_element_end('p');
+ }
+ }
+
+ function show_tag($tag, $weight, $relative) {
+
+ # XXX: these should probably tune to the size of the site
+ if ($relative > 0.1) {
+ $cls = 'largest';
+ } else if ($relative > 0.05) {
+ $cls = 'verylarge';
+ } else if ($relative > 0.02) {
+ $cls = 'large';
+ } else if ($relative > 0.01) {
+ $cls = 'medium';
+ } else if ($relative > 0.005) {
+ $cls = 'small';
+ } else if ($relative > 0.002) {
+ $cls = 'verysmall';
+ } else {
+ $cls = 'smallest';
+ }
+
+ common_element('a', array('class' => "$cls weight-$weight relative-$relative",
+ 'href' => common_local_url('tag', array('tag' => $tag))),
+ $tag);
+ common_text(' ');
+ }
+
+ function show_notices($tag) {
+
+ $cnt = 0;
+
+ $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
+
+ $notice = Notice_tag::getStream($tag, (($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
$cnt = $this->show_notice_list($notice);
- common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
- $page, 'tag', array('tag' => $tag));
- }
+ common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
+ $page, 'tag', array('tag' => $tag));
+ }
}
diff --git a/_darcs/pristine/actions/tagother.php b/_darcs/pristine/actions/tagother.php
index a4449dd69..832671ae7 100644
--- a/_darcs/pristine/actions/tagother.php
+++ b/_darcs/pristine/actions/tagother.php
@@ -23,171 +23,171 @@ require_once(INSTALLDIR.'/lib/settingsaction.php');
class TagotherAction extends Action {
- function handle($args) {
-
- parent::handle($args);
-
- if (!common_logged_in()) {
- $this->client_error(_('Not logged in'), 403);
- return;
- }
-
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->save_tags();
- } else {
- $id = $this->trimmed('id');
- if (!$id) {
- $this->client_error(_('No id argument.'));
- return;
- }
- $profile = Profile::staticGet('id', $id);
- if (!$profile) {
- $this->client_error(_('No profile with that ID.'));
- return;
- }
- $this->show_form($profile);
- }
- }
-
- function show_form($profile, $error=NULL) {
-
- $user = common_current_user();
-
- common_show_header(_('Tag a person'),
- NULL, array($profile, $error), array($this, 'show_top'));
-
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
-
- common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
- 'class' => 'avatar stream',
- 'width' => AVATAR_PROFILE_SIZE,
- 'height' => AVATAR_PROFILE_SIZE,
- 'alt' =>
- ($profile->fullname) ? $profile->fullname :
- $profile->nickname));
-
- common_element('a', array('href' => $profile->profileurl,
- 'class' => 'external profile nickname'),
- $profile->nickname);
-
- if ($profile->fullname) {
- common_element_start('div', 'fullname');
- if ($profile->homepage) {
- common_element('a', array('href' => $profile->homepage),
- $profile->fullname);
- } else {
- common_text($profile->fullname);
- }
- common_element_end('div');
- }
- if ($profile->location) {
- common_element('div', 'location', $profile->location);
- }
- if ($profile->bio) {
- common_element('div', 'bio', $profile->bio);
- }
-
- common_element_start('form', array('method' => 'post',
- 'id' => 'tag_user',
- 'name' => 'tagother',
- 'action' => $this->self_url()));
- common_hidden('token', common_session_token());
- common_hidden('id', $profile->id);
- common_input('tags', _('Tags'),
- ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $profile->id)),
- _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
-
- common_submit('save', _('Save'));
- common_element_end('form');
- common_show_footer();
-
- }
-
- function save_tags() {
-
- $id = $this->trimmed('id');
- $tagstring = $this->trimmed('tags');
- $token = $this->trimmed('token');
-
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- $profile = Profile::staticGet('id', $id);
-
- if (!$profile) {
- $this->client_error(_('No such profile.'));
- return;
- }
-
- if (is_string($tagstring) && strlen($tagstring) > 0) {
-
- $tags = array_map('common_canonical_tag',
- preg_split('/[\s,]+/', $tagstring));
-
- foreach ($tags as $tag) {
- if (!common_valid_profile_tag($tag)) {
- $this->show_form($profile, sprintf(_('Invalid tag: "%s"'), $tag));
- return;
- }
- }
- } else {
- $tags = array();
- }
-
- $user = common_current_user();
-
- if (!Subscription::pkeyGet(array('subscriber' => $user->id,
- 'subscribed' => $profile->id)) &&
- !Subscription::pkeyGet(array('subscriber' => $profile->id,
- 'subscribed' => $user->id)))
- {
- $this->client_error(_('You can only tag people you are subscribed to or who are subscribed to you.'));
- return;
- }
-
- $result = Profile_tag::setTags($user->id, $profile->id, $tags);
-
- if (!$result) {
- $this->client_error(_('Could not save tags.'));
- return;
- }
-
- $action = $user->isSubscribed($profile) ? 'subscriptions' : 'subscribers';
-
- if ($this->boolean('ajax')) {
- common_start_html('text/xml');
- common_element_start('head');
- common_element('title', null, _('Tags'));
- common_element_end('head');
- common_element_start('body');
- common_element_start('p', 'subtags');
- foreach ($tags as $tag) {
- common_element('a', array('href' => common_local_url($action,
- array('nickname' => $user->nickname,
- 'tag' => $tag))),
- $tag);
- }
- common_element_end('p');
- common_element_end('body');
- common_element_end('html');
- } else {
- common_redirect(common_local_url($action, array('nickname' =>
- $user->nickname)));
+ function handle($args) {
+
+ parent::handle($args);
+
+ if (!common_logged_in()) {
+ $this->client_error(_('Not logged in'), 403);
+ return;
+ }
+
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ $this->save_tags();
+ } else {
+ $id = $this->trimmed('id');
+ if (!$id) {
+ $this->client_error(_('No id argument.'));
+ return;
+ }
+ $profile = Profile::staticGet('id', $id);
+ if (!$profile) {
+ $this->client_error(_('No profile with that ID.'));
+ return;
+ }
+ $this->show_form($profile);
+ }
+ }
+
+ function show_form($profile, $error=NULL) {
+
+ $user = common_current_user();
+
+ common_show_header(_('Tag a person'),
+ NULL, array($profile, $error), array($this, 'show_top'));
+
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+
+ common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
+ 'class' => 'avatar stream',
+ 'width' => AVATAR_PROFILE_SIZE,
+ 'height' => AVATAR_PROFILE_SIZE,
+ 'alt' =>
+ ($profile->fullname) ? $profile->fullname :
+ $profile->nickname));
+
+ common_element('a', array('href' => $profile->profileurl,
+ 'class' => 'external profile nickname'),
+ $profile->nickname);
+
+ if ($profile->fullname) {
+ common_element_start('div', 'fullname');
+ if ($profile->homepage) {
+ common_element('a', array('href' => $profile->homepage),
+ $profile->fullname);
+ } else {
+ common_text($profile->fullname);
+ }
+ common_element_end('div');
+ }
+ if ($profile->location) {
+ common_element('div', 'location', $profile->location);
+ }
+ if ($profile->bio) {
+ common_element('div', 'bio', $profile->bio);
+ }
+
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'tag_user',
+ 'name' => 'tagother',
+ 'action' => $this->self_url()));
+ common_hidden('token', common_session_token());
+ common_hidden('id', $profile->id);
+ common_input('tags', _('Tags'),
+ ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $profile->id)),
+ _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
+
+ common_submit('save', _('Save'));
+ common_element_end('form');
+ common_show_footer();
+
+ }
+
+ function save_tags() {
+
+ $id = $this->trimmed('id');
+ $tagstring = $this->trimmed('tags');
+ $token = $this->trimmed('token');
+
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ $profile = Profile::staticGet('id', $id);
+
+ if (!$profile) {
+ $this->client_error(_('No such profile.'));
+ return;
+ }
+
+ if (is_string($tagstring) && strlen($tagstring) > 0) {
+
+ $tags = array_map('common_canonical_tag',
+ preg_split('/[\s,]+/', $tagstring));
+
+ foreach ($tags as $tag) {
+ if (!common_valid_profile_tag($tag)) {
+ $this->show_form($profile, sprintf(_('Invalid tag: "%s"'), $tag));
+ return;
+ }
+ }
+ } else {
+ $tags = array();
+ }
+
+ $user = common_current_user();
+
+ if (!Subscription::pkeyGet(array('subscriber' => $user->id,
+ 'subscribed' => $profile->id)) &&
+ !Subscription::pkeyGet(array('subscriber' => $profile->id,
+ 'subscribed' => $user->id)))
+ {
+ $this->client_error(_('You can only tag people you are subscribed to or who are subscribed to you.'));
+ return;
+ }
+
+ $result = Profile_tag::setTags($user->id, $profile->id, $tags);
+
+ if (!$result) {
+ $this->client_error(_('Could not save tags.'));
+ return;
+ }
+
+ $action = $user->isSubscribed($profile) ? 'subscriptions' : 'subscribers';
+
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml');
+ common_element_start('head');
+ common_element('title', null, _('Tags'));
+ common_element_end('head');
+ common_element_start('body');
+ common_element_start('p', 'subtags');
+ foreach ($tags as $tag) {
+ common_element('a', array('href' => common_local_url($action,
+ array('nickname' => $user->nickname,
+ 'tag' => $tag))),
+ $tag);
+ }
+ common_element_end('p');
+ common_element_end('body');
+ common_element_end('html');
+ } else {
+ common_redirect(common_local_url($action, array('nickname' =>
+ $user->nickname)));
+ }
+ }
+
+ function show_top($arr = NULL) {
+ list($profile, $error) = $arr;
+ if ($error) {
+ common_element('p', 'error', $error);
+ } else {
+ common_element_start('div', 'instructions');
+ common_element('p', NULL,
+ _('Use this form to add tags to your subscribers or subscriptions.'));
+ common_element_end('div');
}
- }
-
- function show_top($arr = NULL) {
- list($profile, $error) = $arr;
- if ($error) {
- common_element('p', 'error', $error);
- } else {
- common_element_start('div', 'instructions');
- common_element('p', NULL,
- _('Use this form to add tags to your subscribers or subscriptions.'));
- common_element_end('div');
- }
- }
+ }
}
diff --git a/_darcs/pristine/actions/tagrss.php b/_darcs/pristine/actions/tagrss.php
index 9187bdc87..45639fec4 100644
--- a/_darcs/pristine/actions/tagrss.php
+++ b/_darcs/pristine/actions/tagrss.php
@@ -25,41 +25,41 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class TagrssAction extends Rss10Action {
- function init() {
- $tag = $this->trimmed('tag');
- $this->tag = Notice_tag::staticGet('tag', $tag);
+ function init() {
+ $tag = $this->trimmed('tag');
+ $this->tag = Notice_tag::staticGet('tag', $tag);
- if (!$this->tag) {
- common_user_error(_('No such tag.'));
- return false;
- } else {
- return true;
- }
- }
+ if (!$this->tag) {
+ common_user_error(_('No such tag.'));
+ return false;
+ } else {
+ return true;
+ }
+ }
- function get_notices($limit=0) {
- $tag = $this->tag;
+ function get_notices($limit=0) {
+ $tag = $this->tag;
- if (is_null($tag)) {
- return NULL;
- }
+ if (is_null($tag)) {
+ return NULL;
+ }
- $notice = Notice_tag::getStream($tag->tag, 0, ($limit == 0) ? NOTICES_PER_PAGE : $limit);
+ $notice = Notice_tag::getStream($tag->tag, 0, ($limit == 0) ? NOTICES_PER_PAGE : $limit);
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
- return $notices;
- }
+ return $notices;
+ }
- function get_channel() {
- $tag = $this->tag->tag;
+ function get_channel() {
+ $tag = $this->tag->tag;
- $c = array('url' => common_local_url('tagrss', array('tag' => $tagname)),
- 'title' => $tagname,
- 'link' => common_local_url('tagrss', array('tag' => $tagname)),
- 'description' => sprintf(_('Microblog tagged with %s'), $tagname));
- return $c;
- }
+ $c = array('url' => common_local_url('tagrss', array('tag' => $tagname)),
+ 'title' => $tagname,
+ 'link' => common_local_url('tagrss', array('tag' => $tagname)),
+ 'description' => sprintf(_('Microblog tagged with %s'), $tagname));
+ return $c;
+ }
}
diff --git a/_darcs/pristine/actions/twitapiaccount.php b/_darcs/pristine/actions/twitapiaccount.php
index f6e955828..b1caa3481 100644
--- a/_darcs/pristine/actions/twitapiaccount.php
+++ b/_darcs/pristine/actions/twitapiaccount.php
@@ -23,74 +23,74 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiaccountAction extends TwitterapiAction {
- function verify_credentials($args, $apidata) {
- parent::handle($args);
+ function verify_credentials($args, $apidata) {
+ parent::handle($args);
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
- $this->show_extended_profile($apidata['user'], $apidata);
- }
+ $this->show_extended_profile($apidata['user'], $apidata);
+ }
- function end_session($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ function end_session($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
- function update_location($args, $apidata) {
- parent::handle($args);
+ function update_location($args, $apidata) {
+ parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
- return;
- }
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+ return;
+ }
- $location = trim($this->arg('location'));
+ $location = trim($this->arg('location'));
- if (!is_null($location) && strlen($location) > 255) {
+ if (!is_null($location) && strlen($location) > 255) {
- // XXX: But Twitter just truncates and runs with it. -- Zach
- $this->client_error(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']);
- return;
- }
+ // XXX: But Twitter just truncates and runs with it. -- Zach
+ $this->client_error(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']);
+ return;
+ }
- $user = $apidata['user'];
- $profile = $user->getProfile();
+ $user = $apidata['user'];
+ $profile = $user->getProfile();
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
- $orig_profile = clone($profile);
- $profile->location = $location;
+ $orig_profile = clone($profile);
+ $profile->location = $location;
- $result = $profile->update($orig_profile);
+ $result = $profile->update($orig_profile);
- if (!$result) {
- common_log_db_error($profile, 'UPDATE', __FILE__);
- common_server_error(_('Couldn\'t save profile.'));
- return;
- }
+ if (!$result) {
+ common_log_db_error($profile, 'UPDATE', __FILE__);
+ common_server_error(_('Couldn\'t save profile.'));
+ return;
+ }
- common_broadcast_profile($profile);
- $type = $apidata['content-type'];
+ common_broadcast_profile($profile);
+ $type = $apidata['content-type'];
- $this->init_document($type);
- $this->show_profile($profile, $type);
- $this->end_document($type);
- }
+ $this->init_document($type);
+ $this->show_profile($profile, $type);
+ $this->end_document($type);
+ }
- function update_delivery_device($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ function update_delivery_device($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
- function rate_limit_status($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ function rate_limit_status($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/twitapiblocks.php b/_darcs/pristine/actions/twitapiblocks.php
index 4852ff938..16b2e76bc 100644
--- a/_darcs/pristine/actions/twitapiblocks.php
+++ b/_darcs/pristine/actions/twitapiblocks.php
@@ -23,15 +23,15 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiblocksAction extends TwitterapiAction {
- function create($args, $apidata) {
+ function create($args, $apidata) {
- parent::handle($args);
+ parent::handle($args);
- $blockee = $this->get_user($apidata['api_arg'], $apidata);
+ $blockee = $this->get_user($apidata['api_arg'], $apidata);
if (!$blockee) {
- $this->client_error('Not Found', 404, $apidata['content-type']);
- return;
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
}
$user = $apidata['user'];
@@ -42,17 +42,17 @@ class TwitapiblocksAction extends TwitterapiAction {
$this->show_profile($blockee, $type);
$this->end_document($type);
} else {
- common_server_error(_('Block user failed.'));
+ common_server_error(_('Block user failed.'));
}
- }
+ }
- function destroy($args, $apidata) {
- parent::handle($args);
- $blockee = $this->get_user($apidata['api_arg'], $apidata);
+ function destroy($args, $apidata) {
+ parent::handle($args);
+ $blockee = $this->get_user($apidata['api_arg'], $apidata);
if (!$blockee) {
- $this->client_error('Not Found', 404, $apidata['content-type']);
- return;
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
}
$user = $apidata['user'];
@@ -63,7 +63,7 @@ class TwitapiblocksAction extends TwitterapiAction {
$this->show_profile($blockee, $type);
$this->end_document($type);
} else {
- common_server_error(_('Unblock user failed.'));
+ common_server_error(_('Unblock user failed.'));
}
- }
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/twitapidirect_messages.php b/_darcs/pristine/actions/twitapidirect_messages.php
index 535795ca4..2e3b50173 100644
--- a/_darcs/pristine/actions/twitapidirect_messages.php
+++ b/_darcs/pristine/actions/twitapidirect_messages.php
@@ -23,265 +23,265 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class Twitapidirect_messagesAction extends TwitterapiAction {
- function direct_messages($args, $apidata) {
- parent::handle($args);
- return $this->show_messages($args, $apidata, 'received');
- }
-
- function sent($args, $apidata) {
- parent::handle($args);
- return $this->show_messages($args, $apidata, 'sent');
- }
-
- function show_messages($args, $apidata, $type) {
-
- $user = $apidata['user'];
-
- $count = $this->arg('count');
- $since = $this->arg('since');
- $since_id = $this->arg('since_id');
- $before_id = $this->arg('before_id');
-
- $page = $this->arg('page');
-
- if (!$page) {
- $page = 1;
- }
-
- if (!$count) {
- $count = 20;
- }
-
- $message = new Message();
-
- $title = null;
- $subtitle = null;
- $link = null;
- $server = common_root_url();
-
- if ($type == 'received') {
- $message->to_profile = $user->id;
- $title = sprintf(_("Direct messages to %s"), $user->nickname);
- $subtitle = sprintf(_("All the direct messages sent to %s"), $user->nickname);
- $link = $server . $user->nickname . '/inbox';
- } else {
- $message->from_profile = $user->id;
- $title = _('Direct Messages You\'ve Sent');
- $subtitle = sprintf(_("All the direct messages sent from %s"), $user->nickname);
- $link = $server . $user->nickname . '/outbox';
- }
-
- if ($before_id) {
- $message->whereAdd("id < $before_id");
- }
-
- if ($since_id) {
- $message->whereAdd("id > $since_id");
- }
-
- $since = strtotime($this->arg('since'));
-
- if ($since) {
- $d = date('Y-m-d H:i:s', $since);
- $message->whereAdd("created > '$d'");
- }
-
- $message->orderBy('created DESC, id DESC');
- $message->limit((($page-1)*20), $count);
- $message->find();
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_dmsgs($message);
- break;
- case 'rss':
- $this->show_rss_dmsgs($message, $title, $link, $subtitle);
- break;
- case 'atom':
- $this->show_atom_dmsgs($message, $title, $link, $subtitle);
- break;
- case 'json':
- $this->show_json_dmsgs($message);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- }
-
- }
-
- // had to change this from "new" to "create" to avoid PHP reserved word
- function create($args, $apidata) {
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
- return;
- }
-
- $user = $apidata['user'];
- $source = $this->trimmed('source'); // Not supported by Twitter.
+ function direct_messages($args, $apidata) {
+ parent::handle($args);
+ return $this->show_messages($args, $apidata, 'received');
+ }
+
+ function sent($args, $apidata) {
+ parent::handle($args);
+ return $this->show_messages($args, $apidata, 'sent');
+ }
+
+ function show_messages($args, $apidata, $type) {
+
+ $user = $apidata['user'];
+
+ $count = $this->arg('count');
+ $since = $this->arg('since');
+ $since_id = $this->arg('since_id');
+ $before_id = $this->arg('before_id');
+
+ $page = $this->arg('page');
+
+ if (!$page) {
+ $page = 1;
+ }
+
+ if (!$count) {
+ $count = 20;
+ }
+
+ $message = new Message();
+
+ $title = null;
+ $subtitle = null;
+ $link = null;
+ $server = common_root_url();
+
+ if ($type == 'received') {
+ $message->to_profile = $user->id;
+ $title = sprintf(_("Direct messages to %s"), $user->nickname);
+ $subtitle = sprintf(_("All the direct messages sent to %s"), $user->nickname);
+ $link = $server . $user->nickname . '/inbox';
+ } else {
+ $message->from_profile = $user->id;
+ $title = _('Direct Messages You\'ve Sent');
+ $subtitle = sprintf(_("All the direct messages sent from %s"), $user->nickname);
+ $link = $server . $user->nickname . '/outbox';
+ }
+
+ if ($before_id) {
+ $message->whereAdd("id < $before_id");
+ }
+
+ if ($since_id) {
+ $message->whereAdd("id > $since_id");
+ }
+
+ $since = strtotime($this->arg('since'));
+
+ if ($since) {
+ $d = date('Y-m-d H:i:s', $since);
+ $message->whereAdd("created > '$d'");
+ }
+
+ $message->orderBy('created DESC, id DESC');
+ $message->limit((($page-1)*20), $count);
+ $message->find();
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_xml_dmsgs($message);
+ break;
+ case 'rss':
+ $this->show_rss_dmsgs($message, $title, $link, $subtitle);
+ break;
+ case 'atom':
+ $this->show_atom_dmsgs($message, $title, $link, $subtitle);
+ break;
+ case 'json':
+ $this->show_json_dmsgs($message);
+ break;
+ default:
+ common_user_error(_('API method not found!'), $code = 404);
+ }
+
+ }
+
+ // had to change this from "new" to "create" to avoid PHP reserved word
+ function create($args, $apidata) {
+ parent::handle($args);
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+ return;
+ }
+
+ $user = $apidata['user'];
+ $source = $this->trimmed('source'); // Not supported by Twitter.
$reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
- if (!$source || in_array($source, $reserved_sources)) {
- $source = 'api';
- }
-
- $content = $this->trimmed('text');
-
- if (!$content) {
- $this->client_error(_('No message text!'), $code = 406, $apidata['content-type']);
- } else {
- $content_shortened = common_shorten_links($content);
- if (mb_strlen($content_shortened) > 140) {
- $this->client_error(_('That\'s too long. Max message size is 140 chars.'),
- $code = 406, $apidata['content-type']);
- return;
- }
- }
-
- $other = $this->get_user($this->trimmed('user'));
-
- if (!$other) {
- $this->client_error(_('Recipient user not found.'), $code = 403, $apidata['content-type']);
- return;
- } else if (!$user->mutuallySubscribed($other)) {
- $this->client_error(_('Can\'t send direct messages to users who aren\'t your friend.'),
- $code = 403, $apidata['content-type']);
- return;
- } else if ($user->id == $other->id) {
- // Sending msgs to yourself is allowed by Twitter
- $this->client_error(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'),
- $code = 403, $apidata['content-type']);
- return;
- }
-
- $message = Message::saveNew($user->id, $other->id,
- html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
-
- if (is_string($message)) {
- $this->server_error($message);
- return;
- }
-
- $this->notify($user, $other, $message);
-
- if ($apidata['content-type'] == 'xml') {
- $this->show_single_xml_dmsg($message);
- } elseif ($apidata['content-type'] == 'json') {
- $this->show_single_json_dmsg($message);
- }
-
- }
-
- function destroy($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
-
- function show_xml_dmsgs($message) {
-
- $this->init_document('xml');
- common_element_start('direct-messages', array('type' => 'array'));
-
- if (is_array($messages)) {
- foreach ($message as $m) {
- $twitter_dm = $this->twitter_dmsg_array($m);
- $this->show_twitter_xml_dmsg($twitter_dm);
- }
- } else {
- while ($message->fetch()) {
- $twitter_dm = $this->twitter_dmsg_array($message);
- $this->show_twitter_xml_dmsg($twitter_dm);
- }
- }
-
- common_element_end('direct-messages');
- $this->end_document('xml');
-
- }
-
- function show_json_dmsgs($message) {
-
- $this->init_document('json');
-
- $dmsgs = array();
-
- if (is_array($message)) {
- foreach ($message as $m) {
- $twitter_dm = $this->twitter_dmsg_array($m);
- array_push($dmsgs, $twitter_dm);
- }
- } else {
- while ($message->fetch()) {
- $twitter_dm = $this->twitter_dmsg_array($message);
- array_push($dmsgs, $twitter_dm);
- }
- }
-
- $this->show_json_objects($dmsgs);
- $this->end_document('json');
-
- }
-
- function show_rss_dmsgs($message, $title, $link, $subtitle) {
-
- $this->init_document('rss');
-
- common_element_start('channel');
- common_element('title', NULL, $title);
-
- common_element('link', NULL, $link);
- common_element('description', NULL, $subtitle);
- common_element('language', NULL, 'en-us');
- common_element('ttl', NULL, '40');
-
- if (is_array($message)) {
- foreach ($message as $m) {
- $entry = $this->twitter_rss_dmsg_array($m);
- $this->show_twitter_rss_item($entry);
- }
- } else {
- while ($message->fetch()) {
- $entry = $this->twitter_rss_dmsg_array($message);
- $this->show_twitter_rss_item($entry);
- }
- }
-
- common_element_end('channel');
- $this->end_twitter_rss();
-
- }
-
- function show_atom_dmsgs($message, $title, $link, $subtitle) {
-
- $this->init_document('atom');
-
- common_element('title', NULL, $title);
- $siteserver = common_config('site', 'server');
- common_element('id', NULL, "tag:$siteserver,2008:DirectMessage");
- common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
- common_element('updated', NULL, common_date_iso8601(strftime('%c')));
- common_element('subtitle', NULL, $subtitle);
-
- if (is_array($message)) {
- foreach ($message as $m) {
- $entry = $this->twitter_rss_dmsg_array($m);
- $this->show_twitter_atom_entry($entry);
- }
- } else {
- while ($message->fetch()) {
- $entry = $this->twitter_rss_dmsg_array($message);
- $this->show_twitter_atom_entry($entry);
- }
- }
-
- $this->end_document('atom');
- }
-
- // swiped from MessageAction. Should it be place in util.php?
- function notify($from, $to, $message) {
- mail_notify_message($message, $from, $to);
- # XXX: Jabber, SMS notifications... probably queued
- }
+ if (!$source || in_array($source, $reserved_sources)) {
+ $source = 'api';
+ }
+
+ $content = $this->trimmed('text');
+
+ if (!$content) {
+ $this->client_error(_('No message text!'), $code = 406, $apidata['content-type']);
+ } else {
+ $content_shortened = common_shorten_links($content);
+ if (mb_strlen($content_shortened) > 140) {
+ $this->client_error(_('That\'s too long. Max message size is 140 chars.'),
+ $code = 406, $apidata['content-type']);
+ return;
+ }
+ }
+
+ $other = $this->get_user($this->trimmed('user'));
+
+ if (!$other) {
+ $this->client_error(_('Recipient user not found.'), $code = 403, $apidata['content-type']);
+ return;
+ } else if (!$user->mutuallySubscribed($other)) {
+ $this->client_error(_('Can\'t send direct messages to users who aren\'t your friend.'),
+ $code = 403, $apidata['content-type']);
+ return;
+ } else if ($user->id == $other->id) {
+ // Sending msgs to yourself is allowed by Twitter
+ $this->client_error(_('Don\'t send a message to yourself; just say it to yourself quietly instead.'),
+ $code = 403, $apidata['content-type']);
+ return;
+ }
+
+ $message = Message::saveNew($user->id, $other->id,
+ html_entity_decode($content, ENT_NOQUOTES, 'UTF-8'), $source);
+
+ if (is_string($message)) {
+ $this->server_error($message);
+ return;
+ }
+
+ $this->notify($user, $other, $message);
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->show_single_xml_dmsg($message);
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->show_single_json_dmsg($message);
+ }
+
+ }
+
+ function destroy($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
+
+ function show_xml_dmsgs($message) {
+
+ $this->init_document('xml');
+ common_element_start('direct-messages', array('type' => 'array'));
+
+ if (is_array($messages)) {
+ foreach ($message as $m) {
+ $twitter_dm = $this->twitter_dmsg_array($m);
+ $this->show_twitter_xml_dmsg($twitter_dm);
+ }
+ } else {
+ while ($message->fetch()) {
+ $twitter_dm = $this->twitter_dmsg_array($message);
+ $this->show_twitter_xml_dmsg($twitter_dm);
+ }
+ }
+
+ common_element_end('direct-messages');
+ $this->end_document('xml');
+
+ }
+
+ function show_json_dmsgs($message) {
+
+ $this->init_document('json');
+
+ $dmsgs = array();
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $twitter_dm = $this->twitter_dmsg_array($m);
+ array_push($dmsgs, $twitter_dm);
+ }
+ } else {
+ while ($message->fetch()) {
+ $twitter_dm = $this->twitter_dmsg_array($message);
+ array_push($dmsgs, $twitter_dm);
+ }
+ }
+
+ $this->show_json_objects($dmsgs);
+ $this->end_document('json');
+
+ }
+
+ function show_rss_dmsgs($message, $title, $link, $subtitle) {
+
+ $this->init_document('rss');
+
+ common_element_start('channel');
+ common_element('title', NULL, $title);
+
+ common_element('link', NULL, $link);
+ common_element('description', NULL, $subtitle);
+ common_element('language', NULL, 'en-us');
+ common_element('ttl', NULL, '40');
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $entry = $this->twitter_rss_dmsg_array($m);
+ $this->show_twitter_rss_item($entry);
+ }
+ } else {
+ while ($message->fetch()) {
+ $entry = $this->twitter_rss_dmsg_array($message);
+ $this->show_twitter_rss_item($entry);
+ }
+ }
+
+ common_element_end('channel');
+ $this->end_twitter_rss();
+
+ }
+
+ function show_atom_dmsgs($message, $title, $link, $subtitle) {
+
+ $this->init_document('atom');
+
+ common_element('title', NULL, $title);
+ $siteserver = common_config('site', 'server');
+ common_element('id', NULL, "tag:$siteserver,2008:DirectMessage");
+ common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ common_element('updated', NULL, common_date_iso8601(strftime('%c')));
+ common_element('subtitle', NULL, $subtitle);
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $entry = $this->twitter_rss_dmsg_array($m);
+ $this->show_twitter_atom_entry($entry);
+ }
+ } else {
+ while ($message->fetch()) {
+ $entry = $this->twitter_rss_dmsg_array($message);
+ $this->show_twitter_atom_entry($entry);
+ }
+ }
+
+ $this->end_document('atom');
+ }
+
+ // swiped from MessageAction. Should it be place in util.php?
+ function notify($from, $to, $message) {
+ mail_notify_message($message, $from, $to);
+ # XXX: Jabber, SMS notifications... probably queued
+ }
}
diff --git a/_darcs/pristine/actions/twitapifavorites.php b/_darcs/pristine/actions/twitapifavorites.php
index 3eaff327a..ad8c5f18b 100644
--- a/_darcs/pristine/actions/twitapifavorites.php
+++ b/_darcs/pristine/actions/twitapifavorites.php
@@ -23,153 +23,153 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapifavoritesAction extends TwitterapiAction {
- function favorites($args, $apidata) {
- parent::handle($args);
-
- $this->auth_user = $apidata['user'];
- $user = $this->get_user($apidata['api_arg'], $apidata);
-
- if (!$user) {
- $this->client_error('Not Found', 404, $apidata['content-type']);
- return;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $page = $this->arg('page');
-
- if (!$page) {
- $page = 1;
- }
-
- if (!$count) {
- $count = 20;
- }
-
- $notice = $user->favoriteNotices((($page-1)*20), $count);
-
- if (!$notice) {
- common_server_error(_('Could not retrieve favorite notices.'));
- return;
- }
-
- $sitename = common_config('site', 'name');
- $siteserver = common_config('site', 'server');
-
- $title = sprintf(_('%s / Favorites from %s'), $sitename, $user->nickname);
- $id = "tag:$siteserver:favorites:".$user->id;
- $link = common_local_url('favorites', array('nickname' => $user->nickname));
- $subtitle = sprintf(_('%s updates favorited by %s / %s.'), $sitename, $profile->getBestName(), $user->nickname);
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_timeline($notice);
- break;
- case 'rss':
- $this->show_rss_timeline($notice, $title, $link, $subtitle);
- break;
- case 'atom':
- $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
- break;
- case 'json':
- $this->show_json_timeline($notice);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- }
-
- }
-
- function create($args, $apidata) {
- parent::handle($args);
-
- // Check for RESTfulness
- if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
- // XXX: Twitter just prints the err msg, no XML / JSON.
- $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
- return;
- }
-
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
-
- $this->auth_user = $apidata['user'];
- $user = $this->auth_user;
- $notice_id = $apidata['api_arg'];
- $notice = Notice::staticGet($notice_id);
-
- if (!$notice) {
- $this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
- return;
- }
-
- // XXX: Twitter lets you fave things repeatedly via api.
- if ($user->hasFave($notice)) {
- $this->client_error(_('This notice is already a favorite!'), 403, $apidata['content-type']);
- return;
- }
-
- $fave = Fave::addNew($user, $notice);
-
- if (!$fave) {
- common_server_error(_('Could not create favorite.'));
- return;
- }
-
- $this->notify($fave, $notice, $user);
- $user->blowFavesCache();
-
- if ($apidata['content-type'] == 'xml') {
- $this->show_single_xml_status($notice);
- } elseif ($apidata['content-type'] == 'json') {
- $this->show_single_json_status($notice);
- }
-
- }
-
- function destroy($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
-
- // XXX: these two funcs swiped from faves. Maybe put in util.php, or some common base class?
-
- function notify($fave, $notice, $user) {
- $other = User::staticGet('id', $notice->profile_id);
- if ($other && $other->id != $user->id) {
- if ($other->email && $other->emailnotifyfav) {
- $this->notify_mail($other, $user, $notice);
- }
- # XXX: notify by IM
- # XXX: notify by SMS
- }
- }
-
- function notify_mail($other, $user, $notice) {
- $profile = $user->getProfile();
- $bestname = $profile->getBestName();
- $subject = sprintf(_('%s added your notice as a favorite'), $bestname);
- $body = sprintf(_("%1\$s just added your notice from %2\$s as one of their favorites.\n\n" .
- "In case you forgot, you can see the text of your notice here:\n\n" .
- "%3\$s\n\n" .
- "You can see the list of %1\$s's favorites here:\n\n" .
- "%4\$s\n\n" .
- "Faithfully yours,\n" .
- "%5\$s\n"),
- $bestname,
- common_exact_date($notice->created),
- common_local_url('shownotice', array('notice' => $notice->id)),
- common_local_url('showfavorites', array('nickname' => $user->nickname)),
- common_config('site', 'name'));
-
- mail_to_user($other, $subject, $body);
- }
+ function favorites($args, $apidata) {
+ parent::handle($args);
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->get_user($apidata['api_arg'], $apidata);
+
+ if (!$user) {
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
+
+ $page = $this->arg('page');
+
+ if (!$page) {
+ $page = 1;
+ }
+
+ if (!$count) {
+ $count = 20;
+ }
+
+ $notice = $user->favoriteNotices((($page-1)*20), $count);
+
+ if (!$notice) {
+ common_server_error(_('Could not retrieve favorite notices.'));
+ return;
+ }
+
+ $sitename = common_config('site', 'name');
+ $siteserver = common_config('site', 'server');
+
+ $title = sprintf(_('%s / Favorites from %s'), $sitename, $user->nickname);
+ $id = "tag:$siteserver:favorites:".$user->id;
+ $link = common_local_url('favorites', array('nickname' => $user->nickname));
+ $subtitle = sprintf(_('%s updates favorited by %s / %s.'), $sitename, $profile->getBestName(), $user->nickname);
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_xml_timeline($notice);
+ break;
+ case 'rss':
+ $this->show_rss_timeline($notice, $title, $link, $subtitle);
+ break;
+ case 'atom':
+ $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+ break;
+ case 'json':
+ $this->show_json_timeline($notice);
+ break;
+ default:
+ common_user_error(_('API method not found!'), $code = 404);
+ }
+
+ }
+
+ function create($args, $apidata) {
+ parent::handle($args);
+
+ // Check for RESTfulness
+ if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
+ // XXX: Twitter just prints the err msg, no XML / JSON.
+ $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
+ return;
+ }
+
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->auth_user;
+ $notice_id = $apidata['api_arg'];
+ $notice = Notice::staticGet($notice_id);
+
+ if (!$notice) {
+ $this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
+ return;
+ }
+
+ // XXX: Twitter lets you fave things repeatedly via api.
+ if ($user->hasFave($notice)) {
+ $this->client_error(_('This notice is already a favorite!'), 403, $apidata['content-type']);
+ return;
+ }
+
+ $fave = Fave::addNew($user, $notice);
+
+ if (!$fave) {
+ common_server_error(_('Could not create favorite.'));
+ return;
+ }
+
+ $this->notify($fave, $notice, $user);
+ $user->blowFavesCache();
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->show_single_xml_status($notice);
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->show_single_json_status($notice);
+ }
+
+ }
+
+ function destroy($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
+
+ // XXX: these two funcs swiped from faves. Maybe put in util.php, or some common base class?
+
+ function notify($fave, $notice, $user) {
+ $other = User::staticGet('id', $notice->profile_id);
+ if ($other && $other->id != $user->id) {
+ if ($other->email && $other->emailnotifyfav) {
+ $this->notify_mail($other, $user, $notice);
+ }
+ # XXX: notify by IM
+ # XXX: notify by SMS
+ }
+ }
+
+ function notify_mail($other, $user, $notice) {
+ $profile = $user->getProfile();
+ $bestname = $profile->getBestName();
+ $subject = sprintf(_('%s added your notice as a favorite'), $bestname);
+ $body = sprintf(_("%1\$s just added your notice from %2\$s as one of their favorites.\n\n" .
+ "In case you forgot, you can see the text of your notice here:\n\n" .
+ "%3\$s\n\n" .
+ "You can see the list of %1\$s's favorites here:\n\n" .
+ "%4\$s\n\n" .
+ "Faithfully yours,\n" .
+ "%5\$s\n"),
+ $bestname,
+ common_exact_date($notice->created),
+ common_local_url('shownotice', array('notice' => $notice->id)),
+ common_local_url('showfavorites', array('nickname' => $user->nickname)),
+ common_config('site', 'name'));
+
+ mail_to_user($other, $subject, $body);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/twitapifriendships.php b/_darcs/pristine/actions/twitapifriendships.php
index e4b49cbe4..d352b933b 100644
--- a/_darcs/pristine/actions/twitapifriendships.php
+++ b/_darcs/pristine/actions/twitapifriendships.php
@@ -23,133 +23,133 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapifriendshipsAction extends TwitterapiAction {
- function create($args, $apidata) {
- parent::handle($args);
+ function create($args, $apidata) {
+ parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
- return;
- }
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+ return;
+ }
- $id = $apidata['api_arg'];
+ $id = $apidata['api_arg'];
- $other = $this->get_user($id);
+ $other = $this->get_user($id);
- if (!$other) {
- $this->client_error(_('Could not follow user: User not found.'), 403, $apidata['content-type']);
- return;
- }
+ if (!$other) {
+ $this->client_error(_('Could not follow user: User not found.'), 403, $apidata['content-type']);
+ return;
+ }
- $user = $apidata['user'];
+ $user = $apidata['user'];
- if ($user->isSubscribed($other)) {
- $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname);
- $this->client_error($errmsg, 403, $apidata['content-type']);
- return;
- }
+ if ($user->isSubscribed($other)) {
+ $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname);
+ $this->client_error($errmsg, 403, $apidata['content-type']);
+ return;
+ }
- $sub = new Subscription();
+ $sub = new Subscription();
- $sub->query('BEGIN');
+ $sub->query('BEGIN');
- $sub->subscriber = $user->id;
- $sub->subscribed = $other->id;
- $sub->created = DB_DataObject_Cast::dateTime(); # current time
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $other->id;
+ $sub->created = DB_DataObject_Cast::dateTime(); # current time
- $result = $sub->insert();
+ $result = $sub->insert();
- if (!$result) {
- $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname);
- $this->client_error($errmsg, 400, $apidata['content-type']);
- return;
- }
+ if (!$result) {
+ $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $other->nickname);
+ $this->client_error($errmsg, 400, $apidata['content-type']);
+ return;
+ }
- $sub->query('COMMIT');
+ $sub->query('COMMIT');
- mail_subscribe_notify($other, $user);
+ mail_subscribe_notify($other, $user);
- $type = $apidata['content-type'];
- $this->init_document($type);
- $this->show_profile($other, $type);
- $this->end_document($type);
+ $type = $apidata['content-type'];
+ $this->init_document($type);
+ $this->show_profile($other, $type);
+ $this->end_document($type);
- }
+ }
- function destroy($args, $apidata) {
- parent::handle($args);
+ function destroy($args, $apidata) {
+ parent::handle($args);
- if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
- $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
- return;
- }
+ if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
+ $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
+ return;
+ }
- $id = $apidata['api_arg'];
+ $id = $apidata['api_arg'];
- # We can't subscribe to a remote person, but we can unsub
+ # We can't subscribe to a remote person, but we can unsub
- $other = $this->get_profile($id);
- $user = $apidata['user'];
+ $other = $this->get_profile($id);
+ $user = $apidata['user'];
- $sub = new Subscription();
- $sub->subscriber = $user->id;
- $sub->subscribed = $other->id;
+ $sub = new Subscription();
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $other->id;
- if ($sub->find(TRUE)) {
- $sub->query('BEGIN');
- $sub->delete();
- $sub->query('COMMIT');
- } else {
- $this->client_error(_('You are not friends with the specified user.'), 403, $apidata['content-type']);
- return;
- }
+ if ($sub->find(TRUE)) {
+ $sub->query('BEGIN');
+ $sub->delete();
+ $sub->query('COMMIT');
+ } else {
+ $this->client_error(_('You are not friends with the specified user.'), 403, $apidata['content-type']);
+ return;
+ }
- $type = $apidata['content-type'];
- $this->init_document($type);
- $this->show_profile($other, $type);
- $this->end_document($type);
+ $type = $apidata['content-type'];
+ $this->init_document($type);
+ $this->show_profile($other, $type);
+ $this->end_document($type);
- }
+ }
- function exists($args, $apidata) {
- parent::handle($args);
+ function exists($args, $apidata) {
+ parent::handle($args);
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
- $user_a_id = $this->trimmed('user_a');
- $user_b_id = $this->trimmed('user_b');
+ $user_a_id = $this->trimmed('user_a');
+ $user_b_id = $this->trimmed('user_b');
- $user_a = $this->get_user($user_a_id);
- $user_b = $this->get_user($user_b_id);
+ $user_a = $this->get_user($user_a_id);
+ $user_b = $this->get_user($user_b_id);
- if (!$user_a || !$user_b) {
- $this->client_error(_('Two user ids or screen_names must be supplied.'), 400, $apidata['content-type']);
- return;
- }
+ if (!$user_a || !$user_b) {
+ $this->client_error(_('Two user ids or screen_names must be supplied.'), 400, $apidata['content-type']);
+ return;
+ }
- if ($user_a->isSubscribed($user_b)) {
- $result = 'true';
- } else {
- $result = 'false';
- }
+ if ($user_a->isSubscribed($user_b)) {
+ $result = 'true';
+ } else {
+ $result = 'false';
+ }
- switch ($apidata['content-type']) {
- case 'xml':
- $this->init_document('xml');
- common_element('friends', NULL, $result);
- $this->end_document('xml');
- break;
- case 'json':
- $this->init_document('json');
- print json_encode($result);
- $this->end_document('json');
- break;
- default:
- break;
- }
+ switch ($apidata['content-type']) {
+ case 'xml':
+ $this->init_document('xml');
+ common_element('friends', NULL, $result);
+ $this->end_document('xml');
+ break;
+ case 'json':
+ $this->init_document('json');
+ print json_encode($result);
+ $this->end_document('json');
+ break;
+ default:
+ break;
+ }
- }
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/twitapihelp.php b/_darcs/pristine/actions/twitapihelp.php
index c5d503e11..d268b7c82 100644
--- a/_darcs/pristine/actions/twitapihelp.php
+++ b/_darcs/pristine/actions/twitapihelp.php
@@ -23,30 +23,30 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapihelpAction extends TwitterapiAction {
- /* Returns the string "ok" in the requested format with a 200 OK HTTP status code.
- * URL:http://identi.ca/api/help/test.format
- * Formats: xml, json
- */
- function test($args, $apidata) {
- parent::handle($args);
-
- if ($apidata['content-type'] == 'xml') {
- $this->init_document('xml');
- common_element('ok', NULL, 'true');
- $this->end_document('xml');
- } elseif ($apidata['content-type'] == 'json') {
- $this->init_document('json');
- print '"ok"';
- $this->end_document('json');
- } else {
- common_user_error(_('API method not found!'), $code=404);
- }
-
- }
-
- function downtime_schedule($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ /* Returns the string "ok" in the requested format with a 200 OK HTTP status code.
+ * URL:http://identi.ca/api/help/test.format
+ * Formats: xml, json
+ */
+ function test($args, $apidata) {
+ parent::handle($args);
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->init_document('xml');
+ common_element('ok', NULL, 'true');
+ $this->end_document('xml');
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->init_document('json');
+ print '"ok"';
+ $this->end_document('json');
+ } else {
+ common_user_error(_('API method not found!'), $code=404);
+ }
+
+ }
+
+ function downtime_schedule($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/twitapinotifications.php b/_darcs/pristine/actions/twitapinotifications.php
index 8d93309a2..26f66d7e5 100644
--- a/_darcs/pristine/actions/twitapinotifications.php
+++ b/_darcs/pristine/actions/twitapinotifications.php
@@ -24,14 +24,14 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
# This naming convention looks real sick
class TwitapinotificationsAction extends TwitterapiAction {
- function follow($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ function follow($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
- function leave($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
+ function leave($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/twitapistatuses.php b/_darcs/pristine/actions/twitapistatuses.php
index 7b6598b10..c33643a3c 100644
--- a/_darcs/pristine/actions/twitapistatuses.php
+++ b/_darcs/pristine/actions/twitapistatuses.php
@@ -23,541 +23,541 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapistatusesAction extends TwitterapiAction {
- function public_timeline($args, $apidata) {
- parent::handle($args);
-
- $sitename = common_config('site', 'name');
- $siteserver = common_config('site', 'server');
- $title = sprintf(_("%s public timeline"), $sitename);
- $id = "tag:$siteserver:Statuses";
- $link = common_root_url();
- $subtitle = sprintf(_("%s updates from everyone!"), $sitename);
-
- // Number of public statuses to return by default -- Twitter sends 20
- $MAX_PUBSTATUSES = 20;
-
- // FIXME: To really live up to the spec we need to build a list
- // of notices by users who have custom avatars, so fix this SQL -- Zach
-
- $page = $this->arg('page');
- $since_id = $this->arg('since_id');
- $before_id = $this->arg('before_id');
-
- // NOTE: page, since_id, and before_id are extensions to Twitter API -- TB
- if (!$page) {
- $page = 1;
- }
- if (!$since_id) {
- $since_id = 0;
- }
- if (!$before_id) {
- $before_id = 0;
- }
-
- $since = strtotime($this->arg('since'));
-
- $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $before_id, $since);
-
- if ($notice) {
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_timeline($notice);
- break;
- case 'rss':
- $this->show_rss_timeline($notice, $title, $link, $subtitle);
- break;
- case 'atom':
- $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
- break;
- case 'json':
- $this->show_json_timeline($notice);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- break;
- }
-
- } else {
- common_server_error(_('Couldn\'t find any statuses.'), $code = 503);
- }
-
- }
-
- function friends_timeline($args, $apidata) {
- parent::handle($args);
-
- $since = $this->arg('since');
- $since_id = $this->arg('since_id');
- $count = $this->arg('count');
- $page = $this->arg('page');
- $before_id = $this->arg('before_id');
-
- if (!$page) {
- $page = 1;
- }
-
- if (!$count) {
- $count = 20;
- }
-
- if (!$since_id) {
- $since_id = 0;
- }
-
- // NOTE: before_id is an extension to Twitter API -- TB
- if (!$before_id) {
- $before_id = 0;
- }
-
- $since = strtotime($this->arg('since'));
-
- $user = $this->get_user(NULL, $apidata);
- $this->auth_user = $user;
-
- $profile = $user->getProfile();
-
- $sitename = common_config('site', 'name');
- $siteserver = common_config('site', 'server');
-
- $title = sprintf(_("%s and friends"), $user->nickname);
- $id = "tag:$siteserver:friends:" . $user->id;
- $link = common_local_url('all', array('nickname' => $user->nickname));
- $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename);
-
- $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $before_id, $since);
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_timeline($notice);
- break;
- case 'rss':
- $this->show_rss_timeline($notice, $title, $link, $subtitle);
- break;
- case 'atom':
- $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
- break;
- case 'json':
- $this->show_json_timeline($notice);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- }
-
- }
-
- function user_timeline($args, $apidata) {
- parent::handle($args);
-
- $this->auth_user = $apidata['user'];
- $user = $this->get_user($apidata['api_arg'], $apidata);
-
- if (!$user) {
- $this->client_error('Not Found', 404, $apidata['content-type']);
- return;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $count = $this->arg('count');
- $since = $this->arg('since');
- $since_id = $this->arg('since_id');
- $page = $this->arg('page');
- $before_id = $this->arg('before_id');
-
- if (!$page) {
- $page = 1;
- }
-
- if (!$count) {
- $count = 20;
- }
-
- if (!$since_id) {
- $since_id = 0;
- }
-
- // NOTE: before_id is an extensions to Twitter API -- TB
- if (!$before_id) {
- $before_id = 0;
- }
-
- $since = strtotime($this->arg('since'));
-
- $sitename = common_config('site', 'name');
- $siteserver = common_config('site', 'server');
-
- $title = sprintf(_("%s timeline"), $user->nickname);
- $id = "tag:$siteserver:user:".$user->id;
- $link = common_local_url('showstream', array('nickname' => $user->nickname));
- $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename);
-
- # FriendFeed's SUP protocol
- # Also added RSS and Atom feeds
-
- $suplink = common_local_url('sup', NULL, $user->id);
- header('X-SUP-ID: '.$suplink);
-
- # XXX: since
-
- $notice = $user->getNotices((($page-1)*20), $count, $since_id, $before_id, $since);
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_timeline($notice);
- break;
- case 'rss':
- $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink);
- break;
- case 'atom':
- $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink);
- break;
- case 'json':
- $this->show_json_timeline($notice);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- }
-
- }
-
- function update($args, $apidata) {
-
- parent::handle($args);
-
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
- return;
- }
-
- $this->auth_user = $apidata['user'];
- $user = $this->auth_user;
- $status = $this->trimmed('status');
- $source = $this->trimmed('source');
- $in_reply_to_status_id = intval($this->trimmed('in_reply_to_status_id'));
+ function public_timeline($args, $apidata) {
+ parent::handle($args);
+
+ $sitename = common_config('site', 'name');
+ $siteserver = common_config('site', 'server');
+ $title = sprintf(_("%s public timeline"), $sitename);
+ $id = "tag:$siteserver:Statuses";
+ $link = common_root_url();
+ $subtitle = sprintf(_("%s updates from everyone!"), $sitename);
+
+ // Number of public statuses to return by default -- Twitter sends 20
+ $MAX_PUBSTATUSES = 20;
+
+ // FIXME: To really live up to the spec we need to build a list
+ // of notices by users who have custom avatars, so fix this SQL -- Zach
+
+ $page = $this->arg('page');
+ $since_id = $this->arg('since_id');
+ $before_id = $this->arg('before_id');
+
+ // NOTE: page, since_id, and before_id are extensions to Twitter API -- TB
+ if (!$page) {
+ $page = 1;
+ }
+ if (!$since_id) {
+ $since_id = 0;
+ }
+ if (!$before_id) {
+ $before_id = 0;
+ }
+
+ $since = strtotime($this->arg('since'));
+
+ $notice = Notice::publicStream((($page-1)*$MAX_PUBSTATUSES), $MAX_PUBSTATUSES, $since_id, $before_id, $since);
+
+ if ($notice) {
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_xml_timeline($notice);
+ break;
+ case 'rss':
+ $this->show_rss_timeline($notice, $title, $link, $subtitle);
+ break;
+ case 'atom':
+ $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+ break;
+ case 'json':
+ $this->show_json_timeline($notice);
+ break;
+ default:
+ common_user_error(_('API method not found!'), $code = 404);
+ break;
+ }
+
+ } else {
+ common_server_error(_('Couldn\'t find any statuses.'), $code = 503);
+ }
+
+ }
+
+ function friends_timeline($args, $apidata) {
+ parent::handle($args);
+
+ $since = $this->arg('since');
+ $since_id = $this->arg('since_id');
+ $count = $this->arg('count');
+ $page = $this->arg('page');
+ $before_id = $this->arg('before_id');
+
+ if (!$page) {
+ $page = 1;
+ }
+
+ if (!$count) {
+ $count = 20;
+ }
+
+ if (!$since_id) {
+ $since_id = 0;
+ }
+
+ // NOTE: before_id is an extension to Twitter API -- TB
+ if (!$before_id) {
+ $before_id = 0;
+ }
+
+ $since = strtotime($this->arg('since'));
+
+ $user = $this->get_user(NULL, $apidata);
+ $this->auth_user = $user;
+
+ $profile = $user->getProfile();
+
+ $sitename = common_config('site', 'name');
+ $siteserver = common_config('site', 'server');
+
+ $title = sprintf(_("%s and friends"), $user->nickname);
+ $id = "tag:$siteserver:friends:" . $user->id;
+ $link = common_local_url('all', array('nickname' => $user->nickname));
+ $subtitle = sprintf(_('Updates from %1$s and friends on %2$s!'), $user->nickname, $sitename);
+
+ $notice = $user->noticesWithFriends(($page-1)*20, $count, $since_id, $before_id, $since);
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_xml_timeline($notice);
+ break;
+ case 'rss':
+ $this->show_rss_timeline($notice, $title, $link, $subtitle);
+ break;
+ case 'atom':
+ $this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+ break;
+ case 'json':
+ $this->show_json_timeline($notice);
+ break;
+ default:
+ common_user_error(_('API method not found!'), $code = 404);
+ }
+
+ }
+
+ function user_timeline($args, $apidata) {
+ parent::handle($args);
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->get_user($apidata['api_arg'], $apidata);
+
+ if (!$user) {
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
+
+ $count = $this->arg('count');
+ $since = $this->arg('since');
+ $since_id = $this->arg('since_id');
+ $page = $this->arg('page');
+ $before_id = $this->arg('before_id');
+
+ if (!$page) {
+ $page = 1;
+ }
+
+ if (!$count) {
+ $count = 20;
+ }
+
+ if (!$since_id) {
+ $since_id = 0;
+ }
+
+ // NOTE: before_id is an extensions to Twitter API -- TB
+ if (!$before_id) {
+ $before_id = 0;
+ }
+
+ $since = strtotime($this->arg('since'));
+
+ $sitename = common_config('site', 'name');
+ $siteserver = common_config('site', 'server');
+
+ $title = sprintf(_("%s timeline"), $user->nickname);
+ $id = "tag:$siteserver:user:".$user->id;
+ $link = common_local_url('showstream', array('nickname' => $user->nickname));
+ $subtitle = sprintf(_('Updates from %1$s on %2$s!'), $user->nickname, $sitename);
+
+ # FriendFeed's SUP protocol
+ # Also added RSS and Atom feeds
+
+ $suplink = common_local_url('sup', NULL, $user->id);
+ header('X-SUP-ID: '.$suplink);
+
+ # XXX: since
+
+ $notice = $user->getNotices((($page-1)*20), $count, $since_id, $before_id, $since);
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_xml_timeline($notice);
+ break;
+ case 'rss':
+ $this->show_rss_timeline($notice, $title, $link, $subtitle, $suplink);
+ break;
+ case 'atom':
+ $this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink);
+ break;
+ case 'json':
+ $this->show_json_timeline($notice);
+ break;
+ default:
+ common_user_error(_('API method not found!'), $code = 404);
+ }
+
+ }
+
+ function update($args, $apidata) {
+
+ parent::handle($args);
+
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->client_error(_('This method requires a POST.'), 400, $apidata['content-type']);
+ return;
+ }
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->auth_user;
+ $status = $this->trimmed('status');
+ $source = $this->trimmed('source');
+ $in_reply_to_status_id = intval($this->trimmed('in_reply_to_status_id'));
$reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api');
- if (!$source || in_array($source, $reserved_sources)) {
- $source = 'api';
- }
+ if (!$source || in_array($source, $reserved_sources)) {
+ $source = 'api';
+ }
- if (!$status) {
+ if (!$status) {
- // XXX: Note: In this case, Twitter simply returns '200 OK'
- // No error is given, but the status is not posted to the
- // user's timeline. Seems bad. Shouldn't we throw an
- // errror? -- Zach
- return;
+ // XXX: Note: In this case, Twitter simply returns '200 OK'
+ // No error is given, but the status is not posted to the
+ // user's timeline. Seems bad. Shouldn't we throw an
+ // errror? -- Zach
+ return;
- } else {
+ } else {
- $status_shortened = common_shorten_links($status);
+ $status_shortened = common_shorten_links($status);
- if (mb_strlen($status_shortened) > 140) {
+ if (mb_strlen($status_shortened) > 140) {
- // XXX: Twitter truncates anything over 140, flags the status
- // as "truncated." Sending this error may screw up some clients
- // that assume Twitter will truncate for them. Should we just
- // truncate too? -- Zach
- $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
- return;
+ // XXX: Twitter truncates anything over 140, flags the status
+ // as "truncated." Sending this error may screw up some clients
+ // that assume Twitter will truncate for them. Should we just
+ // truncate too? -- Zach
+ $this->client_error(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']);
+ return;
- }
- }
+ }
+ }
- // Check for commands
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $status_shortened);
+ // Check for commands
+ $inter = new CommandInterpreter();
+ $cmd = $inter->handle_command($user, $status_shortened);
- if ($cmd) {
+ if ($cmd) {
- if ($this->supported($cmd)) {
- $cmd->execute(new Channel());
- }
-
- // cmd not supported? Twitter just returns your latest status.
- // And, it returns your last status whether the cmd was successful
- // or not!
- $n = $user->getCurrentNotice();
- $apidata['api_arg'] = $n->id;
- } else {
+ if ($this->supported($cmd)) {
+ $cmd->execute(new Channel());
+ }
+
+ // cmd not supported? Twitter just returns your latest status.
+ // And, it returns your last status whether the cmd was successful
+ // or not!
+ $n = $user->getCurrentNotice();
+ $apidata['api_arg'] = $n->id;
+ } else {
- $reply_to = NULL;
+ $reply_to = NULL;
- if ($in_reply_to_status_id) {
-
- // check whether notice actually exists
- $reply = Notice::staticGet($in_reply_to_status_id);
-
- if ($reply) {
- $reply_to = $in_reply_to_status_id;
- } else {
- $this->client_error(_('Not found'), $code = 404, $apidata['content-type']);
- return;
- }
- }
-
- $notice = Notice::saveNew($user->id, html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'),
- $source, 1, $reply_to);
-
- if (is_string($notice)) {
- $this->server_error($notice);
- return;
- }
-
- common_broadcast_notice($notice);
- $apidata['api_arg'] = $notice->id;
- }
-
- $this->show($args, $apidata);
- }
-
- function replies($args, $apidata) {
-
- parent::handle($args);
-
- $since = $this->arg('since');
- $count = $this->arg('count');
- $page = $this->arg('page');
- $since_id = $this->arg('since_id');
- $before_id = $this->arg('before_id');
-
- $this->auth_user = $apidata['user'];
- $user = $this->auth_user;
- $profile = $user->getProfile();
-
- $sitename = common_config('site', 'name');
- $siteserver = common_config('site', 'server');
-
- $title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname);
- $id = "tag:$siteserver:replies:".$user->id;
- $link = common_local_url('replies', array('nickname' => $user->nickname));
- $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName());
-
- if (!$page) {
- $page = 1;
- }
-
- if (!$count) {
- $count = 20;
- }
-
- if (!$since_id) {
- $since_id = 0;
- }
-
- // NOTE: before_id is an extension to Twitter API -- TB
- if (!$before_id) {
- $before_id = 0;
- }
-
- $since = strtotime($this->arg('since'));
-
- $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id, $since);
- $notices = array();
-
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
-
- switch($apidata['content-type']) {
- case 'xml':
- $this->show_xml_timeline($notices);
- break;
- case 'rss':
- $this->show_rss_timeline($notices, $title, $link, $subtitle);
- break;
- case 'atom':
- $this->show_atom_timeline($notices, $title, $id, $link, $subtitle);
- break;
- case 'json':
- $this->show_json_timeline($notices);
- break;
- default:
- common_user_error(_('API method not found!'), $code = 404);
- }
-
- }
-
- function show($args, $apidata) {
- parent::handle($args);
-
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
-
- $this->auth_user = $apidata['user'];
- $notice_id = $apidata['api_arg'];
- $notice = Notice::staticGet($notice_id);
-
- if ($notice) {
- if ($apidata['content-type'] == 'xml') {
- $this->show_single_xml_status($notice);
- } elseif ($apidata['content-type'] == 'json') {
- $this->show_single_json_status($notice);
- }
- } else {
- // XXX: Twitter just sets a 404 header and doens't bother to return an err msg
- $this->client_error(_('No status with that ID found.'), 404, $apidata['content-type']);
- }
-
- }
-
- function destroy($args, $apidata) {
-
- parent::handle($args);
-
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
-
- // Check for RESTfulness
- if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
- // XXX: Twitter just prints the err msg, no XML / JSON.
- $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
- return;
- }
-
- $this->auth_user = $apidata['user'];
- $user = $this->auth_user;
- $notice_id = $apidata['api_arg'];
- $notice = Notice::staticGet($notice_id);
-
- if (!$notice) {
- $this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
- return;
- }
-
- if ($user->id == $notice->profile_id) {
- $replies = new Reply;
- $replies->get('notice_id', $notice_id);
- common_dequeue_notice($notice);
- $replies->delete();
- $notice->delete();
-
- if ($apidata['content-type'] == 'xml') {
- $this->show_single_xml_status($notice);
- } elseif ($apidata['content-type'] == 'json') {
- $this->show_single_json_status($notice);
- }
- } else {
- $this->client_error(_('You may not delete another user\'s status.'), 403, $apidata['content-type']);
- }
-
- }
-
- function friends($args, $apidata) {
- parent::handle($args);
- return $this->subscriptions($apidata, 'subscribed', 'subscriber');
- }
-
- function followers($args, $apidata) {
- parent::handle($args);
-
- return $this->subscriptions($apidata, 'subscriber', 'subscribed');
- }
-
- function subscriptions($apidata, $other_attr, $user_attr) {
-
- # XXX: lite
-
- $this->auth_user = $apidate['user'];
- $user = $this->get_user($apidata['api_arg'], $apidata);
-
- if (!$user) {
- $this->client_error('Not Found', 404, $apidata['content-type']);
- return;
- }
-
- $page = $this->trimmed('page');
-
- if (!$page || !is_numeric($page)) {
- $page = 1;
- }
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $sub = new Subscription();
- $sub->$user_attr = $profile->id;
-
- $since = strtotime($this->trimmed('since'));
-
- if ($since) {
- $d = date('Y-m-d H:i:s', $since);
- $sub->whereAdd("created > '$d'");
- }
-
- $sub->orderBy('created DESC');
- $sub->limit(($page-1)*100, 100);
-
- $others = array();
-
- if ($sub->find()) {
- while ($sub->fetch()) {
- $others[] = Profile::staticGet($sub->$other_attr);
- }
- } else {
- // user has no followers
- }
-
- $type = $apidata['content-type'];
-
- $this->init_document($type);
- $this->show_profiles($others, $type);
- $this->end_document($type);
- }
-
- function show_profiles($profiles, $type) {
- switch ($type) {
- case 'xml':
- common_element_start('users', array('type' => 'array'));
- foreach ($profiles as $profile) {
- $this->show_profile($profile);
- }
- common_element_end('users');
- break;
- case 'json':
- $arrays = array();
- foreach ($profiles as $profile) {
- $arrays[] = $this->twitter_user_array($profile, true);
- }
- print json_encode($arrays);
- break;
- default:
- $this->client_error(_('unsupported file type'));
- }
- }
-
- function featured($args, $apidata) {
- parent::handle($args);
- common_server_error(_('API method under construction.'), $code=501);
- }
-
- function supported($cmd) {
-
- $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', 'FavCommand', 'OnCommand', 'OffCommand');
+ if ($in_reply_to_status_id) {
+
+ // check whether notice actually exists
+ $reply = Notice::staticGet($in_reply_to_status_id);
+
+ if ($reply) {
+ $reply_to = $in_reply_to_status_id;
+ } else {
+ $this->client_error(_('Not found'), $code = 404, $apidata['content-type']);
+ return;
+ }
+ }
+
+ $notice = Notice::saveNew($user->id, html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'),
+ $source, 1, $reply_to);
+
+ if (is_string($notice)) {
+ $this->server_error($notice);
+ return;
+ }
+
+ common_broadcast_notice($notice);
+ $apidata['api_arg'] = $notice->id;
+ }
+
+ $this->show($args, $apidata);
+ }
+
+ function replies($args, $apidata) {
+
+ parent::handle($args);
+
+ $since = $this->arg('since');
+ $count = $this->arg('count');
+ $page = $this->arg('page');
+ $since_id = $this->arg('since_id');
+ $before_id = $this->arg('before_id');
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->auth_user;
+ $profile = $user->getProfile();
+
+ $sitename = common_config('site', 'name');
+ $siteserver = common_config('site', 'server');
+
+ $title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname);
+ $id = "tag:$siteserver:replies:".$user->id;
+ $link = common_local_url('replies', array('nickname' => $user->nickname));
+ $subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName());
+
+ if (!$page) {
+ $page = 1;
+ }
+
+ if (!$count) {
+ $count = 20;
+ }
+
+ if (!$since_id) {
+ $since_id = 0;
+ }
+
+ // NOTE: before_id is an extension to Twitter API -- TB
+ if (!$before_id) {
+ $before_id = 0;
+ }
+
+ $since = strtotime($this->arg('since'));
+
+ $notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id, $since);
+ $notices = array();
+
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_xml_timeline($notices);
+ break;
+ case 'rss':
+ $this->show_rss_timeline($notices, $title, $link, $subtitle);
+ break;
+ case 'atom':
+ $this->show_atom_timeline($notices, $title, $id, $link, $subtitle);
+ break;
+ case 'json':
+ $this->show_json_timeline($notices);
+ break;
+ default:
+ common_user_error(_('API method not found!'), $code = 404);
+ }
+
+ }
+
+ function show($args, $apidata) {
+ parent::handle($args);
+
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
+
+ $this->auth_user = $apidata['user'];
+ $notice_id = $apidata['api_arg'];
+ $notice = Notice::staticGet($notice_id);
+
+ if ($notice) {
+ if ($apidata['content-type'] == 'xml') {
+ $this->show_single_xml_status($notice);
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->show_single_json_status($notice);
+ }
+ } else {
+ // XXX: Twitter just sets a 404 header and doens't bother to return an err msg
+ $this->client_error(_('No status with that ID found.'), 404, $apidata['content-type']);
+ }
+
+ }
+
+ function destroy($args, $apidata) {
+
+ parent::handle($args);
+
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
+
+ // Check for RESTfulness
+ if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
+ // XXX: Twitter just prints the err msg, no XML / JSON.
+ $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
+ return;
+ }
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->auth_user;
+ $notice_id = $apidata['api_arg'];
+ $notice = Notice::staticGet($notice_id);
+
+ if (!$notice) {
+ $this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
+ return;
+ }
+
+ if ($user->id == $notice->profile_id) {
+ $replies = new Reply;
+ $replies->get('notice_id', $notice_id);
+ common_dequeue_notice($notice);
+ $replies->delete();
+ $notice->delete();
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->show_single_xml_status($notice);
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->show_single_json_status($notice);
+ }
+ } else {
+ $this->client_error(_('You may not delete another user\'s status.'), 403, $apidata['content-type']);
+ }
+
+ }
+
+ function friends($args, $apidata) {
+ parent::handle($args);
+ return $this->subscriptions($apidata, 'subscribed', 'subscriber');
+ }
+
+ function followers($args, $apidata) {
+ parent::handle($args);
+
+ return $this->subscriptions($apidata, 'subscriber', 'subscribed');
+ }
+
+ function subscriptions($apidata, $other_attr, $user_attr) {
+
+ # XXX: lite
+
+ $this->auth_user = $apidate['user'];
+ $user = $this->get_user($apidata['api_arg'], $apidata);
+
+ if (!$user) {
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
+ }
+
+ $page = $this->trimmed('page');
+
+ if (!$page || !is_numeric($page)) {
+ $page = 1;
+ }
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
+
+ $sub = new Subscription();
+ $sub->$user_attr = $profile->id;
+
+ $since = strtotime($this->trimmed('since'));
+
+ if ($since) {
+ $d = date('Y-m-d H:i:s', $since);
+ $sub->whereAdd("created > '$d'");
+ }
+
+ $sub->orderBy('created DESC');
+ $sub->limit(($page-1)*100, 100);
+
+ $others = array();
+
+ if ($sub->find()) {
+ while ($sub->fetch()) {
+ $others[] = Profile::staticGet($sub->$other_attr);
+ }
+ } else {
+ // user has no followers
+ }
+
+ $type = $apidata['content-type'];
+
+ $this->init_document($type);
+ $this->show_profiles($others, $type);
+ $this->end_document($type);
+ }
+
+ function show_profiles($profiles, $type) {
+ switch ($type) {
+ case 'xml':
+ common_element_start('users', array('type' => 'array'));
+ foreach ($profiles as $profile) {
+ $this->show_profile($profile);
+ }
+ common_element_end('users');
+ break;
+ case 'json':
+ $arrays = array();
+ foreach ($profiles as $profile) {
+ $arrays[] = $this->twitter_user_array($profile, true);
+ }
+ print json_encode($arrays);
+ break;
+ default:
+ $this->client_error(_('unsupported file type'));
+ }
+ }
+
+ function featured($args, $apidata) {
+ parent::handle($args);
+ common_server_error(_('API method under construction.'), $code=501);
+ }
+
+ function supported($cmd) {
+
+ $cmdlist = array('MessageCommand', 'SubCommand', 'UnsubCommand', 'FavCommand', 'OnCommand', 'OffCommand');
- if (in_array(get_class($cmd), $cmdlist)) {
- return true;
- }
+ if (in_array(get_class($cmd), $cmdlist)) {
+ return true;
+ }
- return false;
- }
+ return false;
+ }
}
diff --git a/_darcs/pristine/actions/twitapiusers.php b/_darcs/pristine/actions/twitapiusers.php
index 9e06efa64..43f6969f4 100644
--- a/_darcs/pristine/actions/twitapiusers.php
+++ b/_darcs/pristine/actions/twitapiusers.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,30 +23,30 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiusersAction extends TwitterapiAction {
- function show($args, $apidata) {
- parent::handle($args);
+ function show($args, $apidata) {
+ parent::handle($args);
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- return;
- }
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
- $user = null;
- $email = $this->arg('email');
+ $user = null;
+ $email = $this->arg('email');
- if ($email) {
- $user = User::staticGet('email', $email);
- } elseif (isset($apidata['api_arg'])) {
- $user = $this->get_user($apidata['api_arg']);
- }
+ if ($email) {
+ $user = User::staticGet('email', $email);
+ } elseif (isset($apidata['api_arg'])) {
+ $user = $this->get_user($apidata['api_arg']);
+ }
- if (!$user) {
- // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
- $this->client_error(_('Not found.'), 404, $apidata['content-type']);
- return;
- }
+ if (!$user) {
+ // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
+ $this->client_error(_('Not found.'), 404, $apidata['content-type']);
+ return;
+ }
- $this->show_extended_profile($user, $apidata);
- }
+ $this->show_extended_profile($user, $apidata);
+ }
}
diff --git a/_darcs/pristine/actions/twittersettings.php b/_darcs/pristine/actions/twittersettings.php
index ae3aff877..e300e699a 100644
--- a/_darcs/pristine/actions/twittersettings.php
+++ b/_darcs/pristine/actions/twittersettings.php
@@ -25,354 +25,354 @@ define('SUBSCRIPTIONS', 80);
class TwittersettingsAction extends SettingsAction {
- function get_instructions() {
- return _('Add your Twitter account to automatically send your notices to Twitter, ' .
- 'and subscribe to Twitter friends already here.');
- }
+ function get_instructions() {
+ return _('Add your Twitter account to automatically send your notices to Twitter, ' .
+ 'and subscribe to Twitter friends already here.');
+ }
- function show_form($msg=NULL, $success=false) {
- $user = common_current_user();
- $profile = $user->getProfile();
- $fuser = NULL;
- $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter
+ function show_form($msg=NULL, $success=false) {
+ $user = common_current_user();
+ $profile = $user->getProfile();
+ $fuser = NULL;
+ $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter
- if ($flink) {
- $fuser = $flink->getForeignUser();
- }
+ if ($flink) {
+ $fuser = $flink->getForeignUser();
+ }
- $this->form_header(_('Twitter settings'), $msg, $success);
- common_element_start('form', array('method' => 'post',
- 'id' => 'twittersettings',
- 'action' =>
- common_local_url('twittersettings')));
- common_hidden('token', common_session_token());
+ $this->form_header(_('Twitter settings'), $msg, $success);
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'twittersettings',
+ 'action' =>
+ common_local_url('twittersettings')));
+ common_hidden('token', common_session_token());
- common_element('h2', NULL, _('Twitter Account'));
+ common_element('h2', NULL, _('Twitter Account'));
- if ($fuser) {
- common_element_start('p');
+ if ($fuser) {
+ common_element_start('p');
- common_element('span', 'twitter_user', $fuser->nickname);
- common_element('a', array('href' => $fuser->uri), $fuser->uri);
- common_element('span', 'input_instructions',
- _('Current verified Twitter account.'));
- common_hidden('flink_foreign_id', $flink->foreign_id);
- common_element_end('p');
- common_submit('remove', _('Remove'));
- } else {
- common_input('twitter_username', _('Twitter user name'),
- ($this->arg('twitter_username')) ? $this->arg('twitter_username') : $profile->nickname,
- _('No spaces, please.')); // hey, it's what Twitter says
+ common_element('span', 'twitter_user', $fuser->nickname);
+ common_element('a', array('href' => $fuser->uri), $fuser->uri);
+ common_element('span', 'input_instructions',
+ _('Current verified Twitter account.'));
+ common_hidden('flink_foreign_id', $flink->foreign_id);
+ common_element_end('p');
+ common_submit('remove', _('Remove'));
+ } else {
+ common_input('twitter_username', _('Twitter user name'),
+ ($this->arg('twitter_username')) ? $this->arg('twitter_username') : $profile->nickname,
+ _('No spaces, please.')); // hey, it's what Twitter says
- common_password('twitter_password', _('Twitter password'));
- }
+ common_password('twitter_password', _('Twitter password'));
+ }
- common_element('h2', NULL, _('Preferences'));
+ common_element('h2', NULL, _('Preferences'));
- common_checkbox('noticesync', _('Automatically send my notices to Twitter.'),
- ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
+ common_checkbox('noticesync', _('Automatically send my notices to Twitter.'),
+ ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
- common_checkbox('replysync', _('Send local "@" replies to Twitter.'),
- ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
+ common_checkbox('replysync', _('Send local "@" replies to Twitter.'),
+ ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
- common_checkbox('friendsync', _('Subscribe to my Twitter friends here.'),
- ($flink) ? ($flink->friendsync & FOREIGN_FRIEND_RECV) : false);
+ common_checkbox('friendsync', _('Subscribe to my Twitter friends here.'),
+ ($flink) ? ($flink->friendsync & FOREIGN_FRIEND_RECV) : false);
- if ($flink) {
- common_submit('save', _('Save'));
- } else {
- common_submit('add', _('Add'));
- }
+ if ($flink) {
+ common_submit('save', _('Save'));
+ } else {
+ common_submit('add', _('Add'));
+ }
- $this->show_twitter_subscriptions();
+ $this->show_twitter_subscriptions();
- common_element_end('form');
+ common_element_end('form');
- common_show_footer();
- }
+ common_show_footer();
+ }
- function subscribed_twitter_users() {
+ function subscribed_twitter_users() {
- $current_user = common_current_user();
+ $current_user = common_current_user();
- $qry = 'SELECT user.* ' .
- 'FROM subscription ' .
- 'JOIN user ON subscription.subscribed = user.id ' .
- 'JOIN foreign_link ON foreign_link.user_id = user.id ' .
- 'WHERE subscriber = %d ' .
- 'ORDER BY user.nickname';
+ $qry = 'SELECT user.* ' .
+ 'FROM subscription ' .
+ 'JOIN user ON subscription.subscribed = user.id ' .
+ 'JOIN foreign_link ON foreign_link.user_id = user.id ' .
+ 'WHERE subscriber = %d ' .
+ 'ORDER BY user.nickname';
- $user = new User();
+ $user = new User();
- $user->query(sprintf($qry, $current_user->id));
-
- $users = array();
+ $user->query(sprintf($qry, $current_user->id));
+
+ $users = array();
- while ($user->fetch()) {
-
- // Don't include the user's own self-subscription
- if ($user->id != $current_user->id) {
- $users[] = clone($user);
- }
- }
-
- return $users;
- }
-
- function show_twitter_subscriptions() {
-
- $friends = $this->subscribed_twitter_users();
- $friends_count = count($friends);
-
- if ($friends_count > 0) {
-
- common_element('h3', NULL, _('Twitter Friends'));
- common_element_start('div', array('id' => 'subscriptions'));
- common_element_start('ul', array('id' => 'subscriptions_avatars'));
-
- for ($i = 0; $i < min($friends_count, SUBSCRIPTIONS); $i++) {
-
- $other = Profile::staticGet($friends[$i]->id);
-
- if (!$other) {
- common_log_db_error($subs, 'SELECT', __FILE__);
- continue;
- }
-
- common_element_start('li');
- common_element_start('a', array('title' => ($other->fullname) ?
- $other->fullname :
- $other->nickname,
- 'href' => $other->profileurl,
- 'rel' => 'contact',
- 'class' => 'subscription'));
- $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
- common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
- 'width' => AVATAR_MINI_SIZE,
- 'height' => AVATAR_MINI_SIZE,
- 'class' => 'avatar mini',
- 'alt' => ($other->fullname) ?
- $other->fullname :
- $other->nickname));
- common_element_end('a');
- common_element_end('li');
-
- }
+ while ($user->fetch()) {
+
+ // Don't include the user's own self-subscription
+ if ($user->id != $current_user->id) {
+ $users[] = clone($user);
+ }
+ }
+
+ return $users;
+ }
+
+ function show_twitter_subscriptions() {
+
+ $friends = $this->subscribed_twitter_users();
+ $friends_count = count($friends);
+
+ if ($friends_count > 0) {
+
+ common_element('h3', NULL, _('Twitter Friends'));
+ common_element_start('div', array('id' => 'subscriptions'));
+ common_element_start('ul', array('id' => 'subscriptions_avatars'));
+
+ for ($i = 0; $i < min($friends_count, SUBSCRIPTIONS); $i++) {
+
+ $other = Profile::staticGet($friends[$i]->id);
+
+ if (!$other) {
+ common_log_db_error($subs, 'SELECT', __FILE__);
+ continue;
+ }
+
+ common_element_start('li');
+ common_element_start('a', array('title' => ($other->fullname) ?
+ $other->fullname :
+ $other->nickname,
+ 'href' => $other->profileurl,
+ 'rel' => 'contact',
+ 'class' => 'subscription'));
+ $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
+ common_element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
+ 'width' => AVATAR_MINI_SIZE,
+ 'height' => AVATAR_MINI_SIZE,
+ 'class' => 'avatar mini',
+ 'alt' => ($other->fullname) ?
+ $other->fullname :
+ $other->nickname));
+ common_element_end('a');
+ common_element_end('li');
+
+ }
- common_element_end('ul');
- common_element_end('div');
+ common_element_end('ul');
+ common_element_end('div');
- }
+ }
- // XXX Figure out a way to show all Twitter friends... ?
+ // XXX Figure out a way to show all Twitter friends... ?
- /*
- if ($subs_count > SUBSCRIPTIONS) {
- common_element_start('p', array('id' => 'subscriptions_viewall'));
+ /*
+ if ($subs_count > SUBSCRIPTIONS) {
+ common_element_start('p', array('id' => 'subscriptions_viewall'));
- common_element('a', array('href' => common_local_url('subscriptions',
- array('nickname' => $profile->nickname)),
- 'class' => 'moresubscriptions'),
- _('All subscriptions'));
- common_element_end('p');
- }
- */
+ common_element('a', array('href' => common_local_url('subscriptions',
+ array('nickname' => $profile->nickname)),
+ 'class' => 'moresubscriptions'),
+ _('All subscriptions'));
+ common_element_end('p');
+ }
+ */
- }
-
- function handle_post() {
+ }
+
+ function handle_post() {
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->show_form(_('There was a problem with your session token. Try again, please.'));
- return;
- }
-
- if ($this->arg('save')) {
- $this->save_preferences();
- } else if ($this->arg('add')) {
- $this->add_twitter_acct();
- } else if ($this->arg('remove')) {
- $this->remove_twitter_acct();
- } else {
- $this->show_form(_('Unexpected form submission.'));
- }
- }
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $this->show_form(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
+
+ if ($this->arg('save')) {
+ $this->save_preferences();
+ } else if ($this->arg('add')) {
+ $this->add_twitter_acct();
+ } else if ($this->arg('remove')) {
+ $this->remove_twitter_acct();
+ } else {
+ $this->show_form(_('Unexpected form submission.'));
+ }
+ }
- function add_twitter_acct() {
+ function add_twitter_acct() {
- $screen_name = $this->trimmed('twitter_username');
- $password = $this->trimmed('twitter_password');
- $noticesync = $this->boolean('noticesync');
- $replysync = $this->boolean('replysync');
- $friendsync = $this->boolean('friendsync');
-
- if (!Validate::string($screen_name,
- array( 'min_length' => 1,
- 'max_length' => 15,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA . '_'))) {
- $this->show_form(
- _('Username must have only numbers, upper- and lowercase letters, and underscore (_). 15 chars max.'));
- return;
- }
-
- if (!$this->verify_credentials($screen_name, $password)) {
- $this->show_form(_('Could not verify your Twitter credentials!'));
- return;
- }
-
- $twit_user = twitter_user_info($screen_name, $password);
-
- if (!$twit_user) {
- $this->show_form(sprintf(_('Unable to retrieve account information for "%s" from Twitter.'),
- $screen_name));
- return;
- }
-
- if (!save_twitter_user($twit_user->id, $screen_name)) {
- $this->show_form(_('Unable to save your Twitter settings!'));
- return;
- }
-
- $user = common_current_user();
-
- $flink = DB_DataObject::factory('foreign_link');
- $flink->user_id = $user->id;
- $flink->foreign_id = $twit_user->id;
- $flink->service = 1; // Twitter
- $flink->credentials = $password;
- $flink->created = common_sql_now();
-
- $this->set_flags($flink, $noticesync, $replysync, $friendsync);
-
- $flink_id = $flink->insert();
-
- if (!$flink_id) {
- common_log_db_error($flink, 'INSERT', __FILE__);
- $this->show_form(_('Unable to save your Twitter settings!'));
- return;
- }
+ $screen_name = $this->trimmed('twitter_username');
+ $password = $this->trimmed('twitter_password');
+ $noticesync = $this->boolean('noticesync');
+ $replysync = $this->boolean('replysync');
+ $friendsync = $this->boolean('friendsync');
+
+ if (!Validate::string($screen_name,
+ array( 'min_length' => 1,
+ 'max_length' => 15,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA . '_'))) {
+ $this->show_form(
+ _('Username must have only numbers, upper- and lowercase letters, and underscore (_). 15 chars max.'));
+ return;
+ }
+
+ if (!$this->verify_credentials($screen_name, $password)) {
+ $this->show_form(_('Could not verify your Twitter credentials!'));
+ return;
+ }
+
+ $twit_user = twitter_user_info($screen_name, $password);
+
+ if (!$twit_user) {
+ $this->show_form(sprintf(_('Unable to retrieve account information for "%s" from Twitter.'),
+ $screen_name));
+ return;
+ }
+
+ if (!save_twitter_user($twit_user->id, $screen_name)) {
+ $this->show_form(_('Unable to save your Twitter settings!'));
+ return;
+ }
+
+ $user = common_current_user();
+
+ $flink = DB_DataObject::factory('foreign_link');
+ $flink->user_id = $user->id;
+ $flink->foreign_id = $twit_user->id;
+ $flink->service = 1; // Twitter
+ $flink->credentials = $password;
+ $flink->created = common_sql_now();
+
+ $this->set_flags($flink, $noticesync, $replysync, $friendsync);
+
+ $flink_id = $flink->insert();
+
+ if (!$flink_id) {
+ common_log_db_error($flink, 'INSERT', __FILE__);
+ $this->show_form(_('Unable to save your Twitter settings!'));
+ return;
+ }
- if ($friendsync) {
- save_twitter_friends($user, $twit_user->id, $screen_name, $password);
- }
+ if ($friendsync) {
+ save_twitter_friends($user, $twit_user->id, $screen_name, $password);
+ }
- $this->show_form(_('Twitter settings saved.'), true);
- }
+ $this->show_form(_('Twitter settings saved.'), true);
+ }
- function remove_twitter_acct() {
-
- $user = common_current_user();
- $flink = Foreign_link::getByUserID($user->id, 1);
- $flink_foreign_id = $this->arg('flink_foreign_id');
-
- # Maybe an old tab open...?
- if ($flink->foreign_id != $flink_foreign_id) {
- $this->show_form(_('That is not your Twitter account.'));
- return;
- }
-
- $result = $flink->delete();
-
- if (!$result) {
- common_log_db_error($flink, 'DELETE', __FILE__);
- common_server_error(_('Couldn\'t remove Twitter user.'));
- return;
- }
-
- $this->show_form(_('Twitter account removed.'), TRUE);
- }
-
- function save_preferences() {
-
- $noticesync = $this->boolean('noticesync');
- $friendsync = $this->boolean('friendsync');
- $replysync = $this->boolean('replysync');
-
- $user = common_current_user();
-
- $flink = Foreign_link::getByUserID($user->id, 1);
-
- if (!$flink) {
- common_log_db_error($flink, 'SELECT', __FILE__);
- $this->show_form(_('Couldn\'t save Twitter preferences.'));
- return;
- }
+ function remove_twitter_acct() {
+
+ $user = common_current_user();
+ $flink = Foreign_link::getByUserID($user->id, 1);
+ $flink_foreign_id = $this->arg('flink_foreign_id');
+
+ # Maybe an old tab open...?
+ if ($flink->foreign_id != $flink_foreign_id) {
+ $this->show_form(_('That is not your Twitter account.'));
+ return;
+ }
+
+ $result = $flink->delete();
+
+ if (!$result) {
+ common_log_db_error($flink, 'DELETE', __FILE__);
+ common_server_error(_('Couldn\'t remove Twitter user.'));
+ return;
+ }
+
+ $this->show_form(_('Twitter account removed.'), TRUE);
+ }
+
+ function save_preferences() {
+
+ $noticesync = $this->boolean('noticesync');
+ $friendsync = $this->boolean('friendsync');
+ $replysync = $this->boolean('replysync');
+
+ $user = common_current_user();
+
+ $flink = Foreign_link::getByUserID($user->id, 1);
+
+ if (!$flink) {
+ common_log_db_error($flink, 'SELECT', __FILE__);
+ $this->show_form(_('Couldn\'t save Twitter preferences.'));
+ return;
+ }
- $twitter_id = $flink->foreign_id;
- $password = $flink->credentials;
-
- $fuser = $flink->getForeignUser();
+ $twitter_id = $flink->foreign_id;
+ $password = $flink->credentials;
+
+ $fuser = $flink->getForeignUser();
- if (!$fuser) {
- common_log_db_error($fuser, 'SELECT', __FILE__);
- $this->show_form(_('Couldn\'t save Twitter preferences.'));
- return;
- }
+ if (!$fuser) {
+ common_log_db_error($fuser, 'SELECT', __FILE__);
+ $this->show_form(_('Couldn\'t save Twitter preferences.'));
+ return;
+ }
- $screen_name = $fuser->nickname;
+ $screen_name = $fuser->nickname;
- $original = clone($flink);
- $this->set_flags($flink, $noticesync, $replysync, $friendsync);
- $result = $flink->update($original);
+ $original = clone($flink);
+ $this->set_flags($flink, $noticesync, $replysync, $friendsync);
+ $result = $flink->update($original);
- if ($result === FALSE) {
- common_log_db_error($flink, 'UPDATE', __FILE__);
- $this->show_form(_('Couldn\'t save Twitter preferences.'));
- return;
- }
+ if ($result === FALSE) {
+ common_log_db_error($flink, 'UPDATE', __FILE__);
+ $this->show_form(_('Couldn\'t save Twitter preferences.'));
+ return;
+ }
- if ($friendsync) {
- save_twitter_friends($user, $flink->foreign_id, $screen_name, $password);
- }
+ if ($friendsync) {
+ save_twitter_friends($user, $flink->foreign_id, $screen_name, $password);
+ }
- $this->show_form(_('Twitter preferences saved.'));
- }
+ $this->show_form(_('Twitter preferences saved.'));
+ }
- function verify_credentials($screen_name, $password) {
- $uri = 'http://twitter.com/account/verify_credentials.json';
- $data = get_twitter_data($uri, $screen_name, $password);
+ function verify_credentials($screen_name, $password) {
+ $uri = 'http://twitter.com/account/verify_credentials.json';
+ $data = get_twitter_data($uri, $screen_name, $password);
- if (!$data) {
- return false;
- }
+ if (!$data) {
+ return false;
+ }
- $user = json_decode($data);
+ $user = json_decode($data);
- if (!$user) {
- return false;
- }
+ if (!$user) {
+ return false;
+ }
- $twitter_id = $user->status->id;
+ $twitter_id = $user->status->id;
- if ($twitter_id) {
- return $twitter_id;
- }
+ if ($twitter_id) {
+ return $twitter_id;
+ }
- return false;
- }
+ return false;
+ }
- function set_flags(&$flink, $noticesync, $replysync, $friendsync) {
- if ($noticesync) {
- $flink->noticesync |= FOREIGN_NOTICE_SEND;
- } else {
- $flink->noticesync &= ~FOREIGN_NOTICE_SEND;
- }
+ function set_flags(&$flink, $noticesync, $replysync, $friendsync) {
+ if ($noticesync) {
+ $flink->noticesync |= FOREIGN_NOTICE_SEND;
+ } else {
+ $flink->noticesync &= ~FOREIGN_NOTICE_SEND;
+ }
- if ($replysync) {
- $flink->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
- } else {
- $flink->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
- }
+ if ($replysync) {
+ $flink->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
+ } else {
+ $flink->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
+ }
- if ($friendsync) {
- $flink->friendsync |= FOREIGN_FRIEND_RECV;
- } else {
- $flink->friendsync &= ~FOREIGN_FRIEND_RECV;
- }
+ if ($friendsync) {
+ $flink->friendsync |= FOREIGN_FRIEND_RECV;
+ } else {
+ $flink->friendsync &= ~FOREIGN_FRIEND_RECV;
+ }
- $flink->profilesync = 0;
- }
+ $flink->profilesync = 0;
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/unblock.php b/_darcs/pristine/actions/unblock.php
index d60cc7088..6a86c2bf0 100644
--- a/_darcs/pristine/actions/unblock.php
+++ b/_darcs/pristine/actions/unblock.php
@@ -32,12 +32,12 @@ class UnblockAction extends Action {
return false;
}
- $token = $this->trimmed('token');
+ $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
$id = $this->trimmed('unblockto');
diff --git a/_darcs/pristine/actions/unsubscribe.php b/_darcs/pristine/actions/unsubscribe.php
index 98291e897..38fcc21de 100644
--- a/_darcs/pristine/actions/unsubscribe.php
+++ b/_darcs/pristine/actions/unsubscribe.php
@@ -19,30 +19,30 @@
class UnsubscribeAction extends Action {
- function handle($args) {
- parent::handle($args);
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- return;
- }
+ function handle($args) {
+ parent::handle($args);
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ return;
+ }
- $user = common_current_user();
+ $user = common_current_user();
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)));
- return;
- }
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)));
+ return;
+ }
- # CSRF protection
+ # CSRF protection
- $token = $this->trimmed('token');
+ $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->client_error(_('There was a problem with your session token. Try again, please.'));
- return;
- }
+ if (!$token || $token != common_session_token()) {
+ $this->client_error(_('There was a problem with your session token. Try again, please.'));
+ return;
+ }
- $other_id = $this->arg('unsubscribeto');
+ $other_id = $this->arg('unsubscribeto');
if (!$other_id) {
$this->client_error(_('No profile id in request.'));
@@ -56,25 +56,25 @@ class UnsubscribeAction extends Action {
return;
}
- $result = subs_unsubscribe_to($user, $other);
+ $result = subs_unsubscribe_to($user, $other);
- if ($result != true) {
- common_user_error($result);
- return;
- }
+ if ($result != true) {
+ common_user_error($result);
+ return;
+ }
- if ($this->boolean('ajax')) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Unsubscribed'));
- common_element_end('head');
- common_element_start('body');
- common_subscribe_form($other);
- common_element_end('body');
- common_element_end('html');
- } else {
- common_redirect(common_local_url('subscriptions', array('nickname' =>
- $user->nickname)));
+ if ($this->boolean('ajax')) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Unsubscribed'));
+ common_element_end('head');
+ common_element_start('body');
+ common_subscribe_form($other);
+ common_element_end('body');
+ common_element_end('html');
+ } else {
+ common_redirect(common_local_url('subscriptions', array('nickname' =>
+ $user->nickname)));
}
- }
+ }
}
diff --git a/_darcs/pristine/actions/updateprofile.php b/_darcs/pristine/actions/updateprofile.php
index 921e88e63..4b4bb53a1 100644
--- a/_darcs/pristine/actions/updateprofile.php
+++ b/_darcs/pristine/actions/updateprofile.php
@@ -22,153 +22,153 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/lib/omb.php');
class UpdateprofileAction extends Action {
-
- function handle($args) {
- parent::handle($args);
- try {
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
- # Note: server-to-server function!
- $server = omb_oauth_server();
- list($consumer, $token) = $server->verify_request($req);
- if ($this->update_profile($req, $consumer, $token)) {
- print "omb_version=".OMB_VERSION_01;
- }
- } catch (OAuthException $e) {
- $this->server_error($e->getMessage());
- return;
- }
- }
+
+ function handle($args) {
+ parent::handle($args);
+ try {
+ common_remove_magic_from_request();
+ $req = OAuthRequest::from_request();
+ # Note: server-to-server function!
+ $server = omb_oauth_server();
+ list($consumer, $token) = $server->verify_request($req);
+ if ($this->update_profile($req, $consumer, $token)) {
+ print "omb_version=".OMB_VERSION_01;
+ }
+ } catch (OAuthException $e) {
+ $this->server_error($e->getMessage());
+ return;
+ }
+ }
- function update_profile($req, $consumer, $token) {
- $version = $req->get_parameter('omb_version');
- if ($version != OMB_VERSION_01) {
- $this->client_error(_('Unsupported OMB version'), 400);
- return false;
- }
- # First, check to see if listenee exists
- $listenee = $req->get_parameter('omb_listenee');
- $remote = Remote_profile::staticGet('uri', $listenee);
- if (!$remote) {
- $this->client_error(_('Profile unknown'), 404);
- return false;
- }
- # Second, check to see if they should be able to post updates!
- # We see if there are any subscriptions to that remote user with
- # the given token.
+ function update_profile($req, $consumer, $token) {
+ $version = $req->get_parameter('omb_version');
+ if ($version != OMB_VERSION_01) {
+ $this->client_error(_('Unsupported OMB version'), 400);
+ return false;
+ }
+ # First, check to see if listenee exists
+ $listenee = $req->get_parameter('omb_listenee');
+ $remote = Remote_profile::staticGet('uri', $listenee);
+ if (!$remote) {
+ $this->client_error(_('Profile unknown'), 404);
+ return false;
+ }
+ # Second, check to see if they should be able to post updates!
+ # We see if there are any subscriptions to that remote user with
+ # the given token.
- $sub = new Subscription();
- $sub->subscribed = $remote->id;
- $sub->token = $token->key;
- if (!$sub->find(true)) {
- $this->client_error(_('You did not send us that profile'), 403);
- return false;
- }
+ $sub = new Subscription();
+ $sub->subscribed = $remote->id;
+ $sub->token = $token->key;
+ if (!$sub->find(true)) {
+ $this->client_error(_('You did not send us that profile'), 403);
+ return false;
+ }
- $profile = Profile::staticGet('id', $remote->id);
- if (!$profile) {
- # This one is our fault
- $this->server_error(_('Remote profile with no matching profile'), 500);
- return false;
- }
- $nickname = $req->get_parameter('omb_listenee_nickname');
- if ($nickname && !Validate::string($nickname, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- $this->client_error(_('Nickname must have only lowercase letters and numbers and no spaces.'));
- return false;
- }
- $license = $req->get_parameter('omb_listenee_license');
- if ($license && !common_valid_http_url($license)) {
- $this->client_error(sprintf(_("Invalid license URL '%s'"), $license));
- return false;
- }
- $profile_url = $req->get_parameter('omb_listenee_profile');
- if ($profile_url && !common_valid_http_url($profile_url)) {
- $this->client_error(sprintf(_("Invalid profile URL '%s'."), $profile_url));
- return false;
- }
- # optional stuff
- $fullname = $req->get_parameter('omb_listenee_fullname');
- if ($fullname && strlen($fullname) > 255) {
- $this->client_error(_("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)) {
- $this->client_error(sprintf(_("Invalid homepage '%s'"), $homepage));
- return false;
- }
- $bio = $req->get_parameter('omb_listenee_bio');
- if ($bio && strlen($bio) > 140) {
- $this->client_error(_("Bio is too long (max 140 chars)."));
- return false;
- }
- $location = $req->get_parameter('omb_listenee_location');
- if ($location && strlen($location) > 255) {
- $this->client_error(_("Location is too long (max 255 chars)."));
- return false;
- }
- $avatar = $req->get_parameter('omb_listenee_avatar');
- if ($avatar) {
- if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
- $this->client_error(sprintf(_("Invalid avatar URL '%s'"), $avatar));
- return false;
- }
- $size = @getimagesize($avatar);
- if (!$size) {
- $this->client_error(sprintf(_("Can't read avatar URL '%s'"), $avatar));
- return false;
- }
- if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
- $this->client_error(sprintf(_("Wrong size image at '%s'"), $avatar));
- return false;
- }
- if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG,
- IMAGETYPE_PNG))) {
- $this->client_error(sprintf(_("Wrong image type for '%s'"), $avatar));
- return false;
- }
- }
+ $profile = Profile::staticGet('id', $remote->id);
+ if (!$profile) {
+ # This one is our fault
+ $this->server_error(_('Remote profile with no matching profile'), 500);
+ return false;
+ }
+ $nickname = $req->get_parameter('omb_listenee_nickname');
+ if ($nickname && !Validate::string($nickname, array('min_length' => 1,
+ 'max_length' => 64,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+ $this->client_error(_('Nickname must have only lowercase letters and numbers and no spaces.'));
+ return false;
+ }
+ $license = $req->get_parameter('omb_listenee_license');
+ if ($license && !common_valid_http_url($license)) {
+ $this->client_error(sprintf(_("Invalid license URL '%s'"), $license));
+ return false;
+ }
+ $profile_url = $req->get_parameter('omb_listenee_profile');
+ if ($profile_url && !common_valid_http_url($profile_url)) {
+ $this->client_error(sprintf(_("Invalid profile URL '%s'."), $profile_url));
+ return false;
+ }
+ # optional stuff
+ $fullname = $req->get_parameter('omb_listenee_fullname');
+ if ($fullname && strlen($fullname) > 255) {
+ $this->client_error(_("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)) {
+ $this->client_error(sprintf(_("Invalid homepage '%s'"), $homepage));
+ return false;
+ }
+ $bio = $req->get_parameter('omb_listenee_bio');
+ if ($bio && strlen($bio) > 140) {
+ $this->client_error(_("Bio is too long (max 140 chars)."));
+ return false;
+ }
+ $location = $req->get_parameter('omb_listenee_location');
+ if ($location && strlen($location) > 255) {
+ $this->client_error(_("Location is too long (max 255 chars)."));
+ return false;
+ }
+ $avatar = $req->get_parameter('omb_listenee_avatar');
+ if ($avatar) {
+ if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
+ $this->client_error(sprintf(_("Invalid avatar URL '%s'"), $avatar));
+ return false;
+ }
+ $size = @getimagesize($avatar);
+ if (!$size) {
+ $this->client_error(sprintf(_("Can't read avatar URL '%s'"), $avatar));
+ return false;
+ }
+ if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
+ $this->client_error(sprintf(_("Wrong size image at '%s'"), $avatar));
+ return false;
+ }
+ if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG,
+ IMAGETYPE_PNG))) {
+ $this->client_error(sprintf(_("Wrong image type for '%s'"), $avatar));
+ return false;
+ }
+ }
- $orig_profile = clone($profile);
+ $orig_profile = clone($profile);
- if ($nickname) {
- $profile->nickname = $nickname;
- }
- if ($profile_url) {
- $profile->profileurl = $profile_url;
- }
- if ($fullname) {
- $profile->fullname = $fullname;
- }
- if ($homepage) {
- $profile->homepage = $homepage;
- }
- if ($bio) {
- $profile->bio = $bio;
- }
- if ($location) {
- $profile->location = $location;
- }
+ if ($nickname) {
+ $profile->nickname = $nickname;
+ }
+ if ($profile_url) {
+ $profile->profileurl = $profile_url;
+ }
+ if ($fullname) {
+ $profile->fullname = $fullname;
+ }
+ if ($homepage) {
+ $profile->homepage = $homepage;
+ }
+ if ($bio) {
+ $profile->bio = $bio;
+ }
+ if ($location) {
+ $profile->location = $location;
+ }
- if (!$profile->update($orig_profile)) {
- $this->server_error(_('Could not save new profile info'), 500);
- return false;
- } else {
- if ($avatar) {
- $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
- copy($avatar, $temp_filename);
- if (!$profile->setOriginal($temp_filename)) {
- $this->server_error(_('Could not save avatar info'), 500);
- return false;
- }
- }
- header('HTTP/1.1 200 OK');
- header('Content-type: text/plain');
- print 'Updated profile';
- print "\n";
- return true;
- }
- }
+ if (!$profile->update($orig_profile)) {
+ $this->server_error(_('Could not save new profile info'), 500);
+ return false;
+ } else {
+ if ($avatar) {
+ $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
+ copy($avatar, $temp_filename);
+ if (!$profile->setOriginal($temp_filename)) {
+ $this->server_error(_('Could not save avatar info'), 500);
+ return false;
+ }
+ }
+ header('HTTP/1.1 200 OK');
+ header('Content-type: text/plain');
+ print 'Updated profile';
+ print "\n";
+ return true;
+ }
+ }
}
diff --git a/_darcs/pristine/actions/userauthorization.php b/_darcs/pristine/actions/userauthorization.php
index ac0a0728c..97809f197 100644
--- a/_darcs/pristine/actions/userauthorization.php
+++ b/_darcs/pristine/actions/userauthorization.php
@@ -24,556 +24,556 @@ define('TIMESTAMP_THRESHOLD', 300);
class UserauthorizationAction extends Action {
- function handle($args) {
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- # CSRF protection
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $req = $this->get_stored_request();
- $this->show_form(_('There was a problem with your session token. Try again, please.'), $req);
- return;
- }
- # We've shown the form, now post user's choice
- $this->send_authorization();
- } else {
- if (!common_logged_in()) {
- # Go log in, and then come back
- common_debug('saving URL for returnto', __FILE__);
- common_set_returnto($_SERVER['REQUEST_URI']);
-
- common_debug('redirecting to login', __FILE__);
- common_redirect(common_local_url('login'));
- return;
- }
- try {
- # this must be a new request
- common_debug('getting new request', __FILE__);
- $req = $this->get_new_request();
- if (!$req) {
- $this->client_error(_('No request found!'));
- }
- common_debug('validating request', __FILE__);
- # XXX: only validate new requests, since nonce is one-time use
- $this->validate_request($req);
- common_debug('showing form', __FILE__);
- $this->store_request($req);
- $this->show_form($req);
- } catch (OAuthException $e) {
- $this->clear_request();
- $this->client_error($e->getMessage());
- return;
- }
-
- }
- }
-
- function show_form($req) {
-
- $nickname = $req->get_parameter('omb_listenee_nickname');
- $profile = $req->get_parameter('omb_listenee_profile');
- $license = $req->get_parameter('omb_listenee_license');
- $fullname = $req->get_parameter('omb_listenee_fullname');
- $homepage = $req->get_parameter('omb_listenee_homepage');
- $bio = $req->get_parameter('omb_listenee_bio');
- $location = $req->get_parameter('omb_listenee_location');
- $avatar = $req->get_parameter('omb_listenee_avatar');
-
- common_show_header(_('Authorize subscription'));
- common_element('p', NULL, _('Please check these details to make sure '.
- 'that you want to subscribe to this user\'s notices. '.
- 'If you didn\'t just ask to subscribe to someone\'s notices, '.
- 'click "Cancel".'));
- common_element_start('div', 'profile');
- if ($avatar) {
- common_element('img', array('src' => $avatar,
- 'class' => 'avatar profile',
- 'width' => AVATAR_PROFILE_SIZE,
- 'height' => AVATAR_PROFILE_SIZE,
- 'alt' => $nickname));
- }
- common_element('a', array('href' => $profile,
- 'class' => 'external profile nickname'),
- $nickname);
- if ($fullname) {
- common_element_start('div', 'fullname');
- if ($homepage) {
- common_element('a', array('href' => $homepage),
- $fullname);
- } else {
- common_text($fullname);
- }
- common_element_end('div');
- }
- if ($location) {
- common_element('div', 'location', $location);
- }
- if ($bio) {
- common_element('div', 'bio', $bio);
- }
- common_element_start('div', 'license');
- common_element('a', array('href' => $license,
- 'class' => 'license'),
- $license);
- common_element_end('div');
- common_element_end('div');
- common_element_start('form', array('method' => 'post',
- 'id' => 'userauthorization',
- 'name' => 'userauthorization',
- 'action' => common_local_url('userauthorization')));
- common_hidden('token', common_session_token());
- common_submit('accept', _('Accept'));
- common_submit('reject', _('Reject'));
- common_element_end('form');
- common_show_footer();
- }
-
- function send_authorization() {
- $req = $this->get_stored_request();
-
- if (!$req) {
- common_user_error(_('No authorization request!'));
- return;
- }
-
- $callback = $req->get_parameter('oauth_callback');
-
- if ($this->arg('accept')) {
- if (!$this->authorize_token($req)) {
- $this->client_error(_('Error authorizing token'));
- }
- if (!$this->save_remote_profile($req)) {
- $this->client_error(_('Error saving remote profile'));
- }
- if (!$callback) {
- $this->show_accept_message($req->get_parameter('oauth_token'));
- } else {
- $params = array();
- $params['oauth_token'] = $req->get_parameter('oauth_token');
- $params['omb_version'] = OMB_VERSION_01;
- $user = User::staticGet('uri', $req->get_parameter('omb_listener'));
- $profile = $user->getProfile();
- if (!$profile) {
- common_log_db_error($user, 'SELECT', __FILE__);
- $this->server_error(_('User without matching profile'));
- return;
- }
- $params['omb_listener_nickname'] = $user->nickname;
- $params['omb_listener_profile'] = common_local_url('showstream',
- array('nickname' => $user->nickname));
- if ($profile->fullname) {
- $params['omb_listener_fullname'] = $profile->fullname;
- }
- if ($profile->homepage) {
- $params['omb_listener_homepage'] = $profile->homepage;
- }
- if ($profile->bio) {
- $params['omb_listener_bio'] = $profile->bio;
- }
- if ($profile->location) {
- $params['omb_listener_location'] = $profile->location;
- }
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- if ($avatar) {
- $params['omb_listener_avatar'] = $avatar->url;
- }
- $parts = array();
- foreach ($params as $k => $v) {
- $parts[] = $k . '=' . OAuthUtil::urlencodeRFC3986($v);
- }
- $query_string = implode('&', $parts);
- $parsed = parse_url($callback);
- $url = $callback . (($parsed['query']) ? '&' : '?') . $query_string;
- common_redirect($url, 303);
- }
- } else {
- if (!$callback) {
- $this->show_reject_message();
- } else {
- # XXX: not 100% sure how to signal failure... just redirect without token?
- common_redirect($callback, 303);
- }
- }
- }
-
- function authorize_token(&$req) {
- $consumer_key = $req->get_parameter('oauth_consumer_key');
- $token_field = $req->get_parameter('oauth_token');
- common_debug('consumer key = "'.$consumer_key.'"', __FILE__);
- common_debug('token field = "'.$token_field.'"', __FILE__);
- $rt = new Token();
- $rt->consumer_key = $consumer_key;
- $rt->tok = $token_field;
- $rt->type = 0;
- $rt->state = 0;
- common_debug('request token to look up: "'.print_r($rt,TRUE).'"');
- if ($rt->find(true)) {
- common_debug('found request token to authorize', __FILE__);
- $orig_rt = clone($rt);
- $rt->state = 1; # Authorized but not used
- if ($rt->update($orig_rt)) {
- common_debug('updated request token so it is authorized', __FILE__);
- return true;
- }
- }
- return FALSE;
- }
-
- # XXX: refactor with similar code in finishremotesubscribe.php
-
- function save_remote_profile(&$req) {
- # FIXME: we should really do this when the consumer comes
- # back for an access token. If they never do, we've got stuff in a
- # weird state.
-
- $nickname = $req->get_parameter('omb_listenee_nickname');
- $fullname = $req->get_parameter('omb_listenee_fullname');
- $profile_url = $req->get_parameter('omb_listenee_profile');
- $homepage = $req->get_parameter('omb_listenee_homepage');
- $bio = $req->get_parameter('omb_listenee_bio');
- $location = $req->get_parameter('omb_listenee_location');
- $avatar_url = $req->get_parameter('omb_listenee_avatar');
-
- $listenee = $req->get_parameter('omb_listenee');
- $remote = Remote_profile::staticGet('uri', $listenee);
-
- if ($remote) {
- $exists = true;
- $profile = Profile::staticGet($remote->id);
- $orig_remote = clone($remote);
- $orig_profile = clone($profile);
- } else {
- $exists = false;
- $remote = new Remote_profile();
- $remote->uri = $listenee;
- $profile = new Profile();
- }
-
- $profile->nickname = $nickname;
- $profile->profileurl = $profile_url;
-
- if ($fullname) {
- $profile->fullname = $fullname;
- }
- if ($homepage) {
- $profile->homepage = $homepage;
- }
- if ($bio) {
- $profile->bio = $bio;
- }
- if ($location) {
- $profile->location = $location;
- }
-
- if ($exists) {
- $profile->update($orig_profile);
- } else {
- $profile->created = DB_DataObject_Cast::dateTime(); # current time
- $id = $profile->insert();
- if (!$id) {
- return FALSE;
- }
- $remote->id = $id;
- }
-
- if ($exists) {
- if (!$remote->update($orig_remote)) {
- return FALSE;
- }
- } else {
- $remote->created = DB_DataObject_Cast::dateTime(); # current time
- if (!$remote->insert()) {
- return FALSE;
- }
- }
-
- if ($avatar_url) {
- if (!$this->add_avatar($profile, $avatar_url)) {
- return FALSE;
- }
- }
-
- $user = common_current_user();
- $datastore = omb_oauth_datastore();
- $consumer = $this->get_consumer($datastore, $req);
- $token = $this->get_token($datastore, $req, $consumer);
-
- $sub = new Subscription();
- $sub->subscriber = $user->id;
- $sub->subscribed = $remote->id;
- $sub->token = $token->key; # NOTE: request token, not valid for use!
- $sub->created = DB_DataObject_Cast::dateTime(); # current time
-
- if (!$sub->insert()) {
- return FALSE;
- }
-
- return TRUE;
- }
-
- function add_avatar($profile, $url) {
- $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
- copy($url, $temp_filename);
- return $profile->setOriginal($temp_filename);
- }
-
- function show_accept_message($tok) {
- common_show_header(_('Subscription authorized'));
- common_element('p', NULL,
- _('The subscription has been authorized, but no '.
- 'callback URL was passed. Check with the site\'s instructions for '.
- 'details on how to authorize the subscription. Your subscription token is:'));
- common_element('blockquote', 'token', $tok);
- common_show_footer();
- }
-
- function show_reject_message($tok) {
- common_show_header(_('Subscription rejected'));
- common_element('p', NULL,
- _('The subscription has been rejected, but no '.
- 'callback URL was passed. Check with the site\'s instructions for '.
- 'details on how to fully reject the subscription.'));
- common_show_footer();
- }
-
- function store_request($req) {
- common_ensure_session();
- $_SESSION['userauthorizationrequest'] = $req;
- }
-
- function clear_request() {
- common_ensure_session();
- unset($_SESSION['userauthorizationrequest']);
- }
-
- function get_stored_request() {
- common_ensure_session();
- $req = $_SESSION['userauthorizationrequest'];
- return $req;
- }
-
- function get_new_request() {
- common_remove_magic_from_request();
- $req = OAuthRequest::from_request();
- return $req;
- }
-
- # Throws an OAuthException if anything goes wrong
-
- function validate_request(&$req) {
- # OAuth stuff -- have to copy from OAuth.php since they're
- # all private methods, and there's no user-authentication method
- common_debug('checking version', __FILE__);
- $this->check_version($req);
- common_debug('getting datastore', __FILE__);
- $datastore = omb_oauth_datastore();
- common_debug('getting consumer', __FILE__);
- $consumer = $this->get_consumer($datastore, $req);
- common_debug('getting token', __FILE__);
- $token = $this->get_token($datastore, $req, $consumer);
- common_debug('checking timestamp', __FILE__);
- $this->check_timestamp($req);
- common_debug('checking nonce', __FILE__);
- $this->check_nonce($datastore, $req, $consumer, $token);
- common_debug('checking signature', __FILE__);
- $this->check_signature($req, $consumer, $token);
- common_debug('validating omb stuff', __FILE__);
- $this->validate_omb($req);
- common_debug('done validating', __FILE__);
- return true;
- }
-
- function validate_omb(&$req) {
- foreach (array('omb_version', 'omb_listener', 'omb_listenee',
- 'omb_listenee_profile', 'omb_listenee_nickname',
- 'omb_listenee_license') as $param)
- {
- if (!$req->get_parameter($param)) {
- throw new OAuthException("Required parameter '$param' not found");
- }
- }
- # Now, OMB stuff
- $version = $req->get_parameter('omb_version');
- if ($version != OMB_VERSION_01) {
- throw new OAuthException("OpenMicroBlogging version '$version' not supported");
- }
- $listener = $req->get_parameter('omb_listener');
- $user = User::staticGet('uri', $listener);
- if (!$user) {
- throw new OAuthException("Listener URI '$listener' not found here");
- }
- $cur = common_current_user();
- if ($cur->id != $user->id) {
- throw new OAuthException("Can't add for another user!");
- }
- $listenee = $req->get_parameter('omb_listenee');
- if (!Validate::uri($listenee) &&
- !common_valid_tag($listenee)) {
- throw new OAuthException("Listenee URI '$listenee' not a recognizable URI");
- }
- if (strlen($listenee) > 255) {
- throw new OAuthException("Listenee URI '$listenee' too long");
- }
-
- $other = User::staticGet('uri', $listenee);
- if ($other) {
- throw new OAuthException("Listenee URI '$listenee' is local user");
- }
-
- $remote = Remote_profile::staticGet('uri', $listenee);
- if ($remote) {
- $sub = new Subscription();
- $sub->subscriber = $user->id;
- $sub->subscribed = $remote->id;
- if ($sub->find(TRUE)) {
- throw new OAuthException("Already subscribed to user!");
- }
- }
- $nickname = $req->get_parameter('omb_listenee_nickname');
- if (!Validate::string($nickname, array('min_length' => 1,
- 'max_length' => 64,
- 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
- throw new OAuthException('Nickname must have only letters and numbers and no spaces.');
- }
- $profile = $req->get_parameter('omb_listenee_profile');
- if (!common_valid_http_url($profile)) {
- throw new OAuthException("Invalid profile URL '$profile'.");
- }
-
- if ($profile == common_local_url('showstream', array('nickname' => $nickname))) {
- throw new OAuthException("Profile URL '$profile' is for a local user.");
- }
-
- $license = $req->get_parameter('omb_listenee_license');
- if (!common_valid_http_url($license)) {
- throw new OAuthException("Invalid license URL '$license'.");
- }
- $site_license = common_config('license', 'url');
- if (!common_compatible_license($license, $site_license)) {
- throw new OAuthException("Listenee stream license '$license' not compatible with site license '$site_license'.");
- }
- # optional stuff
- $fullname = $req->get_parameter('omb_listenee_fullname');
- if ($fullname && 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)) {
- throw new OAuthException("Invalid homepage '$homepage'");
- }
- $bio = $req->get_parameter('omb_listenee_bio');
- if ($bio && strlen($bio) > 140) {
- throw new OAuthException("Bio too long '$bio'");
- }
- $location = $req->get_parameter('omb_listenee_location');
- if ($location && strlen($location) > 255) {
- throw new OAuthException("Location too long '$location'");
- }
- $avatar = $req->get_parameter('omb_listenee_avatar');
- if ($avatar) {
- if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
- throw new OAuthException("Invalid avatar URL '$avatar'");
- }
- $size = @getimagesize($avatar);
- if (!$size) {
- throw new OAuthException("Can't read avatar URL '$avatar'");
- }
- if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
- throw new OAuthException("Wrong size image at '$avatar'");
- }
- if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG,
- IMAGETYPE_PNG))) {
- throw new OAuthException("Wrong image type for '$avatar'");
- }
- }
- $callback = $req->get_parameter('oauth_callback');
- if ($callback && !common_valid_http_url($callback)) {
- throw new OAuthException("Invalid callback URL '$callback'");
- }
- if ($callback && $callback == common_local_url('finishremotesubscribe')) {
- throw new OAuthException("Callback URL '$callback' is for local site.");
- }
- }
-
- # Snagged from OAuthServer
-
- function check_version(&$req) {
- $version = $req->get_parameter("oauth_version");
- if (!$version) {
- $version = 1.0;
- }
- if ($version != 1.0) {
- throw new OAuthException("OAuth version '$version' not supported");
- }
- return $version;
- }
-
- # Snagged from OAuthServer
-
- function get_consumer($datastore, $req) {
- $consumer_key = @$req->get_parameter("oauth_consumer_key");
- if (!$consumer_key) {
- throw new OAuthException("Invalid consumer key");
- }
-
- $consumer = $datastore->lookup_consumer($consumer_key);
- if (!$consumer) {
- throw new OAuthException("Invalid consumer");
- }
- return $consumer;
- }
-
- # Mostly cadged from OAuthServer
-
- function get_token($datastore, &$req, $consumer) {/*{{{*/
- $token_field = @$req->get_parameter('oauth_token');
- $token = $datastore->lookup_token($consumer, 'request', $token_field);
- if (!$token) {
- throw new OAuthException("Invalid $token_type token: $token_field");
- }
- return $token;
- }
-
- function check_timestamp(&$req) {
- $timestamp = @$req->get_parameter('oauth_timestamp');
- $now = time();
- if ($now - $timestamp > TIMESTAMP_THRESHOLD) {
- throw new OAuthException("Expired timestamp, yours $timestamp, ours $now");
- }
- }
-
- # NOTE: don't call twice on the same request; will fail!
- function check_nonce(&$datastore, &$req, $consumer, $token) {
- $timestamp = @$req->get_parameter('oauth_timestamp');
- $nonce = @$req->get_parameter('oauth_nonce');
- $found = $datastore->lookup_nonce($consumer, $token, $nonce, $timestamp);
- if ($found) {
- throw new OAuthException("Nonce already used");
- }
- return true;
- }
-
- function check_signature(&$req, $consumer, $token) {
- $signature_method = $this->get_signature_method($req);
- $signature = $req->get_parameter('oauth_signature');
- $valid_sig = $signature_method->check_signature($req,
- $consumer,
- $token,
- $signature);
- if (!$valid_sig) {
- throw new OAuthException("Invalid signature");
- }
- }
-
- function get_signature_method(&$req) {
- $signature_method = @$req->get_parameter("oauth_signature_method");
- if (!$signature_method) {
- $signature_method = "PLAINTEXT";
- }
- if ($signature_method != 'HMAC-SHA1') {
- throw new OAuthException("Signature method '$signature_method' not supported.");
- }
- return omb_hmac_sha1();
- }
+ function handle($args) {
+ parent::handle($args);
+
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ # CSRF protection
+ $token = $this->trimmed('token');
+ if (!$token || $token != common_session_token()) {
+ $req = $this->get_stored_request();
+ $this->show_form(_('There was a problem with your session token. Try again, please.'), $req);
+ return;
+ }
+ # We've shown the form, now post user's choice
+ $this->send_authorization();
+ } else {
+ if (!common_logged_in()) {
+ # Go log in, and then come back
+ common_debug('saving URL for returnto', __FILE__);
+ common_set_returnto($_SERVER['REQUEST_URI']);
+
+ common_debug('redirecting to login', __FILE__);
+ common_redirect(common_local_url('login'));
+ return;
+ }
+ try {
+ # this must be a new request
+ common_debug('getting new request', __FILE__);
+ $req = $this->get_new_request();
+ if (!$req) {
+ $this->client_error(_('No request found!'));
+ }
+ common_debug('validating request', __FILE__);
+ # XXX: only validate new requests, since nonce is one-time use
+ $this->validate_request($req);
+ common_debug('showing form', __FILE__);
+ $this->store_request($req);
+ $this->show_form($req);
+ } catch (OAuthException $e) {
+ $this->clear_request();
+ $this->client_error($e->getMessage());
+ return;
+ }
+
+ }
+ }
+
+ function show_form($req) {
+
+ $nickname = $req->get_parameter('omb_listenee_nickname');
+ $profile = $req->get_parameter('omb_listenee_profile');
+ $license = $req->get_parameter('omb_listenee_license');
+ $fullname = $req->get_parameter('omb_listenee_fullname');
+ $homepage = $req->get_parameter('omb_listenee_homepage');
+ $bio = $req->get_parameter('omb_listenee_bio');
+ $location = $req->get_parameter('omb_listenee_location');
+ $avatar = $req->get_parameter('omb_listenee_avatar');
+
+ common_show_header(_('Authorize subscription'));
+ common_element('p', NULL, _('Please check these details to make sure '.
+ 'that you want to subscribe to this user\'s notices. '.
+ 'If you didn\'t just ask to subscribe to someone\'s notices, '.
+ 'click "Cancel".'));
+ common_element_start('div', 'profile');
+ if ($avatar) {
+ common_element('img', array('src' => $avatar,
+ 'class' => 'avatar profile',
+ 'width' => AVATAR_PROFILE_SIZE,
+ 'height' => AVATAR_PROFILE_SIZE,
+ 'alt' => $nickname));
+ }
+ common_element('a', array('href' => $profile,
+ 'class' => 'external profile nickname'),
+ $nickname);
+ if ($fullname) {
+ common_element_start('div', 'fullname');
+ if ($homepage) {
+ common_element('a', array('href' => $homepage),
+ $fullname);
+ } else {
+ common_text($fullname);
+ }
+ common_element_end('div');
+ }
+ if ($location) {
+ common_element('div', 'location', $location);
+ }
+ if ($bio) {
+ common_element('div', 'bio', $bio);
+ }
+ common_element_start('div', 'license');
+ common_element('a', array('href' => $license,
+ 'class' => 'license'),
+ $license);
+ common_element_end('div');
+ common_element_end('div');
+ common_element_start('form', array('method' => 'post',
+ 'id' => 'userauthorization',
+ 'name' => 'userauthorization',
+ 'action' => common_local_url('userauthorization')));
+ common_hidden('token', common_session_token());
+ common_submit('accept', _('Accept'));
+ common_submit('reject', _('Reject'));
+ common_element_end('form');
+ common_show_footer();
+ }
+
+ function send_authorization() {
+ $req = $this->get_stored_request();
+
+ if (!$req) {
+ common_user_error(_('No authorization request!'));
+ return;
+ }
+
+ $callback = $req->get_parameter('oauth_callback');
+
+ if ($this->arg('accept')) {
+ if (!$this->authorize_token($req)) {
+ $this->client_error(_('Error authorizing token'));
+ }
+ if (!$this->save_remote_profile($req)) {
+ $this->client_error(_('Error saving remote profile'));
+ }
+ if (!$callback) {
+ $this->show_accept_message($req->get_parameter('oauth_token'));
+ } else {
+ $params = array();
+ $params['oauth_token'] = $req->get_parameter('oauth_token');
+ $params['omb_version'] = OMB_VERSION_01;
+ $user = User::staticGet('uri', $req->get_parameter('omb_listener'));
+ $profile = $user->getProfile();
+ if (!$profile) {
+ common_log_db_error($user, 'SELECT', __FILE__);
+ $this->server_error(_('User without matching profile'));
+ return;
+ }
+ $params['omb_listener_nickname'] = $user->nickname;
+ $params['omb_listener_profile'] = common_local_url('showstream',
+ array('nickname' => $user->nickname));
+ if ($profile->fullname) {
+ $params['omb_listener_fullname'] = $profile->fullname;
+ }
+ if ($profile->homepage) {
+ $params['omb_listener_homepage'] = $profile->homepage;
+ }
+ if ($profile->bio) {
+ $params['omb_listener_bio'] = $profile->bio;
+ }
+ if ($profile->location) {
+ $params['omb_listener_location'] = $profile->location;
+ }
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ if ($avatar) {
+ $params['omb_listener_avatar'] = $avatar->url;
+ }
+ $parts = array();
+ foreach ($params as $k => $v) {
+ $parts[] = $k . '=' . OAuthUtil::urlencodeRFC3986($v);
+ }
+ $query_string = implode('&', $parts);
+ $parsed = parse_url($callback);
+ $url = $callback . (($parsed['query']) ? '&' : '?') . $query_string;
+ common_redirect($url, 303);
+ }
+ } else {
+ if (!$callback) {
+ $this->show_reject_message();
+ } else {
+ # XXX: not 100% sure how to signal failure... just redirect without token?
+ common_redirect($callback, 303);
+ }
+ }
+ }
+
+ function authorize_token(&$req) {
+ $consumer_key = $req->get_parameter('oauth_consumer_key');
+ $token_field = $req->get_parameter('oauth_token');
+ common_debug('consumer key = "'.$consumer_key.'"', __FILE__);
+ common_debug('token field = "'.$token_field.'"', __FILE__);
+ $rt = new Token();
+ $rt->consumer_key = $consumer_key;
+ $rt->tok = $token_field;
+ $rt->type = 0;
+ $rt->state = 0;
+ common_debug('request token to look up: "'.print_r($rt,TRUE).'"');
+ if ($rt->find(true)) {
+ common_debug('found request token to authorize', __FILE__);
+ $orig_rt = clone($rt);
+ $rt->state = 1; # Authorized but not used
+ if ($rt->update($orig_rt)) {
+ common_debug('updated request token so it is authorized', __FILE__);
+ return true;
+ }
+ }
+ return FALSE;
+ }
+
+ # XXX: refactor with similar code in finishremotesubscribe.php
+
+ function save_remote_profile(&$req) {
+ # FIXME: we should really do this when the consumer comes
+ # back for an access token. If they never do, we've got stuff in a
+ # weird state.
+
+ $nickname = $req->get_parameter('omb_listenee_nickname');
+ $fullname = $req->get_parameter('omb_listenee_fullname');
+ $profile_url = $req->get_parameter('omb_listenee_profile');
+ $homepage = $req->get_parameter('omb_listenee_homepage');
+ $bio = $req->get_parameter('omb_listenee_bio');
+ $location = $req->get_parameter('omb_listenee_location');
+ $avatar_url = $req->get_parameter('omb_listenee_avatar');
+
+ $listenee = $req->get_parameter('omb_listenee');
+ $remote = Remote_profile::staticGet('uri', $listenee);
+
+ if ($remote) {
+ $exists = true;
+ $profile = Profile::staticGet($remote->id);
+ $orig_remote = clone($remote);
+ $orig_profile = clone($profile);
+ } else {
+ $exists = false;
+ $remote = new Remote_profile();
+ $remote->uri = $listenee;
+ $profile = new Profile();
+ }
+
+ $profile->nickname = $nickname;
+ $profile->profileurl = $profile_url;
+
+ if ($fullname) {
+ $profile->fullname = $fullname;
+ }
+ if ($homepage) {
+ $profile->homepage = $homepage;
+ }
+ if ($bio) {
+ $profile->bio = $bio;
+ }
+ if ($location) {
+ $profile->location = $location;
+ }
+
+ if ($exists) {
+ $profile->update($orig_profile);
+ } else {
+ $profile->created = DB_DataObject_Cast::dateTime(); # current time
+ $id = $profile->insert();
+ if (!$id) {
+ return FALSE;
+ }
+ $remote->id = $id;
+ }
+
+ if ($exists) {
+ if (!$remote->update($orig_remote)) {
+ return FALSE;
+ }
+ } else {
+ $remote->created = DB_DataObject_Cast::dateTime(); # current time
+ if (!$remote->insert()) {
+ return FALSE;
+ }
+ }
+
+ if ($avatar_url) {
+ if (!$this->add_avatar($profile, $avatar_url)) {
+ return FALSE;
+ }
+ }
+
+ $user = common_current_user();
+ $datastore = omb_oauth_datastore();
+ $consumer = $this->get_consumer($datastore, $req);
+ $token = $this->get_token($datastore, $req, $consumer);
+
+ $sub = new Subscription();
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $remote->id;
+ $sub->token = $token->key; # NOTE: request token, not valid for use!
+ $sub->created = DB_DataObject_Cast::dateTime(); # current time
+
+ if (!$sub->insert()) {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ function add_avatar($profile, $url) {
+ $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
+ copy($url, $temp_filename);
+ return $profile->setOriginal($temp_filename);
+ }
+
+ function show_accept_message($tok) {
+ common_show_header(_('Subscription authorized'));
+ common_element('p', NULL,
+ _('The subscription has been authorized, but no '.
+ 'callback URL was passed. Check with the site\'s instructions for '.
+ 'details on how to authorize the subscription. Your subscription token is:'));
+ common_element('blockquote', 'token', $tok);
+ common_show_footer();
+ }
+
+ function show_reject_message($tok) {
+ common_show_header(_('Subscription rejected'));
+ common_element('p', NULL,
+ _('The subscription has been rejected, but no '.
+ 'callback URL was passed. Check with the site\'s instructions for '.
+ 'details on how to fully reject the subscription.'));
+ common_show_footer();
+ }
+
+ function store_request($req) {
+ common_ensure_session();
+ $_SESSION['userauthorizationrequest'] = $req;
+ }
+
+ function clear_request() {
+ common_ensure_session();
+ unset($_SESSION['userauthorizationrequest']);
+ }
+
+ function get_stored_request() {
+ common_ensure_session();
+ $req = $_SESSION['userauthorizationrequest'];
+ return $req;
+ }
+
+ function get_new_request() {
+ common_remove_magic_from_request();
+ $req = OAuthRequest::from_request();
+ return $req;
+ }
+
+ # Throws an OAuthException if anything goes wrong
+
+ function validate_request(&$req) {
+ # OAuth stuff -- have to copy from OAuth.php since they're
+ # all private methods, and there's no user-authentication method
+ common_debug('checking version', __FILE__);
+ $this->check_version($req);
+ common_debug('getting datastore', __FILE__);
+ $datastore = omb_oauth_datastore();
+ common_debug('getting consumer', __FILE__);
+ $consumer = $this->get_consumer($datastore, $req);
+ common_debug('getting token', __FILE__);
+ $token = $this->get_token($datastore, $req, $consumer);
+ common_debug('checking timestamp', __FILE__);
+ $this->check_timestamp($req);
+ common_debug('checking nonce', __FILE__);
+ $this->check_nonce($datastore, $req, $consumer, $token);
+ common_debug('checking signature', __FILE__);
+ $this->check_signature($req, $consumer, $token);
+ common_debug('validating omb stuff', __FILE__);
+ $this->validate_omb($req);
+ common_debug('done validating', __FILE__);
+ return true;
+ }
+
+ function validate_omb(&$req) {
+ foreach (array('omb_version', 'omb_listener', 'omb_listenee',
+ 'omb_listenee_profile', 'omb_listenee_nickname',
+ 'omb_listenee_license') as $param)
+ {
+ if (!$req->get_parameter($param)) {
+ throw new OAuthException("Required parameter '$param' not found");
+ }
+ }
+ # Now, OMB stuff
+ $version = $req->get_parameter('omb_version');
+ if ($version != OMB_VERSION_01) {
+ throw new OAuthException("OpenMicroBlogging version '$version' not supported");
+ }
+ $listener = $req->get_parameter('omb_listener');
+ $user = User::staticGet('uri', $listener);
+ if (!$user) {
+ throw new OAuthException("Listener URI '$listener' not found here");
+ }
+ $cur = common_current_user();
+ if ($cur->id != $user->id) {
+ throw new OAuthException("Can't add for another user!");
+ }
+ $listenee = $req->get_parameter('omb_listenee');
+ if (!Validate::uri($listenee) &&
+ !common_valid_tag($listenee)) {
+ throw new OAuthException("Listenee URI '$listenee' not a recognizable URI");
+ }
+ if (strlen($listenee) > 255) {
+ throw new OAuthException("Listenee URI '$listenee' too long");
+ }
+
+ $other = User::staticGet('uri', $listenee);
+ if ($other) {
+ throw new OAuthException("Listenee URI '$listenee' is local user");
+ }
+
+ $remote = Remote_profile::staticGet('uri', $listenee);
+ if ($remote) {
+ $sub = new Subscription();
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $remote->id;
+ if ($sub->find(TRUE)) {
+ throw new OAuthException("Already subscribed to user!");
+ }
+ }
+ $nickname = $req->get_parameter('omb_listenee_nickname');
+ if (!Validate::string($nickname, array('min_length' => 1,
+ 'max_length' => 64,
+ 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+ throw new OAuthException('Nickname must have only letters and numbers and no spaces.');
+ }
+ $profile = $req->get_parameter('omb_listenee_profile');
+ if (!common_valid_http_url($profile)) {
+ throw new OAuthException("Invalid profile URL '$profile'.");
+ }
+
+ if ($profile == common_local_url('showstream', array('nickname' => $nickname))) {
+ throw new OAuthException("Profile URL '$profile' is for a local user.");
+ }
+
+ $license = $req->get_parameter('omb_listenee_license');
+ if (!common_valid_http_url($license)) {
+ throw new OAuthException("Invalid license URL '$license'.");
+ }
+ $site_license = common_config('license', 'url');
+ if (!common_compatible_license($license, $site_license)) {
+ throw new OAuthException("Listenee stream license '$license' not compatible with site license '$site_license'.");
+ }
+ # optional stuff
+ $fullname = $req->get_parameter('omb_listenee_fullname');
+ if ($fullname && 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)) {
+ throw new OAuthException("Invalid homepage '$homepage'");
+ }
+ $bio = $req->get_parameter('omb_listenee_bio');
+ if ($bio && strlen($bio) > 140) {
+ throw new OAuthException("Bio too long '$bio'");
+ }
+ $location = $req->get_parameter('omb_listenee_location');
+ if ($location && strlen($location) > 255) {
+ throw new OAuthException("Location too long '$location'");
+ }
+ $avatar = $req->get_parameter('omb_listenee_avatar');
+ if ($avatar) {
+ if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
+ throw new OAuthException("Invalid avatar URL '$avatar'");
+ }
+ $size = @getimagesize($avatar);
+ if (!$size) {
+ throw new OAuthException("Can't read avatar URL '$avatar'");
+ }
+ if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
+ throw new OAuthException("Wrong size image at '$avatar'");
+ }
+ if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG,
+ IMAGETYPE_PNG))) {
+ throw new OAuthException("Wrong image type for '$avatar'");
+ }
+ }
+ $callback = $req->get_parameter('oauth_callback');
+ if ($callback && !common_valid_http_url($callback)) {
+ throw new OAuthException("Invalid callback URL '$callback'");
+ }
+ if ($callback && $callback == common_local_url('finishremotesubscribe')) {
+ throw new OAuthException("Callback URL '$callback' is for local site.");
+ }
+ }
+
+ # Snagged from OAuthServer
+
+ function check_version(&$req) {
+ $version = $req->get_parameter("oauth_version");
+ if (!$version) {
+ $version = 1.0;
+ }
+ if ($version != 1.0) {
+ throw new OAuthException("OAuth version '$version' not supported");
+ }
+ return $version;
+ }
+
+ # Snagged from OAuthServer
+
+ function get_consumer($datastore, $req) {
+ $consumer_key = @$req->get_parameter("oauth_consumer_key");
+ if (!$consumer_key) {
+ throw new OAuthException("Invalid consumer key");
+ }
+
+ $consumer = $datastore->lookup_consumer($consumer_key);
+ if (!$consumer) {
+ throw new OAuthException("Invalid consumer");
+ }
+ return $consumer;
+ }
+
+ # Mostly cadged from OAuthServer
+
+ function get_token($datastore, &$req, $consumer) {/*{{{*/
+ $token_field = @$req->get_parameter('oauth_token');
+ $token = $datastore->lookup_token($consumer, 'request', $token_field);
+ if (!$token) {
+ throw new OAuthException("Invalid $token_type token: $token_field");
+ }
+ return $token;
+ }
+
+ function check_timestamp(&$req) {
+ $timestamp = @$req->get_parameter('oauth_timestamp');
+ $now = time();
+ if ($now - $timestamp > TIMESTAMP_THRESHOLD) {
+ throw new OAuthException("Expired timestamp, yours $timestamp, ours $now");
+ }
+ }
+
+ # NOTE: don't call twice on the same request; will fail!
+ function check_nonce(&$datastore, &$req, $consumer, $token) {
+ $timestamp = @$req->get_parameter('oauth_timestamp');
+ $nonce = @$req->get_parameter('oauth_nonce');
+ $found = $datastore->lookup_nonce($consumer, $token, $nonce, $timestamp);
+ if ($found) {
+ throw new OAuthException("Nonce already used");
+ }
+ return true;
+ }
+
+ function check_signature(&$req, $consumer, $token) {
+ $signature_method = $this->get_signature_method($req);
+ $signature = $req->get_parameter('oauth_signature');
+ $valid_sig = $signature_method->check_signature($req,
+ $consumer,
+ $token,
+ $signature);
+ if (!$valid_sig) {
+ throw new OAuthException("Invalid signature");
+ }
+ }
+
+ function get_signature_method(&$req) {
+ $signature_method = @$req->get_parameter("oauth_signature_method");
+ if (!$signature_method) {
+ $signature_method = "PLAINTEXT";
+ }
+ if ($signature_method != 'HMAC-SHA1') {
+ throw new OAuthException("Signature method '$signature_method' not supported.");
+ }
+ return omb_hmac_sha1();
+ }
}
diff --git a/_darcs/pristine/actions/userbyid.php b/_darcs/pristine/actions/userbyid.php
index 38bff2ede..4eab8758c 100644
--- a/_darcs/pristine/actions/userbyid.php
+++ b/_darcs/pristine/actions/userbyid.php
@@ -20,30 +20,30 @@
if (!defined('LACONICA')) { exit(1); }
class UserbyidAction extends Action {
-
- function is_readonly() {
- return true;
- }
-
+
+ function is_readonly() {
+ return true;
+ }
+
function handle($args) {
parent::handle($args);
$id = $this->trimmed('id');
if (!$id) {
- $this->client_error(_('No id.'));
- }
- $user =& User::staticGet($id);
- if (!$user) {
- $this->client_error(_('No such user.'));
+ $this->client_error(_('No id.'));
+ }
+ $user =& User::staticGet($id);
+ if (!$user) {
+ $this->client_error(_('No such user.'));
}
// support redirecting to FOAF rdf/xml if the agent prefers it
$page_prefs = 'application/rdf+xml,text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2';
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL;
- $type = common_negotiate_type(common_accept_to_prefs($httpaccept),
+ $type = common_negotiate_type(common_accept_to_prefs($httpaccept),
common_accept_to_prefs($page_prefs));
- $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream';
+ $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream';
- $url = common_local_url($page, array('nickname' => $user->nickname));
- common_redirect($url, 303);
- }
+ $url = common_local_url($page, array('nickname' => $user->nickname));
+ common_redirect($url, 303);
+ }
}
diff --git a/_darcs/pristine/actions/userrss.php b/_darcs/pristine/actions/userrss.php
index e57f86105..b5cb5a40a 100644
--- a/_darcs/pristine/actions/userrss.php
+++ b/_darcs/pristine/actions/userrss.php
@@ -25,66 +25,66 @@ require_once(INSTALLDIR.'/lib/rssaction.php');
class UserrssAction extends Rss10Action {
- var $user = NULL;
+ var $user = NULL;
- function init() {
- $nickname = $this->trimmed('nickname');
- $this->user = User::staticGet('nickname', $nickname);
+ function init() {
+ $nickname = $this->trimmed('nickname');
+ $this->user = User::staticGet('nickname', $nickname);
- if (!$this->user) {
- common_user_error(_('No such user.'));
- return false;
- } else {
- return true;
- }
- }
+ if (!$this->user) {
+ common_user_error(_('No such user.'));
+ return false;
+ } else {
+ return true;
+ }
+ }
- function get_notices($limit=0) {
+ function get_notices($limit=0) {
- $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);
- }
+ $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);
+ }
- return $notices;
- }
+ return $notices;
+ }
- function get_channel() {
- $user = $this->user;
- $profile = $user->getProfile();
- $c = array('url' => common_local_url('userrss',
- array('nickname' =>
- $user->nickname)),
- 'title' => $user->nickname,
- 'link' => $profile->profileurl,
- 'description' => sprintf(_('Microblog by %s'), $user->nickname));
- return $c;
- }
+ function get_channel() {
+ $user = $this->user;
+ $profile = $user->getProfile();
+ $c = array('url' => common_local_url('userrss',
+ array('nickname' =>
+ $user->nickname)),
+ 'title' => $user->nickname,
+ 'link' => $profile->profileurl,
+ 'description' => sprintf(_('Microblog by %s'), $user->nickname));
+ return $c;
+ }
- function get_image() {
- $user = $this->user;
- $profile = $user->getProfile();
- if (!$profile) {
- common_log_db_error($user, 'SELECT', __FILE__);
- $this->server_error(_('User without matching profile'));
- return NULL;
- }
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- return ($avatar) ? $avatar->url : NULL;
- }
+ function get_image() {
+ $user = $this->user;
+ $profile = $user->getProfile();
+ if (!$profile) {
+ common_log_db_error($user, 'SELECT', __FILE__);
+ $this->server_error(_('User without matching profile'));
+ return NULL;
+ }
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ return ($avatar) ? $avatar->url : NULL;
+ }
- # override parent to add X-SUP-ID URL
-
- function init_rss($limit=0) {
- $url = common_local_url('sup', NULL, $this->user->id);
- header('X-SUP-ID: '.$url);
- parent::init_rss($limit);
- }
+ # override parent to add X-SUP-ID URL
+
+ function init_rss($limit=0) {
+ $url = common_local_url('sup', NULL, $this->user->id);
+ header('X-SUP-ID: '.$url);
+ parent::init_rss($limit);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/actions/xrds.php b/_darcs/pristine/actions/xrds.php
index 1d516aab7..9788c87aa 100644
--- a/_darcs/pristine/actions/xrds.php
+++ b/_darcs/pristine/actions/xrds.php
@@ -23,110 +23,110 @@ require_once(INSTALLDIR.'/lib/omb.php');
class XrdsAction extends Action {
- function is_readonly() {
- return true;
- }
-
- function handle($args) {
- parent::handle($args);
- $nickname = $this->trimmed('nickname');
- $user = User::staticGet('nickname', $nickname);
- if (!$user) {
- common_user_error(_('No such user.'));
- return;
- }
- $this->show_xrds($user);
- }
-
- function show_xrds($user) {
-
- header('Content-Type: application/xrds+xml');
-
- common_start_xml();
- common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
-
- common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
- 'xml:id' => 'oauth',
- 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
- 'version' => '2.0'));
-
- common_element('Type', NULL, 'xri://$xrds*simple');
-
- $this->show_service(OAUTH_ENDPOINT_REQUEST,
- common_local_url('requesttoken'),
- array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
- array(OAUTH_HMAC_SHA1),
- $user->uri);
-
- $this->show_service(OAUTH_ENDPOINT_AUTHORIZE,
- common_local_url('userauthorization'),
- array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
- array(OAUTH_HMAC_SHA1));
-
- $this->show_service(OAUTH_ENDPOINT_ACCESS,
- common_local_url('accesstoken'),
- array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
- array(OAUTH_HMAC_SHA1));
-
- $this->show_service(OAUTH_ENDPOINT_RESOURCE,
- NULL,
- array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
- array(OAUTH_HMAC_SHA1));
-
- common_element_end('XRD');
-
- # XXX: decide whether to include user's ID/nickname in postNotice URL
-
- common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
- 'xml:id' => 'omb',
- 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
- 'version' => '2.0'));
-
- common_element('Type', NULL, 'xri://$xrds*simple');
-
- $this->show_service(OMB_ENDPOINT_POSTNOTICE,
- common_local_url('postnotice'));
-
- $this->show_service(OMB_ENDPOINT_UPDATEPROFILE,
- common_local_url('updateprofile'));
-
- common_element_end('XRD');
-
- common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
- 'version' => '2.0'));
-
- common_element('Type', NULL, 'xri://$xrds*simple');
-
- $this->show_service(OAUTH_DISCOVERY,
- '#oauth');
- $this->show_service(OMB_NAMESPACE,
- '#omb');
-
- common_element_end('XRD');
-
- common_element_end('XRDS');
- common_end_xml();
- }
-
- function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
- common_element_start('Service');
- if ($uri) {
- common_element('URI', NULL, $uri);
- }
- common_element('Type', NULL, $type);
- if ($params) {
- foreach ($params as $param) {
- common_element('Type', NULL, $param);
- }
- }
- if ($sigs) {
- foreach ($sigs as $sig) {
- common_element('Type', NULL, $sig);
- }
- }
- if ($localId) {
- common_element('LocalID', NULL, $localId);
- }
- common_element_end('Service');
- }
+ function is_readonly() {
+ return true;
+ }
+
+ function handle($args) {
+ parent::handle($args);
+ $nickname = $this->trimmed('nickname');
+ $user = User::staticGet('nickname', $nickname);
+ if (!$user) {
+ common_user_error(_('No such user.'));
+ return;
+ }
+ $this->show_xrds($user);
+ }
+
+ function show_xrds($user) {
+
+ header('Content-Type: application/xrds+xml');
+
+ common_start_xml();
+ common_element_start('XRDS', array('xmlns' => 'xri://$xrds'));
+
+ common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+ 'xml:id' => 'oauth',
+ 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+ 'version' => '2.0'));
+
+ common_element('Type', NULL, 'xri://$xrds*simple');
+
+ $this->show_service(OAUTH_ENDPOINT_REQUEST,
+ common_local_url('requesttoken'),
+ array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
+ array(OAUTH_HMAC_SHA1),
+ $user->uri);
+
+ $this->show_service(OAUTH_ENDPOINT_AUTHORIZE,
+ common_local_url('userauthorization'),
+ array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
+ array(OAUTH_HMAC_SHA1));
+
+ $this->show_service(OAUTH_ENDPOINT_ACCESS,
+ common_local_url('accesstoken'),
+ array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
+ array(OAUTH_HMAC_SHA1));
+
+ $this->show_service(OAUTH_ENDPOINT_RESOURCE,
+ NULL,
+ array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY),
+ array(OAUTH_HMAC_SHA1));
+
+ common_element_end('XRD');
+
+ # XXX: decide whether to include user's ID/nickname in postNotice URL
+
+ common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+ 'xml:id' => 'omb',
+ 'xmlns:simple' => 'http://xrds-simple.net/core/1.0',
+ 'version' => '2.0'));
+
+ common_element('Type', NULL, 'xri://$xrds*simple');
+
+ $this->show_service(OMB_ENDPOINT_POSTNOTICE,
+ common_local_url('postnotice'));
+
+ $this->show_service(OMB_ENDPOINT_UPDATEPROFILE,
+ common_local_url('updateprofile'));
+
+ common_element_end('XRD');
+
+ common_element_start('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)',
+ 'version' => '2.0'));
+
+ common_element('Type', NULL, 'xri://$xrds*simple');
+
+ $this->show_service(OAUTH_DISCOVERY,
+ '#oauth');
+ $this->show_service(OMB_NAMESPACE,
+ '#omb');
+
+ common_element_end('XRD');
+
+ common_element_end('XRDS');
+ common_end_xml();
+ }
+
+ function show_service($type, $uri, $params=NULL, $sigs=NULL, $localId=NULL) {
+ common_element_start('Service');
+ if ($uri) {
+ common_element('URI', NULL, $uri);
+ }
+ common_element('Type', NULL, $type);
+ if ($params) {
+ foreach ($params as $param) {
+ common_element('Type', NULL, $param);
+ }
+ }
+ if ($sigs) {
+ foreach ($sigs as $sig) {
+ common_element('Type', NULL, $sig);
+ }
+ }
+ if ($localId) {
+ common_element('LocalID', NULL, $localId);
+ }
+ common_element_end('Service');
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/classes/Avatar.php b/_darcs/pristine/classes/Avatar.php
index 901c47c51..e63668a33 100644
--- a/_darcs/pristine/classes/Avatar.php
+++ b/_darcs/pristine/classes/Avatar.php
@@ -26,70 +26,70 @@ class Avatar extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- # We clean up the file, too
+ # We clean up the file, too
- function delete() {
- $filename = $this->filename;
- if (parent::delete()) {
- @unlink(common_avatar_path($filename));
- }
- }
+ function delete() {
+ $filename = $this->filename;
+ if (parent::delete()) {
+ @unlink(common_avatar_path($filename));
+ }
+ }
- # Create and save scaled version of this avatar
- # XXX: maybe break into different methods
+ # Create and save scaled version of this avatar
+ # XXX: maybe break into different methods
- function scale($size) {
+ function scale($size) {
- $image_s = imagecreatetruecolor($size, $size);
- $image_a = $this->to_image();
- $square = min($this->width, $this->height);
+ $image_s = imagecreatetruecolor($size, $size);
+ $image_a = $this->to_image();
+ $square = min($this->width, $this->height);
imagecolortransparent($image_s, imagecolorallocate($image_s, 0, 0, 0));
imagealphablending($image_s, false);
imagesavealpha($image_s, true);
- imagecopyresampled($image_s, $image_a, 0, 0, 0, 0,
- $size, $size, $square, $square);
+ imagecopyresampled($image_s, $image_a, 0, 0, 0, 0,
+ $size, $size, $square, $square);
- $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png";
+ $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png";
- $filename = common_avatar_filename($this->profile_id, $ext, $size, common_timestamp());
+ $filename = common_avatar_filename($this->profile_id, $ext, $size, common_timestamp());
- if ($this->mediatype == 'image/jpeg') {
- imagejpeg($image_s, common_avatar_path($filename));
- } else {
- imagepng($image_s, common_avatar_path($filename));
- }
+ if ($this->mediatype == 'image/jpeg') {
+ imagejpeg($image_s, common_avatar_path($filename));
+ } else {
+ imagepng($image_s, common_avatar_path($filename));
+ }
- $scaled = DB_DataObject::factory('avatar');
- $scaled->profile_id = $this->profile_id;
- $scaled->width = $size;
- $scaled->height = $size;
- $scaled->original = false;
- $scaled->mediatype = ($this->mediattype == 'image/jpeg') ? 'image/jpeg' : 'image/png';
- $scaled->filename = $filename;
- $scaled->url = common_avatar_url($filename);
- $scaled->created = DB_DataObject_Cast::dateTime(); # current time
+ $scaled = DB_DataObject::factory('avatar');
+ $scaled->profile_id = $this->profile_id;
+ $scaled->width = $size;
+ $scaled->height = $size;
+ $scaled->original = false;
+ $scaled->mediatype = ($this->mediattype == 'image/jpeg') ? 'image/jpeg' : 'image/png';
+ $scaled->filename = $filename;
+ $scaled->url = common_avatar_url($filename);
+ $scaled->created = DB_DataObject_Cast::dateTime(); # current time
- if ($scaled->insert()) {
- return $scaled;
- } else {
- return NULL;
- }
- }
+ if ($scaled->insert()) {
+ return $scaled;
+ } else {
+ return NULL;
+ }
+ }
- function to_image() {
- $filepath = common_avatar_path($this->filename);
- if ($this->mediatype == 'image/gif') {
- return imagecreatefromgif($filepath);
- } else if ($this->mediatype == 'image/jpeg') {
- return imagecreatefromjpeg($filepath);
- } else if ($this->mediatype == 'image/png') {
- return imagecreatefrompng($filepath);
- } else {
- return NULL;
- }
- }
-
- function &pkeyGet($kv) {
- return Memcached_DataObject::pkeyGet('Avatar', $kv);
- }
+ function to_image() {
+ $filepath = common_avatar_path($this->filename);
+ if ($this->mediatype == 'image/gif') {
+ return imagecreatefromgif($filepath);
+ } else if ($this->mediatype == 'image/jpeg') {
+ return imagecreatefromjpeg($filepath);
+ } else if ($this->mediatype == 'image/png') {
+ return imagecreatefrompng($filepath);
+ } else {
+ return NULL;
+ }
+ }
+
+ function &pkeyGet($kv) {
+ return Memcached_DataObject::pkeyGet('Avatar', $kv);
+ }
}
diff --git a/_darcs/pristine/classes/Channel.php b/_darcs/pristine/classes/Channel.php
index bcc0c36b5..384fe8bb1 100644
--- a/_darcs/pristine/classes/Channel.php
+++ b/_darcs/pristine/classes/Channel.php
@@ -20,181 +20,181 @@
if (!defined('LACONICA')) { exit(1); }
class Channel {
-
- function on($user) {
- return false;
- }
-
- function off($user) {
- return false;
- }
-
- function output($user, $text) {
- return false;
- }
-
- function error($user, $text) {
- return false;
- }
-
- function source() {
- return NULL;
- }
+
+ function on($user) {
+ return false;
+ }
+
+ function off($user) {
+ return false;
+ }
+
+ function output($user, $text) {
+ return false;
+ }
+
+ function error($user, $text) {
+ return false;
+ }
+
+ function source() {
+ return NULL;
+ }
}
class XMPPChannel extends Channel {
- var $conn = NULL;
-
- function source() {
- return 'xmpp';
- }
-
- function __construct($conn) {
- $this->conn = $conn;
- }
-
- function on($user) {
- return $this->set_notify($user, 1);
- }
-
- function off($user) {
- return $this->set_notify($user, 0);
- }
-
- function output($user, $text) {
- $text = '['.common_config('site', 'name') . '] ' . $text;
- jabber_send_message($user->jabber, $text);
- }
-
- function error($user, $text) {
- $text = '['.common_config('site', 'name') . '] ' . $text;
- jabber_send_message($user->jabber, $text);
- }
-
- function set_notify(&$user, $notify) {
- $orig = clone($user);
- $user->jabbernotify = $notify;
- $result = $user->update($orig);
- if (!$result) {
- $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
- common_log(LOG_ERR,
- 'Could not set notify flag to ' . $notify .
- ' for user ' . common_log_objstring($user) .
- ': ' . $last_error->message);
- return false;
- } else {
- common_log(LOG_INFO,
- 'User ' . $user->nickname . ' set notify flag to ' . $notify);
- return true;
- }
- }
+ var $conn = NULL;
+
+ function source() {
+ return 'xmpp';
+ }
+
+ function __construct($conn) {
+ $this->conn = $conn;
+ }
+
+ function on($user) {
+ return $this->set_notify($user, 1);
+ }
+
+ function off($user) {
+ return $this->set_notify($user, 0);
+ }
+
+ function output($user, $text) {
+ $text = '['.common_config('site', 'name') . '] ' . $text;
+ jabber_send_message($user->jabber, $text);
+ }
+
+ function error($user, $text) {
+ $text = '['.common_config('site', 'name') . '] ' . $text;
+ jabber_send_message($user->jabber, $text);
+ }
+
+ function set_notify(&$user, $notify) {
+ $orig = clone($user);
+ $user->jabbernotify = $notify;
+ $result = $user->update($orig);
+ if (!$result) {
+ $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
+ common_log(LOG_ERR,
+ 'Could not set notify flag to ' . $notify .
+ ' for user ' . common_log_objstring($user) .
+ ': ' . $last_error->message);
+ return false;
+ } else {
+ common_log(LOG_INFO,
+ 'User ' . $user->nickname . ' set notify flag to ' . $notify);
+ return true;
+ }
+ }
}
class WebChannel extends Channel {
- function source() {
- return 'web';
- }
-
- function on($user) {
- return false;
- }
-
- function off($user) {
- return false;
- }
-
- function output($user, $text) {
- # XXX: buffer all output and send it at the end
- # XXX: even better, redirect to appropriate page
- # depending on what command was run
- common_show_header(_('Command results'));
- common_element('p', NULL, $text);
- common_show_footer();
- }
-
- function error($user, $text) {
- common_user_error($text);
- }
+ function source() {
+ return 'web';
+ }
+
+ function on($user) {
+ return false;
+ }
+
+ function off($user) {
+ return false;
+ }
+
+ function output($user, $text) {
+ # XXX: buffer all output and send it at the end
+ # XXX: even better, redirect to appropriate page
+ # depending on what command was run
+ common_show_header(_('Command results'));
+ common_element('p', NULL, $text);
+ common_show_footer();
+ }
+
+ function error($user, $text) {
+ common_user_error($text);
+ }
}
class AjaxWebChannel extends WebChannel {
- function output($user, $text) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Command results'));
- common_element_end('head');
- common_element_start('body');
- common_element('p', array('id' => 'command_result'), $text);
- common_element_end('body');
- common_element_end('html');
- }
-
- function error($user, $text) {
- common_start_html('text/xml;charset=utf-8', true);
- common_element_start('head');
- common_element('title', null, _('Ajax Error'));
- common_element_end('head');
- common_element_start('body');
- common_element('p', array('id' => 'error'), $text);
- common_element_end('body');
- common_element_end('html');
- }
+ function output($user, $text) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Command results'));
+ common_element_end('head');
+ common_element_start('body');
+ common_element('p', array('id' => 'command_result'), $text);
+ common_element_end('body');
+ common_element_end('html');
+ }
+
+ function error($user, $text) {
+ common_start_html('text/xml;charset=utf-8', true);
+ common_element_start('head');
+ common_element('title', null, _('Ajax Error'));
+ common_element_end('head');
+ common_element_start('body');
+ common_element('p', array('id' => 'error'), $text);
+ common_element_end('body');
+ common_element_end('html');
+ }
}
class MailChannel extends Channel {
- var $addr = NULL;
-
- function source() {
- return 'mail';
- }
-
- function __construct($addr=NULL) {
- $this->addr = $addr;
- }
-
- function on($user) {
- return $this->set_notify($user, 1);
- }
-
- function off($user) {
- return $this->set_notify($user, 0);
- }
-
- function output($user, $text) {
-
- $headers['From'] = $user->incomingemail;
- $headers['To'] = $this->addr;
-
- $headers['Subject'] = _('Command complete');
-
- return mail_send(array($this->addr), $headers, $text);
- }
-
- function error($user, $text) {
-
- $headers['From'] = $user->incomingemail;
- $headers['To'] = $this->addr;
-
- $headers['Subject'] = _('Command failed');
-
- return mail_send(array($this->addr), $headers, $text);
- }
-
- function set_notify($user, $value) {
- $orig = clone($user);
- $user->smsnotify = $value;
- $result = $user->update($orig);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- return false;
- }
- return true;
- }
+ var $addr = NULL;
+
+ function source() {
+ return 'mail';
+ }
+
+ function __construct($addr=NULL) {
+ $this->addr = $addr;
+ }
+
+ function on($user) {
+ return $this->set_notify($user, 1);
+ }
+
+ function off($user) {
+ return $this->set_notify($user, 0);
+ }
+
+ function output($user, $text) {
+
+ $headers['From'] = $user->incomingemail;
+ $headers['To'] = $this->addr;
+
+ $headers['Subject'] = _('Command complete');
+
+ return mail_send(array($this->addr), $headers, $text);
+ }
+
+ function error($user, $text) {
+
+ $headers['From'] = $user->incomingemail;
+ $headers['To'] = $this->addr;
+
+ $headers['Subject'] = _('Command failed');
+
+ return mail_send(array($this->addr), $headers, $text);
+ }
+
+ function set_notify($user, $value) {
+ $orig = clone($user);
+ $user->smsnotify = $value;
+ $result = $user->update($orig);
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ return false;
+ }
+ return true;
+ }
}
diff --git a/_darcs/pristine/classes/Command.php b/_darcs/pristine/classes/Command.php
index c2409d140..ff44b9d1e 100644
--- a/_darcs/pristine/classes/Command.php
+++ b/_darcs/pristine/classes/Command.php
@@ -22,22 +22,22 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/classes/Channel.php');
class Command {
-
- var $user = NULL;
-
- function __construct($user=NULL) {
- $this->user = $user;
- }
-
- function execute($channel) {
- return false;
- }
+
+ var $user = NULL;
+
+ function __construct($user=NULL) {
+ $this->user = $user;
+ }
+
+ function execute($channel) {
+ return false;
+ }
}
class UnimplementedCommand extends Command {
- function execute($channel) {
- $channel->error($this->user, _("Sorry, this command is not yet implemented."));
- }
+ function execute($channel) {
+ $channel->error($this->user, _("Sorry, this command is not yet implemented."));
+ }
}
class TrackingCommand extends UnimplementedCommand {
@@ -47,330 +47,330 @@ class TrackOffCommand extends UnimplementedCommand {
}
class TrackCommand extends UnimplementedCommand {
- var $word = NULL;
- function __construct($user, $word) {
- parent::__construct($user);
- $this->word = $word;
- }
+ var $word = NULL;
+ function __construct($user, $word) {
+ parent::__construct($user);
+ $this->word = $word;
+ }
}
class UntrackCommand extends UnimplementedCommand {
- var $word = NULL;
- function __construct($user, $word) {
- parent::__construct($user);
- $this->word = $word;
- }
+ var $word = NULL;
+ function __construct($user, $word) {
+ parent::__construct($user);
+ $this->word = $word;
+ }
}
class NudgeCommand extends UnimplementedCommand {
- var $other = NULL;
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
+ var $other = NULL;
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
}
class InviteCommand extends UnimplementedCommand {
- var $other = NULL;
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
+ var $other = NULL;
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
}
class StatsCommand extends Command {
- function execute($channel) {
+ function execute($channel) {
- $subs = new Subscription();
- $subs->subscriber = $this->user->id;
- $subs_count = (int) $subs->count() - 1;
+ $subs = new Subscription();
+ $subs->subscriber = $this->user->id;
+ $subs_count = (int) $subs->count() - 1;
- $subbed = new Subscription();
- $subbed->subscribed = $this->user->id;
- $subbed_count = (int) $subbed->count() - 1;
+ $subbed = new Subscription();
+ $subbed->subscribed = $this->user->id;
+ $subbed_count = (int) $subbed->count() - 1;
- $notices = new Notice();
- $notices->profile_id = $this->user->id;
- $notice_count = (int) $notices->count();
-
- $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
- "Subscribers: %2\$s\n".
- "Notices: %3\$s"),
- $subs_count,
- $subbed_count,
- $notice_count));
- }
+ $notices = new Notice();
+ $notices->profile_id = $this->user->id;
+ $notice_count = (int) $notices->count();
+
+ $channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
+ "Subscribers: %2\$s\n".
+ "Notices: %3\$s"),
+ $subs_count,
+ $subbed_count,
+ $notice_count));
+ }
}
class FavCommand extends Command {
-
- var $other = NULL;
-
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
-
- function execute($channel) {
-
- $recipient =
- common_relative_profile($this->user, common_canonical_nickname($this->other));
-
- if (!$recipient) {
- $channel->error($this->user, _('No such user.'));
- return;
- }
- $notice = $recipient->getCurrentNotice();
- if (!$notice) {
- $channel->error($this->user, _('User has no last notice'));
- return;
- }
-
- $fave = Fave::addNew($this->user, $notice);
+
+ var $other = NULL;
+
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
+
+ function execute($channel) {
+
+ $recipient =
+ common_relative_profile($this->user, common_canonical_nickname($this->other));
+
+ if (!$recipient) {
+ $channel->error($this->user, _('No such user.'));
+ return;
+ }
+ $notice = $recipient->getCurrentNotice();
+ if (!$notice) {
+ $channel->error($this->user, _('User has no last notice'));
+ return;
+ }
+
+ $fave = Fave::addNew($this->user, $notice);
- if (!$fave) {
- $channel->error($this->user, _('Could not create favorite.'));
- return;
- }
+ if (!$fave) {
+ $channel->error($this->user, _('Could not create favorite.'));
+ return;
+ }
- $other = User::staticGet('id', $recipient->id);
-
- if ($other && $other->id != $user->id) {
- if ($other->email && $other->emailnotifyfav) {
- mail_notify_fave($other, $this->user, $notice);
- }
- }
-
- $this->user->blowFavesCache();
-
- $channel->output($this->user, _('Notice marked as fave.'));
- }
+ $other = User::staticGet('id', $recipient->id);
+
+ if ($other && $other->id != $user->id) {
+ if ($other->email && $other->emailnotifyfav) {
+ mail_notify_fave($other, $this->user, $notice);
+ }
+ }
+
+ $this->user->blowFavesCache();
+
+ $channel->output($this->user, _('Notice marked as fave.'));
+ }
}
class WhoisCommand extends Command {
- var $other = NULL;
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
-
- function execute($channel) {
- $recipient =
- common_relative_profile($this->user, common_canonical_nickname($this->other));
-
- if (!$recipient) {
- $channel->error($this->user, _('No such user.'));
- return;
- }
-
- $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
- $recipient->profileurl);
- if ($recipient->fullname) {
- $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
- }
- if ($recipient->location) {
- $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
- }
- if ($recipient->homepage) {
- $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
- }
- if ($recipient->bio) {
- $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
- }
- $channel->output($this->user, $whois);
- }
+ var $other = NULL;
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
+
+ function execute($channel) {
+ $recipient =
+ common_relative_profile($this->user, common_canonical_nickname($this->other));
+
+ if (!$recipient) {
+ $channel->error($this->user, _('No such user.'));
+ return;
+ }
+
+ $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
+ $recipient->profileurl);
+ if ($recipient->fullname) {
+ $whois .= "\n" . sprintf(_('Fullname: %s'), $recipient->fullname);
+ }
+ if ($recipient->location) {
+ $whois .= "\n" . sprintf(_('Location: %s'), $recipient->location);
+ }
+ if ($recipient->homepage) {
+ $whois .= "\n" . sprintf(_('Homepage: %s'), $recipient->homepage);
+ }
+ if ($recipient->bio) {
+ $whois .= "\n" . sprintf(_('About: %s'), $recipient->bio);
+ }
+ $channel->output($this->user, $whois);
+ }
}
class MessageCommand extends Command {
- var $other = NULL;
- var $text = NULL;
- function __construct($user, $other, $text) {
- parent::__construct($user);
- $this->other = $other;
- $this->text = $text;
- }
-
- function execute($channel) {
- $other = User::staticGet('nickname', common_canonical_nickname($this->other));
- $len = mb_strlen($this->text);
- if ($len == 0) {
- $channel->error($this->user, _('No content!'));
- return;
- } else if ($len > 140) {
- $content = common_shorten_links($content);
- if (mb_strlen($content) > 140) {
- $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
- return;
- }
- }
-
- if (!$other) {
- $channel->error($this->user, _('No such user.'));
- return;
- } else if (!$this->user->mutuallySubscribed($other)) {
- $channel->error($this->user, _('You can\'t send a message to this user.'));
- return;
- } else if ($this->user->id == $other->id) {
- $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
- return;
- }
- $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
- if ($message) {
- $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
- } else {
- $channel->error($this->user, _('Error sending direct message.'));
- }
- }
+ var $other = NULL;
+ var $text = NULL;
+ function __construct($user, $other, $text) {
+ parent::__construct($user);
+ $this->other = $other;
+ $this->text = $text;
+ }
+
+ function execute($channel) {
+ $other = User::staticGet('nickname', common_canonical_nickname($this->other));
+ $len = mb_strlen($this->text);
+ if ($len == 0) {
+ $channel->error($this->user, _('No content!'));
+ return;
+ } else if ($len > 140) {
+ $content = common_shorten_links($content);
+ if (mb_strlen($content) > 140) {
+ $channel->error($this->user, sprintf(_('Message too long - maximum is 140 characters, you sent %d'), $len));
+ return;
+ }
+ }
+
+ if (!$other) {
+ $channel->error($this->user, _('No such user.'));
+ return;
+ } else if (!$this->user->mutuallySubscribed($other)) {
+ $channel->error($this->user, _('You can\'t send a message to this user.'));
+ return;
+ } else if ($this->user->id == $other->id) {
+ $channel->error($this->user, _('Don\'t send a message to yourself; just say it to yourself quietly instead.'));
+ return;
+ }
+ $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source());
+ if ($message) {
+ $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other));
+ } else {
+ $channel->error($this->user, _('Error sending direct message.'));
+ }
+ }
}
class GetCommand extends Command {
-
- var $other = NULL;
-
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
-
- function execute($channel) {
- $target_nickname = common_canonical_nickname($this->other);
-
- $target =
- common_relative_profile($this->user, $target_nickname);
+
+ var $other = NULL;
+
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
+
+ function execute($channel) {
+ $target_nickname = common_canonical_nickname($this->other);
+
+ $target =
+ common_relative_profile($this->user, $target_nickname);
- if (!$target) {
- $channel->error($this->user, _('No such user.'));
- return;
- }
- $notice = $target->getCurrentNotice();
- if (!$notice) {
- $channel->error($this->user, _('User has no last notice'));
- return;
- }
- $notice_content = $notice->content;
-
- $channel->output($this->user, $target_nickname . ": " . $notice_content);
- }
+ if (!$target) {
+ $channel->error($this->user, _('No such user.'));
+ return;
+ }
+ $notice = $target->getCurrentNotice();
+ if (!$notice) {
+ $channel->error($this->user, _('User has no last notice'));
+ return;
+ }
+ $notice_content = $notice->content;
+
+ $channel->output($this->user, $target_nickname . ": " . $notice_content);
+ }
}
class SubCommand extends Command {
-
- var $other = NULL;
-
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
-
- function execute($channel) {
-
- if (!$this->other) {
- $channel->error($this->user, _('Specify the name of the user to subscribe to'));
- return;
- }
-
- $result = subs_subscribe_user($this->user, $this->other);
-
- if ($result == 'true') {
- $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
- } else {
- $channel->error($this->user, $result);
- }
- }
+
+ var $other = NULL;
+
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
+
+ function execute($channel) {
+
+ if (!$this->other) {
+ $channel->error($this->user, _('Specify the name of the user to subscribe to'));
+ return;
+ }
+
+ $result = subs_subscribe_user($this->user, $this->other);
+
+ if ($result == 'true') {
+ $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
+ } else {
+ $channel->error($this->user, $result);
+ }
+ }
}
class UnsubCommand extends Command {
- var $other = NULL;
-
- function __construct($user, $other) {
- parent::__construct($user);
- $this->other = $other;
- }
+ var $other = NULL;
+
+ function __construct($user, $other) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
- function execute($channel) {
- if(!$this->other) {
- $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
- return;
- }
-
- $result=subs_unsubscribe_user($this->user, $this->other);
-
- if ($result) {
- $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
- } else {
- $channel->error($this->user, $result);
- }
- }
+ function execute($channel) {
+ if(!$this->other) {
+ $channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
+ return;
+ }
+
+ $result=subs_unsubscribe_user($this->user, $this->other);
+
+ if ($result) {
+ $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
+ } else {
+ $channel->error($this->user, $result);
+ }
+ }
}
class OffCommand extends Command {
- var $other = NULL;
- function __construct($user, $other=NULL) {
- parent::__construct($user);
- $this->other = $other;
- }
- function execute($channel) {
- if ($other) {
- $channel->error($this->user, _("Command not yet implemented."));
- } else {
- if ($channel->off($this->user)) {
- $channel->output($this->user, _('Notification off.'));
- } else {
- $channel->error($this->user, _('Can\'t turn off notification.'));
- }
- }
- }
+ var $other = NULL;
+ function __construct($user, $other=NULL) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
+ function execute($channel) {
+ if ($other) {
+ $channel->error($this->user, _("Command not yet implemented."));
+ } else {
+ if ($channel->off($this->user)) {
+ $channel->output($this->user, _('Notification off.'));
+ } else {
+ $channel->error($this->user, _('Can\'t turn off notification.'));
+ }
+ }
+ }
}
class OnCommand extends Command {
- var $other = NULL;
- function __construct($user, $other=NULL) {
- parent::__construct($user);
- $this->other = $other;
- }
-
- function execute($channel) {
- if ($other) {
- $channel->error($this->user, _("Command not yet implemented."));
- } else {
- if ($channel->on($this->user)) {
- $channel->output($this->user, _('Notification on.'));
- } else {
- $channel->error($this->user, _('Can\'t turn on notification.'));
- }
- }
- }
+ var $other = NULL;
+ function __construct($user, $other=NULL) {
+ parent::__construct($user);
+ $this->other = $other;
+ }
+
+ function execute($channel) {
+ if ($other) {
+ $channel->error($this->user, _("Command not yet implemented."));
+ } else {
+ if ($channel->on($this->user)) {
+ $channel->output($this->user, _('Notification on.'));
+ } else {
+ $channel->error($this->user, _('Can\'t turn on notification.'));
+ }
+ }
+ }
}
class HelpCommand extends Command {
- function execute($channel) {
- $channel->output($this->user,
- _("Commands:\n".
- "on - turn on notifications\n".
- "off - turn off notifications\n".
- "help - show this help\n".
- "follow <nickname> - subscribe to user\n".
- "leave <nickname> - unsubscribe from user\n".
- "d <nickname> <text> - direct message to user\n".
- "get <nickname> - get last notice from user\n".
- "whois <nickname> - get profile info on user\n".
- "fav <nickname> - add user's last notice as a 'fave'\n".
- "stats - get your stats\n".
- "stop - same as 'off'\n".
- "quit - same as 'off'\n".
- "sub <nickname> - same as 'follow'\n".
- "unsub <nickname> - same as 'leave'\n".
- "last <nickname> - same as 'get'\n".
- "on <nickname> - not yet implemented.\n".
- "off <nickname> - not yet implemented.\n".
- "nudge <nickname> - not yet implemented.\n".
- "invite <phone number> - not yet implemented.\n".
- "track <word> - not yet implemented.\n".
- "untrack <word> - not yet implemented.\n".
- "track off - not yet implemented.\n".
- "untrack all - not yet implemented.\n".
- "tracks - not yet implemented.\n".
- "tracking - not yet implemented.\n"));
- }
+ function execute($channel) {
+ $channel->output($this->user,
+ _("Commands:\n".
+ "on - turn on notifications\n".
+ "off - turn off notifications\n".
+ "help - show this help\n".
+ "follow <nickname> - subscribe to user\n".
+ "leave <nickname> - unsubscribe from user\n".
+ "d <nickname> <text> - direct message to user\n".
+ "get <nickname> - get last notice from user\n".
+ "whois <nickname> - get profile info on user\n".
+ "fav <nickname> - add user's last notice as a 'fave'\n".
+ "stats - get your stats\n".
+ "stop - same as 'off'\n".
+ "quit - same as 'off'\n".
+ "sub <nickname> - same as 'follow'\n".
+ "unsub <nickname> - same as 'leave'\n".
+ "last <nickname> - same as 'get'\n".
+ "on <nickname> - not yet implemented.\n".
+ "off <nickname> - not yet implemented.\n".
+ "nudge <nickname> - not yet implemented.\n".
+ "invite <phone number> - not yet implemented.\n".
+ "track <word> - not yet implemented.\n".
+ "untrack <word> - not yet implemented.\n".
+ "track off - not yet implemented.\n".
+ "untrack all - not yet implemented.\n".
+ "tracks - not yet implemented.\n".
+ "tracking - not yet implemented.\n"));
+ }
}
diff --git a/_darcs/pristine/classes/CommandInterpreter.php b/_darcs/pristine/classes/CommandInterpreter.php
index 4e27f8f79..8192fb1a9 100644
--- a/_darcs/pristine/classes/CommandInterpreter.php
+++ b/_darcs/pristine/classes/CommandInterpreter.php
@@ -22,174 +22,174 @@ if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/classes/Command.php');
class CommandInterpreter {
-
- function handle_command($user, $text) {
- # XXX: localise
+
+ function handle_command($user, $text) {
+ # XXX: localise
- $text = preg_replace('/\s+/', ' ', trim($text));
- list($cmd, $arg) = explode(' ', $text, 2);
+ $text = preg_replace('/\s+/', ' ', trim($text));
+ list($cmd, $arg) = explode(' ', $text, 2);
- # We try to support all the same commands as Twitter, see
- # http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
- # There are a few compatibility commands from earlier versions of
- # Laconica
-
- switch(strtolower($cmd)) {
- case 'help':
- if ($arg) {
- return NULL;
- }
- return new HelpCommand($user);
- case 'on':
- if ($arg) {
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new OnCommand($user, $other);
- }
- } else {
- return new OnCommand($user);
- }
- case 'off':
- if ($arg) {
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new OffCommand($user, $other);
- }
- } else {
- return new OffCommand($user);
- }
- case 'stop':
- case 'quit':
- if ($arg) {
- return NULL;
- } else {
- return new OffCommand($user);
- }
- case 'follow':
- case 'sub':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new SubCommand($user, $other);
- }
- case 'leave':
- case 'unsub':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new UnsubCommand($user, $other);
- }
- case 'get':
- case 'last':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new GetCommand($user, $other);
- }
- case 'd':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if (!$extra) {
- return NULL;
- } else {
- return new MessageCommand($user, $other, $extra);
- }
- case 'whois':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new WhoisCommand($user, $other);
- }
- case 'fav':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new FavCommand($user, $other);
- }
- case 'nudge':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new NudgeCommand($user, $other);
- }
- case 'stats':
- if ($arg) {
- return NULL;
- }
- return new StatsCommand($user);
- case 'invite':
- if (!$arg) {
- return NULL;
- }
- list($other, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else {
- return new InviteCommand($user, $other);
- }
- case 'track':
- if (!$arg) {
- return NULL;
- }
- list($word, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else if ($word == 'off') {
- return new TrackOffCommand($user);
- } else {
- return new TrackCommand($user, $word);
- }
- case 'untrack':
- if (!$arg) {
- return NULL;
- }
- list($word, $extra) = explode(' ', $arg, 2);
- if ($extra) {
- return NULL;
- } else if ($word == 'all') {
- return new TrackOffCommand($user);
- } else {
- return new UntrackCommand($user, $word);
- }
- case 'tracks':
- case 'tracking':
- if ($arg) {
- return NULL;
- }
- return new TrackingCommand($user);
- default:
- return false;
- }
- }
+ # We try to support all the same commands as Twitter, see
+ # http://getsatisfaction.com/twitter/topics/what_are_the_twitter_commands
+ # There are a few compatibility commands from earlier versions of
+ # Laconica
+
+ switch(strtolower($cmd)) {
+ case 'help':
+ if ($arg) {
+ return NULL;
+ }
+ return new HelpCommand($user);
+ case 'on':
+ if ($arg) {
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new OnCommand($user, $other);
+ }
+ } else {
+ return new OnCommand($user);
+ }
+ case 'off':
+ if ($arg) {
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new OffCommand($user, $other);
+ }
+ } else {
+ return new OffCommand($user);
+ }
+ case 'stop':
+ case 'quit':
+ if ($arg) {
+ return NULL;
+ } else {
+ return new OffCommand($user);
+ }
+ case 'follow':
+ case 'sub':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new SubCommand($user, $other);
+ }
+ case 'leave':
+ case 'unsub':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new UnsubCommand($user, $other);
+ }
+ case 'get':
+ case 'last':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new GetCommand($user, $other);
+ }
+ case 'd':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if (!$extra) {
+ return NULL;
+ } else {
+ return new MessageCommand($user, $other, $extra);
+ }
+ case 'whois':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new WhoisCommand($user, $other);
+ }
+ case 'fav':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new FavCommand($user, $other);
+ }
+ case 'nudge':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new NudgeCommand($user, $other);
+ }
+ case 'stats':
+ if ($arg) {
+ return NULL;
+ }
+ return new StatsCommand($user);
+ case 'invite':
+ if (!$arg) {
+ return NULL;
+ }
+ list($other, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else {
+ return new InviteCommand($user, $other);
+ }
+ case 'track':
+ if (!$arg) {
+ return NULL;
+ }
+ list($word, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else if ($word == 'off') {
+ return new TrackOffCommand($user);
+ } else {
+ return new TrackCommand($user, $word);
+ }
+ case 'untrack':
+ if (!$arg) {
+ return NULL;
+ }
+ list($word, $extra) = explode(' ', $arg, 2);
+ if ($extra) {
+ return NULL;
+ } else if ($word == 'all') {
+ return new TrackOffCommand($user);
+ } else {
+ return new UntrackCommand($user, $word);
+ }
+ case 'tracks':
+ case 'tracking':
+ if ($arg) {
+ return NULL;
+ }
+ return new TrackingCommand($user);
+ default:
+ return false;
+ }
+ }
}
diff --git a/_darcs/pristine/classes/Fave.php b/_darcs/pristine/classes/Fave.php
index 7cc3f585e..b70a8a897 100644
--- a/_darcs/pristine/classes/Fave.php
+++ b/_darcs/pristine/classes/Fave.php
@@ -20,18 +20,18 @@ class Fave extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- static function addNew($user, $notice) {
- $fave = new Fave();
- $fave->user_id = $user->id;
- $fave->notice_id = $notice->id;
- if (!$fave->insert()) {
- common_log_db_error($fave, 'INSERT', __FILE__);
- return false;
- }
- return $fave;
- }
-
- function &pkeyGet($kv) {
- return Memcached_DataObject::pkeyGet('Fave', $kv);
- }
+ static function addNew($user, $notice) {
+ $fave = new Fave();
+ $fave->user_id = $user->id;
+ $fave->notice_id = $notice->id;
+ if (!$fave->insert()) {
+ common_log_db_error($fave, 'INSERT', __FILE__);
+ return false;
+ }
+ return $fave;
+ }
+
+ function &pkeyGet($kv) {
+ return Memcached_DataObject::pkeyGet('Fave', $kv);
+ }
}
diff --git a/_darcs/pristine/classes/Foreign_link.php b/_darcs/pristine/classes/Foreign_link.php
index 7a625a209..7ce0df833 100644
--- a/_darcs/pristine/classes/Foreign_link.php
+++ b/_darcs/pristine/classes/Foreign_link.php
@@ -26,51 +26,51 @@ class Foreign_link extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- // XXX: This only returns a 1->1 single obj mapping. Change? Or make
- // a getForeignUsers() that returns more than one? --Zach
- static function getByUserID($user_id, $service) {
- $flink = new Foreign_link();
- $flink->service = $service;
- $flink->user_id = $user_id;
- $flink->limit(1);
+ // XXX: This only returns a 1->1 single obj mapping. Change? Or make
+ // a getForeignUsers() that returns more than one? --Zach
+ static function getByUserID($user_id, $service) {
+ $flink = new Foreign_link();
+ $flink->service = $service;
+ $flink->user_id = $user_id;
+ $flink->limit(1);
- if ($flink->find(TRUE)) {
- return $flink;
- }
+ if ($flink->find(TRUE)) {
+ return $flink;
+ }
- return NULL;
- }
-
- static function getByForeignID($foreign_id, $service) {
- $flink = new Foreign_link();
- $flink->service = $service;
- $flink->foreign_id = $foreign_id;
- $flink->limit(1);
+ return NULL;
+ }
+
+ static function getByForeignID($foreign_id, $service) {
+ $flink = new Foreign_link();
+ $flink->service = $service;
+ $flink->foreign_id = $foreign_id;
+ $flink->limit(1);
- if ($flink->find(TRUE)) {
- return $flink;
- }
+ if ($flink->find(TRUE)) {
+ return $flink;
+ }
- return NULL;
- }
-
- # Convenience methods
- function getForeignUser() {
- $fuser = new Foreign_user();
- $fuser->service = $this->service;
- $fuser->id = $this->foreign_id;
-
- $fuser->limit(1);
-
- if ($fuser->find(TRUE)) {
- return $fuser;
- }
-
- return NULL;
- }
-
- function getUser() {
- return User::staticGet($this->user_id);
- }
-
+ return NULL;
+ }
+
+ # Convenience methods
+ function getForeignUser() {
+ $fuser = new Foreign_user();
+ $fuser->service = $this->service;
+ $fuser->id = $this->foreign_id;
+
+ $fuser->limit(1);
+
+ if ($fuser->find(TRUE)) {
+ return $fuser;
+ }
+
+ return NULL;
+ }
+
+ function getUser() {
+ return User::staticGet($this->user_id);
+ }
+
}
diff --git a/_darcs/pristine/classes/Foreign_user.php b/_darcs/pristine/classes/Foreign_user.php
index 027fae69d..396680128 100644
--- a/_darcs/pristine/classes/Foreign_user.php
+++ b/_darcs/pristine/classes/Foreign_user.php
@@ -22,49 +22,49 @@ class Foreign_user extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
- // XXX: This only returns a 1->1 single obj mapping. Change? Or make
- // a getForeignUsers() that returns more than one? --Zach
- static function getForeignUser($id, $service) {
- $fuser = new Foreign_user();
- $fuser->whereAdd("service = $service");
- $fuser->whereAdd("id = $id");
- $fuser->limit(1);
-
- if ($fuser->find()) {
- $fuser->fetch();
- return $fuser;
- }
-
- return NULL;
- }
-
- function updateKeys(&$orig) {
- $parts = array();
- foreach (array('id', 'service', 'uri', 'nickname') as $k) {
- if (strcmp($this->$k, $orig->$k) != 0) {
- $parts[] = $k . ' = ' . $this->_quote($this->$k);
- }
- }
- if (count($parts) == 0) {
- # No changes
- return true;
- }
- $toupdate = implode(', ', $parts);
+
+ // XXX: This only returns a 1->1 single obj mapping. Change? Or make
+ // a getForeignUsers() that returns more than one? --Zach
+ static function getForeignUser($id, $service) {
+ $fuser = new Foreign_user();
+ $fuser->whereAdd("service = $service");
+ $fuser->whereAdd("id = $id");
+ $fuser->limit(1);
+
+ if ($fuser->find()) {
+ $fuser->fetch();
+ return $fuser;
+ }
+
+ return NULL;
+ }
+
+ function updateKeys(&$orig) {
+ $parts = array();
+ foreach (array('id', 'service', 'uri', 'nickname') as $k) {
+ if (strcmp($this->$k, $orig->$k) != 0) {
+ $parts[] = $k . ' = ' . $this->_quote($this->$k);
+ }
+ }
+ if (count($parts) == 0) {
+ # No changes
+ return true;
+ }
+ $toupdate = implode(', ', $parts);
- $table = $this->tableName();
- if(common_config('db','quote_identifiers')) {
- $table = '"' . $table . '"';
- }
- $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
- ' WHERE id = ' . $this->id;
- $orig->decache();
- $result = $this->query($qry);
- if ($result) {
- $this->encache();
- }
- return $result;
- }
+ $table = $this->tableName();
+ if(common_config('db','quote_identifiers')) {
+ $table = '"' . $table . '"';
+ }
+ $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
+ ' WHERE id = ' . $this->id;
+ $orig->decache();
+ $result = $this->query($qry);
+ if ($result) {
+ $this->encache();
+ }
+ return $result;
+ }
-
+
}
diff --git a/_darcs/pristine/classes/Memcached_DataObject.php b/_darcs/pristine/classes/Memcached_DataObject.php
index 7a33e158d..7699e1b38 100644
--- a/_darcs/pristine/classes/Memcached_DataObject.php
+++ b/_darcs/pristine/classes/Memcached_DataObject.php
@@ -24,151 +24,151 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Memcached_DataObject extends DB_DataObject
{
function &staticGet($cls, $k, $v=NULL) {
- if (is_null($v)) {
- $v = $k;
- # XXX: HACK!
- $i = new $cls;
- $keys = $i->keys();
- $k = $keys[0];
- unset($i);
- }
- $i = Memcached_DataObject::getcached($cls, $k, $v);
- if ($i) {
- return $i;
- } else {
- $i = DB_DataObject::staticGet($cls, $k, $v);
- if ($i) {
- $i->encache();
- }
- return $i;
- }
- }
+ if (is_null($v)) {
+ $v = $k;
+ # XXX: HACK!
+ $i = new $cls;
+ $keys = $i->keys();
+ $k = $keys[0];
+ unset($i);
+ }
+ $i = Memcached_DataObject::getcached($cls, $k, $v);
+ if ($i) {
+ return $i;
+ } else {
+ $i = DB_DataObject::staticGet($cls, $k, $v);
+ if ($i) {
+ $i->encache();
+ }
+ return $i;
+ }
+ }
- function &pkeyGet($cls, $kv) {
- $i = Memcached_DataObject::multicache($cls, $kv);
- if ($i) {
- return $i;
- } else {
- $i = new $cls();
- foreach ($kv as $k => $v) {
- $i->$k = $v;
- }
- if ($i->find(true)) {
- $i->encache();
- } else {
- $i = NULL;
- }
+ function &pkeyGet($cls, $kv) {
+ $i = Memcached_DataObject::multicache($cls, $kv);
+ if ($i) {
+ return $i;
+ } else {
+ $i = new $cls();
+ foreach ($kv as $k => $v) {
+ $i->$k = $v;
+ }
+ if ($i->find(true)) {
+ $i->encache();
+ } else {
+ $i = NULL;
+ }
return $i;
- }
- }
+ }
+ }
- function insert() {
- $result = parent::insert();
- return $result;
- }
-
- function update($orig=NULL) {
- if (is_object($orig) && $orig instanceof Memcached_DataObject) {
- $orig->decache(); # might be different keys
- }
- $result = parent::update($orig);
- if ($result) {
- $this->encache();
- }
- return $result;
- }
-
- function delete() {
- $this->decache(); # while we still have the values!
- return parent::delete();
- }
-
- static function memcache() {
- return common_memcache();
- }
-
- static function cacheKey($cls, $k, $v) {
- return common_cache_key(strtolower($cls).':'.$k.':'.$v);
- }
-
- static function getcached($cls, $k, $v) {
- $c = Memcached_DataObject::memcache();
- if (!$c) {
- return false;
- } else {
- return $c->get(Memcached_DataObject::cacheKey($cls, $k, $v));
- }
- }
+ function insert() {
+ $result = parent::insert();
+ return $result;
+ }
+
+ function update($orig=NULL) {
+ if (is_object($orig) && $orig instanceof Memcached_DataObject) {
+ $orig->decache(); # might be different keys
+ }
+ $result = parent::update($orig);
+ if ($result) {
+ $this->encache();
+ }
+ return $result;
+ }
+
+ function delete() {
+ $this->decache(); # while we still have the values!
+ return parent::delete();
+ }
+
+ static function memcache() {
+ return common_memcache();
+ }
+
+ static function cacheKey($cls, $k, $v) {
+ return common_cache_key(strtolower($cls).':'.$k.':'.$v);
+ }
+
+ static function getcached($cls, $k, $v) {
+ $c = Memcached_DataObject::memcache();
+ if (!$c) {
+ return false;
+ } else {
+ return $c->get(Memcached_DataObject::cacheKey($cls, $k, $v));
+ }
+ }
- function keyTypes() {
- global $_DB_DATAOBJECT;
+ function keyTypes() {
+ global $_DB_DATAOBJECT;
if (!isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"])) {
- $this->databaseStructure();
+ $this->databaseStructure();
}
- return $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
- }
-
- function encache() {
- $c = $this->memcache();
- if (!$c) {
- return false;
- } else {
- $pkey = array();
- $pval = array();
- $types = $this->keyTypes();
- ksort($types);
- foreach ($types as $key => $type) {
- if ($type == 'K') {
- $pkey[] = $key;
- $pval[] = $this->$key;
- } else {
- $c->set($this->cacheKey($this->tableName(), $key, $this->$key), $this);
- }
- }
- # XXX: should work for both compound and scalar pkeys
- $pvals = implode(',', $pval);
- $pkeys = implode(',', $pkey);
- $c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this);
- }
- }
-
- function decache() {
- $c = $this->memcache();
- if (!$c) {
- return false;
- } else {
- $pkey = array();
- $pval = array();
- $types = $this->keyTypes();
- ksort($types);
- foreach ($types as $key => $type) {
- if ($type == 'K') {
- $pkey[] = $key;
- $pval[] = $this->$key;
- } else {
- $c->delete($this->cacheKey($this->tableName(), $key, $this->$key));
- }
- }
- # should work for both compound and scalar pkeys
- # XXX: comma works for now but may not be safe separator for future keys
- $pvals = implode(',', $pval);
- $pkeys = implode(',', $pkey);
- $c->delete($this->cacheKey($this->tableName(), $pkeys, $pvals));
- }
- }
+ return $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"];
+ }
+
+ function encache() {
+ $c = $this->memcache();
+ if (!$c) {
+ return false;
+ } else {
+ $pkey = array();
+ $pval = array();
+ $types = $this->keyTypes();
+ ksort($types);
+ foreach ($types as $key => $type) {
+ if ($type == 'K') {
+ $pkey[] = $key;
+ $pval[] = $this->$key;
+ } else {
+ $c->set($this->cacheKey($this->tableName(), $key, $this->$key), $this);
+ }
+ }
+ # XXX: should work for both compound and scalar pkeys
+ $pvals = implode(',', $pval);
+ $pkeys = implode(',', $pkey);
+ $c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this);
+ }
+ }
+
+ function decache() {
+ $c = $this->memcache();
+ if (!$c) {
+ return false;
+ } else {
+ $pkey = array();
+ $pval = array();
+ $types = $this->keyTypes();
+ ksort($types);
+ foreach ($types as $key => $type) {
+ if ($type == 'K') {
+ $pkey[] = $key;
+ $pval[] = $this->$key;
+ } else {
+ $c->delete($this->cacheKey($this->tableName(), $key, $this->$key));
+ }
+ }
+ # should work for both compound and scalar pkeys
+ # XXX: comma works for now but may not be safe separator for future keys
+ $pvals = implode(',', $pval);
+ $pkeys = implode(',', $pkey);
+ $c->delete($this->cacheKey($this->tableName(), $pkeys, $pvals));
+ }
+ }
- function multicache($cls, $kv) {
- ksort($kv);
- $c = Memcached_DataObject::memcache();
- if (!$c) {
- return false;
- } else {
- $pkeys = implode(',', array_keys($kv));
- $pvals = implode(',', array_values($kv));
- return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
- }
- }
+ function multicache($cls, $kv) {
+ ksort($kv);
+ $c = Memcached_DataObject::memcache();
+ if (!$c) {
+ return false;
+ } else {
+ $pkeys = implode(',', array_keys($kv));
+ $pvals = implode(',', array_values($kv));
+ return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
+ }
+ }
function getSearchEngine($table) {
require_once INSTALLDIR.'/lib/search_engines.php';
diff --git a/_darcs/pristine/classes/Message.php b/_darcs/pristine/classes/Message.php
index ef4bd0316..dc527fcb1 100644
--- a/_darcs/pristine/classes/Message.php
+++ b/_darcs/pristine/classes/Message.php
@@ -26,43 +26,43 @@ class Message extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
- function getFrom() {
- return Profile::staticGet('id', $this->from_profile);
- }
-
- function getTo() {
- return Profile::staticGet('id', $this->to_profile);
- }
-
- static function saveNew($from, $to, $content, $source) {
-
- $msg = new Message();
-
- $msg->from_profile = $from;
- $msg->to_profile = $to;
- $msg->content = common_shorten_links($content);
- $msg->rendered = common_render_text($content);
- $msg->created = common_sql_now();
- $msg->source = $source;
-
- $result = $msg->insert();
-
- if (!$result) {
- common_log_db_error($msg, 'INSERT', __FILE__);
- return _('Could not insert message.');
- }
-
- $orig = clone($msg);
- $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
-
- $result = $msg->update($orig);
-
- if (!$result) {
- common_log_db_error($msg, 'UPDATE', __FILE__);
- return _('Could not update message with new URI.');
- }
-
- return $msg;
- }
+
+ function getFrom() {
+ return Profile::staticGet('id', $this->from_profile);
+ }
+
+ function getTo() {
+ return Profile::staticGet('id', $this->to_profile);
+ }
+
+ static function saveNew($from, $to, $content, $source) {
+
+ $msg = new Message();
+
+ $msg->from_profile = $from;
+ $msg->to_profile = $to;
+ $msg->content = common_shorten_links($content);
+ $msg->rendered = common_render_text($content);
+ $msg->created = common_sql_now();
+ $msg->source = $source;
+
+ $result = $msg->insert();
+
+ if (!$result) {
+ common_log_db_error($msg, 'INSERT', __FILE__);
+ return _('Could not insert message.');
+ }
+
+ $orig = clone($msg);
+ $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
+
+ $result = $msg->update($orig);
+
+ if (!$result) {
+ common_log_db_error($msg, 'UPDATE', __FILE__);
+ return _('Could not update message with new URI.');
+ }
+
+ return $msg;
+ }
}
diff --git a/_darcs/pristine/classes/Notice.php b/_darcs/pristine/classes/Notice.php
index ca8283bce..35e03e342 100644
--- a/_darcs/pristine/classes/Notice.php
+++ b/_darcs/pristine/classes/Notice.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -31,69 +31,69 @@ define('NOTICE_CACHE_WINDOW', 61);
class Notice extends Memcached_DataObject
{
- ###START_AUTOCODE
- /* the code below is auto generated do not remove the above tag */
-
- public $__table = 'notice'; // table name
- public $id; // int(4) primary_key not_null
- public $profile_id; // int(4) not_null
- public $uri; // varchar(255) unique_key
- public $content; // varchar(140)
- public $rendered; // text()
- public $url; // varchar(255)
- public $created; // datetime() not_null
- public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
- public $reply_to; // int(4)
- public $is_local; // tinyint(1)
- public $source; // varchar(32)
-
- /* Static get */
- function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice',$k,$v); }
-
- /* the code above is auto generated do not remove the tag below */
- ###END_AUTOCODE
-
- function getProfile() {
- return Profile::staticGet('id', $this->profile_id);
- }
-
- function delete() {
- $this->blowCaches(true);
- $this->blowFavesCache(true);
- $this->blowInboxes();
- return parent::delete();
- }
-
- function saveTags() {
- /* extract all #hastags */
- $count = preg_match_all('/(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/', strtolower($this->content), $match);
- if (!$count) {
- return true;
- }
-
- /* elide characters we don't want in the tag */
- $match[1] = str_replace(array('-', '_', '.'), '', $match[1]);
-
- /* Add them to the database */
- foreach(array_unique($match[1]) as $hashtag) {
- $tag = DB_DataObject::factory('Notice_tag');
- $tag->notice_id = $this->id;
- $tag->tag = $hashtag;
- $tag->created = $this->created;
- $id = $tag->insert();
- if (!$id) {
- $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
- common_log(LOG_ERR, 'DB error inserting hashtag: ' . $last_error->message);
- common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
- return;
- }
- }
- return true;
- }
-
- static function saveNew($profile_id, $content, $source=NULL, $is_local=1, $reply_to=NULL, $uri=NULL) {
-
- $profile = Profile::staticGet($profile_id);
+ ###START_AUTOCODE
+ /* the code below is auto generated do not remove the above tag */
+
+ public $__table = 'notice'; // table name
+ public $id; // int(4) primary_key not_null
+ public $profile_id; // int(4) not_null
+ public $uri; // varchar(255) unique_key
+ public $content; // varchar(140)
+ public $rendered; // text()
+ public $url; // varchar(255)
+ public $created; // datetime() not_null
+ public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
+ public $reply_to; // int(4)
+ public $is_local; // tinyint(1)
+ public $source; // varchar(32)
+
+ /* Static get */
+ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice',$k,$v); }
+
+ /* the code above is auto generated do not remove the tag below */
+ ###END_AUTOCODE
+
+ function getProfile() {
+ return Profile::staticGet('id', $this->profile_id);
+ }
+
+ function delete() {
+ $this->blowCaches(true);
+ $this->blowFavesCache(true);
+ $this->blowInboxes();
+ return parent::delete();
+ }
+
+ function saveTags() {
+ /* extract all #hastags */
+ $count = preg_match_all('/(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/', strtolower($this->content), $match);
+ if (!$count) {
+ return true;
+ }
+
+ /* elide characters we don't want in the tag */
+ $match[1] = str_replace(array('-', '_', '.'), '', $match[1]);
+
+ /* Add them to the database */
+ foreach(array_unique($match[1]) as $hashtag) {
+ $tag = DB_DataObject::factory('Notice_tag');
+ $tag->notice_id = $this->id;
+ $tag->tag = $hashtag;
+ $tag->created = $this->created;
+ $id = $tag->insert();
+ if (!$id) {
+ $last_error = PEAR::getStaticProperty('DB_DataObject','lastError');
+ common_log(LOG_ERR, 'DB error inserting hashtag: ' . $last_error->message);
+ common_server_error(sprintf(_('DB error inserting hashtag: %s'), $last_error->message));
+ return;
+ }
+ }
+ return true;
+ }
+
+ static function saveNew($profile_id, $content, $source=NULL, $is_local=1, $reply_to=NULL, $uri=NULL) {
+
+ $profile = Profile::staticGet($profile_id);
if (!$profile) {
common_log(LOG_ERR, 'Problem saving notice. Unknown user.');
@@ -102,69 +102,69 @@ class Notice extends Memcached_DataObject
if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
- return _('Too many notices too fast; take a breather and post again in a few minutes.');
+ return _('Too many notices too fast; take a breather and post again in a few minutes.');
}
- $banned = common_config('profile', 'banned');
+ $banned = common_config('profile', 'banned');
- if ( in_array($profile_id, $banned) || in_array($profile->nickname, $banned)) {
- common_log(LOG_WARNING, "Attempted post from banned user: $profile->nickname (user id = $profile_id).");
+ if ( in_array($profile_id, $banned) || in_array($profile->nickname, $banned)) {
+ common_log(LOG_WARNING, "Attempted post from banned user: $profile->nickname (user id = $profile_id).");
return _('You are banned from posting notices on this site.');
- }
+ }
- $notice = new Notice();
- $notice->profile_id = $profile_id;
+ $notice = new Notice();
+ $notice->profile_id = $profile_id;
- $blacklist = common_config('public', 'blacklist');
+ $blacklist = common_config('public', 'blacklist');
- # Blacklisted are non-false, but not 1, either
+ # Blacklisted are non-false, but not 1, either
- if ($blacklist && in_array($profile_id, $blacklist)) {
- $notice->is_local = -1;
- } else {
- $notice->is_local = $is_local;
- }
+ if ($blacklist && in_array($profile_id, $blacklist)) {
+ $notice->is_local = -1;
+ } else {
+ $notice->is_local = $is_local;
+ }
- $notice->reply_to = $reply_to;
- $notice->created = common_sql_now();
- $notice->content = common_shorten_links($content);
- $notice->rendered = common_render_content($notice->content, $notice);
- $notice->source = $source;
- $notice->uri = $uri;
+ $notice->reply_to = $reply_to;
+ $notice->created = common_sql_now();
+ $notice->content = common_shorten_links($content);
+ $notice->rendered = common_render_content($notice->content, $notice);
+ $notice->source = $source;
+ $notice->uri = $uri;
- $id = $notice->insert();
+ $id = $notice->insert();
- if (!$id) {
- common_log_db_error($notice, 'INSERT', __FILE__);
- return _('Problem saving notice.');
- }
+ if (!$id) {
+ common_log_db_error($notice, 'INSERT', __FILE__);
+ return _('Problem saving notice.');
+ }
- # Update the URI after the notice is in the database
- if (!$uri) {
- $orig = clone($notice);
- $notice->uri = common_notice_uri($notice);
+ # Update the URI after the notice is in the database
+ if (!$uri) {
+ $orig = clone($notice);
+ $notice->uri = common_notice_uri($notice);
- if (!$notice->update($orig)) {
- common_log_db_error($notice, 'UPDATE', __FILE__);
- return _('Problem saving notice.');
- }
- }
+ if (!$notice->update($orig)) {
+ common_log_db_error($notice, 'UPDATE', __FILE__);
+ return _('Problem saving notice.');
+ }
+ }
- # XXX: do we need to change this for remote users?
+ # XXX: do we need to change this for remote users?
- common_save_replies($notice);
- $notice->saveTags();
+ common_save_replies($notice);
+ $notice->saveTags();
- # Clear the cache for subscribed users, so they'll update at next request
- # XXX: someone clever could prepend instead of clearing the cache
+ # Clear the cache for subscribed users, so they'll update at next request
+ # XXX: someone clever could prepend instead of clearing the cache
- if (common_config('memcached', 'enabled')) {
- $notice->blowCaches();
- }
+ if (common_config('memcached', 'enabled')) {
+ $notice->blowCaches();
+ }
- $notice->addToInboxes();
- return $notice;
- }
+ $notice->addToInboxes();
+ return $notice;
+ }
static function checkEditThrottle($profile_id) {
$profile = Profile::staticGet($profile_id);
@@ -184,356 +184,356 @@ class Notice extends Memcached_DataObject
return true;
}
- function blowCaches($blowLast=false) {
- $this->blowSubsCache($blowLast);
- $this->blowNoticeCache($blowLast);
- $this->blowRepliesCache($blowLast);
- $this->blowPublicCache($blowLast);
- $this->blowTagCache($blowLast);
- }
-
- function blowTagCache($blowLast=false) {
- $cache = common_memcache();
- if ($cache) {
- $tag = new Notice_tag();
- $tag->notice_id = $this->id;
- if ($tag->find()) {
- while ($tag->fetch()) {
- $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag));
- if ($blowLast) {
- $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag . ';last'));
- }
- }
- }
- $tag->free();
- unset($tag);
- }
- }
-
- function blowSubsCache($blowLast=false) {
- $cache = common_memcache();
- if ($cache) {
- $user = new User();
-
- $user->query('SELECT id ' .
- 'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
- 'WHERE subscription.subscribed = ' . $this->profile_id);
-
- while ($user->fetch()) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
- if ($blowLast) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));
- }
- }
- $user->free();
- unset($user);
- }
- }
-
- function blowNoticeCache($blowLast=false) {
- if ($this->is_local) {
- $cache = common_memcache();
- if ($cache) {
- $cache->delete(common_cache_key('profile:notices:'.$this->profile_id));
- if ($blowLast) {
- $cache->delete(common_cache_key('profile:notices:'.$this->profile_id.';last'));
- }
- }
- }
- }
-
- function blowRepliesCache($blowLast=false) {
- $cache = common_memcache();
- if ($cache) {
- $reply = new Reply();
- $reply->notice_id = $this->id;
- if ($reply->find()) {
- while ($reply->fetch()) {
- $cache->delete(common_cache_key('user:replies:'.$reply->profile_id));
- if ($blowLast) {
- $cache->delete(common_cache_key('user:replies:'.$reply->profile_id.';last'));
- }
- }
- }
- $reply->free();
- unset($reply);
- }
- }
-
- function blowPublicCache($blowLast=false) {
- if ($this->is_local == 1) {
- $cache = common_memcache();
- if ($cache) {
- $cache->delete(common_cache_key('public'));
- if ($blowLast) {
- $cache->delete(common_cache_key('public').';last');
- }
- }
- }
- }
-
- function blowFavesCache($blowLast=false) {
- $cache = common_memcache();
- if ($cache) {
- $fave = new Fave();
- $fave->notice_id = $this->id;
- if ($fave->find()) {
- while ($fave->fetch()) {
- $cache->delete(common_cache_key('user:faves:'.$fave->user_id));
- if ($blowLast) {
- $cache->delete(common_cache_key('user:faves:'.$fave->user_id.';last'));
- }
- }
- }
- $fave->free();
- unset($fave);
- }
- }
-
- # XXX: too many args; we need to move to named params or even a separate
- # class for notice streams
-
- static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $order=NULL, $since=NULL) {
-
- if (common_config('memcached', 'enabled')) {
-
- # Skip the cache if this is a since, since_id or before_id qry
- if ($since_id > 0 || $before_id > 0 || $since) {
- return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since);
- } else {
- return Notice::getCachedStream($qry, $cachekey, $offset, $limit, $order);
- }
- }
-
- return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since);
- }
-
- static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) {
-
- $needAnd = FALSE;
- $needWhere = TRUE;
-
- if (preg_match('/\bWHERE\b/i', $qry)) {
- $needWhere = FALSE;
- $needAnd = TRUE;
- }
-
- if ($since_id > 0) {
-
- if ($needWhere) {
- $qry .= ' WHERE ';
- $needWhere = FALSE;
- } else {
- $qry .= ' AND ';
- }
-
- $qry .= ' notice.id > ' . $since_id;
- }
-
- if ($before_id > 0) {
-
- if ($needWhere) {
- $qry .= ' WHERE ';
- $needWhere = FALSE;
- } else {
- $qry .= ' AND ';
- }
-
- $qry .= ' notice.id < ' . $before_id;
- }
+ function blowCaches($blowLast=false) {
+ $this->blowSubsCache($blowLast);
+ $this->blowNoticeCache($blowLast);
+ $this->blowRepliesCache($blowLast);
+ $this->blowPublicCache($blowLast);
+ $this->blowTagCache($blowLast);
+ }
+
+ function blowTagCache($blowLast=false) {
+ $cache = common_memcache();
+ if ($cache) {
+ $tag = new Notice_tag();
+ $tag->notice_id = $this->id;
+ if ($tag->find()) {
+ while ($tag->fetch()) {
+ $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('notice_tag:notice_stream:' . $tag->tag . ';last'));
+ }
+ }
+ }
+ $tag->free();
+ unset($tag);
+ }
+ }
+
+ function blowSubsCache($blowLast=false) {
+ $cache = common_memcache();
+ if ($cache) {
+ $user = new User();
+
+ $user->query('SELECT id ' .
+ 'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
+ 'WHERE subscription.subscribed = ' . $this->profile_id);
+
+ while ($user->fetch()) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));
+ }
+ }
+ $user->free();
+ unset($user);
+ }
+ }
+
+ function blowNoticeCache($blowLast=false) {
+ if ($this->is_local) {
+ $cache = common_memcache();
+ if ($cache) {
+ $cache->delete(common_cache_key('profile:notices:'.$this->profile_id));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('profile:notices:'.$this->profile_id.';last'));
+ }
+ }
+ }
+ }
+
+ function blowRepliesCache($blowLast=false) {
+ $cache = common_memcache();
+ if ($cache) {
+ $reply = new Reply();
+ $reply->notice_id = $this->id;
+ if ($reply->find()) {
+ while ($reply->fetch()) {
+ $cache->delete(common_cache_key('user:replies:'.$reply->profile_id));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('user:replies:'.$reply->profile_id.';last'));
+ }
+ }
+ }
+ $reply->free();
+ unset($reply);
+ }
+ }
+
+ function blowPublicCache($blowLast=false) {
+ if ($this->is_local == 1) {
+ $cache = common_memcache();
+ if ($cache) {
+ $cache->delete(common_cache_key('public'));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('public').';last');
+ }
+ }
+ }
+ }
+
+ function blowFavesCache($blowLast=false) {
+ $cache = common_memcache();
+ if ($cache) {
+ $fave = new Fave();
+ $fave->notice_id = $this->id;
+ if ($fave->find()) {
+ while ($fave->fetch()) {
+ $cache->delete(common_cache_key('user:faves:'.$fave->user_id));
+ if ($blowLast) {
+ $cache->delete(common_cache_key('user:faves:'.$fave->user_id.';last'));
+ }
+ }
+ }
+ $fave->free();
+ unset($fave);
+ }
+ }
+
+ # XXX: too many args; we need to move to named params or even a separate
+ # class for notice streams
- if ($since) {
-
- if ($needWhere) {
- $qry .= ' WHERE ';
- $needWhere = FALSE;
- } else {
- $qry .= ' AND ';
- }
+ static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $order=NULL, $since=NULL) {
- $qry .= ' notice.created > \'' . date('Y-m-d H:i:s', $since) . '\'';
- }
+ if (common_config('memcached', 'enabled')) {
- # Allow ORDER override
+ # Skip the cache if this is a since, since_id or before_id qry
+ if ($since_id > 0 || $before_id > 0 || $since) {
+ return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since);
+ } else {
+ return Notice::getCachedStream($qry, $cachekey, $offset, $limit, $order);
+ }
+ }
- if ($order) {
- $qry .= $order;
- } else {
- $qry .= ' ORDER BY notice.created DESC, notice.id DESC ';
- }
+ return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since);
+ }
- if (common_config('db','type') == 'pgsql') {
- $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
- } else {
- $qry .= ' LIMIT ' . $offset . ', ' . $limit;
- }
+ static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) {
- $notice = new Notice();
+ $needAnd = FALSE;
+ $needWhere = TRUE;
- $notice->query($qry);
+ if (preg_match('/\bWHERE\b/i', $qry)) {
+ $needWhere = FALSE;
+ $needAnd = TRUE;
+ }
- return $notice;
- }
+ if ($since_id > 0) {
- # XXX: this is pretty long and should probably be broken up into
- # some helper functions
+ if ($needWhere) {
+ $qry .= ' WHERE ';
+ $needWhere = FALSE;
+ } else {
+ $qry .= ' AND ';
+ }
- static function getCachedStream($qry, $cachekey, $offset, $limit, $order) {
+ $qry .= ' notice.id > ' . $since_id;
+ }
- # If outside our cache window, just go to the DB
+ if ($before_id > 0) {
- if ($offset + $limit > NOTICE_CACHE_WINDOW) {
- return Notice::getStreamDirect($qry, $offset, $limit, NULL, NULL, $order, NULL);
- }
+ if ($needWhere) {
+ $qry .= ' WHERE ';
+ $needWhere = FALSE;
+ } else {
+ $qry .= ' AND ';
+ }
- # Get the cache; if we can't, just go to the DB
+ $qry .= ' notice.id < ' . $before_id;
+ }
- $cache = common_memcache();
+ if ($since) {
- if (!$cache) {
- return Notice::getStreamDirect($qry, $offset, $limit, NULL, NULL, $order, NULL);
- }
+ if ($needWhere) {
+ $qry .= ' WHERE ';
+ $needWhere = FALSE;
+ } else {
+ $qry .= ' AND ';
+ }
- # Get the notices out of the cache
+ $qry .= ' notice.created > \'' . date('Y-m-d H:i:s', $since) . '\'';
+ }
- $notices = $cache->get(common_cache_key($cachekey));
+ # Allow ORDER override
- # On a cache hit, return a DB-object-like wrapper
+ if ($order) {
+ $qry .= $order;
+ } else {
+ $qry .= ' ORDER BY notice.created DESC, notice.id DESC ';
+ }
- if ($notices !== FALSE) {
- $wrapper = new NoticeWrapper(array_slice($notices, $offset, $limit));
- return $wrapper;
- }
+ if (common_config('db','type') == 'pgsql') {
+ $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
+ } else {
+ $qry .= ' LIMIT ' . $offset . ', ' . $limit;
+ }
- # If the cache was invalidated because of new data being
- # added, we can try and just get the new stuff. We keep an additional
- # copy of the data at the key + ';last'
+ $notice = new Notice();
- # No cache hit. Try to get the *last* cached version
+ $notice->query($qry);
- $last_notices = $cache->get(common_cache_key($cachekey) . ';last');
+ return $notice;
+ }
- if ($last_notices) {
+ # XXX: this is pretty long and should probably be broken up into
+ # some helper functions
- # Reverse-chron order, so last ID is last.
+ static function getCachedStream($qry, $cachekey, $offset, $limit, $order) {
- $last_id = $last_notices[0]->id;
+ # If outside our cache window, just go to the DB
- # XXX: this assumes monotonically increasing IDs; a fair
- # bet with our DB.
+ if ($offset + $limit > NOTICE_CACHE_WINDOW) {
+ return Notice::getStreamDirect($qry, $offset, $limit, NULL, NULL, $order, NULL);
+ }
- $new_notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW,
- $last_id, NULL, $order, NULL);
+ # Get the cache; if we can't, just go to the DB
- if ($new_notice) {
- $new_notices = array();
- while ($new_notice->fetch()) {
- $new_notices[] = clone($new_notice);
- }
- $new_notice->free();
- $notices = array_slice(array_merge($new_notices, $last_notices),
- 0, NOTICE_CACHE_WINDOW);
+ $cache = common_memcache();
- # Store the array in the cache for next time
+ if (!$cache) {
+ return Notice::getStreamDirect($qry, $offset, $limit, NULL, NULL, $order, NULL);
+ }
- $result = $cache->set(common_cache_key($cachekey), $notices);
- $result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
+ # Get the notices out of the cache
- # return a wrapper of the array for use now
+ $notices = $cache->get(common_cache_key($cachekey));
- return new NoticeWrapper(array_slice($notices, $offset, $limit));
- }
- }
+ # On a cache hit, return a DB-object-like wrapper
- # Otherwise, get the full cache window out of the DB
+ if ($notices !== FALSE) {
+ $wrapper = new NoticeWrapper(array_slice($notices, $offset, $limit));
+ return $wrapper;
+ }
- $notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, NULL, NULL, $order, NULL);
+ # If the cache was invalidated because of new data being
+ # added, we can try and just get the new stuff. We keep an additional
+ # copy of the data at the key + ';last'
- # If there are no hits, just return the value
+ # No cache hit. Try to get the *last* cached version
- if (!$notice) {
- return $notice;
- }
+ $last_notices = $cache->get(common_cache_key($cachekey) . ';last');
- # Pack results into an array
+ if ($last_notices) {
- $notices = array();
+ # Reverse-chron order, so last ID is last.
- while ($notice->fetch()) {
- $notices[] = clone($notice);
- }
+ $last_id = $last_notices[0]->id;
- $notice->free();
+ # XXX: this assumes monotonically increasing IDs; a fair
+ # bet with our DB.
- # Store the array in the cache for next time
+ $new_notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW,
+ $last_id, NULL, $order, NULL);
- $result = $cache->set(common_cache_key($cachekey), $notices);
- $result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
+ if ($new_notice) {
+ $new_notices = array();
+ while ($new_notice->fetch()) {
+ $new_notices[] = clone($new_notice);
+ }
+ $new_notice->free();
+ $notices = array_slice(array_merge($new_notices, $last_notices),
+ 0, NOTICE_CACHE_WINDOW);
- # return a wrapper of the array for use now
+ # Store the array in the cache for next time
- $wrapper = new NoticeWrapper(array_slice($notices, $offset, $limit));
+ $result = $cache->set(common_cache_key($cachekey), $notices);
+ $result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
- return $wrapper;
- }
+ # return a wrapper of the array for use now
- function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=NULL) {
+ return new NoticeWrapper(array_slice($notices, $offset, $limit));
+ }
+ }
- $parts = array();
+ # Otherwise, get the full cache window out of the DB
- $qry = 'SELECT * FROM notice ';
+ $notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, NULL, NULL, $order, NULL);
- if (common_config('public', 'localonly')) {
- $parts[] = 'is_local = 1';
- } else {
- # -1 == blacklisted
- $parts[] = 'is_local != -1';
- }
+ # If there are no hits, just return the value
- if ($parts) {
- $qry .= ' WHERE ' . implode(' AND ', $parts);
- }
+ if (!$notice) {
+ return $notice;
+ }
- return Notice::getStream($qry,
- 'public',
- $offset, $limit, $since_id, $before_id, NULL, $since);
- }
+ # Pack results into an array
- function addToInboxes() {
- $enabled = common_config('inboxes', 'enabled');
+ $notices = array();
- if ($enabled === true || $enabled === 'transitional') {
- $inbox = new Notice_inbox();
- $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
- 'SELECT user.id, ' . $this->id . ', "' . $this->created . '" ' .
- 'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
- 'WHERE subscription.subscribed = ' . $this->profile_id . ' ' .
- 'AND NOT EXISTS (SELECT user_id, notice_id ' .
- 'FROM notice_inbox ' .
- 'WHERE user_id = user.id ' .
- 'AND notice_id = ' . $this->id . ' )';
- if ($enabled === 'transitional') {
- $qry .= ' AND user.inboxed = 1';
- }
- $inbox->query($qry);
- }
- return;
- }
+ while ($notice->fetch()) {
+ $notices[] = clone($notice);
+ }
- # Delete from inboxes if we're deleted.
+ $notice->free();
- function blowInboxes() {
+ # Store the array in the cache for next time
- $enabled = common_config('inboxes', 'enabled');
+ $result = $cache->set(common_cache_key($cachekey), $notices);
+ $result = $cache->set(common_cache_key($cachekey) . ';last', $notices);
- if ($enabled === true || $enabled === 'transitional') {
- $inbox = new Notice_inbox();
- $inbox->notice_id = $this->id;
- $inbox->delete();
- }
+ # return a wrapper of the array for use now
- return;
- }
+ $wrapper = new NoticeWrapper(array_slice($notices, $offset, $limit));
+
+ return $wrapper;
+ }
+
+ function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=NULL) {
+
+ $parts = array();
+
+ $qry = 'SELECT * FROM notice ';
+
+ if (common_config('public', 'localonly')) {
+ $parts[] = 'is_local = 1';
+ } else {
+ # -1 == blacklisted
+ $parts[] = 'is_local != -1';
+ }
+
+ if ($parts) {
+ $qry .= ' WHERE ' . implode(' AND ', $parts);
+ }
+
+ return Notice::getStream($qry,
+ 'public',
+ $offset, $limit, $since_id, $before_id, NULL, $since);
+ }
+
+ function addToInboxes() {
+ $enabled = common_config('inboxes', 'enabled');
+
+ if ($enabled === true || $enabled === 'transitional') {
+ $inbox = new Notice_inbox();
+ $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
+ 'SELECT user.id, ' . $this->id . ', "' . $this->created . '" ' .
+ 'FROM user JOIN subscription ON user.id = subscription.subscriber ' .
+ 'WHERE subscription.subscribed = ' . $this->profile_id . ' ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ 'WHERE user_id = user.id ' .
+ 'AND notice_id = ' . $this->id . ' )';
+ if ($enabled === 'transitional') {
+ $qry .= ' AND user.inboxed = 1';
+ }
+ $inbox->query($qry);
+ }
+ return;
+ }
+
+ # Delete from inboxes if we're deleted.
+
+ function blowInboxes() {
+
+ $enabled = common_config('inboxes', 'enabled');
+
+ if ($enabled === true || $enabled === 'transitional') {
+ $inbox = new Notice_inbox();
+ $inbox->notice_id = $this->id;
+ $inbox->delete();
+ }
+
+ return;
+ }
}
diff --git a/_darcs/pristine/classes/NoticeWrapper.php b/_darcs/pristine/classes/NoticeWrapper.php
index f8c0aa381..edecb3092 100644
--- a/_darcs/pristine/classes/NoticeWrapper.php
+++ b/_darcs/pristine/classes/NoticeWrapper.php
@@ -35,25 +35,25 @@ class NoticeWrapper extends Notice {
public $is_local; // tinyint(1)
public $source; // varchar(32)
- var $notices = NULL;
- var $i = -1;
-
- function __construct($arr) {
- $this->notices = $arr;
- }
-
- function fetch() {
- static $fields = array('id', 'profile_id', 'uri', 'content', 'rendered',
- 'url', 'created', 'modified', 'reply_to', 'is_local', 'source');
- $this->i++;
- if ($this->i >= count($this->notices)) {
- return false;
- } else {
- $n = $this->notices[$this->i];
- foreach ($fields as $f) {
- $this->$f = $n->$f;
- }
- return true;
- }
- }
+ var $notices = NULL;
+ var $i = -1;
+
+ function __construct($arr) {
+ $this->notices = $arr;
+ }
+
+ function fetch() {
+ static $fields = array('id', 'profile_id', 'uri', 'content', 'rendered',
+ 'url', 'created', 'modified', 'reply_to', 'is_local', 'source');
+ $this->i++;
+ if ($this->i >= count($this->notices)) {
+ return false;
+ } else {
+ $n = $this->notices[$this->i];
+ foreach ($fields as $f) {
+ $this->$f = $n->$f;
+ }
+ return true;
+ }
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/classes/Notice_tag.php b/_darcs/pristine/classes/Notice_tag.php
index 5b75ff13f..84c4a1020 100644
--- a/_darcs/pristine/classes/Notice_tag.php
+++ b/_darcs/pristine/classes/Notice_tag.php
@@ -34,22 +34,22 @@ class Notice_tag extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
- static function getStream($tag, $offset=0, $limit=20) {
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN notice_tag ON notice.id = notice_tag.notice_id ' .
- 'WHERE notice_tag.tag = "%s" ';
+
+ static function getStream($tag, $offset=0, $limit=20) {
+ $qry =
+ 'SELECT notice.* ' .
+ 'FROM notice JOIN notice_tag ON notice.id = notice_tag.notice_id ' .
+ 'WHERE notice_tag.tag = "%s" ';
- return Notice::getStream(sprintf($qry, $tag),
- 'notice_tag:notice_stream:' . common_keyize($tag),
- $offset, $limit);
- }
-
- function blowCache() {
- $cache = common_memcache();
- if ($cache) {
- $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
- }
- }
+ return Notice::getStream(sprintf($qry, $tag),
+ 'notice_tag:notice_stream:' . common_keyize($tag),
+ $offset, $limit);
+ }
+
+ function blowCache() {
+ $cache = common_memcache();
+ if ($cache) {
+ $cache->delete(common_cache_key('notice_tag:notice_stream:' . $this->tag));
+ }
+ }
}
diff --git a/_darcs/pristine/classes/Profile.php b/_darcs/pristine/classes/Profile.php
index b57d7e38d..1f4508bf1 100644
--- a/_darcs/pristine/classes/Profile.php
+++ b/_darcs/pristine/classes/Profile.php
@@ -46,114 +46,114 @@ class Profile extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function getAvatar($width, $height=NULL) {
- if (is_null($height)) {
- $height = $width;
- }
- return Avatar::pkeyGet(array('profile_id' => $this->id,
- 'width' => $width,
- 'height' => $height));
- }
-
- function getOriginalAvatar() {
- $avatar = DB_DataObject::factory('avatar');
- $avatar->profile_id = $this->id;
- $avatar->original = true;
- if ($avatar->find(true)) {
- return $avatar;
- } else {
- return NULL;
- }
- }
-
- function setOriginal($source) {
-
- $info = @getimagesize($source);
-
- if (!$info) {
- return NULL;
- }
-
- $filename = common_avatar_filename($this->id,
- image_type_to_extension($info[2]),
- NULL, common_timestamp());
- $filepath = common_avatar_path($filename);
-
- copy($source, $filepath);
-
- $avatar = new Avatar();
-
- $avatar->profile_id = $this->id;
- $avatar->width = $info[0];
- $avatar->height = $info[1];
- $avatar->mediatype = image_type_to_mime_type($info[2]);
- $avatar->filename = $filename;
- $avatar->original = true;
- $avatar->url = common_avatar_url($filename);
- $avatar->created = DB_DataObject_Cast::dateTime(); # current time
-
- # XXX: start a transaction here
-
- if (!$this->delete_avatars()) {
- @unlink($filepath);
- return NULL;
- }
-
- if (!$avatar->insert()) {
- @unlink($filepath);
- return NULL;
- }
-
- foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
- # We don't do a scaled one if original is our scaled size
- if (!($avatar->width == $size && $avatar->height == $size)) {
- $s = $avatar->scale($size);
- if (!$s) {
- return NULL;
- }
- }
- }
-
- return $avatar;
- }
-
- function delete_avatars() {
- $avatar = new Avatar();
- $avatar->profile_id = $this->id;
- $avatar->find();
- while ($avatar->fetch()) {
- $avatar->delete();
- }
- return true;
- }
-
- function getBestName() {
- return ($this->fullname) ? $this->fullname : $this->nickname;
- }
+ function getAvatar($width, $height=NULL) {
+ if (is_null($height)) {
+ $height = $width;
+ }
+ return Avatar::pkeyGet(array('profile_id' => $this->id,
+ 'width' => $width,
+ 'height' => $height));
+ }
+
+ function getOriginalAvatar() {
+ $avatar = DB_DataObject::factory('avatar');
+ $avatar->profile_id = $this->id;
+ $avatar->original = true;
+ if ($avatar->find(true)) {
+ return $avatar;
+ } else {
+ return NULL;
+ }
+ }
+
+ function setOriginal($source) {
+
+ $info = @getimagesize($source);
+
+ if (!$info) {
+ return NULL;
+ }
+
+ $filename = common_avatar_filename($this->id,
+ image_type_to_extension($info[2]),
+ NULL, common_timestamp());
+ $filepath = common_avatar_path($filename);
+
+ copy($source, $filepath);
+
+ $avatar = new Avatar();
+
+ $avatar->profile_id = $this->id;
+ $avatar->width = $info[0];
+ $avatar->height = $info[1];
+ $avatar->mediatype = image_type_to_mime_type($info[2]);
+ $avatar->filename = $filename;
+ $avatar->original = true;
+ $avatar->url = common_avatar_url($filename);
+ $avatar->created = DB_DataObject_Cast::dateTime(); # current time
+
+ # XXX: start a transaction here
+
+ if (!$this->delete_avatars()) {
+ @unlink($filepath);
+ return NULL;
+ }
+
+ if (!$avatar->insert()) {
+ @unlink($filepath);
+ return NULL;
+ }
+
+ foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) {
+ # We don't do a scaled one if original is our scaled size
+ if (!($avatar->width == $size && $avatar->height == $size)) {
+ $s = $avatar->scale($size);
+ if (!$s) {
+ return NULL;
+ }
+ }
+ }
+
+ return $avatar;
+ }
+
+ function delete_avatars() {
+ $avatar = new Avatar();
+ $avatar->profile_id = $this->id;
+ $avatar->find();
+ while ($avatar->fetch()) {
+ $avatar->delete();
+ }
+ return true;
+ }
+
+ function getBestName() {
+ return ($this->fullname) ? $this->fullname : $this->nickname;
+ }
# Get latest notice on or before date; default now
- function getCurrentNotice($dt=NULL) {
- $notice = new Notice();
- $notice->profile_id = $this->id;
- if ($dt) {
- $notice->whereAdd('created < "' . $dt . '"');
- }
- $notice->orderBy('created DESC, notice.id DESC');
- $notice->limit(1);
- if ($notice->find(true)) {
- return $notice;
- }
- return NULL;
- }
-
- function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
- $qry =
- 'SELECT * ' .
- 'FROM notice ' .
- 'WHERE profile_id = %d ';
-
- return Notice::getStream(sprintf($qry, $this->id),
- 'profile:notices:'.$this->id,
- $offset, $limit, $since_id, $before_id);
- }
+ function getCurrentNotice($dt=NULL) {
+ $notice = new Notice();
+ $notice->profile_id = $this->id;
+ if ($dt) {
+ $notice->whereAdd('created < "' . $dt . '"');
+ }
+ $notice->orderBy('created DESC, notice.id DESC');
+ $notice->limit(1);
+ if ($notice->find(true)) {
+ return $notice;
+ }
+ return NULL;
+ }
+
+ function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
+ $qry =
+ 'SELECT * ' .
+ 'FROM notice ' .
+ 'WHERE profile_id = %d ';
+
+ return Notice::getStream(sprintf($qry, $this->id),
+ 'profile:notices:'.$this->id,
+ $offset, $limit, $since_id, $before_id);
+ }
}
diff --git a/_darcs/pristine/classes/Profile_tag.php b/_darcs/pristine/classes/Profile_tag.php
index dde19aea2..2daabf867 100644
--- a/_darcs/pristine/classes/Profile_tag.php
+++ b/_darcs/pristine/classes/Profile_tag.php
@@ -21,81 +21,81 @@ class Profile_tag extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- static function getTags($tagger, $tagged) {
-
- $tags = array();
+ static function getTags($tagger, $tagged) {
+
+ $tags = array();
- # XXX: store this in memcached
-
- $profile_tag = new Profile_tag();
- $profile_tag->tagger = $tagger;
- $profile_tag->tagged = $tagged;
-
- $profile_tag->find();
-
- while ($profile_tag->fetch()) {
- $tags[] = $profile_tag->tag;
- }
-
- $profile_tag->free();
-
- return $tags;
- }
-
- static function setTags($tagger, $tagged, $newtags) {
-
- $oldtags = Profile_tag::getTags($tagger, $tagged);
-
- # Delete stuff that's old that not in new
-
- $to_delete = array_diff($oldtags, $newtags);
-
- # Insert stuff that's in new and not in old
-
- $to_insert = array_diff($newtags, $oldtags);
-
- $profile_tag = new Profile_tag();
-
- $profile_tag->tagger = $tagger;
- $profile_tag->tagged = $tagged;
-
- $profile_tag->query('BEGIN');
-
- foreach ($to_delete as $deltag) {
- $profile_tag->tag = $deltag;
- $result = $profile_tag->delete();
- if (!$result) {
- common_log_db_error($profile_tag, 'DELETE', __FILE__);
- return false;
- }
- }
-
- foreach ($to_insert as $instag) {
- $profile_tag->tag = $instag;
- $result = $profile_tag->insert();
- if (!$result) {
- common_log_db_error($profile_tag, 'INSERT', __FILE__);
- return false;
- }
- }
-
- $profile_tag->query('COMMIT');
-
- return true;
- }
-
- # Return profiles with a given tag
- static function getTagged($tagger, $tag) {
- $profile = new Profile();
- $profile->query('SELECT profile.* ' .
- 'FROM profile JOIN profile_tag ' .
- 'ON profile.id = profile_tag.tagged ' .
- 'WHERE profile_tag.tagger = ' . $tagger . ' ' .
- 'AND profile_tag.tag = "' . $tag . '" ');
- $tagged = array();
- while ($profile->fetch()) {
- $tagged[] = clone($profile);
- }
- return $tagged;
- }
+ # XXX: store this in memcached
+
+ $profile_tag = new Profile_tag();
+ $profile_tag->tagger = $tagger;
+ $profile_tag->tagged = $tagged;
+
+ $profile_tag->find();
+
+ while ($profile_tag->fetch()) {
+ $tags[] = $profile_tag->tag;
+ }
+
+ $profile_tag->free();
+
+ return $tags;
+ }
+
+ static function setTags($tagger, $tagged, $newtags) {
+
+ $oldtags = Profile_tag::getTags($tagger, $tagged);
+
+ # Delete stuff that's old that not in new
+
+ $to_delete = array_diff($oldtags, $newtags);
+
+ # Insert stuff that's in new and not in old
+
+ $to_insert = array_diff($newtags, $oldtags);
+
+ $profile_tag = new Profile_tag();
+
+ $profile_tag->tagger = $tagger;
+ $profile_tag->tagged = $tagged;
+
+ $profile_tag->query('BEGIN');
+
+ foreach ($to_delete as $deltag) {
+ $profile_tag->tag = $deltag;
+ $result = $profile_tag->delete();
+ if (!$result) {
+ common_log_db_error($profile_tag, 'DELETE', __FILE__);
+ return false;
+ }
+ }
+
+ foreach ($to_insert as $instag) {
+ $profile_tag->tag = $instag;
+ $result = $profile_tag->insert();
+ if (!$result) {
+ common_log_db_error($profile_tag, 'INSERT', __FILE__);
+ return false;
+ }
+ }
+
+ $profile_tag->query('COMMIT');
+
+ return true;
+ }
+
+ # Return profiles with a given tag
+ static function getTagged($tagger, $tag) {
+ $profile = new Profile();
+ $profile->query('SELECT profile.* ' .
+ 'FROM profile JOIN profile_tag ' .
+ 'ON profile.id = profile_tag.tagged ' .
+ 'WHERE profile_tag.tagger = ' . $tagger . ' ' .
+ 'AND profile_tag.tag = "' . $tag . '" ');
+ $tagged = array();
+ while ($profile->fetch()) {
+ $tagged[] = clone($profile);
+ }
+ return $tagged;
+ }
}
diff --git a/_darcs/pristine/classes/Queue_item.php b/_darcs/pristine/classes/Queue_item.php
index 8ba3281de..e54b4976b 100644
--- a/_darcs/pristine/classes/Queue_item.php
+++ b/_darcs/pristine/classes/Queue_item.php
@@ -22,34 +22,34 @@ class Queue_item extends Memcached_DataObject
###END_AUTOCODE
function sequenceKey() { return array(false, false); }
-
- static function top($transport) {
-
- $qi = new Queue_item();
- $qi->transport = $transport;
- $qi->orderBy('created');
- $qi->whereAdd('claimed is NULL');
-
- $qi->limit(1);
-
- $cnt = $qi->find(TRUE);
-
- if ($cnt) {
- # XXX: potential race condition
- # can we force it to only update if claimed is still NULL
- # (or old)?
- common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport);
- $orig = clone($qi);
- $qi->claimed = common_sql_now();
- $result = $qi->update($orig);
- if ($result) {
- common_log(LOG_INFO, 'claim succeeded.');
- return $qi;
- } else {
- common_log(LOG_INFO, 'claim failed.');
- }
- }
- $qi = NULL;
- return NULL;
- }
+
+ static function top($transport) {
+
+ $qi = new Queue_item();
+ $qi->transport = $transport;
+ $qi->orderBy('created');
+ $qi->whereAdd('claimed is NULL');
+
+ $qi->limit(1);
+
+ $cnt = $qi->find(TRUE);
+
+ if ($cnt) {
+ # XXX: potential race condition
+ # can we force it to only update if claimed is still NULL
+ # (or old)?
+ common_log(LOG_INFO, 'claiming queue item = ' . $qi->notice_id . ' for transport ' . $transport);
+ $orig = clone($qi);
+ $qi->claimed = common_sql_now();
+ $result = $qi->update($orig);
+ if ($result) {
+ common_log(LOG_INFO, 'claim succeeded.');
+ return $qi;
+ } else {
+ common_log(LOG_INFO, 'claim failed.');
+ }
+ }
+ $qi = NULL;
+ return NULL;
+ }
}
diff --git a/_darcs/pristine/classes/Sms_carrier.php b/_darcs/pristine/classes/Sms_carrier.php
index 6ecb51346..f6e0791f9 100644
--- a/_darcs/pristine/classes/Sms_carrier.php
+++ b/_darcs/pristine/classes/Sms_carrier.php
@@ -21,8 +21,8 @@ class Sms_carrier extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
- function toEmailAddress($sms) {
- return sprintf($this->email_pattern, $sms);
- }
+
+ function toEmailAddress($sms) {
+ return sprintf($this->email_pattern, $sms);
+ }
}
diff --git a/_darcs/pristine/classes/Subscription.php b/_darcs/pristine/classes/Subscription.php
index cc174fcce..a3b5e4b90 100644
--- a/_darcs/pristine/classes/Subscription.php
+++ b/_darcs/pristine/classes/Subscription.php
@@ -44,8 +44,8 @@ class Subscription extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
-
- function &pkeyGet($kv) {
- return Memcached_DataObject::pkeyGet('Subscription', $kv);
- }
+
+ function &pkeyGet($kv) {
+ return Memcached_DataObject::pkeyGet('Subscription', $kv);
+ }
}
diff --git a/_darcs/pristine/classes/User.php b/_darcs/pristine/classes/User.php
index 32d5bedde..c2c6ad57f 100644
--- a/_darcs/pristine/classes/User.php
+++ b/_darcs/pristine/classes/User.php
@@ -67,82 +67,82 @@ class User extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- function getProfile() {
- return Profile::staticGet('id', $this->id);
- }
-
- function isSubscribed($other) {
- assert(!is_null($other));
- # XXX: cache results of this query
- $sub = Subscription::pkeyGet(array('subscriber' => $this->id,
- 'subscribed' => $other->id));
- return (is_null($sub)) ? false : true;
- }
-
- # 'update' won't write key columns, so we have to do it ourselves.
-
- function updateKeys(&$orig) {
- $parts = array();
- foreach (array('nickname', 'email', 'jabber', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) {
- if (strcmp($this->$k, $orig->$k) != 0) {
- $parts[] = $k . ' = ' . $this->_quote($this->$k);
- }
- }
- if (count($parts) == 0) {
- # No changes
- return true;
- }
- $toupdate = implode(', ', $parts);
-
- $table = $this->tableName();
- if(common_config('db','quote_identifiers')) {
- $table = '"' . $table . '"';
- }
- $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
- ' WHERE id = ' . $this->id;
- $orig->decache();
- $result = $this->query($qry);
- if ($result) {
- $this->encache();
- }
- return $result;
- }
-
- function allowed_nickname($nickname) {
- # XXX: should already be validated for size, content, etc.
- static $blacklist = array('rss', 'xrds', 'doc', 'main',
- 'settings', 'notice', 'user',
- 'search', 'avatar', 'tag', 'tags',
- 'api', 'message');
- $merged = array_merge($blacklist, common_config('nickname', 'blacklist'));
- return !in_array($nickname, $merged);
- }
-
- function getCurrentNotice($dt=NULL) {
- $profile = $this->getProfile();
- if (!$profile) {
- return NULL;
- }
- return $profile->getCurrentNotice($dt);
- }
-
- function getCarrier() {
- return Sms_carrier::staticGet('id', $this->carrier);
- }
-
- function subscribeTo($other) {
- $sub = new Subscription();
- $sub->subscriber = $this->id;
- $sub->subscribed = $other->id;
-
- $sub->created = common_sql_now(); # current time
-
- if (!$sub->insert()) {
- return false;
- }
-
- return true;
- }
+ function getProfile() {
+ return Profile::staticGet('id', $this->id);
+ }
+
+ function isSubscribed($other) {
+ assert(!is_null($other));
+ # XXX: cache results of this query
+ $sub = Subscription::pkeyGet(array('subscriber' => $this->id,
+ 'subscribed' => $other->id));
+ return (is_null($sub)) ? false : true;
+ }
+
+ # 'update' won't write key columns, so we have to do it ourselves.
+
+ function updateKeys(&$orig) {
+ $parts = array();
+ foreach (array('nickname', 'email', 'jabber', 'incomingemail', 'sms', 'carrier', 'smsemail', 'language', 'timezone') as $k) {
+ if (strcmp($this->$k, $orig->$k) != 0) {
+ $parts[] = $k . ' = ' . $this->_quote($this->$k);
+ }
+ }
+ if (count($parts) == 0) {
+ # No changes
+ return true;
+ }
+ $toupdate = implode(', ', $parts);
+
+ $table = $this->tableName();
+ if(common_config('db','quote_identifiers')) {
+ $table = '"' . $table . '"';
+ }
+ $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
+ ' WHERE id = ' . $this->id;
+ $orig->decache();
+ $result = $this->query($qry);
+ if ($result) {
+ $this->encache();
+ }
+ return $result;
+ }
+
+ function allowed_nickname($nickname) {
+ # XXX: should already be validated for size, content, etc.
+ static $blacklist = array('rss', 'xrds', 'doc', 'main',
+ 'settings', 'notice', 'user',
+ 'search', 'avatar', 'tag', 'tags',
+ 'api', 'message');
+ $merged = array_merge($blacklist, common_config('nickname', 'blacklist'));
+ return !in_array($nickname, $merged);
+ }
+
+ function getCurrentNotice($dt=NULL) {
+ $profile = $this->getProfile();
+ if (!$profile) {
+ return NULL;
+ }
+ return $profile->getCurrentNotice($dt);
+ }
+
+ function getCarrier() {
+ return Sms_carrier::staticGet('id', $this->carrier);
+ }
+
+ function subscribeTo($other) {
+ $sub = new Subscription();
+ $sub->subscriber = $this->id;
+ $sub->subscribed = $other->id;
+
+ $sub->created = common_sql_now(); # current time
+
+ if (!$sub->insert()) {
+ return false;
+ }
+
+ return true;
+ }
function hasBlocked($other) {
@@ -158,193 +158,193 @@ class User extends Memcached_DataObject
return $result;
}
- static function register($fields) {
+ static function register($fields) {
+
+ # MAGICALLY put fields into current scope
+
+ extract($fields);
+
+ $profile = new Profile();
+
+ $profile->query('BEGIN');
+
+ $profile->nickname = $nickname;
+ $profile->profileurl = common_profile_url($nickname);
+
+ if ($fullname) {
+ $profile->fullname = $fullname;
+ }
+ if ($homepage) {
+ $profile->homepage = $homepage;
+ }
+ if ($bio) {
+ $profile->bio = $bio;
+ }
+ if ($location) {
+ $profile->location = $location;
+ }
+
+ $profile->created = common_sql_now();
+
+ $id = $profile->insert();
+
+ if (!$id) {
+ common_log_db_error($profile, 'INSERT', __FILE__);
+ return FALSE;
+ }
+
+ $user = new User();
- # MAGICALLY put fields into current scope
+ $user->id = $id;
+ $user->nickname = $nickname;
- extract($fields);
+ if ($password) { # may not have a password for OpenID users
+ $user->password = common_munge_password($password, $id);
+ }
+
+ # Users who respond to invite email have proven their ownership of that address
+
+ if ($code) {
+ $invite = Invitation::staticGet($code);
+ if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
+ $user->email = $invite->address;
+ }
+ }
+
+ $inboxes = common_config('inboxes', 'enabled');
- $profile = new Profile();
+ if ($inboxes === true || $inboxes == 'transitional') {
+ $user->inboxed = 1;
+ }
+
+ $user->created = common_sql_now();
+ $user->uri = common_user_uri($user);
+
+ $result = $user->insert();
+
+ if (!$result) {
+ common_log_db_error($user, 'INSERT', __FILE__);
+ return FALSE;
+ }
- $profile->query('BEGIN');
+ # Everyone is subscribed to themself
- $profile->nickname = $nickname;
- $profile->profileurl = common_profile_url($nickname);
+ $subscription = new Subscription();
+ $subscription->subscriber = $user->id;
+ $subscription->subscribed = $user->id;
+ $subscription->created = $user->created;
- if ($fullname) {
- $profile->fullname = $fullname;
- }
- if ($homepage) {
- $profile->homepage = $homepage;
- }
- if ($bio) {
- $profile->bio = $bio;
- }
- if ($location) {
- $profile->location = $location;
- }
+ $result = $subscription->insert();
+
+ if (!$result) {
+ common_log_db_error($subscription, 'INSERT', __FILE__);
+ return FALSE;
+ }
+
+ if ($email && !$user->email) {
+
+ $confirm = new Confirm_address();
+ $confirm->code = common_confirmation_code(128);
+ $confirm->user_id = $user->id;
+ $confirm->address = $email;
+ $confirm->address_type = 'email';
+
+ $result = $confirm->insert();
+ if (!$result) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ return FALSE;
+ }
+ }
+
+ if ($code && $user->email) {
+ $user->emailChanged();
+ }
- $profile->created = common_sql_now();
+ $profile->query('COMMIT');
- $id = $profile->insert();
+ if ($email && !$user->email) {
+ mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
+ }
- if (!$id) {
- common_log_db_error($profile, 'INSERT', __FILE__);
- return FALSE;
- }
+ return $user;
+ }
- $user = new User();
+ # Things we do when the email changes
- $user->id = $id;
- $user->nickname = $nickname;
+ function emailChanged() {
- if ($password) { # may not have a password for OpenID users
- $user->password = common_munge_password($password, $id);
- }
+ $invites = new Invitation();
+ $invites->address = $this->email;
+ $invites->address_type = 'email';
- # Users who respond to invite email have proven their ownership of that address
+ if ($invites->find()) {
+ while ($invites->fetch()) {
+ $other = User::staticGet($invites->user_id);
+ subs_subscribe_to($other, $this);
+ }
+ }
+ }
- if ($code) {
- $invite = Invitation::staticGet($code);
- if ($invite && $invite->address && $invite->address_type == 'email' && $invite->address == $email) {
- $user->email = $invite->address;
- }
- }
-
- $inboxes = common_config('inboxes', 'enabled');
-
- if ($inboxes === true || $inboxes == 'transitional') {
- $user->inboxed = 1;
- }
-
- $user->created = common_sql_now();
- $user->uri = common_user_uri($user);
-
- $result = $user->insert();
-
- if (!$result) {
- common_log_db_error($user, 'INSERT', __FILE__);
- return FALSE;
- }
-
- # Everyone is subscribed to themself
-
- $subscription = new Subscription();
- $subscription->subscriber = $user->id;
- $subscription->subscribed = $user->id;
- $subscription->created = $user->created;
-
- $result = $subscription->insert();
-
- if (!$result) {
- common_log_db_error($subscription, 'INSERT', __FILE__);
- return FALSE;
- }
-
- if ($email && !$user->email) {
-
- $confirm = new Confirm_address();
- $confirm->code = common_confirmation_code(128);
- $confirm->user_id = $user->id;
- $confirm->address = $email;
- $confirm->address_type = 'email';
-
- $result = $confirm->insert();
- if (!$result) {
- common_log_db_error($confirm, 'INSERT', __FILE__);
- return FALSE;
- }
- }
-
- if ($code && $user->email) {
- $user->emailChanged();
- }
-
- $profile->query('COMMIT');
-
- if ($email && !$user->email) {
- mail_confirm_address($user, $confirm->code, $profile->nickname, $email);
- }
-
- return $user;
- }
-
- # Things we do when the email changes
-
- function emailChanged() {
-
- $invites = new Invitation();
- $invites->address = $this->email;
- $invites->address_type = 'email';
-
- if ($invites->find()) {
- while ($invites->fetch()) {
- $other = User::staticGet($invites->user_id);
- subs_subscribe_to($other, $this);
- }
- }
- }
-
- function hasFave($notice) {
- $cache = common_memcache();
-
- # XXX: Kind of a hack.
- if ($cache) {
- # This is the stream of favorite notices, in rev chron
- # order. This forces it into cache.
- $faves = $this->favoriteNotices(0, NOTICE_CACHE_WINDOW);
- $cnt = 0;
- while ($faves->fetch()) {
- if ($faves->id < $notice->id) {
- # If we passed it, it's not a fave
- return false;
- } else if ($faves->id == $notice->id) {
- # If it matches a cached notice, then it's a fave
- return true;
- }
- $cnt++;
- }
- # If we're not past the end of the cache window,
- # then the cache has all available faves, so this one
- # is not a fave.
- if ($cnt < NOTICE_CACHE_WINDOW) {
- return false;
- }
- # Otherwise, cache doesn't have all faves;
- # fall through to the default
- }
- $fave = Fave::pkeyGet(array('user_id' => $this->id,
- 'notice_id' => $notice->id));
- return ((is_null($fave)) ? false : true);
- }
- function mutuallySubscribed($other) {
- return $this->isSubscribed($other) &&
- $other->isSubscribed($this);
- }
+ function hasFave($notice) {
+ $cache = common_memcache();
+
+ # XXX: Kind of a hack.
+ if ($cache) {
+ # This is the stream of favorite notices, in rev chron
+ # order. This forces it into cache.
+ $faves = $this->favoriteNotices(0, NOTICE_CACHE_WINDOW);
+ $cnt = 0;
+ while ($faves->fetch()) {
+ if ($faves->id < $notice->id) {
+ # If we passed it, it's not a fave
+ return false;
+ } else if ($faves->id == $notice->id) {
+ # If it matches a cached notice, then it's a fave
+ return true;
+ }
+ $cnt++;
+ }
+ # If we're not past the end of the cache window,
+ # then the cache has all available faves, so this one
+ # is not a fave.
+ if ($cnt < NOTICE_CACHE_WINDOW) {
+ return false;
+ }
+ # Otherwise, cache doesn't have all faves;
+ # fall through to the default
+ }
+ $fave = Fave::pkeyGet(array('user_id' => $this->id,
+ 'notice_id' => $notice->id));
+ return ((is_null($fave)) ? false : true);
+ }
+ function mutuallySubscribed($other) {
+ return $this->isSubscribed($other) &&
+ $other->isSubscribed($this);
+ }
function mutuallySubscribedUsers() {
- # 3-way join; probably should get cached
- $qry = 'SELECT user.* ' .
- 'FROM subscription sub1 JOIN user ON sub1.subscribed = user.id ' .
- 'JOIN subscription sub2 ON user.id = sub2.subscriber ' .
- 'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
- 'ORDER BY user.nickname';
- $user = new User();
- $user->query(sprintf($qry, $this->id, $this->id));
-
- return $user;
- }
-
- function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=NULL) {
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN reply ON notice.id = reply.notice_id ' .
- 'WHERE reply.profile_id = %d ';
- return Notice::getStream(sprintf($qry, $this->id),
- 'user:replies:'.$this->id,
- $offset, $limit, $since_id, $before_id, NULL, $since);
- }
+ # 3-way join; probably should get cached
+ $qry = 'SELECT user.* ' .
+ 'FROM subscription sub1 JOIN user ON sub1.subscribed = user.id ' .
+ 'JOIN subscription sub2 ON user.id = sub2.subscriber ' .
+ 'WHERE sub1.subscriber = %d and sub2.subscribed = %d ' .
+ 'ORDER BY user.nickname';
+ $user = new User();
+ $user->query(sprintf($qry, $this->id, $this->id));
+
+ return $user;
+ }
+
+ function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=NULL) {
+ $qry =
+ 'SELECT notice.* ' .
+ 'FROM notice JOIN reply ON notice.id = reply.notice_id ' .
+ 'WHERE reply.profile_id = %d ';
+ return Notice::getStream(sprintf($qry, $this->id),
+ 'user:replies:'.$this->id,
+ $offset, $limit, $since_id, $before_id, NULL, $since);
+ }
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=NULL) {
$profile = $this->getProfile();
@@ -353,64 +353,64 @@ class User extends Memcached_DataObject
} else {
return $profile->getNotices($offset, $limit, $since_id, $before_id);
}
- }
+ }
function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE) {
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
- 'WHERE fave.user_id = %d ';
- return Notice::getStream(sprintf($qry, $this->id),
- 'user:faves:'.$this->id,
- $offset, $limit);
- }
+ $qry =
+ 'SELECT notice.* ' .
+ 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
+ 'WHERE fave.user_id = %d ';
+ return Notice::getStream(sprintf($qry, $this->id),
+ 'user:faves:'.$this->id,
+ $offset, $limit);
+ }
function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=NULL) {
- $enabled = common_config('inboxes', 'enabled');
-
- # Complicated code, depending on whether we support inboxes yet
- # XXX: make this go away when inboxes become mandatory
-
- if ($enabled === false ||
- ($enabled == 'transitional' && $this->inboxed == 0)) {
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
- 'WHERE subscription.subscriber = %d ';
- $order = NULL;
- } else if ($enabled === true ||
- ($enabled == 'transitional' && $this->inboxed == 1)) {
-
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
- 'WHERE notice_inbox.user_id = %d ';
- # NOTE: we override ORDER
- $order = 'ORDER BY notice_inbox.created DESC, notice_inbox.notice_id DESC ';
- }
- return Notice::getStream(sprintf($qry, $this->id),
- 'user:notices_with_friends:' . $this->id,
- $offset, $limit, $since_id, $before_id,
- $order, $since);
- }
+ $enabled = common_config('inboxes', 'enabled');
+
+ # Complicated code, depending on whether we support inboxes yet
+ # XXX: make this go away when inboxes become mandatory
+
+ if ($enabled === false ||
+ ($enabled == 'transitional' && $this->inboxed == 0)) {
+ $qry =
+ 'SELECT notice.* ' .
+ 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
+ 'WHERE subscription.subscriber = %d ';
+ $order = NULL;
+ } else if ($enabled === true ||
+ ($enabled == 'transitional' && $this->inboxed == 1)) {
+
+ $qry =
+ 'SELECT notice.* ' .
+ 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
+ 'WHERE notice_inbox.user_id = %d ';
+ # NOTE: we override ORDER
+ $order = 'ORDER BY notice_inbox.created DESC, notice_inbox.notice_id DESC ';
+ }
+ return Notice::getStream(sprintf($qry, $this->id),
+ 'user:notices_with_friends:' . $this->id,
+ $offset, $limit, $since_id, $before_id,
+ $order, $since);
+ }
function blowFavesCache() {
- $cache = common_memcache();
- if ($cache) {
- # Faves don't happen chronologically, so we need to blow
- # ;last cache, too
- $cache->delete(common_cache_key('user:faves:'.$this->id));
- $cache->delete(common_cache_key('user:faves:'.$this->id).';last');
- }
- }
+ $cache = common_memcache();
+ if ($cache) {
+ # Faves don't happen chronologically, so we need to blow
+ # ;last cache, too
+ $cache->delete(common_cache_key('user:faves:'.$this->id));
+ $cache->delete(common_cache_key('user:faves:'.$this->id).';last');
+ }
+ }
function getSelfTags() {
- return Profile_tag::getTags($this->id, $this->id);
- }
+ return Profile_tag::getTags($this->id, $this->id);
+ }
function setSelfTags($newtags) {
- return Profile_tag::setTags($this->id, $this->id, $newtags);
- }
+ return Profile_tag::setTags($this->id, $this->id, $newtags);
+ }
function block($other) {
@@ -434,8 +434,8 @@ class User extends Memcached_DataObject
# Cancel their subscription, if it exists
- $sub = Subscription::pkeyGet(array('subscriber' => $other->id,
- 'subscribed' => $this->id));
+ $sub = Subscription::pkeyGet(array('subscriber' => $other->id,
+ 'subscribed' => $this->id));
if ($sub) {
$result = $sub->delete();
diff --git a/_darcs/pristine/lib/common.php b/_darcs/pristine/lib/common.php
index 5a28c3091..95ba64d0f 100644
--- a/_darcs/pristine/lib/common.php
+++ b/_darcs/pristine/lib/common.php
@@ -54,100 +54,100 @@ require_once(INSTALLDIR.'/lib/language.php');
$config =
array('site' =>
- array('name' => 'Just another Laconica microblog',
- 'server' => 'localhost',
- 'theme' => 'default',
- 'path' => '/',
- 'logfile' => NULL,
- 'fancy' => false,
- 'locale_path' => INSTALLDIR.'/locale',
- 'language' => 'en_US',
- 'languages' => get_all_languages(),
- 'email' =>
- array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
- 'broughtby' => NULL,
- 'timezone' => 'UTC',
- 'broughtbyurl' => NULL,
- 'closed' => false,
- 'inviteonly' => false,
+ array('name' => 'Just another Laconica microblog',
+ 'server' => 'localhost',
+ 'theme' => 'default',
+ 'path' => '/',
+ 'logfile' => NULL,
+ 'fancy' => false,
+ 'locale_path' => INSTALLDIR.'/locale',
+ 'language' => 'en_US',
+ 'languages' => get_all_languages(),
+ 'email' =>
+ array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL,
+ 'broughtby' => NULL,
+ 'timezone' => 'UTC',
+ 'broughtbyurl' => NULL,
+ 'closed' => false,
+ 'inviteonly' => false,
'private' => false),
- 'syslog' =>
- array('appname' => 'laconica', # for syslog
- 'priority' => 'debug'), # XXX: currently ignored
- 'queue' =>
- array('enabled' => false),
- 'license' =>
- array('url' => 'http://creativecommons.org/licenses/by/3.0/',
- 'title' => 'Creative Commons Attribution 3.0',
- 'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'),
- 'mail' =>
- array('backend' => 'mail',
- 'params' => NULL),
- 'nickname' =>
- array('blacklist' => array(),
- 'featured' => array()),
- 'profile' =>
- array('banned' => array()),
- 'avatar' =>
- array('server' => NULL),
- 'public' =>
- array('localonly' => true,
- 'blacklist' => array()),
- 'theme' =>
- array('server' => NULL),
- 'throttle' =>
+ 'syslog' =>
+ array('appname' => 'laconica', # for syslog
+ 'priority' => 'debug'), # XXX: currently ignored
+ 'queue' =>
+ array('enabled' => false),
+ 'license' =>
+ array('url' => 'http://creativecommons.org/licenses/by/3.0/',
+ 'title' => 'Creative Commons Attribution 3.0',
+ 'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'),
+ 'mail' =>
+ array('backend' => 'mail',
+ 'params' => NULL),
+ 'nickname' =>
+ array('blacklist' => array(),
+ 'featured' => array()),
+ 'profile' =>
+ array('banned' => array()),
+ 'avatar' =>
+ array('server' => NULL),
+ 'public' =>
+ array('localonly' => true,
+ 'blacklist' => array()),
+ 'theme' =>
+ array('server' => NULL),
+ 'throttle' =>
array('enabled' => false, // whether to throttle edits; false by default
'count' => 20, // number of allowed messages in timespan
'timespan' => 600), // timespan for throttling
- 'xmpp' =>
- array('enabled' => false,
- 'server' => 'INVALID SERVER',
- 'port' => 5222,
- 'user' => 'update',
- 'encryption' => true,
- 'resource' => 'uniquename',
- 'password' => 'blahblahblah',
- 'host' => NULL, # only set if != server
- 'debug' => false, # print extra debug info
- 'public' => array()), # JIDs of users who want to receive the public stream
+ 'xmpp' =>
+ array('enabled' => false,
+ 'server' => 'INVALID SERVER',
+ 'port' => 5222,
+ 'user' => 'update',
+ 'encryption' => true,
+ 'resource' => 'uniquename',
+ 'password' => 'blahblahblah',
+ 'host' => NULL, # only set if != server
+ 'debug' => false, # print extra debug info
+ 'public' => array()), # JIDs of users who want to receive the public stream
'sphinx' =>
array('enabled' => false,
'server' => 'localhost',
'port' => 3312),
- 'tag' =>
- array('dropoff' => 864000.0),
- 'popular' =>
- array('dropoff' => 864000.0),
- 'daemon' =>
- array('piddir' => '/var/run',
- 'user' => false,
- 'group' => false),
- 'integration' =>
- array('source' => 'Laconica'), # source attribute for Twitter
- 'memcached' =>
- array('enabled' => false,
- 'server' => 'localhost',
- 'port' => 11211),
- 'inboxes' =>
- array('enabled' => true), # on by default for new sites
- );
+ 'tag' =>
+ array('dropoff' => 864000.0),
+ 'popular' =>
+ array('dropoff' => 864000.0),
+ 'daemon' =>
+ array('piddir' => '/var/run',
+ 'user' => false,
+ 'group' => false),
+ 'integration' =>
+ array('source' => 'Laconica'), # source attribute for Twitter
+ 'memcached' =>
+ array('enabled' => false,
+ 'server' => 'localhost',
+ 'port' => 11211),
+ 'inboxes' =>
+ array('enabled' => true), # on by default for new sites
+ );
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
$config['db'] =
array('database' => 'YOU HAVE TO SET THIS IN config.php',
- 'schema_location' => INSTALLDIR . '/classes',
- 'class_location' => INSTALLDIR . '/classes',
- 'require_prefix' => 'classes/',
- 'class_prefix' => '',
- 'mirror' => NULL,
+ 'schema_location' => INSTALLDIR . '/classes',
+ 'class_location' => INSTALLDIR . '/classes',
+ 'require_prefix' => 'classes/',
+ 'class_prefix' => '',
+ 'mirror' => NULL,
'db_driver' => 'DB', # XXX: JanRain libs only work with DB
- 'quote_identifiers' => false,
- 'type' => 'mysql' );
+ 'quote_identifiers' => false,
+ 'type' => 'mysql' );
if (function_exists('date_default_timezone_set')) {
- /* Work internally in UTC */
- date_default_timezone_set('UTC');
+ /* Work internally in UTC */
+ date_default_timezone_set('UTC');
}
require_once(INSTALLDIR.'/config.php');
@@ -164,9 +164,9 @@ require_once(INSTALLDIR.'/lib/Shorturl_api.php');
require_once(INSTALLDIR.'/lib/twitter.php');
function __autoload($class) {
- if ($class == 'OAuthRequest') {
- require_once('OAuth.php');
- } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) {
+ if ($class == 'OAuthRequest') {
+ require_once('OAuth.php');
+ } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) {
require_once(INSTALLDIR.'/classes/' . $class . '.php');
}
}
diff --git a/_darcs/pristine/lib/deleteaction.php b/_darcs/pristine/lib/deleteaction.php
index 5ba0e7e44..335070cc4 100644
--- a/_darcs/pristine/lib/deleteaction.php
+++ b/_darcs/pristine/lib/deleteaction.php
@@ -21,41 +21,41 @@ if (!defined('LACONICA')) { exit(1); }
class DeleteAction extends Action {
- function handle($args) {
- parent::handle($args);
- $user = common_current_user();
- $notice_id = $this->trimmed('notice');
- $notice = Notice::staticGet($notice_id);
- if (!$notice) {
- common_user_error(_('No such notice.'));
- exit;
- }
-
- $profile = $notice->getProfile();
- $user_profile = $user->getProfile();
-
- if (!common_logged_in()) {
- common_user_error(_('Not logged in.'));
- exit;
- } else if ($notice->profile_id != $user_profile->id) {
- common_user_error(_('Can\'t delete this notice.'));
- exit;
- }
- }
-
- function show_top($arr=NULL) {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
-
- function get_title() {
- return NULL;
- }
-
- function show_header() {
- return;
- }
+ function handle($args) {
+ parent::handle($args);
+ $user = common_current_user();
+ $notice_id = $this->trimmed('notice');
+ $notice = Notice::staticGet($notice_id);
+ if (!$notice) {
+ common_user_error(_('No such notice.'));
+ exit;
+ }
+
+ $profile = $notice->getProfile();
+ $user_profile = $user->getProfile();
+
+ if (!common_logged_in()) {
+ common_user_error(_('Not logged in.'));
+ exit;
+ } else if ($notice->profile_id != $user_profile->id) {
+ common_user_error(_('Can\'t delete this notice.'));
+ exit;
+ }
+ }
+
+ function show_top($arr=NULL) {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+
+ function get_title() {
+ return NULL;
+ }
+
+ function show_header() {
+ return;
+ }
}
diff --git a/_darcs/pristine/lib/facebookaction.php b/_darcs/pristine/lib/facebookaction.php
index 87a82ba01..67595861f 100644
--- a/_darcs/pristine/lib/facebookaction.php
+++ b/_darcs/pristine/lib/facebookaction.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -23,261 +23,261 @@ require_once(INSTALLDIR.'/extlib/facebook/facebook.php');
class FacebookAction extends Action {
- function handle($args) {
- parent::handle($args);
- }
-
- function get_facebook() {
- $apikey = common_config('facebook', 'apikey');
- $secret = common_config('facebook', 'secret');
- return new Facebook($apikey, $secret);
- }
-
- function update_profile_box($facebook, $fbuid, $user) {
-
- $notice = $user->getCurrentNotice();
-
- # Need to include inline CSS for styling the Profile box
-
- $style = '<style>
- #notices {
- clear: both;
- margin: 0 auto;
- padding: 0;
- list-style-type: none;
- width: 600px;
- border-top: 1px solid #dec5b5;
- }
- #notices a:hover {
- text-decoration: underline;
- }
- .notice_single {
- clear: both;
- display: block;
- margin: 0;
- padding: 5px 5px 5px 0;
- min-height: 48px;
- font-family: Georgia, "Times New Roman", Times, serif;
- font-size: 13px;
- line-height: 16px;
- border-bottom: 1px solid #dec5b5;
- background-color:#FCFFF5;
- opacity:1;
- }
- .notice_single:hover {
- background-color: #f7ebcc;
- }
- .notice_single p {
- display: inline;
- margin: 0;
- padding: 0;
- }
- </style>';
-
- $html = $this->render_notice($notice);
-
- $fbml = "<fb:wide>$content $html</fb:wide>";
- $fbml .= "<fb:narrow>$content $html</fb:narrow>";
-
- $fbml_main = "<fb:narrow>$content $html</fb:narrow>";
-
- $facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
- }
-
- # Display methods
-
- function show_header($selected ='Home') {
-
- # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
- $ts = filemtime(theme_file('facebookapp.css'));
- $cssurl = theme_path('facebookapp.css') . "?ts=$ts";
-
- $header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />';
- # $header .='<script src="" ></script>';
- $header .= '<fb:dashboard/>';
-
- $header .=
- '<fb:tabs>'
- .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
- .'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />'
- .'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />'
- .'</fb:tabs>';
- $header .= '<div id="main_body">';
-
- echo $header;
-
- }
-
- function show_footer() {
- $footer = '</div>';
- echo $footer;
- }
-
- function show_login_form() {
-
- $loginform =
- ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
- .'<a href="http://identi.ca/">'
- .' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
- .'</a>'
- .'<h1 class="pagetitle">Login</h1>'
- .'<div class="instructions">'
- .' <p>Login with your username and password. Don\'t have a username yet?'
- .' <a href="http://identi.ca/main/register">Register</a> a new account.'
- .' </p>'
- .'</div>'
- .'<div id="content">'
- .' <form method="post" id="login">'
- .' <p>'
- .' <label for="nickname">Nickname</label>'
- .' <input name="nickname" type="text" class="input_text" id="nickname"/>'
- .' </p>'
- .' <p>'
- .' <label for="password">Password</label>'
- .' <input name="password" type="password" class="password" id="password"/>'
- .' </p>'
- .' <p>'
- .' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
- .' </p>'
- .' </form>'
- .' <p>'
- .' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
- .' </p>'
- .'</div';
-
- echo $loginform;
- }
-
- function render_notice($notice) {
-
- global $config;
-
- $profile = $notice->getProfile();
- $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
-
- $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
-
- # XXX: we need to figure this out better. Is this right?
- if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
- $noticeurl = $notice->uri;
- }
-
- $html =
- '<li class="notice_single" id="' . $notice->id . '">'
- .'<a href="' . $profile->profileurl . '">'
- .'<img src="';
-
- if ($avatar) {
- $html .= common_avatar_display_url($avatar);
- } else {
- $html .= common_default_avatar(AVATAR_STREAM_SIZE);
- }
-
- $html .=
- '" class="avatar stream" width="'
- . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
- .' alt="';
-
- if ($profile->fullname) {
- $html .= $profile->fullname;
- } else {
- $html .= $profile->nickname;
- }
-
- $html .=
- '"></a>'
- .'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
- .'<p class="content">' . $notice->rendered . '</p>'
- .'<p class="time">'
- .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
-
- if ($notice->source) {
- $html .= _(' from ');
- $html .= $this->source_link($notice->source);
- }
-
- if ($notice->reply_to) {
- $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
- $html .=
- ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
- }
-
- $html .= '</p></li>';
-
- return $html;
- }
-
- function source_link($source) {
- $source_name = _($source);
-
- $html = '<span class="noticesource">';
-
- switch ($source) {
- case 'web':
- case 'xmpp':
- case 'mail':
- case 'omb':
- case 'api':
- $html .= $source_name;
- break;
- default:
- $ns = Notice_source::staticGet($source);
- if ($ns) {
- $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
- } else {
- $html .= $source_name;
- }
- break;
- }
-
- $html .= '</span>';
-
- return $html;
- }
-
- function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
-
- $html = '';
-
- if ($have_before || $have_after) {
- $html = '<div id="pagination">';
- $html .'<ul id="nav_pagination">';
- }
-
- if ($have_before) {
- $pargs = array('page' => $page-1);
- $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
- $html .= '<li class="before">';
- $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
- $html .'</li>';
- }
-
- if ($have_after) {
- $pargs = array('page' => $page+1);
- $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
- $html .= '<li class="after">';
- $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
- $html .'</li>';
- }
-
- if ($have_before || $have_after) {
- $html .= '<ul>';
- $html .'<div>';
- }
- }
-
- function pagination_url($fbaction, $args=NULL) {
- global $config;
-
- $extra = '';
-
- if ($args) {
- foreach ($args as $key => $value) {
- $extra .= "&${key}=${value}";
- }
- }
-
- return "$fbaction?${extra}";
- }
+ function handle($args) {
+ parent::handle($args);
+ }
+
+ function get_facebook() {
+ $apikey = common_config('facebook', 'apikey');
+ $secret = common_config('facebook', 'secret');
+ return new Facebook($apikey, $secret);
+ }
+
+ function update_profile_box($facebook, $fbuid, $user) {
+
+ $notice = $user->getCurrentNotice();
+
+ # Need to include inline CSS for styling the Profile box
+
+ $style = '<style>
+ #notices {
+ clear: both;
+ margin: 0 auto;
+ padding: 0;
+ list-style-type: none;
+ width: 600px;
+ border-top: 1px solid #dec5b5;
+ }
+ #notices a:hover {
+ text-decoration: underline;
+ }
+ .notice_single {
+ clear: both;
+ display: block;
+ margin: 0;
+ padding: 5px 5px 5px 0;
+ min-height: 48px;
+ font-family: Georgia, "Times New Roman", Times, serif;
+ font-size: 13px;
+ line-height: 16px;
+ border-bottom: 1px solid #dec5b5;
+ background-color:#FCFFF5;
+ opacity:1;
+ }
+ .notice_single:hover {
+ background-color: #f7ebcc;
+ }
+ .notice_single p {
+ display: inline;
+ margin: 0;
+ padding: 0;
+ }
+ </style>';
+
+ $html = $this->render_notice($notice);
+
+ $fbml = "<fb:wide>$content $html</fb:wide>";
+ $fbml .= "<fb:narrow>$content $html</fb:narrow>";
+
+ $fbml_main = "<fb:narrow>$content $html</fb:narrow>";
+
+ $facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main);
+ }
+
+ # Display methods
+
+ function show_header($selected ='Home') {
+
+ # Add a timestamp to the CSS file so Facebook cache wont ignore our changes
+ $ts = filemtime(theme_file('facebookapp.css'));
+ $cssurl = theme_path('facebookapp.css') . "?ts=$ts";
+
+ $header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />';
+ # $header .='<script src="" ></script>';
+ $header .= '<fb:dashboard/>';
+
+ $header .=
+ '<fb:tabs>'
+ .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />'
+ .'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />'
+ .'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />'
+ .'</fb:tabs>';
+ $header .= '<div id="main_body">';
+
+ echo $header;
+
+ }
+
+ function show_footer() {
+ $footer = '</div>';
+ echo $footer;
+ }
+
+ function show_login_form() {
+
+ $loginform =
+ ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>'
+ .'<a href="http://identi.ca/">'
+ .' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>'
+ .'</a>'
+ .'<h1 class="pagetitle">Login</h1>'
+ .'<div class="instructions">'
+ .' <p>Login with your username and password. Don\'t have a username yet?'
+ .' <a href="http://identi.ca/main/register">Register</a> a new account.'
+ .' </p>'
+ .'</div>'
+ .'<div id="content">'
+ .' <form method="post" id="login">'
+ .' <p>'
+ .' <label for="nickname">Nickname</label>'
+ .' <input name="nickname" type="text" class="input_text" id="nickname"/>'
+ .' </p>'
+ .' <p>'
+ .' <label for="password">Password</label>'
+ .' <input name="password" type="password" class="password" id="password"/>'
+ .' </p>'
+ .' <p>'
+ .' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>'
+ .' </p>'
+ .' </form>'
+ .' <p>'
+ .' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>'
+ .' </p>'
+ .'</div';
+
+ echo $loginform;
+ }
+
+ function render_notice($notice) {
+
+ global $config;
+
+ $profile = $notice->getProfile();
+ $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+
+ $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
+
+ # XXX: we need to figure this out better. Is this right?
+ if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
+ $noticeurl = $notice->uri;
+ }
+
+ $html =
+ '<li class="notice_single" id="' . $notice->id . '">'
+ .'<a href="' . $profile->profileurl . '">'
+ .'<img src="';
+
+ if ($avatar) {
+ $html .= common_avatar_display_url($avatar);
+ } else {
+ $html .= common_default_avatar(AVATAR_STREAM_SIZE);
+ }
+
+ $html .=
+ '" class="avatar stream" width="'
+ . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"'
+ .' alt="';
+
+ if ($profile->fullname) {
+ $html .= $profile->fullname;
+ } else {
+ $html .= $profile->nickname;
+ }
+
+ $html .=
+ '"></a>'
+ .'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>'
+ .'<p class="content">' . $notice->rendered . '</p>'
+ .'<p class="time">'
+ .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>';
+
+ if ($notice->source) {
+ $html .= _(' from ');
+ $html .= $this->source_link($notice->source);
+ }
+
+ if ($notice->reply_to) {
+ $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
+ $html .=
+ ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')';
+ }
+
+ $html .= '</p></li>';
+
+ return $html;
+ }
+
+ function source_link($source) {
+ $source_name = _($source);
+
+ $html = '<span class="noticesource">';
+
+ switch ($source) {
+ case 'web':
+ case 'xmpp':
+ case 'mail':
+ case 'omb':
+ case 'api':
+ $html .= $source_name;
+ break;
+ default:
+ $ns = Notice_source::staticGet($source);
+ if ($ns) {
+ $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>';
+ } else {
+ $html .= $source_name;
+ }
+ break;
+ }
+
+ $html .= '</span>';
+
+ return $html;
+ }
+
+ function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) {
+
+ $html = '';
+
+ if ($have_before || $have_after) {
+ $html = '<div id="pagination">';
+ $html .'<ul id="nav_pagination">';
+ }
+
+ if ($have_before) {
+ $pargs = array('page' => $page-1);
+ $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
+ $html .= '<li class="before">';
+ $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>';
+ $html .'</li>';
+ }
+
+ if ($have_after) {
+ $pargs = array('page' => $page+1);
+ $newargs = ($args) ? array_merge($args,$pargs) : $pargs;
+ $html .= '<li class="after">';
+ $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>';
+ $html .'</li>';
+ }
+
+ if ($have_before || $have_after) {
+ $html .= '<ul>';
+ $html .'<div>';
+ }
+ }
+
+ function pagination_url($fbaction, $args=NULL) {
+ global $config;
+
+ $extra = '';
+
+ if ($args) {
+ foreach ($args as $key => $value) {
+ $extra .= "&${key}=${value}";
+ }
+ }
+
+ return "$fbaction?${extra}";
+ }
}
diff --git a/_darcs/pristine/lib/oauthstore.php b/_darcs/pristine/lib/oauthstore.php
index d7f9c9ff1..aa705be30 100644
--- a/_darcs/pristine/lib/oauthstore.php
+++ b/_darcs/pristine/lib/oauthstore.php
@@ -23,122 +23,122 @@ require_once(INSTALLDIR.'/lib/omb.php');
class LaconicaOAuthDataStore extends OAuthDataStore {
- # We keep a record of who's contacted us
+ # We keep a record of who's contacted us
- function lookup_consumer($consumer_key) {
- $con = Consumer::staticGet('consumer_key', $consumer_key);
- if (!$con) {
- $con = new Consumer();
- $con->consumer_key = $consumer_key;
- $con->seed = common_good_rand(16);
- $con->created = DB_DataObject_Cast::dateTime();
- if (!$con->insert()) {
- return NULL;
- }
- }
- return new OAuthConsumer($con->consumer_key, '');
- }
+ function lookup_consumer($consumer_key) {
+ $con = Consumer::staticGet('consumer_key', $consumer_key);
+ if (!$con) {
+ $con = new Consumer();
+ $con->consumer_key = $consumer_key;
+ $con->seed = common_good_rand(16);
+ $con->created = DB_DataObject_Cast::dateTime();
+ if (!$con->insert()) {
+ return NULL;
+ }
+ }
+ return new OAuthConsumer($con->consumer_key, '');
+ }
- function lookup_token($consumer, $token_type, $token_key) {
- $t = new Token();
- $t->consumer_key = $consumer->key;
- $t->tok = $token_key;
- $t->type = ($token_type == 'access') ? 1 : 0;
- if ($t->find(true)) {
- return new OAuthToken($t->tok, $t->secret);
- } else {
- return NULL;
- }
- }
+ function lookup_token($consumer, $token_type, $token_key) {
+ $t = new Token();
+ $t->consumer_key = $consumer->key;
+ $t->tok = $token_key;
+ $t->type = ($token_type == 'access') ? 1 : 0;
+ if ($t->find(true)) {
+ return new OAuthToken($t->tok, $t->secret);
+ } else {
+ return NULL;
+ }
+ }
- function lookup_nonce($consumer, $token, $nonce, $timestamp) {
- $n = new Nonce();
- $n->consumer_key = $consumer->key;
- $n->tok = $token->key;
- $n->nonce = $nonce;
- if ($n->find(TRUE)) {
- return TRUE;
- } else {
- $n->timestamp = $timestamp;
- $n->created = DB_DataObject_Cast::dateTime();
- $n->insert();
- return FALSE;
- }
- }
+ function lookup_nonce($consumer, $token, $nonce, $timestamp) {
+ $n = new Nonce();
+ $n->consumer_key = $consumer->key;
+ $n->tok = $token->key;
+ $n->nonce = $nonce;
+ if ($n->find(TRUE)) {
+ return TRUE;
+ } else {
+ $n->timestamp = $timestamp;
+ $n->created = DB_DataObject_Cast::dateTime();
+ $n->insert();
+ return FALSE;
+ }
+ }
- function new_request_token($consumer) {
- $t = new Token();
- $t->consumer_key = $consumer->key;
- $t->tok = common_good_rand(16);
- $t->secret = common_good_rand(16);
- $t->type = 0; # request
- $t->state = 0; # unauthorized
- $t->created = DB_DataObject_Cast::dateTime();
- if (!$t->insert()) {
- return NULL;
- } else {
- return new OAuthToken($t->tok, $t->secret);
- }
- }
+ function new_request_token($consumer) {
+ $t = new Token();
+ $t->consumer_key = $consumer->key;
+ $t->tok = common_good_rand(16);
+ $t->secret = common_good_rand(16);
+ $t->type = 0; # request
+ $t->state = 0; # unauthorized
+ $t->created = DB_DataObject_Cast::dateTime();
+ if (!$t->insert()) {
+ return NULL;
+ } else {
+ return new OAuthToken($t->tok, $t->secret);
+ }
+ }
- # defined in OAuthDataStore, but not implemented anywhere
+ # defined in OAuthDataStore, but not implemented anywhere
- function fetch_request_token($consumer) {
- return $this->new_request_token($consumer);
- }
+ function fetch_request_token($consumer) {
+ return $this->new_request_token($consumer);
+ }
- function new_access_token($token, $consumer) {
- common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__);
- $rt = new Token();
- $rt->consumer_key = $consumer->key;
- $rt->tok = $token->key;
- $rt->type = 0; # request
- if ($rt->find(TRUE) && $rt->state == 1) { # authorized
- common_debug('request token found.', __FILE__);
- $at = new Token();
- $at->consumer_key = $consumer->key;
- $at->tok = common_good_rand(16);
- $at->secret = common_good_rand(16);
- $at->type = 1; # access
- $at->created = DB_DataObject_Cast::dateTime();
- if (!$at->insert()) {
- $e = $at->_lastError;
- common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__);
- return NULL;
- } else {
- common_debug('access token "'.$at->tok.'" inserted', __FILE__);
- # burn the old one
- $orig_rt = clone($rt);
- $rt->state = 2; # used
- if (!$rt->update($orig_rt)) {
- return NULL;
- }
- common_debug('request token "'.$rt->tok.'" updated', __FILE__);
- # Update subscription
- # XXX: mixing levels here
- $sub = Subscription::staticGet('token', $rt->tok);
- if (!$sub) {
- return NULL;
- }
- common_debug('subscription for request token found', __FILE__);
- $orig_sub = clone($sub);
- $sub->token = $at->tok;
- $sub->secret = $at->secret;
- if (!$sub->update($orig_sub)) {
- return NULL;
- } else {
- common_debug('subscription updated to use access token', __FILE__);
- return new OAuthToken($at->tok, $at->secret);
- }
- }
- } else {
- return NULL;
- }
- }
+ function new_access_token($token, $consumer) {
+ common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__);
+ $rt = new Token();
+ $rt->consumer_key = $consumer->key;
+ $rt->tok = $token->key;
+ $rt->type = 0; # request
+ if ($rt->find(TRUE) && $rt->state == 1) { # authorized
+ common_debug('request token found.', __FILE__);
+ $at = new Token();
+ $at->consumer_key = $consumer->key;
+ $at->tok = common_good_rand(16);
+ $at->secret = common_good_rand(16);
+ $at->type = 1; # access
+ $at->created = DB_DataObject_Cast::dateTime();
+ if (!$at->insert()) {
+ $e = $at->_lastError;
+ common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__);
+ return NULL;
+ } else {
+ common_debug('access token "'.$at->tok.'" inserted', __FILE__);
+ # burn the old one
+ $orig_rt = clone($rt);
+ $rt->state = 2; # used
+ if (!$rt->update($orig_rt)) {
+ return NULL;
+ }
+ common_debug('request token "'.$rt->tok.'" updated', __FILE__);
+ # Update subscription
+ # XXX: mixing levels here
+ $sub = Subscription::staticGet('token', $rt->tok);
+ if (!$sub) {
+ return NULL;
+ }
+ common_debug('subscription for request token found', __FILE__);
+ $orig_sub = clone($sub);
+ $sub->token = $at->tok;
+ $sub->secret = $at->secret;
+ if (!$sub->update($orig_sub)) {
+ return NULL;
+ } else {
+ common_debug('subscription updated to use access token', __FILE__);
+ return new OAuthToken($at->tok, $at->secret);
+ }
+ }
+ } else {
+ return NULL;
+ }
+ }
- # defined in OAuthDataStore, but not implemented anywhere
+ # defined in OAuthDataStore, but not implemented anywhere
- function fetch_access_token($consumer) {
- return $this->new_access_token($consumer);
- }
+ function fetch_access_token($consumer) {
+ return $this->new_access_token($consumer);
+ }
}
diff --git a/_darcs/pristine/lib/omb.php b/_darcs/pristine/lib/omb.php
index 96736b4d4..94ccc2ecd 100644
--- a/_darcs/pristine/lib/omb.php
+++ b/_darcs/pristine/lib/omb.php
@@ -44,256 +44,256 @@ define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body');
define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1');
function omb_oauth_consumer() {
- static $con = NULL;
- if (!$con) {
- $con = new OAuthConsumer(common_root_url(), '');
- }
- return $con;
+ static $con = NULL;
+ if (!$con) {
+ $con = new OAuthConsumer(common_root_url(), '');
+ }
+ return $con;
}
function omb_oauth_server() {
- static $server = null;
- if (!$server) {
- $server = new OAuthServer(omb_oauth_datastore());
- $server->add_signature_method(omb_hmac_sha1());
- }
- return $server;
+ static $server = null;
+ if (!$server) {
+ $server = new OAuthServer(omb_oauth_datastore());
+ $server->add_signature_method(omb_hmac_sha1());
+ }
+ return $server;
}
function omb_oauth_datastore() {
- static $store = NULL;
- if (!$store) {
- $store = new LaconicaOAuthDataStore();
- }
- return $store;
+ static $store = NULL;
+ if (!$store) {
+ $store = new LaconicaOAuthDataStore();
+ }
+ return $store;
}
function omb_hmac_sha1() {
- static $hmac_method = NULL;
- if (!$hmac_method) {
- $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
- }
- return $hmac_method;
+ static $hmac_method = NULL;
+ if (!$hmac_method) {
+ $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
+ }
+ return $hmac_method;
}
function omb_get_services($xrd, $type) {
- return $xrd->services(array(omb_service_filter($type)));
+ return $xrd->services(array(omb_service_filter($type)));
}
function omb_service_filter($type) {
- return create_function('$s',
- 'return omb_match_service($s, \''.$type.'\');');
+ return create_function('$s',
+ 'return omb_match_service($s, \''.$type.'\');');
}
function omb_match_service($service, $type) {
- return in_array($type, $service->getTypes());
+ return in_array($type, $service->getTypes());
}
function omb_service_uri($service) {
- if (!$service) {
- return NULL;
- }
- $uris = $service->getURIs();
- if (!$uris) {
- return NULL;
- }
- return $uris[0];
+ if (!$service) {
+ return NULL;
+ }
+ $uris = $service->getURIs();
+ if (!$uris) {
+ return NULL;
+ }
+ return $uris[0];
}
function omb_local_id($service) {
- if (!$service) {
- return NULL;
- }
- $els = $service->getElements('xrd:LocalID');
- if (!$els) {
- return NULL;
- }
- $el = $els[0];
- return $service->parser->content($el);
+ if (!$service) {
+ return NULL;
+ }
+ $els = $service->getElements('xrd:LocalID');
+ if (!$els) {
+ return NULL;
+ }
+ $el = $els[0];
+ return $service->parser->content($el);
}
function omb_broadcast_remote_subscribers($notice) {
- # First, get remote users subscribed to this profile
- $rp = new Remote_profile();
+ # First, get remote users subscribed to this profile
+ $rp = new Remote_profile();
- $rp->query('SELECT postnoticeurl, token, secret ' .
- 'FROM subscription JOIN remote_profile ' .
- 'ON subscription.subscriber = remote_profile.id ' .
- 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
+ $rp->query('SELECT postnoticeurl, token, secret ' .
+ 'FROM subscription JOIN remote_profile ' .
+ 'ON subscription.subscriber = remote_profile.id ' .
+ 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ');
- $posted = array();
+ $posted = array();
- while ($rp->fetch()) {
- if (!$posted[$rp->postnoticeurl]) {
- common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl);
- if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) {
- common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl);
- $posted[$rp->postnoticeurl] = TRUE;
- } else {
- common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl);
- }
- }
- }
+ while ($rp->fetch()) {
+ if (!$posted[$rp->postnoticeurl]) {
+ common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl);
+ if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) {
+ common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl);
+ $posted[$rp->postnoticeurl] = TRUE;
+ } else {
+ common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl);
+ }
+ }
+ }
- $rp->free();
- unset($rp);
+ $rp->free();
+ unset($rp);
- return true;
+ return true;
}
function omb_post_notice($notice, $remote_profile, $subscription) {
- return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret);
+ return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret);
}
function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret) {
- common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__);
+ common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__);
- $user = User::staticGet('id', $notice->profile_id);
+ $user = User::staticGet('id', $notice->profile_id);
- if (!$user) {
- common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__);
- return false;
- }
+ if (!$user) {
+ common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__);
+ return false;
+ }
- $con = omb_oauth_consumer();
+ $con = omb_oauth_consumer();
- $token = new OAuthToken($tk, $secret);
+ $token = new OAuthToken($tk, $secret);
- $url = $postnoticeurl;
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
+ $url = $postnoticeurl;
+ $parsed = parse_url($url);
+ $params = array();
+ parse_str($parsed['query'], $params);
- $req = OAuthRequest::from_consumer_and_token($con, $token,
- 'POST', $url, $params);
+ $req = OAuthRequest::from_consumer_and_token($con, $token,
+ 'POST', $url, $params);
- $req->set_parameter('omb_version', OMB_VERSION_01);
- $req->set_parameter('omb_listenee', $user->uri);
- $req->set_parameter('omb_notice', $notice->uri);
- $req->set_parameter('omb_notice_content', $notice->content);
- $req->set_parameter('omb_notice_url', common_local_url('shownotice',
- array('notice' =>
- $notice->id)));
- $req->set_parameter('omb_notice_license', common_config('license', 'url'));
+ $req->set_parameter('omb_version', OMB_VERSION_01);
+ $req->set_parameter('omb_listenee', $user->uri);
+ $req->set_parameter('omb_notice', $notice->uri);
+ $req->set_parameter('omb_notice_content', $notice->content);
+ $req->set_parameter('omb_notice_url', common_local_url('shownotice',
+ array('notice' =>
+ $notice->id)));
+ $req->set_parameter('omb_notice_license', common_config('license', 'url'));
- $user->free();
- unset($user);
+ $user->free();
+ unset($user);
- $req->sign_request(omb_hmac_sha1(), $con, $token);
+ $req->sign_request(omb_hmac_sha1(), $con, $token);
- # We re-use this tool's fetcher, since it's pretty good
+ # We re-use this tool's fetcher, since it's pretty good
- $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
- if (!$fetcher) {
- common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
- return false;
- }
+ if (!$fetcher) {
+ common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
+ return false;
+ }
- $result = $fetcher->post($req->get_normalized_http_url(),
- $req->to_postdata(),
+ $result = $fetcher->post($req->get_normalized_http_url(),
+ $req->to_postdata(),
array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
- common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
-
- if ($result->status == 403) { # not authorized, don't send again
- common_debug('403 result, deleting subscription', __FILE__);
- # FIXME: figure out how to delete this
- # $subscription->delete();
- return false;
- } else if ($result->status != 200) {
- common_debug('Error status '.$result->status, __FILE__);
- return false;
- } else { # success!
- parse_str($result->body, $return);
- if ($return['omb_version'] == OMB_VERSION_01) {
- return true;
- } else {
- return false;
- }
- }
+ common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
+
+ if ($result->status == 403) { # not authorized, don't send again
+ common_debug('403 result, deleting subscription', __FILE__);
+ # FIXME: figure out how to delete this
+ # $subscription->delete();
+ return false;
+ } else if ($result->status != 200) {
+ common_debug('Error status '.$result->status, __FILE__);
+ return false;
+ } else { # success!
+ parse_str($result->body, $return);
+ if ($return['omb_version'] == OMB_VERSION_01) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
function omb_broadcast_profile($profile) {
- # First, get remote users subscribed to this profile
- # XXX: use a join here rather than looping through results
- $sub = new Subscription();
- $sub->subscribed = $profile->id;
- if ($sub->find()) {
- $updated = array();
- while ($sub->fetch()) {
- $rp = Remote_profile::staticGet('id', $sub->subscriber);
- if ($rp) {
- if (!$updated[$rp->updateprofileurl]) {
- if (omb_update_profile($profile, $rp, $sub)) {
- $updated[$rp->updateprofileurl] = TRUE;
- }
- }
- }
- }
- }
+ # First, get remote users subscribed to this profile
+ # XXX: use a join here rather than looping through results
+ $sub = new Subscription();
+ $sub->subscribed = $profile->id;
+ if ($sub->find()) {
+ $updated = array();
+ while ($sub->fetch()) {
+ $rp = Remote_profile::staticGet('id', $sub->subscriber);
+ if ($rp) {
+ if (!$updated[$rp->updateprofileurl]) {
+ if (omb_update_profile($profile, $rp, $sub)) {
+ $updated[$rp->updateprofileurl] = TRUE;
+ }
+ }
+ }
+ }
+ }
}
function omb_update_profile($profile, $remote_profile, $subscription) {
- global $config; # for license URL
- $user = User::staticGet($profile->id);
- $con = omb_oauth_consumer();
- $token = new OAuthToken($subscription->token, $subscription->secret);
- $url = $remote_profile->updateprofileurl;
- $parsed = parse_url($url);
- $params = array();
- parse_str($parsed['query'], $params);
- $req = OAuthRequest::from_consumer_and_token($con, $token,
- "POST", $url, $params);
- $req->set_parameter('omb_version', OMB_VERSION_01);
- $req->set_parameter('omb_listenee', $user->uri);
- $req->set_parameter('omb_listenee_profile', common_profile_url($profile->nickname));
- $req->set_parameter('omb_listenee_nickname', $profile->nickname);
-
- # We use blanks to force emptying any existing values in these optional fields
-
- $req->set_parameter('omb_listenee_fullname',
- ($profile->fullname) ? $profile->fullname : '');
- $req->set_parameter('omb_listenee_homepage',
- ($profile->homepage) ? $profile->homepage : '');
- $req->set_parameter('omb_listenee_bio',
- ($profile->bio) ? $profile->bio : '');
- $req->set_parameter('omb_listenee_location',
- ($profile->location) ? $profile->location : '');
-
- $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
- $req->set_parameter('omb_listenee_avatar',
- ($avatar) ? $avatar->url : '');
-
- $req->sign_request(omb_hmac_sha1(), $con, $token);
-
- # We re-use this tool's fetcher, since it's pretty good
-
- $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
-
- common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__);
- common_debug('postdata = '.$req->to_postdata(), __FILE__);
- $result = $fetcher->post($req->get_normalized_http_url(),
- $req->to_postdata(),
+ global $config; # for license URL
+ $user = User::staticGet($profile->id);
+ $con = omb_oauth_consumer();
+ $token = new OAuthToken($subscription->token, $subscription->secret);
+ $url = $remote_profile->updateprofileurl;
+ $parsed = parse_url($url);
+ $params = array();
+ parse_str($parsed['query'], $params);
+ $req = OAuthRequest::from_consumer_and_token($con, $token,
+ "POST", $url, $params);
+ $req->set_parameter('omb_version', OMB_VERSION_01);
+ $req->set_parameter('omb_listenee', $user->uri);
+ $req->set_parameter('omb_listenee_profile', common_profile_url($profile->nickname));
+ $req->set_parameter('omb_listenee_nickname', $profile->nickname);
+
+ # We use blanks to force emptying any existing values in these optional fields
+
+ $req->set_parameter('omb_listenee_fullname',
+ ($profile->fullname) ? $profile->fullname : '');
+ $req->set_parameter('omb_listenee_homepage',
+ ($profile->homepage) ? $profile->homepage : '');
+ $req->set_parameter('omb_listenee_bio',
+ ($profile->bio) ? $profile->bio : '');
+ $req->set_parameter('omb_listenee_location',
+ ($profile->location) ? $profile->location : '');
+
+ $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+ $req->set_parameter('omb_listenee_avatar',
+ ($avatar) ? $avatar->url : '');
+
+ $req->sign_request(omb_hmac_sha1(), $con, $token);
+
+ # We re-use this tool's fetcher, since it's pretty good
+
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+
+ common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__);
+ common_debug('postdata = '.$req->to_postdata(), __FILE__);
+ $result = $fetcher->post($req->get_normalized_http_url(),
+ $req->to_postdata(),
array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
- common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
-
- if ($result->status == 403) { # not authorized, don't send again
- common_debug('403 result, deleting subscription', __FILE__);
- $subscription->delete();
- return false;
- } else if ($result->status != 200) {
- common_debug('Error status '.$result->status, __FILE__);
- return false;
- } else { # success!
- parse_str($result->body, $return);
- if ($return['omb_version'] == OMB_VERSION_01) {
- return true;
- } else {
- return false;
- }
- }
+ common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__);
+
+ if ($result->status == 403) { # not authorized, don't send again
+ common_debug('403 result, deleting subscription', __FILE__);
+ $subscription->delete();
+ return false;
+ } else if ($result->status != 200) {
+ common_debug('Error status '.$result->status, __FILE__);
+ return false;
+ } else { # success!
+ parse_str($result->body, $return);
+ if ($return['omb_version'] == OMB_VERSION_01) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
diff --git a/_darcs/pristine/lib/openid.php b/_darcs/pristine/lib/openid.php
index 6e501c2b1..ebc5ed168 100644
--- a/_darcs/pristine/lib/openid.php
+++ b/_darcs/pristine/lib/openid.php
@@ -33,210 +33,210 @@ define('OPENID_COOKIE_KEY', 'lastusedopenid');
function oid_store() {
static $store = NULL;
- if (!$store) {
- # Can't be called statically
- $user = new User();
- $conn = $user->getDatabaseConnection();
- $store = new Auth_OpenID_MySQLStore($conn);
- }
- return $store;
+ if (!$store) {
+ # Can't be called statically
+ $user = new User();
+ $conn = $user->getDatabaseConnection();
+ $store = new Auth_OpenID_MySQLStore($conn);
+ }
+ return $store;
}
function oid_consumer() {
- $store = oid_store();
- $consumer = new Auth_OpenID_Consumer($store);
- return $consumer;
+ $store = oid_store();
+ $consumer = new Auth_OpenID_Consumer($store);
+ return $consumer;
}
function oid_clear_last() {
- oid_set_last('');
+ oid_set_last('');
}
function oid_set_last($openid_url) {
- common_set_cookie(OPENID_COOKIE_KEY,
- $openid_url,
- time() + OPENID_COOKIE_EXPIRY);
+ common_set_cookie(OPENID_COOKIE_KEY,
+ $openid_url,
+ time() + OPENID_COOKIE_EXPIRY);
}
function oid_get_last() {
- $openid_url = $_COOKIE[OPENID_COOKIE_KEY];
- if ($openid_url && strlen($openid_url) > 0) {
- return $openid_url;
- } else {
- return NULL;
- }
+ $openid_url = $_COOKIE[OPENID_COOKIE_KEY];
+ if ($openid_url && strlen($openid_url) > 0) {
+ return $openid_url;
+ } else {
+ return NULL;
+ }
}
function oid_link_user($id, $canonical, $display) {
- $oid = new User_openid();
- $oid->user_id = $id;
- $oid->canonical = $canonical;
- $oid->display = $display;
- $oid->created = DB_DataObject_Cast::dateTime();
+ $oid = new User_openid();
+ $oid->user_id = $id;
+ $oid->canonical = $canonical;
+ $oid->display = $display;
+ $oid->created = DB_DataObject_Cast::dateTime();
- if (!$oid->insert()) {
- $err = PEAR::getStaticProperty('DB_DataObject','lastError');
- common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__);
- return false;
- }
+ if (!$oid->insert()) {
+ $err = PEAR::getStaticProperty('DB_DataObject','lastError');
+ common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__);
+ return false;
+ }
- return true;
+ return true;
}
function oid_get_user($openid_url) {
- $user = NULL;
- $oid = User_openid::staticGet('canonical', $openid_url);
- if ($oid) {
- $user = User::staticGet('id', $oid->user_id);
- }
- return $user;
+ $user = NULL;
+ $oid = User_openid::staticGet('canonical', $openid_url);
+ if ($oid) {
+ $user = User::staticGet('id', $oid->user_id);
+ }
+ return $user;
}
function oid_check_immediate($openid_url, $backto=NULL) {
- if (!$backto) {
- $action = $_REQUEST['action'];
- $args = common_copy_args($_GET);
- unset($args['action']);
- $backto = common_local_url($action, $args);
- }
- common_debug('going back to "' . $backto . '"', __FILE__);
-
- common_ensure_session();
-
- $_SESSION['openid_immediate_backto'] = $backto;
- common_debug('passed-in variable is "' . $backto . '"', __FILE__);
- common_debug('session variable is "' . $_SESSION['openid_immediate_backto'] . '"', __FILE__);
-
- oid_authenticate($openid_url,
- 'finishimmediate',
- true);
+ if (!$backto) {
+ $action = $_REQUEST['action'];
+ $args = common_copy_args($_GET);
+ unset($args['action']);
+ $backto = common_local_url($action, $args);
+ }
+ common_debug('going back to "' . $backto . '"', __FILE__);
+
+ common_ensure_session();
+
+ $_SESSION['openid_immediate_backto'] = $backto;
+ common_debug('passed-in variable is "' . $backto . '"', __FILE__);
+ common_debug('session variable is "' . $_SESSION['openid_immediate_backto'] . '"', __FILE__);
+
+ oid_authenticate($openid_url,
+ 'finishimmediate',
+ true);
}
function oid_authenticate($openid_url, $returnto, $immediate=false) {
- $consumer = oid_consumer();
-
- if (!$consumer) {
- common_server_error(_('Cannot instantiate OpenID consumer object.'));
- return false;
- }
-
- common_ensure_session();
-
- $auth_request = $consumer->begin($openid_url);
-
- // Handle failure status return values.
- if (!$auth_request) {
- return _('Not a valid OpenID.');
- } else if (Auth_OpenID::isFailure($auth_request)) {
- return sprintf(_('OpenID failure: %s'), $auth_request->message);
- }
-
- $sreg_request = Auth_OpenID_SRegRequest::build(// Required
- array(),
- // Optional
- array('nickname',
- 'email',
- 'fullname',
- 'language',
- 'timezone',
- 'postcode',
- 'country'));
-
- if ($sreg_request) {
- $auth_request->addExtension($sreg_request);
- }
-
- $trust_root = common_local_url('public');
- $process_url = common_local_url($returnto);
-
- if ($auth_request->shouldSendRedirect()) {
- $redirect_url = $auth_request->redirectURL($trust_root,
- $process_url,
- $immediate);
- if (!$redirect_url) {
- } else if (Auth_OpenID::isFailure($redirect_url)) {
- return sprintf(_('Could not redirect to server: %s'), $redirect_url->message);
- } else {
- common_redirect($redirect_url);
- }
- } else {
- // Generate form markup and render it.
- $form_id = 'openid_message';
- $form_html = $auth_request->formMarkup($trust_root, $process_url,
- $immediate, array('id' => $form_id));
-
- # XXX: This is cheap, but things choke if we don't escape ampersands
- # in the HTML attributes
-
- $form_html = preg_replace('/&/', '&amp;', $form_html);
-
- // Display an error if the form markup couldn't be generated;
- // otherwise, render the HTML.
- if (Auth_OpenID::isFailure($form_html)) {
- $this->show_form(sprintf(_('Could not create OpenID form: %s'), $form_html->message));
- } else {
- common_show_header(_('OpenID Auto-Submit'), NULL, NULL, '_oid_print_instructions');
- common_raw($form_html);
- common_element('script', NULL,
- '$(document).ready(function() { ' .
- ' $("#'. $form_id .'").submit(); '.
- '});');
- common_show_footer();
- }
- }
+ $consumer = oid_consumer();
+
+ if (!$consumer) {
+ common_server_error(_('Cannot instantiate OpenID consumer object.'));
+ return false;
+ }
+
+ common_ensure_session();
+
+ $auth_request = $consumer->begin($openid_url);
+
+ // Handle failure status return values.
+ if (!$auth_request) {
+ return _('Not a valid OpenID.');
+ } else if (Auth_OpenID::isFailure($auth_request)) {
+ return sprintf(_('OpenID failure: %s'), $auth_request->message);
+ }
+
+ $sreg_request = Auth_OpenID_SRegRequest::build(// Required
+ array(),
+ // Optional
+ array('nickname',
+ 'email',
+ 'fullname',
+ 'language',
+ 'timezone',
+ 'postcode',
+ 'country'));
+
+ if ($sreg_request) {
+ $auth_request->addExtension($sreg_request);
+ }
+
+ $trust_root = common_local_url('public');
+ $process_url = common_local_url($returnto);
+
+ if ($auth_request->shouldSendRedirect()) {
+ $redirect_url = $auth_request->redirectURL($trust_root,
+ $process_url,
+ $immediate);
+ if (!$redirect_url) {
+ } else if (Auth_OpenID::isFailure($redirect_url)) {
+ return sprintf(_('Could not redirect to server: %s'), $redirect_url->message);
+ } else {
+ common_redirect($redirect_url);
+ }
+ } else {
+ // Generate form markup and render it.
+ $form_id = 'openid_message';
+ $form_html = $auth_request->formMarkup($trust_root, $process_url,
+ $immediate, array('id' => $form_id));
+
+ # XXX: This is cheap, but things choke if we don't escape ampersands
+ # in the HTML attributes
+
+ $form_html = preg_replace('/&/', '&amp;', $form_html);
+
+ // Display an error if the form markup couldn't be generated;
+ // otherwise, render the HTML.
+ if (Auth_OpenID::isFailure($form_html)) {
+ $this->show_form(sprintf(_('Could not create OpenID form: %s'), $form_html->message));
+ } else {
+ common_show_header(_('OpenID Auto-Submit'), NULL, NULL, '_oid_print_instructions');
+ common_raw($form_html);
+ common_element('script', NULL,
+ '$(document).ready(function() { ' .
+ ' $("#'. $form_id .'").submit(); '.
+ '});');
+ common_show_footer();
+ }
+ }
}
# Half-assed attempt at a module-private function
function _oid_print_instructions() {
- common_element('div', 'instructions',
- _('This form should automatically submit itself. '.
- 'If not, click the submit button to go to your '.
- 'OpenID provider.'));
+ common_element('div', 'instructions',
+ _('This form should automatically submit itself. '.
+ 'If not, click the submit button to go to your '.
+ 'OpenID provider.'));
}
# update a user from sreg parameters
function oid_update_user(&$user, &$sreg) {
- $profile = $user->getProfile();
+ $profile = $user->getProfile();
- $orig_profile = clone($profile);
+ $orig_profile = clone($profile);
- if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
- $profile->fullname = $sreg['fullname'];
- }
+ if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) {
+ $profile->fullname = $sreg['fullname'];
+ }
- if ($sreg['country']) {
- if ($sreg['postcode']) {
- # XXX: use postcode to get city and region
- # XXX: also, store postcode somewhere -- it's valuable!
- $profile->location = $sreg['postcode'] . ', ' . $sreg['country'];
- } else {
- $profile->location = $sreg['country'];
- }
- }
+ if ($sreg['country']) {
+ if ($sreg['postcode']) {
+ # XXX: use postcode to get city and region
+ # XXX: also, store postcode somewhere -- it's valuable!
+ $profile->location = $sreg['postcode'] . ', ' . $sreg['country'];
+ } else {
+ $profile->location = $sreg['country'];
+ }
+ }
- # XXX save language if it's passed
- # XXX save timezone if it's passed
+ # XXX save language if it's passed
+ # XXX save timezone if it's passed
- if (!$profile->update($orig_profile)) {
- common_server_error(_('Error saving the profile.'));
- return false;
- }
+ if (!$profile->update($orig_profile)) {
+ common_server_error(_('Error saving the profile.'));
+ return false;
+ }
- $orig_user = clone($user);
+ $orig_user = clone($user);
- if ($sreg['email'] && Validate::email($sreg['email'], true)) {
- $user->email = $sreg['email'];
- }
+ if ($sreg['email'] && Validate::email($sreg['email'], true)) {
+ $user->email = $sreg['email'];
+ }
- if (!$user->update($orig_user)) {
- common_server_error(_('Error saving the user.'));
- return false;
- }
+ if (!$user->update($orig_user)) {
+ common_server_error(_('Error saving the user.'));
+ return false;
+ }
- return true;
+ return true;
}
diff --git a/_darcs/pristine/lib/personal.php b/_darcs/pristine/lib/personal.php
index 86433b486..1928349a3 100644
--- a/_darcs/pristine/lib/personal.php
+++ b/_darcs/pristine/lib/personal.php
@@ -20,187 +20,187 @@
if (!defined('LACONICA')) { exit(1); }
class PersonalAction extends Action {
-
- function is_readonly() {
- return true;
- }
-
- function handle($args) {
- parent::handle($args);
- common_set_returnto($this->self_url());
- }
-
- function views_menu() {
-
- $user = NULL;
- $action = $this->trimmed('action');
- $nickname = $this->trimmed('nickname');
-
- if ($nickname) {
- $user = User::staticGet('nickname', $nickname);
- $user_profile = $user->getProfile();
- } else {
- $user_profile = false;
- }
-
- common_element_start('ul', array('id' => 'nav_views'));
-
- common_menu_item(common_local_url('all', array('nickname' =>
- $nickname)),
- _('Personal'),
- sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
- $action == 'all');
- common_menu_item(common_local_url('replies', array('nickname' =>
- $nickname)),
- _('Replies'),
- sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
- $action == 'replies');
- common_menu_item(common_local_url('showstream', array('nickname' =>
- $nickname)),
- _('Profile'),
- ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname,
- $action == 'showstream');
- common_menu_item(common_local_url('showfavorites', array('nickname' =>
- $nickname)),
- _('Favorites'),
- sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')),
- $action == 'showfavorites');
-
- $cur = common_current_user();
-
- if ($cur && $cur->id == $user->id) {
-
- common_menu_item(common_local_url('inbox', array('nickname' =>
- $nickname)),
- _('Inbox'),
- _('Your incoming messages'),
- $action == 'inbox');
- common_menu_item(common_local_url('outbox', array('nickname' =>
- $nickname)),
- _('Outbox'),
- _('Your sent messages'),
- $action == 'outbox');
- }
-
- common_element_end('ul');
- }
-
- function show_feeds_list($feeds) {
- common_element_start('div', array('class' => 'feeds'));
- common_element('p', null, 'Feeds:');
- common_element_start('ul', array('class' => 'xoxo'));
-
- foreach ($feeds as $key => $value) {
- $this->common_feed_item($feeds[$key]);
- }
- common_element_end('ul');
- common_element_end('div');
- }
-
- function common_feed_item($feed) {
- $nickname = $this->trimmed('nickname');
-
- switch($feed['item']) {
- case 'notices': default:
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's ".$feed['version']." notice feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'allrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = $feed['version']." feed for $nickname and friends";
- $feed['textContent'] = "RSS";
- break;
-
- case 'repliesrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = $feed['version']." feed for replies to $nickname";
- $feed['textContent'] = "RSS";
- break;
-
- case 'publicrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Public timeline ".$feed['version']." feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'publicatom':
- $feed_classname = "atom";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Public timeline ".$feed['version']." feed";
- $feed['textContent'] = "Atom";
- break;
-
- case 'tagrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = $feed['version']." feed for this tag";
- $feed['textContent'] = "RSS";
- break;
-
- case 'favoritedrss':
- $feed_classname = $feed['type'];
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Favorited ".$feed['version']." feed";
- $feed['textContent'] = "RSS";
- break;
-
- case 'foaf':
- $feed_classname = "foaf";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's FOAF file";
- $feed['textContent'] = "FOAF";
- break;
-
- case 'favoritesrss':
- $feed_classname = "favorites";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "Feed for favorites of $nickname";
- $feed['textContent'] = "RSS";
- break;
-
- case 'usertimeline':
- $feed_classname = "atom";
- $feed_mimetype = "application/".$feed['type']."+xml";
- $feed_title = "$nickname's ".$feed['version']." notice feed";
- $feed['textContent'] = "Atom";
- break;
- }
- common_element_start('li');
- common_element('a', array('href' => $feed['href'],
- 'class' => $feed_classname,
- 'type' => $feed_mimetype,
- 'title' => $feed_title),
- $feed['textContent']);
- common_element_end('li');
- }
-
-
- function source_link($source) {
- $source_name = _($source);
- switch ($source) {
- case 'web':
- case 'xmpp':
- case 'mail':
- case 'omb':
- case 'api':
- common_element('span', 'noticesource', $source_name);
- break;
- default:
- $ns = Notice_source::staticGet($source);
- if ($ns) {
- common_element('a', array('href' => $ns->url),
- $ns->name);
- } else {
- common_element('span', 'noticesource', $source_name);
- }
- break;
- }
- return;
- }
+
+ function is_readonly() {
+ return true;
+ }
+
+ function handle($args) {
+ parent::handle($args);
+ common_set_returnto($this->self_url());
+ }
+
+ function views_menu() {
+
+ $user = NULL;
+ $action = $this->trimmed('action');
+ $nickname = $this->trimmed('nickname');
+
+ if ($nickname) {
+ $user = User::staticGet('nickname', $nickname);
+ $user_profile = $user->getProfile();
+ } else {
+ $user_profile = false;
+ }
+
+ common_element_start('ul', array('id' => 'nav_views'));
+
+ common_menu_item(common_local_url('all', array('nickname' =>
+ $nickname)),
+ _('Personal'),
+ sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
+ $action == 'all');
+ common_menu_item(common_local_url('replies', array('nickname' =>
+ $nickname)),
+ _('Replies'),
+ sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
+ $action == 'replies');
+ common_menu_item(common_local_url('showstream', array('nickname' =>
+ $nickname)),
+ _('Profile'),
+ ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname,
+ $action == 'showstream');
+ common_menu_item(common_local_url('showfavorites', array('nickname' =>
+ $nickname)),
+ _('Favorites'),
+ sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')),
+ $action == 'showfavorites');
+
+ $cur = common_current_user();
+
+ if ($cur && $cur->id == $user->id) {
+
+ common_menu_item(common_local_url('inbox', array('nickname' =>
+ $nickname)),
+ _('Inbox'),
+ _('Your incoming messages'),
+ $action == 'inbox');
+ common_menu_item(common_local_url('outbox', array('nickname' =>
+ $nickname)),
+ _('Outbox'),
+ _('Your sent messages'),
+ $action == 'outbox');
+ }
+
+ common_element_end('ul');
+ }
+
+ function show_feeds_list($feeds) {
+ common_element_start('div', array('class' => 'feeds'));
+ common_element('p', null, 'Feeds:');
+ common_element_start('ul', array('class' => 'xoxo'));
+
+ foreach ($feeds as $key => $value) {
+ $this->common_feed_item($feeds[$key]);
+ }
+ common_element_end('ul');
+ common_element_end('div');
+ }
+
+ function common_feed_item($feed) {
+ $nickname = $this->trimmed('nickname');
+
+ switch($feed['item']) {
+ case 'notices': default:
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's ".$feed['version']." notice feed";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'allrss':
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = $feed['version']." feed for $nickname and friends";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'repliesrss':
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = $feed['version']." feed for replies to $nickname";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'publicrss':
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "Public timeline ".$feed['version']." feed";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'publicatom':
+ $feed_classname = "atom";
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "Public timeline ".$feed['version']." feed";
+ $feed['textContent'] = "Atom";
+ break;
+
+ case 'tagrss':
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = $feed['version']." feed for this tag";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'favoritedrss':
+ $feed_classname = $feed['type'];
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "Favorited ".$feed['version']." feed";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'foaf':
+ $feed_classname = "foaf";
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's FOAF file";
+ $feed['textContent'] = "FOAF";
+ break;
+
+ case 'favoritesrss':
+ $feed_classname = "favorites";
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "Feed for favorites of $nickname";
+ $feed['textContent'] = "RSS";
+ break;
+
+ case 'usertimeline':
+ $feed_classname = "atom";
+ $feed_mimetype = "application/".$feed['type']."+xml";
+ $feed_title = "$nickname's ".$feed['version']." notice feed";
+ $feed['textContent'] = "Atom";
+ break;
+ }
+ common_element_start('li');
+ common_element('a', array('href' => $feed['href'],
+ 'class' => $feed_classname,
+ 'type' => $feed_mimetype,
+ 'title' => $feed_title),
+ $feed['textContent']);
+ common_element_end('li');
+ }
+
+
+ function source_link($source) {
+ $source_name = _($source);
+ switch ($source) {
+ case 'web':
+ case 'xmpp':
+ case 'mail':
+ case 'omb':
+ case 'api':
+ common_element('span', 'noticesource', $source_name);
+ break;
+ default:
+ $ns = Notice_source::staticGet($source);
+ if ($ns) {
+ common_element('a', array('href' => $ns->url),
+ $ns->name);
+ } else {
+ common_element('span', 'noticesource', $source_name);
+ }
+ break;
+ }
+ return;
+ }
}
diff --git a/_darcs/pristine/lib/profilelist.php b/_darcs/pristine/lib/profilelist.php
index 9079ea9d7..e32c5c254 100644
--- a/_darcs/pristine/lib/profilelist.php
+++ b/_darcs/pristine/lib/profilelist.php
@@ -24,138 +24,138 @@ define('PROFILES_PER_PAGE', 20);
class ProfileList {
- var $profile = NULL;
- var $owner = NULL;
- var $action = NULL;
-
- function __construct($profile, $owner=NULL, $action=NULL) {
- $this->profile = $profile;
- $this->owner = $owner;
- $this->action = $action;
- }
-
- function show_list() {
-
- common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list'));
-
- $cnt = 0;
-
- while ($this->profile->fetch()) {
- $cnt++;
- if($cnt > PROFILES_PER_PAGE) {
- break;
- }
- $this->show();
- }
-
- common_element_end('ul');
-
- return $cnt;
- }
-
- function show() {
-
- common_element_start('li', array('class' => 'profile_single',
- 'id' => 'profile-' . $this->profile->id));
-
- $user = common_current_user();
-
- if ($user && $user->id != $this->profile->id) {
- # XXX: special-case for user looking at own
- # subscriptions page
- if ($user->isSubscribed($this->profile)) {
- common_unsubscribe_form($this->profile);
- } else {
- common_subscribe_form($this->profile);
- }
- }
-
- $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
- common_element_start('a', array('href' => $this->profile->profileurl));
- common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
- 'class' => 'avatar stream',
- 'width' => AVATAR_STREAM_SIZE,
- 'height' => AVATAR_STREAM_SIZE,
- 'alt' =>
- ($this->profile->fullname) ? $this->profile->fullname :
- $this->profile->nickname));
- common_element_end('a');
- common_element_start('p');
- common_element_start('a', array('href' => $this->profile->profileurl,
- 'class' => 'nickname'));
- common_raw($this->highlight($this->profile->nickname));
- common_element_end('a');
- if ($this->profile->fullname) {
- common_text(' | ');
- common_element_start('span', 'fullname');
- common_raw($this->highlight($this->profile->fullname));
- common_element_end('span');
- }
- if ($this->profile->location) {
- common_text(' | ');
- common_element_start('span', 'location');
- common_raw($this->highlight($this->profile->location));
- common_element_end('span');
- }
- common_element_end('p');
- if ($this->profile->homepage) {
- common_element_start('p', 'website');
- common_element_start('a', array('href' => $this->profile->homepage));
- common_raw($this->highlight($this->profile->homepage));
- common_element_end('a');
- common_element_end('p');
- }
- if ($this->profile->bio) {
- common_element_start('p', 'bio');
- common_raw($this->highlight($this->profile->bio));
- common_element_end('p');
- }
-
- # If we're on a list with an owner (subscriptions or subscribers)...
-
- if ($this->owner) {
- # Get tags
- $tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
-
- common_element_start('div', 'tags_user');
- common_element_start('dl');
- common_element_start('dt');
- if ($user->id == $this->owner->id) {
- common_element('a', array('href' => common_local_url('tagother',
- array('id' => $this->profile->id))),
- _('Tags'));
- } else {
- common_text(_('Tags'));
- }
- common_text(":");
- common_element_end('dt');
- common_element_start('dd');
- if ($tags) {
- common_element_start('ul', 'tags xoxo');
- foreach ($tags as $tag) {
- common_element_start('li');
- common_element('a', array('rel' => 'tag',
- 'href' => common_local_url($this->action,
- array('nickname' => $this->owner->nickname,
- 'tag' => $tag))),
- $tag);
- common_element_end('li');
- }
- common_element_end('ul');
- } else {
- common_text(_('(none)'));
- }
- common_element_end('dd');
- common_element_end('dl');
- common_element_end('div');
- }
+ var $profile = NULL;
+ var $owner = NULL;
+ var $action = NULL;
+
+ function __construct($profile, $owner=NULL, $action=NULL) {
+ $this->profile = $profile;
+ $this->owner = $owner;
+ $this->action = $action;
+ }
+
+ function show_list() {
+
+ common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list'));
+
+ $cnt = 0;
+
+ while ($this->profile->fetch()) {
+ $cnt++;
+ if($cnt > PROFILES_PER_PAGE) {
+ break;
+ }
+ $this->show();
+ }
+
+ common_element_end('ul');
+
+ return $cnt;
+ }
+
+ function show() {
+
+ common_element_start('li', array('class' => 'profile_single',
+ 'id' => 'profile-' . $this->profile->id));
+
+ $user = common_current_user();
+
+ if ($user && $user->id != $this->profile->id) {
+ # XXX: special-case for user looking at own
+ # subscriptions page
+ if ($user->isSubscribed($this->profile)) {
+ common_unsubscribe_form($this->profile);
+ } else {
+ common_subscribe_form($this->profile);
+ }
+ }
+
+ $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
+ common_element_start('a', array('href' => $this->profile->profileurl));
+ common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
+ 'class' => 'avatar stream',
+ 'width' => AVATAR_STREAM_SIZE,
+ 'height' => AVATAR_STREAM_SIZE,
+ 'alt' =>
+ ($this->profile->fullname) ? $this->profile->fullname :
+ $this->profile->nickname));
+ common_element_end('a');
+ common_element_start('p');
+ common_element_start('a', array('href' => $this->profile->profileurl,
+ 'class' => 'nickname'));
+ common_raw($this->highlight($this->profile->nickname));
+ common_element_end('a');
+ if ($this->profile->fullname) {
+ common_text(' | ');
+ common_element_start('span', 'fullname');
+ common_raw($this->highlight($this->profile->fullname));
+ common_element_end('span');
+ }
+ if ($this->profile->location) {
+ common_text(' | ');
+ common_element_start('span', 'location');
+ common_raw($this->highlight($this->profile->location));
+ common_element_end('span');
+ }
+ common_element_end('p');
+ if ($this->profile->homepage) {
+ common_element_start('p', 'website');
+ common_element_start('a', array('href' => $this->profile->homepage));
+ common_raw($this->highlight($this->profile->homepage));
+ common_element_end('a');
+ common_element_end('p');
+ }
+ if ($this->profile->bio) {
+ common_element_start('p', 'bio');
+ common_raw($this->highlight($this->profile->bio));
+ common_element_end('p');
+ }
+
+ # If we're on a list with an owner (subscriptions or subscribers)...
+
+ if ($this->owner) {
+ # Get tags
+ $tags = Profile_tag::getTags($this->owner->id, $this->profile->id);
+
+ common_element_start('div', 'tags_user');
+ common_element_start('dl');
+ common_element_start('dt');
+ if ($user->id == $this->owner->id) {
+ common_element('a', array('href' => common_local_url('tagother',
+ array('id' => $this->profile->id))),
+ _('Tags'));
+ } else {
+ common_text(_('Tags'));
+ }
+ common_text(":");
+ common_element_end('dt');
+ common_element_start('dd');
+ if ($tags) {
+ common_element_start('ul', 'tags xoxo');
+ foreach ($tags as $tag) {
+ common_element_start('li');
+ common_element('a', array('rel' => 'tag',
+ 'href' => common_local_url($this->action,
+ array('nickname' => $this->owner->nickname,
+ 'tag' => $tag))),
+ $tag);
+ common_element_end('li');
+ }
+ common_element_end('ul');
+ } else {
+ common_text(_('(none)'));
+ }
+ common_element_end('dd');
+ common_element_end('dl');
+ common_element_end('div');
+ }
if ($user && $user->id == $this->owner->id) {
$this->show_owner_controls($this->profile);
}
- common_element_end('li');
- }
+ common_element_end('li');
+ }
/* Override this in subclasses. */
@@ -163,7 +163,7 @@ class ProfileList {
return;
}
- function highlight($text) {
- return htmlspecialchars($text);
- }
+ function highlight($text) {
+ return htmlspecialchars($text);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/lib/queuehandler.php b/_darcs/pristine/lib/queuehandler.php
index 23f295c45..5e3905f59 100644
--- a/_darcs/pristine/lib/queuehandler.php
+++ b/_darcs/pristine/lib/queuehandler.php
@@ -27,106 +27,106 @@ require_once(INSTALLDIR.'/classes/Notice.php');
class QueueHandler extends Daemon {
- var $_id = 'generic';
+ var $_id = 'generic';
- function QueueHandler($id=NULL) {
- if ($id) {
- $this->set_id($id);
- }
- }
-
- function class_name() {
- return ucfirst($this->transport()) . 'Handler';
- }
+ function QueueHandler($id=NULL) {
+ if ($id) {
+ $this->set_id($id);
+ }
+ }
+
+ function class_name() {
+ return ucfirst($this->transport()) . 'Handler';
+ }
- function name() {
- return strtolower($this->class_name().'.'.$this->get_id());
- }
-
- function get_id() {
- return $this->_id;
- }
+ function name() {
+ return strtolower($this->class_name().'.'.$this->get_id());
+ }
+
+ function get_id() {
+ return $this->_id;
+ }
- function set_id($id) {
- $this->_id = $id;
- }
-
- function transport() {
- return NULL;
- }
-
- function start() {
- }
-
- function finish() {
- }
+ function set_id($id) {
+ $this->_id = $id;
+ }
+
+ function transport() {
+ return NULL;
+ }
+
+ function start() {
+ }
+
+ function finish() {
+ }
- function handle_notice($notice) {
- return true;
- }
-
- function run() {
- if (!$this->start()) {
- return false;
- }
- $this->log(LOG_INFO, 'checking for queued notices');
- $transport = $this->transport();
- do {
- $qi = Queue_item::top($transport);
- if ($qi) {
- $this->log(LOG_INFO, 'Got item enqueued '.common_exact_date($qi->created));
- $notice = Notice::staticGet($qi->notice_id);
- if ($notice) {
- $this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id);
- # XXX: what to do if broadcast fails?
- $result = $this->handle_notice($notice);
- if (!$result) {
- $this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id);
- $orig = $qi;
- $qi->claimed = NULL;
- $qi->update($orig);
- $this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id);
- continue;
- }
- $this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id);
- $notice->free();
- unset($notice);
- $notice = NULL;
- } else {
- $this->log(LOG_WARNING, 'queue item for notice that does not exist');
- }
- $qi->delete();
- $qi->free();
- unset($qi);
- $this->idle(0);
- } else {
- $this->clear_old_claims();
- $this->idle(5);
- }
- } while (true);
- if (!$this->finish()) {
- return false;
- }
- return true;
- }
+ function handle_notice($notice) {
+ return true;
+ }
+
+ function run() {
+ if (!$this->start()) {
+ return false;
+ }
+ $this->log(LOG_INFO, 'checking for queued notices');
+ $transport = $this->transport();
+ do {
+ $qi = Queue_item::top($transport);
+ if ($qi) {
+ $this->log(LOG_INFO, 'Got item enqueued '.common_exact_date($qi->created));
+ $notice = Notice::staticGet($qi->notice_id);
+ if ($notice) {
+ $this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id);
+ # XXX: what to do if broadcast fails?
+ $result = $this->handle_notice($notice);
+ if (!$result) {
+ $this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id);
+ $orig = $qi;
+ $qi->claimed = NULL;
+ $qi->update($orig);
+ $this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id);
+ continue;
+ }
+ $this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id);
+ $notice->free();
+ unset($notice);
+ $notice = NULL;
+ } else {
+ $this->log(LOG_WARNING, 'queue item for notice that does not exist');
+ }
+ $qi->delete();
+ $qi->free();
+ unset($qi);
+ $this->idle(0);
+ } else {
+ $this->clear_old_claims();
+ $this->idle(5);
+ }
+ } while (true);
+ if (!$this->finish()) {
+ return false;
+ }
+ return true;
+ }
- function idle($timeout=0) {
- if ($timeout>0) {
- sleep($timeout);
- }
- }
-
- function clear_old_claims() {
- $qi = new Queue_item();
- $qi->transport = $this->transport();
- $qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
- $qi->update(DB_DATAOBJECT_WHEREADD_ONLY);
- $qi->free();
- unset($qi);
- }
-
- function log($level, $msg) {
- common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg);
- }
+ function idle($timeout=0) {
+ if ($timeout>0) {
+ sleep($timeout);
+ }
+ }
+
+ function clear_old_claims() {
+ $qi = new Queue_item();
+ $qi->transport = $this->transport();
+ $qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
+ $qi->update(DB_DATAOBJECT_WHEREADD_ONLY);
+ $qi->free();
+ unset($qi);
+ }
+
+ function log($level, $msg) {
+ common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg);
+ }
}
- \ No newline at end of file
+ \ No newline at end of file
diff --git a/_darcs/pristine/lib/rssaction.php b/_darcs/pristine/lib/rssaction.php
index 777511506..b64796888 100644
--- a/_darcs/pristine/lib/rssaction.php
+++ b/_darcs/pristine/lib/rssaction.php
@@ -23,167 +23,167 @@ define('DEFAULT_RSS_LIMIT', 48);
class Rss10Action extends Action {
- # This will contain the details of each feed item's author and be used to generate SIOC data.
- var $creators = array();
-
- function is_readonly() {
- return true;
- }
-
- function handle($args) {
- parent::handle($args);
- $limit = (int) $this->trimmed('limit');
- if ($limit == 0) {
- $limit = DEFAULT_RSS_LIMIT;
- }
- $this->show_rss($limit);
- }
-
- function init() {
- return true;
- }
-
- function get_notices() {
- return array();
- }
-
- function get_channel() {
- return array('url' => '',
- 'title' => '',
- 'link' => '',
- 'description' => '');
- }
-
- function get_image() {
- return NULL;
- }
-
- function show_rss($limit=0) {
-
- if (!$this->init()) {
- return;
- }
-
- $notices = $this->get_notices($limit);
-
- $this->init_rss();
- $this->show_channel($notices);
- $this->show_image();
-
- foreach ($notices as $n) {
- $this->show_item($n);
- }
-
- $this->show_creators();
- $this->end_rss();
- }
-
- function show_channel($notices) {
-
- $channel = $this->get_channel();
- $image = $this->get_image();
-
- common_element_start('channel', array('rdf:about' => $channel['url']));
- common_element('title', NULL, $channel['title']);
- common_element('link', NULL, $channel['link']);
- common_element('description', NULL, $channel['description']);
- common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
-
- if ($image) {
- common_element('image', array('rdf:resource' => $image));
- }
-
- common_element_start('items');
- common_element_start('rdf:Seq');
-
- foreach ($notices as $notice) {
- common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
- }
-
- common_element_end('rdf:Seq');
- common_element_end('items');
-
- common_element_end('channel');
- }
-
- function show_image() {
- $image = $this->get_image();
- if ($image) {
- $channel = $this->get_channel();
- common_element_start('image', array('rdf:about' => $image));
- common_element('title', NULL, $channel['title']);
- common_element('link', NULL, $channel['link']);
- common_element('url', NULL, $image);
- common_element_end('image');
- }
- }
-
- function show_item($notice) {
- $profile = Profile::staticGet($notice->profile_id);
- $nurl = common_local_url('shownotice', array('notice' => $notice->id));
- $creator_uri = common_profile_uri($profile);
- common_element_start('item', array('rdf:about' => $notice->uri));
- $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
- common_element('title', NULL, $title);
- common_element('link', NULL, $nurl);
- common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
- common_element('dc:date', NULL, common_date_w3dtf($notice->created));
- common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
- common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
- common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
- common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
- common_element_end('item');
- $this->creators[$creator_uri] = $profile;
- }
-
- function show_creators() {
- foreach ($this->creators as $uri => $profile) {
- $id = $profile->id;
- $nickname = $profile->nickname;
- common_element_start('sioc:User', array('rdf:about' => $uri));
- common_element('foaf:nick', NULL, $nickname);
- if ($profile->fullname) {
- common_element('foaf:name', NULL, $profile->fullname);
- }
- common_element('sioc:id', NULL, $id);
- $avatar = common_profile_avatar_url($profile);
- common_element('sioc:avatar', array('rdf:resource' => $avatar));
- common_element_end('sioc:User');
- }
- }
-
- function init_rss() {
- $channel = $this->get_channel();
- header('Content-Type: application/rdf+xml');
-
- common_start_xml();
- common_element_start('rdf:RDF', array('xmlns:rdf' =>
- 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
- 'xmlns:dc' =>
- 'http://purl.org/dc/elements/1.1/',
- 'xmlns:cc' =>
- 'http://web.resource.org/cc/',
+ # This will contain the details of each feed item's author and be used to generate SIOC data.
+ var $creators = array();
+
+ function is_readonly() {
+ return true;
+ }
+
+ function handle($args) {
+ parent::handle($args);
+ $limit = (int) $this->trimmed('limit');
+ if ($limit == 0) {
+ $limit = DEFAULT_RSS_LIMIT;
+ }
+ $this->show_rss($limit);
+ }
+
+ function init() {
+ return true;
+ }
+
+ function get_notices() {
+ return array();
+ }
+
+ function get_channel() {
+ return array('url' => '',
+ 'title' => '',
+ 'link' => '',
+ 'description' => '');
+ }
+
+ function get_image() {
+ return NULL;
+ }
+
+ function show_rss($limit=0) {
+
+ if (!$this->init()) {
+ return;
+ }
+
+ $notices = $this->get_notices($limit);
+
+ $this->init_rss();
+ $this->show_channel($notices);
+ $this->show_image();
+
+ foreach ($notices as $n) {
+ $this->show_item($n);
+ }
+
+ $this->show_creators();
+ $this->end_rss();
+ }
+
+ function show_channel($notices) {
+
+ $channel = $this->get_channel();
+ $image = $this->get_image();
+
+ common_element_start('channel', array('rdf:about' => $channel['url']));
+ common_element('title', NULL, $channel['title']);
+ common_element('link', NULL, $channel['link']);
+ common_element('description', NULL, $channel['description']);
+ common_element('cc:licence', array('rdf:resource' => common_config('license','url')));
+
+ if ($image) {
+ common_element('image', array('rdf:resource' => $image));
+ }
+
+ common_element_start('items');
+ common_element_start('rdf:Seq');
+
+ foreach ($notices as $notice) {
+ common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
+ }
+
+ common_element_end('rdf:Seq');
+ common_element_end('items');
+
+ common_element_end('channel');
+ }
+
+ function show_image() {
+ $image = $this->get_image();
+ if ($image) {
+ $channel = $this->get_channel();
+ common_element_start('image', array('rdf:about' => $image));
+ common_element('title', NULL, $channel['title']);
+ common_element('link', NULL, $channel['link']);
+ common_element('url', NULL, $image);
+ common_element_end('image');
+ }
+ }
+
+ function show_item($notice) {
+ $profile = Profile::staticGet($notice->profile_id);
+ $nurl = common_local_url('shownotice', array('notice' => $notice->id));
+ $creator_uri = common_profile_uri($profile);
+ common_element_start('item', array('rdf:about' => $notice->uri));
+ $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
+ common_element('title', NULL, $title);
+ common_element('link', NULL, $nurl);
+ common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created));
+ common_element('dc:date', NULL, common_date_w3dtf($notice->created));
+ common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname);
+ common_element('sioc:has_creator', array('rdf:resource' => $creator_uri));
+ common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
+ common_element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
+ common_element_end('item');
+ $this->creators[$creator_uri] = $profile;
+ }
+
+ function show_creators() {
+ foreach ($this->creators as $uri => $profile) {
+ $id = $profile->id;
+ $nickname = $profile->nickname;
+ common_element_start('sioc:User', array('rdf:about' => $uri));
+ common_element('foaf:nick', NULL, $nickname);
+ if ($profile->fullname) {
+ common_element('foaf:name', NULL, $profile->fullname);
+ }
+ common_element('sioc:id', NULL, $id);
+ $avatar = common_profile_avatar_url($profile);
+ common_element('sioc:avatar', array('rdf:resource' => $avatar));
+ common_element_end('sioc:User');
+ }
+ }
+
+ function init_rss() {
+ $channel = $this->get_channel();
+ header('Content-Type: application/rdf+xml');
+
+ common_start_xml();
+ common_element_start('rdf:RDF', array('xmlns:rdf' =>
+ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
+ 'xmlns:dc' =>
+ 'http://purl.org/dc/elements/1.1/',
+ 'xmlns:cc' =>
+ 'http://web.resource.org/cc/',
'xmlns:content' =>
'http://purl.org/rss/1.0/modules/content/',
- 'xmlns:foaf' =>
- 'http://xmlns.com/foaf/0.1/',
- 'xmlns:sioc' =>
- 'http://rdfs.org/sioc/ns#',
- 'xmlns:sioct' =>
- 'http://rdfs.org/sioc/types#',
- 'xmlns:laconica' =>
- 'http://laconi.ca/ont/',
- 'xmlns' => 'http://purl.org/rss/1.0/'));
- common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
- common_element('sioc:name', NULL, common_config('site', 'name'));
- common_element_start('sioc:container_of');
- common_element('sioc:Container', array('rdf:about' =>
- $channel['url']));
- common_element_end('sioc:container_of');
- common_element_end('sioc:Site');
- }
-
- function end_rss() {
- common_element_end('rdf:RDF');
- }
+ 'xmlns:foaf' =>
+ 'http://xmlns.com/foaf/0.1/',
+ 'xmlns:sioc' =>
+ 'http://rdfs.org/sioc/ns#',
+ 'xmlns:sioct' =>
+ 'http://rdfs.org/sioc/types#',
+ 'xmlns:laconica' =>
+ 'http://laconi.ca/ont/',
+ 'xmlns' => 'http://purl.org/rss/1.0/'));
+ common_element_start('sioc:Site', array('rdf:about' => common_root_url()));
+ common_element('sioc:name', NULL, common_config('site', 'name'));
+ common_element_start('sioc:container_of');
+ common_element('sioc:Container', array('rdf:about' =>
+ $channel['url']));
+ common_element_end('sioc:container_of');
+ common_element_end('sioc:Site');
+ }
+
+ function end_rss() {
+ common_element_end('rdf:RDF');
+ }
}
diff --git a/_darcs/pristine/lib/search_engines.php b/_darcs/pristine/lib/search_engines.php
index 7fcc1ffcb..d53d7d8d8 100644
--- a/_darcs/pristine/lib/search_engines.php
+++ b/_darcs/pristine/lib/search_engines.php
@@ -98,10 +98,10 @@ class MySQLSearch extends SearchEngine {
function query($q) {
if ('identica_people' === $this->table)
return $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
- 'against (\''.addslashes($q).'\')');
+ 'against (\''.addslashes($q).'\')');
if ('identica_notices' === $this->table)
return $this->target->whereAdd('MATCH(content) ' .
- 'against (\''.addslashes($q).'\')');
+ 'against (\''.addslashes($q).'\')');
}
}
diff --git a/_darcs/pristine/lib/searchaction.php b/_darcs/pristine/lib/searchaction.php
index f99883b25..8634bd99c 100644
--- a/_darcs/pristine/lib/searchaction.php
+++ b/_darcs/pristine/lib/searchaction.php
@@ -21,90 +21,90 @@ if (!defined('LACONICA')) { exit(1); }
class SearchAction extends Action {
- function is_readonly() {
- return true;
- }
+ function is_readonly() {
+ return true;
+ }
- function handle($args) {
- parent::handle($args);
- $this->show_form();
- }
+ function handle($args) {
+ parent::handle($args);
+ $this->show_form();
+ }
- function show_top($arr=NULL) {
- if ($arr) {
- $error = $arr[1];
- }
- if ($error) {
- common_element('p', 'error', $error);
- } else {
- $instr = $this->get_instructions();
- $output = common_markup_to_html($instr);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
- $this->search_menu();
- }
+ function show_top($arr=NULL) {
+ if ($arr) {
+ $error = $arr[1];
+ }
+ if ($error) {
+ common_element('p', 'error', $error);
+ } else {
+ $instr = $this->get_instructions();
+ $output = common_markup_to_html($instr);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+ $this->search_menu();
+ }
- function get_title() {
- return NULL;
- }
+ function get_title() {
+ return NULL;
+ }
- function show_header($arr) {
- return;
- }
+ function show_header($arr) {
+ return;
+ }
- function show_form($error=NULL) {
- global $config;
+ function show_form($error=NULL) {
+ global $config;
- $q = $this->trimmed('q');
- $page = $this->trimmed('page', 1);
+ $q = $this->trimmed('q');
+ $page = $this->trimmed('page', 1);
- common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error),
- array($this, 'show_top'));
- common_element_start('form', array('method' => 'get',
- 'id' => 'login',
- 'action' => common_local_url($this->trimmed('action'))));
- common_element_start('p');
- if (!isset($config['site']['fancy']) || !$config['site']['fancy']) {
- common_element('input', array('name' => 'action',
- 'type' => 'hidden',
- 'value' => $this->trimmed('action')));
- }
- common_element('input', array('name' => 'q',
- 'id' => 'q',
- 'type' => 'text',
- 'class' => 'input_text',
- 'value' => ($q) ? $q : ''));
- common_text(' ');
- common_element('input', array('type' => 'submit',
- 'id' => 'search',
- 'name' => 'search',
- 'class' => 'submit',
- 'value' => _('Search')));
+ common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error),
+ array($this, 'show_top'));
+ common_element_start('form', array('method' => 'get',
+ 'id' => 'login',
+ 'action' => common_local_url($this->trimmed('action'))));
+ common_element_start('p');
+ if (!isset($config['site']['fancy']) || !$config['site']['fancy']) {
+ common_element('input', array('name' => 'action',
+ 'type' => 'hidden',
+ 'value' => $this->trimmed('action')));
+ }
+ common_element('input', array('name' => 'q',
+ 'id' => 'q',
+ 'type' => 'text',
+ 'class' => 'input_text',
+ 'value' => ($q) ? $q : ''));
+ common_text(' ');
+ common_element('input', array('type' => 'submit',
+ 'id' => 'search',
+ 'name' => 'search',
+ 'class' => 'submit',
+ 'value' => _('Search')));
- common_element_end('p');
- common_element_end('form');
- if ($q) {
- $this->show_results($q, $page);
- }
- common_show_footer();
- }
+ common_element_end('p');
+ common_element_end('form');
+ if ($q) {
+ $this->show_results($q, $page);
+ }
+ common_show_footer();
+ }
- function search_menu() {
- # action => array('prompt', 'title', $args)
- $action = $this->trimmed('action');
- $menu =
- array('peoplesearch' =>
- array(
- _('People'),
- _('Find people on this site'),
- ($action != 'peoplesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL),
- 'noticesearch' =>
- array( _('Text'),
- _('Find content of notices'),
- ($action != 'noticesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL)
- );
- $this->nav_menu($menu);
- }
+ function search_menu() {
+ # action => array('prompt', 'title', $args)
+ $action = $this->trimmed('action');
+ $menu =
+ array('peoplesearch' =>
+ array(
+ _('People'),
+ _('Find people on this site'),
+ ($action != 'peoplesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL),
+ 'noticesearch' =>
+ array( _('Text'),
+ _('Find content of notices'),
+ ($action != 'noticesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL)
+ );
+ $this->nav_menu($menu);
+ }
}
diff --git a/_darcs/pristine/lib/settingsaction.php b/_darcs/pristine/lib/settingsaction.php
index 9e783431f..3021eb192 100644
--- a/_darcs/pristine/lib/settingsaction.php
+++ b/_darcs/pristine/lib/settingsaction.php
@@ -27,9 +27,9 @@ class SettingsAction extends Action {
common_user_error(_('Not logged in.'));
return;
} else if (!common_is_real_login()) {
- # Cookie theft means that automatic logins can't
- # change important settings or see private info, and
- # _all_ our settings are important
+ # Cookie theft means that automatic logins can't
+ # change important settings or see private info, and
+ # _all_ our settings are important
common_set_returnto($this->self_url());
common_redirect(common_local_url('login'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@@ -55,60 +55,60 @@ class SettingsAction extends Action {
}
}
- function form_header($title, $msg=NULL, $success=false) {
- common_show_header($title,
- NULL,
- array($msg, $success),
- array($this, 'show_top'));
- }
+ function form_header($title, $msg=NULL, $success=false) {
+ common_show_header($title,
+ NULL,
+ array($msg, $success),
+ array($this, 'show_top'));
+ }
- function show_top($arr) {
- $msg = $arr[0];
- $success = $arr[1];
- if ($msg) {
- $this->message($msg, $success);
- } else {
- $inst = $this->get_instructions();
- $output = common_markup_to_html($inst);
- common_element_start('div', 'instructions');
- common_raw($output);
- common_element_end('div');
- }
- $this->settings_menu();
- }
+ function show_top($arr) {
+ $msg = $arr[0];
+ $success = $arr[1];
+ if ($msg) {
+ $this->message($msg, $success);
+ } else {
+ $inst = $this->get_instructions();
+ $output = common_markup_to_html($inst);
+ common_element_start('div', 'instructions');
+ common_raw($output);
+ common_element_end('div');
+ }
+ $this->settings_menu();
+ }
function settings_menu() {
# action => array('prompt', 'title')
- $menu =
- array('profilesettings' =>
- array(_('Profile'),
- _('Change your profile settings')),
- 'emailsettings' =>
- array(_('Email'),
- _('Change email handling')),
- 'openidsettings' =>
- array(_('OpenID'),
- _('Add or remove OpenIDs')),
- 'smssettings' =>
- array(_('SMS'),
- _('Updates by SMS')),
- 'imsettings' =>
- array(_('IM'),
- _('Updates by instant messenger (IM)')),
- 'twittersettings' =>
- array(_('Twitter'),
- _('Twitter integration options')),
- 'othersettings' =>
- array(_('Other'),
- _('Other options')));
-
+ $menu =
+ array('profilesettings' =>
+ array(_('Profile'),
+ _('Change your profile settings')),
+ 'emailsettings' =>
+ array(_('Email'),
+ _('Change email handling')),
+ 'openidsettings' =>
+ array(_('OpenID'),
+ _('Add or remove OpenIDs')),
+ 'smssettings' =>
+ array(_('SMS'),
+ _('Updates by SMS')),
+ 'imsettings' =>
+ array(_('IM'),
+ _('Updates by instant messenger (IM)')),
+ 'twittersettings' =>
+ array(_('Twitter'),
+ _('Twitter integration options')),
+ 'othersettings' =>
+ array(_('Other'),
+ _('Other options')));
+
$action = $this->trimmed('action');
common_element_start('ul', array('id' => 'nav_views'));
foreach ($menu as $menuaction => $menudesc) {
- if ($menuaction == 'imsettings' &&
- !common_config('xmpp', 'enabled')) {
- continue;
- }
+ if ($menuaction == 'imsettings' &&
+ !common_config('xmpp', 'enabled')) {
+ continue;
+ }
common_menu_item(common_local_url($menuaction),
$menudesc[0],
$menudesc[1],
diff --git a/_darcs/pristine/lib/stream.php b/_darcs/pristine/lib/stream.php
index 27ab78137..2d45df2d3 100644
--- a/_darcs/pristine/lib/stream.php
+++ b/_darcs/pristine/lib/stream.php
@@ -10,11 +10,11 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('LACONICA')) { exit(1); }
@@ -24,29 +24,29 @@ require_once(INSTALLDIR.'/lib/noticelist.php');
class StreamAction extends PersonalAction {
- function public_views_menu() {
+ function public_views_menu() {
- $action = $this->trimmed('action');
+ $action = $this->trimmed('action');
- common_element_start('ul', array('id' => 'nav_views'));
+ common_element_start('ul', array('id' => 'nav_views'));
- common_menu_item(common_local_url('public'), _('Public'),
- _('Public timeline'), $action == 'public');
+ common_menu_item(common_local_url('public'), _('Public'),
+ _('Public timeline'), $action == 'public');
- common_menu_item(common_local_url('tag'), _('Recent tags'),
- _('Recent tags'), $action == 'tag');
+ common_menu_item(common_local_url('tag'), _('Recent tags'),
+ _('Recent tags'), $action == 'tag');
- if (count(common_config('nickname', 'featured')) > 0) {
- common_menu_item(common_local_url('featured'), _('Featured'),
- _('Featured users'), $action == 'featured');
- }
+ if (count(common_config('nickname', 'featured')) > 0) {
+ common_menu_item(common_local_url('featured'), _('Featured'),
+ _('Featured users'), $action == 'featured');
+ }
- common_menu_item(common_local_url('favorited'), _('Popular'),
- _("Popular notices"), $action == 'favorited');
+ common_menu_item(common_local_url('favorited'), _('Popular'),
+ _("Popular notices"), $action == 'favorited');
- common_element_end('ul');
+ common_element_end('ul');
- }
+ }
function show_notice_list($notice) {
$nl = new NoticeList($notice);
diff --git a/_darcs/pristine/lib/subs.php b/_darcs/pristine/lib/subs.php
index 91fc8445d..55e74e0b2 100644
--- a/_darcs/pristine/lib/subs.php
+++ b/_darcs/pristine/lib/subs.php
@@ -27,13 +27,13 @@ require_once('XMPPHP/XMPP.php');
function subs_subscribe_user($user, $other_nickname) {
- $other = User::staticGet('nickname', $other_nickname);
+ $other = User::staticGet('nickname', $other_nickname);
- if (!$other) {
- return _('No such user.');
- }
+ if (!$other) {
+ return _('No such user.');
+ }
- return subs_subscribe_to($user, $other);
+ return subs_subscribe_to($user, $other);
}
/* Subscribe user $user to other user $other.
@@ -43,54 +43,54 @@ function subs_subscribe_user($user, $other_nickname) {
function subs_subscribe_to($user, $other) {
- if ($user->isSubscribed($other)) {
- return _('Already subscribed!.');
- }
+ if ($user->isSubscribed($other)) {
+ return _('Already subscribed!.');
+ }
if ($other->hasBlocked($user)) {
- return _('User has blocked you.');
+ return _('User has blocked you.');
}
- if (!$user->subscribeTo($other)) {
- return _('Could not subscribe.');
- return;
- }
+ if (!$user->subscribeTo($other)) {
+ return _('Could not subscribe.');
+ return;
+ }
subs_notify($other, $user);
- if (common_config('memcached', 'enabled')) {
- $cache = new Memcache();
- if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
- }
- }
-
- if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) {
- if (!$other->subscribeTo($user)) {
- return _('Could not subscribe other to you.');
- }
- if (common_config('memcached', 'enabled')) {
- $cache = new Memcache();
- if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $other->id));
- }
- }
-
- subs_notify($user, $other);
- }
-
- return true;
+ if (common_config('memcached', 'enabled')) {
+ $cache = new Memcache();
+ if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
+ }
+ }
+
+ if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) {
+ if (!$other->subscribeTo($user)) {
+ return _('Could not subscribe other to you.');
+ }
+ if (common_config('memcached', 'enabled')) {
+ $cache = new Memcache();
+ if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $other->id));
+ }
+ }
+
+ subs_notify($user, $other);
+ }
+
+ return true;
}
function subs_notify($listenee, $listener) {
- # XXX: add other notifications (Jabber, SMS) here
- # XXX: queue this and handle it offline
- # XXX: Whatever happens, do it in Twitter-like API, too
- subs_notify_email($listenee, $listener);
+ # XXX: add other notifications (Jabber, SMS) here
+ # XXX: queue this and handle it offline
+ # XXX: Whatever happens, do it in Twitter-like API, too
+ subs_notify_email($listenee, $listener);
}
function subs_notify_email($listenee, $listener) {
- mail_subscribe_notify($listenee, $listener);
+ mail_subscribe_notify($listenee, $listener);
}
/* Unsubscribe $user from nickname $other_nickname
@@ -99,13 +99,13 @@ function subs_notify_email($listenee, $listener) {
function subs_unsubscribe_user($user, $other_nickname) {
- $other = User::staticGet('nickname', $other_nickname);
+ $other = User::staticGet('nickname', $other_nickname);
- if (!$other) {
- return _('No such user.');
- }
+ if (!$other) {
+ return _('No such user.');
+ }
- return subs_unsubscribe_to($user, $other->getProfile());
+ return subs_unsubscribe_to($user, $other->getProfile());
}
/* Unsubscribe user $user from profile $other
@@ -113,28 +113,28 @@ function subs_unsubscribe_user($user, $other_nickname) {
function subs_unsubscribe_to($user, $other) {
- if (!$user->isSubscribed($other))
- return _('Not subscribed!.');
+ if (!$user->isSubscribed($other))
+ return _('Not subscribed!.');
- $sub = DB_DataObject::factory('subscription');
+ $sub = DB_DataObject::factory('subscription');
- $sub->subscriber = $user->id;
- $sub->subscribed = $other->id;
+ $sub->subscriber = $user->id;
+ $sub->subscribed = $other->id;
- $sub->find(true);
+ $sub->find(true);
- // note we checked for existence above
+ // note we checked for existence above
- if (!$sub->delete())
- return _('Couldn\'t delete subscription.');
+ if (!$sub->delete())
+ return _('Couldn\'t delete subscription.');
- if (common_config('memcached', 'enabled')) {
- $cache = new Memcache();
- if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
- }
- }
+ if (common_config('memcached', 'enabled')) {
+ $cache = new Memcache();
+ if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
+ }
+ }
- return true;
+ return true;
}
diff --git a/_darcs/pristine/lib/theme.php b/_darcs/pristine/lib/theme.php
index 80982aa82..346cff434 100644
--- a/_darcs/pristine/lib/theme.php
+++ b/_darcs/pristine/lib/theme.php
@@ -20,16 +20,16 @@
if (!defined('LACONICA')) { exit(1); }
function theme_file($relative) {
- $theme = common_config('site', 'theme');
- return INSTALLDIR.'/theme/'.$theme.'/'.$relative;
+ $theme = common_config('site', 'theme');
+ return INSTALLDIR.'/theme/'.$theme.'/'.$relative;
}
function theme_path($relative) {
- $theme = common_config('site', 'theme');
- $server = common_config('theme', 'server');
- if ($server) {
- return 'http://'.$server.'/'.$theme.'/'.$relative;
- } else {
- return common_path('theme/'.$theme.'/'.$relative);
- }
+ $theme = common_config('site', 'theme');
+ $server = common_config('theme', 'server');
+ if ($server) {
+ return 'http://'.$server.'/'.$theme.'/'.$relative;
+ } else {
+ return common_path('theme/'.$theme.'/'.$relative);
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/lib/twitter.php b/_darcs/pristine/lib/twitter.php
index 5c9ef5d6f..c1d2de0ea 100644
--- a/_darcs/pristine/lib/twitter.php
+++ b/_darcs/pristine/lib/twitter.php
@@ -21,179 +21,179 @@ if (!defined('LACONICA')) { exit(1); }
function get_twitter_data($uri, $screen_name, $password) {
- $options = array(
- CURLOPT_USERPWD => sprintf("%s:%s", $screen_name, $password),
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FAILONERROR => true,
- CURLOPT_HEADER => false,
- CURLOPT_FOLLOWLOCATION => true,
- // CURLOPT_USERAGENT => "identi.ca",
- CURLOPT_CONNECTTIMEOUT => 120,
- CURLOPT_TIMEOUT => 120
- );
-
-
- $ch = curl_init($uri);
+ $options = array(
+ CURLOPT_USERPWD => sprintf("%s:%s", $screen_name, $password),
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_FAILONERROR => true,
+ CURLOPT_HEADER => false,
+ CURLOPT_FOLLOWLOCATION => true,
+ // CURLOPT_USERAGENT => "identi.ca",
+ CURLOPT_CONNECTTIMEOUT => 120,
+ CURLOPT_TIMEOUT => 120
+ );
+
+
+ $ch = curl_init($uri);
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
$errmsg = curl_error($ch);
- if ($errmsg) {
- common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $twit_user.",
- __FILE__);
- }
+ if ($errmsg) {
+ common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $twit_user.",
+ __FILE__);
+ }
- curl_close($ch);
+ curl_close($ch);
- return $data;
+ return $data;
}
function twitter_user_info($screen_name, $password) {
- $uri = "http://twitter.com/users/show/$screen_name.json";
- $data = get_twitter_data($uri, $screen_name, $password);
+ $uri = "http://twitter.com/users/show/$screen_name.json";
+ $data = get_twitter_data($uri, $screen_name, $password);
- if (!$data) {
- return false;
- }
+ if (!$data) {
+ return false;
+ }
- $twit_user = json_decode($data);
+ $twit_user = json_decode($data);
- if (!$twit_user) {
- return false;
- }
+ if (!$twit_user) {
+ return false;
+ }
- return $twit_user;
+ return $twit_user;
}
function update_twitter_user($fuser, $twitter_id, $screen_name) {
- $original = clone($fuser);
- $fuser->nickname = $screen_name;
- $fuser->uri = 'http://twitter.com/' . $screen_name;
- $result = $fuser->updateKeys($original);
+ $original = clone($fuser);
+ $fuser->nickname = $screen_name;
+ $fuser->uri = 'http://twitter.com/' . $screen_name;
+ $result = $fuser->updateKeys($original);
- if (!$result) {
- common_log_db_error($fuser, 'UPDATE', __FILE__);
- return false;
- }
+ if (!$result) {
+ common_log_db_error($fuser, 'UPDATE', __FILE__);
+ return false;
+ }
- return true;
+ return true;
}
function add_twitter_user($twitter_id, $screen_name) {
- // Otherwise, create a new Twitter user
- $fuser = DB_DataObject::factory('foreign_user');
+ // Otherwise, create a new Twitter user
+ $fuser = DB_DataObject::factory('foreign_user');
- $fuser->nickname = $screen_name;
- $fuser->uri = 'http://twitter.com/' . $screen_name;
- $fuser->id = $twitter_id;
- $fuser->service = 1; // Twitter
- $fuser->created = common_sql_now();
- $result = $fuser->insert();
+ $fuser->nickname = $screen_name;
+ $fuser->uri = 'http://twitter.com/' . $screen_name;
+ $fuser->id = $twitter_id;
+ $fuser->service = 1; // Twitter
+ $fuser->created = common_sql_now();
+ $result = $fuser->insert();
- if (!$result) {
- common_debug("Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
- common_log_db_error($fuser, 'INSERT', __FILE__);
- return false;
- }
+ if (!$result) {
+ common_debug("Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
+ common_log_db_error($fuser, 'INSERT', __FILE__);
+ return false;
+ }
- common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
+ common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id).");
- return true;
+ return true;
}
// Creates or Updates a Twitter user
function save_twitter_user($twitter_id, $screen_name) {
- // Check to see whether the Twitter user is already in the system,
- // and update its screen name and uri if so.
- $fuser = Foreign_user::getForeignUser($twitter_id, 1);
+ // Check to see whether the Twitter user is already in the system,
+ // and update its screen name and uri if so.
+ $fuser = Foreign_user::getForeignUser($twitter_id, 1);
- if ($fuser) {
+ if ($fuser) {
- // Only update if Twitter screen name has changed
- if ($fuser->nickname != $screen_name) {
+ // Only update if Twitter screen name has changed
+ if ($fuser->nickname != $screen_name) {
- common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' .
- "$fuser->id to $screen_name, was $fuser->nickname");
+ common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' .
+ "$fuser->id to $screen_name, was $fuser->nickname");
- return update_twitter_user($fuser, $twitter_id, $screen_name);
- }
+ return update_twitter_user($fuser, $twitter_id, $screen_name);
+ }
- } else {
- return add_twitter_user($twitter_id, $screen_name);
- }
+ } else {
+ return add_twitter_user($twitter_id, $screen_name);
+ }
- return true;
+ return true;
}
function retreive_twitter_friends($twitter_id, $screen_name, $password) {
- $uri = "http://twitter.com/statuses/friends/$twitter_id.json?page=";
- $twitter_user = twitter_user_info($screen_name, $password);
+ $uri = "http://twitter.com/statuses/friends/$twitter_id.json?page=";
+ $twitter_user = twitter_user_info($screen_name, $password);
- // Calculate how many pages to get...
- $pages = ceil($twitter_user->friends_count / 100);
+ // Calculate how many pages to get...
+ $pages = ceil($twitter_user->friends_count / 100);
- if ($pages == 0) {
- common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame.");
- }
+ if ($pages == 0) {
+ common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame.");
+ }
- $friends = array();
+ $friends = array();
- for ($i = 1; $i <= $pages; $i++) {
+ for ($i = 1; $i <= $pages; $i++) {
- $data = get_twitter_data($uri . $i, $screen_name, $password);
+ $data = get_twitter_data($uri . $i, $screen_name, $password);
- if (!$data) {
- return NULL;
- }
+ if (!$data) {
+ return NULL;
+ }
- $more_friends = json_decode($data);
+ $more_friends = json_decode($data);
- if (!$more_friends) {
- return NULL;
- }
+ if (!$more_friends) {
+ return NULL;
+ }
- $friends = array_merge($friends, $more_friends);
- }
+ $friends = array_merge($friends, $more_friends);
+ }
- return $friends;
+ return $friends;
}
function save_twitter_friends($user, $twitter_id, $screen_name, $password) {
- $friends = retreive_twitter_friends($twitter_id, $screen_name, $password);
+ $friends = retreive_twitter_friends($twitter_id, $screen_name, $password);
- if (is_null($friends)) {
- common_debug("Twitter bridge - Couldn't get friends data from Twitter.");
- return false;
- }
+ if (is_null($friends)) {
+ common_debug("Twitter bridge - Couldn't get friends data from Twitter.");
+ return false;
+ }
foreach ($friends as $friend) {
- $friend_name = $friend->screen_name;
- $friend_id = $friend->id;
+ $friend_name = $friend->screen_name;
+ $friend_id = $friend->id;
- // Update or create the Foreign_user record
- if (!save_twitter_user($friend_id, $friend_name)) {
- return false;
- }
+ // Update or create the Foreign_user record
+ if (!save_twitter_user($friend_id, $friend_name)) {
+ return false;
+ }
- // Check to see if there's a related local user
- $flink = Foreign_link::getByForeignID($friend_id, 1);
+ // Check to see if there's a related local user
+ $flink = Foreign_link::getByForeignID($friend_id, 1);
- if ($flink) {
+ if ($flink) {
- // Get associated user and subscribe her
- $friend_user = User::staticGet('id', $flink->user_id);
- subs_subscribe_to($user, $friend_user);
- common_debug("Twitter bridge - subscribed $friend_user->nickname to $user->nickname.");
- }
- }
+ // Get associated user and subscribe her
+ $friend_user = User::staticGet('id', $flink->user_id);
+ subs_subscribe_to($user, $friend_user);
+ common_debug("Twitter bridge - subscribed $friend_user->nickname to $user->nickname.");
+ }
+ }
- return true;
+ return true;
}
diff --git a/_darcs/pristine/lib/twitterapi.php b/_darcs/pristine/lib/twitterapi.php
index 2eb127525..3122caf12 100644
--- a/_darcs/pristine/lib/twitterapi.php
+++ b/_darcs/pristine/lib/twitterapi.php
@@ -21,637 +21,637 @@ if (!defined('LACONICA')) { exit(1); }
class TwitterapiAction extends Action {
- var $auth_user;
+ var $auth_user;
- function handle($args) {
- parent::handle($args);
- }
+ function handle($args) {
+ parent::handle($args);
+ }
- function twitter_user_array($profile, $get_notice=false) {
+ function twitter_user_array($profile, $get_notice=false) {
- $twitter_user = array();
+ $twitter_user = array();
- $twitter_user['name'] = $profile->getBestName();
- $twitter_user['followers_count'] = $this->count_subscriptions($profile);
- $twitter_user['screen_name'] = $profile->nickname;
- $twitter_user['description'] = ($profile->bio) ? $profile->bio : NULL;
- $twitter_user['location'] = ($profile->location) ? $profile->location : NULL;
- $twitter_user['id'] = intval($profile->id);
+ $twitter_user['name'] = $profile->getBestName();
+ $twitter_user['followers_count'] = $this->count_subscriptions($profile);
+ $twitter_user['screen_name'] = $profile->nickname;
+ $twitter_user['description'] = ($profile->bio) ? $profile->bio : NULL;
+ $twitter_user['location'] = ($profile->location) ? $profile->location : NULL;
+ $twitter_user['id'] = intval($profile->id);
- $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
+ $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
- $twitter_user['profile_image_url'] = ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE);
- $twitter_user['protected'] = 'false'; # not supported by Laconica yet
- $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : NULL;
+ $twitter_user['profile_image_url'] = ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE);
+ $twitter_user['protected'] = 'false'; # not supported by Laconica yet
+ $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : NULL;
- if ($get_notice) {
- $notice = $profile->getCurrentNotice();
- if ($notice) {
- # don't get user!
- $twitter_user['status'] = $this->twitter_status_array($notice, false);
- }
- }
+ if ($get_notice) {
+ $notice = $profile->getCurrentNotice();
+ if ($notice) {
+ # don't get user!
+ $twitter_user['status'] = $this->twitter_status_array($notice, false);
+ }
+ }
- return $twitter_user;
- }
+ return $twitter_user;
+ }
- function twitter_status_array($notice, $include_user=true) {
+ function twitter_status_array($notice, $include_user=true) {
- $profile = $notice->getProfile();
+ $profile = $notice->getProfile();
- $twitter_status = array();
- $twitter_status['text'] = $notice->content;
- $twitter_status['truncated'] = 'false'; # Not possible on Laconica
- $twitter_status['created_at'] = $this->date_twitter($notice->created);
- $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL;
- $twitter_status['source'] = $this->source_link($notice->source);
- $twitter_status['id'] = intval($notice->id);
- $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL;
+ $twitter_status = array();
+ $twitter_status['text'] = $notice->content;
+ $twitter_status['truncated'] = 'false'; # Not possible on Laconica
+ $twitter_status['created_at'] = $this->date_twitter($notice->created);
+ $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL;
+ $twitter_status['source'] = $this->source_link($notice->source);
+ $twitter_status['id'] = intval($notice->id);
+ $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL;
- if (isset($this->auth_user)) {
- $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
- } else {
- $twitter_status['favorited'] = 'false';
- }
+ if (isset($this->auth_user)) {
+ $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
+ } else {
+ $twitter_status['favorited'] = 'false';
+ }
- if ($include_user) {
- # Don't get notice (recursive!)
- $twitter_user = $this->twitter_user_array($profile, false);
- $twitter_status['user'] = $twitter_user;
- }
+ if ($include_user) {
+ # Don't get notice (recursive!)
+ $twitter_user = $this->twitter_user_array($profile, false);
+ $twitter_status['user'] = $twitter_user;
+ }
- return $twitter_status;
- }
+ return $twitter_status;
+ }
- function twitter_rss_entry_array($notice) {
+ function twitter_rss_entry_array($notice) {
- $profile = $notice->getProfile();
+ $profile = $notice->getProfile();
- $server = common_config('site', 'server');
- $entry = array();
+ $server = common_config('site', 'server');
+ $entry = array();
# We trim() to avoid extraneous whitespace in the output
- $entry['content'] = common_xml_safe_str(trim($notice->rendered));
- $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
- $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
- $entry['published'] = common_date_iso8601($notice->created);
- $entry['id'] = "tag:$server,2008:$entry[link]";
- $entry['updated'] = $entry['published'];
-
- # RSS Item specific
- $entry['description'] = $entry['content'];
- $entry['pubDate'] = common_date_rfc2822($notice->created);
- $entry['guid'] = $entry['link'];
-
- return $entry;
- }
-
- function twitter_rss_dmsg_array($message) {
-
- $server = common_config('site', 'server');
- $entry = array();
-
- $entry['title'] = sprintf('Message from %s to %s',
- $message->getFrom()->nickname, $message->getTo()->nickname);
-
- $entry['content'] = common_xml_safe_str(trim($message->content));
- $entry['link'] = common_local_url('showmessage', array('message' => $message->id));
- $entry['published'] = common_date_iso8601($message->created);
- $entry['id'] = "tag:$server,2008:$entry[link]";
- $entry['updated'] = $entry['published'];
-
- # RSS Item specific
- $entry['description'] = $entry['content'];
- $entry['pubDate'] = common_date_rfc2822($message->created);
- $entry['guid'] = $entry['link'];
-
- return $entry;
- }
-
- function twitter_dmsg_array($message) {
-
- $twitter_dm = array();
-
- $from_profile = $message->getFrom();
- $to_profile = $message->getTo();
-
- $twitter_dm['id'] = $message->id;
- $twitter_dm['sender_id'] = $message->from_profile;
- $twitter_dm['text'] = trim($message->content);
- $twitter_dm['recipient_id'] = $message->to_profile;
- $twitter_dm['created_at'] = $this->date_twitter($message->created);
- $twitter_dm['sender_screen_name'] = $from_profile->nickname;
- $twitter_dm['recipient_screen_name'] = $to_profile->nickname;
- $twitter_dm['sender'] = $this->twitter_user_array($from_profile, false);
- $twitter_dm['recipient'] = $this->twitter_user_array($to_profile, false);
-
- return $twitter_dm;
- }
-
- function show_twitter_xml_status($twitter_status) {
- common_element_start('status');
- foreach($twitter_status as $element => $value) {
- switch ($element) {
- case 'user':
- $this->show_twitter_xml_user($twitter_status['user']);
- break;
- case 'text':
- common_element($element, NULL, common_xml_safe_str($value));
- break;
- default:
- common_element($element, NULL, $value);
- }
- }
- common_element_end('status');
- }
-
- function show_twitter_xml_user($twitter_user, $role='user') {
- common_element_start($role);
- foreach($twitter_user as $element => $value) {
- if ($element == 'status') {
- $this->show_twitter_xml_status($twitter_user['status']);
- } else {
- common_element($element, NULL, $value);
- }
- }
- common_element_end($role);
- }
-
- function show_twitter_rss_item($entry) {
- common_element_start('item');
- common_element('title', NULL, $entry['title']);
- common_element('description', NULL, $entry['description']);
- common_element('pubDate', NULL, $entry['pubDate']);
- common_element('guid', NULL, $entry['guid']);
- common_element('link', NULL, $entry['link']);
- common_element_end('item');
- }
-
- function show_twitter_atom_entry($entry) {
- common_element_start('entry');
- common_element('title', NULL, $entry['title']);
- common_element('content', array('type' => 'html'), $entry['content']);
- common_element('id', NULL, $entry['id']);
- common_element('published', NULL, $entry['published']);
- common_element('updated', NULL, $entry['updated']);
- common_element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), NULL);
- common_element_end('entry');
- }
-
- function show_json_objects($objects) {
- print(json_encode($objects));
- }
-
- function show_single_xml_status($notice) {
- $this->init_document('xml');
- $twitter_status = $this->twitter_status_array($notice);
- $this->show_twitter_xml_status($twitter_status);
- $this->end_document('xml');
- }
-
- function show_single_json_status($notice) {
- $this->init_document('json');
- $status = $this->twitter_status_array($notice);
- $this->show_json_objects($status);
- $this->end_document('json');
- }
-
- function show_single_xml_dmsg($message) {
- $this->init_document('xml');
- $dmsg = $this->twitter_dmsg_array($message);
- $this->show_twitter_xml_dmsg($dmsg);
- $this->end_document('xml');
- }
-
- function show_single_json_dmsg($message) {
- $this->init_document('json');
- $dmsg = $this->twitter_dmsg_array($message);
- $this->show_json_objects($dmsg);
- $this->end_document('json');
- }
-
- function show_twitter_xml_dmsg($twitter_dm) {
- common_element_start('direct_message');
- foreach($twitter_dm as $element => $value) {
- switch ($element) {
- case 'sender':
- case 'recipient':
- $this->show_twitter_xml_user($value, $element);
- break;
- case 'text':
- common_element($element, NULL, common_xml_safe_str($value));
- break;
- default:
- common_element($element, NULL, $value);
- }
- }
- common_element_end('direct_message');
- }
-
- function show_xml_timeline($notice) {
-
- $this->init_document('xml');
- common_element_start('statuses', array('type' => 'array'));
-
- if (is_array($notice)) {
- foreach ($notice as $n) {
- $twitter_status = $this->twitter_status_array($n);
- $this->show_twitter_xml_status($twitter_status);
- }
- } else {
- while ($notice->fetch()) {
- $twitter_status = $this->twitter_status_array($notice);
- $this->show_twitter_xml_status($twitter_status);
- }
- }
-
- common_element_end('statuses');
- $this->end_document('xml');
- }
-
- function show_rss_timeline($notice, $title, $link, $subtitle, $suplink=NULL) {
-
- $this->init_document('rss');
-
- common_element_start('channel');
- common_element('title', NULL, $title);
- common_element('link', NULL, $link);
- if (!is_null($suplink)) {
- # For FriendFeed's SUP protocol
- common_element('link', array('xmlns' => 'http://www.w3.org/2005/Atom',
- 'rel' => 'http://api.friendfeed.com/2008/03#sup',
- 'href' => $suplink,
- 'type' => 'application/json'));
- }
- common_element('description', NULL, $subtitle);
- common_element('language', NULL, 'en-us');
- common_element('ttl', NULL, '40');
-
- if (is_array($notice)) {
- foreach ($notice as $n) {
- $entry = $this->twitter_rss_entry_array($n);
- $this->show_twitter_rss_item($entry);
- }
- } else {
- while ($notice->fetch()) {
- $entry = $this->twitter_rss_entry_array($notice);
- $this->show_twitter_rss_item($entry);
- }
- }
-
- common_element_end('channel');
- $this->end_twitter_rss();
- }
-
- function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL, $suplink=NULL) {
-
- $this->init_document('atom');
-
- common_element('title', NULL, $title);
- common_element('id', NULL, $id);
- common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
- if (!is_null($suplink)) {
- # For FriendFeed's SUP protocol
- common_element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup',
- 'href' => $suplink,
- 'type' => 'application/json'));
- }
- common_element('subtitle', NULL, $subtitle);
-
- if (is_array($notice)) {
- foreach ($notice as $n) {
- $entry = $this->twitter_rss_entry_array($n);
- $this->show_twitter_atom_entry($entry);
- }
- } else {
- while ($notice->fetch()) {
- $entry = $this->twitter_rss_entry_array($notice);
- $this->show_twitter_atom_entry($entry);
- }
- }
-
- $this->end_document('atom');
-
- }
-
- function show_json_timeline($notice) {
-
- $this->init_document('json');
-
- $statuses = array();
-
- if (is_array($notice)) {
- foreach ($notice as $n) {
- $twitter_status = $this->twitter_status_array($n);
- array_push($statuses, $twitter_status);
- }
- } else {
- while ($notice->fetch()) {
- $twitter_status = $this->twitter_status_array($notice);
- array_push($statuses, $twitter_status);
- }
- }
-
- $this->show_json_objects($statuses);
-
- $this->end_document('json');
- }
-
- // Anyone know what date format this is?
- // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach
- function date_twitter($dt) {
- $t = strtotime($dt);
- return date("D M d G:i:s O Y", $t);
- }
-
- function replier_by_reply($reply_id) {
- $notice = Notice::staticGet($reply_id);
- if ($notice) {
- $profile = $notice->getProfile();
- if ($profile) {
- return intval($profile->id);
- } else {
- common_debug('Can\'t find a profile for notice: ' . $notice->id, __FILE__);
- }
- } else {
- common_debug("Can't get notice: $reply_id", __FILE__);
- }
- return NULL;
- }
-
- // XXX: Candidate for a general utility method somewhere?
- function count_subscriptions($profile) {
-
- $count = 0;
- $sub = new Subscription();
- $sub->subscribed = $profile->id;
-
- $count = $sub->find();
-
- if ($count > 0) {
- return $count - 1;
- } else {
- return 0;
- }
- }
-
- function init_document($type='xml') {
- switch ($type) {
- case 'xml':
- header('Content-Type: application/xml; charset=utf-8');
- common_start_xml();
- break;
- case 'json':
- header('Content-Type: application/json; charset=utf-8');
-
- // Check for JSONP callback
- $callback = $this->arg('callback');
- if ($callback) {
- print $callback . '(';
- }
- break;
- case 'rss':
- header("Content-Type: application/rss+xml; charset=utf-8");
- $this->init_twitter_rss();
- break;
- case 'atom':
- header('Content-Type: application/atom+xml; charset=utf-8');
- $this->init_twitter_atom();
- break;
- default:
- $this->client_error(_('Not a supported data format.'));
- break;
- }
-
- return;
- }
-
- function end_document($type='xml') {
- switch ($type) {
- case 'xml':
- common_end_xml();
- break;
- case 'json':
-
- // Check for JSONP callback
- $callback = $this->arg('callback');
- if ($callback) {
- print ')';
- }
- break;
- case 'rss':
- $this->end_twitter_rss();
- break;
- case 'atom':
- $this->end_twitter_rss();
- break;
- default:
- $this->client_error(_('Not a supported data format.'));
- break;
- }
- return;
- }
-
- function client_error($msg, $code = 400, $content_type = 'json') {
-
- static $status = array(400 => 'Bad Request',
- 401 => 'Unauthorized',
- 402 => 'Payment Required',
- 403 => 'Forbidden',
- 404 => 'Not Found',
- 405 => 'Method Not Allowed',
- 406 => 'Not Acceptable',
- 407 => 'Proxy Authentication Required',
- 408 => 'Request Timeout',
- 409 => 'Conflict',
- 410 => 'Gone',
- 411 => 'Length Required',
- 412 => 'Precondition Failed',
- 413 => 'Request Entity Too Large',
- 414 => 'Request-URI Too Long',
- 415 => 'Unsupported Media Type',
- 416 => 'Requested Range Not Satisfiable',
- 417 => 'Expectation Failed');
-
- $action = $this->trimmed('action');
-
- common_debug("User error '$code' on '$action': $msg", __FILE__);
-
- if (!array_key_exists($code, $status)) {
- $code = 400;
- }
-
- $status_string = $status[$code];
- header('HTTP/1.1 '.$code.' '.$status_string);
-
- if ($content_type == 'xml') {
- $this->init_document('xml');
- common_element_start('hash');
- common_element('error', NULL, $msg);
- common_element('request', NULL, $_SERVER['REQUEST_URI']);
- common_element_end('hash');
- $this->end_document('xml');
- } else {
- $this->init_document('json');
- $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
- print(json_encode($error_array));
- $this->end_document('json');
- }
-
- }
-
- function init_twitter_rss() {
- common_start_xml();
- common_element_start('rss', array('version' => '2.0'));
- }
-
- function end_twitter_rss() {
- common_element_end('rss');
- common_end_xml();
- }
-
- function init_twitter_atom() {
- common_start_xml();
- common_element_start('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US'));
- }
-
- function end_twitter_atom() {
- common_end_xml();
- common_element_end('feed');
- }
-
- function show_profile($profile, $content_type='xml', $notice=NULL) {
- $profile_array = $this->twitter_user_array($profile, true);
- switch ($content_type) {
- case 'xml':
- $this->show_twitter_xml_user($profile_array);
- break;
- case 'json':
- $this->show_json_objects($profile_array);
- break;
- default:
- $this->client_error(_('Not a supported data format.'));
- return;
- }
- return;
- }
-
- function get_user($id, $apidata=NULL) {
- if (!$id) {
- return $apidata['user'];
- } else if (is_numeric($id)) {
- return User::staticGet($id);
- } else {
- $nickname = common_canonical_nickname($id);
- return User::staticGet('nickname', $nickname);
- }
- }
-
- function get_profile($id) {
- if (is_numeric($id)) {
- return Profile::staticGet($id);
- } else {
- $user = User::staticGet('nickname', $id);
- if ($user) {
- return $user->getProfile();
- } else {
- return NULL;
- }
- }
- }
-
- function source_link($source) {
- $source_name = _($source);
- switch ($source) {
- case 'web':
- case 'xmpp':
- case 'mail':
- case 'omb':
- case 'api':
- break;
- default:
- $ns = Notice_source::staticGet($source);
- if ($ns) {
- $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>';
- }
- break;
- }
- return $source_name;
- }
-
- function show_extended_profile($user, $apidata) {
-
- $this->auth_user = $apidata['user'];
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $twitter_user = $this->twitter_user_array($profile, true);
-
- // Add in extended user fields offered up by this method
- $twitter_user['created_at'] = $this->date_twitter($profile->created);
-
- $subbed = DB_DataObject::factory('subscription');
- $subbed->subscriber = $profile->id;
- $subbed_count = (int) $subbed->count() - 1;
-
- $notices = DB_DataObject::factory('notice');
- $notices->profile_id = $profile->id;
- $notice_count = (int) $notices->count();
-
- $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0;
- $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0;
-
- // Other fields Twitter sends...
- $twitter_user['profile_background_color'] = '';
- $twitter_user['profile_text_color'] = '';
- $twitter_user['profile_link_color'] = '';
- $twitter_user['profile_sidebar_fill_color'] = '';
-
- $faves = DB_DataObject::factory('fave');
- $faves->user_id = $user->id;
- $faves_count = (int) $faves->count();
- $twitter_user['favourites_count'] = $faves_count;
-
- $timezone = 'UTC';
-
- if ($user->timezone) {
- $timezone = $user->timezone;
- }
-
- $t = new DateTime;
- $t->setTimezone(new DateTimeZone($timezone));
- $twitter_user['utc_offset'] = $t->format('Z');
- $twitter_user['time_zone'] = $timezone;
-
- $following = 'false';
-
- if (isset($this->auth_user)) {
- if ($this->auth_user->isSubscribed($profile)) {
- $following = 'true';
- }
-
- // Not implemented yet
- $twitter_user['notifications'] = 'false';
- }
-
- $twitter_user['following'] = $following;
-
- if ($apidata['content-type'] == 'xml') {
- $this->init_document('xml');
- $this->show_twitter_xml_user($twitter_user);
- $this->end_document('xml');
- } elseif ($apidata['content-type'] == 'json') {
- $this->init_document('json');
- $this->show_json_objects($twitter_user);
- $this->end_document('json');
- }
-
- }
+ $entry['content'] = common_xml_safe_str(trim($notice->rendered));
+ $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content));
+ $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
+ $entry['published'] = common_date_iso8601($notice->created);
+ $entry['id'] = "tag:$server,2008:$entry[link]";
+ $entry['updated'] = $entry['published'];
+
+ # RSS Item specific
+ $entry['description'] = $entry['content'];
+ $entry['pubDate'] = common_date_rfc2822($notice->created);
+ $entry['guid'] = $entry['link'];
+
+ return $entry;
+ }
+
+ function twitter_rss_dmsg_array($message) {
+
+ $server = common_config('site', 'server');
+ $entry = array();
+
+ $entry['title'] = sprintf('Message from %s to %s',
+ $message->getFrom()->nickname, $message->getTo()->nickname);
+
+ $entry['content'] = common_xml_safe_str(trim($message->content));
+ $entry['link'] = common_local_url('showmessage', array('message' => $message->id));
+ $entry['published'] = common_date_iso8601($message->created);
+ $entry['id'] = "tag:$server,2008:$entry[link]";
+ $entry['updated'] = $entry['published'];
+
+ # RSS Item specific
+ $entry['description'] = $entry['content'];
+ $entry['pubDate'] = common_date_rfc2822($message->created);
+ $entry['guid'] = $entry['link'];
+
+ return $entry;
+ }
+
+ function twitter_dmsg_array($message) {
+
+ $twitter_dm = array();
+
+ $from_profile = $message->getFrom();
+ $to_profile = $message->getTo();
+
+ $twitter_dm['id'] = $message->id;
+ $twitter_dm['sender_id'] = $message->from_profile;
+ $twitter_dm['text'] = trim($message->content);
+ $twitter_dm['recipient_id'] = $message->to_profile;
+ $twitter_dm['created_at'] = $this->date_twitter($message->created);
+ $twitter_dm['sender_screen_name'] = $from_profile->nickname;
+ $twitter_dm['recipient_screen_name'] = $to_profile->nickname;
+ $twitter_dm['sender'] = $this->twitter_user_array($from_profile, false);
+ $twitter_dm['recipient'] = $this->twitter_user_array($to_profile, false);
+
+ return $twitter_dm;
+ }
+
+ function show_twitter_xml_status($twitter_status) {
+ common_element_start('status');
+ foreach($twitter_status as $element => $value) {
+ switch ($element) {
+ case 'user':
+ $this->show_twitter_xml_user($twitter_status['user']);
+ break;
+ case 'text':
+ common_element($element, NULL, common_xml_safe_str($value));
+ break;
+ default:
+ common_element($element, NULL, $value);
+ }
+ }
+ common_element_end('status');
+ }
+
+ function show_twitter_xml_user($twitter_user, $role='user') {
+ common_element_start($role);
+ foreach($twitter_user as $element => $value) {
+ if ($element == 'status') {
+ $this->show_twitter_xml_status($twitter_user['status']);
+ } else {
+ common_element($element, NULL, $value);
+ }
+ }
+ common_element_end($role);
+ }
+
+ function show_twitter_rss_item($entry) {
+ common_element_start('item');
+ common_element('title', NULL, $entry['title']);
+ common_element('description', NULL, $entry['description']);
+ common_element('pubDate', NULL, $entry['pubDate']);
+ common_element('guid', NULL, $entry['guid']);
+ common_element('link', NULL, $entry['link']);
+ common_element_end('item');
+ }
+
+ function show_twitter_atom_entry($entry) {
+ common_element_start('entry');
+ common_element('title', NULL, $entry['title']);
+ common_element('content', array('type' => 'html'), $entry['content']);
+ common_element('id', NULL, $entry['id']);
+ common_element('published', NULL, $entry['published']);
+ common_element('updated', NULL, $entry['updated']);
+ common_element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ common_element_end('entry');
+ }
+
+ function show_json_objects($objects) {
+ print(json_encode($objects));
+ }
+
+ function show_single_xml_status($notice) {
+ $this->init_document('xml');
+ $twitter_status = $this->twitter_status_array($notice);
+ $this->show_twitter_xml_status($twitter_status);
+ $this->end_document('xml');
+ }
+
+ function show_single_json_status($notice) {
+ $this->init_document('json');
+ $status = $this->twitter_status_array($notice);
+ $this->show_json_objects($status);
+ $this->end_document('json');
+ }
+
+ function show_single_xml_dmsg($message) {
+ $this->init_document('xml');
+ $dmsg = $this->twitter_dmsg_array($message);
+ $this->show_twitter_xml_dmsg($dmsg);
+ $this->end_document('xml');
+ }
+
+ function show_single_json_dmsg($message) {
+ $this->init_document('json');
+ $dmsg = $this->twitter_dmsg_array($message);
+ $this->show_json_objects($dmsg);
+ $this->end_document('json');
+ }
+
+ function show_twitter_xml_dmsg($twitter_dm) {
+ common_element_start('direct_message');
+ foreach($twitter_dm as $element => $value) {
+ switch ($element) {
+ case 'sender':
+ case 'recipient':
+ $this->show_twitter_xml_user($value, $element);
+ break;
+ case 'text':
+ common_element($element, NULL, common_xml_safe_str($value));
+ break;
+ default:
+ common_element($element, NULL, $value);
+ }
+ }
+ common_element_end('direct_message');
+ }
+
+ function show_xml_timeline($notice) {
+
+ $this->init_document('xml');
+ common_element_start('statuses', array('type' => 'array'));
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $twitter_status = $this->twitter_status_array($n);
+ $this->show_twitter_xml_status($twitter_status);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $twitter_status = $this->twitter_status_array($notice);
+ $this->show_twitter_xml_status($twitter_status);
+ }
+ }
+
+ common_element_end('statuses');
+ $this->end_document('xml');
+ }
+
+ function show_rss_timeline($notice, $title, $link, $subtitle, $suplink=NULL) {
+
+ $this->init_document('rss');
+
+ common_element_start('channel');
+ common_element('title', NULL, $title);
+ common_element('link', NULL, $link);
+ if (!is_null($suplink)) {
+ # For FriendFeed's SUP protocol
+ common_element('link', array('xmlns' => 'http://www.w3.org/2005/Atom',
+ 'rel' => 'http://api.friendfeed.com/2008/03#sup',
+ 'href' => $suplink,
+ 'type' => 'application/json'));
+ }
+ common_element('description', NULL, $subtitle);
+ common_element('language', NULL, 'en-us');
+ common_element('ttl', NULL, '40');
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $entry = $this->twitter_rss_entry_array($n);
+ $this->show_twitter_rss_item($entry);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $entry = $this->twitter_rss_entry_array($notice);
+ $this->show_twitter_rss_item($entry);
+ }
+ }
+
+ common_element_end('channel');
+ $this->end_twitter_rss();
+ }
+
+ function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL, $suplink=NULL) {
+
+ $this->init_document('atom');
+
+ common_element('title', NULL, $title);
+ common_element('id', NULL, $id);
+ common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ if (!is_null($suplink)) {
+ # For FriendFeed's SUP protocol
+ common_element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup',
+ 'href' => $suplink,
+ 'type' => 'application/json'));
+ }
+ common_element('subtitle', NULL, $subtitle);
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $entry = $this->twitter_rss_entry_array($n);
+ $this->show_twitter_atom_entry($entry);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $entry = $this->twitter_rss_entry_array($notice);
+ $this->show_twitter_atom_entry($entry);
+ }
+ }
+
+ $this->end_document('atom');
+
+ }
+
+ function show_json_timeline($notice) {
+
+ $this->init_document('json');
+
+ $statuses = array();
+
+ if (is_array($notice)) {
+ foreach ($notice as $n) {
+ $twitter_status = $this->twitter_status_array($n);
+ array_push($statuses, $twitter_status);
+ }
+ } else {
+ while ($notice->fetch()) {
+ $twitter_status = $this->twitter_status_array($notice);
+ array_push($statuses, $twitter_status);
+ }
+ }
+
+ $this->show_json_objects($statuses);
+
+ $this->end_document('json');
+ }
+
+ // Anyone know what date format this is?
+ // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach
+ function date_twitter($dt) {
+ $t = strtotime($dt);
+ return date("D M d G:i:s O Y", $t);
+ }
+
+ function replier_by_reply($reply_id) {
+ $notice = Notice::staticGet($reply_id);
+ if ($notice) {
+ $profile = $notice->getProfile();
+ if ($profile) {
+ return intval($profile->id);
+ } else {
+ common_debug('Can\'t find a profile for notice: ' . $notice->id, __FILE__);
+ }
+ } else {
+ common_debug("Can't get notice: $reply_id", __FILE__);
+ }
+ return NULL;
+ }
+
+ // XXX: Candidate for a general utility method somewhere?
+ function count_subscriptions($profile) {
+
+ $count = 0;
+ $sub = new Subscription();
+ $sub->subscribed = $profile->id;
+
+ $count = $sub->find();
+
+ if ($count > 0) {
+ return $count - 1;
+ } else {
+ return 0;
+ }
+ }
+
+ function init_document($type='xml') {
+ switch ($type) {
+ case 'xml':
+ header('Content-Type: application/xml; charset=utf-8');
+ common_start_xml();
+ break;
+ case 'json':
+ header('Content-Type: application/json; charset=utf-8');
+
+ // Check for JSONP callback
+ $callback = $this->arg('callback');
+ if ($callback) {
+ print $callback . '(';
+ }
+ break;
+ case 'rss':
+ header("Content-Type: application/rss+xml; charset=utf-8");
+ $this->init_twitter_rss();
+ break;
+ case 'atom':
+ header('Content-Type: application/atom+xml; charset=utf-8');
+ $this->init_twitter_atom();
+ break;
+ default:
+ $this->client_error(_('Not a supported data format.'));
+ break;
+ }
+
+ return;
+ }
+
+ function end_document($type='xml') {
+ switch ($type) {
+ case 'xml':
+ common_end_xml();
+ break;
+ case 'json':
+
+ // Check for JSONP callback
+ $callback = $this->arg('callback');
+ if ($callback) {
+ print ')';
+ }
+ break;
+ case 'rss':
+ $this->end_twitter_rss();
+ break;
+ case 'atom':
+ $this->end_twitter_rss();
+ break;
+ default:
+ $this->client_error(_('Not a supported data format.'));
+ break;
+ }
+ return;
+ }
+
+ function client_error($msg, $code = 400, $content_type = 'json') {
+
+ static $status = array(400 => 'Bad Request',
+ 401 => 'Unauthorized',
+ 402 => 'Payment Required',
+ 403 => 'Forbidden',
+ 404 => 'Not Found',
+ 405 => 'Method Not Allowed',
+ 406 => 'Not Acceptable',
+ 407 => 'Proxy Authentication Required',
+ 408 => 'Request Timeout',
+ 409 => 'Conflict',
+ 410 => 'Gone',
+ 411 => 'Length Required',
+ 412 => 'Precondition Failed',
+ 413 => 'Request Entity Too Large',
+ 414 => 'Request-URI Too Long',
+ 415 => 'Unsupported Media Type',
+ 416 => 'Requested Range Not Satisfiable',
+ 417 => 'Expectation Failed');
+
+ $action = $this->trimmed('action');
+
+ common_debug("User error '$code' on '$action': $msg", __FILE__);
+
+ if (!array_key_exists($code, $status)) {
+ $code = 400;
+ }
+
+ $status_string = $status[$code];
+ header('HTTP/1.1 '.$code.' '.$status_string);
+
+ if ($content_type == 'xml') {
+ $this->init_document('xml');
+ common_element_start('hash');
+ common_element('error', NULL, $msg);
+ common_element('request', NULL, $_SERVER['REQUEST_URI']);
+ common_element_end('hash');
+ $this->end_document('xml');
+ } else {
+ $this->init_document('json');
+ $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
+ print(json_encode($error_array));
+ $this->end_document('json');
+ }
+
+ }
+
+ function init_twitter_rss() {
+ common_start_xml();
+ common_element_start('rss', array('version' => '2.0'));
+ }
+
+ function end_twitter_rss() {
+ common_element_end('rss');
+ common_end_xml();
+ }
+
+ function init_twitter_atom() {
+ common_start_xml();
+ common_element_start('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US'));
+ }
+
+ function end_twitter_atom() {
+ common_end_xml();
+ common_element_end('feed');
+ }
+
+ function show_profile($profile, $content_type='xml', $notice=NULL) {
+ $profile_array = $this->twitter_user_array($profile, true);
+ switch ($content_type) {
+ case 'xml':
+ $this->show_twitter_xml_user($profile_array);
+ break;
+ case 'json':
+ $this->show_json_objects($profile_array);
+ break;
+ default:
+ $this->client_error(_('Not a supported data format.'));
+ return;
+ }
+ return;
+ }
+
+ function get_user($id, $apidata=NULL) {
+ if (!$id) {
+ return $apidata['user'];
+ } else if (is_numeric($id)) {
+ return User::staticGet($id);
+ } else {
+ $nickname = common_canonical_nickname($id);
+ return User::staticGet('nickname', $nickname);
+ }
+ }
+
+ function get_profile($id) {
+ if (is_numeric($id)) {
+ return Profile::staticGet($id);
+ } else {
+ $user = User::staticGet('nickname', $id);
+ if ($user) {
+ return $user->getProfile();
+ } else {
+ return NULL;
+ }
+ }
+ }
+
+ function source_link($source) {
+ $source_name = _($source);
+ switch ($source) {
+ case 'web':
+ case 'xmpp':
+ case 'mail':
+ case 'omb':
+ case 'api':
+ break;
+ default:
+ $ns = Notice_source::staticGet($source);
+ if ($ns) {
+ $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>';
+ }
+ break;
+ }
+ return $source_name;
+ }
+
+ function show_extended_profile($user, $apidata) {
+
+ $this->auth_user = $apidata['user'];
+
+ $profile = $user->getProfile();
+
+ if (!$profile) {
+ common_server_error(_('User has no profile.'));
+ return;
+ }
+
+ $twitter_user = $this->twitter_user_array($profile, true);
+
+ // Add in extended user fields offered up by this method
+ $twitter_user['created_at'] = $this->date_twitter($profile->created);
+
+ $subbed = DB_DataObject::factory('subscription');
+ $subbed->subscriber = $profile->id;
+ $subbed_count = (int) $subbed->count() - 1;
+
+ $notices = DB_DataObject::factory('notice');
+ $notices->profile_id = $profile->id;
+ $notice_count = (int) $notices->count();
+
+ $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0;
+ $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0;
+
+ // Other fields Twitter sends...
+ $twitter_user['profile_background_color'] = '';
+ $twitter_user['profile_text_color'] = '';
+ $twitter_user['profile_link_color'] = '';
+ $twitter_user['profile_sidebar_fill_color'] = '';
+
+ $faves = DB_DataObject::factory('fave');
+ $faves->user_id = $user->id;
+ $faves_count = (int) $faves->count();
+ $twitter_user['favourites_count'] = $faves_count;
+
+ $timezone = 'UTC';
+
+ if ($user->timezone) {
+ $timezone = $user->timezone;
+ }
+
+ $t = new DateTime;
+ $t->setTimezone(new DateTimeZone($timezone));
+ $twitter_user['utc_offset'] = $t->format('Z');
+ $twitter_user['time_zone'] = $timezone;
+
+ $following = 'false';
+
+ if (isset($this->auth_user)) {
+ if ($this->auth_user->isSubscribed($profile)) {
+ $following = 'true';
+ }
+
+ // Not implemented yet
+ $twitter_user['notifications'] = 'false';
+ }
+
+ $twitter_user['following'] = $following;
+
+ if ($apidata['content-type'] == 'xml') {
+ $this->init_document('xml');
+ $this->show_twitter_xml_user($twitter_user);
+ $this->end_document('xml');
+ } elseif ($apidata['content-type'] == 'json') {
+ $this->init_document('json');
+ $this->show_json_objects($twitter_user);
+ $this->end_document('json');
+ }
+
+ }
} \ No newline at end of file
diff --git a/_darcs/pristine/lib/xmppqueuehandler.php b/_darcs/pristine/lib/xmppqueuehandler.php
index cfc9642e4..33b987291 100644
--- a/_darcs/pristine/lib/xmppqueuehandler.php
+++ b/_darcs/pristine/lib/xmppqueuehandler.php
@@ -29,63 +29,63 @@ require_once(INSTALLDIR.'/lib/queuehandler.php');
*/
class XmppQueueHandler extends QueueHandler {
-
- function start() {
- # Low priority; we don't want to receive messages
- $this->log(LOG_INFO, "INITIALIZE");
- $this->conn = jabber_connect($this->_id);
- if ($this->conn) {
- $this->conn->addEventHandler('message', 'forward_message', $this);
- $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
- $this->conn->setReconnectTimeout(600);
- jabber_send_presence("Send me a message to post a notice", 'available', NULL, 'available', -1);
- }
- return !is_null($this->conn);
- }
-
- function handle_reconnect(&$pl) {
- $this->conn->processUntil('session_start');
- $this->conn->presence(NULL, 'available', NULL, 'available', -1);
- }
+
+ function start() {
+ # Low priority; we don't want to receive messages
+ $this->log(LOG_INFO, "INITIALIZE");
+ $this->conn = jabber_connect($this->_id);
+ if ($this->conn) {
+ $this->conn->addEventHandler('message', 'forward_message', $this);
+ $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
+ $this->conn->setReconnectTimeout(600);
+ jabber_send_presence("Send me a message to post a notice", 'available', NULL, 'available', -1);
+ }
+ return !is_null($this->conn);
+ }
+
+ function handle_reconnect(&$pl) {
+ $this->conn->processUntil('session_start');
+ $this->conn->presence(NULL, 'available', NULL, 'available', -1);
+ }
- function idle($timeout=0) {
- # Process the queue for as long as needed
- try {
- if ($this->conn) {
- $this->conn->processTime($timeout);
- }
- } catch (XMPPHP_Exception $e) {
- $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
- die($e->getMessage());
- }
- }
-
- function forward_message(&$pl) {
- if ($pl['type'] != 'chat') {
- $this->log(LOG_DEBUG, 'Ignoring message of type ' . $pl['type'] . ' from ' . $pl['from']);
- return;
- }
- $listener = $this->listener();
- if (strtolower($listener) == strtolower($pl['from'])) {
- $this->log(LOG_WARNING, 'Ignoring loop message.');
- return;
- }
- $this->log(LOG_INFO, 'Forwarding message from ' . $pl['from'] . ' to ' . $listener);
- $this->conn->message($this->listener(), $pl['body'], 'chat', NULL, $this->ofrom($pl['from']));
- }
+ function idle($timeout=0) {
+ # Process the queue for as long as needed
+ try {
+ if ($this->conn) {
+ $this->conn->processTime($timeout);
+ }
+ } catch (XMPPHP_Exception $e) {
+ $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
+ die($e->getMessage());
+ }
+ }
+
+ function forward_message(&$pl) {
+ if ($pl['type'] != 'chat') {
+ $this->log(LOG_DEBUG, 'Ignoring message of type ' . $pl['type'] . ' from ' . $pl['from']);
+ return;
+ }
+ $listener = $this->listener();
+ if (strtolower($listener) == strtolower($pl['from'])) {
+ $this->log(LOG_WARNING, 'Ignoring loop message.');
+ return;
+ }
+ $this->log(LOG_INFO, 'Forwarding message from ' . $pl['from'] . ' to ' . $listener);
+ $this->conn->message($this->listener(), $pl['body'], 'chat', NULL, $this->ofrom($pl['from']));
+ }
- function ofrom($from) {
- $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
- $address .= "<address type='ofrom' jid='$from' />\n";
- $address .= "</addresses>\n";
- return $address;
- }
+ function ofrom($from) {
+ $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
+ $address .= "<address type='ofrom' jid='$from' />\n";
+ $address .= "</addresses>\n";
+ return $address;
+ }
- function listener() {
- if (common_config('xmpp', 'listener')) {
- return common_config('xmpp', 'listener');
- } else {
- return jabber_daemon_address() . '/' . common_config('xmpp','resource') . '-listener';
- }
- }
+ function listener() {
+ if (common_config('xmpp', 'listener')) {
+ return common_config('xmpp', 'listener');
+ } else {
+ return jabber_daemon_address() . '/' . common_config('xmpp','resource') . '-listener';
+ }
+ }
}
diff --git a/_darcs/pristine/scripts/enjitqueuehandler.php b/_darcs/pristine/scripts/enjitqueuehandler.php
index 8538ae09a..cfb253753 100644
--- a/_darcs/pristine/scripts/enjitqueuehandler.php
+++ b/_darcs/pristine/scripts/enjitqueuehandler.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -34,20 +34,20 @@ require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler');
class EnjitQueueHandler extends QueueHandler {
-
- function transport() {
- return 'enjit';
- }
+
+ function transport() {
+ return 'enjit';
+ }
- function start() {
+ function start() {
$this->log(LOG_INFO, "Starting EnjitQueueHandler");
$this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl'));
- return true;
- }
+ return true;
+ }
- function handle_notice($notice) {
+ function handle_notice($notice) {
- $profile = Profile::staticGet($notice->profile_id);
+ $profile = Profile::staticGet($notice->profile_id);
$this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname);
@@ -60,25 +60,25 @@ class EnjitQueueHandler extends QueueHandler {
#
# Build an Atom message from the notice
#
- $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
- $msg = $profile->nickname . ': ' . $notice->content;
-
- $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
- $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n";
- $atom .= "<source>\n";
- $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
- $atom .= "<link href='" . $profile->profileurl . "'/>\n";
- $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
- $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
- $atom .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n";
- $atom .= "</source>\n";
- $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
- $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
- $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
- $atom .= "<id>". $notice->uri . "</id>\n";
- $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
- $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
- $atom .= "</entry>\n";
+ $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
+ $msg = $profile->nickname . ': ' . $notice->content;
+
+ $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
+ $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n";
+ $atom .= "<source>\n";
+ $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
+ $atom .= "<link href='" . $profile->profileurl . "'/>\n";
+ $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
+ $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
+ $atom .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n";
+ $atom .= "</source>\n";
+ $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
+ $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
+ $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
+ $atom .= "<id>". $notice->uri . "</id>\n";
+ $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
+ $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
+ $atom .= "</entry>\n";
$url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey');
$data = "msg=$atom";
@@ -86,32 +86,32 @@ class EnjitQueueHandler extends QueueHandler {
#
# POST the message to $config['enjit']['apiurl']
#
- $ch = curl_init();
+ $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1) ;
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_POST, 1) ;
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
# SSL and Debugging options
#
- # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+ # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+ # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
# curl_setopt($ch, CURLOPT_VERBOSE, 1);
- $result = curl_exec($ch);
+ $result = curl_exec($ch);
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE );
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE );
$this->log(LOG_INFO, "Response Code: $code");
- curl_close($ch);
+ curl_close($ch);
return $code;
- }
-
+ }
+
}
@@ -122,7 +122,7 @@ $id = ($argc > 1) ? $argv[1] : NULL;
$handler = new EnjitQueueHandler($id);
if ($handler->start()) {
- $handler->handle_queue();
+ $handler->handle_queue();
}
$handler->finish();
diff --git a/_darcs/pristine/scripts/fixup_hashtags.php b/_darcs/pristine/scripts/fixup_hashtags.php
index 88f385798..6f65c78a1 100644
--- a/_darcs/pristine/scripts/fixup_hashtags.php
+++ b/_darcs/pristine/scripts/fixup_hashtags.php
@@ -37,10 +37,10 @@ $cnt = $notice->find();
while ($notice->fetch()) {
common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id);
$notice->saveTags();
- $original = clone($notice);
- $notice->rendered = common_render_content($notice->content, $notice);
- $result = $notice->update($original);
- if (!$result) {
- common_log_db_error($notice, 'UPDATE', __FILE__);
- }
+ $original = clone($notice);
+ $notice->rendered = common_render_content($notice->content, $notice);
+ $result = $notice->update($original);
+ if (!$result) {
+ common_log_db_error($notice, 'UPDATE', __FILE__);
+ }
}
diff --git a/_darcs/pristine/scripts/fixup_inboxes.php b/_darcs/pristine/scripts/fixup_inboxes.php
index 1715b0bc1..e631a80ed 100644
--- a/_darcs/pristine/scripts/fixup_inboxes.php
+++ b/_darcs/pristine/scripts/fixup_inboxes.php
@@ -41,7 +41,7 @@ common_log(LOG_INFO, 'Updating user inboxes.');
$user = new User();
if ($start_at) {
- $user->whereAdd('id >= ' . $start_at);
+ $user->whereAdd('id >= ' . $start_at);
}
$cnt = $user->find();
@@ -49,32 +49,32 @@ $cache = common_memcache();
while ($user->fetch()) {
common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
- $user->query('BEGIN');
- $inbox = new Notice_inbox();
- $result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' .
- 'SELECT ' . $user->id . ', notice.id, notice.created ' .
- 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' .
- 'WHERE subscription.subscriber = ' . $user->id . ' ' .
- 'AND notice.created >= subscription.created ' .
- 'AND NOT EXISTS (SELECT user_id, notice_id ' .
- 'FROM notice_inbox ' .
- 'WHERE user_id = ' . $user->id . ' ' .
- 'AND notice_id = notice.id)');
- if (is_null($result) || $result === false) {
- common_log_db_error($inbox, 'INSERT', __FILE__);
- continue;
- }
- $orig = clone($user);
- $user->inboxed = 1;
- $result = $user->update($orig);
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- continue;
- }
- $user->query('COMMIT');
- $inbox->free();
- unset($inbox);
- if ($cache) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
- }
+ $user->query('BEGIN');
+ $inbox = new Notice_inbox();
+ $result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' .
+ 'SELECT ' . $user->id . ', notice.id, notice.created ' .
+ 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' .
+ 'WHERE subscription.subscriber = ' . $user->id . ' ' .
+ 'AND notice.created >= subscription.created ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ 'WHERE user_id = ' . $user->id . ' ' .
+ 'AND notice_id = notice.id)');
+ if (is_null($result) || $result === false) {
+ common_log_db_error($inbox, 'INSERT', __FILE__);
+ continue;
+ }
+ $orig = clone($user);
+ $user->inboxed = 1;
+ $result = $user->update($orig);
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ continue;
+ }
+ $user->query('COMMIT');
+ $inbox->free();
+ unset($inbox);
+ if ($cache) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
+ }
}
diff --git a/_darcs/pristine/scripts/fixup_notices_rendered.php b/_darcs/pristine/scripts/fixup_notices_rendered.php
index c6c925729..1fa9f394e 100644
--- a/_darcs/pristine/scripts/fixup_notices_rendered.php
+++ b/_darcs/pristine/scripts/fixup_notices_rendered.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -35,16 +35,16 @@ $start_at = ($argc > 1) ? $argv[1] : NULL;
$notice = new Notice();
if ($start_at) {
- $notice->whereAdd('id >= ' . $start_at);
+ $notice->whereAdd('id >= ' . $start_at);
}
$cnt = $notice->find();
while ($notice->fetch()) {
- common_log(LOG_INFO, 'Pre-rendering notice #' . $notice->id);
- $original = clone($notice);
- $notice->rendered = common_render_content($notice->content, $notice);
- $result = $notice->update($original);
- if (!$result) {
- common_log_db_error($notice, 'UPDATE', __FILE__);
- }
+ common_log(LOG_INFO, 'Pre-rendering notice #' . $notice->id);
+ $original = clone($notice);
+ $notice->rendered = common_render_content($notice->content, $notice);
+ $result = $notice->update($original);
+ if (!$result) {
+ common_log_db_error($notice, 'UPDATE', __FILE__);
+ }
}
diff --git a/_darcs/pristine/scripts/getpiddir.php b/_darcs/pristine/scripts/getpiddir.php
index b4dda2254..4f5704249 100644
--- a/_darcs/pristine/scripts/getpiddir.php
+++ b/_darcs/pristine/scripts/getpiddir.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
diff --git a/_darcs/pristine/scripts/inbox_users.php b/_darcs/pristine/scripts/inbox_users.php
index 0543abb2a..f907e1584 100644
--- a/_darcs/pristine/scripts/inbox_users.php
+++ b/_darcs/pristine/scripts/inbox_users.php
@@ -42,68 +42,68 @@ common_log(LOG_INFO, 'Updating user inboxes.');
$ids = file($id_file);
foreach ($ids as $id) {
-
- $user = User::staticGet('id', $id);
+
+ $user = User::staticGet('id', $id);
- if (!$user) {
- common_log(LOG_WARNING, 'No such user: ' . $id);
- continue;
- }
-
- if ($user->inboxed) {
- common_log(LOG_WARNING, 'Already inboxed: ' . $id);
- continue;
- }
-
+ if (!$user) {
+ common_log(LOG_WARNING, 'No such user: ' . $id);
+ continue;
+ }
+
+ if ($user->inboxed) {
+ common_log(LOG_WARNING, 'Already inboxed: ' . $id);
+ continue;
+ }
+
common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
-
- $user->query('BEGIN');
-
- $old_inbox = new Notice_inbox();
- $old_inbox->user_id = $user->id;
-
- $result = $old_inbox->delete();
-
- if (is_null($result) || $result === false) {
- common_log_db_error($old_inbox, 'DELETE', __FILE__);
- continue;
- }
+
+ $user->query('BEGIN');
+
+ $old_inbox = new Notice_inbox();
+ $old_inbox->user_id = $user->id;
+
+ $result = $old_inbox->delete();
+
+ if (is_null($result) || $result === false) {
+ common_log_db_error($old_inbox, 'DELETE', __FILE__);
+ continue;
+ }
- $old_inbox->free();
-
- $inbox = new Notice_inbox();
-
- $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' .
- 'SELECT ' . $user->id . ', notice.id, notice.created ' .
- 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' .
- 'WHERE subscription.subscriber = ' . $user->id . ' ' .
- 'AND notice.created >= subscription.created ' .
- 'AND now() - notice.created < ' . (7 * 24 * 3600) . ' ' .
- 'AND NOT EXISTS (SELECT user_id, notice_id ' .
- 'FROM notice_inbox ' .
- 'WHERE user_id = ' . $user->id . ' ' .
- 'AND notice_id = notice.id)');
-
- if (is_null($result) || $result === false) {
- common_log_db_error($inbox, 'INSERT', __FILE__);
- continue;
- }
-
- $orig = clone($user);
- $user->inboxed = 1;
- $result = $user->update($orig);
-
- if (!$result) {
- common_log_db_error($user, 'UPDATE', __FILE__);
- continue;
- }
-
- $user->query('COMMIT');
-
- $inbox->free();
- unset($inbox);
-
- if ($cache) {
- $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
- }
+ $old_inbox->free();
+
+ $inbox = new Notice_inbox();
+
+ $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' .
+ 'SELECT ' . $user->id . ', notice.id, notice.created ' .
+ 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' .
+ 'WHERE subscription.subscriber = ' . $user->id . ' ' .
+ 'AND notice.created >= subscription.created ' .
+ 'AND now() - notice.created < ' . (7 * 24 * 3600) . ' ' .
+ 'AND NOT EXISTS (SELECT user_id, notice_id ' .
+ 'FROM notice_inbox ' .
+ 'WHERE user_id = ' . $user->id . ' ' .
+ 'AND notice_id = notice.id)');
+
+ if (is_null($result) || $result === false) {
+ common_log_db_error($inbox, 'INSERT', __FILE__);
+ continue;
+ }
+
+ $orig = clone($user);
+ $user->inboxed = 1;
+ $result = $user->update($orig);
+
+ if (!$result) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ continue;
+ }
+
+ $user->query('COMMIT');
+
+ $inbox->free();
+ unset($inbox);
+
+ if ($cache) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
+ }
}
diff --git a/_darcs/pristine/scripts/jabberqueuehandler.php b/_darcs/pristine/scripts/jabberqueuehandler.php
index 59cdb94ad..8e33cfaf0 100644
--- a/_darcs/pristine/scripts/jabberqueuehandler.php
+++ b/_darcs/pristine/scripts/jabberqueuehandler.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -35,20 +35,20 @@ set_error_handler('common_error_handler');
class JabberQueueHandler extends XmppQueueHandler {
- var $conn = NULL;
+ var $conn = NULL;
- function transport() {
- return 'jabber';
- }
+ function transport() {
+ return 'jabber';
+ }
- function handle_notice($notice) {
- try {
- return jabber_broadcast_notice($notice);
- } catch (XMPPHP_Exception $e) {
- $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
- exit(1);
- }
- }
+ function handle_notice($notice) {
+ try {
+ return jabber_broadcast_notice($notice);
+ } catch (XMPPHP_Exception $e) {
+ $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
+ exit(1);
+ }
+ }
}
ini_set("max_execution_time", "0");
diff --git a/_darcs/pristine/scripts/maildaemon.php b/_darcs/pristine/scripts/maildaemon.php
index 8b809f646..6d8507514 100644
--- a/_darcs/pristine/scripts/maildaemon.php
+++ b/_darcs/pristine/scripts/maildaemon.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -36,179 +36,179 @@ require_once('Mail/mimeDecode.php');
class MailerDaemon {
- function __construct() {
- }
-
- function handle_message($fname='php://stdin') {
- list($from, $to, $msg) = $this->parse_message($fname);
- if (!$from || !$to || !$msg) {
- $this->error(NULL, _('Could not parse message.'));
- }
- common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20));
- $user = $this->user_from($from);
- if (!$user) {
- $this->error($from, _('Not a registered user.'));
- return false;
- }
- if (!$this->user_match_to($user, $to)) {
- $this->error($from, _('Sorry, that is not your incoming email address.'));
- return false;
- }
- if (!$user->emailpost) {
- $this->error($from, _('Sorry, no incoming email allowed.'));
- return false;
- }
- $response = $this->handle_command($user, $from, $msg);
- if ($response) {
- return true;
- }
- $msg = $this->cleanup_msg($msg);
- $this->add_notice($user, $msg);
- }
-
- function error($from, $msg) {
- file_put_contents("php://stderr", $msg . "\n");
- exit(1);
- }
-
- function user_from($from_hdr) {
- $froms = mailparse_rfc822_parse_addresses($from_hdr);
- if (!$froms) {
- return NULL;
- }
- $from = $froms[0];
- $addr = common_canonical_email($from['address']);
- $user = User::staticGet('email', $addr);
- if (!$user) {
- $user = User::staticGet('smsemail', $addr);
- }
- return $user;
- }
-
- function user_match_to($user, $to_hdr) {
- $incoming = $user->incomingemail;
- $tos = mailparse_rfc822_parse_addresses($to_hdr);
- foreach ($tos as $to) {
- if (strcasecmp($incoming, $to['address']) == 0) {
- return true;
- }
- }
- return false;
- }
-
- function handle_command($user, $from, $msg) {
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $msg);
- if ($cmd) {
- $cmd->execute(new MailChannel($from));
- return true;
- }
- return false;
- }
-
- function respond($from, $to, $response) {
-
- $headers['From'] = $to;
- $headers['To'] = $from;
- $headers['Subject'] = "Command complete";
-
- return mail_send(array($from), $headers, $response);
- }
-
- function log($level, $msg) {
- common_log($level, 'MailDaemon: '.$msg);
- }
-
- function add_notice($user, $msg) {
+ function __construct() {
+ }
+
+ function handle_message($fname='php://stdin') {
+ list($from, $to, $msg) = $this->parse_message($fname);
+ if (!$from || !$to || !$msg) {
+ $this->error(NULL, _('Could not parse message.'));
+ }
+ common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20));
+ $user = $this->user_from($from);
+ if (!$user) {
+ $this->error($from, _('Not a registered user.'));
+ return false;
+ }
+ if (!$this->user_match_to($user, $to)) {
+ $this->error($from, _('Sorry, that is not your incoming email address.'));
+ return false;
+ }
+ if (!$user->emailpost) {
+ $this->error($from, _('Sorry, no incoming email allowed.'));
+ return false;
+ }
+ $response = $this->handle_command($user, $from, $msg);
+ if ($response) {
+ return true;
+ }
+ $msg = $this->cleanup_msg($msg);
+ $this->add_notice($user, $msg);
+ }
+
+ function error($from, $msg) {
+ file_put_contents("php://stderr", $msg . "\n");
+ exit(1);
+ }
+
+ function user_from($from_hdr) {
+ $froms = mailparse_rfc822_parse_addresses($from_hdr);
+ if (!$froms) {
+ return NULL;
+ }
+ $from = $froms[0];
+ $addr = common_canonical_email($from['address']);
+ $user = User::staticGet('email', $addr);
+ if (!$user) {
+ $user = User::staticGet('smsemail', $addr);
+ }
+ return $user;
+ }
+
+ function user_match_to($user, $to_hdr) {
+ $incoming = $user->incomingemail;
+ $tos = mailparse_rfc822_parse_addresses($to_hdr);
+ foreach ($tos as $to) {
+ if (strcasecmp($incoming, $to['address']) == 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function handle_command($user, $from, $msg) {
+ $inter = new CommandInterpreter();
+ $cmd = $inter->handle_command($user, $msg);
+ if ($cmd) {
+ $cmd->execute(new MailChannel($from));
+ return true;
+ }
+ return false;
+ }
+
+ function respond($from, $to, $response) {
+
+ $headers['From'] = $to;
+ $headers['To'] = $from;
+ $headers['Subject'] = "Command complete";
+
+ return mail_send(array($from), $headers, $response);
+ }
+
+ function log($level, $msg) {
+ common_log($level, 'MailDaemon: '.$msg);
+ }
+
+ function add_notice($user, $msg) {
// should test
// $msg_shortened = common_shorten_links($msg);
// if (mb_strlen($msg_shortened) > 140) ERROR and STOP
- $notice = Notice::saveNew($user->id, $msg, 'mail');
- if (is_string($notice)) {
- $this->log(LOG_ERR, $notice);
- return;
- }
- common_broadcast_notice($notice);
- $this->log(LOG_INFO,
- 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
- }
-
- function parse_message($fname) {
- $contents = file_get_contents($fname);
- $parsed = Mail_mimeDecode::decode(array('input' => $contents,
- 'include_bodies' => true,
- 'decode_headers' => true,
- 'decode_bodies' => true));
- if (!$parsed) {
- return NULL;
- }
-
- $from = $parsed->headers['from'];
-
- $to = $parsed->headers['to'];
-
- $type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary;
-
- if ($parsed->ctype_primary == 'multipart') {
- foreach ($parsed->parts as $part) {
- if ($part->ctype_primary == 'text' &&
- $part->ctype_secondary == 'plain') {
- $msg = $part->body;
- break;
- }
- }
- } else if ($type == 'text/plain') {
- $msg = $parsed->body;
- } else {
- $this->unsupported_type($type);
- }
-
- return array($from, $to, $msg);
- }
-
- function unsupported_type($type) {
- $this->error(NULL, "Unsupported message type: " . $type);
- }
-
- function cleanup_msg($msg) {
- $lines = explode("\n", $msg);
-
- $output = '';
-
- foreach ($lines as $line) {
- // skip quotes
- if (preg_match('/^\s*>.*$/', $line)) {
- continue;
- }
- // skip start of quote
- if (preg_match('/^\s*On.*wrote:\s*$/', $line)) {
- continue;
- }
- // probably interesting to someone, not us
- if (preg_match('/^\s*Sent via/', $line)) {
- continue;
- }
- // skip everything after a sig
- if (preg_match('/^\s*--+\s*$/', $line) ||
- preg_match('/^\s*__+\s*$/', $line))
- {
- break;
- }
- // skip everything after Outlook quote
- if (preg_match('/^\s*-+\s*Original Message\s*-+\s*$/', $line)) {
- break;
- }
- // skip everything after weird forward
- if (preg_match('/^\s*Begin\s+forward/', $line)) {
- break;
- }
-
- $output .= ' ' . $line;
- }
-
- preg_replace('/\s+/', ' ', $output);
- return trim($output);
- }
+ $notice = Notice::saveNew($user->id, $msg, 'mail');
+ if (is_string($notice)) {
+ $this->log(LOG_ERR, $notice);
+ return;
+ }
+ common_broadcast_notice($notice);
+ $this->log(LOG_INFO,
+ 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
+ }
+
+ function parse_message($fname) {
+ $contents = file_get_contents($fname);
+ $parsed = Mail_mimeDecode::decode(array('input' => $contents,
+ 'include_bodies' => true,
+ 'decode_headers' => true,
+ 'decode_bodies' => true));
+ if (!$parsed) {
+ return NULL;
+ }
+
+ $from = $parsed->headers['from'];
+
+ $to = $parsed->headers['to'];
+
+ $type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary;
+
+ if ($parsed->ctype_primary == 'multipart') {
+ foreach ($parsed->parts as $part) {
+ if ($part->ctype_primary == 'text' &&
+ $part->ctype_secondary == 'plain') {
+ $msg = $part->body;
+ break;
+ }
+ }
+ } else if ($type == 'text/plain') {
+ $msg = $parsed->body;
+ } else {
+ $this->unsupported_type($type);
+ }
+
+ return array($from, $to, $msg);
+ }
+
+ function unsupported_type($type) {
+ $this->error(NULL, "Unsupported message type: " . $type);
+ }
+
+ function cleanup_msg($msg) {
+ $lines = explode("\n", $msg);
+
+ $output = '';
+
+ foreach ($lines as $line) {
+ // skip quotes
+ if (preg_match('/^\s*>.*$/', $line)) {
+ continue;
+ }
+ // skip start of quote
+ if (preg_match('/^\s*On.*wrote:\s*$/', $line)) {
+ continue;
+ }
+ // probably interesting to someone, not us
+ if (preg_match('/^\s*Sent via/', $line)) {
+ continue;
+ }
+ // skip everything after a sig
+ if (preg_match('/^\s*--+\s*$/', $line) ||
+ preg_match('/^\s*__+\s*$/', $line))
+ {
+ break;
+ }
+ // skip everything after Outlook quote
+ if (preg_match('/^\s*-+\s*Original Message\s*-+\s*$/', $line)) {
+ break;
+ }
+ // skip everything after weird forward
+ if (preg_match('/^\s*Begin\s+forward/', $line)) {
+ break;
+ }
+
+ $output .= ' ' . $line;
+ }
+
+ preg_replace('/\s+/', ' ', $output);
+ return trim($output);
+ }
}
$md = new MailerDaemon();
diff --git a/_darcs/pristine/scripts/ombqueuehandler.php b/_darcs/pristine/scripts/ombqueuehandler.php
index 1df816d14..31ae20f00 100644
--- a/_darcs/pristine/scripts/ombqueuehandler.php
+++ b/_darcs/pristine/scripts/ombqueuehandler.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -34,32 +34,32 @@ require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler');
class OmbQueueHandler extends QueueHandler {
-
- function transport() {
- return 'omb';
- }
-
- function start() {
- $this->log(LOG_INFO, "INITIALIZE");
- return true;
- }
+
+ function transport() {
+ return 'omb';
+ }
+
+ function start() {
+ $this->log(LOG_INFO, "INITIALIZE");
+ return true;
+ }
- function handle_notice($notice) {
- if ($this->is_remote($notice)) {
- $this->log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id);
- return true;
- } else {
- return omb_broadcast_remote_subscribers($notice);
- }
- }
-
- function finish() {
- }
+ function handle_notice($notice) {
+ if ($this->is_remote($notice)) {
+ $this->log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id);
+ return true;
+ } else {
+ return omb_broadcast_remote_subscribers($notice);
+ }
+ }
+
+ function finish() {
+ }
- function is_remote($notice) {
- $user = User::staticGet($notice->profile_id);
- return is_null($user);
- }
+ function is_remote($notice) {
+ $user = User::staticGet($notice->profile_id);
+ return is_null($user);
+ }
}
ini_set("max_execution_time", "0");
diff --git a/_darcs/pristine/scripts/publicqueuehandler.php b/_darcs/pristine/scripts/publicqueuehandler.php
index b1ae1d581..2168aade2 100644
--- a/_darcs/pristine/scripts/publicqueuehandler.php
+++ b/_darcs/pristine/scripts/publicqueuehandler.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -34,19 +34,19 @@ require_once(INSTALLDIR . '/lib/xmppqueuehandler.php');
set_error_handler('common_error_handler');
class PublicQueueHandler extends XmppQueueHandler {
-
- function transport() {
- return 'public';
- }
-
- function handle_notice($notice) {
- try {
- return jabber_public_notice($notice);
- } catch (XMPPHP_Exception $e) {
- $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
- die($e->getMessage());
- }
- }
+
+ function transport() {
+ return 'public';
+ }
+
+ function handle_notice($notice) {
+ try {
+ return jabber_public_notice($notice);
+ } catch (XMPPHP_Exception $e) {
+ $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage());
+ die($e->getMessage());
+ }
+ }
}
ini_set("max_execution_time", "0");
diff --git a/_darcs/pristine/scripts/sitemap.php b/_darcs/pristine/scripts/sitemap.php
index 6b845beae..b49bfe2a5 100644
--- a/_darcs/pristine/scripts/sitemap.php
+++ b/_darcs/pristine/scripts/sitemap.php
@@ -19,188 +19,188 @@ index_map();
# Generate index sitemap of all other sitemaps.
function index_map() {
- global $output_paths;
- $output_dir = $output_paths['output_dir'];
- $output_url = $output_paths['output_url'];
+ global $output_paths;
+ $output_dir = $output_paths['output_dir'];
+ $output_url = $output_paths['output_url'];
- foreach (glob("$output_dir*.xml") as $file_name) {
+ foreach (glob("$output_dir*.xml") as $file_name) {
- # Just the file name please.
- $file_name = preg_replace("|$output_dir|", '', $file_name);
+ # Just the file name please.
+ $file_name = preg_replace("|$output_dir|", '', $file_name);
- $index_urls .= sitemap(
- array(
- 'url' => $output_url . $file_name,
- 'changefreq' => 'daily'
- )
- );
- }
+ $index_urls .= sitemap(
+ array(
+ 'url' => $output_url . $file_name,
+ 'changefreq' => 'daily'
+ )
+ );
+ }
- write_file($output_paths['index_file'], sitemapindex($index_urls));
+ write_file($output_paths['index_file'], sitemapindex($index_urls));
}
# Generate sitemap of standard site elements.
function standard_map() {
- global $output_paths;
-
- $standard_map_urls .= url(
- array(
- 'url' => common_local_url('public'),
- 'changefreq' => 'daily',
- 'priority' => '1',
- )
- );
-
- $standard_map_urls .= url(
- array(
- 'url' => common_local_url('publicrss'),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- )
- );
-
- $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source');
-
- foreach($docs as $title) {
- $standard_map_urls .= url(
- array(
- 'url' => common_local_url('doc', array('title' => $title)),
- 'changefreq' => 'monthly',
- 'priority' => '0.2',
- )
- );
- }
-
- $urlset_path = $output_paths['output_dir'] . 'standard.xml';
-
- write_file($urlset_path, urlset($standard_map_urls));
+ global $output_paths;
+
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('public'),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ )
+ );
+
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('publicrss'),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ )
+ );
+
+ $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source');
+
+ foreach($docs as $title) {
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('doc', array('title' => $title)),
+ 'changefreq' => 'monthly',
+ 'priority' => '0.2',
+ )
+ );
+ }
+
+ $urlset_path = $output_paths['output_dir'] . 'standard.xml';
+
+ write_file($urlset_path, urlset($standard_map_urls));
}
# Generate sitemaps of all notices.
function notices_map() {
- global $output_paths;
+ global $output_paths;
- $notices = DB_DataObject::factory('notice');
+ $notices = DB_DataObject::factory('notice');
- $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1');
+ $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1');
- $notice_count = 0;
- $map_count = 1;
+ $notice_count = 0;
+ $map_count = 1;
- while ($notices->fetch()) {
+ while ($notices->fetch()) {
- # Maximum 50,000 URLs per sitemap file.
- if ($notice_count == 50000) {
- $notice_count = 0;
- $map_count++;
- }
+ # Maximum 50,000 URLs per sitemap file.
+ if ($notice_count == 50000) {
+ $notice_count = 0;
+ $map_count++;
+ }
- # remote notices have an URL
-
- if (!$notices->url && $notices->uri) {
- $notice = array(
- 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)),
- 'lastmod' => common_date_w3dtf($notices->modified),
- 'changefreq' => 'never',
- 'priority' => '1',
- );
+ # remote notices have an URL
+
+ if (!$notices->url && $notices->uri) {
+ $notice = array(
+ 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)),
+ 'lastmod' => common_date_w3dtf($notices->modified),
+ 'changefreq' => 'never',
+ 'priority' => '1',
+ );
- $notice_list[$map_count] .= url($notice);
- $notice_count++;
- }
- }
+ $notice_list[$map_count] .= url($notice);
+ $notice_count++;
+ }
+ }
- # Make full sitemaps from the lists and save them.
- array_to_map($notice_list, 'notice');
+ # Make full sitemaps from the lists and save them.
+ array_to_map($notice_list, 'notice');
}
# Generate sitemaps of all users.
function user_map() {
- global $output_paths;
-
- $users = DB_DataObject::factory('user');
-
- $users->query('SELECT id, nickname FROM user');
-
- $user_count = 0;
- $map_count = 1;
-
- while ($users->fetch()) {
-
- # Maximum 50,000 URLs per sitemap file.
- if ($user_count == 50000) {
- $user_count = 0;
- $map_count++;
- }
-
- $user_args = array('nickname' => $users->nickname);
-
- # Define parameters for generating <url></url> elements.
- $user = array(
- 'url' => common_local_url('showstream', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '1',
- );
-
- $user_rss = array(
- 'url' => common_local_url('userrss', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- );
-
- $all = array(
- 'url' => common_local_url('all', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '1',
- );
-
- $all_rss = array(
- 'url' => common_local_url('allrss', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- );
-
- $replies = array(
- 'url' => common_local_url('replies', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '1',
- );
-
- $replies_rss = array(
- 'url' => common_local_url('repliesrss', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- );
-
- $foaf = array(
- 'url' => common_local_url('foaf', $user_args),
- 'changefreq' => 'weekly',
- 'priority' => '0.5',
- );
-
- # Construct a <url></url> element for each user facet and add it
- # to our existing list of those.
- $user_list[$map_count] .= url($user);
- $user_rss_list[$map_count] .= url($user_rss);
- $all_list[$map_count] .= url($all);
- $all_rss_list[$map_count] .= url($all_rss);
- $replies_list[$map_count] .= url($replies);
- $replies_rss_list[$map_count] .= url($replies_rss);
- $foaf_list[$map_count] .= url($foaf);
-
- $user_count++;
- }
-
- # Make full sitemaps from the lists and save them.
- # Possible factoring: put all the lists into a master array, thus allowing
- # calling with single argument (i.e., array_to_map('user')).
- array_to_map($user_list, 'user');
- array_to_map($user_rss_list, 'user_rss');
- array_to_map($all_list, 'all');
- array_to_map($all_rss_list, 'all_rss');
- array_to_map($replies_list, 'replies');
- array_to_map($replies_rss_list, 'replies_rss');
- array_to_map($foaf_list, 'foaf');
+ global $output_paths;
+
+ $users = DB_DataObject::factory('user');
+
+ $users->query('SELECT id, nickname FROM user');
+
+ $user_count = 0;
+ $map_count = 1;
+
+ while ($users->fetch()) {
+
+ # Maximum 50,000 URLs per sitemap file.
+ if ($user_count == 50000) {
+ $user_count = 0;
+ $map_count++;
+ }
+
+ $user_args = array('nickname' => $users->nickname);
+
+ # Define parameters for generating <url></url> elements.
+ $user = array(
+ 'url' => common_local_url('showstream', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $user_rss = array(
+ 'url' => common_local_url('userrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $all = array(
+ 'url' => common_local_url('all', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $all_rss = array(
+ 'url' => common_local_url('allrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $replies = array(
+ 'url' => common_local_url('replies', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $replies_rss = array(
+ 'url' => common_local_url('repliesrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $foaf = array(
+ 'url' => common_local_url('foaf', $user_args),
+ 'changefreq' => 'weekly',
+ 'priority' => '0.5',
+ );
+
+ # Construct a <url></url> element for each user facet and add it
+ # to our existing list of those.
+ $user_list[$map_count] .= url($user);
+ $user_rss_list[$map_count] .= url($user_rss);
+ $all_list[$map_count] .= url($all);
+ $all_rss_list[$map_count] .= url($all_rss);
+ $replies_list[$map_count] .= url($replies);
+ $replies_rss_list[$map_count] .= url($replies_rss);
+ $foaf_list[$map_count] .= url($foaf);
+
+ $user_count++;
+ }
+
+ # Make full sitemaps from the lists and save them.
+ # Possible factoring: put all the lists into a master array, thus allowing
+ # calling with single argument (i.e., array_to_map('user')).
+ array_to_map($user_list, 'user');
+ array_to_map($user_rss_list, 'user_rss');
+ array_to_map($all_list, 'all');
+ array_to_map($all_rss_list, 'all_rss');
+ array_to_map($replies_list, 'replies');
+ array_to_map($replies_rss_list, 'replies_rss');
+ array_to_map($foaf_list, 'foaf');
}
# ------------------------------------------------------------------------------
@@ -209,87 +209,87 @@ function user_map() {
# Generate a <url></url> element.
function url($url_args) {
- $url = preg_replace('/&/', '&amp;', $url_args['url']); # escape ampersands for XML
- $lastmod = $url_args['lastmod'];
- $changefreq = $url_args['changefreq'];
- $priority = $url_args['priority'];
+ $url = preg_replace('/&/', '&amp;', $url_args['url']); # escape ampersands for XML
+ $lastmod = $url_args['lastmod'];
+ $changefreq = $url_args['changefreq'];
+ $priority = $url_args['priority'];
- if (is_null($url)) {
- error("url() arguments require 'url' value.");
- }
+ if (is_null($url)) {
+ error("url() arguments require 'url' value.");
+ }
- $url_out = "\t<url>\n";
- $url_out .= "\t\t<loc>$url</loc>\n";
+ $url_out = "\t<url>\n";
+ $url_out .= "\t\t<loc>$url</loc>\n";
- if ($changefreq) {
- $url_out .= "\t\t<changefreq>$changefreq</changefreq>\n";
- }
+ if ($changefreq) {
+ $url_out .= "\t\t<changefreq>$changefreq</changefreq>\n";
+ }
- if ($lastmod) {
- $url_out .= "\t\t<lastmod>$lastmod</lastmod>\n";
- }
+ if ($lastmod) {
+ $url_out .= "\t\t<lastmod>$lastmod</lastmod>\n";
+ }
- if ($priority) {
- $url_out .= "\t\t<priority>$priority</priority>\n";
- }
+ if ($priority) {
+ $url_out .= "\t\t<priority>$priority</priority>\n";
+ }
- $url_out .= "\t</url>\n";
+ $url_out .= "\t</url>\n";
- return $url_out;
+ return $url_out;
}
function sitemap($sitemap_args) {
- $url = preg_replace('/&/', '&amp;', $sitemap_args['url']); # escape ampersands for XML
- $lastmod = $sitemap_args['lastmod'];
+ $url = preg_replace('/&/', '&amp;', $sitemap_args['url']); # escape ampersands for XML
+ $lastmod = $sitemap_args['lastmod'];
- if (is_null($url)) {
- error("url() arguments require 'url' value.");
- }
+ if (is_null($url)) {
+ error("url() arguments require 'url' value.");
+ }
- $sitemap_out = "\t<sitemap>\n";
- $sitemap_out .= "\t\t<loc>$url</loc>\n";
+ $sitemap_out = "\t<sitemap>\n";
+ $sitemap_out .= "\t\t<loc>$url</loc>\n";
- if ($lastmod) {
- $sitemap_out .= "\t\t<lastmod>$lastmod</lastmod>\n";
- }
+ if ($lastmod) {
+ $sitemap_out .= "\t\t<lastmod>$lastmod</lastmod>\n";
+ }
- $sitemap_out .= "\t</sitemap>\n";
+ $sitemap_out .= "\t</sitemap>\n";
- return $sitemap_out;
+ return $sitemap_out;
}
# Generate a <urlset></urlset> element.
function urlset($urlset_text) {
- $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
- '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
- $urlset_text .
- '</urlset>';
+ $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
+ $urlset_text .
+ '</urlset>';
- return $urlset;
+ return $urlset;
}
# Generate a <urlset></urlset> element.
function sitemapindex($sitemapindex_text) {
- $sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
- '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
- $sitemapindex_text .
- '</sitemapindex>';
+ $sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
+ '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
+ $sitemapindex_text .
+ '</sitemapindex>';
- return $sitemapindex;
+ return $sitemapindex;
}
# Generate a sitemap from an array containing <url></url> elements and write it to a file.
function array_to_map($url_list, $filename_prefix) {
- global $output_paths;
-
- if ($url_list) {
- # $map_urls is a long string containing concatenated <url></url> elements.
- while (list($map_idx, $map_urls) = each($url_list)) {
- $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml";
-
- write_file($urlset_path, urlset($map_urls));
- }
- }
+ global $output_paths;
+
+ if ($url_list) {
+ # $map_urls is a long string containing concatenated <url></url> elements.
+ while (list($map_idx, $map_urls) = each($url_list)) {
+ $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml";
+
+ write_file($urlset_path, urlset($map_urls));
+ }
+ }
}
# ------------------------------------------------------------------------------
@@ -298,79 +298,79 @@ function array_to_map($url_list, $filename_prefix) {
# Parse command line arguments.
function parse_args() {
- $args = getopt('f:d:u:');
-
- if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) {
- error('Mandatory arguments: -f <index file path> -d <output directory path> -u <URL of sitemaps directory>');
- }
-
- if (is_null($args[f])) {
- error('You must specify an index file name with the -f option.');
- }
-
- if (is_null($args[d])) {
- error('You must specify a directory for the output file with the -d option.');
- }
-
- if (is_null($args[u])) {
- error('You must specify a URL for the directory where the sitemaps will be kept with the -u option.');
- }
-
- $index_file = $args[f];
- $output_dir = $args[d];
- $output_url = $args[u];
-
- if (file_exists($output_dir)) {
- if (is_writable($output_dir) === FALSE) {
- error("$output_dir is not writable.");
- }
- } else {
- error("output directory $output_dir does not exist.");
- }
-
- $paths = array(
- 'index_file' => $index_file,
- 'output_dir' => trailing_slash($output_dir),
- 'output_url' => trailing_slash($output_url),
- );
-
- return $paths;
+ $args = getopt('f:d:u:');
+
+ if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) {
+ error('Mandatory arguments: -f <index file path> -d <output directory path> -u <URL of sitemaps directory>');
+ }
+
+ if (is_null($args[f])) {
+ error('You must specify an index file name with the -f option.');
+ }
+
+ if (is_null($args[d])) {
+ error('You must specify a directory for the output file with the -d option.');
+ }
+
+ if (is_null($args[u])) {
+ error('You must specify a URL for the directory where the sitemaps will be kept with the -u option.');
+ }
+
+ $index_file = $args[f];
+ $output_dir = $args[d];
+ $output_url = $args[u];
+
+ if (file_exists($output_dir)) {
+ if (is_writable($output_dir) === FALSE) {
+ error("$output_dir is not writable.");
+ }
+ } else {
+ error("output directory $output_dir does not exist.");
+ }
+
+ $paths = array(
+ 'index_file' => $index_file,
+ 'output_dir' => trailing_slash($output_dir),
+ 'output_url' => trailing_slash($output_url),
+ );
+
+ return $paths;
}
# Ensure paths end with a "/".
function trailing_slash($path) {
- if (preg_match('/\/$/', $path) == 0) {
- $path .= '/';
- }
+ if (preg_match('/\/$/', $path) == 0) {
+ $path .= '/';
+ }
- return $path;
+ return $path;
}
# Write data to disk.
function write_file($path, $data) {
- if (is_null($path)) {
- error('No path specified for writing to.');
- } elseif (is_null($data)) {
- error('No data specified for writing.');
- }
-
- if (($fh_out = fopen($path,'w')) === FALSE) {
- error("couldn't open $path for writing.");
- }
-
- if (fwrite($fh_out, $data) === FALSE) {
- error("couldn't write to $path.");
- }
+ if (is_null($path)) {
+ error('No path specified for writing to.');
+ } elseif (is_null($data)) {
+ error('No data specified for writing.');
+ }
+
+ if (($fh_out = fopen($path,'w')) === FALSE) {
+ error("couldn't open $path for writing.");
+ }
+
+ if (fwrite($fh_out, $data) === FALSE) {
+ error("couldn't write to $path.");
+ }
}
# Display an error message and exit.
function error ($error_msg) {
- if (is_null($error_msg)) {
- $error_msg = 'error() was called without any explanation!';
- }
+ if (is_null($error_msg)) {
+ $error_msg = 'error() was called without any explanation!';
+ }
- echo "Error: $error_msg\n";
- exit(1);
+ echo "Error: $error_msg\n";
+ exit(1);
}
?> \ No newline at end of file
diff --git a/_darcs/pristine/scripts/smsqueuehandler.php b/_darcs/pristine/scripts/smsqueuehandler.php
index 8f0d02d9b..f17429d96 100644
--- a/_darcs/pristine/scripts/smsqueuehandler.php
+++ b/_darcs/pristine/scripts/smsqueuehandler.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -34,22 +34,22 @@ require_once(INSTALLDIR . '/lib/queuehandler.php');
set_error_handler('common_error_handler');
class SmsQueueHandler extends QueueHandler {
-
- function transport() {
- return 'sms';
- }
+
+ function transport() {
+ return 'sms';
+ }
- function start() {
- $this->log(LOG_INFO, "INITIALIZE");
- return true;
- }
+ function start() {
+ $this->log(LOG_INFO, "INITIALIZE");
+ return true;
+ }
- function handle_notice($notice) {
- return mail_broadcast_notice_sms($notice);
- }
-
- function finish() {
- }
+ function handle_notice($notice) {
+ return mail_broadcast_notice_sms($notice);
+ }
+
+ function finish() {
+ }
}
ini_set("max_execution_time", "0");
diff --git a/_darcs/pristine/scripts/synctwitterfriends.php b/_darcs/pristine/scripts/synctwitterfriends.php
index 070eb9bbb..0ce34c2ae 100644
--- a/_darcs/pristine/scripts/synctwitterfriends.php
+++ b/_darcs/pristine/scripts/synctwitterfriends.php
@@ -11,17 +11,17 @@
*
* 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
+ * 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/>.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -35,21 +35,21 @@ $flink->find();
while ($flink->fetch()) {
- if (($flink->friendsync & FOREIGN_FRIEND_RECV) == FOREIGN_FRIEND_RECV) {
+ if (($flink->friendsync & FOREIGN_FRIEND_RECV) == FOREIGN_FRIEND_RECV) {
- $user = User::staticGet($flink->user_id);
+ $user = User::staticGet($flink->user_id);
- print "Updating Twitter friends for user $user->nickname ($user->id)\n";
+ print "Updating Twitter friends for user $user->nickname ($user->id)\n";
- $fuser = $flink->getForeignUser();
+ $fuser = $flink->getForeignUser();
- $result = save_twitter_friends($user, $fuser->id, $fuser->nickname, $flink->credentials);
+ $result = save_twitter_friends($user, $fuser->id, $fuser->nickname, $flink->credentials);
- if ($result == false) {
- print "Problems updating Twitter friends! Check the log.\n";
- exit(1);
- }
- }
+ if ($result == false) {
+ print "Problems updating Twitter friends! Check the log.\n";
+ exit(1);
+ }
+ }
}
diff --git a/_darcs/pristine/scripts/update_translations.php b/_darcs/pristine/scripts/update_translations.php
index 3eb7b3401..8ad07ccca 100644
--- a/_darcs/pristine/scripts/update_translations.php
+++ b/_darcs/pristine/scripts/update_translations.php
@@ -5,62 +5,62 @@ chdir(dirname(__FILE__) . '/..');
/* Languages to pull */
$languages = array(
- 'da_DK' => 'http://laconi.ca/translate/download.php?file_id=23',
- 'nl_NL' => 'http://laconi.ca/translate/download.php?file_id=39',
- 'en_NZ' => 'http://laconi.ca/translate/download.php?file_id=15',
- 'eo' => 'http://laconi.ca/translate/download.php?file_id=10',
- 'fr_FR' => 'http://laconi.ca/translate/download.php?file_id=19',
- 'de_DE' => 'http://laconi.ca/translate/download.php?file_id=18',
- 'it_IT' => 'http://laconi.ca/translate/download.php?file_id=21',
- 'ko' => 'http://laconi.ca/translate/download.php?file_id=33',
- 'no_NB' => 'http://laconi.ca/translate/download.php?file_id=31',
- 'pt' => 'http://laconi.ca/translate/download.php?file_id=8',
- 'pt_BR' => 'http://laconi.ca/translate/download.php?file_id=72',
- 'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26',
- 'es' => 'http://laconi.ca/translate/download.php?file_id=9',
- 'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37',
- 'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44',
- 'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71',
- 'mk_MK' => 'http://laconi.ca/translate/download.php?file_id=67',
- 'ja_JP' => 'http://laconi.ca/translate/download.php?file_id=43',
- 'cs_CZ' => 'http://laconi.ca/translate/download.php?file_id=63',
- 'ca_ES' => 'http://laconi.ca/translate/download.php?file_id=49',
- 'pl_PL' => 'http://laconi.ca/translate/download.php?file_id=51',
- 'sv_SE' => 'http://laconi.ca/translate/download.php?file_id=55'
+ 'da_DK' => 'http://laconi.ca/translate/download.php?file_id=23',
+ 'nl_NL' => 'http://laconi.ca/translate/download.php?file_id=39',
+ 'en_NZ' => 'http://laconi.ca/translate/download.php?file_id=15',
+ 'eo' => 'http://laconi.ca/translate/download.php?file_id=10',
+ 'fr_FR' => 'http://laconi.ca/translate/download.php?file_id=19',
+ 'de_DE' => 'http://laconi.ca/translate/download.php?file_id=18',
+ 'it_IT' => 'http://laconi.ca/translate/download.php?file_id=21',
+ 'ko' => 'http://laconi.ca/translate/download.php?file_id=33',
+ 'no_NB' => 'http://laconi.ca/translate/download.php?file_id=31',
+ 'pt' => 'http://laconi.ca/translate/download.php?file_id=8',
+ 'pt_BR' => 'http://laconi.ca/translate/download.php?file_id=72',
+ 'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26',
+ 'es' => 'http://laconi.ca/translate/download.php?file_id=9',
+ 'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37',
+ 'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44',
+ 'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71',
+ 'mk_MK' => 'http://laconi.ca/translate/download.php?file_id=67',
+ 'ja_JP' => 'http://laconi.ca/translate/download.php?file_id=43',
+ 'cs_CZ' => 'http://laconi.ca/translate/download.php?file_id=63',
+ 'ca_ES' => 'http://laconi.ca/translate/download.php?file_id=49',
+ 'pl_PL' => 'http://laconi.ca/translate/download.php?file_id=51',
+ 'sv_SE' => 'http://laconi.ca/translate/download.php?file_id=55'
);
/* Update the languages */
foreach ($languages as $code => $file) {
- $lcdir='locale/'.$code;
- $msgdir=$lcdir.'/LC_MESSAGES';
- $pofile=$msgdir.'/laconica.po';
- $mofile=$msgdir.'/laconica.mo';
+ $lcdir='locale/'.$code;
+ $msgdir=$lcdir.'/LC_MESSAGES';
+ $pofile=$msgdir.'/laconica.po';
+ $mofile=$msgdir.'/laconica.mo';
- /* Check for an existing */
- if (!is_dir($msgdir)) {
- mkdir($lcdir);
- mkdir($msgdir);
- $existingSHA1 = '';
- } else {
- $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
- }
+ /* Check for an existing */
+ if (!is_dir($msgdir)) {
+ mkdir($lcdir);
+ mkdir($msgdir);
+ $existingSHA1 = '';
+ } else {
+ $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : '';
+ }
- /* Get the remote one */
- $newFile = file_get_contents($file);
+ /* Get the remote one */
+ $newFile = file_get_contents($file);
- // Update if the local .po file is different to the one downloaded, or
- // if the .mo file is not present.
- if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) {
- echo "Updating ".$code."\n";
- file_put_contents($pofile, $newFile);
- $prevdir = getcwd();
- chdir($msgdir);
- system('msgmerge -U laconica.po ../../laconica.pot');
- system('msgfmt -f -o laconica.mo laconica.po');
- chdir($prevdir);
- } else {
- echo "Unchanged - ".$code."\n";
- }
+ // Update if the local .po file is different to the one downloaded, or
+ // if the .mo file is not present.
+ if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) {
+ echo "Updating ".$code."\n";
+ file_put_contents($pofile, $newFile);
+ $prevdir = getcwd();
+ chdir($msgdir);
+ system('msgmerge -U laconica.po ../../laconica.pot');
+ system('msgfmt -f -o laconica.mo laconica.po');
+ chdir($prevdir);
+ } else {
+ echo "Unchanged - ".$code."\n";
+ }
}
echo "Finished\n";
diff --git a/_darcs/pristine/scripts/xmppconfirmhandler.php b/_darcs/pristine/scripts/xmppconfirmhandler.php
index 8961b0b6e..454616ca0 100644
--- a/_darcs/pristine/scripts/xmppconfirmhandler.php
+++ b/_darcs/pristine/scripts/xmppconfirmhandler.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -37,102 +37,102 @@ define('CLAIM_TIMEOUT', 1200);
class XmppConfirmHandler extends XmppQueueHandler {
- var $_id = 'confirm';
-
- function class_name() {
- return 'XmppConfirmHandler';
- }
-
- function run() {
- if (!$this->start()) {
- return false;
- }
- $this->log(LOG_INFO, 'checking for queued confirmations');
- do {
- $confirm = $this->next_confirm();
- if ($confirm) {
- $this->log(LOG_INFO, 'Sending confirmation for ' . $confirm->address);
- $user = User::staticGet($confirm->user_id);
- if (!$user) {
- $this->log(LOG_WARNING, 'Confirmation for unknown user ' . $confirm->user_id);
- continue;
- }
- $success = jabber_confirm_address($confirm->code,
- $user->nickname,
- $confirm->address);
- if (!$success) {
- $this->log(LOG_ERR, 'Confirmation failed for ' . $confirm->address);
- # Just let the claim age out; hopefully things work then
- continue;
- } else {
- $this->log(LOG_INFO, 'Confirmation sent for ' . $confirm->address);
- # Mark confirmation sent; need a dupe so we don't have the WHERE clause
- $dupe = Confirm_address::staticGet('code', $confirm->code);
- if (!$dupe) {
- common_log(LOG_WARNING, 'Could not refetch confirm', __FILE__);
- continue;
- }
- $orig = clone($dupe);
- $dupe->sent = $dupe->claimed;
- $result = $dupe->update($orig);
- if (!$result) {
- common_log_db_error($dupe, 'UPDATE', __FILE__);
- # Just let the claim age out; hopefully things work then
- continue;
- }
- $dupe->free();
- unset($dupe);
- }
- $user->free();
- unset($user);
- $confirm->free();
- unset($confirm);
- $this->idle(0);
- } else {
-# $this->clear_old_confirm_claims();
- $this->idle(10);
- }
- } while (true);
- if (!$this->finish()) {
- return false;
- }
- return true;
- }
+ var $_id = 'confirm';
+
+ function class_name() {
+ return 'XmppConfirmHandler';
+ }
+
+ function run() {
+ if (!$this->start()) {
+ return false;
+ }
+ $this->log(LOG_INFO, 'checking for queued confirmations');
+ do {
+ $confirm = $this->next_confirm();
+ if ($confirm) {
+ $this->log(LOG_INFO, 'Sending confirmation for ' . $confirm->address);
+ $user = User::staticGet($confirm->user_id);
+ if (!$user) {
+ $this->log(LOG_WARNING, 'Confirmation for unknown user ' . $confirm->user_id);
+ continue;
+ }
+ $success = jabber_confirm_address($confirm->code,
+ $user->nickname,
+ $confirm->address);
+ if (!$success) {
+ $this->log(LOG_ERR, 'Confirmation failed for ' . $confirm->address);
+ # Just let the claim age out; hopefully things work then
+ continue;
+ } else {
+ $this->log(LOG_INFO, 'Confirmation sent for ' . $confirm->address);
+ # Mark confirmation sent; need a dupe so we don't have the WHERE clause
+ $dupe = Confirm_address::staticGet('code', $confirm->code);
+ if (!$dupe) {
+ common_log(LOG_WARNING, 'Could not refetch confirm', __FILE__);
+ continue;
+ }
+ $orig = clone($dupe);
+ $dupe->sent = $dupe->claimed;
+ $result = $dupe->update($orig);
+ if (!$result) {
+ common_log_db_error($dupe, 'UPDATE', __FILE__);
+ # Just let the claim age out; hopefully things work then
+ continue;
+ }
+ $dupe->free();
+ unset($dupe);
+ }
+ $user->free();
+ unset($user);
+ $confirm->free();
+ unset($confirm);
+ $this->idle(0);
+ } else {
+# $this->clear_old_confirm_claims();
+ $this->idle(10);
+ }
+ } while (true);
+ if (!$this->finish()) {
+ return false;
+ }
+ return true;
+ }
- function next_confirm() {
- $confirm = new Confirm_address();
- $confirm->whereAdd('claimed IS NULL');
- $confirm->whereAdd('sent IS NULL');
- # XXX: eventually we could do other confirmations in the queue, too
- $confirm->address_type = 'jabber';
- $confirm->orderBy('modified DESC');
- $confirm->limit(1);
- if ($confirm->find(TRUE)) {
- $this->log(LOG_INFO, 'Claiming confirmation for ' . $confirm->address);
- # working around some weird DB_DataObject behaviour
- $confirm->whereAdd(''); # clears where stuff
- $original = clone($confirm);
- $confirm->claimed = common_sql_now();
- $result = $confirm->update($original);
- if ($result) {
- $this->log(LOG_INFO, 'Succeeded in claim! '. $result);
- return $confirm;
- } else {
- $this->log(LOG_INFO, 'Failed in claim!');
- return false;
- }
- }
- return NULL;
- }
+ function next_confirm() {
+ $confirm = new Confirm_address();
+ $confirm->whereAdd('claimed IS NULL');
+ $confirm->whereAdd('sent IS NULL');
+ # XXX: eventually we could do other confirmations in the queue, too
+ $confirm->address_type = 'jabber';
+ $confirm->orderBy('modified DESC');
+ $confirm->limit(1);
+ if ($confirm->find(TRUE)) {
+ $this->log(LOG_INFO, 'Claiming confirmation for ' . $confirm->address);
+ # working around some weird DB_DataObject behaviour
+ $confirm->whereAdd(''); # clears where stuff
+ $original = clone($confirm);
+ $confirm->claimed = common_sql_now();
+ $result = $confirm->update($original);
+ if ($result) {
+ $this->log(LOG_INFO, 'Succeeded in claim! '. $result);
+ return $confirm;
+ } else {
+ $this->log(LOG_INFO, 'Failed in claim!');
+ return false;
+ }
+ }
+ return NULL;
+ }
- function clear_old_confirm_claims() {
- $confirm = new Confirm();
- $confirm->claimed = NULL;
- $confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
- $confirm->update(DB_DATAOBJECT_WHEREADD_ONLY);
- $confirm->free();
- unset($confirm);
- }
+ function clear_old_confirm_claims() {
+ $confirm = new Confirm();
+ $confirm->claimed = NULL;
+ $confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
+ $confirm->update(DB_DATAOBJECT_WHEREADD_ONLY);
+ $confirm->free();
+ unset($confirm);
+ }
}
ini_set("max_execution_time", "0");
diff --git a/_darcs/pristine/scripts/xmppdaemon.php b/_darcs/pristine/scripts/xmppdaemon.php
index 9a60970a6..cd27a2c14 100644
--- a/_darcs/pristine/scripts/xmppdaemon.php
+++ b/_darcs/pristine/scripts/xmppdaemon.php
@@ -20,8 +20,8 @@
# Abort if called from a web server
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
- print "This script must be run from the command line\n";
- exit();
+ print "This script must be run from the command line\n";
+ exit();
}
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
@@ -39,203 +39,203 @@ set_error_handler('common_error_handler');
class XMPPDaemon extends Daemon {
- function XMPPDaemon($resource=NULL) {
- static $attrs = array('server', 'port', 'user', 'password', 'host');
-
- foreach ($attrs as $attr)
- {
- $this->$attr = common_config('xmpp', $attr);
- }
-
- if ($resource) {
- $this->resource = $resource;
- } else {
- $this->resource = common_config('xmpp', 'resource') . 'daemon';
- }
-
- $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}");
- }
-
- function connect() {
-
- $connect_to = ($this->host) ? $this->host : $this->server;
-
- $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port");
-
- $this->conn = jabber_connect($this->resource);
-
- if (!$this->conn) {
- return false;
- }
-
- $this->conn->setReconnectTimeout(600);
-
- jabber_send_presence("Send me a message to post a notice", 'available',
- NULL, 'available', 100);
- return !$this->conn->isDisconnected();
- }
-
- function name() {
- return strtolower('xmppdaemon.'.$this->resource);
- }
-
- function run() {
- if ($this->connect()) {
-
- $this->conn->addEventHandler('message', 'handle_message', $this);
- $this->conn->addEventHandler('presence', 'handle_presence', $this);
- $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
-
- $this->conn->process();
- }
- }
-
- function handle_reconnect(&$pl) {
- $this->conn->processUntil('session_start');
- $this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100);
- }
-
- function get_user($from) {
- $user = User::staticGet('jabber', jabber_normalize_jid($from));
- return $user;
- }
-
- function handle_message(&$pl) {
- if ($pl['type'] != 'chat') {
- return;
- }
- if (mb_strlen($pl['body']) == 0) {
- return;
- }
-
- $from = jabber_normalize_jid($pl['from']);
-
- # Forwarded from another daemon (probably a broadcaster) for
- # us to handle
-
- if ($this->is_self($from)) {
- $from = $this->get_ofrom($pl);
- if (is_null($from) || $this->is_self($from)) {
- return;
- }
- }
-
- $user = $this->get_user($from);
-
- if (!$user) {
- $this->from_site($from, 'Unknown user; go to ' .
- common_local_url('imsettings') .
- ' to add your address to your account');
- $this->log(LOG_WARNING, 'Message from unknown user ' . $from);
- return;
- }
- if ($this->handle_command($user, $pl['body'])) {
- return;
- } else if ($this->is_autoreply($pl['body'])) {
- $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from);
- return;
- } else if ($this->is_otr($pl['body'])) {
- $this->log(LOG_INFO, 'Ignoring OTR from ' . $from);
- return;
- } else if ($this->is_direct($pl['body'])) {
- preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to);
-
- $to = preg_replace('/^d([\ ])*/', '', $to[0][0]);
- $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
- $this->add_direct($user, $body, $to, $from);
- } else {
- $len = mb_strlen($pl['body']);
- if($len > 140) {
- $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len);
- return;
- }
- $this->add_notice($user, $pl);
- }
-
- $user->free();
- unset($user);
- }
-
- function is_self($from) {
- return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from));
- }
-
- function get_ofrom($pl) {
- $xml = $pl['xml'];
- $addresses = $xml->sub('addresses');
- if (!$addresses) {
- $this->log(LOG_WARNING, 'Forwarded message without addresses');
- return NULL;
- }
- $address = $addresses->sub('address');
- if (!$address) {
- $this->log(LOG_WARNING, 'Forwarded message without address');
- return NULL;
- }
- if (!array_key_exists('type', $address->attrs)) {
- $this->log(LOG_WARNING, 'No type for forwarded message');
- return NULL;
- }
- $type = $address->attrs['type'];
- if ($type != 'ofrom') {
- $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom');
- return NULL;
- }
- if (!array_key_exists('jid', $address->attrs)) {
- $this->log(LOG_WARNING, 'No jid for forwarded message');
- return NULL;
- }
- $jid = $address->attrs['jid'];
- if (!$jid) {
- $this->log(LOG_WARNING, 'Could not get jid from address');
- return NULL;
- }
- $this->log(LOG_DEBUG, 'Got message forwarded from jid ' . $jid);
- return $jid;
- }
-
- function is_autoreply($txt) {
- if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) {
- return true;
- } else {
- return false;
- }
- }
-
- function is_otr($txt) {
- if (preg_match('/^\?OTR/', $txt)) {
- return true;
- } else {
- return false;
- }
- }
-
- function is_direct($txt) {
- if (strtolower(substr($txt, 0, 2))=='d ') {
- return true;
- } else {
- return false;
- }
- }
-
- function from_site($address, $msg) {
- $text = '['.common_config('site', 'name') . '] ' . $msg;
- jabber_send_message($address, $text);
- }
-
- function handle_command($user, $body) {
- $inter = new CommandInterpreter();
- $cmd = $inter->handle_command($user, $body);
- if ($cmd) {
- $chan = new XMPPChannel($this->conn);
- $cmd->execute($chan);
- return true;
- } else {
- return false;
- }
- }
-
- function add_notice(&$user, &$pl) {
+ function XMPPDaemon($resource=NULL) {
+ static $attrs = array('server', 'port', 'user', 'password', 'host');
+
+ foreach ($attrs as $attr)
+ {
+ $this->$attr = common_config('xmpp', $attr);
+ }
+
+ if ($resource) {
+ $this->resource = $resource;
+ } else {
+ $this->resource = common_config('xmpp', 'resource') . 'daemon';
+ }
+
+ $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}");
+ }
+
+ function connect() {
+
+ $connect_to = ($this->host) ? $this->host : $this->server;
+
+ $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port");
+
+ $this->conn = jabber_connect($this->resource);
+
+ if (!$this->conn) {
+ return false;
+ }
+
+ $this->conn->setReconnectTimeout(600);
+
+ jabber_send_presence("Send me a message to post a notice", 'available',
+ NULL, 'available', 100);
+ return !$this->conn->isDisconnected();
+ }
+
+ function name() {
+ return strtolower('xmppdaemon.'.$this->resource);
+ }
+
+ function run() {
+ if ($this->connect()) {
+
+ $this->conn->addEventHandler('message', 'handle_message', $this);
+ $this->conn->addEventHandler('presence', 'handle_presence', $this);
+ $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
+
+ $this->conn->process();
+ }
+ }
+
+ function handle_reconnect(&$pl) {
+ $this->conn->processUntil('session_start');
+ $this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100);
+ }
+
+ function get_user($from) {
+ $user = User::staticGet('jabber', jabber_normalize_jid($from));
+ return $user;
+ }
+
+ function handle_message(&$pl) {
+ if ($pl['type'] != 'chat') {
+ return;
+ }
+ if (mb_strlen($pl['body']) == 0) {
+ return;
+ }
+
+ $from = jabber_normalize_jid($pl['from']);
+
+ # Forwarded from another daemon (probably a broadcaster) for
+ # us to handle
+
+ if ($this->is_self($from)) {
+ $from = $this->get_ofrom($pl);
+ if (is_null($from) || $this->is_self($from)) {
+ return;
+ }
+ }
+
+ $user = $this->get_user($from);
+
+ if (!$user) {
+ $this->from_site($from, 'Unknown user; go to ' .
+ common_local_url('imsettings') .
+ ' to add your address to your account');
+ $this->log(LOG_WARNING, 'Message from unknown user ' . $from);
+ return;
+ }
+ if ($this->handle_command($user, $pl['body'])) {
+ return;
+ } else if ($this->is_autoreply($pl['body'])) {
+ $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from);
+ return;
+ } else if ($this->is_otr($pl['body'])) {
+ $this->log(LOG_INFO, 'Ignoring OTR from ' . $from);
+ return;
+ } else if ($this->is_direct($pl['body'])) {
+ preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to);
+
+ $to = preg_replace('/^d([\ ])*/', '', $to[0][0]);
+ $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
+ $this->add_direct($user, $body, $to, $from);
+ } else {
+ $len = mb_strlen($pl['body']);
+ if($len > 140) {
+ $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len);
+ return;
+ }
+ $this->add_notice($user, $pl);
+ }
+
+ $user->free();
+ unset($user);
+ }
+
+ function is_self($from) {
+ return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from));
+ }
+
+ function get_ofrom($pl) {
+ $xml = $pl['xml'];
+ $addresses = $xml->sub('addresses');
+ if (!$addresses) {
+ $this->log(LOG_WARNING, 'Forwarded message without addresses');
+ return NULL;
+ }
+ $address = $addresses->sub('address');
+ if (!$address) {
+ $this->log(LOG_WARNING, 'Forwarded message without address');
+ return NULL;
+ }
+ if (!array_key_exists('type', $address->attrs)) {
+ $this->log(LOG_WARNING, 'No type for forwarded message');
+ return NULL;
+ }
+ $type = $address->attrs['type'];
+ if ($type != 'ofrom') {
+ $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom');
+ return NULL;
+ }
+ if (!array_key_exists('jid', $address->attrs)) {
+ $this->log(LOG_WARNING, 'No jid for forwarded message');
+ return NULL;
+ }
+ $jid = $address->attrs['jid'];
+ if (!$jid) {
+ $this->log(LOG_WARNING, 'Could not get jid from address');
+ return NULL;
+ }
+ $this->log(LOG_DEBUG, 'Got message forwarded from jid ' . $jid);
+ return $jid;
+ }
+
+ function is_autoreply($txt) {
+ if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function is_otr($txt) {
+ if (preg_match('/^\?OTR/', $txt)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function is_direct($txt) {
+ if (strtolower(substr($txt, 0, 2))=='d ') {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function from_site($address, $msg) {
+ $text = '['.common_config('site', 'name') . '] ' . $msg;
+ jabber_send_message($address, $text);
+ }
+
+ function handle_command($user, $body) {
+ $inter = new CommandInterpreter();
+ $cmd = $inter->handle_command($user, $body);
+ if ($cmd) {
+ $chan = new XMPPChannel($this->conn);
+ $cmd->execute($chan);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function add_notice(&$user, &$pl) {
$body = trim($pl['body']);
$content_shortened = common_shorten_link($body);
if (mb_strlen($content_shortened) > 140) {
@@ -245,59 +245,59 @@ class XMPPDaemon extends Daemon {
else {
$content = $body;
}
- $notice = Notice::saveNew($user->id, $content, 'xmpp');
- if (is_string($notice)) {
- $this->log(LOG_ERR, $notice);
- return;
- }
- common_broadcast_notice($notice);
- $this->log(LOG_INFO,
- 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
- $notice->free();
- unset($notice);
- }
-
- function handle_presence(&$pl) {
- $from = jabber_normalize_jid($pl['from']);
- switch ($pl['type']) {
- case 'subscribe':
- # We let anyone subscribe
- $this->subscribed($from);
- $this->log(LOG_INFO,
- 'Accepted subscription from ' . $from);
- break;
- case 'subscribed':
- case 'unsubscribed':
- case 'unsubscribe':
- $this->log(LOG_INFO,
- 'Ignoring "' . $pl['type'] . '" from ' . $from);
- break;
- default:
- if (!$pl['type']) {
- $user = User::staticGet('jabber', $from);
- if (!$user) {
- $this->log(LOG_WARNING, 'Presence from unknown user ' . $from);
- return;
- }
- if ($user->updatefrompresence) {
- $this->log(LOG_INFO, 'Updating ' . $user->nickname .
- ' status from presence.');
- $this->add_notice($user, $pl);
- }
- $user->free();
- unset($user);
- }
- break;
- }
- }
-
- function log($level, $msg) {
- common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
- }
-
- function subscribed($to) {
- jabber_special_presence('subscribed', $to);
- }
+ $notice = Notice::saveNew($user->id, $content, 'xmpp');
+ if (is_string($notice)) {
+ $this->log(LOG_ERR, $notice);
+ return;
+ }
+ common_broadcast_notice($notice);
+ $this->log(LOG_INFO,
+ 'Added notice ' . $notice->id . ' from user ' . $user->nickname);
+ $notice->free();
+ unset($notice);
+ }
+
+ function handle_presence(&$pl) {
+ $from = jabber_normalize_jid($pl['from']);
+ switch ($pl['type']) {
+ case 'subscribe':
+ # We let anyone subscribe
+ $this->subscribed($from);
+ $this->log(LOG_INFO,
+ 'Accepted subscription from ' . $from);
+ break;
+ case 'subscribed':
+ case 'unsubscribed':
+ case 'unsubscribe':
+ $this->log(LOG_INFO,
+ 'Ignoring "' . $pl['type'] . '" from ' . $from);
+ break;
+ default:
+ if (!$pl['type']) {
+ $user = User::staticGet('jabber', $from);
+ if (!$user) {
+ $this->log(LOG_WARNING, 'Presence from unknown user ' . $from);
+ return;
+ }
+ if ($user->updatefrompresence) {
+ $this->log(LOG_INFO, 'Updating ' . $user->nickname .
+ ' status from presence.');
+ $this->add_notice($user, $pl);
+ }
+ $user->free();
+ unset($user);
+ }
+ break;
+ }
+ }
+
+ function log($level, $msg) {
+ common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
+ }
+
+ function subscribed($to) {
+ jabber_special_presence('subscribed', $to);
+ }
}
ini_set("max_execution_time", "0");