diff options
author | Evan Prodromou <git@evanprodromou.name> | 2009-01-23 08:58:31 +0100 |
---|---|---|
committer | Evan Prodromou <git@evanprodromou.name> | 2009-01-23 08:58:31 +0100 |
commit | a7c85bebd5be9ea019a8c80d74730d7eb28d4651 (patch) | |
tree | c3fdf9575a342624bc71aad1d439ae73594f558c | |
parent | 4873277b58941ae6ec16543f437f4267ccab5ac0 (diff) | |
parent | 7aa496cd8a939960eeaf79f3397f6fe94097e047 (diff) |
Merge branch 'master' of /var/www/mublog
Conflicts:
actions/api.php
actions/deletenotice.php
actions/recoverpassword.php
actions/remotesubscribe.php
actions/tag.php
actions/tagrss.php
actions/twitapiaccount.php
actions/twitapiusers.php
classes/Notice.php
classes/User.php
lib/common.php
lib/language.php
lib/subs.php
lib/twitterapi.php
lib/util.php
scripts/inbox_users.php
scripts/update_translations.php
Merged development trunk into laconica head. woohoo!
432 files changed, 39814 insertions, 20103 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f5a3e0212 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +avatar/* +files/* +_darcs/* +config.php +.htaccess +*.tmproj +dataobject.ini +*~ +*.bak +*.orig +*.rej @@ -817,6 +817,10 @@ private: If set to 'true', anonymous users will be redirected to the authentication will require it. Note that this does not turn off registration; use 'closed' or 'inviteonly' for the behaviour you want. +notice: A plain string that will appear on every page. A good place + to put introductory information about your service, or info about + upgrades and outages, or other community info. Any HTML will + be escaped. db -- diff --git a/actions/accesstoken.php b/actions/accesstoken.php index 4907749ce..65c67c64e 100644 --- a/actions/accesstoken.php +++ b/actions/accesstoken.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Access token class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,26 +28,47 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/omb.php'); +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()); - } - } +/** + * Access token class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class AccesstokenAction extends Action +{ + /** + * Class handler. + * + * @param array $args query arguments + * + * @return boolean false if user doesn't exist + */ + 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) { + $this->serverError($e->getMessage()); + } + } } diff --git a/actions/all.php b/actions/all.php index 2a26e48d4..428466f24 100644 --- a/actions/all.php +++ b/actions/all.php @@ -19,75 +19,86 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/actions/showstream.php'); - -class AllAction extends StreamAction { - - function handle($args) { - - parent::handle($args); - - $nickname = common_canonical_nickname($this->arg('nickname')); - $user = User::staticGet('nickname', $nickname); - - if (!$user) { - $this->client_error(_('No such user.')); - return; - } - - $profile = $user->getProfile(); - - if (!$profile) { - common_server_error(_('User has no profile.')); - return; - } - - # 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')); - - $this->show_notices($user); - - 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_top($user) { - $cur = common_current_user(); - - if ($cur && $cur->id == $user->id) { - common_notice_form('all'); - } - - $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'))); - } - - function show_notices($user) { - - $page = $this->trimmed('page'); - if (!$page) { - $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)); - } +require_once INSTALLDIR.'/lib/personalgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; + +class AllAction extends Action +{ + var $user = null; + var $page = null; + + function isReadOnly() + { + return true; + } + + function prepare($args) + { + parent::prepare($args); + $nickname = common_canonical_nickname($this->arg('nickname')); + $this->user = User::staticGet('nickname', $nickname); + $this->page = $this->trimmed('page'); + if (!$this->page) { + $this->page = 1; + } + return true; + } + + function handle($args) + { + parent::handle($args); + + if (!$this->user) { + $this->clientError(_('No such user.')); + return; + } + + $this->showPage(); + } + + function title() + { + if ($this->page > 1) { + return sprintf(_("%s and friends, page %d"), $this->user->nickname, $this->page); + } else { + return sprintf(_("%s and friends"), $this->user->nickname); + } + } + + function showFeeds() + { + $this->element('link', array('rel' => 'alternate', + 'href' => common_local_url('allrss', array('nickname' => + $this->user->nickname)), + 'type' => 'application/rss+xml', + 'title' => sprintf(_('Feed for friends of %s'), $this->user->nickname))); + } + + function showLocalNav() + { + $nav = new PersonalGroupNav($this); + $nav->show(); + } + + function showExportData() + { + $fl = new FeedList($this); + $fl->show(array(0=>array('href'=>common_local_url('allrss', array('nickname' => $this->user->nickname)), + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'allrss'))); + } + + function showContent() + { + $notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'all', array('nickname' => $this->user->nickname)); + } } diff --git a/actions/allrss.php b/actions/allrss.php index e49ac5540..248f59f43 100644 --- a/actions/allrss.php +++ b/actions/allrss.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * RSS feed for user and friends timeline action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,61 +29,99 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/rssaction.php'); +if (!defined('LACONICA')) { + exit(1); +} -// Formatting of RSS handled by Rss10Action +require_once INSTALLDIR.'/lib/rssaction.php'; -class AllrssAction extends Rss10Action { - - var $user = NULL; +/** + * RSS feed for user and friends timeline. + * + * Formatting of RSS handled by Rss10Action + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class AllrssAction extends Rss10Action +{ + var $user = null; - function init() { - $nickname = $this->trimmed('nickname'); - $this->user = User::staticGet('nickname', $nickname); + /** + * Initialization. + * + * @return boolean false if user doesn't exist + */ + function prepare($args) + { + parent::prepare($args); + $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) { + $this->clientError(_('No such user.')); + return false; + } else { + return true; + } + } - function get_notices($limit=0) { + /** + * Get notices + * + * @param integer $limit max number of notices to return + * + * @return array notices + */ + function getNotices($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; - } + /** + * Get channel. + * + * @return array associative array on channel information + */ + function getChannel() + { + $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; - } + /** + * Get image. + * + * @return string user avatar URL or null + */ + function getImage() + { + $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/actions/api.php b/actions/api.php index ccebcd89e..dfe2c8857 100644 --- a/actions/api.php +++ b/actions/api.php @@ -10,65 +10,67 @@ * * 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); +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 ($user) { - $this->user = $user; - $this->process_command(); - } else { - # basic authentication failed - $this->show_basic_auth_error(); - } - } - } else { + 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 { # Caller might give us a username even if not required if (isset($_SERVER['PHP_AUTH_USER'])) { @@ -79,50 +81,55 @@ class ApiAction extends Action { # Twitter doesn't throw an error if the user isn't found } - $this->process_command(); - } - } + $this->process_command(); + } + } - function process_command() { - $action = "twitapi$this->api_action"; - $actionfile = INSTALLDIR."/actions/$action.php"; + 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 (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); + 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'); + call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata); + } else { + $this->clientError("API method not found!", $code=404); + } + } else { + $this->clientError("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', + 'laconica/version', + 'laconica/config', + 'laconica/wadl'); + + static $bareauth = array('statuses/user_timeline', + 'statuses/friends', + 'statuses/followers', + 'favorites/favorites'); # If the site is "private", all API methods need authentication @@ -130,71 +137,73 @@ class ApiAction extends Action { return true; } - $fullname = "$this->api_action/$this->api_method"; + $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; - } - } + 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(); + $this->elementStart('hash'); + $this->element('error', null, $msg); + $this->element('request', null, $_SERVER['REQUEST_URI']); + $this->elementEnd('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 isReadOnly() + { + # 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; - } + return false; + } } diff --git a/actions/avatarbynickname.php b/actions/avatarbynickname.php index b33cababf..fec202016 100644 --- a/actions/avatarbynickname.php +++ b/actions/avatarbynickname.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Retrieve user avatar by nickname action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,52 +28,74 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -class AvatarbynicknameAction extends Action { - function handle($args) { +/** + * Retrieve user avatar by nickname action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class AvatarbynicknameAction extends Action +{ + /** + * Class handler. + * + * @param array $args query arguments + * + * @return boolean false if nickname or user isn't found + */ + function handle($args) + { parent::handle($args); $nickname = $this->trimmed('nickname'); if (!$nickname) { - $this->client_error(_('No nickname.')); - return; - } - $size = $this->trimmed('size'); + $this->clientError(_('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->clientError(_('No size.')); + return; + } + $size = strtolower($size); + if (!in_array($size, array('original', '96', '48', '24'))) { + $this->clientError(_('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->clientError(_('No such user.')); + return; + } + $profile = $user->getProfile(); + if (!$profile) { + $this->clientError(_('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/actions/avatarsettings.php b/actions/avatarsettings.php new file mode 100644 index 000000000..19f53b882 --- /dev/null +++ b/actions/avatarsettings.php @@ -0,0 +1,437 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Upload an avatar + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; + +/** + * Upload an avatar + * + * We use jCrop plugin for jQuery to crop the image after upload. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class AvatarsettingsAction extends AccountSettingsAction +{ + var $mode = null; + var $imagefile = null; + var $filename = null; + + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Avatar'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('You can upload your personal avatar.'); + } + + /** + * Content area of the page + * + * Shows a form for uploading an avatar. + * + * @return void + */ + + function showContent() + { + if ($this->mode == 'crop') { + $this->showCropForm(); + } else { + $this->showUploadForm(); + } + } + + function showUploadForm() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('User without matching profile')); + return; + } + + $original = $profile->getOriginalAvatar(); + + $this->elementStart('form', array('enctype' => 'multipart/form-data', + 'method' => 'post', + 'id' => 'form_settings_avatar', + 'class' => 'form_settings', + 'action' => + common_local_url('avatarsettings'))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Avatar settings')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + if ($original) { + $this->elementStart('li', array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => $original->url, + 'width' => $original->width, + 'height' => $original->height, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); + + if ($avatar) { + $this->elementStart('li', array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => $original->url, + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + $this->elementStart('li', array ('id' => 'settings_attach')); + $this->element('input', array('name' => 'avatarfile', + 'type' => 'file', + 'id' => 'avatarfile')); + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => MAX_AVATAR_SIZE)); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementStart('ul', 'form_actions'); + $this->elementStart('li'); + $this->submit('upload', _('Upload')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + function showCropForm() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('User without matching profile')); + return; + } + + $original = $profile->getOriginalAvatar(); + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_avatar', + 'class' => 'form_settings', + 'action' => + common_local_url('avatarsettings'))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Avatar settings')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + + $this->elementStart('li', + array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + 'width' => $this->filedata['width'], + 'height' => $this->filedata['height'], + 'alt' => $user->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + + $this->elementStart('li', + array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $user->nickname)); + $this->elementEnd('div'); + + foreach (array('avatar_crop_x', 'avatar_crop_y', + 'avatar_crop_w', 'avatar_crop_h') as $crop_info) { + $this->element('input', array('name' => $crop_info, + 'type' => 'hidden', + 'id' => $crop_info)); + } + $this->submit('crop', _('Crop')); + + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + /** + * Handle a post + * + * We mux on the button name to figure out what the user actually wanted. + * + * @return void + */ + + function handlePost() + { + // 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('upload')) { + $this->uploadAvatar(); + } else if ($this->arg('crop')) { + $this->cropAvatar(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Handle an image upload + * + * Does all the magic for handling an image upload, and crops the + * image by default. + * + * @return void + */ + + function uploadAvatar() + { + try { + $imagefile = ImageFile::fromUpload('avatarfile'); + } catch (Exception $e) { + $this->showForm($e->getMessage()); + return; + } + + $cur = common_current_user(); + + $filename = common_avatar_filename($cur->id, + image_type_to_extension($imagefile->type), + null, + 'tmp'.common_timestamp()); + + $filepath = common_avatar_path($filename); + + move_uploaded_file($imagefile->filename, $filepath); + + $filedata = array('filename' => $filename, + 'filepath' => $filepath, + 'width' => $imagefile->width, + 'height' => $imagefile->height, + 'type' => $imagefile->type); + + $_SESSION['FILEDATA'] = $filedata; + + $this->filedata = $filedata; + + $this->mode = 'crop'; + + $this->showForm(_('Pick a square area of the image to be your avatar'), + true); + } + + /** + * Handle the results of jcrop. + * + * @return void + */ + + function cropAvatar() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + $x = $this->arg('avatar_crop_x'); + $y = $this->arg('avatar_crop_y'); + $w = $this->arg('avatar_crop_w'); + $h = $this->arg('avatar_crop_h'); + + $filedata = $_SESSION['FILEDATA']; + + if (!$filedata) { + $this->serverError(_('Lost our file data.')); + return; + } + + $filepath = common_avatar_path($filedata['filename']); + + if (!file_exists($filepath)) { + $this->serverError(_('Lost our file.')); + return; + } + + switch ($filedata['type']) { + case IMAGETYPE_GIF: + $image_src = imagecreatefromgif($filepath); + break; + case IMAGETYPE_JPEG: + $image_src = imagecreatefromjpeg($filepath); + break; + case IMAGETYPE_PNG: + $image_src = imagecreatefrompng($filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + common_debug("W = $w, H = $h, X = $x, Y = $y"); + + $image_dest = imagecreatetruecolor($w, $h); + + $background = imagecolorallocate($image_dest, 0, 0, 0); + ImageColorTransparent($image_dest, $background); + imagealphablending($image_dest, false); + + imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $w, $h, $w, $h); + + $cur = common_current_user(); + + $filename = common_avatar_filename($cur->id, + image_type_to_extension($filedata['type']), + null, + common_timestamp()); + + $filepath = common_avatar_path($filename); + + switch ($filedata['type']) { + case IMAGETYPE_GIF: + imagegif($image_dest, $filepath); + break; + case IMAGETYPE_JPEG: + imagejpeg($image_dest, $filepath); + break; + case IMAGETYPE_PNG: + imagepng($image_dest, $filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + $user = common_current_user(); + + $profile = $cur->getProfile(); + + if ($profile->setOriginal($filepath)) { + @unlink(common_avatar_path($filedata['filename'])); + unset($_SESSION['FILEDATA']); + $this->mode = 'upload'; + $this->showForm(_('Avatar updated.'), true); + } else { + $this->showForm(_('Failed updating avatar.')); + } + } + + /** + * Add the jCrop stylesheet + * + * @return void + */ + + function showStylesheets() + { + parent::showStylesheets(); + $jcropStyle = + common_path('theme/base/css/jquery.Jcrop.css?version='.LACONICA_VERSION); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $jcropStyle, + 'media' => 'screen, projection, tv')); + } + + /** + * Add the jCrop scripts + * + * @return void + */ + + function showScripts() + { + parent::showScripts(); + + $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js'); + $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js'); + + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropPack)); + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropGo)); + } +} diff --git a/actions/block.php b/actions/block.php index e6d2b7e49..e77b634c8 100644 --- a/actions/block.php +++ b/actions/block.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Block a user action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,120 +28,151 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -class BlockAction extends Action { - - var $profile = NULL; - - function prepare($args) { +if (!defined('LACONICA')) { + exit(1); +} +/** + * Block a user action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class BlockAction extends Action +{ + var $profile = null; + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + */ + function prepare($args) + { parent::prepare($args); - if (!common_logged_in()) { - $this->client_error(_('Not logged in.')); + $this->clientError(_('Not logged in.')); return false; } - - $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->clientError(_('There was a problem with your session token. Try again, please.')); + return; + } $id = $this->trimmed('blockto'); - if (!$id) { - $this->client_error(_('No profile specified.')); + $this->clientError(_('No profile specified.')); return false; } - $this->profile = Profile::staticGet('id', $id); - if (!$this->profile) { - $this->client_error(_('No profile with that ID.')); + $this->clientError(_('No profile with that ID.')); return false; } - return true; } - function handle($args) { + /** + * Handle request + * + * Shows a page with list of favorite notices + * + * @param array $args $_REQUEST args; handled in prepare() + * + * @return void + */ + function handle($args) + { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] == 'POST') { - if ($this->arg('block')) { - $this->are_you_sure_form(); - } else if ($this->arg('no')) { + if ($this->arg('no')) { $cur = common_current_user(); - common_redirect(common_local_url('subscribers', - array('nickname' => $cur->nickname))); - } else if ($this->arg('yes')) { - $this->block_profile(); + $other = Profile::staticGet('id', $this->arg('blockto')); + common_redirect(common_local_url('showstream', array('nickname' => $other->nickname))); + } elseif ($this->arg('yes')) { + $this->blockProfile(); + } elseif ($this->arg('blockto')) { + $this->showPage(); } } } - function are_you_sure_form() { - $id = $this->profile->id; + function showContent() { + $this->areYouSureForm(); + } - common_show_header(_('Block user')); + function title() { + return _('Block user'); + } + + function showNoticeForm() { + // nop + } - common_element('p', NULL, + /** + * Confirm with user. + * + * Shows a confirmation form. + * + * @return void + */ + function areYouSureForm() + { + $id = $this->profile->id; + $this->element('p', null, _('Are you sure you want to block this user? '. 'Afterwards, they will be unsubscribed from you, '. 'unable to subscribe to you in the future, and '. 'you will not be notified of any @-replies from them.')); - - common_element_start('form', array('id' => 'block-' . $id, + $this->elementStart('form', array('id' => 'block-' . $id, 'method' => 'post', 'class' => 'block', 'action' => common_local_url('block'))); - - common_hidden('token', common_session_token()); - - common_element('input', array('id' => 'blockto-' . $id, + $this->hidden('token', common_session_token()); + $this->element('input', array('id' => 'blockto-' . $id, 'name' => 'blockto', 'type' => 'hidden', 'value' => $id)); - foreach ($this->args as $k => $v) { if (substr($k, 0, 9) == 'returnto-') { - common_hidden($k, $v); + $this->hidden($k, $v); } } - - common_submit('no', _('No')); - common_submit('yes', _('Yes')); - - common_element_end('form'); - - common_show_footer(); + $this->submit('no', _('No')); + $this->submit('yes', _('Yes')); + $this->elementEnd('form'); } - function block_profile() { - + /** + * Actually block a user. + * + * @return void + */ + function blockProfile() + { $cur = common_current_user(); if ($cur->hasBlocked($this->profile)) { - $this->client_error(_('You have already blocked this user.')); + $this->clientError(_('You have already blocked this user.')); return; } - $result = $cur->block($this->profile); - if (!$result) { - $this->server_error(_('Failed to save block information.')); + $this->serverError(_('Failed to save block information.')); return; } - # Now, gotta figure where we go back to - + // Now, gotta figure where we go back to foreach ($this->args as $k => $v) { if ($k == 'returnto-action') { $action = $v; - } else if (substr($k, 0, 9) == 'returnto-') { + } elseif (substr($k, 0, 9) == 'returnto-') { $args[substr($k, 9)] = $v; } } @@ -143,3 +185,4 @@ class BlockAction extends Action { } } } + diff --git a/actions/confirmaddress.php b/actions/confirmaddress.php index 44280e08a..725c1f1e3 100644 --- a/actions/confirmaddress.php +++ b/actions/confirmaddress.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Confirm an address + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,81 +18,146 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Confirm + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Confirm an address + * + * When users change their SMS, email, Jabber, or other addresses, we send out + * a confirmation code to make sure the owner of that address approves. This class + * accepts those codes. + * + * @category Confirm + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +class ConfirmaddressAction extends Action +{ + /** type of confirmation. */ -class ConfirmaddressAction extends Action { + var $type = null; - function handle($args) { + /** + * Accept a confirmation code + * + * Checks the code and confirms the address in the + * user record + * + * @param args $args $_REQUEST array + * + * @return void + */ + + function handle($args) + { parent::handle($args); if (!common_logged_in()) { - common_set_returnto($this->self_url()); + common_set_returnto($this->selfUrl()); common_redirect(common_local_url('login')); return; } $code = $this->trimmed('code'); if (!$code) { - $this->client_error(_('No confirmation code.')); + $this->clientError(_('No confirmation code.')); return; } $confirm = Confirm_address::staticGet('code', $code); if (!$confirm) { - $this->client_error(_('Confirmation code not found.')); + $this->clientError(_('Confirmation code not found.')); return; } $cur = common_current_user(); if ($cur->id != $confirm->user_id) { - $this->client_error(_('That confirmation code is not for you!')); + $this->clientError(_('That confirmation code is not for you!')); + return; + } + $type = $confirm->address_type; + if (!in_array($type, array('email', 'jabber', 'sms'))) { + $this->serverError(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; - } + $this->clientError(_('That address has already been confirmed.')); + 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__); - $this->server_error(_('Couldn\'t update user.')); + common_log_db_error($cur, 'UPDATE', __FILE__); + $this->serverError(_('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__); - $this->server_error(_('Couldn\'t delete email confirmation.')); + common_log_db_error($confirm, 'DELETE', __FILE__); + $this->serverError(_('Couldn\'t delete email confirmation.')); return; } $cur->query('COMMIT'); - common_show_header(_('Confirm Address')); - common_element('p', NULL, - sprintf(_('The address "%s" has been confirmed for your account.'), $cur->$type)); - common_show_footer(); + $this->type = $type; + $this->showPage(); + } + + /** + * Title of the page + * + * @return string title + */ + + function title() + { + return _('Confirm Address'); + } + + /** + * Show a confirmation message. + * + * @return void + */ + + function showContent() + { + $cur = common_current_user(); + $type = $this->type; + + $this->element('p', null, + sprintf(_('The address "%s" has been '. + 'confirmed for your account.'), + $cur->$type)); } } diff --git a/actions/deletenotice.php b/actions/deletenotice.php index 9a5261eed..efef95441 100644 --- a/actions/deletenotice.php +++ b/actions/deletenotice.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Class for deleting a notice + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,87 +18,148 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/deleteaction.php'); - -class DeletenoticeAction extends DeleteAction { - 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(); - } - } - - 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 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_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); - - 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); - } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/deleteaction.php'; + +class DeletenoticeAction extends DeleteAction +{ + var $error = null; + + function handle($args) + { + parent::handle($args); + // XXX: Ajax! + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->deleteNotice(); + } else if ($_SERVER['REQUEST_METHOD'] == 'GET') { + $this->showForm(); + } + } + + /** + * Show the page notice + * + * Shows instructions for the page + * + * @return void + */ + + function showPageNotice() + { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + + function getInstructions() + { + return _('You are about to permanently delete a notice. ' . + 'Once this is done, it cannot be undone.'); + } + + function title() + { + return _('Delete notice'); + } + + /** + * Wrapper for showing a page + * + * Stores an error and shows the page + * + * @param string $error Error, if any + * + * @return void + */ + + function showForm($error = null) + { + $this->error = $error; + $this->showPage(); + } + + /** + * Insert delete notice form into the content + * + * @return void + */ + + function showContent() + { + $this->elementStart('form', array('id' => 'notice_delete_form', + 'method' => 'post', + 'action' => common_local_url('deletenotice'))); + $this->hidden('token', common_session_token()); + $this->hidden('notice', $this->trimmed('notice')); + $this->elementStart('p'); + $this->element('span', array('id' => 'confirmation_text'), + _('Are you sure you want to delete this notice?')); + + $this->element('input', array('id' => 'submit_no', + 'name' => 'submit', + 'type' => 'submit', + 'value' => _('No'))); + $this->element('input', array('id' => 'submit_yes', + 'name' => 'submit', + 'type' => 'submit', + 'value' => _('Yes'))); + $this->elementEnd('p'); + $this->elementEnd('form'); + } + + function deleteNotice() + { + // CSRF protection + $token = $this->trimmed('token'); + + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. ' . + ' Try again, please.')); + return; + } + + $url = common_get_returnto(); + $confirmed = $this->trimmed('submit'); + + if ($confirmed == _('Yes')) { + + $replies = new Reply; + $replies->get('notice_id', $this->notice->id); + + common_dequeue_notice($this->notice); + + if (common_config('memcached', 'enabled')) { + $notice->blowSubsCache(); + } + + $replies->delete(); + $this->notice->delete(); + + } else { + + if ($url) { + common_set_returnto(null); + } else { + $url = common_local_url('public'); + } + } + common_redirect($url); + } } diff --git a/actions/deleteprofile.php b/actions/deleteprofile.php deleted file mode 100644 index 418ac998d..000000000 --- a/actions/deleteprofile.php +++ /dev/null @@ -1,277 +0,0 @@ -<?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -if (!defined('LACONICA')) { exit(1); } - -class DeleteprofileAction extends Action { - function handle($args) { - parent::handle($args); - $this->server_error(_('Code not yet ready.')); - return; - if ('POST' === $_SERVER['REQUEST_METHOD']) { - $this->handle_post(); - } - else if ('GET' === $_SERVER['REQUEST_METHOD']) { - $this->show_form(); - } - } - - 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) { - $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_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'))); - - common_checkbox('confirmation', _('Check if you are sure you want to delete your account.')); - - 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; - } - - if ($this->arg('deleteaccount') && $this->arg('confirmation')) { - $this->delete_account(); - } - $this->show_form(); - } - - function delete_account() { - $user = common_current_user(); - assert(!is_null($user)); # should already be checked - - // deleted later through the profile - /* - $avatar = new Avatar; - $avatar->profile_id = $user->id; - $n_avatars_deleted = $avatar->delete(); - */ - - $fave = new Fave; - $fave->user_id = $user->id; - $n_faves_deleted = $fave->delete(); - - $confirmation = new Confirm_address; - $confirmation->user_id = $user->id; - $n_confirmations_deleted = $confirmation->delete(); - - // TODO foreign stuff... - - $invitation = new Invitation; - $invitation->user_id = $user->id; - $n_invitations_deleted = $invitation->delete(); - - $message_from = new Message; - $message_from->from_profile = $user->id; - $n_messages_from_deleted = $message_from->delete(); - - $message_to = new Message; - $message_to->to_profile = $user->id; - $n_messages_to_deleted = $message_to->delete(); - - $notice_inbox = new Notice_inbox; - $notice_inbox->user_id = $user->id; - $n_notices_inbox_deleted = $notice_inbox->delete(); - - $profile_tagger = new Profile_tag; - $profile_tagger->tagger = $user->id; - $n_profiles_tagger_deleted = $profile_tagger->delete(); - - $profile_tagged = new Profile_tag; - $profile_tagged->tagged = $user->id; - $n_profiles_tagged_deleted = $profile_tagged->delete(); - - $remember_me = new Remember_me; - $remember_me->user_id = $user->id; - $n_remember_mes_deleted = $remember_me->delete(); - - $reply= new Reply; - $reply->profile_id = $user->id; - $n_replies_deleted = $reply->delete(); - - // FIXME we're not removings replies to deleted notices. - // notices should take care of that themselves. - - $notice = new Notice; - $notice->profile_id = $user->id; - $n_notices_deleted = $notice->delete(); - - $subscriber = new Subscription; - $subscriber->subscriber = $user->id; - $n_subscribers_deleted = $subscriber->delete(); - - $subscribed = new Subscription; - $subscribed->subscribed = $user->id; - $n_subscribeds_deleted = $subscribed->delete(); - - $user_openid = new User_openid; - $user_openid->user_id = $user->id; - $n_user_openids_deleted = $user_openid->delete(); - - $profile = new Profile; - $profile->id = $user->id; - $profile->delete_avatars(); - $n_profiles_deleted = $profile->delete(); - $n_users_deleted = $user->delete(); - - // logout and redirect to public - 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 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'))); - - $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; - } - common_menu_item(common_local_url($menuaction), - $menudesc[0], - $menudesc[1], - $action == $menuaction); - } - common_element_end('ul'); - } -} - diff --git a/actions/disfavor.php b/actions/disfavor.php index be208f65a..09b3bf18d 100644 --- a/actions/disfavor.php +++ b/actions/disfavor.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * Disfavor action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,67 +29,79 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -class DisfavorAction 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); - - $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; - } - - $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(); +if (!defined('LACONICA')) { + exit(1); +} - if (!$result) { - common_log_db_error($fave, 'DELETE', __FILE__); - $this->server_error(_('Could not delete favorite.')); - return; - } - - $user->blowFavesCache(); +require_once INSTALLDIR.'/lib/favorform.php'; - 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))); - } - } +/** + * Disfavor class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class DisfavorAction extends Action +{ + /** + * Class handler. + * + * @param array $args query arguments + * + * @return void + */ + function handle($args) + { + parent::handle($args); + if (!common_logged_in()) { + $this->clientError(_('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); + $token = $this->trimmed('token-'.$notice->id); + if (!$token || $token != common_session_token()) { + $this->clientError(_("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->clientError(_('This notice is not a favorite!')); + return; + } + $result = $fave->delete(); + if (!$result) { + common_log_db_error($fave, 'DELETE', __FILE__); + $this->serverError(_('Could not delete favorite.')); + return; + } + $user->blowFavesCache(); + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Add to favorites')); + $this->elementEnd('head'); + $this->elementStart('body'); + $favor = new FavorForm($this, $notice); + $favor->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('showfavorites', + array('nickname' => $user->nickname))); + } + } } + diff --git a/actions/doc.php b/actions/doc.php index f3327048f..3755bb051 100644 --- a/actions/doc.php +++ b/actions/doc.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * Documentation action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,22 +29,82 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Documentation class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class DocAction extends Action +{ + var $filename; + var $title; + + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + function handle($args) + { + parent::handle($args); + $this->title = $this->trimmed('title'); + $this->filename = INSTALLDIR.'/doc/'.$this->title; + if (!file_exists($this->filename)) { + $this->clientError(_('No such document.')); + return; + } + $this->showPage(); + } + + // overrrided to add entry-title class + function showPageTitle() { + $this->element('h1', array('class' => 'entry-title'), $this->title()); + } + + // overrided to add hentry, and content-inner classes + function showContentBlock() + { + $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); + $this->showPageTitle(); + $this->showPageNoticeBlock(); + $this->elementStart('div', array('id' => 'content_inner', + 'class' => 'entry-content')); + // show the actual content (forms, lists, whatever) + $this->showContent(); + $this->elementEnd('div'); + $this->elementEnd('div'); + } -class DocAction extends Action { + /** + * Display content. + * + * @return nothing + */ + function showContent() + { + $c = file_get_contents($this->filename); + $output = common_markup_to_html($c); + $this->raw($output); + } - 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(); - } + /** + * Page title. + * + * @return page title + */ + function title() + { + return ucfirst($this->title); + } } diff --git a/actions/editgroup.php b/actions/editgroup.php new file mode 100644 index 000000000..98ebcb87a --- /dev/null +++ b/actions/editgroup.php @@ -0,0 +1,238 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Edit an existing group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Add a new group + * + * This is the form for adding a new group + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class EditgroupAction extends Action +{ + var $msg; + var $group = null; + + function title() + { + return sprintf(_('Edit %s group'), $this->group->nickname); + } + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to create a group.')); + return false; + } + + $nickname_arg = $this->trimmed('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + common_redirect(common_local_url('editgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $groupid = $this->trimmed('groupid'); + if ($groupid) { + $this->group = User_group::staticGet('id', $groupid); + } else { + $this->group = User_group::staticGet('nickname', $nickname); + } + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + $cur = common_current_user(); + + if (!$cur->isAdmin($this->group)) { + $this->clientError(_('You must be an admin to edit the group'), 403); + return false; + } + + return true; + } + + /** + * Handle the request + * + * On GET, show the form. On POST, try to save the group. + * + * @param array $args unused + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->trySave(); + } else { + $this->showForm(); + } + } + + function showForm($msg=null) + { + $this->msg = $msg; + $this->showPage(); + } + + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } + + function showContent() + { + $form = new GroupEditForm($this, $this->group); + $form->show(); + } + + function showPageNotice() + { + if ($this->msg) { + $this->element('p', 'error', $this->msg); + } else { + $this->element('p', 'instructions', + _('Use this form to edit the group.')); + } + } + + function trySave() + { + $cur = common_current_user(); + if (!$cur->isAdmin($this->group)) { + $this->clientError(_('You must be an admin to edit the group'), 403); + return; + } + + + $nickname = common_canonical_nickname($this->trimmed('nickname')); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $description = $this->trimmed('description'); + $location = $this->trimmed('location'); + + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->showForm(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.')); + return; + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } else if (!User_group::allowedNickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($description) && strlen($description) > 140) { + $this->showForm(_('description is too long (max 140 chars).')); + return; + } else if (!is_null($location) && strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } + + $orig = clone($this->group); + + $this->group->nickname = $nickname; + $this->group->fullname = $fullname; + $this->group->homepage = $homepage; + $this->group->description = $description; + $this->group->location = $location; + $this->group->created = common_sql_now(); + + $result = $this->group->update($orig); + + if (!$result) { + common_log_db_error($this->group, 'UPDATE', __FILE__); + $this->serverError(_('Could not update group.')); + } + + if ($this->group->nickname != $orig->nickname) { + common_redirect(common_local_url('editgroup', + array('nickname' => $nickname)), + 307); + } else { + $this->showForm(_('Options saved.')); + } + } + + function nicknameExists($nickname) + { + $group = User_group::staticGet('nickname', $nickname); + return (!is_null($group) && + $group != false && + $group->id != $this->group->id); + } +} + diff --git a/actions/emailsettings.php b/actions/emailsettings.php index b35b4d28e..b84acb214 100644 --- a/actions/emailsettings.php +++ b/actions/emailsettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Settings for email + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,316 +18,473 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/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; - } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; + +/** + * Settings for email + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class EmailsettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Email Settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('Manage how you get email from %%site.name%%.'); + } + + /** + * Content area of the page + * + * Shows a form for adding and removing email addresses and setting + * email preferences. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_email', + 'class' => 'form_settings', + 'action' => + common_local_url('emailsettings'))); + + $this->elementStart('fieldset', array('id' => 'settings_email_address')); + $this->element('legend', null, _('Address')); + $this->hidden('token', common_session_token()); + + if ($user->email) { + $this->element('p', array('id' => 'form_confirmed'), $user->email); + $this->element('p', array('class' => 'form_note'), _('Current confirmed email address.')); + $this->hidden('email', $user->email); + $this->submit('remove', _('Remove')); + } else { + $confirm = $this->getConfirmation(); + if ($confirm) { + $this->element('p', array('id' => 'form_unconfirmed'), $confirm->address); + $this->element('p', array('class' => 'form_note'), + _('Awaiting confirmation on this address. '. + 'Check your inbox (and spam box!) for a message '. + 'with further instructions.')); + $this->hidden('email', $confirm->address); + $this->submit('cancel', _('Cancel')); + } else { + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('email', _('Email Address'), + ($this->arg('email')) ? $this->arg('email') : null, + _('Email address, like "UserName@example.org"')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('add', _('Add')); + } + } + $this->elementEnd('fieldset'); + + if ($user->email) { + $this->elementStart('fieldset', array('id' => 'settings_email_incoming')); + $this->element('legend',_('Incoming email')); + if ($user->incomingemail) { + $this->elementStart('p'); + $this->element('span', 'address', $user->incomingemail); + $this->element('span', 'input_instructions', + _('Send email to this address to post new notices.')); + $this->elementEnd('p'); + $this->submit('removeincoming', _('Remove')); + } + + $this->elementStart('p'); + $this->element('span', 'input_instructions', + _('Make a new email address for posting to; '. + 'cancels the old one.')); + $this->elementEnd('p'); + $this->submit('newincoming', _('New')); + $this->elementEnd('fieldset'); + } + + $this->elementStart('fieldset', array('id' => 'settings_email_preferences')); + $this->element('legend', null, _('Preferences')); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->checkbox('emailnotifysub', + _('Send me notices of new subscriptions through email.'), + $user->emailnotifysub); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('emailnotifyfav', + _('Send me email when someone '. + 'adds my notice as a favorite.'), + $user->emailnotifyfav); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('emailnotifymsg', + _('Send me email when someone sends me a private message.'), + $user->emailnotifymsg); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('emailnotifynudge', + _('Allow friends to nudge me and send me an email.'), + $user->emailnotifynudge); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('emailpost', + _('I want to post notices by email.'), + $user->emailpost); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('emailmicroid', + _('Publish a MicroID for my email address.'), + $user->emailmicroid); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('save', _('Save')); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + /** + * Gets any existing email address confirmations we're waiting for + * + * @return Confirm_address Email address confirmation for user, or null + */ + + function getConfirmation() + { + $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; + } + } + + /** + * Handle posts + * + * Since there are a lot of different options on the page, we + * figure out what we're supposed to do based on which button was + * pushed + * + * @return void + */ + + function handlePost() + { + // 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->savePreferences(); + } else if ($this->arg('add')) { + $this->addAddress(); + } else if ($this->arg('cancel')) { + $this->cancelConfirmation(); + } else if ($this->arg('remove')) { + $this->removeAddress(); + } else if ($this->arg('removeincoming')) { + $this->removeIncoming(); + } else if ($this->arg('newincoming')) { + $this->newIncoming(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Save email preferences + * + * @return void + */ + + function savePreferences() + { + $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__); + $this->serverError(_('Couldn\'t update user.')); + return; + } + + $user->query('COMMIT'); + + $this->showForm(_('Preferences saved.'), true); + } + + /** + * Add the address passed in by the user + * + * @return void + */ + + function addAddress() + { + $user = common_current_user(); + + $email = $this->trimmed('email'); + + // Some validation + + if (!$email) { + $this->showForm(_('No email address.')); + return; + } + + $email = common_canonical_email($email); + + if (!$email) { + $this->showForm(_('Cannot normalize that email address')); + return; + } + if (!Validate::email($email, true)) { + $this->showForm(_('Not a valid email address')); + return; + } else if ($user->email == $email) { + $this->showForm(_('That is already your email address.')); + return; + } else if ($this->emailExists($email)) { + $this->showForm(_('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__); + $this->serverError(_('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->showForm($msg, true); + } + + /** + * Handle a request to cancel email confirmation + * + * @return void + */ + + function cancelConfirmation() + { + $email = $this->arg('email'); + + $confirm = $this->getConfirmation(); + + if (!$confirm) { + $this->showForm(_('No pending confirmation to cancel.')); + return; + } + if ($confirm->address != $email) { + $this->showForm(_('That is the wrong IM address.')); + return; + } $result = $confirm->delete(); if (!$result) { - common_log_db_error($confirm, 'DELETE', __FILE__); - $this->server_error(_('Couldn\'t delete email confirmation.')); + common_log_db_error($confirm, 'DELETE', __FILE__); + $this->serverError(_('Couldn\'t delete email confirmation.')); + return; + } + + $this->showForm(_('Confirmation cancelled.'), true); + } + + /** + * Handle a request to remove an address from the user's account + * + * @return void + */ + + function removeAddress() + { + $user = common_current_user(); + + $email = $this->arg('email'); + + // Maybe an old tab open...? + + if ($user->email != $email) { + $this->showForm(_('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__); + $this->serverError(_('Couldn\'t update user.')); + return; + } + $user->query('COMMIT'); + + $this->showForm(_('The address was removed.'), true); + } + + /** + * Handle a request to remove an incoming email address + * + * @return void + */ + + function removeIncoming() + { + $user = common_current_user(); + + if (!$user->incomingemail) { + $this->showForm(_('No incoming email address.')); 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; - } - } + $orig = clone($user); + + $user->incomingemail = null; + + if (!$user->updateKeys($orig)) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->serverError(_("Couldn't update user record.")); + } + + $this->showForm(_('Incoming email address removed.'), true); + } + + /** + * Generate a new incoming email address + * + * @return void + */ + + function newIncoming() + { + $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->serverError(_("Couldn't update user record.")); + } + + $this->showForm(_('New incoming email address added.'), true); + } + + /** + * Does another user already have this email address? + * + * Email addresses are unique for users. + * + * @param string $email Address to check + * + * @return boolean Whether the email already exists. + */ + + function emailExists($email) + { + $user = common_current_user(); + + $other = User::staticGet('email', $email); + + if (!$other) { + return false; + } else { + return $other->id != $user->id; + } + } } diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 8ee2d4cd3..9510e7f08 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -10,123 +10,315 @@ * * 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); } -require_once(INSTALLDIR.'/lib/facebookaction.php'); - -class FacebookhomeAction extends FacebookAction { - - function handle($args) { - parent::handle($args); - - $this->login(); - } - - function login() { - - $user = null; - - $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 - - if ($flink) { - - $user = $flink->getUser(); - $this->show_home($facebook, $fbuid, $user); - - } else { - - # Make the user put in her Laconica creds - $nickname = common_canonical_nickname($this->trimmed('nickname')); - $password = $this->arg('password'); - - if ($nickname) { - - if (common_check_user($nickname, $password)) { - - - $user = User::staticGet('nickname', $nickname); - - 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(); - - # $this->set_flags($flink, $noticesync, $replysync, $friendsync); - - $flink_id = $flink->insert(); - - if ($flink_id) { - echo '<fb:success message="You can now use the Identi.ca from Facebook!" />'; - } - - $this->show_home($facebook, $fbuid, $user); - - return; - } else { - echo '<fb:error message="Incorrect username or password." />'; - } - } - - $this->show_login_form(); - } - - } - - function show_home($facebook, $fbuid, $user) { - - $this->show_header('Home'); - - echo $this->show_notices($user); - $this->update_profile_box($facebook, $fbuid, $user); - - $this->show_footer(); - } - - function show_notices($user) { - - $page = $this->trimmed('page'); - if (!$page) { - $page = 1; - } - - $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - - echo '<ul id="notices">'; - - $cnt = 0; - - while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) { - $cnt++; - - if ($cnt > NOTICES_PER_PAGE) { - break; - } - - echo $this->render_notice($notice); - } - - echo '<ul>'; - - $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'index.php', array('nickname' => $user->nickname)); - - } +require_once INSTALLDIR.'/lib/facebookaction.php'; + + +class FacebookhomeAction extends FacebookAction +{ + + var $page = null; + + function prepare($argarray) + { + parent::prepare($argarray); + + $this->page = $this->trimmed('page'); + + if (!$this->page) { + $this->page = 1; + } + + return true; + } + + function handle($args) + { + parent::handle($args); + + // If the user has opted not to initially allow the app to have + // Facebook status update permission, store that preference. Only + // promt the user the first time she uses the app + if ($this->arg('skip')) { + $this->facebook->api_client->data_setUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); + } + + if ($this->flink) { + + $this->user = $this->flink->getUser(); + + // If this is the first time the user has started the app + // prompt for Facebook status update permission + if (!$this->facebook->api_client->users_hasAppPermission('status_update')) { + + if ($this->facebook->api_client->data_getUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { + $this->getUpdatePermission(); + return; + } + } + + // Make sure the user's profile box has the lastest notice + $notice = $this->user->getCurrentNotice(); + if ($notice) { + $this->updateProfileBox($notice); + } + + if ($this->arg('status_submit') == 'Send') { + $this->saveNewNotice(); + } + + // User is authenticated and has already been prompted once for + // Facebook status update permission? Then show the main page + // of the app + $this->showPage(); + + } else { + + // User hasn't authenticated yet, prompt for creds + $this->login(); + } + + } + + function login() + { + + $this->showStylesheets(); + + $nickname = common_canonical_nickname($this->trimmed('nickname')); + $password = $this->arg('password'); + + $msg = null; + + if ($nickname) { + + if (common_check_user($nickname, $password)) { + + $user = User::staticGet('nickname', $nickname); + + if (!$user) { + $this->showLoginForm(_("Server error - couldn't get user!")); + } + + $flink = DB_DataObject::factory('foreign_link'); + $flink->user_id = $user->id; + $flink->foreign_id = $this->fbuid; + $flink->service = FACEBOOK_SERVICE; + $flink->created = common_sql_now(); + $flink->set_flags(true, false, false); + + $flink_id = $flink->insert(); + + // XXX: Do some error handling here + + $this->setDefaults(); + //$this->showHome($flink, _('You can now use Identi.ca from Facebook!')); + + $this->getUpdatePermission(); + return; + + } else { + $msg = _('Incorrect username or password.'); + } + } + + $this->showLoginForm($msg); + + } + + function setDefaults() + { + // A default prefix string for notices + $this->facebook->api_client->data_setUserPreference( + FACEBOOK_NOTICE_PREFIX, 'dented: '); + $this->facebook->api_client->data_setUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF, 'false'); + } + + + function showNoticeForm() + { + + $post_action = "$this->app_uri/index.php"; + + $notice_form = new FacebookNoticeForm($this, $post_action, null, + $post_action, $this->user); + $notice_form->show(); + } + + function title() + { + if ($this->page > 1) { + return sprintf(_("%s and friends, page %d"), $this->user->nickname, $this->page); + } else { + return sprintf(_("%s and friends"), $this->user->nickname); + } + } + + function showContent() + { + + $notice = $this->user->noticesWithFriends(($this->page-1) * + NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'index.php', array('nickname' => $this->user->nickname)); + + } + + function showNoticeList($notice) + { + + $nl = new NoticeList($notice, $this); + return $nl->show(); + } + + function getUpdatePermission() { + + $this->showStylesheets(); + + $this->elementStart('div', array('class' => 'content')); + + $instructions = sprintf(_('If you would like the %s app to automatically update ' . + 'your Facebook status with your latest notice, you need ' . + 'to give it permission.'), $this->app_name); + + $this->elementStart('p'); + $this->element('span', array('id' => 'permissions_notice'), $instructions); + $this->elementEnd('p'); + + $this->elementStart('form', array('method' => 'post', + 'action' => "$app_url/index.php", + 'id' => 'facebook-skip-permissions')); + + $this->elementStart('ul', array('id' => 'fb-permissions-list')); + $this->elementStart('li', array('id' => 'fb-permissions-item')); + $this->elementStart('fb:prompt-permission', array('perms' => 'status_update', + 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/index.php" . '\')')); + $this->element('span', array('class' => 'facebook-button'), + sprintf(_('Allow %s to update my Facebook status'), $this->app_name)); + $this->elementEnd('fb:prompt-permission'); + $this->elementEnd('li'); + + $this->elementStart('li', array('id' => 'fb-permissions-item')); + $this->submit('skip', _('Skip')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementEnd('form'); + $this->elementEnd('div'); + + } + + function saveNewNotice() + { + + $user = $this->flink->getUser(); + + $content = $this->trimmed('status_textarea'); + + if (!$content) { + $this->showPage(_('No notice 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->showPage(_('That\'s too long. Max notice size is 140 chars.')); + return; + } + } + + $inter = new CommandInterpreter(); + + $cmd = $inter->handle_command($user, $content_shortened); + + if ($cmd) { + + // XXX fix this + + $cmd->execute(new WebChannel()); + return; + } + + $replyto = $this->trimmed('inreplyto'); + + $notice = Notice::saveNew($user->id, $content, + 'Facebook', 1, ($replyto == 'false') ? null : $replyto); + + if (is_string($notice)) { + $this->showPage($notice); + return; + } + + common_broadcast_notice($notice); + + } + + /** + * Generate pagination links + * + * @param boolean $have_before is there something before? + * @param boolean $have_after is there something after? + * @param integer $page current page + * @param string $action current action + * @param array $args rest of query arguments + * + * @return nothing + */ + function pagination($have_before, $have_after, $page, $action, $args=null) + { + + // Does a little before-after block for next/prev page + + // XXX: Fix so this uses common_local_url() if possible. + + if ($have_before || $have_after) { + $this->elementStart('div', array('class' => 'pagination')); + $this->elementStart('dl', null); + $this->element('dt', null, _('Pagination')); + $this->elementStart('dd', null); + $this->elementStart('ul', array('class' => 'nav')); + } + if ($have_before) { + $pargs = array('page' => $page-1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_prev')); + $this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'), + _('After')); + $this->elementEnd('li'); + } + if ($have_after) { + $pargs = array('page' => $page+1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_next')); + $this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'next'), + _('Before')); + $this->elementEnd('li'); + } + if ($have_before || $have_after) { + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + $this->elementEnd('div'); + } + } + } diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php index 68b351fb9..b7224783a 100644 --- a/actions/facebookinvite.php +++ b/actions/facebookinvite.php @@ -10,37 +10,124 @@ * * 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); } require_once(INSTALLDIR.'/lib/facebookaction.php'); -class FacebookinviteAction extends FacebookAction { +class FacebookinviteAction extends FacebookAction +{ - function handle($args) { - parent::handle($args); + function handle($args) + { + parent::handle($args); + $this->showForm(); + } - $this->display(); - } + /** + * Wrapper for showing a page + * + * Stores an error and shows the page + * + * @param string $error Error, if any + * + * @return void + */ - function display() { + function showForm($error=null) + { + $this->error = $error; + $this->showPage(); + } - $facebook = $this->get_facebook(); + /** + * Show the page content + * + * Either shows the registration form or, if registration was successful, + * instructions for using the site. + * + * @return void + */ - $fbuid = $facebook->require_login(); + function showContent() + { + if ($this->arg('ids')) { + $this->showSuccessContent(); + } else { + $this->showFormContent(); + } + } - $this->show_header('Invite'); + function showSuccessContent() + { - echo '<h2>Coming soon...</h2>'; + $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'), + common_config('site', 'name'))); + $this->element('p', null, _('Invitations have been sent to the following users:')); - $this->show_footer(); + $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to acces the list? - } + $this->elementStart("ul"); + + foreach ($friend_ids as $friend) { + $this->elementStart('li'); + $this->element('fb:profile-pic', array('uid' => $friend)); + $this->element('fb:name', array('uid' => $friend, + 'capitalize' => 'true')); + $this->elementEnd('li'); + } + + $this->elementEnd("ul"); + + } + + function showFormContent() + { + + // Get a list of users who are already using the app for exclusion + $exclude_ids = $this->facebook->api_client->friends_getAppUsers(); + + $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) . + htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>'); + + $this->elementStart('fb:request-form', array('action' => 'invite.php', + 'method' => 'post', + 'invite' => 'true', + 'type' => common_config('site', 'name'), + 'content' => $content)); + $this->hidden('invite', 'true'); + $actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name')); + $this->element('fb:multi-friend-selector', array('showborder' => 'false', + 'actiontext' => $actiontext, + 'exclude_ids' => implode(',', $exclude_ids), + 'bypass' => 'cancel')); + + $this->elementEnd('fb:request-form'); + + $this->element('h2', null, sprintf(_('Friends already using %s:'), + common_config('site', 'name'))); + $this->elementStart("ul"); + + foreach ($exclude_ids as $friend) { + $this->elementStart('li'); + $this->element('fb:profile-pic', array('uid' => $friend)); + $this->element('fb:name', array('uid' => $friend, + 'capitalize' => 'true')); + $this->elementEnd('li'); + } + + $this->elementEnd("ul"); + } + + function title() + { + return sprintf(_('Send invitations')); + } } diff --git a/actions/facebooklogin.php b/actions/facebooklogin.php new file mode 100644 index 000000000..94d494a82 --- /dev/null +++ b/actions/facebooklogin.php @@ -0,0 +1,101 @@ +<?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('LACONICA')) { exit(1); } + +require_once(INSTALLDIR.'/lib/facebookaction.php'); + +class FacebookinviteAction extends FacebookAction +{ + + function handle($args) + { + parent::handle($args); + + $this->error = $error; + + if ($this->flink) { + if (!$this->facebook->api_client->users_hasAppPermission('status_update') && + $this->facebook->api_client->data_getUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF) == 'true') { + + echo '<h1>REDIRECT TO HOME</h1>'; + } + } else { + $this->showPage(); + } + } + + + function showContent() + { + + // If the user has opted not to initially allow the app to have + // Facebook status update permission, store that preference. Only + // promt the user the first time she uses the app + if ($this->arg('skip')) { + $this->facebook->api_client->data_setUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); + } + + if ($this->flink) { + + $this->user = $this->flink->getUser(); + + // If this is the first time the user has started the app + // prompt for Facebook status update permission + if (!$this->facebook->api_client->users_hasAppPermission('status_update')) { + + if ($this->facebook->api_client->data_getUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { + $this->getUpdatePermission(); + return; + } + } + + } else { + $this->showLoginForm(); + } + + } + + function showSuccessContent() + { + + + + } + + function showFormContent() + { + + + } + + function title() + { + return sprintf(_('Login')); + } + + function redirectHome() + { + + } + +} diff --git a/actions/facebookremove.php b/actions/facebookremove.php index 2a7bdd03e..376e12a2e 100644 --- a/actions/facebookremove.php +++ b/actions/facebookremove.php @@ -10,56 +10,58 @@ * * 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); } -require_once(INSTALLDIR.'/lib/facebookaction.php'); +require_once INSTALLDIR.'/lib/facebookaction.php'; -class FacebookremoveAction extends FacebookAction { +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__); + $this->serverError(_('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/actions/facebooksettings.php b/actions/facebooksettings.php index 4d7000d60..236460c1c 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -10,43 +10,141 @@ * * 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); } -require_once(INSTALLDIR.'/lib/facebookaction.php'); +require_once INSTALLDIR.'/lib/facebookaction.php'; -class FacebooksettingsAction extends FacebookAction { +class FacebooksettingsAction extends FacebookAction +{ - function handle($args) { - parent::handle($args); + function handle($args) + { + parent::handle($args); + $this->showPage(); + } - $this->display(); - } + /** + * Show the page content + * + * Either shows the registration form or, if registration was successful, + * instructions for using the site. + * + * @return void + */ - function display() { + function showContent() + { + if ($this->arg('save')) { + $this->saveSettings(); + } else { + $this->showForm(); + } + } - $facebook = $this->get_facebook(); + function saveSettings() { - $fbuid = $facebook->require_login(); + $noticesync = $this->arg('noticesync'); + $replysync = $this->arg('replysync'); + $prefix = $this->trimmed('prefix'); - $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>'; + $original = clone($this->flink); + $this->flink->set_flags($noticesync, $replysync, false); + $result = $this->flink->update($original); + $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX, + substr($prefix, 0, 128)); - $this->show_header('Settings'); + if ($result === false) { + $this->showForm(_('There was a problem saving your sync preferences!')); + } else { + $this->showForm(_('Sync preferences saved.'), true); + } + } - echo $fbml; + function showForm($msg = null, $success = false) { - $this->show_footer(); + if ($msg) { + if ($success) { + $this->element('fb:success', array('message' => $msg)); + } else { + $this->element('fb:error', array('message' => $msg)); + } + } - } + if ($this->facebook->api_client->users_hasAppPermission('status_update')) { + + $this->elementStart('form', array('method' => 'post', + 'id' => 'facebook_settings')); + + $this->elementStart('ul', 'form_data'); + + $this->elementStart('li'); + + $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'), + ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true); + + $this->elementEnd('li'); + + $this->elementStart('li'); + + $this->checkbox('replysync', _('Send "@" replies to Facebook.'), + ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); + + $this->elementEnd('li'); + + $this->elementStart('li'); + + $prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX); + + $this->input('prefix', _('Prefix'), + ($prefix) ? $prefix : null, + _('A string to prefix notices with.')); + + $this->elementEnd('li'); + + $this->elementStart('li'); + + $this->submit('save', _('Save')); + + $this->elementEnd('li'); + + $this->elementEnd('ul'); + + $this->elementEnd('form'); + + } else { + + $instructions = sprintf(_('If you would like %s to automatically update ' . + 'your Facebook status with your latest notice, you need ' . + 'to give it permission.'), $this->app_name); + + $this->elementStart('p'); + $this->element('span', array('id' => 'permissions_notice'), $instructions); + $this->elementEnd('p'); + + $this->elementStart('ul', array('id' => 'fb-permissions-list')); + $this->elementStart('li', array('id' => 'fb-permissions-item')); + $this->elementStart('fb:prompt-permission', array('perms' => 'status_update', + 'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')')); + $this->element('span', array('class' => 'facebook-button'), + sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name'))); + $this->elementEnd('fb:prompt-permission'); + $this->elementEnd('li'); + $this->elementEnd('ul'); + } + + } + + function title() + { + return _('Sync preferences'); + } } diff --git a/actions/favor.php b/actions/favor.php index aede32902..8ecde4b11 100644 --- a/actions/favor.php +++ b/actions/favor.php @@ -1,4 +1,18 @@ <?php + +/** + * Favor action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + /* * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. @@ -17,78 +31,97 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -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))); - } - } +if (!defined('LACONICA')) { + exit(1); +} - 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 - } - } +require_once INSTALLDIR.'/lib/mail.php'; +require_once INSTALLDIR.'/lib/disfavorform.php'; +/** + * Favor class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class FavorAction extends Action +{ + /** + * Class handler. + * + * @param array $args query arguments + * + * @return void + */ + function handle($args) + { + parent::handle($args); + if (!common_logged_in()) { + $this->clientError(_('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); + $token = $this->trimmed('token-'.$notice->id); + if (!$token || $token != common_session_token()) { + $this->clientError(_("There was a problem with your session token. Try again, please.")); + return; + } + if ($user->hasFave($notice)) { + $this->clientError(_('This notice is already a favorite!')); + return; + } + $fave = Fave::addNew($user, $notice); + if (!$fave) { + $this->serverError(_('Could not create favorite.')); + return; + } + $this->notify($notice, $user); + $user->blowFavesCache(); + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Disfavor favorite')); + $this->elementEnd('head'); + $this->elementStart('body'); + $disfavor = new DisFavorForm($this, $notice); + $disfavor->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('showfavorites', + array('nickname' => $user->nickname))); + } + } + + /** + * Notifies a user when his notice is favorited. + * + * @param class $notice favorited notice + * @param class $user user declaring a favorite + * + * @return void + */ + function notify($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/actions/favorited.php b/actions/favorited.php index dc8070d06..4155b3a23 100644 --- a/actions/favorited.php +++ b/actions/favorited.php @@ -1,99 +1,195 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * List of popular notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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/>. + * + * @category Public + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/stream.php'); - -class FavoritedAction extends StreamAction { - - function handle($args) { - parent::handle($args); - - $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - - common_show_header(_('Popular notices'), - array($this, 'show_header'), NULL, - array($this, 'show_top')); - - $this->show_notices($page); - - 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_header() { - return; - } - - function get_instructions() { - return _('Showing recently popular notices'); - } - - 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'; - - $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; - } - - # Figure out how to cache this query - - $notice = new Notice; - $notice->query(sprintf($qry, common_config('popular', 'dropoff'))); - - common_element_start('ul', array('id' => 'notices')); - - $cnt = 0; - - while ($notice->fetch() && $cnt <= NOTICES_PER_PAGE) { - $cnt++; - - if ($cnt > NOTICES_PER_PAGE) { - break; - } - - $item = new NoticeListItem($notice); - $item->show(); - } +if (!defined('LACONICA')) { + exit(1); +} - common_element_end('ul'); +require_once INSTALLDIR.'/lib/publicgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'favorited'); - } +/** + * List of popular notices + * + * We provide a list of the most popular notices. Popularity + * is measured by + * + * @category Personal + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ +class FavoritedAction extends Action +{ + var $page = null; + + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + if ($this->page == 1) { + return _('Popular notices'); + } else { + return sprintf(_('Popular notices, page %d'), $this->page); + } + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('The most popular notices on the site right now.'); + } + + /** + * Is this page read-only? + * + * @return boolean true + */ + + function isReadOnly() + { + return true; + } + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + * + * @todo move queries from showContent() to here + */ + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; + } + + /** + * Handle request + * + * Shows a page with list of favorite notices + * + * @param array $args $_REQUEST args; handled in prepare() + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + $this->showPage(); + } + + /** + * Show the page notice + * + * Shows instructions for the page + * + * @return void + */ + + function showPageNotice() + { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + + /** + * Local navigation + * + * This page is part of the public group, so show that. + * + * @return void + */ + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + /** + * Content area + * + * Shows the list of popular notices + * + * @return void + */ + + function showContent() + { + $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 = ($this->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; + } + + $notice = Memcached_DataObject::cachedQuery('Notice', + sprintf($qry, common_config('popular', 'dropoff')), + 600); + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'favorited'); + } } diff --git a/actions/favoritesrss.php b/actions/favoritesrss.php index 25dd3861f..19339325c 100644 --- a/actions/favoritesrss.php +++ b/actions/favoritesrss.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * RSS feed for user favorites action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,57 +29,90 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/rssaction.php'); - -// Formatting of RSS handled by Rss10Action - -class FavoritesrssAction extends Rss10Action { +if (!defined('LACONICA')) { + exit(1); +} - var $user = NULL; - - function init() { - $nickname = $this->trimmed('nickname'); - $this->user = User::staticGet('nickname', $nickname); +require_once INSTALLDIR.'/lib/rssaction.php'; - if (!$this->user) { - common_user_error(_('No such user.')); - return false; - } else { - return true; - } - } - - function get_notices($limit=0) { - - $user = $this->user; - - $notice = $user->favoriteNotices(0, $limit); - - $notices = array(); +/** + * RSS feed for user favorites action class. + * + * Formatting of RSS handled by Rss10Action + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class FavoritesrssAction extends Rss10Action +{ + var $user = null; + + /** + * Initialization. + * + * @return boolean false if user doesn't exist + */ + function init() + { + $nickname = $this->trimmed('nickname'); + $this->user = User::staticGet('nickname', $nickname); + if (!$this->user) { + $this->clientError(_('No such user.')); + return false; + } else { + return true; + } + } - while ($notice->fetch()) { - $notices[] = clone($notice); - } + /** + * Get notices + * + * @param integer $limit max number of notices to return + * + * @return array notices + */ + function getNotices($limit=0) + { + $user = $this->user; + $notice = $user->favoriteNotices(0, $limit); + $notices = array(); + while ($notice->fetch()) { + $notices[] = clone($notice); + } + return $notices; + } - return $notices; - } + /** + * Get channel. + * + * @return array associative array on channel information + */ + function getChannel() + { + $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; - } + /** + * Get image. + * + * @return voir + */ + function getImage() + { + return null; + } +} - function get_image() { - return NULL; - } -}
\ No newline at end of file diff --git a/actions/featured.php b/actions/featured.php index 96fbd89ab..f3bade6a5 100644 --- a/actions/featured.php +++ b/actions/featured.php @@ -1,102 +1,148 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * List of featured users + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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/>. + * + * @category Public + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/stream.php'); require_once(INSTALLDIR.'/lib/profilelist.php'); +require_once INSTALLDIR.'/lib/publicgroupnav.php'; -class FeaturedAction extends StreamAction { - - function handle($args) { - parent::handle($args); - - $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - - common_show_header(_('Featured users'), - array($this, 'show_header'), NULL, - array($this, 'show_top')); - - $this->show_notices($page); - - 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_header() { - } - - function get_instructions() { - return _('Featured users'); - } - - 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 - - $featured_nicks = common_config('nickname', 'featured'); - - if (count($featured_nicks) > 0) { - - $quoted = array(); - - 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->find(); - - $profile_ids = array(); - - while ($user->fetch()) { - $profile_ids[] = $user->id; - } - - $profile = new Profile; - $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids))); - $profile->orderBy('nickname ASC'); - - $cnt = $profile->find(); - - if ($cnt > 0) { - $featured = new ProfileList($profile); - $featured->show_list(); - } - - $profile->free(); - - common_pagination($page > 1, $cnt > PROFILES_PER_PAGE, $page, 'featured'); - } - } +/** + * List of featured users + * + * @category Public + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ +class FeaturedAction extends Action +{ + var $page = null; + + function isReadOnly() + { + return true; + } + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + return true; + } + + function title() + { + if ($this->page == 1) { + return _('Featured users'); + } else { + return sprintf(_('Featured users, page %d'), $this->page); + } + } + + function handle($args) + { + parent::handle($args); + + $this->showPage(); + } + + function showPageNotice() + { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + function getInstructions() + { + return sprintf(_('A selection of some of the great users on %s'), + common_config('site', 'name')); + } + + function showContent() + { + // 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'); + + if (count($featured_nicks) > 0) { + + $quoted = array(); + + foreach ($featured_nicks as $nick) { + $quoted[] = "'$nick'"; + } + + $user = new User; + $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted))); + $user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1); + $user->orderBy('user.nickname ASC'); + + $user->find(); + + $profile_ids = array(); + + while ($user->fetch()) { + $profile_ids[] = $user->id; + } + + $profile = new Profile; + $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids))); + $profile->orderBy('nickname ASC'); + + $cnt = $profile->find(); + + if ($cnt > 0) { + $featured = new ProfileList($profile, null, $this); + $featured->show(); + } + + $profile->free(); + + $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, + $this->page, 'featured'); + } + } }
\ No newline at end of file diff --git a/actions/finishaddopenid.php b/actions/finishaddopenid.php index 54d81b0b4..8f10505cf 100644 --- a/actions/finishaddopenid.php +++ b/actions/finishaddopenid.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Complete adding an OpenID + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,89 +18,168 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/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'); +if (!defined('LACONICA')) { + exit(1); +} - oid_set_last($display); +require_once INSTALLDIR.'/lib/openid.php'; - common_redirect(common_local_url('openidsettings')); - } - } +/** + * Complete adding an OpenID + * + * Handle the return from an OpenID verification + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - function message($msg) { - common_show_header(_('OpenID Login')); - common_element('p', NULL, $msg); - common_show_footer(); - } +class FinishaddopenidAction extends Action +{ + var $msg = null; + + /** + * Handle the redirect back from OpenID confirmation + * + * Check to see if the user's logged in, and then try + * to use the OpenID login system. + * + * @param array $args $_REQUEST arguments + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + if (!common_logged_in()) { + $this->clientError(_('Not logged in.')); + } else { + $this->tryLogin(); + } + } + + /** + * Try to log in using OpenID + * + * Check the OpenID for validity; potentially store it. + * + * @return void + */ + + function tryLogin() + { + $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')); + } + } + + /** + * Show a failure message + * + * Something went wrong. Save the message, and show the page. + * + * @param string $msg Error message to show + * + * @return void + */ + + function message($msg) + { + $this->message = $msg; + $this->showPage(); + } + + /** + * Title of the page + * + * @return string title + */ + + function title() + { + return _('OpenID Login'); + } + + /** + * Show error message + * + * @return void + */ + + function showPageNotice() + { + if ($this->message) { + $this->element('p', 'error', $this->message); + } + } } diff --git a/actions/finishimmediate.php b/actions/finishimmediate.php deleted file mode 100644 index 6dbaa3d1c..000000000 --- a/actions/finishimmediate.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/openid.php'); - -class FinishimmediateAction extends Action { - - function handle($args) { - parent::handle($args); - - $consumer = oid_consumer(); - - $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(); - - $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; - } - } - - # Failure! Clear openid so we don't try it again - - 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); - } -} diff --git a/actions/finishopenidlogin.php b/actions/finishopenidlogin.php index 766a08b20..880a9505b 100644 --- a/actions/finishopenidlogin.php +++ b/actions/finishopenidlogin.php @@ -21,416 +21,447 @@ if (!defined('LACONICA')) { exit(1); } 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); - } - 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() { +class FinishopenidloginAction extends Action +{ + var $error = null; + var $username = null; + var $message = null; + + function handle($args) + { + parent::handle($args); + if (common_logged_in()) { + $this->clientError(_('Already logged in.')); + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. Try again, please.')); + return; + } + if ($this->arg('create')) { + if (!$this->boolean('license')) { + $this->showForm(_('You can\'t register if you don\'t agree to the license.'), + $this->trimmed('newname')); + return; + } + $this->createNewUser(); + } else if ($this->arg('connect')) { + $this->connectUser(); + } else { + common_debug(print_r($this->args, true), __FILE__); + $this->showForm(_('Something weird happened.'), + $this->trimmed('newname')); + } + } else { + $this->tryLogin(); + } + } + + function showPageNotice() + { + if ($this->error) { + $this->element('div', array('class' => 'error'), $this->error); + } else { + global $config; + $this->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 title() + { + return _('OpenID Account Setup'); + } + + function showForm($error=null, $username=null) + { + $this->error = $error; + $this->username = $username; + + $this->showPage(); + } + + function showContent() + { + if ($this->message_text) { + $this->element('p', null, $this->message); + return; + } + $this->elementStart('form', array('method' => 'post', + 'id' => 'account_connect', + 'action' => common_local_url('finishopenidlogin'))); + $this->hidden('token', common_session_token()); + $this->element('h2', null, + _('Create new account')); + $this->element('p', null, + _('Create a new user with this nickname.')); + $this->input('newname', _('New nickname'), + ($this->username) ? $this->username : '', + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->elementStart('p'); + $this->element('input', array('type' => 'checkbox', + 'id' => 'license', + 'name' => 'license', + 'value' => 'true')); + $this->text(_('My text and files are available under ')); + $this->element('a', array('href' => common_config('license', 'url')), + common_config('license', 'title')); + $this->text(_(' except this private data: password, email address, IM address, phone number.')); + $this->elementEnd('p'); + $this->submit('create', _('Create')); + $this->element('h2', null, + _('Connect existing account')); + $this->element('p', null, + _('If you already have an account, login with your username and password to connect it to your OpenID.')); + $this->input('nickname', _('Existing nickname')); + $this->password('password', _('Password')); + $this->submit('connect', _('Connect')); + $this->elementEnd('form'); + } + + function tryLogin() + { + $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->goHome($user->nickname); + } else { + $this->saveValues($display, $canonical, $sreg); + $this->showForm(null, $this->bestNewNickname($display, $sreg)); + } + } + } + + function message($msg) + { + $this->message_text = $msg; + $this->showPage(); + } + + function saveValues($display, $canonical, $sreg) + { + common_ensure_session(); + $_SESSION['openid_display'] = $display; + $_SESSION['openid_canonical'] = $canonical; + $_SESSION['openid_sreg'] = $sreg; + } + + function getSavedValues() + { + return array($_SESSION['openid_display'], + $_SESSION['openid_canonical'], + $_SESSION['openid_sreg']); + } + + function createNewUser() + { # 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')) { + $this->clientError(_('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->showForm(_('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->showForm(_('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->showForm(_('Nickname already in use. Try another one.')); + return; + } - list($display, $canonical, $sreg) = $this->get_saved_values(); + list($display, $canonical, $sreg) = $this->getSavedValues(); - if (!$display || !$canonical) { - common_server_error(_('Stored OpenID not found.')); - return; - } + if (!$display || !$canonical) { + $this->serverError(_('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) { + $this->serverError(_('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))); - } - - function connect_user() { + common_redirect(common_local_url('showstream', array('nickname' => $user->nickname))); + } - $nickname = $this->trimmed('nickname'); - $password = $this->trimmed('password'); + function connectUser() + { + $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->showForm(_('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->getSavedValues(); - if (!$display || !$canonical) { - common_server_error(_('Stored OpenID not found.')); - return; - } + if (!$display || !$canonical) { + $this->serverError(_('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) { + $this->serverError(_('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->goHome($user->nickname); + } + + function goHome($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 bestNewNickname($display, $sreg) + { + + # Try the passed-in nickname + + if ($sreg['nickname']) { + $nickname = $this->nicknamize($sreg['nickname']); + if ($this->isNewNickname($nickname)) { + return $nickname; + } + } + + # Try the full name + + if ($sreg['fullname']) { + $fullname = $this->nicknamize($sreg['fullname']); + if ($this->isNewNickname($fullname)) { + return $fullname; + } + } + + # Try the URL + + $from_url = $this->openidToNickname($display); + + if ($from_url && $this->isNewNickname($from_url)) { + return $from_url; + } + + # XXX: others? + + return null; + } + + function isNewNickname($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 openidToNickname($openid) + { if (Auth_Yadis_identifierScheme($openid) == 'XRI') { - 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 - - 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); - } + return $this->xriToNickname($openid); + } else { + return $this->urlToNickname($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 + + function urlToNickname($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 xriToNickname($xri) + { + $base = $this->xriBase($xri); + + if (!$base) { + return null; + } else { + # =evan.prodromou + # or @gratis*evan.prodromou + $parts = explode('*', substr($base, 1)); + return $this->nicknamize(array_pop($parts)); + } + } + + function xriBase($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/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php index 58040683f..f9094a50c 100644 --- a/actions/finishremotesubscribe.php +++ b/actions/finishremotesubscribe.php @@ -21,176 +21,178 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/omb.php'); -class FinishremotesubscribeAction extends Action { +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()) { + $this->clientError(_('You can use the local subscription!')); + return; + } + + $omb = $_SESSION['oauth_authorization_request']; + + if (!$omb) { + $this->clientError(_('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']) { + $this->clientError(_('Not authorized.')); + return; + } - common_remove_magic_from_request(); - $req = OAuthRequest::from_request(); + $version = $req->get_parameter('omb_version'); + + if ($version != OMB_VERSION_01) { + $this->clientError(_('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) { + $this->clientError(_('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) { + $this->clientError(_('No profile URL returned by server.')); + return; + } + + if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) { + $this->clientError(_('Invalid profile URL returned by server.')); + return; + } + + if ($profile_url == common_local_url('showstream', array('nickname' => $nickname))) { + $this->clientError(_('You can use the local subscription!')); + return; + } + + common_debug('listenee: "'.$omb['listenee'].'"', __FILE__); + + $user = User::staticGet('nickname', $omb['listenee']); + + if (!$user) { + $this->clientError(_('User being listened to doesn\'t exist.')); + return; + } + + $other = User::staticGet('uri', $omb['listener']); + + if ($other) { + $this->clientError(_('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) { + $this->clientError(_('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) { + $this->serverError(_('Error inserting new profile')); + return; + } + $remote->id = $id; + } + + if ($avatar_url) { + if (!$this->add_avatar($profile, $avatar_url)) { + $this->serverError(_('Error inserting avatar')); + return; + } + } + + $remote->postnoticeurl = $omb['post_notice_url']; + $remote->updateprofileurl = $omb['update_profile_url']; + + if ($exists) { + if (!$remote->update($orig_remote)) { + $this->serverError(_('Error updating remote profile')); + return; + } + } else { + $remote->created = DB_DataObject_Cast::dateTime(); # current time + if (!$remote->insert()) { + $this->serverError(_('Error inserting remote profile')); + return; + } + } if ($user->hasBlocked($profile)) { - $this->client_error(_('That user has blocked you from subscribing.')); + $this->clientError(_('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 +204,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 +213,80 @@ 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; - } + $this->clientError(_('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/actions/foaf.php b/actions/foaf.php index 6811fc05a..3a99835b4 100644 --- a/actions/foaf.php +++ b/actions/foaf.php @@ -23,180 +23,191 @@ define('LISTENER', 1); define('LISTENEE', -1); 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'); - } +class FoafAction extends Action +{ + function isReadOnly() + { + return true; + } + + function prepare($args) + { + parent::prepare($args); + $this->nickname = $this->trimmed('nickname'); + + $this->user = User::staticGet('nickname', $this->nickname); + + if (!$this->user) { + $this->clientError(_('No such user.'), 404); + return false; + } + + $this->profile = $this->user->getProfile(); + + if (!$this->profile) { + $this->serverError(_('User has no profile.'), 500); + return false; + } + + return true; + } + + function handle($args) + { + parent::handle($args); + + header('Content-Type: application/rdf+xml'); + + $this->startXML(); + $this->elementStart('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->showPpd('', $this->user->uri); + + // XXX: might not be a person + $this->elementStart('Person', array('rdf:about' => + $this->user->uri)); + $this->element('mbox_sha1sum', null, sha1('mailto:' . $this->user->email)); + if ($this->profile->fullname) { + $this->element('name', null, $this->profile->fullname); + } + if ($this->profile->homepage) { + $this->element('homepage', array('rdf:resource' => $this->profile->homepage)); + } + if ($this->profile->bio) { + $this->element('rdfs:comment', null, $this->profile->bio); + } + // XXX: more structured location data + if ($this->profile->location) { + $this->elementStart('based_near'); + $this->elementStart('geo:SpatialThing'); + $this->element('name', null, $this->profile->location); + $this->elementEnd('geo:SpatialThing'); + $this->elementEnd('based_near'); + } + + $this->showMicrobloggingAccount($this->profile, common_root_url()); + + $avatar = $this->profile->getOriginalAvatar(); + + if ($avatar) { + $this->elementStart('img'); + $this->elementStart('Image', array('rdf:about' => $avatar->url)); + foreach (array(AVATAR_PROFILE_SIZE, AVATAR_STREAM_SIZE, AVATAR_MINI_SIZE) as $size) { + $scaled = $this->profile->getAvatar($size); + if (!$scaled->original) { // sometimes the original has one of our scaled sizes + $this->elementStart('thumbnail'); + $this->element('Image', array('rdf:about' => $scaled->url)); + $this->elementEnd('thumbnail'); + } + } + $this->elementEnd('Image'); + $this->elementEnd('img'); + } + + // Get people user is subscribed to + + $person = array(); + + $sub = new Subscription(); + $sub->subscriber = $this->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; + } + $this->element('knows', array('rdf:resource' => $other->uri)); + $person[$other->uri] = array(LISTENEE, $other); + } + } + + // Get people who subscribe to user + + $sub = new Subscription(); + $sub->subscribed = $this->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); + } + } + } + + $this->elementEnd('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)); + } + $this->profile = Profile::staticGet($p[1]->id); + $this->elementStart('Person', array('rdf:about' => $uri)); + if ($p[0] == LISTENER || $p[0] == BOTH) { + $this->element('knows', array('rdf:resource' => $this->user->uri)); + } + $this->showMicrobloggingAccount($this->profile, ($p[1] instanceof User) ? + common_root_url() : null); + if ($foaf_url) { + $this->element('rdfs:seeAlso', array('rdf:resource' => $foaf_url)); + } + $this->elementEnd('Person'); + if ($foaf_url) { + $this->showPpd($foaf_url, $uri); + } + } + + $this->elementEnd('rdf:RDF'); + $this->endXML(); + } + + function showPpd($foaf_url, $person_uri) + { + $this->elementStart('PersonalProfileDocument', array('rdf:about' => $foaf_url)); + $this->element('maker', array('rdf:resource' => $person_uri)); + $this->element('primaryTopic', array('rdf:resource' => $person_uri)); + $this->elementEnd('PersonalProfileDocument'); + } + + function showMicrobloggingAccount($profile, $service=null) + { + // Their account + $this->elementStart('holdsAccount'); + $this->elementStart('OnlineAccount'); + if ($service) { + $this->element('accountServiceHomepage', array('rdf:resource' => + $service)); + } + $this->element('accountName', null, $profile->nickname); + $this->element('homepage', array('rdf:resource' => $profile->profileurl)); + $this->elementEnd('OnlineAccount'); + $this->elementEnd('holdsAccount'); + } } diff --git a/actions/groupbyid.php b/actions/groupbyid.php new file mode 100644 index 000000000..678119a94 --- /dev/null +++ b/actions/groupbyid.php @@ -0,0 +1,108 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Permalink for group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; + +/** + * Permalink for a group + * + * The group nickname can change, but not the group ID. So we use + * an URL with the ID in it as the permanent identifier. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupbyidAction extends Action +{ + /** group we're viewing. */ + var $group = null; + + /** + * Is this page read-only? + * + * @return boolean true + */ + + function isReadOnly() + { + return true; + } + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + $id = $this->arg('id'); + + if (!$id) { + $this->clientError(_('No ID')); + return false; + } + + common_debug("Got ID $id"); + + $this->group = User_group::staticGet('id', $id); + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + return true; + } + + /** + * Handle the request + * + * Shows a profile for the group, some controls, and a list of + * group notices. + * + * @return void + */ + + function handle($args) + { + common_redirect($this->group->homeUrl(), 303); + } +}
\ No newline at end of file diff --git a/actions/grouplogo.php b/actions/grouplogo.php new file mode 100644 index 000000000..393070d5d --- /dev/null +++ b/actions/grouplogo.php @@ -0,0 +1,511 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Upload an avatar + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; + +/** + * Upload an avatar + * + * We use jCrop plugin for jQuery to crop the image after upload. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GrouplogoAction extends Action +{ + var $mode = null; + var $imagefile = null; + var $filename = null; + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to create a group.')); + return false; + } + + $nickname_arg = $this->trimmed('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + common_redirect(common_local_url('editgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $groupid = $this->trimmed('groupid'); + + if ($groupid) { + $this->group = User_group::staticGet('id', $groupid); + } else { + $this->group = User_group::staticGet('nickname', $nickname); + } + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + $cur = common_current_user(); + + if (!$cur->isAdmin($this->group)) { + $this->clientError(_('You must be an admin to edit the group'), 403); + return false; + } + + return true; + } + + function handle($args) + { + parent::handle($args); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->handlePost(); + } else { + $this->showForm(); + } + } + + function showForm($msg = null) + { + $this->msg = $msg; + $this->showPage(); + } + + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Group logo'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('You can upload a logo image for your group.'); + } + + /** + * Content area of the page + * + * Shows a form for uploading an avatar. + * + * @return void + */ + + function showContent() + { + if ($this->mode == 'crop') { + $this->showCropForm(); + } else { + $this->showUploadForm(); + } + } + + function showUploadForm() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('User without matching profile')); + return; + } + + $original = $this->group->original_logo; + + $this->elementStart('form', array('enctype' => 'multipart/form-data', + 'method' => 'post', + 'id' => 'form_settings_logo', + 'class' => 'form_settings', + 'action' => + common_local_url('grouplogo', + array('nickname' => $this->group->nickname)))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Group logo')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + if ($original) { + $this->elementStart('li', array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => $this->group->original_logo, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + if ($this->group->homepage_logo) { + $this->elementStart('li', array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => $this->group->homepage_logo, + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + } + + $this->elementStart('li', array ('id' => 'settings_attach')); + $this->element('input', array('name' => 'avatarfile', + 'type' => 'file', + 'id' => 'avatarfile')); + $this->element('input', array('name' => 'MAX_FILE_SIZE', + 'type' => 'hidden', + 'id' => 'MAX_FILE_SIZE', + 'value' => MAX_AVATAR_SIZE)); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementStart('ul', 'form_actions'); + $this->elementStart('li'); + $this->submit('upload', _('Upload')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + function showCropForm() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_avatar', + 'class' => 'form_settings', + 'action' => + common_local_url('grouplogo', + array('nickname' => $this->group->nickname)))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Avatar settings')); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + + $this->elementStart('li', + array('id' => 'avatar_original', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Original")); + $this->elementStart('div', array('id'=>'avatar_original_view')); + $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + 'width' => $this->filedata['width'], + 'height' => $this->filedata['height'], + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + $this->elementEnd('li'); + + $this->elementStart('li', + array('id' => 'avatar_preview', + 'class' => 'avatar_view')); + $this->element('h2', null, _("Preview")); + $this->elementStart('div', array('id'=>'avatar_preview_view')); + $this->element('img', array('src' => common_avatar_url($this->filedata['filename']), + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); + $this->elementEnd('div'); + + foreach (array('avatar_crop_x', 'avatar_crop_y', + 'avatar_crop_w', 'avatar_crop_h') as $crop_info) { + $this->element('input', array('name' => $crop_info, + 'type' => 'hidden', + 'id' => $crop_info)); + } + $this->submit('crop', _('Crop')); + + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + /** + * Handle a post + * + * We mux on the button name to figure out what the user actually wanted. + * + * @return void + */ + + function handlePost() + { + // 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('upload')) { + $this->uploadAvatar(); + } else if ($this->arg('crop')) { + $this->cropAvatar(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Handle an image upload + * + * Does all the magic for handling an image upload, and crops the + * image by default. + * + * @return void + */ + + function uploadAvatar() + { + try { + $imagefile = ImageFile::fromUpload('avatarfile'); + } catch (Exception $e) { + $this->showForm($e->getMessage()); + return; + } + + $filename = common_avatar_filename($this->group->id, + image_type_to_extension($imagefile->type), + null, + 'group-temp-'.common_timestamp()); + + $filepath = common_avatar_path($filename); + + move_uploaded_file($imagefile->filename, $filepath); + + $filedata = array('filename' => $filename, + 'filepath' => $filepath, + 'width' => $imagefile->width, + 'height' => $imagefile->height, + 'type' => $imagefile->type); + + $_SESSION['FILEDATA'] = $filedata; + + $this->filedata = $filedata; + + $this->mode = 'crop'; + + $this->showForm(_('Pick a square area of the image to be your avatar'), + true); + } + + /** + * Handle the results of jcrop. + * + * @return void + */ + + function cropAvatar() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + $x = $this->arg('avatar_crop_x'); + $y = $this->arg('avatar_crop_y'); + $w = $this->arg('avatar_crop_w'); + $h = $this->arg('avatar_crop_h'); + + $filedata = $_SESSION['FILEDATA']; + + if (!$filedata) { + $this->serverError(_('Lost our file data.')); + return; + } + + $filepath = common_avatar_path($filedata['filename']); + + if (!file_exists($filepath)) { + $this->serverError(_('Lost our file.')); + return; + } + + switch ($filedata['type']) { + case IMAGETYPE_GIF: + $image_src = imagecreatefromgif($filepath); + break; + case IMAGETYPE_JPEG: + $image_src = imagecreatefromjpeg($filepath); + break; + case IMAGETYPE_PNG: + $image_src = imagecreatefrompng($filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + common_debug("W = $w, H = $h, X = $x, Y = $y"); + + $image_dest = imagecreatetruecolor($w, $h); + + $background = imagecolorallocate($image_dest, 0, 0, 0); + ImageColorTransparent($image_dest, $background); + imagealphablending($image_dest, false); + + imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $w, $h, $w, $h); + + $cur = common_current_user(); + + $filename = common_avatar_filename($this->group->id, + image_type_to_extension($imagefile->type), + null, + 'group-'.common_timestamp()); + + $filepath = common_avatar_path($filename); + + switch ($filedata['type']) { + case IMAGETYPE_GIF: + imagegif($image_dest, $filepath); + break; + case IMAGETYPE_JPEG: + imagejpeg($image_dest, $filepath); + break; + case IMAGETYPE_PNG: + imagepng($image_dest, $filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + if ($this->group->setOriginal($filename, $filedata['type'])) { + @unlink(common_avatar_path($filedata['filename'])); + unset($_SESSION['FILEDATA']); + $this->mode = 'upload'; + $this->showForm(_('Logo updated.'), true); + } else { + $this->showForm(_('Failed updating logo.')); + } + } + + function showPageNotice() + { + if ($this->msg) { + $this->element('div', ($this->success) ? 'success' : 'error', + $this->msg); + } else { + $inst = $this->getInstructions(); + $output = common_markup_to_html($inst); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } + + /** + * Add the jCrop stylesheet + * + * @return void + */ + + function showStylesheets() + { + parent::showStylesheets(); + $jcropStyle = + common_path('theme/base/css/jquery.Jcrop.css?version='.LACONICA_VERSION); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => $jcropStyle, + 'media' => 'screen, projection, tv')); + } + + /** + * Add the jCrop scripts + * + * @return void + */ + + function showScripts() + { + parent::showScripts(); + + $jcropPack = common_path('js/jcrop/jquery.Jcrop.pack.js'); + $jcropGo = common_path('js/jcrop/jquery.Jcrop.go.js'); + + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropPack)); + $this->element('script', array('type' => 'text/javascript', + 'src' => $jcropGo)); + } + + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } +} diff --git a/actions/groupmembers.php b/actions/groupmembers.php new file mode 100644 index 000000000..53395c418 --- /dev/null +++ b/actions/groupmembers.php @@ -0,0 +1,138 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * List of group members + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once(INSTALLDIR.'/lib/profilelist.php'); +require_once INSTALLDIR.'/lib/publicgroupnav.php'; + +/** + * List of group members + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupmembersAction extends Action +{ + var $page = null; + + function isReadOnly() + { + return true; + } + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + $nickname_arg = $this->arg('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + if ($this->page != 1) { + $args['page'] = $this->page; + } + common_redirect(common_local_url('groupmembers', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $this->group = User_group::staticGet('nickname', $nickname); + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + return true; + } + + function title() + { + if ($this->page == 1) { + return sprintf(_('%s group members'), + $this->group->nickname); + } else { + return sprintf(_('%s group members, page %d'), + $this->group->nickname, + $this->page); + } + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showPageNotice() + { + $this->element('p', 'instructions', + _('A list of the users in this group.')); + } + + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } + + function showContent() + { + $offset = ($this->page-1) * PROFILES_PER_PAGE; + $limit = PROFILES_PER_PAGE + 1; + + $members = $this->group->getMembers($offset, $limit); + + if ($members) { + $member_list = new ProfileList($members, null, $this); + $member_list->show(); + } + + $members->free(); + + $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, + $this->page, 'groupmembers', + array('nickname' => $this->group->nickname)); + } +}
\ No newline at end of file diff --git a/actions/groups.php b/actions/groups.php new file mode 100644 index 000000000..261f9b3aa --- /dev/null +++ b/actions/groups.php @@ -0,0 +1,127 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Latest groups information + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/grouplist.php'; + +/** + * Latest groups + * + * Show the latest groups on the site + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupsAction extends Action +{ + var $page = null; + var $profile = null; + + function title() + { + if ($this->page == 1) { + return _("Groups"); + } else { + return sprintf(_("Groups, page %d"), $this->page); + } + } + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + function showPageNotice() + { + $notice = + sprintf(_('%%%%site.name%%%% groups let you find and talk with ' . + 'people of similar interests. After you join a group ' . + 'you can send messages to all other members using the ' . + 'syntax "!groupname". Don\'t see a group you like? Try ' . + '[searching for one](%%%%action.groupsearch%%%%) or ' . + '[start your own!](%%%%action.newgroup%%%%)')); + $this->elementStart('div', 'instructions'); + $this->raw(common_markup_to_html($notice)); + $this->elementEnd('div'); + } + + function showContent() + { + $this->elementStart('p', array('id' => 'new_group')); + $this->element('a', array('href' => common_local_url('newgroup'), + 'class' => 'more'), + _('Create a new group')); + $this->elementEnd('p'); + + $offset = ($this->page-1) * GROUPS_PER_PAGE; + $limit = GROUPS_PER_PAGE + 1; + + $groups = new User_group(); + $groups->orderBy('created DESC'); + $groups->limit($offset, $limit); + + if ($groups->find()) { + $gl = new GroupList($groups, null, $this); + $cnt = $gl->show(); + } + + $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE, + $this->page, 'groups'); + } + + function showSections() + { + $gbp = new GroupsByPostsSection($this); + $gbp->show(); + $gbm = new GroupsByMembersSection($this); + $gbm->show(); + } +} diff --git a/actions/imsettings.php b/actions/imsettings.php index 0aa7631dc..e0f5ede3a 100644 --- a/actions/imsettings.php +++ b/actions/imsettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Settings for Jabber/XMPP integration + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,256 +18,410 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/settingsaction.php'); -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; - } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/connectsettingsaction.php'; +require_once INSTALLDIR.'/lib/jabber.php'; + +/** + * Settings for Jabber/XMPP integration + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see SettingsAction + */ + +class ImsettingsAction extends ConnectSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('IM Settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('You can send and receive notices through '. + 'Jabber/GTalk [instant messages](%%doc.im%%). '. + 'Configure your address and settings below.'); + } + + /** + * Content area of the page + * + * We make different sections of the form for the different kinds of + * functions, and have submit buttons with different names. These + * are muxed by handlePost() to see what the user really wants to do. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_im', + 'class' => 'form_settings', + 'action' => + common_local_url('imsettings'))); + $this->elementStart('fieldset', array('id' => 'settings_im_address')); + $this->element('legend', null, _('Address')); + $this->hidden('token', common_session_token()); + + if ($user->jabber) { + $this->element('p', 'form_confirmed', $user->jabber); + $this->element('p', 'form_note', + _('Current confirmed Jabber/GTalk address.')); + $this->hidden('jabber', $user->jabber); + $this->submit('remove', _('Remove')); + } else { + $confirm = $this->getConfirmation(); + if ($confirm) { + $this->element('p', 'form_unconfirmed', $confirm->address); + $this->element('p', 'form_note', + 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())); + $this->hidden('jabber', $confirm->address); + $this->submit('cancel', _('Cancel')); + } else { + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->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())); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('add', _('Add')); + } + } + $this->elementEnd('fieldset'); + + $this->elementStart('fieldset', array('id' => 'settings_im_preferences')); + $this->element('legend', null, _('Preferences')); + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->checkbox('jabbernotify', + _('Send me notices through Jabber/GTalk.'), + $user->jabbernotify); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('updatefrompresence', + _('Post a notice when my Jabber/GTalk status changes.'), + $user->updatefrompresence); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('jabberreplies', + _('Send me replies through Jabber/GTalk '. + 'from people I\'m not subscribed to.'), + $user->jabberreplies); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('jabbermicroid', + _('Publish a MicroID for my Jabber/GTalk address.'), + $user->jabbermicroid); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('save', _('Save')); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + /** + * Get a confirmation code for this user + * + * @return Confirm_address address object for this user + */ + + function getConfirmation() + { + $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; + } + } + + /** + * Handle posts to this form + * + * Based on the button that was pressed, muxes out to other functions + * to do the actual task requested. + * + * All sub-functions reload the form with a message -- success or failure. + * + * @return void + */ + + function handlePost() + { + // CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + if ($this->arg('save')) { + $this->savePreferences(); + } else if ($this->arg('add')) { + $this->addAddress(); + } else if ($this->arg('cancel')) { + $this->cancelConfirmation(); + } else if ($this->arg('remove')) { + $this->removeAddress(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Save user's Jabber preferences + * + * These are the checkboxes at the bottom of the page. They're used to + * set different settings + * + * @return void + */ + + function savePreferences() + { + + $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__); + $this->serverError(_('Couldn\'t update user.')); + return; + } + + $user->query('COMMIT'); + + $this->showForm(_('Preferences saved.'), true); + } + + /** + * Sends a confirmation to the address given + * + * Stores a confirmation record and sends out a + * Jabber message with the confirmation info. + * + * @return void + */ + + function addAddress() + { + $user = common_current_user(); + + $jabber = $this->trimmed('jabber'); + + // Some validation + + if (!$jabber) { + $this->showForm(_('No Jabber ID.')); + return; + } + + $jabber = jabber_normalize_jid($jabber); + + if (!$jabber) { + $this->showForm(_('Cannot normalize that Jabber ID')); + return; + } + if (!jabber_valid_base_jid($jabber)) { + $this->showForm(_('Not a valid Jabber ID')); + return; + } else if ($user->jabber == $jabber) { + $this->showForm(_('That is already your Jabber ID.')); + return; + } else if ($this->jabberExists($jabber)) { + $this->showForm(_('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__); + $this->serverError(_('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->showForm($msg, true); + } + + /** + * Cancel a confirmation + * + * If a confirmation exists, cancel it. + * + * @return void + */ + + function cancelConfirmation() + { + $jabber = $this->arg('jabber'); + + $confirm = $this->getConfirmation(); + + if (!$confirm) { + $this->showForm(_('No pending confirmation to cancel.')); + return; + } + if ($confirm->address != $jabber) { + $this->showForm(_('That is the wrong IM address.')); + return; + } $result = $confirm->delete(); if (!$result) { - common_log_db_error($confirm, 'DELETE', __FILE__); - $this->server_error(_('Couldn\'t delete email confirmation.')); + common_log_db_error($confirm, 'DELETE', __FILE__); + $this->serverError(_('Couldn\'t delete email confirmation.')); + return; + } + + $this->showForm(_('Confirmation cancelled.'), true); + } + + /** + * Remove an address + * + * If the user has a confirmed address, remove it. + * + * @return void + */ + + function removeAddress() + { + $user = common_current_user(); + + $jabber = $this->arg('jabber'); + + // Maybe an old tab open...? + + if ($user->jabber != $jabber) { + $this->showForm(_('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__); + $this->serverError(_('Couldn\'t update user.')); return; } + $user->query('COMMIT'); + + // XXX: unsubscribe to the old address - $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; - } - } + $this->showForm(_('The address was removed.'), true); + } + + /** + * Does this Jabber ID exist? + * + * Checks if we already have another user with this address. + * + * @param string $jabber Address to check + * + * @return boolean whether the Jabber ID exists + */ + + function jabberExists($jabber) + { + $user = common_current_user(); + + $other = User::staticGet('jabber', $jabber); + + if (!$other) { + return false; + } else { + return $other->id != $user->id; + } + } } diff --git a/actions/inbox.php b/actions/inbox.php index c752e404e..b553ab26c 100644 --- a/actions/inbox.php +++ b/actions/inbox.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * action handler for message inbox + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,41 +18,100 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Message + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/mailbox.php'; + +/** + * action handler for message inbox + * + * @category Message + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see MailboxAction */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/mailbox.php'); - -class InboxAction extends MailboxAction { - - function get_title($user, $page) { - if ($page > 1) { - $title = sprintf(_("Inbox for %s - page %d"), $user->nickname, $page); - } else { - $title = sprintf(_("Inbox for %s"), $user->nickname); - } - return $title; - } - - function get_messages($user, $page) { - $message = new Message(); - $message->to_profile = $user->id; - $message->orderBy('created DESC, id DESC'); - $message->limit((($page-1)*MESSAGES_PER_PAGE), MESSAGES_PER_PAGE + 1); - - if ($message->find()) { - return $message; - } else { - return NULL; - } - } - - function get_message_profile($message) { - return $message->getFrom(); - } - - function get_instructions() { - return _('This is your inbox, which lists your incoming private messages.'); - } +class InboxAction extends MailboxAction +{ + + /** + * Title of the page + * + * @return string page title + */ + + function title() + { + if ($this->page > 1) { + return sprintf(_("Inbox for %s - page %d"), $this->user->nickname, + $this->page); + } else { + return sprintf(_("Inbox for %s"), $this->user->nickname); + } + } + + /** + * Retrieve the messages for this user and this page + * + * Does a query for the right messages + * + * @return Message data object with stream for messages + * + * @see MailboxAction::getMessages() + */ + + function getMessages() + { + $message = new Message(); + + $message->to_profile = $this->user->id; + $message->orderBy('created DESC, id DESC'); + $message->limit((($this->page - 1) * MESSAGES_PER_PAGE), + MESSAGES_PER_PAGE + 1); + + if ($message->find()) { + return $message; + } else { + return null; + } + } + + /** + * Returns the profile we want to show with the message + * + * For inboxes, we show the sender; for outboxes, the recipient. + * + * @param Message $message The message to get the profile for + * + * @return Profile The profile that matches the message + */ + + function getMessageProfile($message) + { + return $message->getFrom(); + } + + /** + * Instructions for using this page + * + * @return string localised instructions for using the page + */ + + function getInstructions() + { + return _('This is your inbox, which lists your incoming private messages.'); + } } diff --git a/actions/invite.php b/actions/invite.php index c7d92085c..f4ad2f7c5 100644 --- a/actions/invite.php +++ b/actions/invite.php @@ -19,181 +19,221 @@ if (!defined('LACONICA')) { exit(1); } -class InviteAction extends Action { - - function is_readonly() { - return false; - } - - function handle($args) { +class InviteAction extends Action +{ + var $mode = null; + var $error = null; + var $already = null; + var $subbed = null; + var $sent = null; + + function isReadOnly() + { + 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->clientError(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->sendInvitations(); + } else { + $this->showForm(); + } + } + + function sendInvitations() + { + # CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('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->showForm(sprintf(_('Invalid email address: %s'), $email)); + return; + } + } + + $this->already = array(); + $this->subbed = array(); + + foreach ($addresses as $email) { + $email = common_canonical_email($email); + $other = User::staticGet('email', $email); + if ($other) { + if ($user->isSubscribed($other)) { + $this->already[] = $other; + } else { + subs_subscribe_to($user, $other); + $this->subbed[] = $other; + } + } else { + $this->sent[] = $email; + $this->sendInvitation($email, $user, $personal); + } + } + + $this->mode = 'sent'; + + $this->showPage(); + } + + function title() + { + if ($this->mode == 'sent') { + return _('Invitation(s) sent'); + } else { + return _('Invite new users'); + } + } + + function showContent() + { + if ($this->mode == 'sent') { + $this->showInvitationSuccess(); + } else { + $this->showInviteForm(); + } + } + + function showInvitationSuccess() + { + if ($this->already) { + $this->element('p', null, _('You are already subscribed to these users:')); + $this->elementStart('ul'); + foreach ($this->already as $other) { + $this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email)); + } + $this->elementEnd('ul'); + } + if ($this->subbed) { + $this->element('p', null, _('These people are already users and you were automatically subscribed to them:')); + $this->elementStart('ul'); + foreach ($this->subbed as $other) { + $this->element('li', null, sprintf(_('%s (%s)'), $other->nickname, $other->email)); + } + $this->elementEnd('ul'); + } + if ($this->sent) { + $this->element('p', null, _('Invitation(s) sent to the following people:')); + $this->elementStart('ul'); + foreach ($this->sent as $other) { + $this->element('li', null, $other); + } + $this->elementEnd('ul'); + $this->element('p', null, _('You will be notified when your invitees accept the invitation and register on the site. Thanks for growing the community!')); + } + } + + function showPageNotice() + { + if ($this->mode != 'sent') { + if ($this->error) { + $this->element('p', 'error', $this->error); + } else { + $this->elementStart('div', 'instructions'); + $this->element('p', null, + _('Use this form to invite your friends and colleagues to use this service.')); + $this->elementEnd('div'); + } + } + } + + function showForm($error=null) + { + $this->mode = 'form'; + $this->error = $error; + $this->showPage(); + } + + function showInviteForm() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'invite', + 'action' => common_local_url('invite'))); + $this->hidden('token', common_session_token()); + + $this->textarea('addresses', _('Email addresses'), + $this->trimmed('addresses'), + _('Addresses of friends to invite (one per line)')); + + $this->textarea('personal', _('Personal message'), + $this->trimmed('personal'), + _('Optionally add a personal message to the invitation.')); + + $this->submit('send', _('Send')); + + $this->elementEnd('form'); + } + + function sendInvitation($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); + } + + function showLocalNav() + { + $nav = new SubGroupNav($this, common_current_user()); + $nav->show(); + } } diff --git a/actions/joingroup.php b/actions/joingroup.php new file mode 100644 index 000000000..1888ecdab --- /dev/null +++ b/actions/joingroup.php @@ -0,0 +1,149 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Join a group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Join a group + * + * This is the action for joining a group. It works more or less like the subscribe action + * for users. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class JoingroupAction extends Action +{ + var $group = null; + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to join a group.')); + return false; + } + + $nickname_arg = $this->trimmed('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + common_redirect(common_local_url('editgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $this->group = User_group::staticGet('nickname', $nickname); + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + $cur = common_current_user(); + + if ($cur->isMember($this->group)) { + $this->clientError(_('You are already a member of that group'), 403); + return false; + } + + return true; + } + + /** + * Handle the request + * + * On POST, add the current user to the group + * + * @param array $args unused + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + $cur = common_current_user(); + + $member = new Group_member(); + + $member->group_id = $this->group->id; + $member->profile_id = $cur->id; + $member->created = common_sql_now(); + + $result = $member->insert(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + $this->serverError(sprintf(_('Could not join user %s to group %s'), + $cur->nickname, $this->group->nickname)); + } + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, sprintf(_('%s joined group %s'), + $cur->nickname, + $this->group->nickname)); + $this->elementEnd('head'); + $this->elementStart('body'); + $lf = new LeaveForm($this, $this->group); + $lf->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('groupmembers', array('nickname' => + $this->group->nickname))); + } + } +}
\ No newline at end of file diff --git a/actions/leavegroup.php b/actions/leavegroup.php new file mode 100644 index 000000000..c7152e3c0 --- /dev/null +++ b/actions/leavegroup.php @@ -0,0 +1,159 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Leave a group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Leave a group + * + * This is the action for leaving a group. It works more or less like the subscribe action + * for users. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class LeavegroupAction extends Action +{ + var $group = null; + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work.')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to leave a group.')); + return false; + } + + $nickname_arg = $this->trimmed('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + common_redirect(common_local_url('editgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname.'), 404); + return false; + } + + $this->group = User_group::staticGet('nickname', $nickname); + + if (!$this->group) { + $this->clientError(_('No such group.'), 404); + return false; + } + + $cur = common_current_user(); + + if (!$cur->isMember($this->group)) { + $this->clientError(_('You are not a member of that group.'), 403); + return false; + } + + if ($cur->isAdmin($this->group)) { + $this->clientError(_('You may not leave a group while you are its administrator.'), 403); + return false; + + } + + return true; + } + + /** + * Handle the request + * + * On POST, add the current user to the group + * + * @param array $args unused + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + $cur = common_current_user(); + + $member = new Group_member(); + + $member->group_id = $this->group->id; + $member->profile_id = $cur->id; + + if (!$member->find(true)) { + $this->serverError(_('Could not find membership record.')); + return; + } + + $result = $member->delete(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + $this->serverError(sprintf(_('Could not remove user %s to group %s'), + $cur->nickname, $this->group->nickname)); + } + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, sprintf(_('%s left group %s'), + $cur->nickname, + $this->group->nickname)); + $this->elementEnd('head'); + $this->elementStart('body'); + $jf = new JoinForm($this, $this->group); + $jf->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('groupmembers', array('nickname' => + $this->group->nickname))); + } + } +} diff --git a/actions/login.php b/actions/login.php index ccec9cf8a..11cf1f02a 100644 --- a/actions/login.php +++ b/actions/login.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Login form + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,138 +18,271 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Login + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -class LoginAction extends Action { - - 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 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; - } - - $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; - } - - 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); - } - - 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 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'); - } - } +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Login form + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class LoginAction extends Action +{ + /** + * Has there been an error? + */ + + var $error = null; + + /** + * Is this a read-only action? + * + * @return boolean false + */ + + function isReadOnly() + { + return false; + } + + /** + * Handle input, produce output + * + * Switches on request method; either shows the form or handles its input. + * + * @param array $args $_REQUEST data + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + if (common_is_real_login()) { + $this->clientError(_('Already logged in.')); + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->checkLogin(); + } else { + $this->showForm(); + } + } + + /** + * Check the login data + * + * Determines if the login data is valid. If so, logs the user + * in, and redirects to the 'with friends' page, or to the stored + * return-to URL. + * + * @return void + */ + + function checkLogin() + { + // XXX: login throttle + + // CSRF protection - token set in common_notice_form() + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->clientError(_('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)) { + $this->serverError(_('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->showForm(_('Incorrect username or password.')); + return; + } + + // success! + if (!common_set_user($user)) { + $this->serverError(_('Error setting user.')); + return; + } + + 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); + } + + /** + * Store an error and show the page + * + * This used to show the whole page; now, it's just a wrapper + * that stores the error in an attribute. + * + * @param string $error error, if any. + * + * @return void + */ + + function showForm($error=null) + { + $this->error = $error; + $this->showPage(); + } + + /** + * Title of the page + * + * @return string title of the page + */ + + function title() + { + return _('Login'); + } + + /** + * Show page notice + * + * Display a notice for how to use the page, or the + * error if it exists. + * + * @return void + */ + + function showPageNotice() + { + if ($this->error) { + $this->element('p', 'error', $this->error); + } else { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + + $this->raw($output); + } + } + + /** + * Core of the display code + * + * Shows the login form. + * + * @return void + */ + + function showContent() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_login', + 'class' => 'form_settings', + 'action' => common_local_url('login'))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Login to site')); + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('nickname', _('Nickname')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('password', _('Password')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('rememberme', _('Remember me'), false, + _('Automatically login in the future; ' . + 'not for shared computers!')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('submit', _('Login')); + $this->hidden('token', common_session_token()); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + $this->elementStart('p'); + $this->element('a', array('href' => common_local_url('recoverpassword')), + _('Lost or forgotten password?')); + $this->elementEnd('p'); + } + + /** + * Instructions for using the form + * + * For "remembered" logins, we make the user re-login when they + * try to change settings. Different instructions for this case. + * + * @return void + */ + + function getInstructions() + { + 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%%). '); + } + } + + /** + * A local menu + * + * Shows different login/register actions. + * + * @return void + */ + + function showLocalNav() + { + $nav = new LoginGroupNav($this); + $nav->show(); + } } diff --git a/actions/logout.php b/actions/logout.php index f00fa0ba7..0ff8dc754 100644 --- a/actions/logout.php +++ b/actions/logout.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Logout action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,25 +28,52 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/openid.php'); +require_once INSTALLDIR.'/lib/openid.php'; + +/** + * Logout action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class LogoutAction extends Action +{ + + /** + * This is read only. + * + * @return boolean true + */ + function isReadOnly() + { + return true; + } -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')); - } - } + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + function handle($args) + { + parent::handle($args); + if (!common_logged_in()) { + $this->clientError(_('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/actions/microsummary.php b/actions/microsummary.php index 104467d29..196dd5de8 100644 --- a/actions/microsummary.php +++ b/actions/microsummary.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Microsummary action, see https://wiki.mozilla.org/Microsummaries + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,30 +28,49 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -class MicrosummaryAction extends Action { - - function handle($args) { +if (!defined('LACONICA')) { + exit(1); +} - parent::handle($args); +/** + * Microsummary action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class MicrosummaryAction extends Action +{ + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + function 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->clientError(_('No such user'), 404); + return; + } + + $notice = $user->getCurrentNotice(); + + if (!$notice) { + $this->clientError(_('No current status'), 404); + } + + header('Content-Type: text/plain'); + + print $user->nickname . ': ' . $notice->content; + } } diff --git a/actions/newgroup.php b/actions/newgroup.php new file mode 100644 index 000000000..42fd380df --- /dev/null +++ b/actions/newgroup.php @@ -0,0 +1,205 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Add a new group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Add a new group + * + * This is the form for adding a new group + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class NewgroupAction extends Action +{ + var $msg; + + function title() + { + return _('New group'); + } + + /** + * Prepare to run + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + if (!common_logged_in()) { + $this->clientError(_('You must be logged in to create a group.')); + return false; + } + + return true; + } + + /** + * Handle the request + * + * On GET, show the form. On POST, try to save the group. + * + * @param array $args unused + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->trySave(); + } else { + $this->showForm(); + } + } + + function showForm($msg=null) + { + $this->msg = $msg; + $this->showPage(); + } + + function showContent() + { + $form = new GroupEditForm($this); + $form->show(); + } + + function showPageNotice() + { + if ($this->msg) { + $this->element('p', 'error', $this->msg); + } else { + $this->element('p', 'instructions', + _('Use this form to create a new group.')); + } + } + + function trySave() + { + $nickname = $this->trimmed('nickname'); + $fullname = $this->trimmed('fullname'); + $homepage = $this->trimmed('homepage'); + $description = $this->trimmed('description'); + $location = $this->trimmed('location'); + + if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->showForm(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.')); + return; + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + return; + } else if (!User_group::allowedNickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($description) && strlen($description) > 140) { + $this->showForm(_('description is too long (max 140 chars).')); + return; + } else if (!is_null($location) && strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } + + $cur = common_current_user(); + + // Checked in prepare() above + + assert(!is_null($cur)); + + $group = new User_group(); + + $group->query('BEGIN'); + + $group->nickname = $nickname; + $group->fullname = $fullname; + $group->homepage = $homepage; + $group->description = $description; + $group->location = $location; + $group->created = common_sql_now(); + + $result = $group->insert(); + + if (!$result) { + common_log_db_error($group, 'INSERT', __FILE__); + $this->serverError(_('Could not create group.')); + } + + $member = new Group_member(); + + $member->group_id = $group->id; + $member->profile_id = $cur->id; + $member->is_admin = 1; + $member->created = $group->created; + + $result = $member->insert(); + + if (!$result) { + common_log_db_error($member, 'INSERT', __FILE__); + $this->serverError(_('Could not set group membership.')); + } + + $group->query('COMMIT'); + + common_redirect($group->homeUrl(), 307); + } + + function nicknameExists($nickname) + { + $group = User_group::staticGet('nickname', $nickname); + return (!is_null($group) && $group != false); + } +} + diff --git a/actions/newmessage.php b/actions/newmessage.php index da48fc7e7..aa94f8c4f 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Handler for posting new notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,121 +18,165 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Action for posting new direct messages + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -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 - } +class NewmessageAction extends Action +{ + + /** + * Error message, if any + */ + + var $msg = null; + + /** + * Title of the page + * + * Note that this usually doesn't get called unless something went wrong + * + * @return string page title + */ + + function title() + { + return _('New message'); + } + + /** + * Handle input, produce output + * + * @param array $args $_REQUEST contents + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if (!common_logged_in()) { + $this->clientError(_('Not logged in.'), 403); + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->saveNewMessage(); + } else { + $this->showForm(); + } + } + + function saveNewMessage() + { + $user = common_current_user(); + assert($user); // XXX: maybe an error instead... + + // CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. ' . + 'Try again, please.')); + return; + } + + $content = $this->trimmed('content'); + $to = $this->trimmed('to'); + + if (!$content) { + $this->showForm(_('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->showForm(_('That\'s too long. ' . + 'Max message size is 140 chars.')); + return; + } + } + + $other = User::staticGet('id', $to); + + if (!$other) { + $this->showForm(_('No recipient specified.')); + return; + } else if (!$user->mutuallySubscribed($other)) { + $this->clientError(_('You can\'t send a message to this user.'), 404); + return; + } else if ($user->id == $other->id) { + $this->clientError(_('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->showForm($message); + return; + } + + $this->notify($user, $other, $message); + + $url = common_local_url('outbox', array('nickname' => $user->nickname)); + + common_redirect($url, 303); + } + + function showForm($msg = null) + { + $content = $this->trimmed('content'); + $user = common_current_user(); + + $to = $this->trimmed('to'); + + $other = User::staticGet('id', $to); + + if (!$other) { + $this->clientError(_('No such user'), 404); + return; + } + + if (!$user->mutuallySubscribed($other)) { + $this->clientError(_('You can\'t send a message to this user.'), 404); + return; + } + + $this->msg = $msg; + + $this->showPage(); + } + + function notify($from, $to, $message) + { + mail_notify_message($message, $from, $to); + // XXX: Jabber, SMS notifications... probably queued + } } diff --git a/actions/newnotice.php b/actions/newnotice.php index 42b48923f..572adbb23 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -1,154 +1,289 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Handler for posting new notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once INSTALLDIR . '/lib/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) { - $nli = new NoticeListItem($notice); - $nli->show(); - } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/noticelist.php'; + +/** + * Action for posting new notices + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class NewnoticeAction extends Action +{ + /** + * Error message, if any + */ + + var $msg = null; + + /** + * Title of the page + * + * Note that this usually doesn't get called unless something went wrong + * + * @return string page title + */ + + function title() + { + return _('New notice'); + } + + /** + * Handle input, produce output + * + * Switches based on GET or POST method. On GET, shows a form + * for posting a notice. On POST, saves the results of that form. + * + * Results may be a full page, or just a single notice list item, + * depending on whether AJAX was requested. + * + * @param array $args $_REQUEST contents + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if (!common_logged_in()) { + $this->clientError(_('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->clientError(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + $this->saveNewNotice(); + } else { + $this->showForm(); + } + } + + /** + * Save a new notice, based on arguments + * + * If successful, will show the notice, or return an Ajax-y result. + * If not, it will show an error message -- possibly Ajax-y. + * + * Also, if the notice input looks like a command, it will run the + * command and show the results -- again, possibly ajaxy. + * + * @return void + */ + + function saveNewNotice() + { + $user = common_current_user(); + assert($user); // XXX: maybe an error instead... + $content = $this->trimmed('status_textarea'); + + if (!$content) { + $this->showForm(_('No content!')); + return; + } else { + $content_shortened = common_shorten_links($content); + + if (mb_strlen($content_shortened) > 140) { + $this->showForm(_('That\'s too long. '. + 'Max notice size is 140 chars.')); + return; + } + } + $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->showForm($notice); + return; + } + + common_broadcast_notice($notice); + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Notice posted')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->showNotice($notice); + $this->elementEnd('body'); + $this->elementEnd('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); + } + } + + /** + * Show an Ajax-y error message + * + * Goes back to the browser, where it's shown in a popup. + * + * @param string $msg Message to show + * + * @return void + */ + + function ajaxErrorMsg($msg) + { + common_start_html('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Ajax Error')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'error'), $msg); + $this->elementEnd('body'); + $this->elementEnd('html'); + } + + /** + * Formerly page output + * + * This used to be the whole page output; now that's been largely + * subsumed by showPage. So this just stores an error message, if + * it was passed, and calls showPage. + * + * Note that since we started doing Ajax output, this page is rarely + * seen. + * + * @param string $msg An error message, if any + * + * @return void + */ + + function showForm($msg=null) + { + if ($msg && $this->boolean('ajax')) { + $this->ajaxErrorMsg($msg); + return; + } + + $this->msg = $msg; + $this->showPage(); + } + + /** + * Overload for replies or bad results + * + * We show content in the notice form if there were replies or results. + * + * @return void + */ + + function showNoticeForm() + { + $content = $this->trimmed('status_textarea'); + if (!$content) { + $replyto = $this->trimmed('replyto'); + $profile = Profile::staticGet('nickname', $replyto); + if ($profile) { + $content = '@' . $profile->nickname . ' '; + } + } + + $notice_form = new NoticeForm($this, $content); + $notice_form->show(); + } + + /** + * Show an error message + * + * Shows an error message if there is one. + * + * @return void + * + * @todo maybe show some instructions? + */ + + function showPageNotice() + { + if ($this->msg) { + $this->element('p', array('id' => 'error'), $this->msg); + } + } + + /** + * Output a notice + * + * Used to generate the notice code for Ajax results. + * + * @param Notice $notice Notice that was saved + * + * @return void + */ + + function showNotice($notice) + { + $nli = new NoticeListItem($notice, $this); + $nli->show(); + } } diff --git a/actions/noticesearch.php b/actions/noticesearch.php index 96e4d777f..8c5128de1 100644 --- a/actions/noticesearch.php +++ b/actions/noticesearch.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Notice search action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,148 +28,199 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/searchaction.php'); - -# XXX common parent for people and content search? - -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_title() { - return _('Text search'); - } - - function show_results($q, $page) { - - $notice = new Notice(); +if (!defined('LACONICA')) { + exit(1); +} - # lcase it for comparison - $q = strtolower($q); +require_once INSTALLDIR.'/lib/searchaction.php'; +/** + * Notice search action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * @todo common parent for people and content search? + */ +class NoticesearchAction extends SearchAction +{ + /** + * Get instructions + * + * @return string instruction text + */ + function getInstructions() + { + return _('Search for notices on %%site.name%% by their contents. Separate search terms by spaces; they must be 3 characters or more.'); + } + + /** + * Get title + * + * @return string title + */ + function title() + { + return _('Text search'); + } + + /** + * Show results + * + * @param string $q search query + * @param integer $page page number + * + * @return void + */ + function showResults($q, $page) + { + $notice = new Notice(); + $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(); } - else { - $cnt = $notice->find(); + if ($cnt > 0) { + $terms = preg_split('/[\s,]+/', $q); + $this->elementStart('ul', array('id' => 'notices')); + for ($i = 0; $i < min($cnt, NOTICES_PER_PAGE); $i++) { + if ($notice->fetch()) { + $this->showNotice($notice, $terms); + } else { + // shouldn't happen! + break; + } + } + $this->elementEnd('ul'); + } else { + $this->element('p', 'error', _('No results')); } - 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('→'); - 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; - } + $this->pagination($page > 1, $cnt > NOTICES_PER_PAGE, + $page, 'noticesearch', array('q' => $q)); + } + + /** + * Show header + * + * @param array $arr array containing the query + * + * @return void + */ + + function extraHead() + { + $q = $this->trimmed('q'); + if ($q) { + $this->element('link', array('rel' => 'alternate', + 'href' => common_local_url('noticesearchrss', + array('q' => $q)), + 'type' => 'application/rss+xml', + 'title' => _('Search Stream Feed'))); + } + } + + /** + * Show notice + * + * @param class $notice notice + * @param array $terms terms to highlight + * + * @return void + * + * @todo refactor and combine with StreamAction::showNotice() + */ + function showNotice($notice, $terms) + { + $profile = $notice->getProfile(); + if (!$profile) { + common_log_db_error($notice, 'SELECT', __FILE__); + $this->serverError(_('Notice without matching profile')); + return; + } + // XXX: RDFa + $this->elementStart('li', array('class' => 'notice_single', + 'id' => 'notice-' . $notice->id)); + $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); + $this->elementStart('a', array('href' => $profile->profileurl)); + $this->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)); + $this->elementEnd('a'); + $this->element('a', array('href' => $profile->profileurl, + 'class' => 'nickname'), + $profile->nickname); + // FIXME: URL, image, video, audio + $this->elementStart('p', array('class' => 'content')); + if ($notice->rendered) { + $this->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) + $this->raw($this->highlight(common_render_content($notice->content, $notice), $terms)); + } + $this->elementEnd('p'); + $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); + $this->elementStart('p', 'time'); + $this->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)); + $this->text(' ('); + $this->element('a', array('class' => 'inreplyto', + 'href' => $replyurl), + _('in reply to...')); + $this->text(')'); + } + $this->elementStart('a', + array('href' => common_local_url('newnotice', + array('replyto' => $profile->nickname)), + 'onclick' => 'doreply("'.$profile->nickname.'"); return false', + 'title' => _('reply'), + 'class' => 'replybutton')); + $this->hidden('posttoken', common_session_token()); + + $this->raw('→'); + $this->elementEnd('a'); + $this->elementEnd('p'); + $this->elementEnd('li'); + } + + /** + * Highlist query terms + * + * @param string $text notice text + * @param array $terms terms to highlight + * + * @return void + */ + 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/actions/noticesearchrss.php b/actions/noticesearchrss.php index 0f38515a0..c1a1c2c67 100644 --- a/actions/noticesearchrss.php +++ b/actions/noticesearchrss.php @@ -1,5 +1,16 @@ <?php -/* +/** + * RSS feed for notice search action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,54 +28,71 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/rssaction.php'); +if (!defined('LACONICA')) { + exit(1); +} -// Formatting of RSS handled by Rss10Action +require_once INSTALLDIR.'/lib/rssaction.php'; -class NoticesearchrssAction extends Rss10Action { +/** + * RSS feed for notice search action class. + * + * Formatting of RSS handled by Rss10Action + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class NoticesearchrssAction extends Rss10Action +{ - function init() { - return true; - } + function init() + { + return true; + } - function get_notices($limit=0) { + function getNotices($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 getChannel() + { + 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 getImage() + { + return null; + } } diff --git a/actions/nudge.php b/actions/nudge.php index 677f58800..ca6fd3761 100644 --- a/actions/nudge.php +++ b/actions/nudge.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * User by ID action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,68 +29,98 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/mail.php'); - -class NudgeAction extends Action { +if (!defined('LACONICA')) { + exit(1); +} - function handle($args) { - parent::handle($args); +require_once INSTALLDIR.'/lib/mail.php'; - if (!common_logged_in()) { - $this->client_error(_('Not logged in.')); - return; - } +/** + * Nudge a user action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class NudgeAction extends Action +{ + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + function handle($args) + { + parent::handle($args); - $user = common_current_user(); - $other = User::staticGet('nickname', $this->arg('nickname')); + if (!common_logged_in()) { + $this->clientError(_('Not logged in.')); + return; + } - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - common_redirect(common_local_url('showstream', array('nickname' => $other->nickname))); - return; - } + $user = common_current_user(); + $other = User::staticGet('nickname', $this->arg('nickname')); - # CSRF protection + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + common_redirect(common_local_url('showstream', + array('nickname' => $other->nickname))); + 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; - } + // CSRF protection + $token = $this->trimmed('token'); + + if (!$token || $token != common_session_token()) { + $this->clientError(_('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.')); + $this->clientError(_('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')) { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Nudge sent')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'nudge_response'), _('Nudge sent!')); + $this->elementEnd('body'); + $this->elementEnd('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 - } - } + /** + * Do the actual notification + * + * @param class $user nudger + * @param class $other nudgee + * + * @return nothing + */ + 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/actions/openidlogin.php b/actions/openidlogin.php index 1b289dbea..ec5361c8b 100644 --- a/actions/openidlogin.php +++ b/actions/openidlogin.php @@ -21,72 +21,91 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/openid.php'); -class OpenidloginAction extends Action { +class OpenidloginAction extends Action +{ + function handle($args) + { + parent::handle($args); + if (common_logged_in()) { + $this->clientError(_('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->showForm(_('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'); - $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); - } - } + common_ensure_session(); - function get_instructions() { - return _('Login with an [OpenID](%%doc.openid%%) account.'); - } + $_SESSION['openid_rememberme'] = $rememberme; - 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'); - } - } + $result = oid_authenticate($openid_url, + 'finishopenidlogin'); - 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(); - } + if (is_string($result)) { # error message + unset($_SESSION['openid_rememberme']); + $this->showForm($result, $openid_url); + } + } else { + $openid_url = oid_get_last(); + $this->showForm(null, $openid_url); + } + } + + function getInstructions() + { + return _('Login with an [OpenID](%%doc.openid%%) account.'); + } + + function showPageNotice() + { + if ($this->error) { + $this->element('div', array('class' => 'error'), $this->error); + } else { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } + + function title() + { + return _('OpenID Login'); + } + + function showForm($error=null, $openid_url) + { + $this->error = $error; + $this->openid_url = $openid_url; + $this->showPage(); + } + + function showContent() { + $formaction = common_local_url('openidlogin'); + $this->elementStart('form', array('method' => 'post', + 'id' => 'openidlogin', + 'action' => $formaction)); + $this->hidden('token', common_session_token()); + $this->input('openid_url', _('OpenID URL'), + $this->openid_url, + _('Your OpenID URL')); + $this->checkbox('rememberme', _('Remember me'), false, + _('Automatically login in the future; ' . + 'not for shared computers!')); + $this->submit('submit', _('Login')); + $this->elementEnd('form'); + } + + function showLocalNav() + { + $nav = new LoginGroupNav($this); + $nav->show(); + } } diff --git a/actions/openidsettings.php b/actions/openidsettings.php index f539d111f..92469d20f 100644 --- a/actions/openidsettings.php +++ b/actions/openidsettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Settings for OpenID + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,142 +18,217 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; +require_once INSTALLDIR.'/lib/openid.php'; + +/** + * Settings for OpenID + * + * Lets users add, edit and delete OpenIDs from their account + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/settingsaction.php'); -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; - } +class OpenidsettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Page title + */ + + function title() + { + return _('OpenID settings'); + } + + /** + * Instructions for use + * + * @return string Instructions for use + */ + + function getInstructions() + { + return _('[OpenID](%%doc.openid%%) lets you log into many sites ' . + ' with the same user account. '. + ' Manage your associated OpenIDs from here.'); + } + + /** + * Show the form for OpenID management + * + * We have one form with a few different submit buttons to do different things. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_openid_add', + 'class' => 'form_settings', + 'action' => + common_local_url('openidsettings'))); + $this->elementStart('fieldset', array('id' => 'settings_openid_add')); + $this->element('legend', null, _('Add OpenID')); + $this->hidden('token', common_session_token()); + $this->element('p', 'form_guide', + _('If you want to add an OpenID to your account, ' . + 'enter it in the box below and click "Add".')); + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->element('label', array('for' => 'openid_url'), + _('OpenID URL')); + $this->element('input', array('name' => 'openid_url', + 'type' => 'text', + 'id' => 'openid_url')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->element('input', array('type' => 'submit', + 'id' => 'settings_openid_add_action-submit', + 'name' => 'add', + 'class' => 'submit', + 'value' => _('Add'))); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + $oid = new User_openid(); + + $oid->user_id = $user->id; + + $cnt = $oid->find(); + + if ($cnt > 0) { + + $this->element('h2', null, _('Remove OpenID')); + + if ($cnt == 1 && !$user->password) { + + $this->element('p', 'form_guide', + _('Removing your only OpenID '. + 'would make it impossible to log in! ' . + 'If you need to remove it, '. + 'add another OpenID first.')); + + if ($oid->fetch()) { + $this->elementStart('p'); + $this->element('a', array('href' => $oid->canonical), + $oid->display); + $this->elementEnd('p'); + } + + } else { + + $this->element('p', 'form_guide', + _('You can remove an OpenID from your account '. + 'by clicking the button marked "Remove".')); + $idx = 0; + + while ($oid->fetch()) { + $this->elementStart('form', + array('method' => 'POST', + 'id' => 'form_settings_openid_delete' . $idx, + 'class' => 'form_settings', + 'action' => + common_local_url('openidsettings'))); + $this->elementStart('fieldset'); + $this->hidden('token', common_session_token()); + $this->element('a', array('href' => $oid->canonical), + $oid->display); + $this->element('input', array('type' => 'hidden', + 'id' => 'openid_url'.$idx, + 'name' => 'openid_url', + 'value' => $oid->canonical)); + $this->element('input', array('type' => 'submit', + 'id' => 'remove'.$idx, + 'name' => 'remove', + 'class' => 'submit remove', + 'value' => _('Remove'))); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + $idx++; + } + } + } + } + + /** + * Handle a POST request + * + * Muxes to different sub-functions based on which button was pushed + * + * @return void + */ + + function handlePost() + { + // CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('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->showForm($result); + } + } else if ($this->arg('remove')) { + $this->removeOpenid(); + } else { + $this->showForm(_('Something weird happened.')); + } + } + + /** + * Handles a request to remove an OpenID from the user's account + * + * Validates input and, if everything is OK, deletes the OpenID. + * Reloads the form with a success or error notification. + * + * @return void + */ + + function removeOpenid() + { + $openid_url = $this->trimmed('openid_url'); + + $oid = User_openid::staticGet('canonical', $openid_url); + + if (!$oid) { + $this->showForm(_('No such OpenID.')); + return; + } + $cur = common_current_user(); + if (!$cur || $oid->user_id != $cur->id) { + $this->showForm(_('That OpenID does not belong to you.')); + return; + } + $oid->delete(); + $this->showForm(_('OpenID removed.'), true); + return; + } } diff --git a/actions/opensearch.php b/actions/opensearch.php index 0f366be4c..d7705972f 100644 --- a/actions/opensearch.php +++ b/actions/opensearch.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * Opensearch action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,43 +29,59 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -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'); +if (!defined('LACONICA')) { + exit(1); +} - common_element_end('OpenSearchDescription'); - common_end_xml(); - } +/** + * Opensearch action class. + * + * Formatting of RSS handled by Rss10Action + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class OpensearchAction extends Action +{ + /** + * Class handler. + * + * @param array $args query arguments + * + * @return boolean false if user doesn't exist + */ + function handle($args) + { + parent::handle($args); + $type = $this->trimmed('type'); + $short_name = ''; + if ($type == 'people') { + $type = 'peoplesearch'; + $short_name = _('People Search'); + } else { + $type = 'noticesearch'; + $short_name = _('Notice Search'); + } + header('Content-Type: text/html'); + common_start_xml(); + $this->elementStart('OpenSearchDescription', array('xmlns' => 'http://a9.com/-/spec/opensearch/1.1/')); + $short_name = common_config('site', 'name').' '.$short_name; + $this->element('ShortName', null, $short_name); + $this->element('Contact', null, common_config('site', 'email')); + $this->element('Url', array('type' => 'text/html', 'method' => 'get', + 'template' => str_replace('---', '{searchTerms}', common_local_url($type, array('q' => '---'))))); + $this->element('Image', array('height' => 16, 'width' => 16, 'type' => 'image/vnd.microsoft.icon'), common_path('favicon.ico')); + $this->element('Image', array('height' => 50, 'width' => 50, 'type' => 'image/png'), theme_path('logo.png')); + $this->element('AdultContent', null, 'false'); + $this->element('Language', null, common_language()); + $this->element('OutputEncoding', null, 'UTF-8'); + $this->element('InputEncoding', null, 'UTF-8'); + $this->elementEnd('OpenSearchDescription'); + common_end_xml(); + } } + diff --git a/actions/othersettings.php b/actions/othersettings.php index eccf90e91..b542233ca 100644 --- a/actions/othersettings.php +++ b/actions/othersettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Miscellaneous settings + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,167 +18,153 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Robin Millette <millette@controlyourself.ca> + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/settingsaction.php'); +if (!defined('LACONICA')) { + exit(1); +} -class OthersettingsAction extends SettingsAction { +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; - function get_instructions() { - return _('Manage various other options.'); - } +/** + * Miscellaneous settings actions + * + * Currently this just manages URL shortening. + * + * @category Settings + * @package Laconica + * @author Robin Millette <millette@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - function show_form($msg=NULL, $success=false) { - $user = common_current_user(); +class OthersettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Other Settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('Manage various other options.'); + } + + /** + * Content area of the page + * + * Shows a form for uploading an avatar. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); - $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()); + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_other', + 'class' => 'form_settings', + 'action' => + common_local_url('othersettings'))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('URL Auto-shortening')); + $this->hidden('token', common_session_token()); + + // I18N + + $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' + ); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->dropdown('urlshorteningservice', _('Service'), + $services, _('Automatic shortening service to use.'), + false, $user->urlshorteningservice); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('save', _('Save')); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + /** + * Handle a post + * + * Saves the changes to url-shortening prefs and shows a success or failure + * message. + * + * @return void + */ + + function handlePost() + { + // CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + $urlshorteningservice = $this->trimmed('urlshorteningservice'); + + if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) { + $this->showForm(_('URL shortening service is too long (max 50 chars).')); + return; + } - $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' - ); + $user = common_current_user(); - common_dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), FALSE, $user->urlshorteningservice); + assert(!is_null($user)); // should already be checked - common_submit('save', _('Save')); + $user->query('BEGIN'); - common_element_end('form'); + $original = clone($user); -// common_element('h2', NULL, _('Delete my account')); -// $this->show_delete_form(); + $user->urlshorteningservice = $urlshorteningservice; - common_show_footer(); - } + $result = $user->update($original); - function show_feeds_list($feeds) { - common_element_start('div', array('class' => 'feedsdel')); - common_element('p', null, 'Feeds:'); - common_element_start('ul', array('class' => 'xoxo')); + if ($result === false) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->serverError(_('Couldn\'t update user.')); + return; + } - foreach ($feeds as $key => $value) { - $this->common_feed_item($feeds[$key]); - } - common_element_end('ul'); - common_element_end('div'); - } + $user->query('COMMIT'); - //TODO move to common.php (and retrace its origin) - 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(); -// $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_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'))); -// -// 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; - } - - if ($this->arg('save')) { - $this->save_preferences(); - }else { - $this->show_form(_('Unexpected form submission.')); - } - } - - function save_preferences() { - - $urlshorteningservice = $this->trimmed('urlshorteningservice'); - - if (!is_null($urlshorteningservice) && strlen($urlshorteningservice) > 50) { - $this->show_form(_('URL shortening service is too long (max 50 chars).')); - return; - } - - $user = common_current_user(); - - assert(!is_null($user)); # should already be checked - - $user->query('BEGIN'); - - $original = clone($user); - - $user->urlshorteningservice = $urlshorteningservice; - - $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); - } + $this->showForm(_('Preferences saved.'), true); + } } diff --git a/actions/outbox.php b/actions/outbox.php index c48d9c206..c8d7f2812 100644 --- a/actions/outbox.php +++ b/actions/outbox.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * action handler for message inbox + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,42 +18,101 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Message + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/mailbox.php'; + +/** + * action handler for message outbox + * + * @category Message + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see MailboxAction */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/mailbox.php'); - -class OutboxAction extends MailboxAction { - - function get_title($user, $page) { - if ($page > 1) { - $title = sprintf(_("Outbox for %s - page %d"), $user->nickname, $page); - } else { - $title = sprintf(_("Outbox for %s"), $user->nickname); - } - return $title; - } - - function get_messages($user, $page) { - $message = new Message(); - $message->from_profile = $user->id; - $message->orderBy('created DESC, id DESC'); - $message->limit((($page-1)*MESSAGES_PER_PAGE), MESSAGES_PER_PAGE + 1); - - if ($message->find()) { - return $message; - } else { - return NULL; - } - } - - function get_message_profile($message) { - return $message->getTo(); - } - - function get_instructions() { - return _('This is your outbox, which lists private messages you have sent.'); - } - +class OutboxAction extends MailboxAction +{ + /** + * Title of the page + * + * @return string page title + */ + + function title() + { + if ($this->page > 1) { + return sprintf(_("Outbox for %s - page %d"), + $this->user->nickname, $page); + } else { + return sprintf(_("Outbox for %s"), $this->user->nickname); + } + } + + /** + * retrieve the messages for this user and this page + * + * Does a query for the right messages + * + * @return Message data object with stream for messages + * + * @see MailboxAction::getMessages() + */ + + function getMessages() + { + $message = new Message(); + + $message->from_profile = $this->user->id; + $message->orderBy('created DESC, id DESC'); + $message->limit((($this->page - 1) * MESSAGES_PER_PAGE), + MESSAGES_PER_PAGE + 1); + + if ($message->find()) { + return $message; + } else { + return null; + } + } + + /** + * returns the profile we want to show with the message + * + * For outboxes, we show the recipient. + * + * @param Message $message The message to get the profile for + * + * @return Profile The profile of the message recipient + * + * @see MailboxAction::getMessageProfile() + */ + + function getMessageProfile($message) + { + return $message->getTo(); + } + + /** + * instructions for using this page + * + * @return string localised instructions for using the page + */ + + function getInstructions() + { + return _('This is your outbox, which lists private messages you have sent.'); + } } diff --git a/actions/passwordsettings.php b/actions/passwordsettings.php new file mode 100644 index 000000000..17b2de4e8 --- /dev/null +++ b/actions/passwordsettings.php @@ -0,0 +1,175 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Change user password + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; + +/** + * Change password + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class PasswordsettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Change password'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('Change your password.'); + } + + /** + * Content area of the page + * + * Shows a form for changing the password + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + $this->elementStart('form', array('method' => 'POST', + 'id' => 'form_password', + 'class' => 'form_settings', + 'action' => + common_local_url('profilesettings'))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Password change')); + $this->hidden('token', common_session_token()); + + + $this->elementStart('ul', 'form_data'); + // Users who logged in with OpenID won't have a pwd + if ($user->password) { + $this->elementStart('li'); + $this->password('oldpassword', _('Old password')); + $this->elementEnd('li'); + } + $this->elementStart('li'); + $this->password('newpassword', _('New password'), + _('6 or more characters')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('confirm', _('Confirm'), + _('same as password above')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->submit('changepass', _('Change')); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + /** + * Handle a post + * + * Validate input and save changes. Reload the form with a success + * or error message. + * + * @return void + */ + + function handlePost() + { + // CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + $user = common_current_user(); + assert(!is_null($user)); // should already be checked + + // FIXME: scrub input + + $newpassword = $this->arg('newpassword'); + $confirm = $this->arg('confirm'); + + if (0 != strcmp($newpassword, $confirm)) { + $this->showForm(_('Passwords don\'t match.')); + return; + } + + if ($user->password) { + $oldpassword = $this->arg('oldpassword'); + + if (!common_check_user($user->nickname, $oldpassword)) { + $this->showForm(_('Incorrect old password')); + return; + } + } + + $original = clone($user); + + $user->password = common_munge_password($newpassword, $user->id); + + $val = $user->validate(); + if ($val !== true) { + $this->showForm(_('Error saving user; invalid.')); + return; + } + + if (!$user->update($original)) { + $this->serverError(_('Can\'t save new password.')); + return; + } + + $this->showForm(_('Password saved.'), true); + } +} diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php index 2e54233ec..3c672c940 100644 --- a/actions/peoplesearch.php +++ b/actions/peoplesearch.php @@ -1,5 +1,16 @@ <?php -/* +/** + * People search action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,68 +28,86 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/searchaction.php'); -require_once(INSTALLDIR.'/lib/profilelist.php'); +if (!defined('LACONICA')) { + exit(1); +} -class PeoplesearchAction extends SearchAction { +require_once INSTALLDIR.'/lib/searchaction.php'; +require_once INSTALLDIR.'/lib/profilelist.php'; - 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.'); - } +/** + * People search action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class PeoplesearchAction extends SearchAction +{ + function getInstructions() + { + 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 title() + { + return _('People search'); + } - function show_results($q, $page) { + function showResults($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, $this); + $results->show(); + } else { + $this->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(); + + $this->pagination($page > 1, $cnt > PROFILES_PER_PAGE, + $page, 'peoplesearch', array('q' => $q)); + } } -class PeopleSearchResults extends ProfileList { - - var $terms = NULL; - var $pattern = NULL; - - function __construct($profile, $terms) { - 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)); - } +class PeopleSearchResults extends ProfileList +{ + var $terms = null; + var $pattern = null; + + function __construct($profile, $terms, $action) + { + parent::__construct($profile, $terms, $action); + $this->terms = array_map('preg_quote', + array_map('htmlspecialchars', $terms)); + $this->pattern = '/('.implode('|',$terms).')/i'; + } + + function highlight($text) + { + return preg_replace($this->pattern, '<strong>\\1</strong>', htmlspecialchars($text)); + } } + diff --git a/actions/peopletag.php b/actions/peopletag.php index c508e0594..7bcfcb93e 100644 --- a/actions/peopletag.php +++ b/actions/peopletag.php @@ -21,83 +21,89 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/profilelist.php'); -class PeopletagAction extends Action { - - function handle($args) { +class PeopletagAction extends Action +{ + + 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->clientError(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); + $this->elementStart('div', 'instructions'); + $this->elementStart('p'); + $this->text($instr); + $this->elementEnd('p'); + $this->elementEnd('div'); + } - function get_title() { - return NULL; - } + function get_title() + { + return null; + } - function show_header($arr) { - return; - } + function show_header($arr) + { + return; + } } diff --git a/actions/postnotice.php b/actions/postnotice.php index 243081f12..0b4735296 100644 --- a/actions/postnotice.php +++ b/actions/postnotice.php @@ -21,68 +21,71 @@ 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; - } - } +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) { + $this->serverError($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) { + $this->clientError(_('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) { + $this->clientError(_('Profile unknown'), 403); + return false; + } + $sub = Subscription::staticGet('token', $token->key); + if (!$sub) { + $this->clientError(_('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); + $this->clientError(_('Invalid notice content'), 400); + return false; + } + $notice_uri = $req->get_parameter('omb_notice'); + if (!Validate::uri($notice_uri) && + !common_valid_tag($notice_uri)) { + $this->clientError(_('Invalid notice uri'), 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_url = $req->get_parameter('omb_notice_url'); + if ($notice_url && !common_valid_http_url($notice_url)) { + $this->clientError(_('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/actions/profilesettings.php b/actions/profilesettings.php index ed2623c9b..6dd4775e5 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Change profile settings + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,425 +18,315 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/accountsettingsaction.php'; + +/** + * Change profile settings + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -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; +class ProfilesettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('Profile settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('You can update your personal profile info here '. + 'so people know more about you.'); + } + + /** + * Content area of the page + * + * Shows a form for uploading an avatar. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + $profile = $user->getProfile(); + + $this->elementStart('form', array('method' => 'POST', + 'id' => 'form_settings_profile', + 'class' => 'form_settings', + 'action' => common_local_url('profilesettings'))); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Profile information')); + $this->hidden('token', common_session_token()); + + # too much common patterns here... abstractable? + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('nickname', _('Nickname'), + ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname, + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('fullname', _('Full name'), + ($this->arg('fullname')) ? $this->arg('fullname') : $profile->fullname); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('homepage', _('Homepage'), + ($this->arg('homepage')) ? $this->arg('homepage') : $profile->homepage, + _('URL of your homepage, blog, or profile on another site')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->textarea('bio', _('Bio'), + ($this->arg('bio')) ? $this->arg('bio') : $profile->bio, + _('Describe yourself and your interests in 140 chars')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('location', _('Location'), + ($this->arg('location')) ? $this->arg('location') : $profile->location, + _('Where you are, like "City, State (or Region), Country"')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('tags', _('Tags'), + ($this->arg('tags')) ? $this->arg('tags') : implode(' ', $user->getSelfTags()), + _('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated')); + $this->elementEnd('li'); + $this->elementStart('li'); + $language = common_language(); + $this->dropdown('language', _('Language'), + get_nice_language_list(), _('Preferred language'), + true, $language); + $this->elementEnd('li'); + $timezone = common_timezone(); + $timezones = array(); + foreach(DateTimeZone::listIdentifiers() as $k => $v) { + $timezones[$v] = $v; + } + $this->elementStart('li'); + $this->dropdown('timezone', _('Timezone'), + $timezones, _('What timezone are you normally in?'), + true, $timezone); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('autosubscribe', + _('Automatically subscribe to whoever '. + 'subscribes to me (best for non-humans)'), + ($this->arg('autosubscribe')) ? + $this->boolean('autosubscribe') : $user->autosubscribe); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('save', _('Save')); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + + } + + /** + * Handle a post + * + * Validate input and save changes. Reload the form with a success + * or error message. + * + * @return void + */ + + function handlePost() + { + # CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + $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->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.')); + return; + } else if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + return; + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($bio) && strlen($bio) > 140) { + $this->showForm(_('Bio is too long (max 140 chars).')); + return; + } else if (!is_null($location) && strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) { + $this->showForm(_('Timezone not selected.')); + return; + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('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->showForm(_('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->showForm(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__); + $this->serverError(_('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__); + $this->serverError(_('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__); + $this->serverError(_('Couldn\'t save profile.')); + return; + } + + # Set the user tags + + $result = $user->setSelfTags($tags); + + if (!$result) { + $this->serverError(_('Couldn\'t save tags.')); + return; + } + + $user->query('COMMIT'); + + common_broadcast_profile($profile); + + $this->showForm(_('Settings saved.'), true); + } + + function nicknameExists($nickname) + { + $user = common_current_user(); + $other = User::staticGet('nickname', $nickname); + if (!$other) { + return false; + } else { + return $other->id != $user->id; + } + } } diff --git a/actions/public.php b/actions/public.php index 218f80194..f5380589a 100644 --- a/actions/public.php +++ b/actions/public.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Action for displaying the public stream + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,85 +18,205 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/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'))); - } +if (!defined('LACONICA')) { + exit(1); +} - function show_notices($page) { +require_once INSTALLDIR.'/lib/publicgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; - $cnt = 0; - $notice = Notice::publicStream(($page-1)*NOTICES_PER_PAGE, - NOTICES_PER_PAGE + 1); +/** + * Action for displaying the public stream + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see PublicrssAction + * @see PublicxrdsAction + */ - if (!$notice) { - $this->server_error(_('Could not retrieve public stream.')); +class PublicAction extends Action +{ + /** + * page of the stream we're on; default = 1 + */ + + var $page = null; + + /** + * Read and validate arguments + * + * @param array $args URL parameters + * + * @return boolean success value + */ + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; + } + + /** + * handle request + * + * Show the public stream, using recipe method showPage() + * + * @param array $args arguments, mostly unused + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + header('X-XRDS-Location: '. common_local_url('publicxrds')); + + $this->showPage(); + } + + /** + * Title of the page + * + * @return page title, including page number if over 1 + */ + + function title() + { + if ($this->page > 1) { + return sprintf(_('Public timeline, page %d'), $this->page); + } else { + return _('Public timeline'); + } + } + + /** + * Output <head> elements for RSS and Atom feeds + * + * @return void + */ + + function showFeeds() + { + $this->element('link', array('rel' => 'alternate', + 'href' => common_local_url('publicrss'), + 'type' => 'application/rss+xml', + 'title' => _('Public Stream Feed'))); + } + + /** + * Extra head elements + * + * We include a <meta> element linking to the publicxrds page, for OpenID + * client-side authentication. + * + * @return void + */ + + function extraHead() + { + // for client side of OpenID authentication + $this->element('meta', array('http-equiv' => 'X-XRDS-Location', + 'content' => common_local_url('publicxrds'))); + } + + /** + * Show tabset for this page + * + * Uses the PublicGroupNav widget + * + * @return void + * @see PublicGroupNav + */ + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + /** + * Fill the content area + * + * Shows a list of the notices in the public stream, with some pagination + * controls. + * + * @return void + */ + + function showContent() + { + $notice = Notice::publicStream(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + if (!$notice) { + $this->serverError(_('Could not retrieve public stream.')); return; - } - - $cnt = $this->show_notice_list($notice); - - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'public'); - } + } + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'public'); + } + + /** + * Makes a list of exported feeds for this page + * + * @return void + * + * @todo I18N + */ + + function showExportData() + { + $fl = new FeedList($this); + $fl->show(array(0 => array('href' => common_local_url('publicrss'), + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'publicrss'), + 1 => array('href' => common_local_url('publicatom'), + 'type' => 'atom', + 'version' => 'Atom 1.0', + 'item' => 'publicatom'))); + } + + function showSections() + { + $top = new TopPostersSection($this); + $top->show(); + $pop = new PopularNoticeSection($this); + $pop->show(); + $gbp = new GroupsByPostsSection($this); + $gbp->show(); + $feat = new FeaturedUsersSection($this); + $feat->show(); + } + + function showAnonymousMessage() + { + $m = _('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%%))'); + $this->elementStart('div', array('id' => 'anon_notice')); + $this->raw(common_markup_to_html($m)); + $this->elementEnd('div'); + } } diff --git a/actions/publicrss.php b/actions/publicrss.php index 1ab6a8be0..844c334be 100644 --- a/actions/publicrss.php +++ b/actions/publicrss.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * Public RSS action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,41 +29,78 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/rssaction.php'); - -// Formatting of RSS handled by Rss10Action - -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; - } -}
\ No newline at end of file +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/rssaction.php'; + +/** + * RSS feed for public timeline. + * + * Formatting of RSS handled by Rss10Action + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class PublicrssAction extends Rss10Action +{ + /** + * Initialization. + * + * @return boolean true + */ + function init() + { + return true; + } + + /** + * Get notices + * + * @param integer $limit max number of notices to return + * + * @return array notices + */ + function getNotices($limit=0) + { + $notices = array(); + $notice = Notice::publicStream(0, ($limit == 0) ? 48 : $limit); + while ($notice->fetch()) { + $notices[] = clone($notice); + } + + return $notices; + } + + /** + * Get channel. + * + * @return array associative array on channel information + */ + function getChannel() + { + 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; + } + + /** + * Get image. + * + * @return nothing + */ + function getImage() + { + // nop + } +} + diff --git a/actions/publictagcloud.php b/actions/publictagcloud.php new file mode 100644 index 000000000..6f5fc7541 --- /dev/null +++ b/actions/publictagcloud.php @@ -0,0 +1,155 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Public tag cloud for notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Public + * @package Laconica + * @author Mike Cochrane <mikec@mikenz.geek.nz> + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Mike Cochrane + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { exit(1); } + +define('TAGS_PER_PAGE', 100); + +/** + * Public tag cloud for notices + * + * @category Personal + * @package Laconica + * @author Mike Cochrane <mikec@mikenz.geek.nz> + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Mike Cochrane + * @copyright 2008-2009 Control Yourself, Inc. + * @link http://laconi.ca/ + */ + +class PublictagcloudAction extends Action +{ + function isReadOnly() + { + return true; + } + + function title() + { + return _('Public tag cloud'); + } + + function showPageNotice() + { + $this->element('p', 'instructions', + sprintf(_('These are most popular recent tags on %s '), + common_config('site', 'name'))); + } + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showContent() + { + # This should probably be cached rather than recalculated + $tags = new 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->limit(TAGS_PER_PAGE); + + $cnt = $tags->find(); + + if ($cnt > 0) { + $this->elementStart('div', array('id' => 'tagcloud', + 'class' => 'section')); + + $tw = array(); + $sum = 0; + while ($tags->fetch()) { + $tw[$tags->tag] = $tags->weight; + $sum += $tags->weight; + } + + ksort($tw); + + $this->elementStart('dl'); + $this->element('dt', null, _('Tag cloud')); + $this->elementStart('dd'); + $this->elementStart('ul', 'tags xoxo tag-cloud'); + foreach ($tw as $tag => $weight) { + $this->showTag($tag, $weight, $weight/$sum); + } + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + $this->elementEnd('div'); + } + } + + function showTag($tag, $weight, $relative) + { + if ($relative > 0.1) { + $rel = 'tag-cloud-7'; + } else if ($relative > 0.05) { + $rel = 'tag-cloud-6'; + } else if ($relative > 0.02) { + $rel = 'tag-cloud-5'; + } else if ($relative > 0.01) { + $rel = 'tag-cloud-4'; + } else if ($relative > 0.005) { + $rel = 'tag-cloud-3'; + } else if ($relative > 0.002) { + $rel = 'tag-cloud-2'; + } else { + $rel = 'tag-cloud-1'; + } + + $this->elementStart('li', $rel); + $this->element('a', array('href' => common_local_url('tag', array('tag' => $tag))), + $tag); + $this->elementEnd('li'); + } +} diff --git a/actions/publicxrds.php b/actions/publicxrds.php index 951434c87..aad59d779 100644 --- a/actions/publicxrds.php +++ b/actions/publicxrds.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * Public XRDS for OpenID + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,63 +29,94 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/openid.php'); - -# XXX: factor out similarities with XrdsAction - -class PublicxrdsAction extends Action { - - function is_readonly() { - return true; - } +if (!defined('LACONICA')) { + exit(1); +} - function handle($args) { +require_once INSTALLDIR.'/lib/openid.php'; - parent::handle($args); - - 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)', - 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', - 'version' => '2.0')); - - 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)); - } +/** + * Public XRDS for OpenID + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + * @todo factor out similarities with XrdsAction + */ +class PublicxrdsAction extends Action +{ + /** + * Is read only? + * + * @return boolean true + */ + function isReadOnly() + { + return true; + } - common_element_end('XRD'); + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + function handle($args) + { + parent::handle($args); + header('Content-Type: application/xrds+xml'); + common_start_xml(); + $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds')); + $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $this->element('Type', null, 'xri://$xrds*simple'); + foreach (array('finishopenidlogin', 'finishaddopenid', 'finishimmediate') as $finish) { + $this->showService(Auth_OpenID_RP_RETURN_TO_URL_TYPE, + common_local_url($finish)); + } + $this->elementEnd('XRD'); + $this->elementEnd('XRDS'); + common_end_xml(); + } - common_element_end('XRDS'); - common_end_xml(); - } + /** + * Show service. + * + * @param string $type XRDS type + * @param string $uri URI + * @param array $params type parameters, null by default + * @param array $sigs type signatures, null by default + * @param string $localId local ID, null by default + * + * @return void + */ + function showService($type, $uri, $params=null, $sigs=null, $localId=null) + { + $this->elementStart('Service'); + if ($uri) { + $this->element('URI', null, $uri); + } + $this->element('Type', null, $type); + if ($params) { + foreach ($params as $param) { + $this->element('Type', null, $param); + } + } + if ($sigs) { + foreach ($sigs as $sig) { + $this->element('Type', null, $sig); + } + } + if ($localId) { + $this->element('LocalID', null, $localId); + } + $this->elementEnd('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/actions/recoverpassword.php b/actions/recoverpassword.php index 54a0f2ae3..eeb6b2516 100644 --- a/actions/recoverpassword.php +++ b/actions/recoverpassword.php @@ -23,309 +23,344 @@ if (!defined('LACONICA')) { exit(1); } define(MAX_RECOVERY_TIME, 24 * 60 * 60); -class RecoverpasswordAction extends Action { - - function handle($args) { +class RecoverpasswordAction extends Action +{ + var $mode = null; + var $msg = null; + var $success = null; + + function handle($args) + { parent::handle($args); if (common_logged_in()) { - $this->client_error(_('You are already logged in!')); + $this->clientError(_('You are already logged in!')); return; } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { - if ($this->arg('recover')) { - $this->recover_password(); + if ($this->arg('recover')) { + $this->recoverPassword(); } 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) { - 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) { - 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(); - } + $this->resetPassword(); + } else { + $this->clientError(_('Unexpected form submission.')); + } + } else { + if ($this->trimmed('code')) { + $this->checkCode(); + } else { + $this->showForm(); + } + } + } + + function checkCode() + { + + $code = $this->trimmed('code'); + $confirm = Confirm_address::staticGet('code', $code); + + if (!$confirm) { + $this->clientError(_('No such recovery code.')); + return; + } + if ($confirm->address_type != 'recover') { + $this->clientError(_('Not a recovery code.')); + return; + } + + $user = User::staticGet($confirm->user_id); + + if (!$user) { + $this->serverError(_('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__); + $this->serverError(_('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->clientError(_('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->serverError(_('Could not update user with confirmed email address.')); + return; + } + } + + # Success! + + $this->setTempUser($user); + $this->showPasswordForm(); + } + + function setTempUser(&$user) + { + common_ensure_session(); + $_SESSION['tempuser'] = $user->id; + } + + function getTempUser() + { + common_ensure_session(); + $user_id = $_SESSION['tempuser']; + if ($user_id) { + $user = User::staticGet($user_id); + } + return $user; + } + + function clearTempUser() + { + common_ensure_session(); + unset($_SESSION['tempuser']); + } + + function showPageNotice() + { + if ($this->msg) { + $this->element('div', ($this->success) ? 'success' : 'error', $this->msg); + } else { + $this->elementStart('div', 'instructions'); + if ($this->mode == 'recover') { + $this->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.')); + } else if ($this->mode == 'reset') { + $this->element('p', null, + _('You\'ve been identified. Enter a ' . + ' new password below. ')); + } + $this->elementEnd('div'); + } + } + + function showForm($msg=null) + { + $this->msg = $msg; + $this->mode = 'recover'; + $this->showPage(); + } + + function showContent() + { + if ($this->mode == 'recover') { + $this->showRecoverForm(); + } else if ($this->mode == 'reset') { + $this->showResetForm(); + } + } + + function showRecoverForm() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'recoverpassword', + 'action' => common_local_url('recoverpassword'))); + $this->input('nicknameoremail', _('Nickname or email'), + $this->trimmed('nicknameoremail'), + _('Your nickname on this server, ' . + 'or your registered email address.')); + $this->submit('recover', _('Recover')); + $this->elementEnd('form'); + } + + function title() + { + switch ($this->mode) { + case 'reset': return _('Reset password'); + case 'recover': return _('Recover password'); + case 'sent': return _('Password recovery requested'); + case 'saved': return _('Password saved.'); + default: + return _('Unknown action'); + } + } + + function showPasswordForm($msg=null) + { + $this->msg = $msg; + $this->mode = 'reset'; + $this->showPage(); + } + + function showResetForm() + { + $this->elementStart('form', array('method' => 'post', + 'id' => 'recoverpassword', + 'action' => common_local_url('recoverpassword'))); + $this->hidden('token', common_session_token()); + $this->password('newpassword', _('New password'), + _('6 or more characters, and don\'t forget it!')); + $this->password('confirm', _('Confirm'), + _('Same as password above')); + $this->submit('reset', _('Reset')); + $this->elementEnd('form'); + } + + function recoverPassword() + { + $nore = $this->trimmed('nicknameoremail'); + if (!$nore) { + $this->showForm(_('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->showForm(_('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->clientError(_('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->serverError(_('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); + + $this->mode = 'sent'; + $this->msg = _('Instructions for recovering your password ' . + 'have been sent to the email address registered to your ' . + 'account.'); + $this->success = true; + $this->showPage(); + } + + function resetPassword() + { + # CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. Try again, please.')); + return; + } + + $user = $this->getTempUser(); + + if (!$user) { + $this->clientError(_('Unexpected password reset.')); + return; + } + + $newpassword = $this->trimmed('newpassword'); + $confirm = $this->trimmed('confirm'); + + if (!$newpassword || strlen($newpassword) < 6) { + $this->showPasswordForm(_('Password must be 6 chars or more.')); + return; + } + if ($newpassword != $confirm) { + $this->showPasswordForm(_('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__); + $this->serverError(_('Can\'t save new password.')); + return; + } + + $this->clearTempUser(); + + if (!common_set_user($user->nickname)) { + $this->serverError(_('Error setting user.')); + return; + } + + common_real_login(true); + + $this->mode = 'saved'; + $this->msg = _('New password successfully saved. ' . + 'You are now logged in.'); + $this->success = true; + $this->showPage(); + } } diff --git a/actions/register.php b/actions/register.php index a22ffca28..a63da2e0f 100644 --- a/actions/register.php +++ b/actions/register.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Register a new user account + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,248 +18,498 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Login + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -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(); - } +if (!defined('LACONICA')) { + exit(1); +} + +/** + * An action for registering a new user account + * + * @category Login + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ +class RegisterAction extends Action +{ + /** + * Has there been an error? + */ + + var $error = null; + + /** + * Have we registered? + */ + + var $registered = false; + + /** + * Title of the page + * + * @return string title + */ + + function title() + { + if ($this->registered) { + return _('Registration successful'); + } else { + return _('Register'); + } + } + + /** + * Handle input, produce output + * + * Switches on request method; either shows the form or handles its input. + * + * Checks if registration is closed and shows an error if so. + * + * @param array $args $_REQUEST data + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if (common_config('site', 'closed')) { + $this->clientError(_('Registration not allowed.')); + } else if (common_logged_in()) { + $this->clientError(_('Already logged in.')); + } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->tryRegister(); + } else { + $this->showForm(); + } + } + + /** + * Try to register a user + * + * Validates the input and tries to save a new user and profile + * record. On success, shows an instructions page. + * + * @return void + */ + + function tryRegister() + { + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('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->clientError(_('Sorry, only invited people can register.')); + return; + } + + // Input scrubbing + + $nickname = common_canonical_nickname($nickname); + $email = common_canonical_email($email); + + if (!$this->boolean('license')) { + $this->showForm(_('You can\'t register if you don\'t '. + 'agree to the license.')); + } else if ($email && !Validate::email($email, true)) { + $this->showForm(_('Not a valid email address.')); + } else if (!Validate::string($nickname, array('min_length' => 1, + 'max_length' => 64, + 'format' => NICKNAME_FMT))) { + $this->showForm(_('Nickname must have only lowercase letters '. + 'and numbers and no spaces.')); + } else if ($this->nicknameExists($nickname)) { + $this->showForm(_('Nickname already in use. Try another one.')); + } else if (!User::allowed_nickname($nickname)) { + $this->showForm(_('Not a valid nickname.')); + } else if ($this->emailExists($email)) { + $this->showForm(_('Email address already exists.')); + } else if (!is_null($homepage) && (strlen($homepage) > 0) && + !Validate::uri($homepage, + array('allowed_schemes' => + array('http', 'https')))) { + $this->showForm(_('Homepage is not a valid URL.')); + return; + } else if (!is_null($fullname) && strlen($fullname) > 255) { + $this->showForm(_('Full name is too long (max 255 chars).')); + return; + } else if (!is_null($bio) && strlen($bio) > 140) { + $this->showForm(_('Bio is too long (max 140 chars).')); + return; + } else if (!is_null($location) && strlen($location) > 255) { + $this->showForm(_('Location is too long (max 255 chars).')); + return; + } else if (strlen($password) < 6) { + $this->showForm(_('Password must be 6 or more characters.')); + return; + } else if ($password != $confirm) { + $this->showForm(_('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->showForm(_('Invalid username or password.')); + return; + } + // success! + if (!common_set_user($user)) { + $this->serverError(_('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->showSuccess(); + } else { + $this->showForm(_('Invalid username or password.')); + } + } + + /** + * Does the given nickname already exist? + * + * Checks a canonical nickname against the database. + * + * @param string $nickname nickname to check + * + * @return boolean true if the nickname already exists + */ + + function nicknameExists($nickname) + { + $user = User::staticGet('nickname', $nickname); + return ($user !== false); + } + + /** + * Does the given email address already exist? + * + * Checks a canonical email address against the database. + * + * @param string $email email address to check + * + * @return boolean true if the address already exists + */ + + function emailExists($email) + { + $email = common_canonical_email($email); + if (!$email || strlen($email) == 0) { + return false; + } + $user = User::staticGet('email', $email); + return ($user !== false); + } + + // overrrided to add entry-title class + function showPageTitle() { + $this->element('h1', array('class' => 'entry-title'), $this->title()); + } + + // overrided to add hentry, and content-inner class + function showContentBlock() + { + $this->elementStart('div', array('id' => 'content', 'class' => 'hentry')); + $this->showPageTitle(); + $this->showPageNoticeBlock(); + $this->elementStart('div', array('id' => 'content_inner', + 'class' => 'entry-content')); + // show the actual content (forms, lists, whatever) + $this->showContent(); + $this->elementEnd('div'); + $this->elementEnd('div'); + } + + /** + * Instructions or a notice for the page + * + * Shows the error, if any, or instructions for registration. + * + * @return void + */ + + function showPageNotice() + { + if ($this->registered) { + return; + } else if ($this->error) { + $this->element('p', 'error', $this->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%%)!)')); + + $this->elementStart('div', 'instructions'); + $this->raw($instr); + $this->elementEnd('div'); + } + } + + /** + * Wrapper for showing a page + * + * Stores an error and shows the page + * + * @param string $error Error, if any + * + * @return void + */ + + function showForm($error=null) + { + $this->error = $error; + $this->showPage(); + } + + /** + * Show the page content + * + * Either shows the registration form or, if registration was successful, + * instructions for using the site. + * + * @return void + */ + + function showContent() + { + if ($this->registered) { + $this->showSuccessContent(); + } else { + $this->showFormContent(); + } + } + + /** + * Show the registration form + * + * @return void + */ + + function showFormContent() + { + $code = $this->trimmed('code'); + + if ($code) { + $invite = Invitation::staticGet($code); + } + + if (common_config('site', 'inviteonly') && !($code && $invite)) { + $this->clientError(_('Sorry, only invited people can register.')); + return; + } + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_register', + 'class' => 'form_settings', + 'action' => common_local_url('register'))); + $this->elementStart('fieldset'); + $this->element('legend', null, 'Account settings'); + $this->hidden('token', common_session_token()); + + if ($code) { + $this->hidden('code', $code); + } + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), + _('1-64 lowercase letters or numbers, '. + 'no punctuation or spaces. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('password', _('Password'), + _('6 or more characters. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('confirm', _('Confirm'), + _('Same as password above. Required.')); + $this->elementEnd('li'); + $this->elementStart('li'); + if ($invite && $invite->address_type == 'email') { + $this->input('email', _('Email'), $invite->address, + _('Used only for updates, announcements, '. + 'and password recovery')); + } else { + $this->input('email', _('Email'), $this->trimmed('email'), + _('Used only for updates, announcements, '. + 'and password recovery')); + } + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('fullname', _('Full name'), + $this->trimmed('fullname'), + _('Longer name, preferably your "real" name')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('homepage', _('Homepage'), + $this->trimmed('homepage'), + _('URL of your homepage, blog, '. + 'or profile on another site')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->textarea('bio', _('Bio'), + $this->trimmed('bio'), + _('Describe yourself and your '. + 'interests in 140 chars')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('location', _('Location'), + $this->trimmed('location'), + _('Where you are, like "City, '. + 'State (or Region), Country"')); + $this->elementEnd('li'); + $this->elementStart('li', array('id' => 'settings_rememberme')); + $this->checkbox('rememberme', _('Remember me'), + $this->boolean('rememberme'), + _('Automatically login in the future; '. + 'not for shared computers!')); + $this->elementEnd('li'); + $attrs = array('type' => 'checkbox', + 'id' => 'license', + 'class' => 'checkbox', + 'name' => 'license', + 'value' => 'true'); + if ($this->boolean('license')) { + $attrs['checked'] = 'checked'; + } + $this->elementStart('li'); + $this->element('input', $attrs); + $this->text(_('My text and files are available under ')); + $this->element('a', array('href' => common_config('license', 'url')), + $config['license']['title']); + $this->text(_(' except this private data: password, '. + 'email address, IM address, phone number.')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('submit', _('Register')); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + /** + * Show some information about registering for the site + * + * Save the registration flag, run showPage + * + * @return void + */ + + function showSuccess() + { + $this->registered = true; + $this->showPage(); + } + + /** + * Show some information about registering for the site + * + * Gives some information and options for new registrees. + * + * @return void + */ + + function showSuccessContent() + { + $nickname = $this->arg('nickname'); + + $profileurl = common_local_url('showstream', + array('nickname' => $nickname)); + + $this->elementStart('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, $profileurl); + + $this->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.)'); + $this->raw(common_markup_to_html($emailinstr)); + } + $this->elementEnd('div'); + } + + /** + * Show the login group nav menu + * + * @return void + */ + + function showLocalNav() + { + $nav = new LoginGroupNav($this); + $nav->show(); + } } diff --git a/actions/remotesubscribe.php b/actions/remotesubscribe.php index 624497af7..f727a63b8 100644 --- a/actions/remotesubscribe.php +++ b/actions/remotesubscribe.php @@ -21,366 +21,396 @@ if (!defined('LACONICA')) { exit(1); } 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 +class RemotesubscribeAction extends Action +{ + var $nickname; + var $profile_url; + var $err; + + function prepare($args) + { + parent::prepare($args); + + if (common_logged_in()) { + $this->clientError(_('You can use the local subscription!')); + return false; + } + + $this->nickname = $this->trimmed('nickname'); + $this->profile_url = $this->trimmed('profile_url'); + + return true; + } + + function handle($args) + { + parent::handle($args); + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + # CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + $this->remoteSubscription(); + } else { + $this->showForm(); + } + } + + function showForm($err=null) + { + $this->err = $err; + $this->showPage(); + } + + function showPageNotice() + { + if ($this->err) { + $this->element('div', 'error', $this->err); + } else { + $inst = _('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.'); + $output = common_markup_to_html($inst); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } + + function title() + { + return _('Remote subscribe'); + } + + function showContent() + { + # id = remotesubscribe conflicts with the + # button on profile page + $this->elementStart('form', array('id' => 'form_remote_subscribe', + 'method' => 'post', + 'class' => 'form_settings', + 'action' => common_local_url('remotesubscribe'))); + $this->elementStart('fieldset'); + $this->element('legend', 'Subscribe to a remote user'); + $this->hidden('token', common_session_token()); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('nickname', _('User nickname'), $this->nickname, + _('Nickname of the user you want to follow')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->input('profile_url', _('Profile URL'), $this->profile_url, + _('URL of your profile on another compatible microblogging service')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('submit', _('Subscribe')); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + function remoteSubscription() + { + $user = $this->getUser(); + + if (!$user) { + $this->showForm(_('No such user.')); + return; + } + + $this->profile_url = $this->trimmed('profile_url'); + + if (!$this->profile_url) { + $this->showForm(_('No such user.')); + return; + } + + if (!Validate::uri($this->profile_url, array('allowed_schemes' => array('http', 'https')))) { + $this->showForm(_('Invalid profile URL (bad format)')); + return; + } + + $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); + $yadis = Auth_Yadis_Yadis::discover($this->profile_url, $fetcher); + + if (!$yadis || $yadis->failed) { + $this->showForm(_('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->showForm(_('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->showForm(_('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->showForm(_('That\'s a local profile! Login to subscribe.')); + return; + } + + if (User::staticGet('uri', omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]))) { + $this->showForm(_('That\'s a local profile! Login to subscribe.')); + return; + } + + list($token, $secret) = $this->requestToken($omb); + + if (!$token || !$secret) { + $this->showForm(_('Couldn\'t get a request token.')); + return; + } + + $this->requestAuthorization($user, $omb, $token, $secret); + } + + function getUser() + { + $user = null; + if ($this->nickname) { + $user = User::staticGet('nickname', $this->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 (!$this->addServices($oauth_xrd, $oauth_endpoints, $omb)) { + return null; + } + + $omb_services = omb_get_services($xrds, OMB_NAMESPACE); + + if (!$omb_services) { + return null; + } + + $omb_service = $omb_services[0]; + + $omb_xrd = $this->getXRD($omb_service, $xrds); + + if (!$omb_xrd) { + return null; + } + + if (!$this->addServices($omb_xrd, $omb_endpoints, $omb)) { + return null; + } + + # 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; + } + } + + if (!omb_local_id($omb[OAUTH_ENDPOINT_REQUEST])) { + return null; + } + + 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 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; + } - if (!$oauth_xrd) { - return NULL; - } + function requestToken($omb) + { + $con = omb_oauth_consumer(); - if (!$this->addServices($oauth_xrd, $oauth_endpoints, $omb)) { - return NULL; - } + $url = omb_service_uri($omb[OAUTH_ENDPOINT_REQUEST]); - $omb_services = omb_get_services($xrds, OMB_NAMESPACE); + # XXX: Is this the right thing to do? Strip off GET params and make them + # POST params? Seems wrong to me. - if (!$omb_services) { - return NULL; - } + $parsed = parse_url($url); + $params = array(); + parse_str($parsed['query'], $params); - $omb_service = $omb_services[0]; + $req = OAuthRequest::from_consumer_and_token($con, null, "POST", $url, $params); - $omb_xrd = $this->getXRD($omb_service, $xrds); + $listener = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]); - if (!$omb_xrd) { - return NULL; - } + if (!$listener) { + return null; + } - if (!$this->addServices($omb_xrd, $omb_endpoints, $omb)) { - return NULL; - } - - # 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; - } - } - - if (!omb_local_id($omb[OAUTH_ENDPOINT_REQUEST])) { - return NULL; - } - - 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 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(); - - $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. - - $parsed = parse_url($url); - $params = array(); - parse_str($parsed['query'], $params); - - $req = OAuthRequest::from_consumer_and_token($con, NULL, "POST", $url, $params); - - $listener = omb_local_id($omb[OAUTH_ENDPOINT_REQUEST]); - - if (!$listener) { - return NULL; - } - - $req->set_parameter('omb_listener', $listener); - $req->set_parameter('omb_version', OMB_VERSION_01); - - # XXX: test to see if endpoint accepts this signature method - - $req->sign_request(omb_hmac_sha1(), $con, NULL); - - # We re-use this tool's fetcher, since it's pretty good - - $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); - - $result = $fetcher->post($req->get_normalized_http_url(), - $req->to_postdata(), + $req->set_parameter('omb_listener', $listener); + $req->set_parameter('omb_version', OMB_VERSION_01); + + # XXX: test to see if endpoint accepts this signature method + + $req->sign_request(omb_hmac_sha1(), $con, null); + + # We re-use this tool's fetcher, since it's pretty good + + $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); + + $result = $fetcher->post($req->get_normalized_http_url(), + $req->to_postdata(), array('User-Agent' => 'Laconica/' . LACONICA_VERSION)); - if ($result->status != 200) { - return NULL; - } - - parse_str($result->body, $return); + if ($result->status != 200) { + return null; + } - return array($return['oauth_token'], $return['oauth_token_secret']); - } + parse_str($result->body, $return); - function request_authorization($user, $omb, $token, $secret) { - global $config; # for license URL + return array($return['oauth_token'], $return['oauth_token_secret']); + } - $con = omb_oauth_consumer(); - $tok = new OAuthToken($token, $secret); + function requestAuthorization($user, $omb, $token, $secret) + { + global $config; # for license URL - $url = omb_service_uri($omb[OAUTH_ENDPOINT_AUTHORIZE]); + $con = omb_oauth_consumer(); + $tok = new OAuthToken($token, $secret); - # XXX: Is this the right thing to do? Strip off GET params and make them - # POST params? Seems wrong to me. + $url = omb_service_uri($omb[OAUTH_ENDPOINT_AUTHORIZE]); - $parsed = parse_url($url); - $params = array(); - parse_str($parsed['query'], $params); + # XXX: Is this the right thing to do? Strip off GET params and make them + # POST params? Seems wrong to me. - $req = OAuthRequest::from_consumer_and_token($con, $tok, 'GET', $url, $params); + $parsed = parse_url($url); + $params = array(); + parse_str($parsed['query'], $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. + $req = OAuthRequest::from_consumer_and_token($con, $tok, 'GET', $url, $params); - $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']); + # 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. - $profile = $user->getProfile(); - if (!$profile) { - common_log_db_error($user, 'SELECT', __FILE__); - $this->server_error(_('User without matching profile')); - return; - } + $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']); - 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); - } + $profile = $user->getProfile(); + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('User without matching profile')); + return; + } - # XXX: add a nonce to prevent replay attacks + 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); + } - $req->set_parameter('oauth_callback', common_local_url('finishremotesubscribe')); + # XXX: add a nonce to prevent replay attacks - # XXX: test to see if endpoint accepts this signature method + $req->set_parameter('oauth_callback', common_local_url('finishremotesubscribe')); - $req->sign_request(omb_hmac_sha1(), $con, $tok); + # XXX: test to see if endpoint accepts this signature method - # store all our info here + $req->sign_request(omb_hmac_sha1(), $con, $tok); - $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]); + # store all our info here - common_ensure_session(); + $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]); - $_SESSION['oauth_authorization_request'] = $omb; + common_ensure_session(); - # Redirect to authorization service + $_SESSION['oauth_authorization_request'] = $omb; - common_redirect($req->to_url()); - return; - } + # Redirect to authorization service - function make_nonce() { - return common_good_rand(16); - } + common_redirect($req->to_url()); + return; + } } diff --git a/actions/replies.php b/actions/replies.php index 835871ffc..ea8ef4764 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * List of replies + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,80 +18,177 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/actions/showstream.php'); - -class RepliesAction extends StreamAction { - - function handle($args) { - - parent::handle($args); - - $nickname = common_canonical_nickname($this->arg('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; show the header - - common_show_header(sprintf(_("Replies to %s"), $profile->nickname), - array($this, 'show_header'), $user, - array($this, 'show_top')); - - $this->show_replies($user); - - common_show_footer(); - } - - 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_top($user) { - $cur = common_current_user(); - - if ($cur && $cur->id == $user->id) { - common_notice_form('replies'); - } - - $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'))); - } - - function show_replies($user) { - - $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; +if (!defined('LACONICA')) { + exit(1); +} - $notice = $user->getReplies(($page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); +require_once INSTALLDIR.'/lib/personalgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; - $cnt = $this->show_notice_list($notice); +/** + * List of replies + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'replies', array('nickname' => $user->nickname)); - } +class RepliesAction extends Action +{ + var $user = null; + var $page = null; + + /** + * Prepare the object + * + * Check the input values and initialize the object. + * Shows an error page on bad input. + * + * @param array $args $_REQUEST data + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + + $nickname = common_canonical_nickname($this->arg('nickname')); + + $this->user = User::staticGet('nickname', $nickname); + + if (!$this->user) { + $this->clientError(_('No such user.')); + return false; + } + + $profile = $this->user->getProfile(); + + if (!$profile) { + $this->serverError(_('User has no profile.')); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + return true; + } + + /** + * Handle a request + * + * Just show the page. All args already handled. + * + * @param array $args $_REQUEST data + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + /** + * Title of the page + * + * Includes name of user and page number. + * + * @return string title of page + */ + + function title() + { + if ($this->page == 1) { + return sprintf(_("Replies to %s"), $this->user->nickname); + } else { + return sprintf(_("Replies to %s, page %d"), + $profile->nickname, + $this->page); + } + } + + /** + * Feeds for the <head> section + * + * @return void + */ + + function showFeeds() + { + $rssurl = common_local_url('repliesrss', + array('nickname' => $this->user->nickname)); + $rsstitle = sprintf(_('Feed for replies to %s'), $this->user->nickname); + + $this->element('link', array('rel' => 'alternate', + 'href' => $rssurl, + 'type' => 'application/rss+xml', + 'title' => $rsstitle)); + } + + /** + * show the personal group nav + * + * @return void + */ + + function showLocalNav() + { + $nav = new PersonalGroupNav($this); + $nav->show(); + } + + /** + * Show the replies feed links + * + * @return void + */ + + function showExportData() + { + $fl = new FeedList($this); + + $rssurl = common_local_url('repliesrss', + array('nickname' => $this->user->nickname)); + + $fl->show(array(0=>array('href'=> $rssurl, + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'repliesrss'))); + } + + /** + * Show the content + * + * A list of notices that are replies to the user, plus pagination. + * + * @return void + */ + + function showContent() + { + $notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'replies', + array('nickname' => $this->user->nickname)); + } } diff --git a/actions/repliesrss.php b/actions/repliesrss.php index 7369db5e0..48c4fa255 100644 --- a/actions/repliesrss.php +++ b/actions/repliesrss.php @@ -23,57 +23,63 @@ require_once(INSTALLDIR.'/lib/rssaction.php'); // Formatting of RSS handled by Rss10Action -class RepliesrssAction extends Rss10Action { +class RepliesrssAction extends Rss10Action +{ - var $user = NULL; + var $user = null; - function init() { - $nickname = $this->trimmed('nickname'); - $this->user = User::staticGet('nickname', $nickname); + function prepare($args) + { + parent::prepare($args); + $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) { + $this->clientError(_('No such user.')); + return false; + } else { + return true; + } + } - function get_notices($limit=0) { + function getNotices($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 getChannel() + { + $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; - } -}
\ No newline at end of file + function getImage() + { + $user = $this->user; + $profile = $user->getProfile(); + if (!$profile) { + return null; + } + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); + return ($avatar) ? $avatar->url : null; + } +} diff --git a/actions/requesttoken.php b/actions/requesttoken.php index 76019a929..ca253b97a 100644 --- a/actions/requesttoken.php +++ b/actions/requesttoken.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * Request token action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,26 +29,53 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/omb.php'); +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()); - } - } +/** + * Request token action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class RequesttokenAction extends Action +{ + /** + * Is read only? + * + * @return boolean false + */ + function isReadOnly() + { + return false; + } + + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return void + */ + 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) { + $this->serverError($e->getMessage()); + } + } } + diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 4de4b1271..bb68f8d94 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * List of replies + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,83 +18,197 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/actions/showstream.php'); - -class ShowfavoritesAction extends StreamAction { - - function handle($args) { - - parent::handle($args); - - $nickname = common_canonical_nickname($this->arg('nickname')); - $user = User::staticGet('nickname', $nickname); - - if (!$user) { - $this->client_error(_('No such user.')); - return; - } - - $profile = $user->getProfile(); - - if (!$profile) { - common_server_error(_('User has no profile.')); - return; - } - - # 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')); - - $this->show_notices($user); - - 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_top($user) { - $cur = common_current_user(); - - 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(); - } - - function show_notices($user) { - - $page = $this->trimmed('page'); - if (!$page) { - $page = 1; - } - - $notice = $user->favoriteNotices(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); +if (!defined('LACONICA')) { + exit(1); +} - if (!$notice) { - $this->server_error(_('Could not retrieve favorite notices.')); - return; - } +require_once INSTALLDIR.'/lib/personalgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; - $cnt = $this->show_notice_list($notice); +/** + * List of replies + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'showfavorites', array('nickname' => $user->nickname)); - } +class ShowfavoritesAction extends Action +{ + /** User we're getting the faves of */ + var $user = null; + /** Page of the faves we're on */ + var $page = null; + + /** + * Is this a read-only page? + * + * @return boolean true + */ + + function isReadOnly() + { + return true; + } + + /** + * Title of the page + * + * Includes name of user and page number. + * + * @return string title of page + */ + + function title() + { + if ($this->page == 1) { + return sprintf(_("%s favorite notices"), $this->user->nickname); + } else { + return sprintf(_("%s favorite notices, page %d"), + $this->user->nickname, + $this->page); + } + } + + /** + * Prepare the object + * + * Check the input values and initialize the object. + * Shows an error page on bad input. + * + * @param array $args $_REQUEST data + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + + $nickname = common_canonical_nickname($this->arg('nickname')); + + $this->user = User::staticGet('nickname', $nickname); + + if (!$this->user) { + $this->clientError(_('No such user.')); + return false; + } + + $this->page = $this->trimmed('page'); + + if (!$this->page) { + $this->page = 1; + } + + return true; + } + + /** + * Handle a request + * + * Just show the page. All args already handled. + * + * @param array $args $_REQUEST data + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + /** + * Feeds for the <head> section + * + * @return void + */ + + function showFeeds() + { + $feedurl = common_local_url('favoritesrss', + array('nickname' => + $this->user->nickname)); + $feedtitle = sprintf(_('Feed for favorites of %s'), + $this->user->nickname); + + $this->element('link', array('rel' => 'alternate', + 'href' => $feedurl, + 'type' => 'application/rss+xml', + 'title' => $feedtitle)); + } + + /** + * show the personal group nav + * + * @return void + */ + + function showLocalNav() + { + $nav = new PersonalGroupNav($this); + $nav->show(); + } + + /** + * Show the replies feed links + * + * @return void + */ + + function showExportData() + { + $feedurl = common_local_url('favoritesrss', + array('nickname' => + $this->user->nickname)); + + $fl = new FeedList($this); + + // XXX: I18N + + $fl->show(array(0=>array('href'=> $feedurl, + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'Favorites'))); + } + + /** + * Show the content + * + * A list of notices that this user has marked as a favorite + * + * @return void + */ + + function showContent() + { + $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + if (!$notice) { + $this->serverError(_('Could not retrieve favorite notices.')); + return; + } + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'showfavorites', + array('nickname' => $this->user->nickname)); + } } diff --git a/actions/showgroup.php b/actions/showgroup.php new file mode 100644 index 000000000..99367a97c --- /dev/null +++ b/actions/showgroup.php @@ -0,0 +1,387 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Group main page + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; + +define('MEMBERS_PER_SECTION', 81); + +/** + * Group main page + * + * @category Group + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class ShowgroupAction extends Action +{ + /** group we're viewing. */ + var $group = null; + /** page we're viewing. */ + var $page = null; + + /** + * Is this page read-only? + * + * @return boolean true + */ + + function isReadOnly() + { + return true; + } + + /** + * Title of the page + * + * @return string page title, with page number + */ + + function title() + { + if ($this->page == 1) { + return sprintf(_("%s group"), $this->group->nickname); + } else { + return sprintf(_("%s group, page %d"), + $this->group->nickname, + $this->page); + } + } + + /** + * Prepare the action + * + * Reads and validates arguments and instantiates the attributes. + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + + if (!common_config('inboxes','enabled')) { + $this->serverError(_('Inboxes must be enabled for groups to work')); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + $nickname_arg = $this->arg('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + if ($this->page != 1) { + $args['page'] = $this->page; + } + common_redirect(common_local_url('showgroup', $args), 301); + return false; + } + + if (!$nickname) { + $this->clientError(_('No nickname'), 404); + return false; + } + + $this->group = User_group::staticGet('nickname', $nickname); + + if (!$this->group) { + $this->clientError(_('No such group'), 404); + return false; + } + + return true; + } + + /** + * Handle the request + * + * Shows a profile for the group, some controls, and a list of + * group notices. + * + * @return void + */ + + function handle($args) + { + $this->showPage(); + } + + /** + * Local menu + * + * @return void + */ + + function showLocalNav() + { + $nav = new GroupNav($this, $this->group); + $nav->show(); + } + + /** + * Show the page content + * + * Shows a group profile and a list of group notices + */ + + function showContent() + { + $this->showGroupProfile(); + $this->showGroupNotices(); + } + + /** + * Show the group notices + * + * @return void + */ + + function showGroupNotices() + { + $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); + + $nl = new NoticeList($notice, $this); + $cnt = $nl->show(); + + $this->pagination($this->page > 1, + $cnt > NOTICES_PER_PAGE, + $this->page, + 'showgroup', + array('nickname' => $this->group->nickname)); + } + + /** + * Show the group profile + * + * Information about the group + * + * @return void + */ + + function showGroupProfile() + { + $this->elementStart('div', 'entity_profile vcard author'); + + $this->element('h2', null, _('Group profile')); + + $this->elementStart('dl', 'entity_depiction'); + $this->element('dt', null, _('Avatar')); + $this->elementStart('dd'); + + $logo = ($this->group->homepage_logo) ? + $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE); + + $this->element('img', array('src' => $logo, + 'class' => 'photo avatar', + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->group->nickname)); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + $this->elementStart('dl', 'entity_nickname'); + $this->element('dt', null, _('Nickname')); + $this->elementStart('dd'); + $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid'; + $this->element('a', array('href' => $this->group->homeUrl(), + 'rel' => 'me', 'class' => $hasFN), + $this->group->nickname); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + if ($this->group->fullname) { + $this->elementStart('dl', 'entity_fn'); + $this->element('dt', null, _('Full name')); + $this->elementStart('dd'); + $this->element('span', 'fn org', $this->group->fullname); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + if ($this->group->location) { + $this->elementStart('dl', 'entity_location'); + $this->element('dt', null, _('Location')); + $this->element('dd', 'location', $this->group->location); + $this->elementEnd('dl'); + } + + if ($this->group->homepage) { + $this->elementStart('dl', 'entity_url'); + $this->element('dt', null, _('URL')); + $this->elementStart('dd'); + $this->element('a', array('href' => $this->group->homepage, + 'rel' => 'me', 'class' => 'url'), + $this->group->homepage); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + if ($this->group->description) { + $this->elementStart('dl', 'entity_note'); + $this->element('dt', null, _('Note')); + $this->element('dd', 'note', $this->group->description); + $this->elementEnd('dl'); + } + + $this->elementEnd('div'); + + $this->elementStart('div', 'entity_actions'); + $this->element('h2', null, _('Group actions')); + $this->elementStart('ul'); + $this->elementStart('li', array('id' => 'entity_subscribe')); + $cur = common_current_user(); + if ($cur) { + if ($cur->isMember($this->group)) { + if (!$cur->isAdmin($this->group)) { + $lf = new LeaveForm($this, $this->group); + $lf->show(); + } + } else { + $jf = new JoinForm($this, $this->group); + $jf->show(); + } + } + + $this->elementEnd('li'); + + $this->elementEnd('ul'); + $this->elementEnd('div'); + } + + /** + * Show a list of links to feeds this page produces + * + * @return void + */ + + function showExportData() + { + $fl = new FeedList($this); + $fl->show(array(0=>array('href'=>common_local_url('grouprss', + array('nickname' => $this->group->nickname)), + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'notices'))); + } + + /** + * Show a list of links to feeds this page produces + * + * @return void + */ + + function showFeeds() + { + $url = + common_local_url('grouprss', + array('nickname' => $this->group->nickname)); + + $this->element('link', array('rel' => 'alternate', + 'href' => $url, + 'type' => 'application/rss+xml', + 'title' => sprintf(_('Notice feed for %s group'), + $this->group->nickname))); + } + + /** + * Fill in the sidebar. + * + * @return void + */ + + function showSections() + { + $this->showMembers(); + $cloud = new GroupTagCloudSection($this, $this->group); + $cloud->show(); + } + + /** + * Show mini-list of members + * + * @return void + */ + + function showMembers() + { + $member = $this->group->getMembers(0, MEMBERS_PER_SECTION); + + if (!$member) { + return; + } + + $this->elementStart('div', array('id' => 'entity_members', + 'class' => 'section')); + + $this->element('h2', null, _('Members')); + + if ($member) { + $pml = new ProfileMiniList($member, null, $this); + $cnt = $pml->show(); + if ($cnt == 0) { + $this->element('p', null, _('(None)')); + } + } + + if ($cnt == MEMBERS_PER_SECTION) { + $this->element('a', array('href' => common_local_url('groupmembers', + array('nickname' => $this->group->nickname))), + _('All members')); + } + + $this->elementEnd('div'); + } + + function showAnonymousMessage() + { + $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . + 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' . + 'short messages about their life and interests. '. + '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'), + $this->group->nickname); + $this->elementStart('div', array('id' => 'anon_notice')); + $this->raw(common_markup_to_html($m)); + $this->elementEnd('div'); + } +} diff --git a/actions/showmessage.php b/actions/showmessage.php index c171ffe0b..289414153 100644 --- a/actions/showmessage.php +++ b/actions/showmessage.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Show a single message + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,86 +18,162 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ +if (!defined('LACONICA')) { + exit(1); +} -if (!defined('LACONICA')) { exit(1); } +require_once INSTALLDIR.'/lib/mailbox.php'; -require_once(INSTALLDIR.'/lib/mailbox.php'); +/** + * Show a single message + * + * // XXX: It is totally weird how this works! + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ -class ShowmessageAction extends MailboxAction { +class ShowmessageAction extends MailboxAction +{ + /** + * Message object to show + */ - function handle($args) { + var $message = null; + + /** + * The current user + */ + + var $user = null; - Action::handle($args); + /** + * Load attributes based on database arguments + * + * Loads all the DB stuff + * + * @param array $args $_REQUEST array + * + * @return success flag + */ - $message = $this->get_message(); + function prepare($args) + { + parent::prepare($args); + + $this->page = 1; + + $id = $this->trimmed('message'); + $this->message = Message::staticGet('id', $id); - 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 (!$this->message) { + $this->clientError(_('No such message.'), 404); + return false; + } - 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 + $this->user = common_current_user(); + + return true; + } + + function handle($args) + { + Action::handle($args); + + if ($this->user && ($this->user->id == $this->message->from_profile || + $this->user->id == $this->message->to_profile)) { + $this->showPage(); + } else { + $this->clientError(_('Only the sender and recipient ' . + 'may read this message.'), 403); + return; + } + } + + function title() + { + if ($this->user->id == $this->message->from_profile) { + $to = $this->message->getTo(); + return sprintf(_("Message to %1\$s on %2\$s"), + $to->nickname, + common_exact_date($this->message->created)); + } else if ($this->user->id == $this->message->to_profile) { + $from = $this->message->getFrom(); + return sprintf(_("Message from %1\$s on %2\$s"), + $from->nickname, + common_exact_date($this->message->created)); + } + } + + function getMessages() + { + $message = new Message(); + $message->id = $this->message->id; + $message->find(); + return $message; + } + + function getMessageProfile() + { + if ($this->user->id == $this->message->from_profile) { + return $this->message->getTo(); + } else if ($this->user->id == $this->message->to_profile) { + return $this->message->getFrom(); + } else { + // This shouldn't happen + return null; + } + } + + /** + * Don't show local navigation + * + * @return void + */ + + function showLocalNavBlock() + { + } + + /** + * Don't show page notice + * + * @return void + */ + + function showPageNoticeBlock() + { + } + + /** + * Don't show aside + * + * @return void + */ + + function showAside() + { + } + + /** + * Don't show any instructions + * + * @return string + */ + + function getInstructions() + { + return ''; + } +}
\ No newline at end of file diff --git a/actions/shownotice.php b/actions/shownotice.php index 6dea6d7bb..d5f35cd84 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Show a single notice + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,102 +18,247 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/personalgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; + +/** + * Show a single notice + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class ShownoticeAction extends Action +{ + /** + * Notice object to show + */ + + var $notice = null; + + /** + * Profile of the notice object + */ + + var $profile = null; + + /** + * Avatar of the profile of the notice object + */ + + var $avatar = null; + + /** + * Load attributes based on database arguments + * + * Loads all the DB stuff + * + * @param array $args $_REQUEST array + * + * @return success flag + */ -require_once(INSTALLDIR.'/lib/stream.php'); + function prepare($args) + { + parent::prepare($args); -class ShownoticeAction extends StreamAction { + $id = $this->arg('notice'); - var $notice = NULL; - var $profile = NULL; - var $avatar = NULL; + $this->notice = Notice::staticGet($id); - function prepare($args) { + if (!$this->notice) { + $this->clientError(_('No such notice.'), 404); + return false; + } - parent::prepare($args); + $this->profile = $this->notice->getProfile(); - $id = $this->arg('notice'); - $this->notice = Notice::staticGet($id); + if (!$this->profile) { + $this->serverError(_('Notice has no profile'), 500); + return false; + } - if (!$this->notice) { - $this->client_error(_('No such notice.'), 404); - return false; - } + $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); - $this->profile = $this->notice->getProfile(); + return true; + } - if (!$this->profile) { - $this->server_error(_('Notice has no profile'), 500); - return false; - } + /** + * Is this action read-only? + * + * @return boolean true + */ - $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE); + function isReadOnly() + { + return true; + } - return true; - } + /** + * Last-modified date for page + * + * When was the content of this page last modified? Based on notice, + * profile, avatar. + * + * @return int last-modified date as unix timestamp + */ - function last_modified() { - return max(strtotime($this->notice->created), - strtotime($this->profile->modified), - ($this->avatar) ? strtotime($this->avatar->modified) : 0); - } + function lastModified() + { + 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)) . '"'; - } + /** + * An entity tag for this page + * + * Shows the ETag for the page, based on the notice ID and timestamps + * for the notice, profile, and avatar. It's weak, since we change + * the date text "one hour ago", etc. + * + * @return string etag + */ - function handle($args) { + function etag() + { + $avtime = ($this->avatar) ? + strtotime($this->avatar->modified) : 0; - parent::handle($args); + return 'W/"' . implode(':', array($this->arg('action'), + common_language(), + $this->notice->id, + strtotime($this->notice->created), + strtotime($this->profile->modified), + $avtime)) . '"'; + } - 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')); + /** + * Title of the page + * + * @return string title of the page + */ - common_element_start('ul', array('id' => 'notices')); - $nli = new NoticeListItem($this->notice); + function title() + { + return sprintf(_('%1$s\'s status on %2$s'), + $this->profile->nickname, + common_exact_date($this->notice->created)); + } + + /** + * Handle input + * + * Only handles get, so just show the page. + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + $this->showPage(); + } + + + /** + * Don't show local navigation + * + * @return void + */ + + function showLocalNavBlock() + { + } + + + /** + * Fill the content area of the page + * + * Shows a single notice list item. + * + * @return void + */ + + function showContent() + { + $this->elementStart('ul', array('class' => 'notices')); + $nli = new NoticeListItem($this->notice, $this); $nli->show(); - common_element_end('ul'); + $this->elementEnd('ul'); + } + + + + /** + * Don't show page notice + * + * @return void + */ + + function showPageNoticeBlock() + { + } + - common_show_footer(); - } + /** + * Don't show aside + * + * @return void + */ - function show_header() { + function showAside() { + } - $user = User::staticGet($this->profile->id); - if (!$user) { - return; - } + /** + * Extra <head> content + * + * We show the microid(s) for the author, if any. + * + * @return void + */ - 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)))); - } + function extraHead() + { + $user = User::staticGet($this->profile->id); - 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) { + return; + } - function show_top() { - $cur = common_current_user(); - if ($cur && $cur->id == $this->profile->id) { - common_notice_form(); - } - } + if ($user->emailmicroid && $user->email && $this->notice->uri) { + $id = new Microid('mailto:'. $user->email, + $this->notice->uri); + $this->element('meta', array('name' => 'microid', + 'content' => $id->toString())); + } - function no_such_notice() { - common_user_error(_('No such notice.')); - } + if ($user->jabbermicroid && $user->jabber && $this->notice->uri) { + $id = new Microid('xmpp:', $user->jabber, + $this->notice->uri); + $this->element('meta', array('name' => 'microid', + 'content' => $id->toString())); + } + } } diff --git a/actions/showstream.php b/actions/showstream.php index 6d6225661..2fd56ad2e 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * User profile page + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,25 +18,67 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/stream.php'); +if (!defined('LACONICA')) { + exit(1); +} -define('SUBSCRIPTIONS_PER_ROW', 4); -define('SUBSCRIPTIONS', 80); +require_once INSTALLDIR.'/lib/personalgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; +require_once INSTALLDIR.'/lib/profileminilist.php'; +require_once INSTALLDIR.'/lib/groupminilist.php'; +require_once INSTALLDIR.'/lib/feedlist.php'; -class ShowstreamAction extends StreamAction { +/** + * User profile page + * + * When I created this page, "show stream" seemed like the best name for it. + * Now, it seems like a really bad name. + * + * It shows a stream of the user's posts, plus lots of profile info, links + * to subscriptions and stuff, etc. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - function handle($args) { +class ShowstreamAction extends Action +{ + var $user = null; + var $page = null; + var $profile = null; + + function title() + { + if ($this->page == 1) { + return $this->user->nickname; + } else { + return sprintf(_("%s, page %d"), + $this->user->nickname, + $this->page); + } + } - parent::handle($args); + function prepare($args) + { + parent::prepare($args); $nickname_arg = $this->arg('nickname'); - $nickname = common_canonical_nickname($nickname_arg); + $nickname = common_canonical_nickname($nickname_arg); - # Permanent redirect on non-canonical nickname + // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); @@ -41,410 +86,479 @@ class ShowstreamAction extends StreamAction { $args['page'] = $this->arg['page']; } common_redirect(common_local_url('showstream', $args), 301); - return; + return false; + } + + $this->user = User::staticGet('nickname', $nickname); + + if (!$this->user) { + $this->clientError(_('No such user.'), 404); + return false; + } + + $this->profile = $this->user->getProfile(); + + if (!$this->profile) { + $this->serverError(_('User has no profile.')); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + return true; + } + + function handle($args) + { + + // 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' => + $this->user->nickname))); + + $this->showPage(); + } + + function showContent() + { + $this->showProfile(); + $this->showNotices(); + } + + function showLocalNav() + { + $nav = new PersonalGroupNav($this); + $nav->show(); + } + + function showPageTitle() + { + $this->element('h1', NULL, $this->profile->nickname._("'s profile")); + } + + function showPageNoticeBlock() + { + return; + } + + function showExportData() + { + $fl = new FeedList($this); + $fl->show(array(0=>array('href'=>common_local_url('userrss', + array('nickname' => $this->user->nickname)), + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'notices'), + 1=>array('href'=>common_local_url('usertimeline', + array('nickname' => $this->user->nickname)), + 'type' => 'atom', + 'version' => 'Atom 1.0', + 'item' => 'usertimeline'), + 2=>array('href'=>common_local_url('foaf', + array('nickname' => $this->user->nickname)), + 'type' => 'rdf', + 'version' => 'FOAF', + 'item' => 'foaf'))); + } + + function showFeeds() + { + // Feeds + $this->element('link', array('rel' => 'alternate', + 'href' => common_local_url('api', + array('apiaction' => 'statuses', + 'method' => 'entity_timeline.rss', + 'argument' => $this->user->nickname)), + 'type' => 'application/rss+xml', + 'title' => sprintf(_('Notice feed for %s'), $this->user->nickname))); + $this->element('link', array('rel' => 'alternate feed', + 'href' => common_local_url('api', + array('apiaction' => 'statuses', + 'method' => 'entity_timeline.atom', + 'argument' => $this->user->nickname)), + 'type' => 'application/atom+xml', + 'title' => sprintf(_('Notice feed for %s'), $this->user->nickname))); + $this->element('link', array('rel' => 'alternate', + 'href' => common_local_url('userrss', array('nickname' => + $this->user->nickname)), + 'type' => 'application/rdf+xml', + 'title' => sprintf(_('Notice feed for %s'), $this->user->nickname))); + } + + function extraHead() + { + // FOAF + $this->element('link', array('rel' => 'meta', + 'href' => common_local_url('foaf', array('nickname' => + $this->user->nickname)), + 'type' => 'application/rdf+xml', + 'title' => 'FOAF')); + // for remote subscriptions etc. + $this->element('meta', array('http-equiv' => 'X-XRDS-Location', + 'content' => common_local_url('xrds', array('nickname' => + $this->user->nickname)))); + + if ($this->profile->bio) { + $this->element('meta', array('name' => 'description', + 'content' => $this->profile->bio)); + } + + if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) { + $id = new Microid('mailto:'.$this->user->email, + $this->selfUrl()); + $this->element('meta', array('name' => 'microid', + 'content' => $id->toString())); + } + if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) { + $id = new Microid('xmpp:'.$this->user->jabber, + $this->selfUrl()); + $this->element('meta', array('name' => 'microid', + 'content' => $id->toString())); + } + + // See https://wiki.mozilla.org/Microsummaries + + $this->element('link', array('rel' => 'microsummary', + 'href' => common_local_url('microsummary', + array('nickname' => $this->profile->nickname)))); + } + + function showProfile() + { + $this->elementStart('div', 'entity_profile vcard author'); + $this->element('h2', null, _('User profile')); + + $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); + $this->elementStart('dl', 'entity_depiction'); + $this->element('dt', null, _('Photo')); + $this->elementStart('dd'); + $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE), + 'class' => 'photo avatar', + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $this->profile->nickname)); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + $this->elementStart('dl', 'entity_nickname'); + $this->element('dt', null, _('Nickname')); + $this->elementStart('dd'); + $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid'; + $this->element('a', array('href' => $this->profile->profileurl, + 'rel' => 'me', 'class' => $hasFN), + $this->profile->nickname); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + if ($this->profile->fullname) { + $this->elementStart('dl', 'entity_fn'); + $this->element('dt', null, _('Full name')); + $this->elementStart('dd'); + $this->element('span', 'fn', $this->profile->fullname); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + if ($this->profile->location) { + $this->elementStart('dl', 'entity_location'); + $this->element('dt', null, _('Location')); + $this->element('dd', 'location', $this->profile->location); + $this->elementEnd('dl'); + } + + if ($this->profile->homepage) { + $this->elementStart('dl', 'entity_url'); + $this->element('dt', null, _('URL')); + $this->elementStart('dd'); + $this->element('a', array('href' => $this->profile->homepage, + 'rel' => 'me', 'class' => 'url'), + $this->profile->homepage); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + if ($this->profile->bio) { + $this->elementStart('dl', 'entity_note'); + $this->element('dt', null, _('Note')); + $this->element('dd', 'note', $this->profile->bio); + $this->elementEnd('dl'); } - $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); - } - common_element_end('li'); - - $user = User::staticGet('id', $profile->id); - common_profile_new_message_nudge($cur, $user, $profile); - - if ($cur && $cur->id != $profile->id) { - $blocked = $cur->hasBlocked($profile); - common_element_start('li', array('id' => 'profile_block')); + $tags = Profile_tag::getTags($this->profile->id, $this->profile->id); + if (count($tags) > 0) { + $this->elementStart('dl', 'entity_tags'); + $this->element('dt', null, _('Tags')); + $this->elementStart('dd'); + $this->elementStart('ul', 'tags xoxo'); + foreach ($tags as $tag) { + $this->elementStart('li'); + $this->element('span', 'mark_hash', '#'); + $this->element('a', array('rel' => 'tag', + 'href' => common_local_url('peopletag', + array('tag' => $tag))), + $tag); + $this->elementEnd('li'); + } + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + $this->elementEnd('div'); + + //XXX: entity_actions doesn't need to be outputted if entity is looking at their own profile + $this->elementStart('div', 'entity_actions'); + $this->element('h2', null, _('User actions')); + $this->elementStart('ul'); + $this->elementStart('li', array('id' => 'entity_subscribe')); + $cur = common_current_user(); + if ($cur) { + if ($cur->id != $this->profile->id) { + if ($cur->isSubscribed($this->profile)) { + $usf = new UnsubscribeForm($this, $this->profile); + $usf->show(); + } else { + $sf = new SubscribeForm($this, $this->profile); + $sf->show(); + } + } + } else { + $this->showRemoteSubscribeLink(); + } + $this->elementEnd('li'); + +// common_profile_new_message_nudge($cur, $this->user, $this->profile); + + $user = User::staticGet('id', $this->profile->id); + if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) { + $this->elementStart('li', array('id' => 'entity_send-a-message')); + $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)), + 'title' => _('Send a direct message to this user')), + _('Message')); + $this->elementEnd('li'); + + if ($user->email && $user->emailnotifynudge) { + $this->elementStart('li', array('id' => 'entity_nudge')); + $nf = new NudgeForm($this, $user); + $nf->show(); + $this->elementEnd('li'); + } + } + + if ($cur && $cur->id != $this->profile->id) { + $blocked = $cur->hasBlocked($this->profile); + $this->elementStart('li', array('id' => 'entity_block')); if ($blocked) { - common_unblock_form($profile, array('action' => 'showstream', - 'nickname' => $profile->nickname)); + $ubf = new UnblockForm($this, $this->profile); + $ubf->show(); } else { - common_block_form($profile, array('action' => 'showstream', - 'nickname' => $profile->nickname)); + $bf = new BlockForm($this, $this->profile); + $bf->show(); } - common_element_end('li'); + $this->elementEnd('li'); } + $this->elementEnd('ul'); + $this->elementEnd('div'); + } + + function showRemoteSubscribeLink() + { + $url = common_local_url('remotesubscribe', + array('nickname' => $this->profile->nickname)); + $this->element('a', array('href' => $url, + 'class' => 'entity_remote_subscribe'), + _('Subscribe')); + } - 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); + function showNotices() + { + $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + + $pnl = new ProfileNoticeList($notice, $this); $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'); - } - } + $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page, + 'showstream', array('nickname' => $this->user->nickname)); + } + + function showSections() + { + $this->showSubscriptions(); + $this->showSubscribers(); + $this->showGroups(); + $this->showStatistics(); + $cloud = new PersonalTagCloudSection($this, $this->user); + $cloud->show(); + } + + function showSubscriptions() + { + $profile = $this->user->getSubscriptions(0, PROFILES_PER_MINILIST + 1); + + $this->elementStart('div', array('id' => 'entity_subscriptions', + 'class' => 'section')); + + $this->element('h2', null, _('Subscriptions')); + + if ($profile) { + $pml = new ProfileMiniList($profile, $this->user, $this); + $cnt = $pml->show(); + if ($cnt == 0) { + $this->element('p', null, _('(None)')); + } + } + + if ($cnt > PROFILES_PER_MINILIST) { + $this->elementStart('p'); + $this->element('a', array('href' => common_local_url('subscriptions', + array('nickname' => $this->profile->nickname)), + 'class' => 'more'), + _('All subscriptions')); + $this->elementEnd('p'); + } + + $this->elementEnd('div'); + } + + function showSubscribers() + { + $profile = $this->user->getSubscribers(0, PROFILES_PER_MINILIST + 1); + + $this->elementStart('div', array('id' => 'entity_subscribers', + 'class' => 'section')); + + $this->element('h2', null, _('Subscribers')); + + if ($profile) { + $pml = new ProfileMiniList($profile, $this->user, $this); + $cnt = $pml->show(); + if ($cnt == 0) { + $this->element('p', null, _('(None)')); + } + } + + if ($cnt > PROFILES_PER_MINILIST) { + $this->elementStart('p'); + $this->element('a', array('href' => common_local_url('subscribers', + array('nickname' => $this->profile->nickname)), + 'class' => 'more'), + _('All subscribers')); + $this->elementEnd('p'); + } + + $this->elementEnd('div'); + } + + function showStatistics() + { + // XXX: WORM cache this + $subs = new Subscription(); + $subs->subscriber = $this->profile->id; + $subs_count = (int) $subs->count() - 1; + + $subbed = new Subscription(); + $subbed->subscribed = $this->profile->id; + $subbed_count = (int) $subbed->count() - 1; + + $notices = new Notice(); + $notices->profile_id = $this->profile->id; + $notice_count = (int) $notices->count(); + + $this->elementStart('div', array('id' => 'entity_statistics', + 'class' => 'section')); + + $this->element('h2', null, _('Statistics')); + + // Other stats...? + $this->elementStart('dl', 'entity_member-since'); + $this->element('dt', null, _('Member since')); + $this->element('dd', null, date('j M Y', + strtotime($this->profile->created))); + $this->elementEnd('dl'); + + $this->elementStart('dl', 'entity_subscriptions'); + $this->elementStart('dt'); + $this->element('a', array('href' => common_local_url('subscriptions', + array('nickname' => $this->profile->nickname))), + _('Subscriptions')); + $this->elementEnd('dt'); + $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0'); + $this->elementEnd('dl'); + + $this->elementStart('dl', 'entity_subscribers'); + $this->elementStart('dt'); + $this->element('a', array('href' => common_local_url('subscribers', + array('nickname' => $this->profile->nickname))), + _('Subscribers')); + $this->elementEnd('dt'); + $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0'); + $this->elementEnd('dl'); + + $this->elementStart('dl', 'entity_notices'); + $this->element('dt', null, _('Notices')); + $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0'); + $this->elementEnd('dl'); + + $this->elementEnd('div'); + } + + function showGroups() + { + $groups = $this->user->getGroups(0, GROUPS_PER_MINILIST + 1); + + $this->elementStart('div', array('id' => 'entity_groups', + 'class' => 'section')); + + $this->element('h2', null, _('Groups')); + + if ($groups) { + $gml = new GroupMiniList($groups, $this->user, $this); + $cnt = $gml->show(); + if ($cnt == 0) { + $this->element('p', null, _('(None)')); + } + } + + if ($cnt > GROUPS_PER_MINILIST) { + $this->elementStart('p'); + $this->element('a', array('href' => common_local_url('usergroups', + array('nickname' => $this->profile->nickname)), + 'class' => 'more'), + _('All groups')); + $this->elementEnd('p'); + } + + $this->elementEnd('div'); + } + + function showAnonymousMessage() + { + $m = sprintf(_('**%s** has an account on %%%%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 follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'), + $this->user->nickname, $this->user->nickname); + $this->elementStart('div', array('id' => 'anon_notice')); + $this->raw(common_markup_to_html($m)); + $this->elementEnd('div'); + } + } -# We don't show the author for a profile, since we already know who it is! +// We don't show the author for a profile, since we already know who it is! -class ProfileNoticeList extends NoticeList { - function new_list_item($notice) { - return new ProfileNoticeListItem($notice); +class ProfileNoticeList extends NoticeList +{ + function newListItem($notice) + { + return new ProfileNoticeListItem($notice, $this->out); } } -class ProfileNoticeListItem extends NoticeListItem { - function show_author() { +class ProfileNoticeListItem extends NoticeListItem +{ + function showAuthor() + { return; } } diff --git a/actions/smssettings.php b/actions/smssettings.php index 5db26730a..f89cbe1ab 100644 --- a/actions/smssettings.php +++ b/actions/smssettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Settings for SMS + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,317 +18,476 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/settingsaction.php'); -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; - } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/connectsettingsaction.php'; + +/** + * Settings for SMS + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see SettingsAction + */ + +class SmssettingsAction extends ConnectSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + return _('SMS Settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('You can receive SMS messages through email from %%site.name%%.'); + } + + /** + * Content area of the page + * + * Shows a form for adding and removing SMS phone numbers and setting + * SMS preferences. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_sms', + 'class' => 'form_settings', + 'action' => + common_local_url('smssettings'))); + + $this->elementStart('fieldset', array('id' => 'settings_sms_address')); + $this->element('legend', null, _('Address')); + $this->hidden('token', common_session_token()); + + if ($user->sms) { + $carrier = $user->getCarrier(); + $this->element('p', 'form_confirmed', + $user->sms . ' (' . $carrier->name . ')'); + $this->element('p', 'form_guide', + _('Current confirmed SMS-enabled phone number.')); + $this->hidden('sms', $user->sms); + $this->hidden('carrier', $user->carrier); + $this->submit('remove', _('Remove')); + } else { + $confirm = $this->getConfirmation(); + if ($confirm) { + $carrier = Sms_carrier::staticGet($confirm->address_extra); + $this->element('p', 'form_unconfirmed', + $confirm->address . ' (' . $carrier->name . ')'); + $this->element('p', 'form_guide', + _('Awaiting confirmation on this phone number.')); + $this->hidden('sms', $confirm->address); + $this->hidden('carrier', $confirm->address_extra); + $this->submit('cancel', _('Cancel')); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('code', _('Confirmation code'), null, + _('Enter the code you received on your phone.')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('confirm', _('Confirm')); + } else { + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('sms', _('SMS Phone number'), + ($this->arg('sms')) ? $this->arg('sms') : null, + _('Phone number, no punctuation or spaces, '. + 'with area code')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->carrierSelect(); + $this->submit('add', _('Add')); + } + } + $this->elementEnd('fieldset'); + + if ($user->sms) { + $this->elementStart('fieldset', array('id' => 'settings_sms_incoming_email')); + $this->element('legend', null, _('Incoming email')); + + if ($user->incomingemail) { + $this->element('p', 'form_unconfirmed', $user->incomingemail); + $this->element('p', 'form_note', + _('Send email to this address to post new notices.')); + $this->submit('removeincoming', _('Remove')); + } + + $this->element('p', 'form_guide', + _('Make a new email address for posting to; '. + 'cancels the old one.')); + $this->submit('newincoming', _('New')); + $this->elementEnd('fieldset'); + } + + $this->elementStart('fieldset', array('id' => 'settings_sms_preferences')); + $this->element('legend', null, _('Preferences')); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->checkbox('smsnotify', + _('Send me notices through SMS; '. + 'I understand I may incur '. + 'exorbitant charges from my carrier.'), + $user->smsnotify); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->submit('save', _('Save')); + + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + /** + * Get a pending confirmation, if any, for this user + * + * @return void + * + * @todo very similar to EmailsettingsAction::getConfirmation(); refactor? + */ + + function getConfirmation() + { + $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; + } + } + + /** + * Handle posts to this form + * + * Based on the button that was pressed, muxes out to other functions + * to do the actual task requested. + * + * All sub-functions reload the form with a message -- success or failure. + * + * @return void + */ + + function handlePost() + { + // CSRF protection + + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + if ($this->arg('save')) { + $this->savePreferences(); + } else if ($this->arg('add')) { + $this->addAddress(); + } else if ($this->arg('cancel')) { + $this->cancelConfirmation(); + } else if ($this->arg('remove')) { + $this->removeAddress(); + } else if ($this->arg('removeincoming')) { + $this->removeIncoming(); + } else if ($this->arg('newincoming')) { + $this->newIncoming(); + } else if ($this->arg('confirm')) { + $this->confirmCode(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Handle a request to save preferences + * + * Sets the user's SMS preferences in the DB. + * + * @return void + */ + + function savePreferences() + { + $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__); + $this->serverError(_('Couldn\'t update user.')); + return; + } + + $user->query('COMMIT'); + + $this->showForm(_('Preferences saved.'), true); + } + + /** + * Add a new SMS number for confirmation + * + * When the user requests a new SMS number, sends a confirmation + * message. + * + * @return void + */ + + function addAddress() + { + $user = common_current_user(); + + $sms = $this->trimmed('sms'); + $carrier_id = $this->trimmed('carrier'); + + // Some validation + + if (!$sms) { + $this->showForm(_('No phone number.')); + return; + } + + if (!$carrier_id) { + $this->showForm(_('No carrier selected.')); + return; + } + + $sms = common_canonical_sms($sms); + + if ($user->sms == $sms) { + $this->showForm(_('That is already your phone number.')); + return; + } else if ($this->smsExists($sms)) { + $this->showForm(_('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__); + $this->serverError(_('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 phone for the code and instructions '. + 'on how to use it.'); + + $this->showForm($msg, true); + } + + /** + * Cancel a pending confirmation + * + * Cancels the confirmation. + * + * @return void + */ + + function cancelConfirmation() + { + $sms = $this->trimmed('sms'); + $carrier = $this->trimmed('carrier'); + + $confirm = $this->getConfirmation(); + + if (!$confirm) { + $this->showForm(_('No pending confirmation to cancel.')); + return; + } + if ($confirm->address != $sms) { + $this->showForm(_('That is the wrong confirmation number.')); + return; + } $result = $confirm->delete(); if (!$result) { - common_log_db_error($confirm, 'DELETE', __FILE__); - $this->server_error(_('Couldn\'t delete email confirmation.')); + common_log_db_error($confirm, 'DELETE', __FILE__); + $this->serverError(_('Couldn\'t delete email confirmation.')); + return; + } + + $this->showForm(_('Confirmation cancelled.'), true); + } + + /** + * Remove a phone number from the user's account + * + * @return void + */ + + function removeAddress() + { + $user = common_current_user(); + + $sms = $this->arg('sms'); + $carrier = $this->arg('carrier'); + + // Maybe an old tab open...? + + if ($user->sms != $sms) { + $this->showForm(_('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__); + $this->serverError(_('Couldn\'t update user.')); + return; + } + $user->query('COMMIT'); + + $this->showForm(_('The address was removed.'), true); + } + + /** + * Does this sms number exist in our database? + * + * Also checks if it belongs to someone else + * + * @param string $sms phone number to check + * + * @return boolean does the number exist + */ + + function smsExists($sms) + { + $user = common_current_user(); + + $other = User::staticGet('sms', $sms); + + if (!$other) { + return false; + } else { + return $other->id != $user->id; + } + } + + /** + * Show a drop-down box with all the SMS carriers in the DB + * + * @return void + */ + + function carrierSelect() + { + $carrier = new Sms_carrier(); + + $cnt = $carrier->find(); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->element('label', array('for' => 'carrier'), _('Mobile carrier')); + $this->elementStart('select', array('name' => 'carrier', + 'id' => 'carrier')); + $this->element('option', array('value' => 0), + _('Select a carrier')); + while ($carrier->fetch()) { + $this->element('option', array('value' => $carrier->id), + $carrier->name); + } + $this->elementEnd('select'); + $this->element('p', 'form_guide', + 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'))); + $this->elementEnd('li'); + $this->elementEnd('ul'); + } + + /** + * Confirm an SMS confirmation code + * + * Redirects to the confirmaddress page for this code + * + * @return void + */ + + function confirmCode() + { + $code = $this->trimmed('code'); + + if (!$code) { + $this->showForm(_('No code entered')); 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))); - } + common_redirect(common_local_url('confirmaddress', + array('code' => $code))); + } } diff --git a/actions/subedit.php b/actions/subedit.php index e7505e3fe..89081ffc7 100644 --- a/actions/subedit.php +++ b/actions/subedit.php @@ -19,44 +19,46 @@ if (!defined('LACONICA')) { exit(1); } -class SubeditAction extends Action { - - var $profile = NULL; - - function prepare($args) { +class SubeditAction extends Action +{ + var $profile = null; + function prepare($args) + { parent::prepare($args); if (!common_logged_in()) { - $this->client_error(_('Not logged in.')); + $this->clientError(_('Not logged in.')); 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->clientError(_('There was a problem with your session token. '. + 'Try again, please.')); + return false; + } $id = $this->trimmed('profile'); if (!$id) { - $this->client_error(_('No profile specified.')); + $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { - $this->client_error(_('No profile with that ID.')); + $this->clientError(_('No profile with that ID.')); return false; } return true; } - function handle($args) { + function handle($args) + { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $cur = common_current_user(); @@ -65,7 +67,7 @@ class SubeditAction extends Action { 'subscribed' => $this->profile->id)); if (!$sub) { - $this->client_error(_('You are not subscribed to that profile.')); + $this->clientError(_('You are not subscribed to that profile.')); return false; } @@ -78,7 +80,7 @@ class SubeditAction extends Action { if (!$result) { common_log_db_error($sub, 'UPDATE', __FILE__); - $this->server_error(_('Could not save subscription.')); + $this->serverError(_('Could not save subscription.')); return false; } diff --git a/actions/subscribe.php b/actions/subscribe.php index 64abda004..171332734 100644 --- a/actions/subscribe.php +++ b/actions/subscribe.php @@ -19,60 +19,63 @@ if (!defined('LACONICA')) { exit(1); } -class SubscribeAction extends Action { +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()) { + $this->clientError(_('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->clientError(_('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->clientError(_('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) { + $this->clientError($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')) { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Subscribed')); + $this->elementEnd('head'); + $this->elementStart('body'); + $unsubscribe = new UnsubscribeForm($this, $other->getProfile()); + $unsubscribe->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('subscriptions', array('nickname' => + $user->nickname))); } - } + } } diff --git a/actions/subscribers.php b/actions/subscribers.php index ae52526e1..be9df2b12 100644 --- a/actions/subscribers.php +++ b/actions/subscribers.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * List a user's subscribers + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,47 +18,89 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Social + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/gallery.php'); +/** + * List a user's subscribers + * + * @category Social + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ -class SubscribersAction extends GalleryAction { +class SubscribersAction extends GalleryAction +{ + function title() + { + if ($this->page == 1) { + return sprintf(_('%s subscribers'), $this->user->nickname); + } else { + return sprintf(_('%s subscribers, page %d'), + $this->user->nickname, + $this->page); + } + } - function gallery_type() { - return _('Subscribers'); - } + function showPageNotice() + { + $user =& common_current_user(); + if ($user && ($user->id == $this->profile->id)) { + $this->element('p', null, + _('These are the people who listen to '. + 'your notices.')); + } else { + $this->element('p', null, + sprintf(_('These are the people who '. + 'listen to %s\'s notices.'), + $this->profile->nickname)); + } + } - 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 showContent() + { + $offset = ($this->page-1) * PROFILES_PER_PAGE; + $limit = PROFILES_PER_PAGE + 1; - function fields() { - return array('subscriber', 'subscribed'); - } + if ($this->tag) { + $subscribers = $this->user->getTaggedSubscribers($this->tag, $offset, $limit); + } else { + $subscribers = $this->user->getSubscribers($offset, $limit); + } - function div_class() { - return 'subscribers'; - } + if ($subscribers) { + $subscribers_list = new SubscribersList($subscribers, $this->user, $this); + $subscribers_list->show(); + } - function get_other(&$subs) { - return $subs->subscriber; - } + $subscribers->free(); - function profile_list_class() { - return 'SubscribersList'; + $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, + $this->page, 'subscribers', + array('nickname' => $this->user->nickname)); } } -class SubscribersList extends ProfileList { - function show_owner_controls($profile) { - common_block_form($profile, array('action' => 'subscribers', - 'nickname' => $this->owner->nickname)); +class SubscribersList extends ProfileList +{ + function showOwnerControls($profile) + { + $bf = new BlockForm($this->out, $profile, + array('action' => 'subscribers', + 'nickname' => $this->owner->nickname)); + $bf->show(); } } diff --git a/actions/subscriptions.php b/actions/subscriptions.php index f518a1f92..d7ba0d624 100644 --- a/actions/subscriptions.php +++ b/actions/subscriptions.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * List of a user's subscriptions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,64 +18,111 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Social + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * A list of the user's subscriptions + * + * @category Social + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/lib/gallery.php'); +class SubscriptionsAction extends GalleryAction +{ + function title() + { + if ($this->page == 1) { + return sprintf(_('%s subscriptions'), $this->user->nickname); + } else { + return sprintf(_('%s subscriptions, page %d'), + $this->user->nickname, + $this->page); + } + } + + function showPageNotice() + { + $user =& common_current_user(); + if ($user && ($user->id == $this->profile->id)) { + $this->element('p', null, + _('These are the people whose notices '. + 'you listen to.')); + } else { + $this->element('p', null, + sprintf(_('These are the people whose '. + 'notices %s listens to.'), + $this->profile->nickname)); + } + } -class SubscriptionsAction extends GalleryAction { + function getAllTags() + { + return $this->getTags('subscribed', 'subscriber'); + } - function gallery_type() { - return _('Subscriptions'); - } + function showContent() + { + parent::showContent(); - 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); - } - } + $offset = ($this->page-1) * PROFILES_PER_PAGE; + $limit = PROFILES_PER_PAGE + 1; - function fields() { - return array('subscribed', 'subscriber'); - } + if ($this->tag) { + $subscriptions = $this->user->getTaggedSubscriptions($this->tag, $offset, $limit); + } else { + $subscriptions = $this->user->getSubscriptions($offset, $limit); + } - function div_class() { - return 'subscriptions'; - } + if ($subscriptions) { + $subscriptions_list = new SubscriptionsList($subscriptions, $this->user, $this); + $subscriptions_list->show(); + } - function get_other(&$subs) { - return $subs->subscribed; - } + $subscriptions->free(); - function profile_list_class() { - return 'SubscriptionsList'; + $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE, + $this->page, 'subscriptions', + array('nickname' => $this->user->nickname)); } } -class SubscriptionsList extends ProfileList { - - function show_owner_controls($profile) { - - $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id, - 'subscribed' => $profile->id)); +class SubscriptionsList extends ProfileList +{ + function showOwnerControls($profile) + { + $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id, + 'subscribed' => $profile->id)); if (!$sub) { return; } - common_element_start('form', array('id' => 'subedit-' . $profile->id, - 'method' => 'post', - 'class' => 'subedit', - 'action' => common_local_url('subedit'))); - common_hidden('token', common_session_token()); - common_hidden('profile', $profile->id); - common_checkbox('jabber', _('Jabber'), $sub->jabber); - common_checkbox('sms', _('SMS'), $sub->sms); - common_submit('save', _('Save')); - common_element_end('form'); + $this->out->elementStart('form', array('id' => 'subedit-' . $profile->id, + 'method' => 'post', + 'class' => 'form_subcription_edit', + 'action' => common_local_url('subedit'))); + $this->out->hidden('token', common_session_token()); + $this->out->hidden('profile', $profile->id); + $this->out->checkbox('jabber', _('Jabber'), $sub->jabber); + $this->out->checkbox('sms', _('SMS'), $sub->sms); + $this->out->submit('save', _('Save')); + $this->out->elementEnd('form'); return; } } diff --git a/actions/sup.php b/actions/sup.php index 887017b2a..f4b1cda23 100644 --- a/actions/sup.php +++ b/actions/sup.php @@ -19,63 +19,66 @@ if (!defined('LACONICA')) { exit(1); } -class SupAction extends Action { - - 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(); - - # 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; - } +class SupAction extends Action +{ + function handle($args) + { + parent::handle($args); + + $seconds = $this->trimmed('seconds'); + + if (!$seconds) { + $seconds = 15; + } + + $updates = $this->getUpdates($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->availablePeriods(), + 'period' => $seconds, + 'updates' => $updates)); + } + + function availablePeriods() + { + 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 getUpdates($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. + + $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 isReadOnly() + { + return true; + } } diff --git a/actions/tag.php b/actions/tag.php index ffb393ae8..039cd9660 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -19,147 +19,71 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/actions/showstream.php'); -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', array('tag' => $tag)), - '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)); - } +class TagAction extends Action +{ + function prepare($args) + { + parent::prepare($args); + $this->tag = $this->trimmed('tag'); + + if (!$this->tag) { + common_redirect(common_local_url('publictagcloud'), 301); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + return true; + } + + function title() + { + if ($this->page == 1) { + return sprintf(_("Notices tagged with %s"), $this->tag); + } else { + return sprintf(_("Notices tagged with %s, page %d"), + $this->tag, + $this->page); + } + } + + function handle($args) + { + parent::handle($args); + + $this->showPage(); + } + + function showFeeds() + { + $this->element('link', array('rel' => 'alternate', + 'href' => common_local_url('tagrss', array('tag' => $this->tag)), + 'type' => 'application/rss+xml', + 'title' => sprintf(_('Feed for tag %s'), $this->tag))); + } + + function showPageNotice() + { + return sprintf(_('Messages tagged "%s", most recent first'), $this->tag); + } + + function showExportData() + { + $fl = new FeedList($this); + $fl->show(array(0=>array('href'=>common_local_url('tagrss', array('tag' => $this->tag)), + 'type' => 'rss', + 'version' => 'RSS 1.0', + 'item' => 'tagrss'))); + } + + function showContent() + { + $notice = Notice_tag::getStream($this->tag, (($this->page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'tag', array('tag' => $this->tag)); + } } diff --git a/actions/tagother.php b/actions/tagother.php index a4449dd69..9a63fc438 100644 --- a/actions/tagother.php +++ b/actions/tagother.php @@ -21,173 +21,218 @@ if (!defined('LACONICA')) { exit(1); } 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))); +class TagotherAction extends Action +{ + var $profile = null; + var $error = null; + + function prepare($args) + { + parent::prepare($args); + if (!common_logged_in()) { + $this->clientError(_('Not logged in'), 403); + return false; } - } - - 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'); - } - } + + $id = $this->trimmed('id'); + if (!$id) { + $this->clientError(_('No id argument.')); + return false; + } + + $this->profile = Profile::staticGet('id', $id); + + if (!$this->profile) { + $this->clientError(_('No profile with that ID.')); + return false; + } + + return true; + } + + function handle($args) + { + parent::handle($args); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->saveTags(); + } else { + $this->showForm($profile); + } + } + + function title() + { + return sprintf(_('Tag %s'), $this->profile->nickname); + } + + function showForm($error=null) + { + $this->error = $error; + $this->showPage(); + } + + function showContent() + { + $this->elementStart('div', 'entity_profile vcard author'); + $this->element('h2', null, _('User profile')); + + $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); + $this->elementStart('dl', 'entity_depiction'); + $this->element('dt', null, _('Photo')); + $this->elementStart('dd'); + $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE), + 'class' => 'photo avatar', + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => + ($this->profile->fullname) ? $this->profile->fullname : + $this->profile->nickname)); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + + $this->elementStart('dl', 'entity_nickname'); + $this->element('dt', null, _('Nickname')); + $this->elementStart('dd'); + $this->element('a', array('href' => $this->profile->profileurl, + 'class' => 'nickname'), + $this->profile->nickname); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + if ($this->profile->fullname) { + $this->elementStart('dl', 'entity_fn'); + $this->element('dt', null, _('Full name')); + $this->elementStart('dd'); + $this->element('span', 'fn', $this->profile->fullname); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + if ($this->profile->location) { + $this->elementStart('dl', 'entity_location'); + $this->element('dt', null, _('Location')); + $this->element('dd', 'location', $this->profile->location); + $this->elementEnd('dl'); + } + if ($this->profile->homepage) { + $this->elementStart('dl', 'entity_url'); + $this->element('dt', null, _('URL')); + $this->elementStart('dd'); + $this->element('a', array('href' => $this->profile->homepage, + 'rel' => 'me', 'class' => 'url'), + $this->profile->homepage); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + if ($this->profile->bio) { + $this->elementStart('dl', 'entity_note'); + $this->element('dt', null, _('Note')); + $this->element('dd', 'note', $this->profile->bio); + $this->elementEnd('dl'); + } + $this->elementEnd('div'); + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_tag_user', + 'class' => 'form_settings', + 'name' => 'tagother', + 'action' => $this->selfUrl())); + $this->elementStart('fieldset'); + $this->element('legend', null, _('Tag user')); + $this->hidden('token', common_session_token()); + $this->hidden('id', $this->profile->id); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->input('tags', _('Tags'), + ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)), + _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->submit('save', _('Save')); + $this->elementEnd('fieldset'); + $this->elementEnd('form'); + } + + function saveTags() + { + $id = $this->trimmed('id'); + $tagstring = $this->trimmed('tags'); + $token = $this->trimmed('token'); + + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token.'. + ' Try again, please.')); + 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->showForm(sprintf(_('Invalid tag: "%s"'), $tag)); + return; + } + } + } else { + $tags = array(); + } + + $user = common_current_user(); + + if (!Subscription::pkeyGet(array('subscriber' => $user->id, + 'subscribed' => $this->profile->id)) && + !Subscription::pkeyGet(array('subscriber' => $this->profile->id, + 'subscribed' => $user->id))) + { + $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.')); + return; + } + + $result = Profile_tag::setTags($user->id, $this->profile->id, $tags); + + if (!$result) { + $this->clientError(_('Could not save tags.')); + return; + } + + $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers'; + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml'); + $this->elementStart('head'); + $this->element('title', null, _('Tags')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->elementStart('p', 'subtags'); + foreach ($tags as $tag) { + $this->element('a', array('href' => common_local_url($action, + array('nickname' => $user->nickname, + 'tag' => $tag))), + $tag); + } + $this->elementEnd('p'); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url($action, array('nickname' => + $user->nickname))); + } + } + + function showPageNotice() + { + if ($this->error) { + $this->element('p', 'error', $this->error); + } else { + $this->elementStart('div', 'instructions'); + $this->element('p', null, + _('Use this form to add tags to your subscribers or subscriptions.')); + $this->elementEnd('div'); + } + } } diff --git a/actions/tagrss.php b/actions/tagrss.php index 737ac113d..b0227ab39 100644 --- a/actions/tagrss.php +++ b/actions/tagrss.php @@ -23,39 +23,47 @@ require_once(INSTALLDIR.'/lib/rssaction.php'); // Formatting of RSS handled by Rss10Action -class TagrssAction extends Rss10Action { +class TagrssAction extends Rss10Action +{ - function init() { - $tag = $this->trimmed('tag'); + function init() + { + $tag = $this->trimmed('tag'); + $this->tag = Notice_tag::staticGet('tag', $tag); - if (!isset($tag) || mb_strlen($tag) == 0) { - common_user_error(_('No tag.')); - return false; + if (!$this->tag) { + $this->clientError(_('No such tag.')); + return false; + } else { + return true; } + } - $this->tag = $tag; - return true; - } + function get_notices($limit=0) + { + $tag = $this->tag; - function get_notices($limit=0) { - $tag = $this->tag; + if (is_null($tag)) { + return null; + } - $notice = Notice_tag::getStream($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; + function get_channel() + { + $tag = $this->tag->tag; - $c = array('url' => common_local_url('tagrss', array('tag' => $tag)), - 'title' => $tag, - 'link' => common_local_url('tagrss', array('tag' => $tag)), - 'description' => sprintf(_('Microblog tagged with %s'), $tag)); - 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/actions/twitapiaccount.php b/actions/twitapiaccount.php index c1960561e..dc8e2e798 100644 --- a/actions/twitapiaccount.php +++ b/actions/twitapiaccount.php @@ -21,9 +21,11 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/twitterapi.php'); -class TwitapiaccountAction extends TwitterapiAction { +class TwitapiaccountAction extends TwitterapiAction +{ - function verify_credentials($args, $apidata) { + function verify_credentials($args, $apidata) + { if ($apidata['content-type'] == 'xml') { header('Content-Type: application/xml; charset=utf-8'); @@ -37,63 +39,67 @@ class TwitapiaccountAction extends TwitterapiAction { } - 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); + $this->serverError(_('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->clientError(_('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->clientError(_('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) { + $this->serverError(_('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__); + $this->serverError(_('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); + $this->serverError(_('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 + function rate_limit_status($args, $apidata) + { + parent::handle($args); + $this->serverError(_('API method under construction.'), $code=501); + } +} diff --git a/actions/twitapiblocks.php b/actions/twitapiblocks.php index 4852ff938..8135adef3 100644 --- a/actions/twitapiblocks.php +++ b/actions/twitapiblocks.php @@ -21,17 +21,19 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/twitterapi.php'); -class TwitapiblocksAction extends TwitterapiAction { +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->clientError('Not Found', 404, $apidata['content-type']); + return; } $user = $apidata['user']; @@ -42,17 +44,18 @@ class TwitapiblocksAction extends TwitterapiAction { $this->show_profile($blockee, $type); $this->end_document($type); } else { - common_server_error(_('Block user failed.')); + $this->serverError(_('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->clientError('Not Found', 404, $apidata['content-type']); + return; } $user = $apidata['user']; @@ -63,7 +66,7 @@ class TwitapiblocksAction extends TwitterapiAction { $this->show_profile($blockee, $type); $this->end_document($type); } else { - common_server_error(_('Unblock user failed.')); + $this->serverError(_('Unblock user failed.')); } - } + } }
\ No newline at end of file diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php index 535795ca4..db55e8cd0 100644 --- a/actions/twitapidirect_messages.php +++ b/actions/twitapidirect_messages.php @@ -21,267 +21,278 @@ if (!defined('LACONICA')) { exit(1); } 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. +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: + $this->clientError(_('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->clientError(_('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->clientError(_('No message text!'), $code = 406, $apidata['content-type']); + } else { + $content_shortened = common_shorten_links($content); + if (mb_strlen($content_shortened) > 140) { + $this->clientError(_('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->clientError(_('Recipient user not found.'), $code = 403, $apidata['content-type']); + return; + } else if (!$user->mutuallySubscribed($other)) { + $this->clientError(_('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->clientError(_('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->serverError($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); + $this->serverError(_('API method under construction.'), $code=501); + } + + function show_xml_dmsgs($message) + { + + $this->init_document('xml'); + $this->elementStart('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); + } + } + + $this->elementEnd('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'); + + $this->elementStart('channel'); + $this->element('title', null, $title); + + $this->element('link', null, $link); + $this->element('description', null, $subtitle); + $this->element('language', null, 'en-us'); + $this->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); + } + } + + $this->elementEnd('channel'); + $this->end_twitter_rss(); + + } + + function show_atom_dmsgs($message, $title, $link, $subtitle) + { + + $this->init_document('atom'); + + $this->element('title', null, $title); + $siteserver = common_config('site', 'server'); + $this->element('id', null, "tag:$siteserver,2008:DirectMessage"); + $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); + $this->element('updated', null, common_date_iso8601(strftime('%c'))); + $this->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/actions/twitapifavorites.php b/actions/twitapifavorites.php index 3eaff327a..737b7229f 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.php @@ -21,155 +21,161 @@ if (!defined('LACONICA')) { exit(1); } 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); - } +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->clientError('Not Found', 404, $apidata['content-type']); + return; + } + + $profile = $user->getProfile(); + + if (!$profile) { + $this->serverError(_('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) { + $this->serverError(_('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: + $this->clientError(_('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->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); + return; + } + + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + $this->clientError(_('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->clientError(_('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->clientError(_('This notice is already a favorite!'), 403, $apidata['content-type']); + return; + } + + $fave = Fave::addNew($user, $notice); + + if (!$fave) { + $this->serverError(_('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); + $this->serverError(_('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/actions/twitapifriendships.php b/actions/twitapifriendships.php index e4b49cbe4..c50c5e84a 100644 --- a/actions/twitapifriendships.php +++ b/actions/twitapifriendships.php @@ -21,135 +21,139 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/twitterapi.php'); -class TwitapifriendshipsAction extends TwitterapiAction { +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->clientError(_('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->clientError(_('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->clientError($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->clientError($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->clientError(_('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->clientError(_('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'))) { + $this->clientError(_('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->clientError(_('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'; - } - - 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; - } - - } + if ($user_a->isSubscribed($user_b)) { + $result = 'true'; + } else { + $result = 'false'; + } + + switch ($apidata['content-type']) { + case 'xml': + $this->init_document('xml'); + $this->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/actions/twitapihelp.php b/actions/twitapihelp.php index c5d503e11..db5892baf 100644 --- a/actions/twitapihelp.php +++ b/actions/twitapihelp.php @@ -21,32 +21,35 @@ if (!defined('LACONICA')) { exit(1); } 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); - } +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'); + $this->element('ok', null, 'true'); + $this->end_document('xml'); + } elseif ($apidata['content-type'] == 'json') { + $this->init_document('json'); + print '"ok"'; + $this->end_document('json'); + } else { + $this->clientError(_('API method not found!'), $code=404); + } + + } + + function downtime_schedule($args, $apidata) + { + parent::handle($args); + $this->serverError(_('API method under construction.'), $code=501); + } }
\ No newline at end of file diff --git a/actions/twitapilaconica.php b/actions/twitapilaconica.php new file mode 100644 index 000000000..8cd7a64b9 --- /dev/null +++ b/actions/twitapilaconica.php @@ -0,0 +1,174 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Laconica-only extensions to the Twitter-like API + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Twitter + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/twitterapi.php'; + +/** + * Laconica-specific API methods + * + * This class handles all /laconica/ API methods. + * + * @category Twitter + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class TwitapilaconicaAction extends TwitterapiAction +{ + /** + * A version stamp for the API + * + * Returns a version number for this version of Laconica, which + * should make things a bit easier for upgrades. + * URL: http://identi.ca/api/laconica/version.(xml|json) + * Formats: xml, json + * + * @param array $args Web arguments + * @param array $apidata Twitter API data + * + * @return void + * + * @see ApiAction::process_command() + */ + + function version($args, $apidata) + { + parent::handle($args); + switch ($apidata['content-type']) { + case 'xml': + $this->init_document('xml'); + $this->element('version', null, LACONICA_VERSION); + $this->end_document('xml'); + break; + case 'json': + $this->init_document('json'); + print '"'.LACONICA_VERSION.'"'; + $this->end_document('json'); + break; + default: + $this->clientError(_('API method not found!'), $code=404); + } + } + + /** + * Dump of configuration variables + * + * Gives a full dump of configuration variables for this instance + * of Laconica, minus variables that may be security-sensitive (like + * passwords). + * URL: http://identi.ca/api/laconica/config.(xml|json) + * Formats: xml, json + * + * @param array $args Web arguments + * @param array $apidata Twitter API data + * + * @return void + * + * @see ApiAction::process_command() + */ + + function config($args, $apidata) + { + static $keys = array('site' => array('name', 'server', 'theme', 'path', 'fancy', 'language', + 'email', 'broughtby', 'broughtbyurl', 'closed', + 'inviteonly', 'private'), + 'license' => array('url', 'title', 'image'), + 'nickname' => array('featured'), + 'throttle' => array('enabled', 'count', 'timespan'), + 'xmpp' => array('enabled', 'server', 'user')); + + parent::handle($args); + + switch ($apidata['content-type']) { + case 'xml': + $this->init_document('xml'); + $this->elementStart('config'); + // XXX: check that all sections and settings are legal XML elements + foreach ($keys as $section => $settings) { + $this->elementStart($section); + foreach ($settings as $setting) { + $value = common_config($section, $setting); + if (is_array($value)) { + $value = implode(',', $value); + } else if ($value === false) { + $value = 'false'; + } else if ($value === true) { + $value = 'true'; + } + $this->element($setting, null, $value); + } + $this->elementEnd($section); + } + $this->elementEnd('config'); + $this->end_document('xml'); + break; + case 'json': + $result = array(); + foreach ($keys as $section => $settings) { + $result[$section] = array(); + foreach ($settings as $setting) { + $result[$section][$setting] = common_config($section, $setting); + } + } + $this->init_document('json'); + $this->show_json_objects($result); + $this->end_document('json'); + break; + default: + $this->clientError(_('API method not found!'), $code=404); + } + } + + /** + * WADL description of the API + * + * Gives a WADL description of the API provided by this version of the + * software. + * + * @param array $args Web arguments + * @param array $apidata Twitter API data + * + * @return void + * + * @see ApiAction::process_command() + */ + + function wadl($args, $apidata) + { + parent::handle($args); + $this->serverError(_('API method under construction.'), 501); + } +} diff --git a/actions/twitapinotifications.php b/actions/twitapinotifications.php index 8d93309a2..411971af1 100644 --- a/actions/twitapinotifications.php +++ b/actions/twitapinotifications.php @@ -22,16 +22,19 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/twitterapi.php'); # This naming convention looks real sick -class TwitapinotificationsAction extends TwitterapiAction { +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); + $this->serverError(_('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); + $this->serverError(_('API method under construction.'), $code=501); + } }
\ No newline at end of file diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 7b6598b10..a35f4b12e 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -21,543 +21,557 @@ if (!defined('LACONICA')) { exit(1); } 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')); +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: + $this->clientError(_('API method not found!'), $code = 404); + break; + } + + } else { + $this->serverError(_('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: + $this->clientError(_('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->clientError('Not Found', 404, $apidata['content-type']); + return; + } + + $profile = $user->getProfile(); + + if (!$profile) { + $this->serverError(_('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: + $this->clientError(_('API method not found!'), $code = 404); + } + + } + + function update($args, $apidata) + { + + parent::handle($args); + + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + $this->clientError(_('API method not found!'), $code = 404); + return; + } + + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + $this->clientError(_('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->clientError(_('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_array(get_class($cmd), $cmdlist)) { - return true; - } - - return false; - } + 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->clientError(_('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->serverError($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: + $this->clientError(_('API method not found!'), $code = 404); + } + + } + + function show($args, $apidata) + { + parent::handle($args); + + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + $this->clientError(_('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->clientError(_('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'))) { + $this->clientError(_('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->clientError(_('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->clientError(_('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->clientError(_('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->clientError('Not Found', 404, $apidata['content-type']); + return; + } + + $page = $this->trimmed('page'); + + if (!$page || !is_numeric($page)) { + $page = 1; + } + + $profile = $user->getProfile(); + + if (!$profile) { + $this->serverError(_('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': + $this->elementStart('users', array('type' => 'array')); + foreach ($profiles as $profile) { + $this->show_profile($profile); + } + $this->elementEnd('users'); + break; + case 'json': + $arrays = array(); + foreach ($profiles as $profile) { + $arrays[] = $this->twitter_user_array($profile, true); + } + print json_encode($arrays); + break; + default: + $this->clientError(_('unsupported file type')); + } + } + + function featured($args, $apidata) + { + parent::handle($args); + $this->serverError(_('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; + } + + return false; + } } diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 337ec91d1..8f16e5613 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -10,28 +10,30 @@ * * 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); } require_once(INSTALLDIR.'/lib/twitterapi.php'); -class TwitapiusersAction extends TwitterapiAction { +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'))) { + $this->clientError(_('API method not found!'), $code = 404); + return; + } - $this->auth_user = $apidata['user']; + $this->auth_user = $apidata['user']; $user = null; $email = $this->arg('email'); diff --git a/actions/twittersettings.php b/actions/twittersettings.php index ae3aff877..efc8215cd 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Settings for Twitter integration + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,364 +18,481 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/settingsaction.php'); +require_once INSTALLDIR.'/lib/connectsettingsaction.php'; 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 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(); - } - - $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')); - - 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_password('twitter_password', _('Twitter password')); - } - - common_element('h2', NULL, _('Preferences')); - - 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('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')); - } - - $this->show_twitter_subscriptions(); - - common_element_end('form'); - - common_show_footer(); - } - - function subscribed_twitter_users() { - - $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'; - - $user = new User(); - - $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'); - - } - - common_element_end('ul'); - common_element_end('div'); - - } - - // XXX Figure out a way to show all Twitter friends... ? - - /* - 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'); - } - */ - - } - - 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.')); - } - } +/** + * Settings for Twitter integration + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see SettingsAction + */ - function add_twitter_acct() { +class TwittersettingsAction extends ConnectSettingsAction +{ + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + _('Twitter settings'); + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('Add your Twitter account to automatically send '. + ' your notices to Twitter, ' . + 'and subscribe to Twitter friends already here.'); + } + + /** + * Content area of the page + * + * Shows a form for associating a Twitter account with this + * Laconica account. Also lets the user set preferences. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + + $profile = $user->getProfile(); + + $fuser = null; + + $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter + + if ($flink) { + $fuser = $flink->getForeignUser(); + } + + $this->elementStart('form', array('method' => 'post', + 'id' => 'form_settings_twitter', + 'class' => 'form_settings', + 'action' => + common_local_url('twittersettings'))); + $this->elementStart('fieldset', array('id' => 'settings_twitter_account')); + $this->element('legend', null, _('Twitter Account')); + $this->hidden('token', common_session_token()); + $this->elementStart('ul', 'form_data'); + if ($fuser) { + $this->elementStart('li'); + $this->element('span', 'twitter_user', $fuser->nickname); + $this->element('a', array('href' => $fuser->uri), $fuser->uri); + $this->element('p', 'form_guide', + _('Current verified Twitter account.')); + $this->hidden('flink_foreign_id', $flink->foreign_id); + $this->submit('remove', _('Remove')); + $this->elementEnd('li'); + } else { + $this->elementStart('li'); + $this->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 + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('twitter_password', _('Twitter password')); + $this->elementend('li'); + } + $this->elementEnd('ul'); + $this->elementEnd('fieldset'); + + $this->elementStart('fieldset', + array('id' => 'settings_twitter_preferences')); + $this->element('legend', null, _('Preferences')); + + $this->elementStart('ul', 'form_data'); + $this->elementStart('li'); + $this->checkbox('noticesync', + _('Automatically send my notices to Twitter.'), + ($flink) ? + ($flink->noticesync & FOREIGN_NOTICE_SEND) : + true); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('replysync', + _('Send local "@" replies to Twitter.'), + ($flink) ? + ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : + true); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->checkbox('friendsync', + _('Subscribe to my Twitter friends here.'), + ($flink) ? + ($flink->friendsync & FOREIGN_FRIEND_RECV) : + false); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + if ($flink) { + $this->submit('save', _('Save')); + } else { + $this->submit('add', _('Add')); + } + $this->elementEnd('fieldset'); + + $this->showTwitterSubscriptions(); + + $this->elementEnd('form'); + } + + /** + * Gets some of the user's Twitter friends + * + * Gets the number of Twitter friends that are on this + * instance of Laconica. + * + * @return array array of User objects + */ + + function subscribedTwitterUsers() + { + + $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'; + + $user = new User(); + + $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; + } + + /** + * Show user's Twitter friends + * + * Gets the number of Twitter friends that are on this + * instance of Laconica, and shows their mini-avatars. + * + * @return void + */ + + function showTwitterSubscriptions() + { + + $friends = $this->subscribedTwitterUsers(); + + $friends_count = count($friends); + + if ($friends_count > 0) { + + $this->element('h3', null, _('Twitter Friends')); + $this->elementStart('div', array('id' => 'subscriptions')); + $this->elementStart('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; + } + + $this->elementStart('li'); + $this->elementStart('a', array('title' => ($other->fullname) ? + $other->fullname : + $other->nickname, + 'href' => $other->profileurl, + 'rel' => 'contact', + 'class' => 'subscription')); + + $avatar = $other->getAvatar(AVATAR_MINI_SIZE); + + $avatar_url = ($avatar) ? + common_avatar_display_url($avatar) : + common_default_avatar(AVATAR_MINI_SIZE); + + $this->element('img', array('src' => $avatar_url, + 'width' => AVATAR_MINI_SIZE, + 'height' => AVATAR_MINI_SIZE, + 'class' => 'avatar mini', + 'alt' => ($other->fullname) ? + $other->fullname : + $other->nickname)); + $this->elementEnd('a'); + $this->elementEnd('li'); + + } + + $this->elementEnd('ul'); + $this->elementEnd('div'); + + } + } + + /** + * Handle posts to this form + * + * Based on the button that was pressed, muxes out to other functions + * to do the actual task requested. + * + * All sub-functions reload the form with a message -- success or failure. + * + * @return void + */ + + function handlePost() + { + + // CSRF protection + $token = $this->trimmed('token'); + if (!$token || $token != common_session_token()) { + $this->showForm(_('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + + if ($this->arg('save')) { + $this->savePreferences(); + } else if ($this->arg('add')) { + $this->addTwitterAccount(); + } else if ($this->arg('remove')) { + $this->removeTwitterAccount(); + } else { + $this->showForm(_('Unexpected form submission.')); + } + } + + /** + * Associate a Twitter account with the user's account + * + * Validates post input; verifies it against Twitter; and if + * successful stores in the database. + * + * @return void + */ + + function addTwitterAccount() + { + $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->showForm(_('Username must have only numbers, '. + 'upper- and lowercase letters, '. + 'and underscore (_). 15 chars max.')); + return; + } + + if (!$this->verifyCredentials($screen_name, $password)) { + $this->showForm(_('Could not verify your Twitter credentials!')); + return; + } + + $twit_user = twitter_user_info($screen_name, $password); + + if (!$twit_user) { + $this->showForm(sprintf(_('Unable to retrieve account information '. + 'For "%s" from Twitter.'), + $screen_name)); + return; + } + + if (!save_twitter_user($twit_user->id, $screen_name)) { + $this->showForm(_('Unable to save your Twitter settings!')); + return; + } + + $user = common_current_user(); + + $flink = new 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(); + + $flink->set_flags($noticesync, $replysync, $friendsync); + + $flink_id = $flink->insert(); + + if (!$flink_id) { + common_log_db_error($flink, 'INSERT', __FILE__); + $this->showForm(_('Unable to save your Twitter settings!')); + return; + } + + if ($friendsync) { + save_twitter_friends($user, $twit_user->id, $screen_name, $password); + } + + $this->showForm(_('Twitter settings saved.'), true); + } + + /** + * Disassociate an existing Twitter account from this account + * + * @return void + */ + + function removeTwitterAccount() + { + $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->showForm(_('That is not your Twitter account.')); + return; + } + + $result = $flink->delete(); + + if (!$result) { + common_log_db_error($flink, 'DELETE', __FILE__); + $this->serverError(_('Couldn\'t remove Twitter user.')); + return; + } + + $this->showForm(_('Twitter account removed.'), true); + } - $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; - } + /** + * Save user's Twitter-bridging preferences + * + * @return void + */ - if ($friendsync) { - save_twitter_friends($user, $twit_user->id, $screen_name, $password); - } + function savePreferences() + { + $noticesync = $this->boolean('noticesync'); + $friendsync = $this->boolean('friendsync'); + $replysync = $this->boolean('replysync'); - $this->show_form(_('Twitter settings saved.'), true); - } + $user = common_current_user(); - 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); + $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; - } + if (!$flink) { + common_log_db_error($flink, 'SELECT', __FILE__); + $this->showForm(_('Couldn\'t save Twitter preferences.')); + return; + } - $twitter_id = $flink->foreign_id; - $password = $flink->credentials; + $twitter_id = $flink->foreign_id; + $password = $flink->credentials; - $fuser = $flink->getForeignUser(); + $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->showForm(_('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); - if ($result === FALSE) { - common_log_db_error($flink, 'UPDATE', __FILE__); - $this->show_form(_('Couldn\'t save Twitter preferences.')); - return; - } + $flink->set_flags($noticesync, $replysync, $friendsync); - if ($friendsync) { - save_twitter_friends($user, $flink->foreign_id, $screen_name, $password); - } + $result = $flink->update($original); - $this->show_form(_('Twitter preferences saved.')); - } + if ($result === false) { + common_log_db_error($flink, 'UPDATE', __FILE__); + $this->showForm(_('Couldn\'t save Twitter preferences.')); + return; + } - function verify_credentials($screen_name, $password) { - $uri = 'http://twitter.com/account/verify_credentials.json'; - $data = get_twitter_data($uri, $screen_name, $password); + if ($friendsync) { + save_twitter_friends($user, $flink->foreign_id, $screen_name, $password); + } - if (!$data) { - return false; - } + $this->showForm(_('Twitter preferences saved.'), true); + } - $user = json_decode($data); + /** + * Verifies a username and password against Twitter's API + * + * @param string $screen_name Twitter user name + * @param string $password Twitter password + * + * @return boolean success flag + */ - if (!$user) { - return false; - } + function verifyCredentials($screen_name, $password) + { + $uri = 'http://twitter.com/account/verifyCredentials.json'; - $twitter_id = $user->status->id; + $data = get_twitter_data($uri, $screen_name, $password); - if ($twitter_id) { - return $twitter_id; - } + if (!$data) { + return false; + } - return false; - } + $user = json_decode($data); - function set_flags(&$flink, $noticesync, $replysync, $friendsync) { - if ($noticesync) { - $flink->noticesync |= FOREIGN_NOTICE_SEND; - } else { - $flink->noticesync &= ~FOREIGN_NOTICE_SEND; - } + if (!$user) { + return false; + } - if ($replysync) { - $flink->noticesync |= FOREIGN_NOTICE_SEND_REPLY; - } else { - $flink->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY; - } + $twitter_id = $user->id; - if ($friendsync) { - $flink->friendsync |= FOREIGN_FRIEND_RECV; - } else { - $flink->friendsync &= ~FOREIGN_FRIEND_RECV; - } + if ($twitter_id) { + return $twitter_id; + } - $flink->profilesync = 0; - } + return false; + } -}
\ No newline at end of file +} diff --git a/actions/unblock.php b/actions/unblock.php index d60cc7088..bad496353 100644 --- a/actions/unblock.php +++ b/actions/unblock.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Unblock a user action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,63 +28,86 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -class UnblockAction extends Action { - - var $profile = NULL; - - function prepare($args) { +if (!defined('LACONICA')) { + exit(1); +} +/** + * Unblock a user action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class UnblockAction extends Action +{ + var $profile = null; + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + */ + function prepare($args) + { parent::prepare($args); - if (!common_logged_in()) { - $this->client_error(_('Not logged in.')); + $this->clientError(_('Not logged in.')); return false; } - - $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->clientError(_('There was a problem with your session token. Try again, please.')); + return; + } $id = $this->trimmed('unblockto'); - if (!$id) { - $this->client_error(_('No profile specified.')); + $this->clientError(_('No profile specified.')); return false; } - $this->profile = Profile::staticGet('id', $id); - if (!$this->profile) { - $this->client_error(_('No profile with that ID.')); + $this->clientError(_('No profile with that ID.')); return false; } - return true; } - function handle($args) { + /** + * Handle request + * + * Shows a page with list of favorite notices + * + * @param array $args $_REQUEST args; handled in prepare() + * + * @return void + */ + function handle($args) + { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->unblock_profile(); + $this->unblockProfile(); } } - function unblock_profile() { - - $cur = common_current_user(); - + /** + * Unblock a user. + * + * @return void + */ + function unblockProfile() + { + $cur = common_current_user(); $result = $cur->unblock($this->profile); - if (!$result) { - $this->server_error(_('Error removing the block.')); + $this->serverError(_('Error removing the block.')); return; } - foreach ($this->args as $k => $v) { if ($k == 'returnto-action') { $action = $v; @@ -81,7 +115,6 @@ class UnblockAction extends Action { $args[substr($k, 9)] = $v; } } - if ($action) { common_redirect(common_local_url($action, $args)); } else { @@ -90,3 +123,4 @@ class UnblockAction extends Action { } } } + diff --git a/actions/unsubscribe.php b/actions/unsubscribe.php index 98291e897..f9dd6f821 100644 --- a/actions/unsubscribe.php +++ b/actions/unsubscribe.php @@ -17,64 +17,67 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -class UnsubscribeAction extends Action { +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()) { + $this->clientError(_('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->clientError(_('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.')); + $this->clientError(_('No profile id in request.')); return; } $other = Profile::staticGet('id', $other_id); if (!$other_id) { - $this->client_error(_('No profile with that id.')); + $this->clientError(_('No profile with that id.')); return; } - $result = subs_unsubscribe_to($user, $other); + $result = subs_unsubscribe_to($user, $other); - if ($result != true) { - common_user_error($result); - return; - } + if ($result != true) { + $this->clientError($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')) { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + $this->element('title', null, _('Unsubscribed')); + $this->elementEnd('head'); + $this->elementStart('body'); + $subscribe = new SubscribeForm($this, $other); + $subscribe->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + common_redirect(common_local_url('subscriptions', array('nickname' => + $user->nickname))); } - } + } } diff --git a/actions/updateprofile.php b/actions/updateprofile.php index 921e88e63..c79112dac 100644 --- a/actions/updateprofile.php +++ b/actions/updateprofile.php @@ -21,154 +21,157 @@ 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; - } - } +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->serverError($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->clientError(_('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->clientError(_('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->clientError(_('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->serverError(_('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->clientError(_('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->clientError(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->clientError(sprintf(_("Invalid profile URL '%s'."), $profile_url)); + return false; + } + # optional stuff + $fullname = $req->get_parameter('omb_listenee_fullname'); + if ($fullname && strlen($fullname) > 255) { + $this->clientError(_("Full name is too long (max 255 chars).")); + return false; + } + $homepage = $req->get_parameter('omb_listenee_homepage'); + if ($homepage && (!common_valid_http_url($homepage) || strlen($homepage) > 255)) { + $this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage)); + return false; + } + $bio = $req->get_parameter('omb_listenee_bio'); + if ($bio && strlen($bio) > 140) { + $this->clientError(_("Bio is too long (max 140 chars).")); + return false; + } + $location = $req->get_parameter('omb_listenee_location'); + if ($location && strlen($location) > 255) { + $this->clientError(_("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->clientError(sprintf(_("Invalid avatar URL '%s'"), $avatar)); + return false; + } + $size = @getimagesize($avatar); + if (!$size) { + $this->clientError(sprintf(_("Can't read avatar URL '%s'"), $avatar)); + return false; + } + if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) { + $this->clientError(sprintf(_("Wrong size image at '%s'"), $avatar)); + return false; + } + if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, + IMAGETYPE_PNG))) { + $this->clientError(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->serverError(_('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->serverError(_('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/actions/userauthorization.php b/actions/userauthorization.php index ac0a0728c..ed62f640c 100644 --- a/actions/userauthorization.php +++ b/actions/userauthorization.php @@ -22,558 +22,579 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/omb.php'); 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(); - } +class UserauthorizationAction extends Action +{ + var $error; + var $req; + + 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->getStoredRequest(); + $this->showForm($req, _('There was a problem with your session token. '. + 'Try again, please.')); + return; + } + # We've shown the form, now post user's choice + $this->sendAuthorization(); + } else { + if (!common_logged_in()) { + # Go log in, and then come back + common_set_returnto($_SERVER['REQUEST_URI']); + + common_redirect(common_local_url('login')); + return; + } + try { + # this must be a new request + $req = $this->getNewRequest(); + if (!$req) { + $this->clientError(_('No request found!')); + } + # XXX: only validate new requests, since nonce is one-time use + $this->validateRequest($req); + $this->storeRequest($req); + $this->showForm($req); + } catch (OAuthException $e) { + $this->clearRequest(); + $this->clientError($e->getMessage()); + return; + } + + } + } + + function showForm($req, $error=null) + { + $this->req = $req; + $this->error = $error; + $this->showPage(); + } + + function title() + { + return _('Authorize subscription'); + } + + function showPageNotice() + { + $this->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".')); + } + + function showContent() + { + $req = $this->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'); + + $this->elementStart('div', 'profile'); + if ($avatar) { + $this->element('img', array('src' => $avatar, + 'class' => 'avatar profile', + 'width' => AVATAR_PROFILE_SIZE, + 'height' => AVATAR_PROFILE_SIZE, + 'alt' => $nickname)); + } + $this->element('a', array('href' => $profile, + 'class' => 'external profile nickname'), + $nickname); + if ($fullname) { + $this->elementStart('div', 'fullname'); + if ($homepage) { + $this->element('a', array('href' => $homepage), + $fullname); + } else { + $this->text($fullname); + } + $this->elementEnd('div'); + } + if ($location) { + $this->element('div', 'location', $location); + } + if ($bio) { + $this->element('div', 'bio', $bio); + } + $this->elementStart('div', 'license'); + $this->element('a', array('href' => $license, + 'class' => 'license'), + $license); + $this->elementEnd('div'); + $this->elementEnd('div'); + $this->elementStart('form', array('method' => 'post', + 'id' => 'userauthorization', + 'name' => 'userauthorization', + 'action' => common_local_url('userauthorization'))); + $this->hidden('token', common_session_token()); + $this->submit('accept', _('Accept')); + $this->submit('reject', _('Reject')); + $this->elementEnd('form'); + } + + function sendAuthorization() + { + $req = $this->getStoredRequest(); + + if (!$req) { + $this->clientError(_('No authorization request!')); + return; + } + + $callback = $req->get_parameter('oauth_callback'); + + if ($this->arg('accept')) { + if (!$this->authorizeToken($req)) { + $this->clientError(_('Error authorizing token')); + } + if (!$this->saveRemoteProfile($req)) { + $this->clientError(_('Error saving remote profile')); + } + if (!$callback) { + $this->showAcceptMessage($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->serverError(_('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->showRejectMessage(); + } else { + # XXX: not 100% sure how to signal failure... just redirect without token? + common_redirect($callback, 303); + } + } + } + + function authorizeToken(&$req) + { + $consumer_key = $req->get_parameter('oauth_consumer_key'); + $token_field = $req->get_parameter('oauth_token'); + $rt = new Token(); + $rt->consumer_key = $consumer_key; + $rt->tok = $token_field; + $rt->type = 0; + $rt->state = 0; + if ($rt->find(true)) { + $orig_rt = clone($rt); + $rt->state = 1; # Authorized but not used + if ($rt->update($orig_rt)) { + return true; + } + } + return false; + } + + # XXX: refactor with similar code in finishremotesubscribe.php + + function saveRemoteProfile(&$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->addAvatar($profile, $avatar_url)) { + return false; + } + } + + $user = common_current_user(); + $datastore = omb_oauth_datastore(); + $consumer = $this->getConsumer($datastore, $req); + $token = $this->getToken($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 addAvatar($profile, $url) + { + $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar'); + copy($url, $temp_filename); + return $profile->setOriginal($temp_filename); + } + + function showAcceptMessage($tok) + { + common_show_header(_('Subscription authorized')); + $this->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:')); + $this->element('blockquote', 'token', $tok); + common_show_footer(); + } + + function showRejectMessage($tok) + { + common_show_header(_('Subscription rejected')); + $this->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 storeRequest($req) + { + common_ensure_session(); + $_SESSION['userauthorizationrequest'] = $req; + } + + function clearRequest() + { + common_ensure_session(); + unset($_SESSION['userauthorizationrequest']); + } + + function getStoredRequest() + { + common_ensure_session(); + $req = $_SESSION['userauthorizationrequest']; + return $req; + } + + function getNewRequest() + { + common_remove_magic_from_request(); + $req = OAuthRequest::from_request(); + return $req; + } + + # Throws an OAuthException if anything goes wrong + + function validateRequest(&$req) + { + # OAuth stuff -- have to copy from OAuth.php since they're + # all private methods, and there's no user-authentication method + $this->checkVersion($req); + $datastore = omb_oauth_datastore(); + $consumer = $this->getConsumer($datastore, $req); + $token = $this->getToken($datastore, $req, $consumer); + $this->checkTimestamp($req); + $this->checkNonce($datastore, $req, $consumer, $token); + $this->checkSignature($req, $consumer, $token); + $this->validateOmb($req); + return true; + } + + function validateOmb(&$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 checkVersion(&$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 getConsumer($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 getToken($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 checkTimestamp(&$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 checkNonce(&$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 checkSignature(&$req, $consumer, $token) + { + $signature_method = $this->getSignatureMethod($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 getSignatureMethod(&$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/actions/userbyid.php b/actions/userbyid.php index 38bff2ede..1e30d1aac 100644 --- a/actions/userbyid.php +++ b/actions/userbyid.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * User by ID action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,33 +29,60 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -class UserbyidAction extends Action { - - function is_readonly() { - return true; - } - - function handle($args) { +/** + * User by ID action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class UserbyidAction extends Action +{ + /** + * Is read only? + * + * @return boolean true + */ + function isReadOnly() + { + return true; + } + + /** + * Class handler. + * + * @param array $args array of arguments + * + * @return nothing + */ + 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->clientError(_('No id.')); + } + $user =& User::staticGet($id); + if (!$user) { + $this->clientError(_('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), - common_accept_to_prefs($page_prefs)); - $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream'; - - $url = common_local_url($page, array('nickname' => $user->nickname)); - common_redirect($url, 303); - } + $httpaccept = isset($_SERVER['HTTP_ACCEPT']) + ? $_SERVER['HTTP_ACCEPT'] : null; + $type = common_negotiate_type(common_accept_to_prefs($httpaccept), + common_accept_to_prefs($page_prefs)); + $page = $type == 'application/rdf+xml' ? 'foaf' : 'showstream'; + $url = common_local_url($page, array('nickname' => $user->nickname)); + common_redirect($url, 303); + } } + diff --git a/actions/usergroups.php b/actions/usergroups.php new file mode 100644 index 000000000..20f2e5a75 --- /dev/null +++ b/actions/usergroups.php @@ -0,0 +1,135 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * User groups information + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/grouplist.php'; + +/** + * User groups page + * + * Show the groups a user belongs to + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class UsergroupsAction extends Action +{ + var $user = null; + var $page = null; + var $profile = null; + + function title() + { + if ($this->page == 1) { + return sprintf(_("%s groups"), $this->user->nickname); + } else { + return sprintf(_("%s groups, page %d"), + $this->user->nickname, + $this->page); + } + } + + function prepare($args) + { + parent::prepare($args); + + $nickname_arg = $this->arg('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + if ($this->arg('page') && $this->arg('page') != 1) { + $args['page'] = $this->arg['page']; + } + common_redirect(common_local_url('usergroups', $args), 301); + return false; + } + + $this->user = User::staticGet('nickname', $nickname); + + if (!$this->user) { + $this->clientError(_('No such user.'), 404); + return false; + } + + $this->profile = $this->user->getProfile(); + + if (!$this->profile) { + $this->serverError(_('User has no profile.')); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + return true; + } + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function showLocalNav() + { + $nav = new SubGroupNav($this, $this->user); + $nav->show(); + } + + function showContent() + { + $this->element('a', array('href' => common_local_url('newgroup'), + 'id' => 'new_group'), + _('Create a new group')); + + $offset = ($this->page-1) * GROUPS_PER_PAGE; + $limit = GROUPS_PER_PAGE + 1; + + $groups = $this->user->getGroups($offset, $limit); + + if ($groups) { + $gl = new GroupList($groups, $this->user, $this); + $cnt = $gl->show(); + } + + $this->pagination($this->page > 1, $cnt > GROUPS_PER_PAGE, + $this->page, 'usergroups', + array('nickname' => $this->user->nickname)); + } +} diff --git a/actions/userrss.php b/actions/userrss.php index e57f86105..c1f2321ee 100644 --- a/actions/userrss.php +++ b/actions/userrss.php @@ -23,68 +23,76 @@ require_once(INSTALLDIR.'/lib/rssaction.php'); // Formatting of RSS handled by Rss10Action -class UserrssAction extends Rss10Action { +class UserrssAction extends Rss10Action +{ - var $user = NULL; + var $user = null; - function init() { - $nickname = $this->trimmed('nickname'); - $this->user = User::staticGet('nickname', $nickname); + function prepare($args) + { + parent::prepare($args); + $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) { + $this->clientError(_('No such user.')); + return false; + } else { + return true; + } + } - function get_notices($limit=0) { + function getNotices($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 getChannel() + { + $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 getImage() + { + $user = $this->user; + $profile = $user->getProfile(); + if (!$profile) { + common_log_db_error($user, 'SELECT', __FILE__); + $this->serverError(_('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 initRss($limit=0) + { + $url = common_local_url('sup', null, $this->user->id); + header('X-SUP-ID: '.$url); + parent::initRss($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/actions/xrds.php b/actions/xrds.php index 1d516aab7..075831803 100644 --- a/actions/xrds.php +++ b/actions/xrds.php @@ -1,5 +1,17 @@ <?php -/* + +/** + * XRDS for OpenID + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,116 +29,145 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -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)); +if (!defined('LACONICA')) { + exit(1); +} - $this->show_service(OAUTH_ENDPOINT_ACCESS, - common_local_url('accesstoken'), - array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY), - array(OAUTH_HMAC_SHA1)); +require_once INSTALLDIR.'/lib/omb.php'; - $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(); - } +/** + * XRDS for OpenID + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class XrdsAction extends Action +{ + /** + * Is read only? + * + * @return boolean true + */ + function isReadOnly() + { + return true; + } + + /** + * Class handler. + * + * @param array $args query arguments + * + * @return void + */ + function handle($args) + { + parent::handle($args); + $nickname = $this->trimmed('nickname'); + $user = User::staticGet('nickname', $nickname); + if (!$user) { + $this->clientError(_('No such user.')); + return; + } + $this->showXrds($user); + } + + /** + * Show XRDS for a user. + * + * @param class $user XRDS for this user. + * + * @return void + */ + function showXrds($user) + { + header('Content-Type: application/xrds+xml'); + $this->startXML(); + $this->elementStart('XRDS', array('xmlns' => 'xri://$xrds')); + + $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xml:id' => 'oauth', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $this->element('Type', null, 'xri://$xrds*simple'); + $this->showService(OAUTH_ENDPOINT_REQUEST, + common_local_url('requesttoken'), + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY), + array(OAUTH_HMAC_SHA1), + $user->uri); + $this->showService(OAUTH_ENDPOINT_AUTHORIZE, + common_local_url('userauthorization'), + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY), + array(OAUTH_HMAC_SHA1)); + $this->showService(OAUTH_ENDPOINT_ACCESS, + common_local_url('accesstoken'), + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY), + array(OAUTH_HMAC_SHA1)); + $this->showService(OAUTH_ENDPOINT_RESOURCE, + null, + array(OAUTH_AUTH_HEADER, OAUTH_POST_BODY), + array(OAUTH_HMAC_SHA1)); + $this->elementEnd('XRD'); + + // XXX: decide whether to include user's ID/nickname in postNotice URL + $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'xml:id' => 'omb', + 'xmlns:simple' => 'http://xrds-simple.net/core/1.0', + 'version' => '2.0')); + $this->element('Type', null, 'xri://$xrds*simple'); + $this->showService(OMB_ENDPOINT_POSTNOTICE, + common_local_url('postnotice')); + $this->showService(OMB_ENDPOINT_UPDATEPROFILE, + common_local_url('updateprofile')); + $this->elementEnd('XRD'); + $this->elementStart('XRD', array('xmlns' => 'xri://$xrd*($v*2.0)', + 'version' => '2.0')); + $this->element('Type', null, 'xri://$xrds*simple'); + $this->showService(OAUTH_DISCOVERY, + '#oauth'); + $this->showService(OMB_NAMESPACE, + '#omb'); + $this->elementEnd('XRD'); + $this->elementEnd('XRDS'); + $this->endXML(); + } + + /** + * Show service. + * + * @param string $type XRDS type + * @param string $uri URI + * @param array $params type parameters, null by default + * @param array $sigs type signatures, null by default + * @param string $localId local ID, null by default + * + * @return void + */ + function showService($type, $uri, $params=null, $sigs=null, $localId=null) + { + $this->elementStart('Service'); + if ($uri) { + $this->element('URI', null, $uri); + } + $this->element('Type', null, $type); + if ($params) { + foreach ($params as $param) { + $this->element('Type', null, $param); + } + } + if ($sigs) { + foreach ($sigs as $sig) { + $this->element('Type', null, $sig); + } + } + if ($localId) { + $this->element('LocalID', null, $localId); + } + $this->elementEnd('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/avatar/.gitignore b/avatar/.gitignore new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/avatar/.gitignore diff --git a/classes/Avatar.php b/classes/Avatar.php index 901c47c51..9ae920647 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -21,75 +21,121 @@ class Avatar extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Avatar',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Avatar',$k,$v); } /* 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); - - $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png"; - - $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)); - } - - $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; - } - } - - 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); - } + imagecopyresampled($image_s, $image_a, 0, 0, 0, 0, + $size, $size, $square, $square); + + $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png"; + + $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)); + } + + $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; + } + } + + function scale_and_crop($size, $x, $y, $w, $h) + { + + $image_s = imagecreatetruecolor($size, $size); + $image_a = $this->to_image(); + + # Retain alpha channel info if possible for .pngs + $background = imagecolorallocate($image_s, 0, 0, 0); + ImageColorTransparent($image_s, $background); + imagealphablending($image_s, false); + + imagecopyresized($image_s, $image_a, 0, 0, $x, $y, $size, $size, $w, $h); + + $ext = ($this->mediattype == 'image/jpeg') ? ".jpeg" : ".png"; + + $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)); + } + + $cropped = DB_DataObject::factory('avatar'); + $cropped->profile_id = $this->profile_id; + $cropped->width = $size; + $cropped->height = $size; + $cropped->original = false; + $cropped->mediatype = ($this->mediattype == 'image/jpeg') ? 'image/jpeg' : 'image/png'; + $cropped->filename = $filename; + $cropped->url = common_avatar_url($filename); + $cropped->created = DB_DataObject_Cast::dateTime(); # current time + + if ($cropped->insert()) { + return $cropped; + } 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); + } + } diff --git a/classes/Channel.php b/classes/Channel.php index bcc0c36b5..2e3e4e8d4 100644 --- a/classes/Channel.php +++ b/classes/Channel.php @@ -19,182 +19,213 @@ 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; - } +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; + } } -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; - } - } +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; + } + } } -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); - } +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); + } } -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'); - } +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'); + } } -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; - } +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; + } } diff --git a/classes/Command.php b/classes/Command.php index c2409d140..eacbdacb3 100644 --- a/classes/Command.php +++ b/classes/Command.php @@ -21,356 +21,399 @@ 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; - } +class Command +{ + + 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.")); - } +class UnimplementedCommand extends Command +{ + function execute($channel) + { + $channel->error($this->user, _("Sorry, this command is not yet implemented.")); + } } -class TrackingCommand extends UnimplementedCommand { +class TrackingCommand extends UnimplementedCommand +{ } -class TrackOffCommand extends UnimplementedCommand { +class TrackOffCommand extends UnimplementedCommand +{ } -class TrackCommand extends UnimplementedCommand { - var $word = NULL; - function __construct($user, $word) { - parent::__construct($user); - $this->word = $word; - } +class TrackCommand extends UnimplementedCommand +{ + 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; - } +class UntrackCommand extends UnimplementedCommand +{ + 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; - } +class NudgeCommand extends UnimplementedCommand +{ + 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; - } +class InviteCommand extends UnimplementedCommand +{ + var $other = null; + function __construct($user, $other) + { + parent::__construct($user); + $this->other = $other; + } } -class StatsCommand extends Command { - function execute($channel) { +class StatsCommand extends Command +{ + 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); +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); - 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); - } +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); + } } -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.')); - } - } +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.')); + } + } } -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); +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); - 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); - } - } +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); + } + } } -class UnsubCommand extends Command { +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.')); - } - } - } +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.')); + } + } + } } -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.')); - } - } - } +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.')); + } + } + } } -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")); - } +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")); + } } diff --git a/classes/CommandInterpreter.php b/classes/CommandInterpreter.php index eae315cb6..0679f5462 100644 --- a/classes/CommandInterpreter.php +++ b/classes/CommandInterpreter.php @@ -21,176 +21,178 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/classes/Command.php'); -class CommandInterpreter { - - function handle_command($user, $text) { - # XXX: localise +class CommandInterpreter +{ - $text = preg_replace('/\s+/', ' ', trim($text)); - list($cmd, $arg) = explode(' ', $text, 2); + function handle_command($user, $text) + { + # XXX: localise - # 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': - case 'dm': - 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; - } - } + $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': + case 'dm': + 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/classes/Confirm_address.php b/classes/Confirm_address.php index 10661ff5c..ed3875d22 100644 --- a/classes/Confirm_address.php +++ b/classes/Confirm_address.php @@ -20,10 +20,12 @@ class Confirm_address extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Confirm_address',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Confirm_address',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function sequenceKey() { return array(false, false); } + function sequenceKey() + { return array(false, false); } } diff --git a/classes/Consumer.php b/classes/Consumer.php index d18e6feeb..d5b7b7e33 100644 --- a/classes/Consumer.php +++ b/classes/Consumer.php @@ -16,7 +16,8 @@ class Consumer extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Consumer',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Consumer',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Fave.php b/classes/Fave.php index 7cc3f585e..24df5938c 100644 --- a/classes/Fave.php +++ b/classes/Fave.php @@ -15,23 +15,25 @@ class Fave extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Fave',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Fave',$k,$v); } /* 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/classes/Foreign_link.php b/classes/Foreign_link.php index 7a625a209..afc0e2180 100644 --- a/classes/Foreign_link.php +++ b/classes/Foreign_link.php @@ -4,7 +4,7 @@ */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Foreign_link extends Memcached_DataObject +class Foreign_link extends Memcached_DataObject { ###START_AUTOCODE /* the code below is auto generated do not remove the above tag */ @@ -13,7 +13,7 @@ class Foreign_link extends Memcached_DataObject public $user_id; // int(4) primary_key not_null public $foreign_id; // int(4) primary_key not_null public $service; // int(4) primary_key not_null - public $credentials; // varchar(255) + public $credentials; // varchar(255) public $noticesync; // tinyint(1) not_null default_1 public $friendsync; // tinyint(1) not_null default_2 public $profilesync; // tinyint(1) not_null default_1 @@ -21,56 +21,84 @@ class Foreign_link extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_link',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Foreign_link',$k,$v); } /* 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); - - 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); - - 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); - } - + // 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; + } + + 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; + } + + return null; + } + + function set_flags($noticesync, $replysync, $friendsync) + { + if ($noticesync) { + $this->noticesync |= FOREIGN_NOTICE_SEND; + } else { + $this->noticesync &= ~FOREIGN_NOTICE_SEND; + } + + if ($replysync) { + $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY; + } else { + $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY; + } + + if ($friendsync) { + $this->friendsync |= FOREIGN_FRIEND_RECV; + } else { + $this->friendsync &= ~FOREIGN_FRIEND_RECV; + } + + $this->profilesync = 0; + } + + # 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/classes/Foreign_service.php b/classes/Foreign_service.php index 18ef83d69..ef614dbd6 100644 --- a/classes/Foreign_service.php +++ b/classes/Foreign_service.php @@ -17,7 +17,8 @@ class Foreign_service extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_service',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Foreign_service',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Foreign_subscription.php b/classes/Foreign_subscription.php index 315064067..d50860621 100644 --- a/classes/Foreign_subscription.php +++ b/classes/Foreign_subscription.php @@ -16,7 +16,8 @@ class Foreign_subscription extends Memcached_DataObject public $created; // datetime() not_null /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_subscription',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Foreign_subscription',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Foreign_user.php b/classes/Foreign_user.php index 027fae69d..61727abe5 100644 --- a/classes/Foreign_user.php +++ b/classes/Foreign_user.php @@ -18,53 +18,55 @@ class Foreign_user extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Foreign_user',$k,$v); } /* 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/classes/Group_inbox.php b/classes/Group_inbox.php new file mode 100755 index 000000000..b80ba4272 --- /dev/null +++ b/classes/Group_inbox.php @@ -0,0 +1,21 @@ +<?php +/** + * Table Definition for group_inbox + */ + +class Group_inbox extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'group_inbox'; // table name + public $group_id; // int(4) primary_key not_null + public $notice_id; // int(4) primary_key not_null + public $created; // datetime() not_null + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_inbox',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/Group_member.php b/classes/Group_member.php new file mode 100755 index 000000000..3c23a991f --- /dev/null +++ b/classes/Group_member.php @@ -0,0 +1,28 @@ +<?php +/** + * Table Definition for group_member + */ + +class Group_member extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'group_member'; // table name + public $group_id; // int(4) primary_key not_null + public $profile_id; // int(4) primary_key not_null + public $is_admin; // tinyint(1) + public $created; // datetime() not_null + public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_member',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + function &pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Group_member', $kv); + } +} diff --git a/classes/Invitation.php b/classes/Invitation.php index 1477391b0..8a36fd8df 100644 --- a/classes/Invitation.php +++ b/classes/Invitation.php @@ -17,7 +17,8 @@ class Invitation extends Memcached_DataObject public $created; // datetime() not_null /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Invitation',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Invitation',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 7a33e158d..5f71f716b 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -21,156 +21,166 @@ if (!defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -class Memcached_DataObject extends DB_DataObject +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; - } - } - - 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 &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; + } + } + + function &pkeyGet($cls, $kv) + { + $i = Memcached_DataObject::multicache($cls, $kv); + if ($i) { 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 keyTypes() { - global $_DB_DATAOBJECT; + } 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 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)); + } + } + 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)); } - 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 getSearchEngine($table) { + } + + function getSearchEngine($table) + { require_once INSTALLDIR.'/lib/search_engines.php'; static $search_engine; if (!isset($search_engine)) { @@ -191,4 +201,30 @@ class Memcached_DataObject extends DB_DataObject } return $search_engine; } + + static function cachedQuery($cls, $qry, $expiry=3600) + { + $c = Memcached_DataObject::memcache(); + if (!$c) { + $inst = new $cls(); + $inst->query($qry); + return $inst; + } + $key_part = common_keyize($cls).':'.md5($qry); + $ckey = common_cache_key($key_part); + $stored = $c->get($ckey); + if ($stored) { + return new ArrayWrapper($stored); + } + + $inst = new $cls(); + $inst->query($qry); + $cached = array(); + while ($inst->fetch()) { + $cached[] = clone($inst); + } + $inst->free(); + $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry); + return new ArrayWrapper($cached); + } } diff --git a/classes/Message.php b/classes/Message.php index ef4bd0316..4806057b4 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -22,47 +22,50 @@ class Message extends Memcached_DataObject public $source; // varchar(32) /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Message',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Message',$k,$v); } /* 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/classes/Nonce.php b/classes/Nonce.php index 89d673c53..2c0edfa14 100644 --- a/classes/Nonce.php +++ b/classes/Nonce.php @@ -18,7 +18,8 @@ class Nonce extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Nonce',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Nonce',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Notice.php b/classes/Notice.php index 281696632..4a06c9258 100644 --- a/classes/Notice.php +++ b/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,73 @@ 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,76 +106,74 @@ 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->query('BEGIN'); - - $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(); + $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; - if (!$id) { - common_log_db_error($notice, 'INSERT', __FILE__); - return _('Problem saving notice.'); - } + $id = $notice->insert(); - # Update the URI after the notice is in the database - if (!$uri) { - $orig = clone($notice); - $notice->uri = common_notice_uri($notice); + if (!$id) { + common_log_db_error($notice, 'INSERT', __FILE__); + return _('Problem saving notice.'); + } - if (!$notice->update($orig)) { - common_log_db_error($notice, 'UPDATE', __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); - # XXX: do we need to change this for remote users? + if (!$notice->update($orig)) { + common_log_db_error($notice, 'UPDATE', __FILE__); + return _('Problem saving notice.'); + } + } - common_save_replies($notice); - $notice->saveTags(); + # XXX: do we need to change this for remote users? - // Add to notice inboxes - - $notice->addToInboxes(); + $notice->saveReplies(); + $notice->saveTags(); + $notice->saveGroups(); + $notice->addToInboxes(); $notice->query('COMMIT'); - - # 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(); - } + # 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(); + } - return $notice; - } + return $notice; + } static function checkEditThrottle($profile_id) { $profile = Profile::staticGet($profile_id); @@ -191,356 +193,538 @@ 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); + $this->blowGroupCache($blowLast); + } - if ($since) { - - if ($needWhere) { - $qry .= ' WHERE '; - $needWhere = FALSE; - } else { - $qry .= ' AND '; - } + function blowGroupCache($blowLast=false) + { + $cache = common_memcache(); + if ($cache) { + $group_inbox = new Group_inbox(); + $group_inbox->notice_id = $this->id; + if ($group_inbox->find()) { + while ($group_inbox->fetch()) { + $cache->delete(common_cache_key('group:notices:'.$group_inbox->group_id)); + if ($blowLast) { + $cache->delete(common_cache_key('group:notices:'.$group_inbox->group_id.';last')); + } + $member = new Group_member(); + $member->group_id = $group_inbox->group_id; + if ($member->find()) { + while ($member->fetch()) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id)); + if ($blowLast) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id . ';last')); + } + } + } + } + } + $group_inbox->free(); + unset($group_inbox); + } + } - $qry .= ' notice.created > \'' . date('Y-m-d H:i:s', $since) . '\''; - } + 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); + } + } - # Allow ORDER override + 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); + } + } - if ($order) { - $qry .= $order; - } else { - $qry .= ' ORDER BY notice.created DESC, notice.id DESC '; - } + 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'); + } + } + } + } - if (common_config('db','type') == 'pgsql') { - $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $qry .= ' LIMIT ' . $offset . ', ' . $limit; - } + 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); + } + } - $notice = new Notice(); + # XXX: too many args; we need to move to named params or even a separate + # class for notice streams - $notice->query($qry); + static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $order=null, $since=null) { - return $notice; - } + if (common_config('memcached', 'enabled')) { - # XXX: this is pretty long and should probably be broken up into - # some helper functions + # 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); + } + } - static function getCachedStream($qry, $cachekey, $offset, $limit, $order) { + return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since); + } - # If outside our cache window, just go to the DB + static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) { - if ($offset + $limit > NOTICE_CACHE_WINDOW) { - return Notice::getStreamDirect($qry, $offset, $limit, NULL, NULL, $order, NULL); - } + $needAnd = false; + $needWhere = true; - # Get the cache; if we can't, just go to the DB + if (preg_match('/\bWHERE\b/i', $qry)) { + $needWhere = false; + $needAnd = true; + } - $cache = common_memcache(); + if ($since_id > 0) { - 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.id > ' . $since_id; + } - $notices = $cache->get(common_cache_key($cachekey)); + if ($before_id > 0) { - # On a cache hit, return a DB-object-like wrapper + if ($needWhere) { + $qry .= ' WHERE '; + $needWhere = false; + } else { + $qry .= ' AND '; + } - if ($notices !== FALSE) { - $wrapper = new NoticeWrapper(array_slice($notices, $offset, $limit)); - return $wrapper; - } + $qry .= ' notice.id < ' . $before_id; + } - # 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 ($since) { - # No cache hit. Try to get the *last* cached version + if ($needWhere) { + $qry .= ' WHERE '; + $needWhere = false; + } else { + $qry .= ' AND '; + } - $last_notices = $cache->get(common_cache_key($cachekey) . ';last'); + $qry .= ' notice.created > \'' . date('Y-m-d H:i:s', $since) . '\''; + } - if ($last_notices) { + # Allow ORDER override - # Reverse-chron order, so last ID is last. + if ($order) { + $qry .= $order; + } else { + $qry .= ' ORDER BY notice.created DESC, notice.id DESC '; + } - $last_id = $last_notices[0]->id; + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } - # XXX: this assumes monotonically increasing IDs; a fair - # bet with our DB. + $notice = new Notice(); - $new_notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, - $last_id, NULL, $order, NULL); + $notice->query($qry); - 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 $notice; + } - # Store the array in the cache for next time + # XXX: this is pretty long and should probably be broken up into + # some helper functions - $result = $cache->set(common_cache_key($cachekey), $notices); - $result = $cache->set(common_cache_key($cachekey) . ';last', $notices); + static function getCachedStream($qry, $cachekey, $offset, $limit, $order) { - # return a wrapper of the array for use now + # If outside our cache window, just go to the DB - return new NoticeWrapper(array_slice($notices, $offset, $limit)); - } - } + if ($offset + $limit > NOTICE_CACHE_WINDOW) { + return Notice::getStreamDirect($qry, $offset, $limit, null, null, $order, null); + } - # Otherwise, get the full cache window out of the DB + # Get the cache; if we can't, just go to the DB - $notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, NULL, NULL, $order, NULL); + $cache = common_memcache(); - # If there are no hits, just return the value + if (!$cache) { + return Notice::getStreamDirect($qry, $offset, $limit, null, null, $order, null); + } - if (!$notice) { - return $notice; - } + # Get the notices out of the cache - # Pack results into an array + $notices = $cache->get(common_cache_key($cachekey)); - $notices = array(); + # On a cache hit, return a DB-object-like wrapper - while ($notice->fetch()) { - $notices[] = clone($notice); - } + if ($notices !== false) { + $wrapper = new ArrayWrapper(array_slice($notices, $offset, $limit)); + return $wrapper; + } - $notice->free(); + # 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' - # Store the array in the cache for next time + # No cache hit. Try to get the *last* cached version - $result = $cache->set(common_cache_key($cachekey), $notices); - $result = $cache->set(common_cache_key($cachekey) . ';last', $notices); + $last_notices = $cache->get(common_cache_key($cachekey) . ';last'); - # return a wrapper of the array for use now + if ($last_notices) { - $wrapper = new NoticeWrapper(array_slice($notices, $offset, $limit)); + # Reverse-chron order, so last ID is last. - return $wrapper; - } + $last_id = $last_notices[0]->id; - function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=NULL) { + # XXX: this assumes monotonically increasing IDs; a fair + # bet with our DB. - $parts = array(); + $new_notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, + $last_id, null, $order, null); - $qry = 'SELECT * FROM notice '; + 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); - if (common_config('public', 'localonly')) { - $parts[] = 'is_local = 1'; - } else { - # -1 == blacklisted - $parts[] = 'is_local != -1'; - } + # Store the array in the cache for next time - if ($parts) { - $qry .= ' WHERE ' . implode(' AND ', $parts); - } + $result = $cache->set(common_cache_key($cachekey), $notices); + $result = $cache->set(common_cache_key($cachekey) . ';last', $notices); - return Notice::getStream($qry, - 'public', - $offset, $limit, $since_id, $before_id, NULL, $since); - } + # return a wrapper of the array for use now - function addToInboxes() { - $enabled = common_config('inboxes', 'enabled'); + return new ArrayWrapper(array_slice($notices, $offset, $limit)); + } + } - 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; - } + # Otherwise, get the full cache window out of the DB - # Delete from inboxes if we're deleted. + $notice = Notice::getStreamDirect($qry, 0, NOTICE_CACHE_WINDOW, null, null, $order, null); - function blowInboxes() { + # If there are no hits, just return the value - $enabled = common_config('inboxes', 'enabled'); + if (!$notice) { + return $notice; + } - if ($enabled === true || $enabled === 'transitional') { - $inbox = new Notice_inbox(); - $inbox->notice_id = $this->id; - $inbox->delete(); - } + # Pack results into an array - return; - } + $notices = array(); -} + while ($notice->fetch()) { + $notices[] = clone($notice); + } + + $notice->free(); + + # Store the array in the cache for next time + + $result = $cache->set(common_cache_key($cachekey), $notices); + $result = $cache->set(common_cache_key($cachekey) . ';last', $notices); + + # return a wrapper of the array for use now + + $wrapper = new ArrayWrapper(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; + } + + function saveGroups() + { + $enabled = common_config('inboxes', 'enabled'); + if ($enabled !== true && $enabled !== 'transitional') { + return; + } + + /* extract all !group */ + $count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/', + strtolower($this->content), + $match); + if (!$count) { + return true; + } + + $profile = $this->getProfile(); + /* Add them to the database */ + + foreach (array_unique($match[1]) as $nickname) { + /* XXX: remote groups. */ + $group = User_group::staticGet('nickname', $nickname); + + if (!$group) { + continue; + } + + if ($profile->isMember($group)) { + + $gi = new Group_inbox(); + + $gi->group_id = $group->id; + $gi->notice_id = $this->id; + $gi->created = common_sql_now(); + + $result = $gi->insert(); + + if (!$result) { + common_log_db_error($gi, 'INSERT', __FILE__); + } + + // FIXME: do this in an offline daemon + + $inbox = new Notice_inbox(); + $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . + 'SELECT user.id, ' . $this->id . ', "' . $this->created . '", 2 ' . + 'FROM user JOIN group_member ON user.id = group_member.profile_id ' . + 'WHERE group_member.group_id = ' . $group->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'; + } + $result = $inbox->query($qry); + } + } + } + + function saveReplies() + { + // Alternative reply format + $tname = false; + if (preg_match('/^T ([A-Z0-9]{1,64}) /', $this->content, $match)) { + $tname = $match[1]; + } + // extract all @messages + $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $this->content, $match); + + $names = array(); + + if ($cnt || $tname) { + // XXX: is there another way to make an array copy? + $names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]); + } + + $sender = Profile::staticGet($this->profile_id); + + $replied = array(); + + // store replied only for first @ (what user/notice what the reply directed, + // we assume first @ is it) + + for ($i=0; $i<count($names); $i++) { + $nickname = $names[$i]; + $recipient = common_relative_profile($sender, $nickname, $this->created); + if (!$recipient) { + continue; + } + if ($i == 0 && ($recipient->id != $sender->id) && !$this->reply_to) { // Don't save reply to self + $reply_for = $recipient; + $recipient_notice = $reply_for->getCurrentNotice(); + if ($recipient_notice) { + $orig = clone($this); + $this->reply_to = $recipient_notice->id; + $this->update($orig); + } + } + // Don't save replies from blocked profile to local user + $recipient_user = User::staticGet('id', $recipient->id); + if ($recipient_user && $recipient_user->hasBlocked($sender)) { + continue; + } + $reply = new Reply(); + $reply->notice_id = $this->id; + $reply->profile_id = $recipient->id; + $id = $reply->insert(); + if (!$id) { + $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); + common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message); + common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message)); + return; + } else { + $replied[$recipient->id] = 1; + } + } + + // Hash format replies, too + $cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $this->content, $match); + if ($cnt) { + foreach ($match[1] as $tag) { + $tagged = Profile_tag::getTagged($sender->id, $tag); + foreach ($tagged as $t) { + if (!$replied[$t->id]) { + // Don't save replies from blocked profile to local user + $t_user = User::staticGet('id', $t->id); + if ($t_user && $t_user->hasBlocked($sender)) { + continue; + } + $reply = new Reply(); + $reply->notice_id = $this->id; + $reply->profile_id = $t->id; + $id = $reply->insert(); + if (!$id) { + common_log_db_error($reply, 'INSERT', __FILE__); + return; + } + } + } + } + } + } +} diff --git a/classes/NoticeWrapper.php b/classes/NoticeWrapper.php deleted file mode 100644 index f8c0aa381..000000000 --- a/classes/NoticeWrapper.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/classes/Notice.php'); - -class NoticeWrapper extends Notice { - - 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) - - 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/classes/Notice_inbox.php b/classes/Notice_inbox.php index cc482bd19..81ddb4538 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -33,7 +33,8 @@ class Notice_inbox extends Memcached_DataObject public $source; // tinyint(1) default_1 /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice_inbox',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Notice_inbox',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Notice_source.php b/classes/Notice_source.php index e0a41b927..e7568bbca 100644 --- a/classes/Notice_source.php +++ b/classes/Notice_source.php @@ -17,7 +17,8 @@ class Notice_source extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice_source',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Notice_source',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Notice_tag.php b/classes/Notice_tag.php index 5b75ff13f..94f9296d6 100644 --- a/classes/Notice_tag.php +++ b/classes/Notice_tag.php @@ -30,26 +30,28 @@ class Notice_tag extends Memcached_DataObject public $created; // datetime() not_null /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Notice_tag',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Notice_tag',$k,$v); } /* 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/classes/Profile.php b/classes/Profile.php index b57d7e38d..ab5a48e57 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -41,119 +41,180 @@ class Profile extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Profile',$k,$v); } /* 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 crop_avatars($x, $y, $w, $h) + { + + $avatar = $this->getOriginalAvatar(); + $this->delete_avatars(false); # don't delete original + + 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_and_crop($size, $x, $y, $w, $h); + if (!$s) { + return NULL; + } + } + } + return true; + } + + function delete_avatars($original=true) + { + $avatar = new Avatar(); + $avatar->profile_id = $this->id; + $avatar->find(); + while ($avatar->fetch()) { + if ($avatar->original) { + if ($original == false) { + continue; + } + } + $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); + } + + function isMember($group) + { + $mem = new Group_member(); + + $mem->group_id = $group->id; + $mem->profile_id = $this->id; + + if ($mem->find()) { + return true; + } else { + return false; + } + } + + function isAdmin($group) + { + $mem = new Group_member(); + + $mem->group_id = $group->id; + $mem->profile_id = $this->id; + $mem->is_admin = 1; + + if ($mem->find()) { + return true; + } else { + return false; + } + } + } diff --git a/classes/Profile_block.php b/classes/Profile_block.php index 6ea26a3bc..551e690e2 100644 --- a/classes/Profile_block.php +++ b/classes/Profile_block.php @@ -36,12 +36,14 @@ class Profile_block extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile_block',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Profile_block',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function get($blocker, $blocked) { + function get($blocker, $blocked) + { return Memcached_DataObject::pkeyGet('Profile_block', array('blocker' => $blocker, 'blocked' => $blocked)); diff --git a/classes/Profile_tag.php b/classes/Profile_tag.php index dde19aea2..cb60cbaec 100644 --- a/classes/Profile_tag.php +++ b/classes/Profile_tag.php @@ -16,86 +16,87 @@ class Profile_tag extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile_tag',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Profile_tag',$k,$v); } /* 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/classes/Queue_item.php b/classes/Queue_item.php index 8ba3281de..9b909ec22 100644 --- a/classes/Queue_item.php +++ b/classes/Queue_item.php @@ -16,40 +16,42 @@ class Queue_item extends Memcached_DataObject public $claimed; // datetime() /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Queue_item',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Queue_item',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###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; - } + 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; + } } diff --git a/classes/Related_group.php b/classes/Related_group.php new file mode 100755 index 000000000..c00ad9c44 --- /dev/null +++ b/classes/Related_group.php @@ -0,0 +1,21 @@ +<?php +/** + * Table Definition for related_group + */ + +class Related_group extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'related_group'; // table name + public $group_id; // int(4) primary_key not_null + public $related_group_id; // int(4) primary_key not_null + public $created; // datetime() not_null + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Related_group',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE +} diff --git a/classes/Remember_me.php b/classes/Remember_me.php index 5bbd6cf17..8dc29bfa3 100644 --- a/classes/Remember_me.php +++ b/classes/Remember_me.php @@ -15,10 +15,12 @@ class Remember_me extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Remember_me',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Remember_me',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function sequenceKey() { return array(false, false); } + function sequenceKey() + { return array(false, false); } } diff --git a/classes/Remote_profile.php b/classes/Remote_profile.php index c961dcca2..5aa6d913e 100644 --- a/classes/Remote_profile.php +++ b/classes/Remote_profile.php @@ -38,7 +38,8 @@ class Remote_profile extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Remote_profile',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Remote_profile',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Reply.php b/classes/Reply.php index d71ce3afb..af86aaf87 100644 --- a/classes/Reply.php +++ b/classes/Reply.php @@ -16,7 +16,8 @@ class Reply extends Memcached_DataObject public $replied_id; // int(4) /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Reply',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Reply',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/Sms_carrier.php b/classes/Sms_carrier.php index 6ecb51346..ffa12de29 100644 --- a/classes/Sms_carrier.php +++ b/classes/Sms_carrier.php @@ -17,12 +17,14 @@ class Sms_carrier extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Sms_carrier',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Sms_carrier',$k,$v); } /* 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/classes/Subscription.php b/classes/Subscription.php index cc174fcce..3fe0d167f 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -40,12 +40,14 @@ class Subscription extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Subscription',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Subscription',$k,$v); } /* 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/classes/Token.php b/classes/Token.php index d180ecebe..1fabd72f1 100644 --- a/classes/Token.php +++ b/classes/Token.php @@ -19,7 +19,8 @@ class Token extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Token',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('Token',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/User.php b/classes/User.php index 5dab5c701..b1bae8835 100644 --- a/classes/User.php +++ b/classes/User.php @@ -62,89 +62,98 @@ class User extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('User',$k,$v); } /* 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 hasBlocked($other) { + 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', 'group', 'groups'); + $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) + { $block = Profile_block::get($this->id, $other->id); @@ -158,260 +167,273 @@ class User extends Memcached_DataObject return $result; } - static function register($fields) { + static function register($fields) { - # MAGICALLY put fields into current scope + # MAGICALLY put fields into current scope - extract($fields); + extract($fields); - $profile = new Profile(); + $profile = new Profile(); - $profile->query('BEGIN'); + $profile->query('BEGIN'); - $profile->nickname = $nickname; - $profile->profileurl = common_profile_url($nickname); + $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; - } + 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(); + $profile->created = common_sql_now(); - $id = $profile->insert(); + $id = $profile->insert(); - if (!$id) { - common_log_db_error($profile, 'INSERT', __FILE__); - return FALSE; - } + if (!$id) { + common_log_db_error($profile, 'INSERT', __FILE__); + return false; + } - $user = new User(); + $user = new User(); - $user->id = $id; - $user->nickname = $nickname; + $user->id = $id; + $user->nickname = $nickname; + + 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'); + + 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; + } - if ($password) { # may not have a password for OpenID users - $user->password = common_munge_password($password, $id); - } + # Things we do when the email changes - # Users who respond to invite email have proven their ownership of that address + function emailChanged() + { - 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 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); - } - - function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=NULL) { + $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 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); + } + + function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) + { $profile = $this->getProfile(); if (!$profile) { - return NULL; + return null; } 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); - } - - 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 '; - $order = null; - } - 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'); - } - } - - function getSelfTags() { - return Profile_tag::getTags($this->id, $this->id); - } - - function setSelfTags($newtags) { - return Profile_tag::setTags($this->id, $this->id, $newtags); - } - - function block($other) { + } + + 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); + } + + 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 = null; + } + 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'); + } + } + + function getSelfTags() + { + return Profile_tag::getTags($this->id, $this->id); + } + + function setSelfTags($newtags) + { + return Profile_tag::setTags($this->id, $this->id, $newtags); + } + + function block($other) + { # Add a new block record @@ -433,8 +455,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(); @@ -449,7 +471,8 @@ class User extends Memcached_DataObject return true; } - function unblock($other) { + function unblock($other) + { # Get the block record @@ -469,4 +492,141 @@ class User extends Memcached_DataObject return true; } + function isMember($group) + { + $profile = $this->getProfile(); + return $profile->isMember($group); + } + + function isAdmin($group) + { + $profile = $this->getProfile(); + return $profile->isAdmin($group); + } + + function getGroups($offset=0, $limit=null) + { + $qry = + 'SELECT user_group.* ' . + 'FROM user_group JOIN group_member '. + 'ON user_group.id = group_member.group_id ' . + 'WHERE group_member.profile_id = %d ' . + 'ORDER BY group_member.created DESC '; + + if ($offset) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $groups = new User_group(); + + $cnt = $groups->query(sprintf($qry, $this->id)); + + return $groups; + } + + function getSubscriptions($offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscribed ' . + 'WHERE subscription.subscriber = %d ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile = new Profile(); + + $profile->query(sprintf($qry, $this->id)); + + return $profile; + } + + function getSubscribers($offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscriber ' . + 'WHERE subscription.subscribed = %d ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if ($offset) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $profile = new Profile(); + + $cnt = $profile->query(sprintf($qry, $this->id)); + + return $profile; + } + + function getTaggedSubscribers($tag, $offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscriber ' . + 'JOIN profile_tag ON (profile_tag.tagged = subscription.subscriber ' . + 'AND profile_tag.tagger = subscription.subscribed) ' . + 'WHERE subscription.subscribed = %d ' . + 'AND profile_tag.tag = "%s" ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if ($offset) { + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + } + + $profile = new Profile(); + + $cnt = $profile->query(sprintf($qry, $this->id, $tag)); + + return $profile; + } + + function getTaggedSubscriptions($tag, $offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN subscription ' . + 'ON profile.id = subscription.subscribed ' . + 'JOIN profile_tag on (profile_tag.tagged = subscription.subscribed ' . + 'AND profile_tag.tagger = subscription.subscriber) ' . + 'WHERE subscription.subscriber = %d ' . + 'AND profile_tag.tag = "%s" ' . + 'AND subscription.subscribed != subscription.subscriber ' . + 'ORDER BY subscription.created DESC '; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile = new Profile(); + + $profile->query(sprintf($qry, $this->id, $tag)); + + return $profile; + } } diff --git a/classes/User_group.php b/classes/User_group.php new file mode 100755 index 000000000..98ad77cc0 --- /dev/null +++ b/classes/User_group.php @@ -0,0 +1,167 @@ +<?php +/** + * Table Definition for user_group + */ + +class User_group extends Memcached_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'user_group'; // table name + public $id; // int(4) primary_key not_null + public $nickname; // varchar(64) unique_key + public $fullname; // varchar(255) + public $homepage; // varchar(255) + public $description; // varchar(140) + public $location; // varchar(255) + public $original_logo; // varchar(255) + public $homepage_logo; // varchar(255) + public $stream_logo; // varchar(255) + public $mini_logo; // varchar(255) + public $created; // datetime() not_null + public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP + + /* Static get */ + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_group',$k,$v); } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + function defaultLogo($size) + { + static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile', + AVATAR_STREAM_SIZE => 'stream', + AVATAR_MINI_SIZE => 'mini'); + return theme_path('default-avatar-'.$sizenames[$size].'.png'); + } + + function homeUrl() + { + return common_local_url('showgroup', + array('nickname' => $this->nickname)); + } + + function permalink() + { + return common_local_url('groupbyid', + array('id' => $this->id)); + } + + function getNotices($offset, $limit) + { + $qry = + 'SELECT notice.* ' . + 'FROM notice JOIN group_inbox ON notice.id = group_inbox.notice_id ' . + 'WHERE group_inbox.group_id = %d '; + return Notice::getStream(sprintf($qry, $this->id), + 'group:notices:'.$this->id, + $offset, $limit); + } + + function allowedNickname($nickname) + { + static $blacklist = array('new'); + return !in_array($nickname, $blacklist); + } + + function getMembers($offset=0, $limit=null) + { + $qry = + 'SELECT profile.* ' . + 'FROM profile JOIN group_member '. + 'ON profile.id = group_member.profile_id ' . + 'WHERE group_member.group_id = %d ' . + 'ORDER BY group_member.created DESC '; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $members = new Profile(); + + $cnt = $members->query(sprintf($qry, $this->id)); + + return $members; + } + + function setOriginal($filename, $type) + { + $orig = clone($this); + $this->original_logo = common_avatar_url($filename); + $this->homepage_logo = common_avatar_url($this->scale($filename, + AVATAR_PROFILE_SIZE, + $type)); + $this->stream_logo = common_avatar_url($this->scale($filename, + AVATAR_STREAM_SIZE, + $type)); + $this->mini_logo = common_avatar_url($this->scale($filename, + AVATAR_MINI_SIZE, + $type)); + common_debug(common_log_objstring($this)); + return $this->update($orig); + } + + function scale($filename, $size, $type) + { + $filepath = common_avatar_path($filename); + + if (!file_exists($filepath)) { + $this->serverError(_('Lost our file.')); + return; + } + + $info = @getimagesize($filepath); + + switch ($type) { + case IMAGETYPE_GIF: + $image_src = imagecreatefromgif($filepath); + break; + case IMAGETYPE_JPEG: + $image_src = imagecreatefromjpeg($filepath); + break; + case IMAGETYPE_PNG: + $image_src = imagecreatefrompng($filepath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + $image_dest = imagecreatetruecolor($size, $size); + + $background = imagecolorallocate($image_dest, 0, 0, 0); + ImageColorTransparent($image_dest, $background); + imagealphablending($image_dest, false); + + imagecopyresized($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $info[0], $info[1]); + + $cur = common_current_user(); + + $outname = common_avatar_filename($cur->id, + image_type_to_extension($type), + null, + common_timestamp()); + + $outpath = common_avatar_path($outname); + + switch ($type) { + case IMAGETYPE_GIF: + imagegif($image_dest, $outpath); + break; + case IMAGETYPE_JPEG: + imagejpeg($image_dest, $outpath); + break; + case IMAGETYPE_PNG: + imagepng($image_dest, $outpath); + break; + default: + $this->serverError(_('Unknown file type')); + return; + } + + return $outname; + } +} diff --git a/classes/User_openid.php b/classes/User_openid.php index ad68f7402..f4fda1c72 100644 --- a/classes/User_openid.php +++ b/classes/User_openid.php @@ -17,7 +17,8 @@ class User_openid extends Memcached_DataObject public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP /* Static get */ - function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_openid',$k,$v); } + function staticGet($k,$v=null) + { return Memcached_DataObject::staticGet('User_openid',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE diff --git a/classes/laconica.ini b/classes/laconica.ini index db76b2dee..255122a97 100644..100755 --- a/classes/laconica.ini +++ b/classes/laconica.ini @@ -98,6 +98,26 @@ id = K service = K uri = U +[group_inbox] +group_id = 129 +notice_id = 129 +created = 142 + +[group_inbox__keys] +group_id = K +notice_id = K + +[group_member] +group_id = 129 +profile_id = 129 +is_admin = 17 +created = 142 +modified = 384 + +[group_member__keys] +group_id = K +profile_id = K + [invitation] code = 130 user_id = 129 @@ -225,6 +245,15 @@ claimed = 14 notice_id = K transport = K +[related_group] +group_id = 129 +related_group_id = 129 +created = 142 + +[related_group__keys] +group_id = K +related_group_id = K + [remember_me] code = 130 user_id = 129 @@ -332,6 +361,23 @@ jabber = U sms = U uri = U +[user_group] +id = 129 +nickname = 2 +fullname = 2 +homepage = 2 +description = 2 +location = 2 +original_logo = 2 +homepage_logo = 2 +stream_logo = 2 +mini_logo = 2 +created = 142 +modified = 384 + +[user_group__keys] +id = N + [user_openid] canonical = 130 display = 130 diff --git a/db/laconica.sql b/db/laconica.sql index a366a6bcb..012270b51 100644 --- a/db/laconica.sql +++ b/db/laconica.sql @@ -368,3 +368,60 @@ create table profile_block ( constraint primary key (blocker, blocked) ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + +create table user_group ( + + id integer auto_increment primary key comment 'unique identifier', + + nickname varchar(64) unique key comment 'nickname for addressing', + fullname varchar(255) comment 'display name', + homepage varchar(255) comment 'URL, cached so we dont regenerate', + description varchar(140) comment 'descriptive biography', + location varchar(255) comment 'related physical location, if any', + + original_logo varchar(255) comment 'original size logo', + homepage_logo varchar(255) comment 'homepage (profile) size logo', + stream_logo varchar(255) comment 'stream-sized logo', + mini_logo varchar(255) comment 'mini logo', + + created datetime not null comment 'date this record was created', + modified timestamp comment 'date this record was modified', + + index user_group_nickname_idx (nickname) + +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + +create table group_member ( + + group_id integer not null comment 'foreign key to user_group' references user_group (id), + profile_id integer not null comment 'foreign key to profile table' references profile (id), + is_admin boolean default false comment 'is this user an admin?', + + created datetime not null comment 'date this record was created', + modified timestamp comment 'date this record was modified', + + constraint primary key (group_id, profile_id) + +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + +create table related_group ( + + group_id integer not null comment 'foreign key to user_group' references user_group (id), + related_group_id integer not null comment 'foreign key to user_group' references user_group (id), + + created datetime not null comment 'date this record was created', + + constraint primary key (group_id, related_group_id) + +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + +create table group_inbox ( + group_id integer not null comment 'group receiving the message' references user_group (id), + notice_id integer not null comment 'notice received' references notice (id), + created datetime not null comment 'date the notice was created', + + constraint primary key (group_id, notice_id), + index group_inbox_created_idx (created) + +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin; + @@ -12,7 +12,7 @@ and fans. How is %%site.name%% different from Twitter, Jaiku, Pownce, Plurk, others? -------------------------------------------------------------------------- -%%site.name%% is an [Open Network Service](http://opendefinition.org/osd). Our main +%%site.name%% is an [Open Network Service](http://opendefinition.org/ossd). Our main goal is to provide a fair and transparent service that preserves users' autonomy. In particular, all the software used for %%site.name%% is [Free Software](http://en.wikipedia.org/wiki/Free_Software), and all the data is available under the [%%license.title%%](%%license.url%%) license, making it Open Data. diff --git a/doc/groups b/doc/groups new file mode 100644 index 000000000..645390e0c --- /dev/null +++ b/doc/groups @@ -0,0 +1,42 @@ +Users on %%site.name%% can create *groups* that other users can join. +Groups can be a great way to share information and entertainment with +a group of people who have a common interest or background. + +You can find out about groups on the server on the +[Groups](%%action.groups%%) page. You can join a group by clicking on +the "Join" button either in the group list or on the group's home page. + +Starting a new group +-------------------- + +If you want, you can start a new group for friends and people with +common interests. Note that all groups are free for anyone to join. + +To start a new group, use the [new group](%%action.newgroup%%) tool +and fill out the form. Describe your group as best you can if you want +people to be able to find it. + +When choosing the nickname for your group, try to keep it short. The +nickname is included in every message to and from the group, so the +less chars the better. Try using acronyms for organizations, or +airport codes for places (like 'pdx' instead of 'portland'). + +Sending messages to a group +--------------------------- + +You can send a message to a group using the syntax "!groupname" +anywhere in the message. If you have more than one group named, the +notice will go to each group. Only members can send notices to a +group, and groups do not respond to direct messages (DMs). + +Receiving messages +------------------ + +New group messages will appear in your inbox, and will also come to +your phone or IM client if you've set them up to receive notices. + +Remote groups +------------- + +While it's technically possible, this version of Laconica does not +support remote group membership. @@ -23,6 +23,9 @@ Here are some documents that you might find helpful in understanding * [FAQ](%%doc.faq%%) - frequently-asked questions about %%site.name%% * [Contact](%%doc.contact%%) - who to contact with questions about the service * [IM](%%doc.im%%) - using the instant-message (IM) features of %%site.name%% +* [SMS](%%doc.sms%%) - tying your cellphone to %%site.name%% +* [tags](%%doc.tags%%) - different ways to use tagging +* [Groups](%%doc.groups%%) - joining together in groups * [OpenID](%%doc.openid%%) - what OpenID is and how to use it with this service * [OpenMicroBlogging](%%doc.openmublog%%) - subscribing to remote users * [Privacy](%%doc.privacy%%) - %%site.name%%'s privacy policy diff --git a/doc/sms b/doc/sms new file mode 100644 index 000000000..1beb49786 --- /dev/null +++ b/doc/sms @@ -0,0 +1,68 @@ +You can post messages to %%site.name%% using a many kinds of cell +phones that support SMS messaging. This site does not support SMS +directly; rather, it uses your carrier's email gateway to send and +receive messages. + +Managing your SMS settings +-------------------------- + +Use the [SMS settings](%%action.smssettings%%) page to set your SMS +preferences. You can add or change your SMS number and set the +flags for SMS updates. + +When you add or change your phone number, you'll receive a message on your +phone with a verification code. Enter it into the SMS settings page to +confirm that the owner of the phone authorizes sending it messages. + +Note that only the carriers listed in the drop down list on the form +are supported by %%site.name%%. They're the only ones we know how to +make email addresses for. + +Receiving messages +------------------ + +Once you've verified your phone number, you can enable sending +messages to your phone. If you have a lot of friends and a typical +phone, it can be hard to keep up. + +Sending messages +---------------- + +To send a message, you must send an email to the incoming email +address visible on your SMS settings page. The method for sending +email from your phone varies from carrier to carrier and from handset +to handet; if in doubt, ask your carrier. + +Keep your incoming email address a secret -- it's the only way we know +you're really you! + +Commands +-------- + +You can use the following commands with %%site.name%%. + +* on - turn on notifications +* off - turn off notifications +* help - show this help +* follow <nickname> - subscribe to user +* leave <nickname> - unsubscribe from user +* d <nickname> <text> - direct message to user +* get <nickname> - get last notice from user +* whois <nickname> - get profile info on user +* fav <nickname> - add user's last notice as a 'fave' +* stats - get your stats +* stop - same as 'off' +* quit - same as 'off' +* sub <nickname> - same as 'follow' +* unsub <nickname> - same as 'leave' +* last <nickname> - same as 'get' +* on <nickname> - not yet implemented. +* off <nickname> - not yet implemented. +* nudge <nickname> - not yet implemented. +* invite <phone number> - not yet implemented. +* track <word> - not yet implemented. +* untrack <word> - not yet implemented. +* track off - not yet implemented. +* untrack all - not yet implemented. +* tracks - not yet implemented. +* tracking - not yet implemented. diff --git a/doc/tags b/doc/tags new file mode 100644 index 000000000..2ed352e70 --- /dev/null +++ b/doc/tags @@ -0,0 +1,40 @@ +%%site.name%% supports +[tags](http://en.wikipedia.org/wiki/Tag_(metadata)) to help you +organize your activities here. You can use tags for people and for +notices. + +Tagging a notice +---------------- + +You can tag a notice using a *hashtag*; a # character followed by +letters and numbers as well as '.', '-', and '_'. Note that accented +latin characters are not supported, and non-roman scripts are right out. + +The HTML for the notice will link to a stream of all the other notices +with that tag. This can be a great way to keep track of a conversation. + +The most popular current tags on the site can be found in the [public +tag cloud](%%action.publictagcloud%%). Their size shows their +popularity and recency. + +Tagging yourself +---------------- + +You can also add tags for yourself on your [profile +settings](%%action.profilesettings%%) page. Use single words to +describe yourself, your experiences and your interest. The tags will +become links on your profile page to a list of all the users on the +site who use that same tag. It can be a nice way to find people who +are related to you geographically or who have a common interest. + +Tagging your subscriptions +-------------------------- + +You can also tag your subscriptions, on the subscriptions page. This +makes it easy to organize your subscriptions into groups and sort +through them separately. + +You can also send a notice "to the attention of" everyone you've +marked with a particular tag (note: *not* people who've marked +themselves with that tag). "@#family hello" will send a notice to +everyone you've marked with the tag 'family'.
\ No newline at end of file diff --git a/favicon.ico b/favicon.ico Binary files differnew file mode 100644 index 000000000..74ff52bd6 --- /dev/null +++ b/favicon.ico diff --git a/file/.gitignore b/file/.gitignore new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/file/.gitignore diff --git a/htaccess.sample b/htaccess.sample index bd29d318f..73b52c55e 100644 --- a/htaccess.sample +++ b/htaccess.sample @@ -21,6 +21,9 @@ RewriteRule ^doc/openid$ index.php?action=doc&title=openid [L,QSA] RewriteRule ^doc/openmublog$ index.php?action=doc&title=openmublog [L,QSA] RewriteRule ^doc/privacy$ index.php?action=doc&title=privacy [L,QSA] RewriteRule ^doc/source$ index.php?action=doc&title=source [L,QSA] +RewriteRule ^doc/tags$ index.php?action=doc&title=tags [L,QSA] +RewriteRule ^doc/groups$ index.php?action=doc&title=groups [L,QSA] +RewriteRule ^doc/sms$ index.php?action=doc&title=sms [L,QSA] RewriteRule ^facebook/$ index.php?action=facebookhome [L,QSA] RewriteRule ^facebook/index.php$ index.php?action=facebookhome [L,QSA] @@ -52,8 +55,9 @@ RewriteRule ^main/tagother$ index.php?action=tagother [L,QSA] RewriteRule ^main/block$ index.php?action=block [L,QSA] -RewriteRule ^settings/delete$ index.php?action=deleteprofile [L,QSA] RewriteRule ^settings/profile$ index.php?action=profilesettings [L,QSA] +RewriteRule ^settings/avatar$ index.php?action=avatarsettings [L,QSA] +RewriteRule ^settings/password$ index.php?action=passwordsettings [L,QSA] RewriteRule ^settings/openid$ index.php?action=openidsettings [L,QSA] RewriteRule ^settings/im$ index.php?action=imsettings [L,QSA] RewriteRule ^settings/email$ index.php?action=emailsettings [L,QSA] @@ -75,7 +79,7 @@ RewriteRule ^message/(\d+)$ index.php?action=showmessage&message=$1 [L,QSA] RewriteRule ^user/(\d+)$ index.php?action=userbyid&id=$1 [L,QSA] -RewriteRule ^tags/?$ index.php?action=tag [L,QSA] +RewriteRule ^tags/?$ index.php?action=publictagcloud [L,QSA] RewriteRule ^tag/([a-zA-Z0-9]+)/rss$ index.php?action=tagrss&tag=$1 [L,QSA] RewriteRule ^tag(/(.*))?$ index.php?action=tag&tag=$2 [L,QSA] @@ -84,26 +88,16 @@ RewriteRule ^peopletag/([a-zA-Z0-9]+)$ index.php?action=peopletag&tag=$1 [L,QSA] RewriteRule ^featured/?$ index.php?action=featured [L,QSA] RewriteRule ^favorited/?$ index.php?action=favorited [L,QSA] -RewriteRule ^(\w+)/subscriptions$ index.php?action=subscriptions&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/subscriptions/([a-zA-Z0-9]+)$ index.php?action=subscriptions&nickname=$1&tag=$2 [L,QSA] -RewriteRule ^(\w+)/subscribers/([a-zA-Z0-9]+)$ index.php?action=subscribers&nickname=$1&tag=$2 [L,QSA] -RewriteRule ^(\w+)/subscribers$ index.php?action=subscribers&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/nudge$ index.php?action=nudge&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/xrds$ index.php?action=xrds&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/rss$ index.php?action=userrss&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/all$ index.php?action=all&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/all/rss$ index.php?action=allrss&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/foaf$ index.php?action=foaf&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/replies$ index.php?action=replies&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/replies/rss$ index.php?action=repliesrss&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/avatar/(original|96|48|24)$ index.php?action=avatarbynickname&nickname=$1&size=$2 [L,QSA] -RewriteRule ^(\w+)/favorites$ index.php?action=showfavorites&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/favorites/rss$ index.php?action=favoritesrss&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/inbox$ index.php?action=inbox&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/outbox$ index.php?action=outbox&nickname=$1 [L,QSA] -RewriteRule ^(\w+)/microsummary$ index.php?action=microsummary&nickname=$1 [L,QSA] - -RewriteRule ^(\w+)$ index.php?action=showstream&nickname=$1 [L,QSA] +RewriteRule ^group/new$ index.php?action=newgroup [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/edit$ index.php?action=editgroup&nickname=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/join$ index.php?action=joingroup&nickname=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/leave$ index.php?action=leavegroup&nickname=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/members$ index.php?action=groupmembers&nickname=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/logo$ index.php?action=grouplogo&nickname=$1 [L,QSA] +RewriteRule ^group/([0-9]+)/id$ index.php?action=groupbyid&id=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)/rss$ index.php?action=grouprss&nickname=$1 [L,QSA] +RewriteRule ^group/([a-zA-Z0-9]+)$ index.php?action=showgroup&nickname=$1 [L,QSA] +RewriteRule ^group$ index.php?action=groups [L,QSA] # Twitter-compatible API rewrites # XXX: Surely these can be refactored a little -- Zach @@ -143,6 +137,31 @@ RewriteRule ^api/notifications/leave/(.*)$ index.php?action=api&apiaction=notifi RewriteRule ^api/blocks/create/(.*)$ index.php?action=api&apiaction=blocks&method=create&argument=$1 [L,QSA] RewriteRule ^api/blocks/destroy/(.*)$ index.php?action=api&apiaction=blocks&method=destroy&argument=$1 [L,QSA] RewriteRule ^api/help/(.*)$ index.php?action=api&apiaction=help&method=$1 [L,QSA] +RewriteRule ^api/laconica/version(.*)$ index.php?action=api&apiaction=laconica&method=version$1 [L,QSA] +RewriteRule ^api/laconica/config(.*)$ index.php?action=api&apiaction=laconica&method=config$1 [L,QSA] +RewriteRule ^api/laconica/wadl\.xml$ index.php?action=api&apiaction=laconica&method=wadl.xml [L,QSA] + +RewriteRule ^(\w+)/subscriptions$ index.php?action=subscriptions&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/subscriptions/([a-zA-Z0-9]+)$ index.php?action=subscriptions&nickname=$1&tag=$2 [L,QSA] +RewriteRule ^(\w+)/subscribers/([a-zA-Z0-9]+)$ index.php?action=subscribers&nickname=$1&tag=$2 [L,QSA] +RewriteRule ^(\w+)/subscribers$ index.php?action=subscribers&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/nudge$ index.php?action=nudge&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/xrds$ index.php?action=xrds&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/rss$ index.php?action=userrss&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/all$ index.php?action=all&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/all/rss$ index.php?action=allrss&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/foaf$ index.php?action=foaf&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/replies$ index.php?action=replies&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/replies/rss$ index.php?action=repliesrss&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/avatar/(original|96|48|24)$ index.php?action=avatarbynickname&nickname=$1&size=$2 [L,QSA] +RewriteRule ^(\w+)/favorites$ index.php?action=showfavorites&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/favorites/rss$ index.php?action=favoritesrss&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/inbox$ index.php?action=inbox&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/outbox$ index.php?action=outbox&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/microsummary$ index.php?action=microsummary&nickname=$1 [L,QSA] +RewriteRule ^(\w+)/groups$ index.php?action=usergroups&nickname=$1 [L,QSA] + +RewriteRule ^(\w+)$ index.php?action=showstream&nickname=$1 [L,QSA] <FilesMatch "\.(ini)"> Order allow,deny @@ -1,5 +1,5 @@ <?php -/* +/** * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -20,13 +20,13 @@ define('INSTALLDIR', dirname(__FILE__)); define('LACONICA', true); -require_once(INSTALLDIR . "/lib/common.php"); +require_once INSTALLDIR . '/lib/common.php'; -# get and cache current user +// get and cache current user $user = common_current_user(); -# initialize language env +// initialize language env common_init_language(); @@ -41,30 +41,34 @@ if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) { if (!$user && common_config('site', 'private') && !in_array($action, array('login', 'openidlogin', 'finishopenidlogin', - 'recoverpassword', 'api', 'doc', 'register'))) -{ + 'recoverpassword', 'api', 'doc', 'register'))) { common_redirect(common_local_url('login')); } $actionfile = INSTALLDIR."/actions/$action.php"; if (file_exists($actionfile)) { - require_once($actionfile); - $action_class = ucfirst($action)."Action"; + + include_once $actionfile; + + $action_class = ucfirst($action).'Action'; + $action_obj = new $action_class(); - if ($config['db']['mirror'] && $action_obj->is_readonly()) { - if (is_array($config['db']['mirror'])) { - # "load balancing", ha ha - $k = array_rand($config['db']['mirror']); - $mirror = $config['db']['mirror'][$k]; - } else { - $mirror = $config['db']['mirror']; - } - $config['db']['database'] = $mirror; - } + + if ($config['db']['mirror'] && $action_obj->isReadOnly()) { + if (is_array($config['db']['mirror'])) { + // "load balancing", ha ha + $k = array_rand($config['db']['mirror']); + + $mirror = $config['db']['mirror'][$k]; + } else { + $mirror = $config['db']['mirror']; + } + $config['db']['database'] = $mirror; + } if (call_user_func(array($action_obj, 'prepare'), $_REQUEST)) { - call_user_func(array($action_obj, 'handle'), $_REQUEST); - } + call_user_func(array($action_obj, 'handle'), $_REQUEST); + } } else { common_user_error(_('Unknown action')); }
\ No newline at end of file diff --git a/js/facebookapp.js b/js/facebookapp.js new file mode 100644 index 000000000..c7e8d6aa2 --- /dev/null +++ b/js/facebookapp.js @@ -0,0 +1,18 @@ +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +
\ No newline at end of file diff --git a/js/identica-badge.js b/js/identica-badge.js new file mode 100644 index 000000000..5c586b5d6 --- /dev/null +++ b/js/identica-badge.js @@ -0,0 +1,293 @@ +// identica badge -- updated to work with the native API, 12-4-2008 +// copyright Kent Brewster 2008 +// see http://kentbrewster.com/identica-badge for info +( function() { + var trueName = ''; + for (var i = 0; i < 16; i++) { + trueName += String.fromCharCode(Math.floor(Math.random() * 26) + 97); + } + window[trueName] = {}; + var $ = window[trueName]; + $.f = function() { + return { + runFunction : [], + init : function(target) { + var theScripts = document.getElementsByTagName('SCRIPT'); + for (var i = 0; i < theScripts.length; i++) { + if (theScripts[i].src.match(target)) { + $.a = {}; + if (theScripts[i].innerHTML) { + $.a = $.f.parseJson(theScripts[i].innerHTML); + } + if ($.a.err) { + alert('bad json!'); + } + $.f.loadDefaults(); + $.f.buildStructure(); + $.f.buildPresentation(); + theScripts[i].parentNode.insertBefore($.s, theScripts[i]); + theScripts[i].parentNode.removeChild(theScripts[i]); + break; + } + } + }, + parseJson : function(json) { + this.parseJson.data = json; + if ( typeof json !== 'string') { + return {"err":"trying to parse a non-string JSON object"}; + } + try { + var f = Function(['var document,top,self,window,parent,Number,Date,Object,Function,', + 'Array,String,Math,RegExp,Image,ActiveXObject;', + 'return (' , json.replace(/<\!--.+-->/gim,'').replace(/\bfunction\b/g,'function­') , ');'].join('')); + return f(); + } catch (e) { + return {"err":"trouble parsing JSON object"}; + } + }, + loadDefaults : function() { + $.d = { + "user":"7000", + "headerText" : "", + "height" : 350, + "width" : 300, + "background" : "#193441", + "border" : "1px solid black", + "userFontSize" : "inherit", + "userColor" : "inherit", + "headerBackground" : "transparent", + "headerColor" : "white", + "evenBackground" : "#fff", + "oddBackground" : "#eee", + "thumbnailBorder" : "1px solid black", + "thumbnailSize" : 24, + "padding" : 3, + "server" : "identi.ca" + }; + for (var k in $.d) { if ($.a[k] === undefined) { $.a[k] = $.d[k]; } } + }, + buildPresentation : function () { + var ns = document.createElement('style'); + document.getElementsByTagName('head')[0].appendChild(ns); + if (!window.createPopup) { + ns.appendChild(document.createTextNode('')); + ns.setAttribute("type", "text/css"); + } + var s = document.styleSheets[document.styleSheets.length - 1]; + var rules = { + "" : "{zoom:1;margin:0;padding:0;width:" + $.a.width + "px;background:" + $.a.background + ";border:" + $.a.border + ";font:13px/1.2em tahoma, veranda, arial, helvetica, clean, sans-serif;*font-size:small;*font:x-small;}", + "a" : "{cursor:pointer;text-decoration:none;}", + "a:hover" : "{text-decoration:underline;}", + "cite" : "{font-weight:bold;margin:0 0 0 4px;padding:0;display:block;font-style:normal;line-height:" + ($.a.thumbnailSize/2) + "px;}", + "cite a" : "{color:#C15D42;}", + "date":"{font-size:87%;margin:0 0 0 4px;padding:0;display:block;font-style:normal;line-height:" + ($.a.thumbnailSize/2) + "px;}", + "date:after" : "{clear:both; content:\".\"; display:block; height:0; visibility:hidden; }", + "date a" : "{color:#676;}", + "h3" : "{margin:0;padding:" + $.a.padding + "px;font-weight:bold;background:" + $.a.headerBackground + " url('http://" + $.a.server + "/favicon.ico') " + $.a.padding + "px 50% no-repeat;text-indent:" + ($.a.padding + 16) + "px;}", + "h3.loading" : "{background-image:url('http://l.yimg.com/us.yimg.com/i/us/my/mw/anim_loading_sm.gif');}", + "h3 a" : "{font-size:92%; color:" + $.a.headerColor + ";}", + "h4" : "{font-weight:normal; background:" + $.a.headerBackground + ";text-align:right;margin:0;padding:" + $.a.padding + "px;}", + "h4 a" : "{font-size:92%; color:" + $.a.headerColor + ";}", + "img":"{float:left; height:" + $.a.thumbnailSize + "px;width:" + $.a.thumbnailSize + "px;border:" + $.a.thumbnailBorder + ";margin-right:" + $.a.padding + "px;}", + "p" : "{margin:0; padding:0;width:" + ($.a.width - 22) + "px;overflow:hidden;font-size:87%;}", + "p a" : "{color:#C15D42;}", + "ul":"{margin:0; padding:0; height:" + $.a.height + "px;width:" + $.a.width + "px;overflow:auto;}", + "ul li":"{background:" + $.a.evenBackground + ";margin:0;padding:" + $.a.padding + "px;list-style:none;width:" + ($.a.width - 22) + "px;overflow:hidden;border-bottom:1px solid #D8E2D7;}", + "ul li:hover":"{background:#f3f8ea;}" + }; + var ieRules = ""; + // brute-force each and every style rule here to !important + // sometimes you have to take off and nuke the site from orbit; it's the only way to be sure + for (var z in rules) { + var selector = '.' + trueName + ' ' + z; + var rule = rules[z]; + if (typeof rule === 'string') { + var important = rule.replace(/;/gi, '!important;'); + if (!window.createPopup) { + var theRule = document.createTextNode(selector + important); + ns.appendChild(theRule); + } else { + ieRules += selector + important; + } + } + } + if (window.createPopup) { s.cssText = ieRules; } + }, + buildStructure : function() { + $.s = document.createElement('DIV'); + $.s.className = trueName; + $.s.h = document.createElement('H3'); + $.s.h.a = document.createElement('A'); + $.s.h.a.target = '_laconica'; + $.s.h.appendChild($.s.h.a); + $.s.appendChild($.s.h); + $.s.r = document.createElement('UL'); + $.s.appendChild($.s.r); + $.s.f = document.createElement('H4'); + var a = document.createElement('A'); + a.innerHTML = 'get this'; + a.target = '_blank'; + a.href = 'http://kentbrewster.com/identica-badge'; + $.s.f.appendChild(a); + $.s.appendChild($.s.f); + $.f.getUser(); + }, + getUser : function() { + if (!$.f.runFunction) { $.f.runFunction = []; } + var n = $.f.runFunction.length; + var id = trueName + '.f.runFunction[' + n + ']'; + $.f.runFunction[n] = function(r) { + delete($.f.runFunction[n]); + var a = document.createElement('A'); + a.rel = $.a.user; + a.rev = r.name; + a.id = r.screen_name; + $.f.removeScript(id); + $.f.changeUserTo(a); + }; + var url = 'http://' + $.a.server + '/api/users/show/' + $.a.user + '.json?callback=' + id; + $.f.runScript(url, id); + }, + changeUserTo : function(el) { + $.a.user = el.rel; + $.s.h.a.innerHTML = el.rev + $.a.headerText; + $.s.h.a.href = 'http://' + $.a.server + '/' + el.id; + $.f.runSearch(); + }, + runSearch : function() { + $.s.h.className = 'loading'; + $.s.r.innerHTML = ''; + if (!$.f.runFunction) { $.f.runFunction = []; } + var n = $.f.runFunction.length; + var id = trueName + '.f.runFunction[' + n + ']'; + $.f.runFunction[n] = function(r) { + delete($.f.runFunction[n]); + $.f.removeScript(id); + $.f.renderResult(r); + }; + var url = 'http://' + $.a.server + '/api/statuses/friends/' + $.a.user + '.json?callback=' + id; + $.f.runScript(url, id); + }, + renderResult: function(r) { + for (var i = 0; i < r.length; i++) { + if (!r[i].status) { + r.splice(i, 1); + } else { + r[i].status_id = parseInt(r[i].status.id); + } + } + r = $.f.sortArray(r, "status_id", true); + $.s.h.className = ''; + for (var i = 0; i < r.length; i++) { + var li = document.createElement('LI'); + var icon = document.createElement('A'); + if (r[i] && r[i].url) { + icon.href = r[i].url; + icon.target = '_laconica'; + icon.title = 'Visit ' + r[i].screen_name + ' at ' + r[i].url; + } else { + icon.href = 'http://' + $.a.server + '/' + r[i].screen_name; + icon.target = '_laconica'; + icon.title = 'Visit ' + r[i].screen_name + ' at http://' + $.a.server + '/' + r[i].screen_name; + } + + var img = document.createElement('IMG'); + img.src = r[i].profile_image_url; + icon.appendChild(img); + li.appendChild(icon); + + var user = document.createElement('CITE'); + var a = document.createElement('A'); + a.rel = r[i].id; + a.rev = r[i].name; + a.id = r[i].screen_name; + a.innerHTML = r[i].name; + a.href = 'http://' + $.a.server + '/' + r[i].screen_name; + a.onclick = function() { + $.f.changeUserTo(this); + return false; + }; + user.appendChild(a); + li.appendChild(user); + var updated = document.createElement('DATE'); + if (r[i].status && r[i].status.created_at) { + var date_link = document.createElement('A'); + date_link.innerHTML = r[i].status.created_at.split(/\+/)[0]; + date_link.href = 'http://' + $.a.server + '/notice/' + r[i].status.id; + date_link.target = '_laconica'; + updated.appendChild(date_link); + if (r[i].status.in_reply_to_status_id) { + updated.appendChild(document.createTextNode(' in reply to ')); + var in_reply_to = document.createElement('A'); + in_reply_to.innerHTML = r[i].status.in_reply_to_status_id; + in_reply_to.href = 'http://' + $.a.server + '/notice/' + r[i].status.in_reply_to_status_id; + in_reply_to.target = '_laconica'; + updated.appendChild(in_reply_to); + } + } else { + updated.innerHTML = 'has not updated yet'; + } + li.appendChild(updated); + var p = document.createElement('P'); + if (r[i].status && r[i].status.text) { + var raw = r[i].status.text; + var cooked = raw; + cooked = cooked.replace(/http:\/\/([^ ]+)/g, "<a href=\"http://$1\" target=\"_laconica\">http://$1</a>"); + cooked = cooked.replace(/@([\w*]+)/g, '@<a href="http://' + $.a.server + '/$1" target=\"_laconica\">$1</a>'); + cooked = cooked.replace(/#([\w*]+)/g, '#<a href="http://' + $.a.server + '/tag/$1" target="_laconica">$1</a>'); + p.innerHTML = cooked; + } + li.appendChild(p); + var a = p.getElementsByTagName('A'); + for (var j = 0; j < a.length; j++) { + if (a[j].className == 'changeUserTo') { + a[j].className = ''; + a[j].href = 'http://' + $.a.server + '/' + a[j].innerHTML; + a[j].rel = a[j].innerHTML; + a[j].onclick = function() { + $.f.changeUserTo(this); + return false; + } + } + } + $.s.r.appendChild(li); + } + }, + sortArray : function(r, k, x) { + if (window.createPopup) { + return r; + } + function s(a, b) { + if (x === true) { + return b[k] - a[k]; + } else { + return a[k] - b[k]; + } + } + r = r.sort(s); + return r; + }, + runScript : function(url, id) { + var s = document.createElement('script'); + s.id = id; + s.type ='text/javascript'; + s.src = url; + document.getElementsByTagName('body')[0].appendChild(s); + }, + removeScript : function(id) { + if (document.getElementById(id)) { + var s = document.getElementById(id); + s.parentNode.removeChild(s); + } + } + }; + }(); +// var thisScript = /^https?:\/\/[^\/]*r8ar.com\/identica-badge.js$/; + var thisScript = /identica-badge.js$/; + if(typeof window.addEventListener !== 'undefined') { + window.addEventListener('load', function() { $.f.init(thisScript); }, false); + } else if(typeof window.attachEvent !== 'undefined') { + window.attachEvent('onload', function() { $.f.init(thisScript); }); + } +} )(); + diff --git a/js/jcrop/jquery.Jcrop.go.js b/js/jcrop/jquery.Jcrop.go.js new file mode 100644 index 000000000..b2737407b --- /dev/null +++ b/js/jcrop/jquery.Jcrop.go.js @@ -0,0 +1,46 @@ + $(function(){ + var x = ($('#avatar_crop_x').val()) ? $('#avatar_crop_x').val() : 0; + var y = ($('#avatar_crop_y').val()) ? $('#avatar_crop_y').val() : 0; + var w = ($('#avatar_crop_w').val()) ? $('#avatar_crop_w').val() : $("#avatar_original img").attr("width"); + var h = ($('#avatar_crop_h').val()) ? $('#avatar_crop_h').val() : $("#avatar_original img").attr("height"); + + jQuery("#avatar_original img").Jcrop({ + onChange: showPreview, + setSelect: [ x, y, w, h ], + onSelect: updateCoords, + aspectRatio: 1, + boxWidth: 480, + boxHeight: 480, + bgColor: '#000', + bgOpacity: .4 + }); + }); + + function showPreview(coords) { + var rx = 96 / coords.w; + var ry = 96 / coords.h; + + var img_width = $("#avatar_original img").attr("width"); + var img_height = $("#avatar_original img").attr("height"); + + $('#avatar_preview img').css({ + width: Math.round(rx *img_width) + 'px', + height: Math.round(ry * img_height) + 'px', + marginLeft: '-' + Math.round(rx * coords.x) + 'px', + marginTop: '-' + Math.round(ry * coords.y) + 'px' + }); + }; + + function updateCoords(c) { + $('#avatar_crop_x').val(c.x); + $('#avatar_crop_y').val(c.y); + $('#avatar_crop_w').val(c.w); + $('#avatar_crop_h').val(c.h); + }; + + function checkCoords() { + if (parseInt($('#avatar_crop_w').val())) return true; + alert('Please select a crop region then press submit.'); + return false; + }; + diff --git a/js/jcrop/jquery.Jcrop.pack.js b/js/jcrop/jquery.Jcrop.pack.js new file mode 100644 index 000000000..aa82e8abe --- /dev/null +++ b/js/jcrop/jquery.Jcrop.pack.js @@ -0,0 +1,8 @@ +/** + * Jcrop v.0.9.5 (packed) + * (c) 2008 Kelly Hallman and DeepLiquid.com + * More information: http://deepliquid.com/content/Jcrop.html + * Released under MIT License - this header must remain with code + */ + +eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$.1n=7(G,F){d G=G,F=F;g(1p(G)!==\'2d\')G=$(G)[0];g(1p(F)!==\'2d\')F={};g(!(\'2x\'1a F))F.2x=$.3d.3e?K:M;g(!(\'2c\'1a F))F.2c=$.3d.3e?K:M;d 4f={2x:K,3W:\'4C\',1f:4D,3T:\'4Y\',3x:.6,3O:.4,3P:.5,53:5,3N:9,3D:5,51:14,25:0,2c:M,3I:M,3B:M,30:M,3A:M,49:0,4p:0,4k:8,3V:20,3X:3,2f:K,3n:[0,0],2z:[0,0],2O:[0,0],2D:7(){},2G:7(){}};d j=4f;21(F);d $I=$(G).B({16:\'1b\'});47($I,j.49,j.4p);d S=$I.W(),L=$I.U(),$12=$(\'<12 />\').W(S).U(L).1f(1L(\'4F\')).B({16:\'4H\',4B:j.3T});g(j.1f)$12.1f(j.1f);$I.54($12);d $34=$(\'<I />\').3Y(\'2N\',$I.3Y(\'2N\')).B(\'16\',\'1b\').W(S).U(L);d $2C=$(\'<12 />\').W(1t(V)).U(1t(V)).B({1l:59,16:\'1b\',4o:\'4g\'}).1P($34);d $2g=$(\'<12 />\').W(1t(V)).U(1t(V)).B({1l:5b});d $28=$(\'<12 />\').B({16:\'1b\',1l:55}).3U($I).1P($2C,$2g);d 23=j.4k;d $1S=$(\'<12 />\').1f(1L(\'3v\')).W(S+(23*2)).U(L+(23*2)).B({16:\'1b\',R:D(-23),P:D(-23),1l:3R,1z:0}).3q(48);d 1I,1Q;d 2u=2Q(G),1q,1B,3i,58,3h,1O;g(\'36\'1a j){1I=j.36[0]/S;1Q=j.36[1]/L}d E=7(){d A=0,u=0,q=0,m=0,Z,Y;7 1A(z){d z=2T(z);q=A=z[0];m=u=z[1]};7 1y(z){d z=2T(z);Z=z[0]-q;Y=z[1]-m;q=z[0];m=z[1]};7 3f(){k[Z,Y]};7 2b(2y){d Z=2y[0],Y=2y[1];g(0>A+Z)Z-=Z+A;g(0>u+Y)Y-=Y+u;g(L<m+Y)Y+=L-(m+Y);g(S<q+Z)Z+=S-(q+Z);A+=Z;q+=Z;u+=Y;m+=Y};7 2K(T){d c=Q();1E(T){C\'1s\':k[c.q,c.y];C\'11\':k[c.x,c.y];C\'2e\':k[c.q,c.m];C\'1M\':k[c.x,c.m]}};7 Q(){g(!j.25&&!1B)k 3F();d 1k=j.25?j.25:1B,5c=j.2O,4u=j.2z,1V=q-A,1Z=m-u,3c=N.17(1V),3j=N.17(1Z),3M=3c/3j,15,13;g(3M<1k){13=m;w=3j*1k;15=1V<0?A-w:w+A;g(15<0){15=0;h=N.17((15-A)/1k);13=1Z<0?u-h:h+u}1g g(15>S){15=S;h=N.17((15-A)/1k);13=1Z<0?u-h:h+u}}1g{15=q;h=3c/1k;13=1Z<0?u-h:u+h;g(13<0){13=0;w=N.17((13-u)*1k);15=1V<0?A-w:w+A}1g g(13>L){13=L;w=N.17(13-u)*1k;15=1V<0?A-w:w+A}}k 4E=3g(1F(A,u,15,13))};7 2T(p){g(p[0]<0)p[0]=0;g(p[1]<0)p[1]=0;g(p[0]>S)p[0]=S;g(p[1]>L)p[1]=L;k[p[0],p[1]]};7 1F(A,u,q,m){d 2R=A,3r=q,3o=u,3l=m;g(q<A){2R=q;3r=A}g(m<u){3o=m;3l=u}k[N.1K(2R),N.1K(3o),N.1K(3r),N.1K(3l)]};7 3F(){d 1U=q-A;d 22=m-u;g(2q&&(N.17(1U)>2q))q=(1U>0)?(A+2q):(A-2q);g(2n&&(N.17(22)>2n))m=(22>0)?(u+2n):(u-2n);g(2i&&(N.17(22)<2i))m=(22>0)?(u+2i):(u-2i);g(2m&&(N.17(1U)<2m))q=(1U>0)?(A+2m):(A-2m);g(A<0){q-=A;A-=A}g(u<0){m-=u;u-=u}g(q<0){A-=q;q-=q}g(m<0){u-=m;m-=m}g(q>S){d X=q-S;A-=X;q-=X}g(m>L){d X=m-L;u-=X;m-=X}g(A>S){d X=A-L;m-=X;u-=X}g(u>L){d X=u-L;m-=X;u-=X}k 3g(1F(A,u,q,m))};7 3g(a){k{x:a[0],y:a[1],q:a[2],m:a[3],w:a[2]-a[0],h:a[3]-a[1]}};k{1F:1F,1A:1A,1y:1y,3f:3f,2b:2b,2K:2K,Q:Q}}();d J=7(){d 4v,4z,4y,1R,2U=4x;d 2F={};d H={};d 2E=K;d 1i=j.3D;g(j.30){2F={R:1Y(\'3C\').B(\'R\',$.3d.3e?D(-1):D(0)),3Q:1Y(\'3C\'),P:1Y(\'3z\'),3L:1Y(\'3z\')}}g(j.3A){H.t=1W(\'n\');H.b=1W(\'s\');H.r=1W(\'e\');H.l=1W(\'w\')}j.3B&&2Y([\'n\',\'s\',\'e\',\'w\']);j.3I&&2Y([\'1M\',\'11\',\'1s\',\'2e\']);7 1Y(1u){d 1J=$(\'<12 />\').B({16:\'1b\',1z:j.3O}).1f(1L(1u));$2C.1P(1J);k 1J};7 2W(T,3y){d 1J=$(\'<12 />\').3q(3b(T)).B({3p:T+\'-2A\',16:\'1b\',1l:3y});$2g.1P(1J);k 1J};7 3J(T){k 2W(T,2U++).B({R:D(-1i+1),P:D(-1i+1),1z:j.3P}).1f(1L(\'H\'))};7 1W(T){d s=j.3N,o=1i,h=s,w=s,t=o,l=o;1E(T){C\'n\':C\'s\':w=1t(V);O;C\'e\':C\'w\':h=1t(V);O}k 2W(T,2U++).W(w).U(h).B({R:D(-t+1),P:D(-l+1)})};7 2Y(2J){4U(i 1a 2J)H[2J[i]]=3J(2J[i])};7 31(c){d 3a=N.1K((c.h/2)-1i),35=N.1K((c.w/2)-1i),4V=4W=-1i+1,2a=c.w-1i,1X=c.h-1i,x,y;\'e\'1a H&&H.e.B({R:D(3a),P:D(2a)})&&H.w.B({R:D(3a)})&&H.s.B({R:D(1X),P:D(35)})&&H.n.B({P:D(35)});\'1s\'1a H&&H.1s.B({P:D(2a)})&&H.2e.B({R:D(1X),P:D(2a)})&&H.1M.B({R:D(1X)});\'b\'1a H&&H.b.B({R:D(1X)})&&H.r.B({P:D(2a)})};7 3K(x,y){$34.B({R:D(-y),P:D(-x)});$28.B({R:D(y),P:D(x)})};7 2A(w,h){$28.W(w).U(h)};7 3s(){d p=E.Q();E.1A([p.x,p.y]);E.1y([p.q,p.m])};7 2I(){g(1R)k 1e()};7 1e(){d c=E.Q();2A(c.w,c.h);3K(c.x,c.y);j.30&&2F[\'3L\'].B({P:D(c.w-1)})&&2F[\'3Q\'].B({R:D(c.h-1)});2E&&31(c);1R||1w();j.2D(2H(c))};7 1w(){$28.1w();$I.B(\'1z\',j.3x);1R=M};7 1r(){1o();$28.1v();$I.B(\'1z\',1);1R=K};7 1v(){1r();$I.B(\'1z\',1);1R=K};7 2t(){2E=M;31(E.Q());$2g.1w()};7 1o(){2E=K;$2g.1v()};7 2o(v){(3h=v)?1o():2t()};7 1h(){d c=E.Q();2o(K);3s()};1o();$2C.1P($(\'<12 />\').1f(1L(\'3v\')).3q(3b(\'1N\')).B({3p:\'1N\',16:\'1b\',1l:4M,1z:0}));k{2I:2I,1e:1e,1r:1r,1w:1w,1v:1v,2t:2t,1o:1o,2o:2o,1h:1h}}();d 1j=7(){d 2w=7(){},2v=7(){},2L=j.2x;g(!2L){$1S.3k(2B).2S(26).4N(26)}7 4j(){g(2L){$(3t).3k(2B).2S(26)}$1S.B({1l:4G})}7 4i(){g(2L){$(3t).3H(\'3k\',2B).3H(\'2S\',26)}$1S.B({1l:3R})}7 2B(e){2w(2r(e))};7 26(e){e.2j();e.2k();g(1q){1q=K;2v(2r(e));j.2G(2H(E.Q()));4i();2w=7(){};2v=7(){}}k K};7 1G(1N,1h){1q=M;2w=1N;2v=1h;4j();k K};7 1x(t){$1S.B(\'3p\',t)};$I.4s($1S);k{1G:1G,1x:1x}}();d 33=7(){d $24=$(\'<4w 1u="4L" />\').B({16:\'1b\',P:\'-4O\'}).57(43).56(2f).5a(41),$3S=$(\'<12 />\').B({16:\'1b\',4o:\'4g\'}).1P($24);7 2l(){g(j.2c){$24.1w();$24.4Z()}};7 41(e){$24.1v()};7 2f(e){g(!j.2f)k;d 42=1O,1C;1O=e.4Q?M:K;g(42!=1O){g(1O&&1q){1C=E.Q();1B=1C.w/1C.h}1g 1B=0;J.1e()}e.2k();e.2j();k K};7 29(e,x,y){E.2b([x,y]);J.2I();e.2j();e.2k()};7 43(e){g(e.4T)k M;2f(e);d 2h=1O?10:1;1E(e.5d){C 37:29(e,-2h,0);O;C 39:29(e,2h,0);O;C 38:29(e,0,-2h);O;C 40:29(e,0,2h);O;C 27:J.1r();O;C 9:k M}k K};g(j.2c)$3S.3U($I);k{2l:2l}}();7 D(n){k\'\'+1m(n)+\'D\'};7 1t(n){k\'\'+1m(n)+\'%\'};7 1L(44){k j.3W+\'-\'+44};7 2Q(G){d z=$(G).2y();k[z.P,z.R]};7 2r(e){k[(e.4q-2u[0]),(e.4r-2u[1])]};7 46(1u){g(1u!=3i){1j.1x(1u);3i=1u}};7 4a(19,z){2u=2Q(G);1j.1x(19==\'1N\'?19:19+\'-2A\');g(19==\'1N\')k 1j.1G(4e(z),2P);d 1C=E.Q();E.1A(E.2K(4b(19)));1j.1G(45(19,1C),2P)};7 45(19,f){k 7(z){g(!j.25&&!1B)1E(19){C\'e\':z[1]=f.m;O;C\'w\':z[1]=f.m;O;C\'n\':z[0]=f.q;O;C\'s\':z[0]=f.q;O}1g 1E(19){C\'e\':z[1]=f.y+1;O;C\'w\':z[1]=f.y+1;O;C\'n\':z[0]=f.x+1;O;C\'s\':z[0]=f.x+1;O}E.1y(z);J.1e()}};7 4e(z){d 2M=z;33.2l();k 7(z){E.2b([z[0]-2M[0],z[1]-2M[1]]);2M=z;J.1e()}};7 4b(T){1E(T){C\'n\':k\'1M\';C\'s\':k\'11\';C\'e\':k\'11\';C\'w\':k\'1s\';C\'1s\':k\'1M\';C\'11\':k\'2e\';C\'2e\':k\'11\';C\'1M\':k\'1s\'}};7 3b(T){k 7(e){1q=M;4a(T,2r(e));e.2k();e.2j();k K}};7 47($G,w,h){d 11=$G.W(),1H=$G.U();g((11>w)&&w>0){11=w;1H=(w/$G.W())*$G.U()}g((1H>h)&&h>0){1H=h;11=(h/$G.U())*$G.W()}1I=$G.W()/11;1Q=$G.U()/1H;$G.W(11).U(1H)};7 2H(c){k{x:1m(c.x*1I),y:1m(c.y*1Q),q:1m(c.q*1I),m:1m(c.m*1Q),w:1m(c.w*1I),h:1m(c.h*1Q)}};7 2P(z){d c=E.Q();g(c.w>j.3n[0]&&c.h>j.3n[1]){J.2t();J.1h()}1g{J.1r()}1j.1x(\'2X\')};7 48(e){1q=M;2u=2Q(G);J.1r();J.1o();46(\'2X\');E.1A(2r(e));1j.1G(4c,2P);33.2l();e.2k();e.2j();k K};7 4c(z){E.1y(z);J.1e()};7 2Z(a){d A=a[0],u=a[1],q=a[2],m=a[3];g(3h)k;d 2s=E.1F(A,u,q,m);d c=E.Q();d 18=2p=[c.x,c.y,c.q,c.m];d 3w=j.3V;d x=18[0];d y=18[1];d q=18[2];d m=18[3];d 3Z=2s[0]-2p[0];d 4m=2s[1]-2p[1];d 4n=2s[2]-2p[2];d 4l=2s[3]-2p[3];d 1c=0;d 4h=j.3X;J.2o(M);d 3u=7(){k 7(){1c+=(V-1c)/4h;18[0]=x+((1c/V)*3Z);18[1]=y+((1c/V)*4m);18[2]=q+((1c/V)*4n);18[3]=m+((1c/V)*4l);g(1c<V)32();1g J.1h();g(1c>=4K.8)1c=V;1d(18)}}();7 32(){4I.4t(3u,3w)};32()};7 1d(l){E.1A([l[0],l[1]]);E.1y([l[2],l[3]]);J.1e()};7 21(F){g(1p(F)!=\'2d\')F={};j=$.4X(j,F);g(1p(j.2D)!==\'7\')j.2D=7(){};g(1p(j.2G)!==\'7\')j.2G=7(){}};7 3m(){k 2H(E.Q())};7 2V(){k E.Q()};7 3E(F){21(F);g(\'1d\'1a F){1d(F.1d);J.1h()}};g(1p(F)!=\'2d\')F={};g(\'1d\'1a F){1d(F.1d);J.1h()}d 2q=j.2z[0]||0;d 2n=j.2z[1]||0;d 2m=j.2O[0]||0;d 2i=j.2O[1]||0;1j.1x(\'2X\');k{2Z:2Z,1d:1d,21:3E,3m:3m,2V:2V}};$.5e.1n=7(j){7 3G(1D){d 4d=j.4R||1D.2N;d I=4P 4S();d 1D=1D;I.50=7(){$(1D).1v().4A(I);1D.1n=$.1n(I,j)};I.2N=4d};g(1p(j)!==\'2d\')j={};1T.4J(7(){g(\'1n\'1a 1T){g(j==\'52\')k 1T.1n;1g 1T.1n.21(j)}1g 3G(1T)});k 1T};',62,325,'|||||||function||||||var|||if|||options|return||y2||||x2||||y1|||||pos|x1|css|case|px|Coords|opt|obj|handle|img|Selection|false|boundy|true|Math|break|left|getFixed|top|boundx|ord|height|100|width|delta|oy|ox||nw|div|yy||xx|position|abs|animat|mode|in|absolute|pcent|setSelect|update|addClass|else|done|hhs|Tracker|aspect|zIndex|parseInt|Jcrop|disableHandles|typeof|btndown|release|ne|pct|type|hide|show|setCursor|setCurrent|opacity|setPressed|aspectLock|fc|from|switch|flipCoords|activateHandlers|nh|xscale|jq|round|cssClass|sw|move|shift_down|append|yscale|awake|trk|this|xsize|rw|insertDragbar|south|insertBorder|rh||setOptions|ysize|bound|keymgr|aspectRatio|trackUp||sel|doNudge|east|moveOffset|keySupport|object|se|watchShift|hdl_holder|nudge|ymin|preventDefault|stopPropagation|watchKeys|xmin|ylimit|animMode|initcr|xlimit|mouseAbs|animto|enableHandles|docOffset|onDone|onMove|trackDocument|offset|maxSize|resize|trackMove|img_holder|onChange|seehandles|borders|onSelect|unscale|updateVisible|li|getCorner|trackDoc|lloc|src|minSize|doneSelect|getPos|xa|mouseup|rebound|hdep|tellScaled|dragDiv|crosshair|createHandles|animateTo|drawBorders|moveHandles|animateStart|KeyManager|img2|midhoriz|trueSize||||midvert|createDragger|rwa|browser|msie|getOffset|makeObj|animating|lastcurs|rha|mousemove|yb|tellSelect|minSelect|ya|cursor|mousedown|xb|refresh|document|animator|tracker|interv|bgOpacity|zi|vline|dragEdges|sideHandles|hline|handleOffset|setOptionsNew|getRect|attachWhenDone|unbind|cornerHandles|insertHandle|moveto|right|real_ratio|handleSize|borderOpacity|handleOpacity|bottom|290|keywrap|bgColor|insertBefore|animationDelay|baseClass|swingSpeed|attr|ix1||onBlur|init_shift|parseKey|cl|dragmodeHandler|myCursor|presize|newSelection|boxWidth|startDragMode|oppLockCorner|selectDrag|loadsrc|createMover|defaults|hidden|velocity|toBack|toFront|boundary|iy2|iy1|ix2|overflow|boxHeight|pageX|pageY|before|setTimeout|max|start|input|370|dragmode|end|after|backgroundColor|jcrop|null|last|holder|450|relative|window|each|99|radio|360|mouseout|30px|new|shiftKey|useImg|Image|ctrlKey|for|north|west|extend|black|focus|onload|edgeMargin|api|handlePad|wrap|300|keyup|keydown|dimmed|310|blur|320|min|keyCode|fn'.split('|'),0,{})) diff --git a/js/jquery.js b/js/jquery.js index 88e661eec..fc06ace27 100644 --- a/js/jquery.js +++ b/js/jquery.js @@ -1,34 +1,36 @@ -(function(){ -/* - * jQuery 1.2.6 - New Wave Javascript +/*! + * jQuery JavaScript Library v1.3 + * http://jquery.com/ * - * Copyright (c) 2008 John Resig (jquery.com) - * Dual licensed under the MIT (MIT-LICENSE.txt) - * and GPL (GPL-LICENSE.txt) licenses. + * Copyright (c) 2009 John Resig + * Dual licensed under the MIT and GPL licenses. + * http://docs.jquery.com/License * - * $Date: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) $ - * $Rev: 5685 $ + * Date: 2009-01-13 12:50:31 -0500 (Tue, 13 Jan 2009) + * Revision: 6104 */ +(function(){ -// Map over jQuery in case of overwrite -var _jQuery = window.jQuery, -// Map over the $ in case of overwrite - _$ = window.$; - -var jQuery = window.jQuery = window.$ = function( selector, context ) { - // The jQuery object is actually just the init constructor 'enhanced' - return new jQuery.fn.init( selector, context ); -}; - -// A simple way to check for HTML strings or ID strings -// (both of which we optimize for) -var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/, - -// Is it a simple selector - isSimple = /^.[^:#\[\.]*$/, +var + // Will speed up references to window, and allows munging its name. + window = this, + // Will speed up references to undefined, and allows munging its name. + undefined, + // Map over jQuery in case of overwrite + _jQuery = window.jQuery, + // Map over the $ in case of overwrite + _$ = window.$, + + jQuery = window.jQuery = window.$ = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + return new jQuery.fn.init( selector, context ); + }, -// Will speed up references to undefined, and allows munging its name. - undefined; + // A simple way to check for HTML strings or ID strings + // (both of which we optimize for) + quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/, + // Is it a simple selector + isSimple = /^.[^:#\[\.,]*$/; jQuery.fn = jQuery.prototype = { init: function( selector, context ) { @@ -39,10 +41,11 @@ jQuery.fn = jQuery.prototype = { if ( selector.nodeType ) { this[0] = selector; this.length = 1; + this.context = selector; return this; } // Handle HTML strings - if ( typeof selector == "string" ) { + if ( typeof selector === "string" ) { // Are we dealing with HTML string or an ID? var match = quickExpr.exec( selector ); @@ -65,7 +68,10 @@ jQuery.fn = jQuery.prototype = { return jQuery().find( selector ); // Otherwise, we inject the element directly into the jQuery object - return jQuery( elem ); + var ret = jQuery( elem ); + ret.context = document; + ret.selector = selector; + return ret; } selector = []; } @@ -78,26 +84,32 @@ jQuery.fn = jQuery.prototype = { // HANDLE: $(function) // Shortcut for document ready } else if ( jQuery.isFunction( selector ) ) - return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector ); + return jQuery( document ).ready( selector ); + + // Make sure that old selector state is passed along + if ( selector.selector && selector.context ) { + this.selector = selector.selector; + this.context = selector.context; + } return this.setArray(jQuery.makeArray(selector)); }, + // Start with an empty selector + selector: "", + // The current version of jQuery being used - jquery: "1.2.6", + jquery: "1.3", // The number of elements contained in the matched element set size: function() { return this.length; }, - // The number of elements contained in the matched element set - length: 0, - // Get the Nth element in the matched element set OR // Get the whole matched element set as a clean array get: function( num ) { - return num == undefined ? + return num === undefined ? // Return a 'clean' array jQuery.makeArray( this ) : @@ -108,13 +120,20 @@ jQuery.fn = jQuery.prototype = { // Take an array of elements and push it onto the stack // (returning the new matched element set) - pushStack: function( elems ) { + pushStack: function( elems, name, selector ) { // Build a new jQuery matched element set var ret = jQuery( elems ); // Add the old object onto the stack (as a reference) ret.prevObject = this; + ret.context = this.context; + + if ( name === "find" ) + ret.selector = this.selector + (this.selector ? " " : "") + selector; + else if ( name ) + ret.selector = this.selector + "." + name + "(" + selector + ")"; + // Return the newly-formed element set return ret; }, @@ -141,8 +160,6 @@ jQuery.fn = jQuery.prototype = { // Determine the position of an element within // the matched set of elements index: function( elem ) { - var ret = -1; - // Locate the position of the desired element return jQuery.inArray( // If it receives a jQuery object, the first element is used @@ -154,7 +171,7 @@ jQuery.fn = jQuery.prototype = { var options = name; // Look for the case where we're accessing a style value - if ( name.constructor == String ) + if ( typeof name === "string" ) if ( value === undefined ) return this[0] && jQuery[ type || "attr" ]( this[0], name ); @@ -184,7 +201,7 @@ jQuery.fn = jQuery.prototype = { }, text: function( text ) { - if ( typeof text != "object" && text != null ) + if ( typeof text !== "object" && text != null ) return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); var ret = ""; @@ -202,20 +219,22 @@ jQuery.fn = jQuery.prototype = { }, wrapAll: function( html ) { - if ( this[0] ) + if ( this[0] ) { // The elements to wrap the target around - jQuery( html, this[0].ownerDocument ) - .clone() - .insertBefore( this[0] ) - .map(function(){ - var elem = this; + var wrap = jQuery( html, this[0].ownerDocument ).clone(); - while ( elem.firstChild ) - elem = elem.firstChild; + if ( this[0].parentNode ) + wrap.insertBefore( this[0] ); - return elem; - }) - .append(this); + wrap.map(function(){ + var elem = this; + + while ( elem.firstChild ) + elem = elem.firstChild; + + return elem; + }).append(this); + } return this; }, @@ -233,27 +252,27 @@ jQuery.fn = jQuery.prototype = { }, append: function() { - return this.domManip(arguments, true, false, function(elem){ + return this.domManip(arguments, true, function(elem){ if (this.nodeType == 1) this.appendChild( elem ); }); }, prepend: function() { - return this.domManip(arguments, true, true, function(elem){ + return this.domManip(arguments, true, function(elem){ if (this.nodeType == 1) this.insertBefore( elem, this.firstChild ); }); }, before: function() { - return this.domManip(arguments, false, false, function(elem){ + return this.domManip(arguments, false, function(elem){ this.parentNode.insertBefore( elem, this ); }); }, after: function() { - return this.domManip(arguments, false, true, function(elem){ + return this.domManip(arguments, false, function(elem){ this.parentNode.insertBefore( elem, this.nextSibling ); }); }, @@ -262,20 +281,31 @@ jQuery.fn = jQuery.prototype = { return this.prevObject || jQuery( [] ); }, + // For internal use only. + // Behaves like an Array's .push method, not like a jQuery method. + push: [].push, + find: function( selector ) { - var elems = jQuery.map(this, function(elem){ - return jQuery.find( selector, elem ); - }); + if ( this.length === 1 && !/,/.test(selector) ) { + var ret = this.pushStack( [], "find", selector ); + ret.length = 0; + jQuery.find( selector, this[0], ret ); + return ret; + } else { + var elems = jQuery.map(this, function(elem){ + return jQuery.find( selector, elem ); + }); - return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ? - jQuery.unique( elems ) : - elems ); + return this.pushStack( /[^+>] [^+>]/.test( selector ) ? + jQuery.unique( elems ) : + elems, "find", selector ); + } }, clone: function( events ) { // Do the clone var ret = this.map(function(){ - if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { + if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) { // IE copies events bound via attachEvent when // using cloneNode. Calling detachEvent on the // clone will also remove the events from the orignal @@ -296,7 +326,7 @@ jQuery.fn = jQuery.prototype = { // removeData doesn't work here, IE removes it from the original as well // this is primarily for IE but the data expando shouldn't be copied over in any browser var clone = ret.find("*").andSelf().each(function(){ - if ( this[ expando ] != undefined ) + if ( this[ expando ] !== undefined ) this[ expando ] = null; }); @@ -323,14 +353,29 @@ jQuery.fn = jQuery.prototype = { return selector.call( elem, i ); }) || - jQuery.multiFilter( selector, this ) ); + jQuery.multiFilter( selector, jQuery.grep(this, function(elem){ + return elem.nodeType === 1; + }) ), "filter", selector ); + }, + + closest: function( selector ) { + var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null; + + return this.map(function(){ + var cur = this; + while ( cur && cur.ownerDocument ) { + if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) + return cur; + cur = cur.parentNode; + } + }); }, not: function( selector ) { - if ( selector.constructor == String ) + if ( typeof selector === "string" ) // test special case where just one selector is passed in if ( isSimple.test( selector ) ) - return this.pushStack( jQuery.multiFilter( selector, this, true ) ); + return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector ); else selector = jQuery.multiFilter( selector, this ); @@ -343,7 +388,7 @@ jQuery.fn = jQuery.prototype = { add: function( selector ) { return this.pushStack( jQuery.unique( jQuery.merge( this.get(), - typeof selector == 'string' ? + typeof selector === "string" ? jQuery( selector ) : jQuery.makeArray( selector ) ))); @@ -354,15 +399,17 @@ jQuery.fn = jQuery.prototype = { }, hasClass: function( selector ) { - return this.is( "." + selector ); + return !!selector && this.is( "." + selector ); }, val: function( value ) { - if ( value == undefined ) { - - if ( this.length ) { - var elem = this[0]; + if ( value === undefined ) { + var elem = this[0]; + if ( elem ) { + if( jQuery.nodeName( elem, 'option' ) ) + return (elem.attributes.value || {}).specified ? elem.value : elem.text; + // We need to handle select boxes special if ( jQuery.nodeName( elem, "select" ) ) { var index = elem.selectedIndex, @@ -380,7 +427,7 @@ jQuery.fn = jQuery.prototype = { if ( option.selected ) { // Get the specifc value for the option - value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; + value = jQuery(option).val(); // We don't need an array for one selects if ( one ) @@ -391,25 +438,25 @@ jQuery.fn = jQuery.prototype = { } } - return values; + return values; + } // Everything else, we just grab the value - } else - return (this[0].value || "").replace(/\r/g, ""); + return (elem.value || "").replace(/\r/g, ""); } return undefined; } - if( value.constructor == Number ) + if ( typeof value === "number" ) value += ''; return this.each(function(){ if ( this.nodeType != 1 ) return; - if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) + if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) ) this.checked = (jQuery.inArray(this.value, value) >= 0 || jQuery.inArray(this.name, value) >= 0); @@ -430,7 +477,7 @@ jQuery.fn = jQuery.prototype = { }, html: function( value ) { - return value == undefined ? + return value === undefined ? (this[0] ? this[0].innerHTML : null) : @@ -442,11 +489,12 @@ jQuery.fn = jQuery.prototype = { }, eq: function( i ) { - return this.slice( i, i + 1 ); + return this.slice( i, +i + 1 ); }, slice: function() { - return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); + return this.pushStack( Array.prototype.slice.apply( this, arguments ), + "slice", Array.prototype.slice.call(arguments).join(",") ); }, map: function( callback ) { @@ -459,69 +507,29 @@ jQuery.fn = jQuery.prototype = { return this.add( this.prevObject ); }, - data: function( key, value ){ - var parts = key.split("."); - parts[1] = parts[1] ? "." + parts[1] : ""; - - if ( value === undefined ) { - var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); - - if ( data === undefined && this.length ) - data = jQuery.data( this[0], key ); - - return data === undefined && parts[1] ? - this.data( parts[0] ) : - data; - } else - return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){ - jQuery.data( this, key, value ); - }); - }, - - removeData: function( key ){ - return this.each(function(){ - jQuery.removeData( this, key ); - }); - }, - - domManip: function( args, table, reverse, callback ) { - var clone = this.length > 1, elems; - - return this.each(function(){ - if ( !elems ) { - elems = jQuery.clean( args, this.ownerDocument ); - - if ( reverse ) - elems.reverse(); - } - - var obj = this; - - if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) ) - obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") ); - - var scripts = jQuery( [] ); - - jQuery.each(elems, function(){ - var elem = clone ? - jQuery( this ).clone( true )[0] : - this; - - // execute all scripts after the elements have been injected - if ( jQuery.nodeName( elem, "script" ) ) - scripts = scripts.add( elem ); - else { - // Remove any inner scripts for later evaluation - if ( elem.nodeType == 1 ) - scripts = scripts.add( jQuery( "script", elem ).remove() ); - - // Inject the elements into the document - callback.call( obj, elem ); - } - }); + domManip: function( args, table, callback ) { + if ( this[0] ) { + var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(), + scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ), + first = fragment.firstChild, + extra = this.length > 1 ? fragment.cloneNode(true) : fragment; + + if ( first ) + for ( var i = 0, l = this.length; i < l; i++ ) + callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment ); + + if ( scripts ) + jQuery.each( scripts, evalScript ); + } - scripts.each( evalScript ); - }); + return this; + + function root( elem, cur ) { + return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ? + (elem.getElementsByTagName("tbody")[0] || + elem.appendChild(elem.ownerDocument.createElement("tbody"))) : + elem; + } } }; @@ -552,7 +560,7 @@ jQuery.extend = jQuery.fn.extend = function() { var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; // Handle a deep copy situation - if ( target.constructor == Boolean ) { + if ( typeof target === "boolean" ) { deep = target; target = arguments[1] || {}; // skip the boolean and the target @@ -560,7 +568,7 @@ jQuery.extend = jQuery.fn.extend = function() { } // Handle case when target is a string or something (possible in deep copy) - if ( typeof target != "object" && typeof target != "function" ) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) target = {}; // extend jQuery itself if only one argument is passed @@ -581,7 +589,7 @@ jQuery.extend = jQuery.fn.extend = function() { continue; // Recurse if we're merging object values - if ( deep && copy && typeof copy == "object" && !copy.nodeType ) + if ( deep && copy && typeof copy === "object" && !copy.nodeType ) target[ name ] = jQuery.extend( deep, // Never move original objects, clone them src || ( copy.length != null ? [ ] : { } ) @@ -597,11 +605,11 @@ jQuery.extend = jQuery.fn.extend = function() { return target; }; -var expando = "jQuery" + now(), uuid = 0, windowData = {}, - // exclude the following css properties to add px - exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, +// exclude the following css properties to add px +var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, // cache defaultView - defaultView = document.defaultView || {}; + defaultView = document.defaultView || {}, + toString = Object.prototype.toString; jQuery.extend({ noConflict: function( deep ) { @@ -613,10 +621,15 @@ jQuery.extend({ return jQuery; }, - // See test/unit/core.js for details concerning this function. - isFunction: function( fn ) { - return !!fn && typeof fn != "string" && !fn.nodeName && - fn.constructor != Array && /^[\s[]?function/.test( fn + "" ); + // See test/unit/core.js for details concerning isFunction. + // Since version 1.3, DOM methods and functions like alert + // aren't supported. They return false on IE (#2968). + isFunction: function( obj ) { + return toString.call(obj) === "[object Function]"; + }, + + isArray: function( obj ) { + return toString.call(obj) === "[object Array]"; }, // check if an element is in a (or is an) XML document @@ -636,10 +649,10 @@ jQuery.extend({ script = document.createElement("script"); script.type = "text/javascript"; - if ( jQuery.browser.msie ) - script.text = data; - else + if ( jQuery.support.scriptEval ) script.appendChild( document.createTextNode( data ) ); + else + script.text = data; // Use insertBefore instead of appendChild to circumvent an IE6 bug. // This arises when a base node is used (#2709). @@ -652,80 +665,12 @@ jQuery.extend({ return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); }, - cache: {}, - - data: function( elem, name, data ) { - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ]; - - // Compute a unique ID for the element - if ( !id ) - id = elem[ expando ] = ++uuid; - - // Only generate the data cache if we're - // trying to access or manipulate it - if ( name && !jQuery.cache[ id ] ) - jQuery.cache[ id ] = {}; - - // Prevent overriding the named cache with undefined values - if ( data !== undefined ) - jQuery.cache[ id ][ name ] = data; - - // Return the named cache data, or the ID for the element - return name ? - jQuery.cache[ id ][ name ] : - id; - }, - - removeData: function( elem, name ) { - elem = elem == window ? - windowData : - elem; - - var id = elem[ expando ]; - - // If we want to remove a specific section of the element's data - if ( name ) { - if ( jQuery.cache[ id ] ) { - // Remove the section of cache data - delete jQuery.cache[ id ][ name ]; - - // If we've removed all the data, remove the element's cache - name = ""; - - for ( name in jQuery.cache[ id ] ) - break; - - if ( !name ) - jQuery.removeData( elem ); - } - - // Otherwise, we want to remove all of the element's data - } else { - // Clean up the element expando - try { - delete elem[ expando ]; - } catch(e){ - // IE has trouble directly removing the expando - // but it's ok with using removeAttribute - if ( elem.removeAttribute ) - elem.removeAttribute( expando ); - } - - // Completely remove the data cache - delete jQuery.cache[ id ]; - } - }, - // args is for internal usage only each: function( object, callback, args ) { var name, i = 0, length = object.length; if ( args ) { - if ( length == undefined ) { + if ( length === undefined ) { for ( name in object ) if ( callback.apply( object[ name ], args ) === false ) break; @@ -736,7 +681,7 @@ jQuery.extend({ // A special, fast, case for the most common use of each } else { - if ( length == undefined ) { + if ( length === undefined ) { for ( name in object ) if ( callback.call( object[ name ], name, object[ name ] ) === false ) break; @@ -754,7 +699,7 @@ jQuery.extend({ value = value.call( elem, i ); // Handle passing in a number to a CSS property - return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ? + return typeof value === "number" && type == "curCSS" && !exclude.test( name ) ? value + "px" : value; }, @@ -771,7 +716,7 @@ jQuery.extend({ // internal only, use removeClass("class") remove: function( elem, classNames ) { if (elem.nodeType == 1) - elem.className = classNames != undefined ? + elem.className = classNames !== undefined ? jQuery.grep(elem.className.split(/\s+/), function(className){ return !jQuery.className.has( classNames, className ); }).join(" ") : @@ -828,30 +773,14 @@ jQuery.extend({ curCSS: function( elem, name, force ) { var ret, style = elem.style; - // A helper method for determining if an element's values are broken - function color( elem ) { - if ( !jQuery.browser.safari ) - return false; - - // defaultView is cached - var ret = defaultView.getComputedStyle( elem, null ); - return !ret || ret.getPropertyValue("color") == ""; - } - // We need to handle opacity special in IE - if ( name == "opacity" && jQuery.browser.msie ) { + if ( name == "opacity" && !jQuery.support.opacity ) { ret = jQuery.attr( style, "opacity" ); return ret == "" ? "1" : ret; } - // Opera sometimes will give the wrong display answer, this fixes it, see #2037 - if ( jQuery.browser.opera && name == "display" ) { - var save = style.outline; - style.outline = "0 solid black"; - style.outline = save; - } // Make sure we're using the right name for getting the float value if ( name.match( /float/i ) ) @@ -870,38 +799,9 @@ jQuery.extend({ var computedStyle = defaultView.getComputedStyle( elem, null ); - if ( computedStyle && !color( elem ) ) + if ( computedStyle ) ret = computedStyle.getPropertyValue( name ); - // If the element isn't reporting its values properly in Safari - // then some display: none elements are involved - else { - var swap = [], stack = [], a = elem, i = 0; - - // Locate all of the parent display: none elements - for ( ; a && color(a); a = a.parentNode ) - stack.unshift(a); - - // Go through and make them visible, but in reverse - // (It would be better if we knew the exact display type that they had) - for ( ; i < stack.length; i++ ) - if ( color( stack[ i ] ) ) { - swap[ i ] = stack[ i ].style.display; - stack[ i ].style.display = "block"; - } - - // Since we flip the display style, we have to handle that - // one special, otherwise get the value - ret = name == "display" && swap[ stack.length - 1 ] != null ? - "none" : - ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; - - // Finally, revert the display styles back - for ( i = 0; i < swap.length; i++ ) - if ( swap[ i ] != null ) - stack[ i ].style.display = swap[ i ]; - } - // We should always get a number back from opacity if ( name == "opacity" && ret == "" ) ret = "1"; @@ -936,22 +836,32 @@ jQuery.extend({ return ret; }, - clean: function( elems, context ) { - var ret = []; + clean: function( elems, context, fragment ) { context = context || document; + // !context.createElement fails in IE with an error but returns typeof 'object' - if (typeof context.createElement == 'undefined') + if ( typeof context.createElement === "undefined" ) context = context.ownerDocument || context[0] && context[0].ownerDocument || document; + // If a single string is passed in and it's a single tag + // just do a createElement and skip the rest + if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) { + var match = /^<(\w+)\s*\/?>$/.exec(elems[0]); + if ( match ) + return [ context.createElement( match[1] ) ]; + } + + var ret = [], scripts = [], div = context.createElement("div"); + jQuery.each(elems, function(i, elem){ + if ( typeof elem === "number" ) + elem += ''; + if ( !elem ) return; - if ( elem.constructor == Number ) - elem += ''; - // Convert html string into DOM nodes - if ( typeof elem == "string" ) { + if ( typeof elem === "string" ) { // Fix "XHTML"-style tags in all browsers elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? @@ -960,7 +870,7 @@ jQuery.extend({ }); // Trim whitespace, otherwise indexOf won't work as expected - var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div"); + var tags = jQuery.trim( elem ).toLowerCase(); var wrap = // option or optgroup @@ -984,7 +894,7 @@ jQuery.extend({ [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] || // IE can't serialize <link> and <script> tags normally - jQuery.browser.msie && + !jQuery.support.htmlSerialize && [ 1, "div<div>", "</div>" ] || [ 0, "", "" ]; @@ -997,7 +907,7 @@ jQuery.extend({ div = div.lastChild; // Remove IE's autoinserted <tbody> from table fragments - if ( jQuery.browser.msie ) { + if ( !jQuery.support.tbody ) { // String was a <table>, *may* have spurious <tbody> var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ? @@ -1012,26 +922,36 @@ jQuery.extend({ if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) tbody[ j ].parentNode.removeChild( tbody[ j ] ); - // IE completely kills leading whitespace when innerHTML is used - if ( /^\s/.test( elem ) ) - div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); - - } + } + // IE completely kills leading whitespace when innerHTML is used + if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) ) + div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); + elem = jQuery.makeArray( div.childNodes ); } - if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) ) - return; - - if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options ) + if ( elem.nodeType ) ret.push( elem ); - else ret = jQuery.merge( ret, elem ); }); + if ( fragment ) { + for ( var i = 0; ret[i]; i++ ) { + if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { + scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); + } else { + if ( ret[i].nodeType === 1 ) + ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) ); + fragment.appendChild( ret[i] ); + } + } + + return scripts; + } + return ret; }, @@ -1042,8 +962,7 @@ jQuery.extend({ var notxml = !jQuery.isXMLDoc( elem ), // Whether we are setting (or getting) - set = value !== undefined, - msie = jQuery.browser.msie; + set = value !== undefined; // Try to normalize/fix the name name = notxml && jQuery.props[ name ] || name; @@ -1057,7 +976,7 @@ jQuery.extend({ // Safari mis-reports the default selected property of a hidden option // Accessing the parent's selectedIndex property fixes it - if ( name == "selected" && jQuery.browser.safari ) + if ( name == "selected" && elem.parentNode ) elem.parentNode.selectedIndex; // If applicable, access the attribute via the DOM 0 way @@ -1074,17 +993,28 @@ jQuery.extend({ if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) return elem.getAttributeNode( name ).nodeValue; + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set + // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ + if ( name == "tabIndex" ) { + var attributeNode = elem.getAttributeNode( "tabIndex" ); + return attributeNode && attributeNode.specified + ? attributeNode.value + : elem.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i) + ? 0 + : undefined; + } + return elem[ name ]; } - if ( msie && notxml && name == "style" ) + if ( !jQuery.support.style && notxml && name == "style" ) return jQuery.attr( elem.style, "cssText", value ); if ( set ) // convert the value to a string (all browsers do this but IE) see #1070 elem.setAttribute( name, "" + value ); - var attr = msie && notxml && special + var attr = !jQuery.support.hrefNormalized && notxml && special // Some attributes require a special call on IE ? elem.getAttribute( name, 2 ) : elem.getAttribute( name ); @@ -1096,7 +1026,7 @@ jQuery.extend({ // elem is actually elem.style ... set the style // IE uses filters for opacity - if ( msie && name == "opacity" ) { + if ( !jQuery.support.opacity && name == "opacity" ) { if ( set ) { // IE has trouble with opacity if it does not have layout // Force it by setting the zoom level @@ -1131,8 +1061,8 @@ jQuery.extend({ if( array != null ){ var i = array.length; - //the window, strings and functions also have 'length' - if( i == null || array.split || array.setInterval || array.call ) + // The window, strings (and functions) also have 'length' + if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval ) ret[0] = array; else while( i ) @@ -1157,13 +1087,13 @@ jQuery.extend({ var i = 0, elem, pos = first.length; // Also, we need to make sure that the correct elements are being returned // (IE returns comment nodes in a '*' query) - if ( jQuery.browser.msie ) { - while ( elem = second[ i++ ] ) + if ( !jQuery.support.getAll ) { + while ( (elem = second[ i++ ]) != null ) if ( elem.nodeType != 8 ) first[ pos++ ] = elem; } else - while ( elem = second[ i++ ] ) + while ( (elem = second[ i++ ]) != null ) first[ pos++ ] = elem; return first; @@ -1218,37 +1148,21 @@ jQuery.extend({ } }); +// Use of jQuery.browser is deprecated. +// It's included for backwards compatibility and plugins, +// although they should work to migrate away. + var userAgent = navigator.userAgent.toLowerCase(); // Figure out what browser is being used jQuery.browser = { - version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1], + version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1], safari: /webkit/.test( userAgent ), opera: /opera/.test( userAgent ), msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ), mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) }; -var styleFloat = jQuery.browser.msie ? - "styleFloat" : - "cssFloat"; - -jQuery.extend({ - // Check to see if the W3C box model is being used - boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat", - - props: { - "for": "htmlFor", - "class": "className", - "float": styleFloat, - cssFloat: styleFloat, - styleFloat: styleFloat, - readonly: "readOnly", - maxlength: "maxLength", - cellspacing: "cellSpacing" - } -}); - jQuery.each({ parent: function(elem){return elem.parentNode;}, parents: function(elem){return jQuery.dir(elem,"parentNode");}, @@ -1266,7 +1180,7 @@ jQuery.each({ if ( selector && typeof selector == "string" ) ret = jQuery.multiFilter( selector, ret ); - return this.pushStack( jQuery.unique( ret ) ); + return this.pushStack( jQuery.unique( ret ), name, selector ); }; }); @@ -1302,14 +1216,16 @@ jQuery.each({ jQuery.className.remove( this, classNames ); }, - toggleClass: function( classNames ) { - jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames ); + toggleClass: function( classNames, state ) { + if( typeof state !== "boolean" ) + state = !jQuery.className.has( this, classNames ); + jQuery.className[ state ? "add" : "remove" ]( this, classNames ); }, remove: function( selector ) { - if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) { + if ( !selector || jQuery.filter( selector, [ this ] ).length ) { // Prevent memory leaks - jQuery( "*", this ).add(this).each(function(){ + jQuery( "*", this ).add([this]).each(function(){ jQuery.event.remove(this); jQuery.removeData(this); }); @@ -1332,489 +1248,1063 @@ jQuery.each({ }; }); -jQuery.each([ "Height", "Width" ], function(i, name){ - var type = name.toLowerCase(); +// Helper function used by the dimensions and offset modules +function num(elem, prop) { + return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0; +} +var expando = "jQuery" + now(), uuid = 0, windowData = {};
+
+jQuery.extend({
+ cache: {},
+
+ data: function( elem, name, data ) {
+ elem = elem == window ?
+ windowData :
+ elem;
+
+ var id = elem[ expando ];
+
+ // Compute a unique ID for the element
+ if ( !id )
+ id = elem[ expando ] = ++uuid;
+
+ // Only generate the data cache if we're
+ // trying to access or manipulate it
+ if ( name && !jQuery.cache[ id ] )
+ jQuery.cache[ id ] = {};
+
+ // Prevent overriding the named cache with undefined values
+ if ( data !== undefined )
+ jQuery.cache[ id ][ name ] = data;
+
+ // Return the named cache data, or the ID for the element
+ return name ?
+ jQuery.cache[ id ][ name ] :
+ id;
+ },
+
+ removeData: function( elem, name ) {
+ elem = elem == window ?
+ windowData :
+ elem;
+
+ var id = elem[ expando ];
+
+ // If we want to remove a specific section of the element's data
+ if ( name ) {
+ if ( jQuery.cache[ id ] ) {
+ // Remove the section of cache data
+ delete jQuery.cache[ id ][ name ];
+
+ // If we've removed all the data, remove the element's cache
+ name = "";
+
+ for ( name in jQuery.cache[ id ] )
+ break;
+
+ if ( !name )
+ jQuery.removeData( elem );
+ }
+
+ // Otherwise, we want to remove all of the element's data
+ } else {
+ // Clean up the element expando
+ try {
+ delete elem[ expando ];
+ } catch(e){
+ // IE has trouble directly removing the expando
+ // but it's ok with using removeAttribute
+ if ( elem.removeAttribute )
+ elem.removeAttribute( expando );
+ }
+
+ // Completely remove the data cache
+ delete jQuery.cache[ id ];
+ }
+ },
+ queue: function( elem, type, data ) {
+ if ( elem ){
+
+ type = (type || "fx") + "queue";
+
+ var q = jQuery.data( elem, type );
+
+ if ( !q || jQuery.isArray(data) )
+ q = jQuery.data( elem, type, jQuery.makeArray(data) );
+ else if( data )
+ q.push( data );
+
+ }
+ return q;
+ },
+
+ dequeue: function( elem, type ){
+ var queue = jQuery.queue( elem, type ),
+ fn = queue.shift();
+
+ if( !type || type === "fx" )
+ fn = queue[0];
+
+ if( fn !== undefined )
+ fn.call(elem);
+ }
+});
+
+jQuery.fn.extend({
+ data: function( key, value ){
+ var parts = key.split(".");
+ parts[1] = parts[1] ? "." + parts[1] : "";
+
+ if ( value === undefined ) {
+ var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
+
+ if ( data === undefined && this.length )
+ data = jQuery.data( this[0], key );
+
+ return data === undefined && parts[1] ?
+ this.data( parts[0] ) :
+ data;
+ } else
+ return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
+ jQuery.data( this, key, value );
+ });
+ },
+
+ removeData: function( key ){
+ return this.each(function(){
+ jQuery.removeData( this, key );
+ });
+ },
+ queue: function(type, data){
+ if ( typeof type !== "string" ) {
+ data = type;
+ type = "fx";
+ }
+
+ if ( data === undefined )
+ return jQuery.queue( this[0], type );
+
+ return this.each(function(){
+ var queue = jQuery.queue( this, type, data );
+
+ if( type == "fx" && queue.length == 1 )
+ queue[0].call(this);
+ });
+ },
+ dequeue: function(type){
+ return this.each(function(){
+ jQuery.dequeue( this, type );
+ });
+ }
+});/*! + * Sizzle CSS Selector Engine - v0.9.1 + * Copyright 2009, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){ - jQuery.fn[ type ] = function( size ) { - // Get window width or height - return this[0] == window ? - // Opera reports document.body.client[Width/Height] properly in both quirks and standards - jQuery.browser.opera && document.body[ "client" + name ] || +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g, + done = 0, + toString = Object.prototype.toString; - // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths) - jQuery.browser.safari && window[ "inner" + name ] || +var Sizzle = function(selector, context, results, seed) { + results = results || []; + context = context || document; - // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode - document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] : + if ( context.nodeType !== 1 && context.nodeType !== 9 ) + return []; + + if ( !selector || typeof selector !== "string" ) { + return results; + } - // Get document width or height - this[0] == document ? - // Either scroll[Width/Height] or offset[Width/Height], whichever is greater - Math.max( - Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]), - Math.max(document.body["offset" + name], document.documentElement["offset" + name]) - ) : + var parts = [], m, set, checkSet, check, mode, extra, prune = true; + + // Reset the position of the chunker regexp (start from head) + chunker.lastIndex = 0; + + while ( (m = chunker.exec(selector)) !== null ) { + parts.push( m[1] ); + + if ( m[2] ) { + extra = RegExp.rightContext; + break; + } + } - // Get or set width or height on the element - size == undefined ? - // Get width or height on the element - (this.length ? jQuery.css( this[0], type ) : null) : + if ( parts.length > 1 && Expr.match.POS.exec( selector ) ) { + if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { + var later = "", match; - // Set the width or height on the element (default to pixels if value is unitless) - this.css( type, size.constructor == String ? size : size + "px" ); - }; -}); + // Position selectors must be done after the filter + while ( (match = Expr.match.POS.exec( selector )) ) { + later += match[0]; + selector = selector.replace( Expr.match.POS, "" ); + } -// Helper function used by the dimensions and offset modules -function num(elem, prop) { - return elem[0] && parseInt( jQuery.curCSS(elem[0], prop, true), 10 ) || 0; -}var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ? - "(?:[\\w*_-]|\\\\.)" : - "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)", - quickChild = new RegExp("^>\\s*(" + chars + "+)"), - quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"), - quickClass = new RegExp("^([#.]?)(" + chars + "*)"); + set = Sizzle.filter( later, Sizzle( /\s$/.test(selector) ? selector + "*" : selector, context ) ); + } else { + set = Expr.relative[ parts[0] ] ? + [ context ] : + Sizzle( parts.shift(), context ); -jQuery.extend({ - expr: { - "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);}, - "#": function(a,i,m){return a.getAttribute("id")==m[2];}, - ":": { - // Position Checks - lt: function(a,i,m){return i<m[3]-0;}, - gt: function(a,i,m){return i>m[3]-0;}, - nth: function(a,i,m){return m[3]-0==i;}, - eq: function(a,i,m){return m[3]-0==i;}, - first: function(a,i){return i==0;}, - last: function(a,i,m,r){return i==r.length-1;}, - even: function(a,i){return i%2==0;}, - odd: function(a,i){return i%2;}, - - // Child Checks - "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;}, - "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;}, - "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");}, - - // Parent Checks - parent: function(a){return a.firstChild;}, - empty: function(a){return !a.firstChild;}, - - // Text Check - contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;}, - - // Visibility - visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";}, - hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";}, - - // Form attributes - enabled: function(a){return !a.disabled;}, - disabled: function(a){return a.disabled;}, - checked: function(a){return a.checked;}, - selected: function(a){return a.selected||jQuery.attr(a,"selected");}, - - // Form elements - text: function(a){return "text"==a.type;}, - radio: function(a){return "radio"==a.type;}, - checkbox: function(a){return "checkbox"==a.type;}, - file: function(a){return "file"==a.type;}, - password: function(a){return "password"==a.type;}, - submit: function(a){return "submit"==a.type;}, - image: function(a){return "image"==a.type;}, - reset: function(a){return "reset"==a.type;}, - button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");}, - input: function(a){return /input|select|textarea|button/i.test(a.nodeName);}, - - // :has() - has: function(a,i,m){return jQuery.find(m[3],a).length;}, - - // :header - header: function(a){return /h\d/i.test(a.nodeName);}, - - // :animated - animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;} - } - }, - - // The regular expressions that power the parsing engine - parse: [ - // Match: [@value='test'], [@foo] - /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, - - // Match: :contains('foo') - /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, - - // Match: :even, :last-child, #id, .class - new RegExp("^([:.#]*)(" + chars + "+)") - ], - - multiFilter: function( expr, elems, not ) { - var old, cur = []; - - while ( expr && expr != old ) { - old = expr; - var f = jQuery.filter( expr, elems, not ); - expr = f.t.replace(/^\s*,\s*/, "" ); - cur = not ? elems = f.r : jQuery.merge( cur, f.r ); - } - - return cur; - }, - - find: function( t, context ) { - // Quickly handle non-string expressions - if ( typeof t != "string" ) - return [ t ]; - - // check to make sure context is a DOM element or a document - if ( context && context.nodeType != 1 && context.nodeType != 9) - return [ ]; - - // Set the correct context (if none is provided) - context = context || document; + while ( parts.length ) { + var tmpSet = []; - // Initialize the search - var ret = [context], done = [], last, nodeName; + selector = parts.shift(); + if ( Expr.relative[ selector ] ) + selector += parts.shift(); - // Continue while a selector expression exists, and while - // we're no longer looping upon ourselves - while ( t && last != t ) { - var r = []; - last = t; + for ( var i = 0, l = set.length; i < l; i++ ) { + Sizzle( selector, set[i], tmpSet ); + } - t = jQuery.trim(t); + set = tmpSet; + } + } + } else { + var ret = seed ? + { expr: parts.pop(), set: makeArray(seed) } : + Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context ); + set = Sizzle.filter( ret.expr, ret.set ); + + if ( parts.length > 0 ) { + checkSet = makeArray(set); + } else { + prune = false; + } - var foundToken = false, + while ( parts.length ) { + var cur = parts.pop(), pop = cur; - // An attempt at speeding up child selectors that - // point to a specific element tag - re = quickChild, + if ( !Expr.relative[ cur ] ) { + cur = ""; + } else { + pop = parts.pop(); + } - m = re.exec(t); + if ( pop == null ) { + pop = context; + } - if ( m ) { - nodeName = m[1].toUpperCase(); + Expr.relative[ cur ]( checkSet, pop, isXML(context) ); + } + } - // Perform our own iteration and filter - for ( var i = 0; ret[i]; i++ ) - for ( var c = ret[i].firstChild; c; c = c.nextSibling ) - if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) ) - r.push( c ); + if ( !checkSet ) { + checkSet = set; + } - ret = r; - t = t.replace( re, "" ); - if ( t.indexOf(" ") == 0 ) continue; - foundToken = true; - } else { - re = /^([>+~])\s*(\w*)/i; + if ( !checkSet ) { + throw "Syntax error, unrecognized expression: " + (cur || selector); + } - if ( (m = re.exec(t)) != null ) { - r = []; + if ( toString.call(checkSet) === "[object Array]" ) { + if ( !prune ) { + results.push.apply( results, checkSet ); + } else if ( context.nodeType === 1 ) { + for ( var i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { + results.push( set[i] ); + } + } + } else { + for ( var i = 0; checkSet[i] != null; i++ ) { + if ( checkSet[i] && checkSet[i].nodeType === 1 ) { + results.push( set[i] ); + } + } + } + } else { + makeArray( checkSet, results ); + } - var merge = {}; - nodeName = m[2].toUpperCase(); - m = m[1]; + if ( extra ) { + Sizzle( extra, context, results, seed ); + } - for ( var j = 0, rl = ret.length; j < rl; j++ ) { - var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild; - for ( ; n; n = n.nextSibling ) - if ( n.nodeType == 1 ) { - var id = jQuery.data(n); + return results; +}; - if ( m == "~" && merge[id] ) break; +Sizzle.matches = function(expr, set){ + return Sizzle(expr, null, null, set); +}; - if (!nodeName || n.nodeName.toUpperCase() == nodeName ) { - if ( m == "~" ) merge[id] = true; - r.push( n ); - } +Sizzle.find = function(expr, context){ + var set, match; + + if ( !expr ) { + return []; + } + + for ( var i = 0, l = Expr.order.length; i < l; i++ ) { + var type = Expr.order[i], match; + + if ( (match = Expr.match[ type ].exec( expr )) ) { + var left = RegExp.leftContext; + + if ( left.substr( left.length - 1 ) !== "\\" ) { + match[1] = (match[1] || "").replace(/\\/g, ""); + set = Expr.find[ type ]( match, context ); + if ( set != null ) { + expr = expr.replace( Expr.match[ type ], "" ); + break; + } + } + } + } + + if ( !set ) { + set = context.getElementsByTagName("*"); + } + + return {set: set, expr: expr}; +}; + +Sizzle.filter = function(expr, set, inplace, not){ + var old = expr, result = [], curLoop = set, match, anyFound; + + while ( expr && set.length ) { + for ( var type in Expr.filter ) { + if ( (match = Expr.match[ type ].exec( expr )) != null ) { + var filter = Expr.filter[ type ], goodArray = null, goodPos = 0, found, item; + anyFound = false; + + if ( curLoop == result ) { + result = []; + } + + if ( Expr.preFilter[ type ] ) { + match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not ); + + if ( !match ) { + anyFound = found = true; + } else if ( match === true ) { + continue; + } else if ( match[0] === true ) { + goodArray = []; + var last = null, elem; + for ( var i = 0; (elem = curLoop[i]) !== undefined; i++ ) { + if ( elem && last !== elem ) { + goodArray.push( elem ); + last = elem; + } + } + } + } - if ( m == "+" ) break; + if ( match ) { + for ( var i = 0; (item = curLoop[i]) !== undefined; i++ ) { + if ( item ) { + if ( goodArray && item != goodArray[goodPos] ) { + goodPos++; + } + + found = filter( item, match, goodPos, goodArray ); + var pass = not ^ !!found; + + if ( inplace && found != null ) { + if ( pass ) { + anyFound = true; + } else { + curLoop[i] = false; + } + } else if ( pass ) { + result.push( item ); + anyFound = true; } + } + } + } + + if ( found !== undefined ) { + if ( !inplace ) { + curLoop = result; } - ret = r; + expr = expr.replace( Expr.match[ type ], "" ); + + if ( !anyFound ) { + return []; + } - // And remove the token - t = jQuery.trim( t.replace( re, "" ) ); - foundToken = true; + break; } } + } - // See if there's still an expression, and that we haven't already - // matched a token - if ( t && !foundToken ) { - // Handle multiple expressions - if ( !t.indexOf(",") ) { - // Clean the result set - if ( context == ret[0] ) ret.shift(); - - // Merge the result sets - done = jQuery.merge( done, ret ); + expr = expr.replace(/\s*,\s*/, ""); - // Reset the context - r = ret = [context]; + // Improper expression + if ( expr == old ) { + if ( anyFound == null ) { + throw "Syntax error, unrecognized expression: " + expr; + } else { + break; + } + } - // Touch up the selector string - t = " " + t.substr(1,t.length); + old = expr; + } - } else { - // Optimize for the case nodeName#idName - var re2 = quickID; - var m = re2.exec(t); + return curLoop; +}; - // Re-organize the results, so that they're consistent - if ( m ) { - m = [ 0, m[2], m[3], m[1] ]; +var Expr = Sizzle.selectors = { + order: [ "ID", "NAME", "TAG" ], + match: { + ID: /#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/, + CLASS: /\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/, + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/, + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, + TAG: /^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/, + CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/, + PSEUDO: /:((?:[\w\u00c0-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/ + }, + attrMap: { + "class": "className", + "for": "htmlFor" + }, + attrHandle: { + href: function(elem){ + return elem.getAttribute("href"); + } + }, + relative: { + "+": function(checkSet, part){ + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + var cur = elem.previousSibling; + while ( cur && cur.nodeType !== 1 ) { + cur = cur.previousSibling; + } + checkSet[i] = typeof part === "string" ? + cur || false : + cur === part; + } + } - } else { - // Otherwise, do a traditional filter check for - // ID, class, and element selectors - re2 = quickClass; - m = re2.exec(t); + if ( typeof part === "string" ) { + Sizzle.filter( part, checkSet, true ); + } + }, + ">": function(checkSet, part, isXML){ + if ( typeof part === "string" && !/\W/.test(part) ) { + part = isXML ? part : part.toUpperCase(); + + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + var parent = elem.parentNode; + checkSet[i] = parent.nodeName === part ? parent : false; } + } + } else { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + checkSet[i] = typeof part === "string" ? + elem.parentNode : + elem.parentNode === part; + } + } - m[2] = m[2].replace(/\\/g, ""); + if ( typeof part === "string" ) { + Sizzle.filter( part, checkSet, true ); + } + } + }, + "": function(checkSet, part, isXML){ + var doneName = "done" + (done++), checkFn = dirCheck; - var elem = ret[ret.length-1]; + if ( !part.match(/\W/) ) { + var nodeCheck = part = isXML ? part : part.toUpperCase(); + checkFn = dirNodeCheck; + } - // Try to do a global search by ID, where we can - if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) { - // Optimization for HTML document case - var oid = elem.getElementById(m[2]); + checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); + }, + "~": function(checkSet, part, isXML){ + var doneName = "done" + (done++), checkFn = dirCheck; - // Do a quick check for the existence of the actual ID attribute - // to avoid selecting by the name attribute in IE - // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form - if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] ) - oid = jQuery('[@id="'+m[2]+'"]', elem)[0]; + if ( typeof part === "string" && !part.match(/\W/) ) { + var nodeCheck = part = isXML ? part : part.toUpperCase(); + checkFn = dirNodeCheck; + } - // Do a quick check for node name (where applicable) so - // that div#foo searches will be really fast - ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : []; - } else { - // We need to find all descendant elements - for ( var i = 0; ret[i]; i++ ) { - // Grab the tag name being searched for - var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2]; + checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML); + } + }, + find: { + ID: function(match, context){ + if ( context.getElementById ) { + var m = context.getElementById(match[1]); + return m ? [m] : []; + } + }, + NAME: function(match, context){ + return context.getElementsByName ? context.getElementsByName(match[1]) : null; + }, + TAG: function(match, context){ + return context.getElementsByTagName(match[1]); + } + }, + preFilter: { + CLASS: function(match, curLoop, inplace, result, not){ + match = " " + match[1].replace(/\\/g, "") + " "; + + for ( var i = 0; curLoop[i]; i++ ) { + if ( not ^ (" " + curLoop[i].className + " ").indexOf(match) >= 0 ) { + if ( !inplace ) + result.push( curLoop[i] ); + } else if ( inplace ) { + curLoop[i] = false; + } + } - // Handle IE7 being really dumb about <object>s - if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" ) - tag = "param"; + return false; + }, + ID: function(match){ + return match[1].replace(/\\/g, ""); + }, + TAG: function(match, curLoop){ + for ( var i = 0; !curLoop[i]; i++ ){} + return isXML(curLoop[i]) ? match[1] : match[1].toUpperCase(); + }, + CHILD: function(match){ + if ( match[1] == "nth" ) { + // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' + var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( + match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" || + !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); + + // calculate the numbers (first)n+(last) including if they are negative + match[2] = (test[1] + (test[2] || 1)) - 0; + match[3] = test[3] - 0; + } - r = jQuery.merge( r, ret[i].getElementsByTagName( tag )); - } + // TODO: Move to normal caching system + match[0] = "done" + (done++); - // It's faster to filter by class and be done with it - if ( m[1] == "." ) - r = jQuery.classFilter( r, m[2] ); + return match; + }, + ATTR: function(match){ + var name = match[1]; + + if ( Expr.attrMap[name] ) { + match[1] = Expr.attrMap[name]; + } - // Same with ID filtering - if ( m[1] == "#" ) { - var tmp = []; + if ( match[2] === "~=" ) { + match[4] = " " + match[4] + " "; + } - // Try to find the element with the ID - for ( var i = 0; r[i]; i++ ) - if ( r[i].getAttribute("id") == m[2] ) { - tmp = [ r[i] ]; - break; - } + return match; + }, + PSEUDO: function(match, curLoop, inplace, result, not){ + if ( match[1] === "not" ) { + // If we're dealing with a complex expression, or a simple one + if ( match[3].match(chunker).length > 1 ) { + match[3] = Sizzle(match[3], null, null, curLoop); + } else { + var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); + if ( !inplace ) { + result.push.apply( result, ret ); + } + return false; + } + } else if ( Expr.match.POS.test( match[0] ) ) { + return true; + } + + return match; + }, + POS: function(match){ + match.unshift( true ); + return match; + } + }, + filters: { + enabled: function(elem){ + return elem.disabled === false && elem.type !== "hidden"; + }, + disabled: function(elem){ + return elem.disabled === true; + }, + checked: function(elem){ + return elem.checked === true; + }, + selected: function(elem){ + // Accessing this property makes selected-by-default + // options in Safari work properly + elem.parentNode.selectedIndex; + return elem.selected === true; + }, + parent: function(elem){ + return !!elem.firstChild; + }, + empty: function(elem){ + return !elem.firstChild; + }, + has: function(elem, i, match){ + return !!Sizzle( match[3], elem ).length; + }, + header: function(elem){ + return /h\d/i.test( elem.nodeName ); + }, + text: function(elem){ + return "text" === elem.type; + }, + radio: function(elem){ + return "radio" === elem.type; + }, + checkbox: function(elem){ + return "checkbox" === elem.type; + }, + file: function(elem){ + return "file" === elem.type; + }, + password: function(elem){ + return "password" === elem.type; + }, + submit: function(elem){ + return "submit" === elem.type; + }, + image: function(elem){ + return "image" === elem.type; + }, + reset: function(elem){ + return "reset" === elem.type; + }, + button: function(elem){ + return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON"; + }, + input: function(elem){ + return /input|select|textarea|button/i.test(elem.nodeName); + } + }, + setFilters: { + first: function(elem, i){ + return i === 0; + }, + last: function(elem, i, match, array){ + return i === array.length - 1; + }, + even: function(elem, i){ + return i % 2 === 0; + }, + odd: function(elem, i){ + return i % 2 === 1; + }, + lt: function(elem, i, match){ + return i < match[3] - 0; + }, + gt: function(elem, i, match){ + return i > match[3] - 0; + }, + nth: function(elem, i, match){ + return match[3] - 0 == i; + }, + eq: function(elem, i, match){ + return match[3] - 0 == i; + } + }, + filter: { + CHILD: function(elem, match){ + var type = match[1], parent = elem.parentNode; - r = tmp; - } + var doneName = "child" + parent.childNodes.length; + + if ( parent && (!parent[ doneName ] || !elem.nodeIndex) ) { + var count = 1; + + for ( var node = parent.firstChild; node; node = node.nextSibling ) { + if ( node.nodeType == 1 ) { + node.nodeIndex = count++; + } + } + + parent[ doneName ] = count - 1; + } + + if ( type == "first" ) { + return elem.nodeIndex == 1; + } else if ( type == "last" ) { + return elem.nodeIndex == parent[ doneName ]; + } else if ( type == "only" ) { + return parent[ doneName ] == 1; + } else if ( type == "nth" ) { + var add = false, first = match[2], last = match[3]; + + if ( first == 1 && last == 0 ) { + return true; + } - ret = r; + if ( first == 0 ) { + if ( elem.nodeIndex == last ) { + add = true; } + } else if ( (elem.nodeIndex - last) % first == 0 && (elem.nodeIndex - last) / first >= 0 ) { + add = true; + } - t = t.replace( re2, "" ); + return add; + } + }, + PSEUDO: function(elem, match, i, array){ + var name = match[1], filter = Expr.filters[ name ]; + + if ( filter ) { + return filter( elem, i, match, array ); + } else if ( name === "contains" ) { + return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0; + } else if ( name === "not" ) { + var not = match[3]; + + for ( var i = 0, l = not.length; i < l; i++ ) { + if ( not[i] === elem ) { + return false; + } } + return true; } + }, + ID: function(elem, match){ + return elem.nodeType === 1 && elem.getAttribute("id") === match; + }, + TAG: function(elem, match){ + return (match === "*" && elem.nodeType === 1) || elem.nodeName === match; + }, + CLASS: function(elem, match){ + return match.test( elem.className ); + }, + ATTR: function(elem, match){ + var result = Expr.attrHandle[ match[1] ] ? Expr.attrHandle[ match[1] ]( elem ) : elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4]; + return result == null ? + false : + type === "=" ? + value === check : + type === "*=" ? + value.indexOf(check) >= 0 : + type === "~=" ? + (" " + value + " ").indexOf(check) >= 0 : + !match[4] ? + result : + type === "!=" ? + value != check : + type === "^=" ? + value.indexOf(check) === 0 : + type === "$=" ? + value.substr(value.length - check.length) === check : + type === "|=" ? + value === check || value.substr(0, check.length + 1) === check + "-" : + false; + }, + POS: function(elem, match, i, array){ + var name = match[2], filter = Expr.setFilters[ name ]; - // If a selector string still exists - if ( t ) { - // Attempt to filter it - var val = jQuery.filter(t,r); - ret = r = val.r; - t = jQuery.trim(val.t); + if ( filter ) { + return filter( elem, i, match, array ); } } + } +}; - // An error occurred with the selector; - // just return an empty set instead - if ( t ) - ret = []; +for ( var type in Expr.match ) { + Expr.match[ type ] = RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); +} - // Remove the root context - if ( ret && context == ret[0] ) - ret.shift(); +var makeArray = function(array, results) { + array = Array.prototype.slice.call( array ); - // And combine the results - done = jQuery.merge( done, ret ); + if ( results ) { + results.push.apply( results, array ); + return results; + } + + return array; +}; - return done; - }, +// Perform a simple check to determine if the browser is capable of +// converting a NodeList to an array using builtin methods. +try { + Array.prototype.slice.call( document.documentElement.childNodes ); + +// Provide a fallback method if it does not work +} catch(e){ + makeArray = function(array, results) { + var ret = results || []; - classFilter: function(r,m,not){ - m = " " + m + " "; - var tmp = []; - for ( var i = 0; r[i]; i++ ) { - var pass = (" " + r[i].className + " ").indexOf( m ) >= 0; - if ( !not && pass || not && !pass ) - tmp.push( r[i] ); + if ( toString.call(array) === "[object Array]" ) { + Array.prototype.push.apply( ret, array ); + } else { + if ( typeof array.length === "number" ) { + for ( var i = 0, l = array.length; i < l; i++ ) { + ret.push( array[i] ); + } + } else { + for ( var i = 0; array[i]; i++ ) { + ret.push( array[i] ); + } + } } - return tmp; - }, - filter: function(t,r,not) { - var last; + return ret; + }; +} + +// Check to see if the browser returns elements by name when +// querying by getElementById (and provide a workaround) +(function(){ + // We're going to inject a fake input element with a specified name + var form = document.createElement("form"), + id = "script" + (new Date).getTime(); + form.innerHTML = "<input name='" + id + "'/>"; + + // Inject it into the root element, check its status, and remove it quickly + var root = document.documentElement; + root.insertBefore( form, root.firstChild ); + + // The workaround has to do additional checks after a getElementById + // Which slows things down for other browsers (hence the branching) + if ( !!document.getElementById( id ) ) { + Expr.find.ID = function(match, context){ + if ( context.getElementById ) { + var m = context.getElementById(match[1]); + return m ? m.id === match[1] || m.getAttributeNode && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : []; + } + }; - // Look for common filter expressions - while ( t && t != last ) { - last = t; + Expr.filter.ID = function(elem, match){ + var node = elem.getAttributeNode && elem.getAttributeNode("id"); + return elem.nodeType === 1 && node && node.nodeValue === match; + }; + } - var p = jQuery.parse, m; + root.removeChild( form ); +})(); - for ( var i = 0; p[i]; i++ ) { - m = p[i].exec( t ); +(function(){ + // Check to see if the browser returns only elements + // when doing getElementsByTagName("*") - if ( m ) { - // Remove what we just matched - t = t.substring( m[0].length ); + // Create a fake element + var div = document.createElement("div"); + div.appendChild( document.createComment("") ); - m[2] = m[2].replace(/\\/g, ""); - break; + // Make sure no comments are found + if ( div.getElementsByTagName("*").length > 0 ) { + Expr.find.TAG = function(match, context){ + var results = context.getElementsByTagName(match[1]); + + // Filter out possible comments + if ( match[1] === "*" ) { + var tmp = []; + + for ( var i = 0; results[i]; i++ ) { + if ( results[i].nodeType === 1 ) { + tmp.push( results[i] ); + } } + + results = tmp; } - if ( !m ) - break; + return results; + }; + } - // :not() is a special case that can be optimized by - // keeping it out of the expression list - if ( m[1] == ":" && m[2] == "not" ) - // optimize if only one selector found (most common case) - r = isSimple.test( m[3] ) ? - jQuery.filter(m[3], r, true).r : - jQuery( r ).not( m[3] ); - - // We can get a big speed boost by filtering by class here - else if ( m[1] == "." ) - r = jQuery.classFilter(r, m[2], not); - - else if ( m[1] == "[" ) { - var tmp = [], type = m[3]; - - for ( var i = 0, rl = r.length; i < rl; i++ ) { - var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ]; - - if ( z == null || /href|src|selected/.test(m[2]) ) - z = jQuery.attr(a,m[2]) || ''; - - if ( (type == "" && !!z || - type == "=" && z == m[5] || - type == "!=" && z != m[5] || - type == "^=" && z && !z.indexOf(m[5]) || - type == "$=" && z.substr(z.length - m[5].length) == m[5] || - (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not ) - tmp.push( a ); - } + // Check to see if an attribute returns normalized href attributes + div.innerHTML = "<a href='#'></a>"; + if ( div.firstChild.getAttribute("href") !== "#" ) { + Expr.attrHandle.href = function(elem){ + return elem.getAttribute("href", 2); + }; + } +})(); - r = tmp; +if ( document.querySelectorAll ) (function(){ + var oldSizzle = Sizzle; + + Sizzle = function(query, context, extra, seed){ + context = context || document; - // We can get a speed boost by handling nth-child here - } else if ( m[1] == ":" && m[2] == "nth-child" ) { - var merge = {}, tmp = [], - // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' - test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( - m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" || - !/\D/.test(m[3]) && "0n+" + m[3] || m[3]), - // calculate the numbers (first)n+(last) including if they are negative - first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0; + if ( !seed && context.nodeType === 9 ) { + try { + return makeArray( context.querySelectorAll(query), extra ); + } catch(e){} + } + + return oldSizzle(query, context, extra, seed); + }; - // loop through all the elements left in the jQuery object - for ( var i = 0, rl = r.length; i < rl; i++ ) { - var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode); + Sizzle.find = oldSizzle.find; + Sizzle.filter = oldSizzle.filter; + Sizzle.selectors = oldSizzle.selectors; + Sizzle.matches = oldSizzle.matches; +})(); - if ( !merge[id] ) { - var c = 1; +if ( document.documentElement.getElementsByClassName ) { + Expr.order.splice(1, 0, "CLASS"); + Expr.find.CLASS = function(match, context) { + return context.getElementsByClassName(match[1]); + }; +} - for ( var n = parentNode.firstChild; n; n = n.nextSibling ) - if ( n.nodeType == 1 ) - n.nodeIndex = c++; +function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + elem = elem[dir]; + var match = false; + + while ( elem && elem.nodeType ) { + var done = elem[doneName]; + if ( done ) { + match = checkSet[ done ]; + break; + } - merge[id] = true; - } + if ( elem.nodeType === 1 && !isXML ) + elem[doneName] = i; - var add = false; + if ( elem.nodeName === cur ) { + match = elem; + break; + } - if ( first == 0 ) { - if ( node.nodeIndex == last ) - add = true; - } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 ) - add = true; + elem = elem[dir]; + } - if ( add ^ not ) - tmp.push( node ); + checkSet[i] = match; + } + } +} + +function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { + for ( var i = 0, l = checkSet.length; i < l; i++ ) { + var elem = checkSet[i]; + if ( elem ) { + elem = elem[dir]; + var match = false; + + while ( elem && elem.nodeType ) { + if ( elem[doneName] ) { + match = checkSet[ elem[doneName] ]; + break; } - r = tmp; + if ( elem.nodeType === 1 ) { + if ( !isXML ) + elem[doneName] = i; - // Otherwise, find the expression to execute - } else { - var fn = jQuery.expr[ m[1] ]; - if ( typeof fn == "object" ) - fn = fn[ m[2] ]; + if ( typeof cur !== "string" ) { + if ( elem === cur ) { + match = true; + break; + } - if ( typeof fn == "string" ) - fn = eval("false||function(a,i){return " + fn + ";}"); + } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { + match = elem; + break; + } + } - // Execute it against the current filter - r = jQuery.grep( r, function(elem, i){ - return fn(elem, i, m, r); - }, not ); + elem = elem[dir]; } + + checkSet[i] = match; } + } +} - // Return an array of filtered elements (r) - // and the modified expression string (t) - return { r: r, t: t }; - }, +var contains = document.compareDocumentPosition ? function(a, b){ + return a.compareDocumentPosition(b) & 16; +} : function(a, b){ + return a !== b && (a.contains ? a.contains(b) : true); +}; - dir: function( elem, dir ){ - var matched = [], - cur = elem[dir]; - while ( cur && cur != document ) { - if ( cur.nodeType == 1 ) - matched.push( cur ); - cur = cur[dir]; - } - return matched; - }, +var isXML = function(elem){ + return elem.documentElement && !elem.body || + elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; +}; - nth: function(cur,result,dir,elem){ - result = result || 1; - var num = 0; +// EXPOSE +jQuery.find = Sizzle; +jQuery.filter = Sizzle.filter; +jQuery.expr = Sizzle.selectors; +jQuery.expr[":"] = jQuery.expr.filters; - for ( ; cur; cur = cur[dir] ) - if ( cur.nodeType == 1 && ++num == result ) - break; +Sizzle.selectors.filters.hidden = function(elem){ + return "hidden" === elem.type || + jQuery.css(elem, "display") === "none" || + jQuery.css(elem, "visibility") === "hidden"; +}; - return cur; - }, +Sizzle.selectors.filters.visible = function(elem){ + return "hidden" !== elem.type && + jQuery.css(elem, "display") !== "none" && + jQuery.css(elem, "visibility") !== "hidden"; +}; - sibling: function( n, elem ) { - var r = []; +Sizzle.selectors.filters.animated = function(elem){ + return jQuery.grep(jQuery.timers, function(fn){ + return elem === fn.elem; + }).length; +}; - for ( ; n; n = n.nextSibling ) { - if ( n.nodeType == 1 && n != elem ) - r.push( n ); - } +jQuery.multiFilter = function( expr, elems, not ) { + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return Sizzle.matches(expr, elems); +}; - return r; +jQuery.dir = function( elem, dir ){ + var matched = [], cur = elem[dir]; + while ( cur && cur != document ) { + if ( cur.nodeType == 1 ) + matched.push( cur ); + cur = cur[dir]; } -}); + return matched; +}; + +jQuery.nth = function(cur, result, dir, elem){ + result = result || 1; + var num = 0; + + for ( ; cur; cur = cur[dir] ) + if ( cur.nodeType == 1 && ++num == result ) + break; + + return cur; +}; + +jQuery.sibling = function(n, elem){ + var r = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType == 1 && n != elem ) + r.push( n ); + } + + return r; +}; + +return; + +window.Sizzle = Sizzle; + +})(); /* * A number of helper functions used for managing events. - * Many of the ideas behind this code orignated from + * Many of the ideas behind this code originated from * Dean Edwards' addEvent library. */ jQuery.event = { @@ -1827,7 +2317,7 @@ jQuery.event = { // For whatever reason, IE has trouble passing the window object // around, causing it to be cloned in the process - if ( jQuery.browser.msie && elem.setInterval ) + if ( elem.setInterval && elem != window ) elem = window; // Make sure that the function being executed has a unique ID @@ -1835,15 +2325,12 @@ jQuery.event = { handler.guid = this.guid++; // if data is passed, bind to handler - if( data != undefined ) { + if ( data !== undefined ) { // Create temporary function pointer to original handler var fn = handler; // Create unique handler function, wrapped around original handler - handler = this.proxy( fn, function() { - // Pass arguments and context to original handler - return fn.apply(this, arguments); - }); + handler = this.proxy( fn ); // Store data in unique handler handler.data = data; @@ -1854,8 +2341,9 @@ jQuery.event = { handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){ // Handle the second event of a trigger and when // an event is called after a page has unloaded - if ( typeof jQuery != "undefined" && !jQuery.event.triggered ) - return jQuery.event.handle.apply(arguments.callee.elem, arguments); + return typeof jQuery !== "undefined" && !jQuery.event.triggered ? + jQuery.event.handle.apply(arguments.callee.elem, arguments) : + undefined; }); // Add elem as a property of the handle function // This is to prevent a memory leak with non-native @@ -1866,12 +2354,15 @@ jQuery.event = { // jQuery(...).bind("mouseover mouseout", fn); jQuery.each(types.split(/\s+/), function(index, type) { // Namespaced event handlers - var parts = type.split("."); - type = parts[0]; - handler.type = parts[1]; + var namespaces = type.split("."); + type = namespaces.shift(); + handler.type = namespaces.slice().sort().join("."); // Get the current list of functions bound to this event var handlers = events[type]; + + if ( jQuery.event.specialAll[type] ) + jQuery.event.specialAll[type].setup.call(elem, data, namespaces); // Init the event handler queue if (!handlers) { @@ -1880,7 +2371,7 @@ jQuery.event = { // Check for a special event handler // Only use addEventListener/attachEvent if the special // events handler returns false - if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) { + if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem, data, namespaces) === false ) { // Bind the global event handler to the element if (elem.addEventListener) elem.addEventListener(type, handle, false); @@ -1913,7 +2404,7 @@ jQuery.event = { if ( events ) { // Unbind all events for the element - if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") ) + if ( types === undefined || (typeof types === "string" && types.charAt(0) == ".") ) for ( var type in events ) this.remove( elem, type + (types || "") ); else { @@ -1927,8 +2418,9 @@ jQuery.event = { // jQuery(...).unbind("mouseover mouseout", fn); jQuery.each(types.split(/\s+/), function(index, type){ // Namespaced event handlers - var parts = type.split("."); - type = parts[0]; + var namespaces = type.split("."); + type = namespaces.shift(); + var namespace = RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); if ( events[type] ) { // remove the given handler for the given type @@ -1937,15 +2429,18 @@ jQuery.event = { // remove all handlers for the given type else - for ( handler in events[type] ) + for ( var handle in events[type] ) // Handle the removal of namespaced events - if ( !parts[1] || events[type][handler].type == parts[1] ) - delete events[type][handler]; + if ( namespace.test(events[type][handle].type) ) + delete events[type][handle]; + + if ( jQuery.event.specialAll[type] ) + jQuery.event.specialAll[type].teardown.call(elem, namespaces); // remove generic event handler if no more handlers exist for ( ret in events[type] ) break; if ( !ret ) { - if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) { + if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem, namespaces) === false ) { if (elem.removeEventListener) elem.removeEventListener(type, jQuery.data(elem, "handle"), false); else if (elem.detachEvent) @@ -1969,97 +2464,95 @@ jQuery.event = { } }, - trigger: function(type, data, elem, donative, extra) { - // Clone the incoming data, if any - data = jQuery.makeArray(data); + // bubbling is internal + trigger: function( event, data, elem, bubbling ) { + // Event object or event type + var type = event.type || event; + + if( !bubbling ){ + event = typeof event === "object" ? + // jQuery.Event object + event[expando] ? event : + // Object literal + jQuery.extend( jQuery.Event(type), event ) : + // Just the event type (string) + jQuery.Event(type); + + if ( type.indexOf("!") >= 0 ) { + event.type = type = type.slice(0, -1); + event.exclusive = true; + } - if ( type.indexOf("!") >= 0 ) { - type = type.slice(0, -1); - var exclusive = true; - } + // Handle a global trigger + if ( !elem ) { + // Don't bubble custom events when global (to avoid too much overhead) + event.stopPropagation(); + // Only trigger if we've ever bound an event for it + if ( this.global[type] ) + jQuery.each( jQuery.cache, function(){ + if ( this.events && this.events[type] ) + jQuery.event.trigger( event, data, this.handle.elem ); + }); + } - // Handle a global trigger - if ( !elem ) { - // Only trigger if we've ever bound an event for it - if ( this.global[type] ) - jQuery("*").add([window, document]).trigger(type, data); + // Handle triggering a single element - // Handle triggering a single element - } else { // don't do events on text and comment nodes - if ( elem.nodeType == 3 || elem.nodeType == 8 ) + if ( !elem || elem.nodeType == 3 || elem.nodeType == 8 ) return undefined; + + // Clean up in case it is reused + event.result = undefined; + event.target = elem; + + // Clone the incoming data, if any + data = jQuery.makeArray(data); + data.unshift( event ); + } - var val, ret, fn = jQuery.isFunction( elem[ type ] || null ), - // Check to see if we need to provide a fake event, or not - event = !data[0] || !data[0].preventDefault; - - // Pass along a fake event - if ( event ) { - data.unshift({ - type: type, - target: elem, - preventDefault: function(){}, - stopPropagation: function(){}, - timeStamp: now() - }); - data[0][expando] = true; // no need to fix fake event - } + event.currentTarget = elem; - // Enforce the right trigger type - data[0].type = type; - if ( exclusive ) - data[0].exclusive = true; - - // Trigger the event, it is assumed that "handle" is a function - var handle = jQuery.data(elem, "handle"); - if ( handle ) - val = handle.apply( elem, data ); - - // Handle triggering native .onfoo handlers (and on links since we don't call .click() for links) - if ( (!fn || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) - val = false; - - // Extra functions don't get the custom event object - if ( event ) - data.shift(); - - // Handle triggering of extra function - if ( extra && jQuery.isFunction( extra ) ) { - // call the extra function and tack the current return value on the end for possible inspection - ret = extra.apply( elem, val == null ? data : data.concat( val ) ); - // if anything is returned, give it precedence and have it overwrite the previous value - if (ret !== undefined) - val = ret; - } + // Trigger the event, it is assumed that "handle" is a function + var handle = jQuery.data(elem, "handle"); + if ( handle ) + handle.apply( elem, data ); - // Trigger the native events (except for clicks on links) - if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) { - this.triggered = true; - try { - elem[ type ](); - // prevent IE from throwing an error for some hidden elements - } catch (e) {} - } + // Handle triggering native .onfoo handlers (and on links since we don't call .click() for links) + if ( (!elem[type] || (jQuery.nodeName(elem, 'a') && type == "click")) && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) + event.result = false; - this.triggered = false; + // Trigger the native events (except for clicks on links) + if ( !bubbling && elem[type] && !event.isDefaultPrevented() && !(jQuery.nodeName(elem, 'a') && type == "click") ) { + this.triggered = true; + try { + elem[ type ](); + // prevent IE from throwing an error for some hidden elements + } catch (e) {} } - return val; + this.triggered = false; + + if ( !event.isPropagationStopped() ) { + var parent = elem.parentNode || elem.ownerDocument; + if ( parent ) + jQuery.event.trigger(event, data, parent, true); + } }, handle: function(event) { // returned undefined or false - var val, ret, namespace, all, handlers; + var all, handlers; event = arguments[0] = jQuery.event.fix( event || window.event ); // Namespaced event handlers - namespace = event.type.split("."); - event.type = namespace[0]; - namespace = namespace[1]; + var namespaces = event.type.split("."); + event.type = namespaces.shift(); + // Cache this now, all = true means, any handler - all = !namespace && !event.exclusive; + all = !namespaces.length && !event.exclusive; + + var namespace = RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); handlers = ( jQuery.data(this, "events") || {} )[event.type]; @@ -2067,61 +2560,44 @@ jQuery.event = { var handler = handlers[j]; // Filter the functions by class - if ( all || handler.type == namespace ) { + if ( all || namespace.test(handler.type) ) { // Pass in a reference to the handler function itself // So that we can later remove it event.handler = handler; event.data = handler.data; - ret = handler.apply( this, arguments ); + var ret = handler.apply(this, arguments); - if ( val !== false ) - val = ret; - - if ( ret === false ) { - event.preventDefault(); - event.stopPropagation(); + if( ret !== undefined ){ + event.result = ret; + if ( ret === false ) { + event.preventDefault(); + event.stopPropagation(); + } } + + if( event.isImmediatePropagationStopped() ) + break; + } } - - return val; }, + props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "), + fix: function(event) { - if ( event[expando] == true ) + if ( event[expando] ) return event; // store a copy of the original event object // and "clone" to set read-only properties var originalEvent = event; - event = { originalEvent: originalEvent }; - var props = "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" "); - for ( var i=props.length; i; i-- ) - event[ props[i] ] = originalEvent[ props[i] ]; - - // Mark it as fixed - event[expando] = true; - - // add preventDefault and stopPropagation since - // they will not work on the clone - event.preventDefault = function() { - // if preventDefault exists run it on the original event - if (originalEvent.preventDefault) - originalEvent.preventDefault(); - // otherwise set the returnValue property of the original event to false (IE) - originalEvent.returnValue = false; - }; - event.stopPropagation = function() { - // if stopPropagation exists run it on the original event - if (originalEvent.stopPropagation) - originalEvent.stopPropagation(); - // otherwise set the cancelBubble property of the original event to true (IE) - originalEvent.cancelBubble = true; - }; + event = jQuery.Event( originalEvent ); - // Fix timeStamp - event.timeStamp = event.timeStamp || now(); + for ( var i = this.props.length, prop; i; ){ + prop = this.props[ --i ]; + event[ prop ] = originalEvent[ prop ]; + } // Fix target property, if necessary if ( !event.target ) @@ -2159,6 +2635,7 @@ jQuery.event = { }, proxy: function( fn, proxy ){ + proxy = proxy || function(){ return fn.apply(this, arguments); }; // Set the guid of unique handler to the same of original handler, so it can be removed proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++; // So proxy can be declared as an argument @@ -2167,60 +2644,128 @@ jQuery.event = { special: { ready: { - setup: function() { - // Make sure the ready event is setup - bindReady(); - return; - }, - - teardown: function() { return; } - }, - - mouseenter: { - setup: function() { - if ( jQuery.browser.msie ) return false; - jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler); - return true; + // Make sure the ready event is setup + setup: bindReady, + teardown: function() {} + } + }, + + specialAll: { + live: { + setup: function( selector, namespaces ){ + jQuery.event.add( this, namespaces[0], liveHandler ); }, + teardown: function( namespaces ){ + if ( namespaces.length ) { + var remove = 0, name = RegExp("(^|\\.)" + namespaces[0] + "(\\.|$)"); + + jQuery.each( (jQuery.data(this, "events").live || {}), function(){ + if ( name.test(this.type) ) + remove++; + }); + + if ( remove < 1 ) + jQuery.event.remove( this, namespaces[0], liveHandler ); + } + } + } + } +}; - teardown: function() { - if ( jQuery.browser.msie ) return false; - jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler); - return true; - }, +jQuery.Event = function( src ){ + // Allow instantiation without the 'new' keyword + if( !this.preventDefault ) + return new jQuery.Event(src); + + // Event object + if( src && src.type ){ + this.originalEvent = src; + this.type = src.type; + this.timeStamp = src.timeStamp; + // Event type + }else + this.type = src; + + if( !this.timeStamp ) + this.timeStamp = now(); + + // Mark it as fixed + this[expando] = true; +}; - handler: function(event) { - // If we actually just moused on to a sub-element, ignore it - if ( withinElement(event, this) ) return true; - // Execute the right handlers by setting the event type to mouseenter - event.type = "mouseenter"; - return jQuery.event.handle.apply(this, arguments); - } - }, +function returnFalse(){ + return false; +} +function returnTrue(){ + return true; +} - mouseleave: { - setup: function() { - if ( jQuery.browser.msie ) return false; - jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler); - return true; - }, +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +jQuery.Event.prototype = { + preventDefault: function() { + this.isDefaultPrevented = returnTrue; - teardown: function() { - if ( jQuery.browser.msie ) return false; - jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler); - return true; - }, + var e = this.originalEvent; + if( !e ) + return; + // if preventDefault exists run it on the original event + if (e.preventDefault) + e.preventDefault(); + // otherwise set the returnValue property of the original event to false (IE) + e.returnValue = false; + }, + stopPropagation: function() { + this.isPropagationStopped = returnTrue; - handler: function(event) { - // If we actually just moused on to a sub-element, ignore it - if ( withinElement(event, this) ) return true; - // Execute the right handlers by setting the event type to mouseleave - event.type = "mouseleave"; - return jQuery.event.handle.apply(this, arguments); - } - } + var e = this.originalEvent; + if( !e ) + return; + // if stopPropagation exists run it on the original event + if (e.stopPropagation) + e.stopPropagation(); + // otherwise set the cancelBubble property of the original event to true (IE) + e.cancelBubble = true; + }, + stopImmediatePropagation:function(){ + this.isImmediatePropagationStopped = returnTrue; + this.stopPropagation(); + }, + isDefaultPrevented: returnFalse, + isPropagationStopped: returnFalse, + isImmediatePropagationStopped: returnFalse +}; +// Checks if an event happened on an element within another element +// Used in jQuery.event.special.mouseenter and mouseleave handlers +var withinElement = function(event) { + // Check if mouse(over|out) are still within the same parent element + var parent = event.relatedTarget; + // Traverse up the tree + while ( parent && parent != this ) + try { parent = parent.parentNode; } + catch(e) { parent = this; } + + if( parent != this ){ + // set the correct event type + event.type = event.data; + // handle event if we actually just moused on to a non sub-element + jQuery.event.handle.apply( this, arguments ); } }; + +jQuery.each({ + mouseover: 'mouseenter', + mouseout: 'mouseleave' +}, function( orig, fix ){ + jQuery.event.special[ fix ] = { + setup: function(){ + jQuery.event.add( this, orig, withinElement, fix ); + }, + teardown: function(){ + jQuery.event.remove( this, orig, withinElement ); + } + }; +}); jQuery.fn.extend({ bind: function( type, data, fn ) { @@ -2245,14 +2790,20 @@ jQuery.fn.extend({ }); }, - trigger: function( type, data, fn ) { + trigger: function( type, data ) { return this.each(function(){ - jQuery.event.trigger( type, data, this, true, fn ); + jQuery.event.trigger( type, data, this ); }); }, - triggerHandler: function( type, data, fn ) { - return this[0] && jQuery.event.trigger( type, data, this[0], false, fn ); + triggerHandler: function( type, data ) { + if( this[0] ){ + var event = jQuery.Event(type); + event.preventDefault(); + event.stopPropagation(); + jQuery.event.trigger( event, data, this[0] ); + return event.result; + } }, toggle: function( fn ) { @@ -2276,7 +2827,7 @@ jQuery.fn.extend({ }, hover: function(fnOver, fnOut) { - return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut); + return this.mouseenter(fnOver).mouseleave(fnOut); }, ready: function(fn) { @@ -2291,12 +2842,52 @@ jQuery.fn.extend({ // Otherwise, remember the function for later else // Add the function to the wait list - jQuery.readyList.push( function() { return fn.call(this, jQuery); } ); + jQuery.readyList.push( fn ); return this; + }, + + live: function( type, fn ){ + var proxy = jQuery.event.proxy( fn ); + proxy.guid += this.selector + type; + + jQuery(document).bind( liveConvert(type, this.selector), this.selector, proxy ); + + return this; + }, + + die: function( type, fn ){ + jQuery(document).unbind( liveConvert(type, this.selector), fn ? { guid: fn.guid + this.selector + type } : null ); + return this; } }); +function liveHandler( event ){ + var check = RegExp("(^|\\.)" + event.type + "(\\.|$)"), + stop = true, + elems = []; + + jQuery.each(jQuery.data(this, "events").live || [], function(i, fn){ + if ( check.test(fn.type) ) { + var elem = jQuery(event.target).closest(fn.data)[0]; + if ( elem ) + elems.push({ elem: elem, fn: fn }); + } + }); + + jQuery.each(elems, function(){ + if ( !event.isImmediatePropagationStopped() && + this.fn.call(this.elem, event, this.fn.data) === false ) + stop = false; + }); + + return stop; +} + +function liveConvert(type, selector){ + return ["live", type, selector.replace(/\./g, "`").replace(/ /g, "|")].join("."); +} + jQuery.extend({ isReady: false, readyList: [], @@ -2311,7 +2902,7 @@ jQuery.extend({ if ( jQuery.readyList ) { // Execute all of them jQuery.each( jQuery.readyList, function(){ - this.call( document ); + this.call( document, jQuery ); }); // Reset the list of functions @@ -2330,53 +2921,39 @@ function bindReady(){ if ( readyBound ) return; readyBound = true; - // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event - if ( document.addEventListener && !jQuery.browser.opera) + // Mozilla, Opera and webkit nightlies currently support this event + if ( document.addEventListener ) { // Use the handy event callback - document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); - - // If IE is used and is not in a frame - // Continually check to see if the document is ready - if ( jQuery.browser.msie && window == top ) (function(){ - if (jQuery.isReady) return; - try { - // If IE is used, use the trick by Diego Perini - // http://javascript.nwbox.com/IEContentLoaded/ - document.documentElement.doScroll("left"); - } catch( error ) { - setTimeout( arguments.callee, 0 ); - return; - } - // and execute any waiting functions - jQuery.ready(); - })(); - - if ( jQuery.browser.opera ) - document.addEventListener( "DOMContentLoaded", function () { - if (jQuery.isReady) return; - for (var i = 0; i < document.styleSheets.length; i++) - if (document.styleSheets[i].disabled) { - setTimeout( arguments.callee, 0 ); - return; - } - // and execute any waiting functions + document.addEventListener( "DOMContentLoaded", function(){ + document.removeEventListener( "DOMContentLoaded", arguments.callee, false ); jQuery.ready(); - }, false); - - if ( jQuery.browser.safari ) { - var numStyles; - (function(){ - if (jQuery.isReady) return; - if ( document.readyState != "loaded" && document.readyState != "complete" ) { - setTimeout( arguments.callee, 0 ); - return; + }, false ); + + // If IE event model is used + } else if ( document.attachEvent ) { + // ensure firing before onload, + // maybe late but safe also for iframes + document.attachEvent("onreadystatechange", function(){ + if ( document.readyState === "complete" ) { + document.detachEvent( "onreadystatechange", arguments.callee ); + jQuery.ready(); } - if ( numStyles === undefined ) - numStyles = jQuery("style, link[rel=stylesheet]").length; - if ( document.styleSheets.length != numStyles ) { + }); + + // If IE and not an iframe + // continually check to see if the document is ready + if ( document.documentElement.doScroll && !window.frameElement ) (function(){ + if ( jQuery.isReady ) return; + + try { + // If IE is used, use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + document.documentElement.doScroll("left"); + } catch( error ) { setTimeout( arguments.callee, 0 ); return; } + // and execute any waiting functions jQuery.ready(); })(); @@ -2387,8 +2964,8 @@ function bindReady(){ } jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + - "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + - "submit,keydown,keypress,keyup,error").split(","), function(i, name){ + "mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," + + "change,select,submit,keydown,keypress,keyup,error").split(","), function(i, name){ // Handle event binding jQuery.fn[name] = function(fn){ @@ -2396,29 +2973,134 @@ jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + }; }); -// Checks if an event happened on an element within another element -// Used in jQuery.event.special.mouseenter and mouseleave handlers -var withinElement = function(event, elem) { - // Check if mouse(over|out) are still within the same parent element - var parent = event.relatedTarget; - // Traverse up the tree - while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; } - // Return true if we actually just moused on to a sub-element - return parent == elem; -}; - // Prevent memory leaks in IE // And prevent errors on refresh with events like mouseover in other browsers // Window isn't included so as not to unbind existing unload events -jQuery(window).bind("unload", function() { - jQuery("*").add(document).unbind(); -}); +jQuery( window ).bind( 'unload', function(){ + for ( var id in jQuery.cache ) + // Skip the window + if ( id != 1 && jQuery.cache[ id ].handle ) + jQuery.event.remove( jQuery.cache[ id ].handle.elem ); +}); +(function(){ + + jQuery.support = {}; + + var root = document.documentElement, + script = document.createElement("script"), + div = document.createElement("div"), + id = "script" + (new Date).getTime(); + + div.style.display = "none"; + div.innerHTML = ' <link/><table></table><a href="/a" style="color:red;float:left;opacity:.5;">a</a><select><option>text</option></select><object><param/></object>'; + + var all = div.getElementsByTagName("*"), + a = div.getElementsByTagName("a")[0]; + + // Can't get basic test support + if ( !all || !all.length || !a ) { + return; + } + + jQuery.support = { + // IE strips leading whitespace when .innerHTML is used + leadingWhitespace: div.firstChild.nodeType == 3, + + // Make sure that tbody elements aren't automatically inserted + // IE will insert them into empty tables + tbody: !div.getElementsByTagName("tbody").length, + + // Make sure that you can get all elements in an <object> element + // IE 7 always returns no results + objectAll: !!div.getElementsByTagName("object")[0] + .getElementsByTagName("*").length, + + // Make sure that link elements get serialized correctly by innerHTML + // This requires a wrapper element in IE + htmlSerialize: !!div.getElementsByTagName("link").length, + + // Get the style information from getAttribute + // (IE uses .cssText insted) + style: /red/.test( a.getAttribute("style") ), + + // Make sure that URLs aren't manipulated + // (IE normalizes it by default) + hrefNormalized: a.getAttribute("href") === "/a", + + // Make sure that element opacity exists + // (IE uses filter instead) + opacity: a.style.opacity === "0.5", + + // Verify style float existence + // (IE uses styleFloat instead of cssFloat) + cssFloat: !!a.style.cssFloat, + + // Will be defined later + scriptEval: false, + noCloneEvent: true, + boxModel: null + }; + + script.type = "text/javascript"; + try { + script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); + } catch(e){} + + root.insertBefore( script, root.firstChild ); + + // Make sure that the execution of code works by injecting a script + // tag with appendChild/createTextNode + // (IE doesn't support this, fails, and uses .text instead) + if ( window[ id ] ) { + jQuery.support.scriptEval = true; + delete window[ id ]; + } + + root.removeChild( script ); + + if ( div.attachEvent && div.fireEvent ) { + div.attachEvent("onclick", function(){ + // Cloning a node shouldn't copy over any + // bound event handlers (IE does this) + jQuery.support.noCloneEvent = false; + div.detachEvent("onclick", arguments.callee); + }); + div.cloneNode(true).fireEvent("onclick"); + } + + // Figure out if the W3C box model works as expected + // document.body must exist before we can do this + jQuery(function(){ + var div = document.createElement("div"); + div.style.width = "1px"; + div.style.paddingLeft = "1px"; + + document.body.appendChild( div ); + jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2; + document.body.removeChild( div ); + }); +})(); + +var styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat"; + +jQuery.props = { + "for": "htmlFor", + "class": "className", + "float": styleFloat, + cssFloat: styleFloat, + styleFloat: styleFloat, + readonly: "readOnly", + maxlength: "maxLength", + cellspacing: "cellSpacing", + rowspan: "rowSpan", + tabindex: "tabIndex" +}; jQuery.fn.extend({ // Keep a copy of the old load _load: jQuery.fn.load, load: function( url, params, callback ) { - if ( typeof url != 'string' ) + if ( typeof url !== "string" ) return this._load( url ); var off = url.indexOf(" "); @@ -2427,8 +3109,6 @@ jQuery.fn.extend({ url = url.slice(0, off); } - callback = callback || function(){}; - // Default to a GET request var type = "GET"; @@ -2441,7 +3121,7 @@ jQuery.fn.extend({ params = null; // Otherwise, build a param string - } else { + } else if( typeof params === "object" ) { params = jQuery.param( params ); type = "POST"; } @@ -2471,7 +3151,8 @@ jQuery.fn.extend({ // If not, just inject the full result res.responseText ); - self.each( callback, [res.responseText, status, res] ); + if( callback ) + self.each( callback, [res.responseText, status, res] ); } }); return this; @@ -2482,8 +3163,7 @@ jQuery.fn.extend({ }, serializeArray: function() { return this.map(function(){ - return jQuery.nodeName(this, "form") ? - jQuery.makeArray(this.elements) : this; + return this.elements ? jQuery.makeArray(this.elements) : this; }) .filter(function(){ return this.name && !this.disabled && @@ -2493,7 +3173,7 @@ jQuery.fn.extend({ .map(function(i, elem){ var val = jQuery(this).val(); return val == null ? null : - val.constructor == Array ? + jQuery.isArray(val) ? jQuery.map( val, function(val, i){ return {name: elem.name, value: val}; }) : @@ -2512,6 +3192,7 @@ jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".sp var jsc = now(); jQuery.extend({ + get: function( url, data, callback, type ) { // shift arguments if data argument was ommited if ( jQuery.isFunction( data ) ) { @@ -2559,13 +3240,21 @@ jQuery.extend({ url: location.href, global: true, type: "GET", - timeout: 0, contentType: "application/x-www-form-urlencoded", processData: true, async: true, + /* + timeout: 0, data: null, username: null, password: null, + */ + // Create the request object; Microsoft failed to properly + // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available + // This function can be overriden by calling jQuery.ajaxSetup + xhr:function(){ + return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); + }, accepts: { xml: "application/xml, text/xml", html: "text/html", @@ -2588,7 +3277,7 @@ jQuery.extend({ type = s.type.toUpperCase(); // convert data if not already a string - if ( s.data && s.processData && typeof s.data != "string" ) + if ( s.data && s.processData && typeof s.data !== "string" ) s.data = jQuery.param(s.data); // Handle JSONP Parameter Callbacks @@ -2651,12 +3340,13 @@ jQuery.extend({ jQuery.event.trigger( "ajaxStart" ); // Matches an absolute URL, and saves the domain - var remote = /^(?:\w+:)?\/\/([^\/?#]+)/; + var parts = /^(\w+:)?\/\/([^\/?#]+)/.exec( s.url ); // If we're requesting a remote document // and trying to load JSON or Script with a GET - if ( s.dataType == "script" && type == "GET" - && remote.test(s.url) && remote.exec(s.url)[1] != location.host ){ + if ( s.dataType == "script" && type == "GET" && parts + && ( parts[1] && parts[1] != location.protocol || parts[2] != location.host )){ + var head = document.getElementsByTagName("head")[0]; var script = document.createElement("script"); script.src = s.url; @@ -2687,9 +3377,8 @@ jQuery.extend({ var requestDone = false; - // Create the request object; Microsoft failed to properly - // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available - var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); + // Create the request object + var xhr = s.xhr(); // Open the socket // Passing null username, generates a login popup on Opera (#2865) @@ -2718,10 +3407,11 @@ jQuery.extend({ s.accepts._default ); } catch(e){} - // Allow custom headers/mimetypes + // Allow custom headers/mimetypes and early abort if ( s.beforeSend && s.beforeSend(xhr, s) === false ) { - // cleanup active request counter - s.global && jQuery.active--; + // Handle the global AJAX counter + if ( s.global && ! --jQuery.active ) + jQuery.event.trigger( "ajaxStop" ); // close opended socket xhr.abort(); return false; @@ -2732,8 +3422,18 @@ jQuery.extend({ // Wait for a response to come back var onreadystatechange = function(isTimeout){ + // The request was aborted, clear the interval and decrement jQuery.active + if (xhr.readyState == 0) { + if (ival) { + // clear poll interval + clearInterval(ival); + ival = null; + // Handle the global AJAX counter + if ( s.global && ! --jQuery.active ) + jQuery.event.trigger( "ajaxStop" ); + } // The transfer is complete and the data is available, or the request timed out - if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) { + } else if ( !requestDone && xhr && (xhr.readyState == 4 || isTimeout == "timeout") ) { requestDone = true; // clear poll interval @@ -2742,16 +3442,16 @@ jQuery.extend({ ival = null; } - status = isTimeout == "timeout" && "timeout" || - !jQuery.httpSuccess( xhr ) && "error" || - s.ifModified && jQuery.httpNotModified( xhr, s.url ) && "notmodified" || + status = isTimeout == "timeout" ? "timeout" : + !jQuery.httpSuccess( xhr ) ? "error" : + s.ifModified && jQuery.httpNotModified( xhr, s.url ) ? "notmodified" : "success"; if ( status == "success" ) { // Watch for, and catch, XML document parse errors try { // process the data (runs the xml through httpData regardless of callback) - data = jQuery.httpData( xhr, s.dataType, s.dataFilter ); + data = jQuery.httpData( xhr, s.dataType, s ); } catch(e) { status = "parsererror"; } @@ -2792,11 +3492,12 @@ jQuery.extend({ setTimeout(function(){ // Check to see if the request is still happening if ( xhr ) { - // Cancel the request - xhr.abort(); - if( !requestDone ) onreadystatechange( "timeout" ); + + // Cancel the request + if ( xhr ) + xhr.abort(); } }, s.timeout); } @@ -2857,8 +3558,7 @@ jQuery.extend({ try { // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 return !xhr.status && location.protocol == "file:" || - ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 || - jQuery.browser.safari && xhr.status == undefined; + ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223; } catch(e){} return false; }, @@ -2869,13 +3569,12 @@ jQuery.extend({ var xhrRes = xhr.getResponseHeader("Last-Modified"); // Firefox always returns 200. check Last-Modified date - return xhr.status == 304 || xhrRes == jQuery.lastModified[url] || - jQuery.browser.safari && xhr.status == undefined; + return xhr.status == 304 || xhrRes == jQuery.lastModified[url]; } catch(e){} return false; }, - httpData: function( xhr, type, filter ) { + httpData: function( xhr, type, s ) { var ct = xhr.getResponseHeader("content-type"), xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0, data = xml ? xhr.responseXML : xhr.responseText; @@ -2884,31 +3583,40 @@ jQuery.extend({ throw "parsererror"; // Allow a pre-filtering function to sanitize the response - if( filter ) - data = filter( data, type ); + // s != null is checked to keep backwards compatibility + if( s && s.dataFilter ) + data = s.dataFilter( data, type ); - // If the type is "script", eval it in global context - if ( type == "script" ) - jQuery.globalEval( data ); + // The filter can actually parse the response + if( typeof data === "string" ){ - // Get the JavaScript object, if JSON is used. - if ( type == "json" ) - data = eval("(" + data + ")"); + // If the type is "script", eval it in global context + if ( type == "script" ) + jQuery.globalEval( data ); + // Get the JavaScript object, if JSON is used. + if ( type == "json" ) + data = window["eval"]("(" + data + ")"); + } + return data; }, // Serialize an array of form elements or a set of // key/values into a query string param: function( a ) { - var s = []; + var s = [ ]; + + function add( key, value ){ + s[ s.length ] = encodeURIComponent(key) + '=' + encodeURIComponent(value); + }; // If an array was passed in, assume that it is an array // of form elements - if ( a.constructor == Array || a.jquery ) + if ( jQuery.isArray(a) || a.jquery ) // Serialize the form elements jQuery.each( a, function(){ - s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) ); + add( this.name, this.value ); }); // Otherwise, assume that it's an object of key/value pairs @@ -2916,83 +3624,99 @@ jQuery.extend({ // Serialize the key/values for ( var j in a ) // If the value is an array then the key names need to be repeated - if ( a[j] && a[j].constructor == Array ) + if ( jQuery.isArray(a[j]) ) jQuery.each( a[j], function(){ - s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) ); + add( j, this ); }); else - s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) ); + add( j, jQuery.isFunction(a[j]) ? a[j]() : a[j] ); // Return the resulting serialization return s.join("&").replace(/%20/g, "+"); } }); +var elemdisplay = {}, + fxAttrs = [ + // height animations + [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ], + // width animations + [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], + // opacity animations + [ "opacity" ] + ]; + +function genFx( type, num ){ + var obj = {}; + jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function(){ + obj[ this ] = type; + }); + return obj; +} + jQuery.fn.extend({ show: function(speed,callback){ - return speed ? - this.animate({ - height: "show", width: "show", opacity: "show" - }, speed, callback) : - - this.filter(":hidden").each(function(){ - this.style.display = this.oldblock || ""; - if ( jQuery.css(this,"display") == "none" ) { - var elem = jQuery("<" + this.tagName + " />").appendTo("body"); - this.style.display = elem.css("display"); - // handle an edge condition where css is - div { display:none; } or similar - if (this.style.display == "none") - this.style.display = "block"; - elem.remove(); + if ( speed ) { + return this.animate( genFx("show", 3), speed, callback); + } else { + for ( var i = 0, l = this.length; i < l; i++ ){ + var old = jQuery.data(this[i], "olddisplay"); + + this[i].style.display = old || ""; + + if ( jQuery.css(this[i], "display") === "none" ) { + var tagName = this[i].tagName, display; + + if ( elemdisplay[ tagName ] ) { + display = elemdisplay[ tagName ]; + } else { + var elem = jQuery("<" + tagName + " />").appendTo("body"); + + display = elem.css("display"); + if ( display === "none" ) + display = "block"; + + elem.remove(); + + elemdisplay[ tagName ] = display; + } + + this[i].style.display = jQuery.data(this[i], "olddisplay", display); } - }).end(); + } + + return this; + } }, hide: function(speed,callback){ - return speed ? - this.animate({ - height: "hide", width: "hide", opacity: "hide" - }, speed, callback) : - - this.filter(":visible").each(function(){ - this.oldblock = this.oldblock || jQuery.css(this,"display"); - this.style.display = "none"; - }).end(); + if ( speed ) { + return this.animate( genFx("hide", 3), speed, callback); + } else { + for ( var i = 0, l = this.length; i < l; i++ ){ + var old = jQuery.data(this[i], "olddisplay"); + if ( !old && old !== "none" ) + jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display")); + this[i].style.display = "none"; + } + return this; + } }, // Save the old toggle function _toggle: jQuery.fn.toggle, toggle: function( fn, fn2 ){ + var bool = typeof fn === "boolean"; + return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ? this._toggle.apply( this, arguments ) : - fn ? - this.animate({ - height: "toggle", width: "toggle", opacity: "toggle" - }, fn, fn2) : + fn == null || bool ? this.each(function(){ - jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ](); - }); - }, - - slideDown: function(speed,callback){ - return this.animate({height: "show"}, speed, callback); - }, - - slideUp: function(speed,callback){ - return this.animate({height: "hide"}, speed, callback); - }, - - slideToggle: function(speed, callback){ - return this.animate({height: "toggle"}, speed, callback); - }, - - fadeIn: function(speed, callback){ - return this.animate({opacity: "show"}, speed, callback); - }, - - fadeOut: function(speed, callback){ - return this.animate({opacity: "hide"}, speed, callback); + var state = bool ? fn : jQuery(this).is(":hidden"); + jQuery(this)[ state ? "show" : "hide" ](); + }) : + this.animate(genFx("toggle", 3), fn, fn2); }, fadeTo: function(speed,to,callback){ @@ -3003,17 +3727,16 @@ jQuery.fn.extend({ var optall = jQuery.speed(speed, easing, callback); return this[ optall.queue === false ? "each" : "queue" ](function(){ - if ( this.nodeType != 1) - return false; - + var opt = jQuery.extend({}, optall), p, - hidden = jQuery(this).is(":hidden"), self = this; - + hidden = this.nodeType == 1 && jQuery(this).is(":hidden"), + self = this; + for ( p in prop ) { if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden ) return opt.complete.call(this); - if ( p == "height" || p == "width" ) { + if ( ( p == "height" || p == "width" ) && this.style ) { // Store display property opt.display = jQuery.css(this, "display"); @@ -3062,27 +3785,6 @@ jQuery.fn.extend({ }); }, - queue: function(type, fn){ - if ( jQuery.isFunction(type) || ( type && type.constructor == Array )) { - fn = type; - type = "fx"; - } - - if ( !type || (typeof type == "string" && !fn) ) - return queue( this[0], type ); - - return this.each(function(){ - if ( fn.constructor == Array ) - queue(this, type, fn); - else { - queue(this, type).push( fn ); - - if ( queue(this, type).length == 1 ) - fn.call(this); - } - }); - }, - stop: function(clearQueue, gotoEnd){ var timers = jQuery.timers; @@ -3109,46 +3811,31 @@ jQuery.fn.extend({ }); -var queue = function( elem, type, array ) { - if ( elem ){ - - type = type || "fx"; - - var q = jQuery.data( elem, type + "queue" ); - - if ( !q || array ) - q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) ); - - } - return q; -}; - -jQuery.fn.dequeue = function(type){ - type = type || "fx"; - - return this.each(function(){ - var q = queue(this, type); - - q.shift(); - - if ( q.length ) - q[0].call( this ); - }); -}; +// Generate shortcuts for custom animations +jQuery.each({ + slideDown: genFx("show", 1), + slideUp: genFx("hide", 1), + slideToggle: genFx("toggle", 1), + fadeIn: { opacity: "show" }, + fadeOut: { opacity: "hide" } +}, function( name, props ){ + jQuery.fn[ name ] = function( speed, callback ){ + return this.animate( props, speed, callback ); + }; +}); jQuery.extend({ speed: function(speed, easing, fn) { - var opt = speed && speed.constructor == Object ? speed : { + var opt = typeof speed === "object" ? speed : { complete: fn || !fn && easing || jQuery.isFunction( speed ) && speed, duration: speed, - easing: fn && easing || easing && easing.constructor != Function && easing + easing: fn && easing || easing && !jQuery.isFunction(easing) && easing }; - opt.duration = (opt.duration && opt.duration.constructor == Number ? - opt.duration : - jQuery.fx.speeds[opt.duration]) || jQuery.fx.speeds.def; + opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration : + jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default; // Queueing opt.old = opt.complete; @@ -3195,13 +3882,13 @@ jQuery.fx.prototype = { (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this ); // Set display property to block for height/width animations - if ( this.prop == "height" || this.prop == "width" ) + if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style ) this.elem.style.display = "block"; }, // Get the current size cur: function(force){ - if ( this.elem[this.prop] != null && this.elem.style[this.prop] == null ) + if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) return this.elem[ this.prop ]; var r = parseFloat(jQuery.css(this.elem, this.prop, force)); @@ -3216,7 +3903,6 @@ jQuery.fx.prototype = { this.unit = unit || this.unit || "px"; this.now = this.start; this.pos = this.state = 0; - this.update(); var self = this; function t(gotoEnd){ @@ -3227,7 +3913,7 @@ jQuery.fx.prototype = { jQuery.timers.push(t); - if ( jQuery.timerId == null ) { + if ( t() && jQuery.timerId == null ) { jQuery.timerId = setInterval(function(){ var timers = jQuery.timers; @@ -3250,12 +3936,9 @@ jQuery.fx.prototype = { this.options.show = true; // Begin the animation - this.custom(0, this.cur()); - // Make sure that we start at a small width/height to avoid any // flash of content - if ( this.prop == "width" || this.prop == "height" ) - this.elem.style[this.prop] = "1px"; + this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur()); // Start by showing the element jQuery(this.elem).show(); @@ -3275,7 +3958,7 @@ jQuery.fx.prototype = { step: function(gotoEnd){ var t = now(); - if ( gotoEnd || t > this.options.duration + this.startTime ) { + if ( gotoEnd || t >= this.options.duration + this.startTime ) { this.now = this.end; this.pos = this.state = 1; this.update(); @@ -3300,7 +3983,7 @@ jQuery.fx.prototype = { // Hide the element if the "hide" operation was done if ( this.options.hide ) - this.elem.style.display = "none"; + jQuery(this.elem).hide(); // Reset the properties, if the item has been hidden or shown if ( this.options.hide || this.options.show ) @@ -3335,124 +4018,106 @@ jQuery.extend( jQuery.fx, { slow: 600, fast: 200, // Default speed - def: 400 + _default: 400 }, step: { - scrollLeft: function(fx){ - fx.elem.scrollLeft = fx.now; - }, - - scrollTop: function(fx){ - fx.elem.scrollTop = fx.now; - }, opacity: function(fx){ jQuery.attr(fx.elem.style, "opacity", fx.now); }, _default: function(fx){ - fx.elem.style[ fx.prop ] = fx.now + fx.unit; + if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) + fx.elem.style[ fx.prop ] = fx.now + fx.unit; + else + fx.elem[ fx.prop ] = fx.now; } } }); -// The Offset Method -// Originally By Brandon Aaron, part of the Dimension Plugin -// http://jquery.com/plugins/project/dimensions -jQuery.fn.offset = function() { - var left = 0, top = 0, elem = this[0], results; - - if ( elem ) with ( jQuery.browser ) { - var parent = elem.parentNode, - offsetChild = elem, - offsetParent = elem.offsetParent, - doc = elem.ownerDocument, - safari2 = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent), - css = jQuery.curCSS, - fixed = css(elem, "position") == "fixed"; - - // Use getBoundingClientRect if available - if ( elem.getBoundingClientRect ) { - var box = elem.getBoundingClientRect(); - - // Add the document scroll offsets - add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft), - box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop)); - - // IE adds the HTML element's border, by default it is medium which is 2px - // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; } - // IE 7 standards mode, the border is always 2px - // This border/offset is typically represented by the clientLeft and clientTop properties - // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS - // Therefore this method will be off by 2px in IE while in quirksmode - add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop ); - - // Otherwise loop through the offsetParents and parentNodes - } else { - - // Initial element offsets - add( elem.offsetLeft, elem.offsetTop ); - - // Get parent offsets - while ( offsetParent ) { - // Add offsetParent offsets - add( offsetParent.offsetLeft, offsetParent.offsetTop ); +if ( document.documentElement["getBoundingClientRect"] ) + jQuery.fn.offset = function() { + if ( !this[0] ) return { top: 0, left: 0 }; + if ( this[0] === this[0].ownerDocument.body ) return jQuery.offset.bodyOffset( this[0] ); + var box = this[0].getBoundingClientRect(), doc = this[0].ownerDocument, body = doc.body, docElem = doc.documentElement, + clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, + top = box.top + (self.pageYOffset || jQuery.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop, + left = box.left + (self.pageXOffset || jQuery.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft; + return { top: top, left: left }; + }; +else + jQuery.fn.offset = function() { + if ( !this[0] ) return { top: 0, left: 0 }; + if ( this[0] === this[0].ownerDocument.body ) return jQuery.offset.bodyOffset( this[0] ); + jQuery.offset.initialized || jQuery.offset.initialize(); + + var elem = this[0], offsetParent = elem.offsetParent, prevOffsetParent = elem, + doc = elem.ownerDocument, computedStyle, docElem = doc.documentElement, + body = doc.body, defaultView = doc.defaultView, + prevComputedStyle = defaultView.getComputedStyle(elem, null), + top = elem.offsetTop, left = elem.offsetLeft; + + while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) { + computedStyle = defaultView.getComputedStyle(elem, null); + top -= elem.scrollTop, left -= elem.scrollLeft; + if ( elem === offsetParent ) { + top += elem.offsetTop, left += elem.offsetLeft; + if ( jQuery.offset.doesNotAddBorder && !(jQuery.offset.doesAddBorderForTableAndCells && /^t(able|d|h)$/i.test(elem.tagName)) ) + top += parseInt( computedStyle.borderTopWidth, 10) || 0, + left += parseInt( computedStyle.borderLeftWidth, 10) || 0; + prevOffsetParent = offsetParent, offsetParent = elem.offsetParent; + } + if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) + top += parseInt( computedStyle.borderTopWidth, 10) || 0, + left += parseInt( computedStyle.borderLeftWidth, 10) || 0; + prevComputedStyle = computedStyle; + } - // Mozilla and Safari > 2 does not include the border on offset parents - // However Mozilla adds the border for table or table cells - if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 ) - border( offsetParent ); + if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) + top += body.offsetTop, + left += body.offsetLeft; - // Add the document scroll offsets if position is fixed on any offsetParent - if ( !fixed && css(offsetParent, "position") == "fixed" ) - fixed = true; + if ( prevComputedStyle.position === "fixed" ) + top += Math.max(docElem.scrollTop, body.scrollTop), + left += Math.max(docElem.scrollLeft, body.scrollLeft); - // Set offsetChild to previous offsetParent unless it is the body element - offsetChild = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent; - // Get next offsetParent - offsetParent = offsetParent.offsetParent; - } + return { top: top, left: left }; + }; - // Get parent scroll offsets - while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) { - // Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug - if ( !/^inline|table.*$/i.test(css(parent, "display")) ) - // Subtract parent scroll offsets - add( -parent.scrollLeft, -parent.scrollTop ); +jQuery.offset = { + initialize: function() { + if ( this.initialized ) return; + var body = document.body, container = document.createElement('div'), innerDiv, checkDiv, table, td, rules, prop, bodyMarginTop = body.style.marginTop, + html = '<div style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"><div></div></div><table style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"cellpadding="0"cellspacing="0"><tr><td></td></tr></table>'; - // Mozilla does not add the border for a parent that has overflow != visible - if ( mozilla && css(parent, "overflow") != "visible" ) - border( parent ); + rules = { position: 'absolute', top: 0, left: 0, margin: 0, border: 0, width: '1px', height: '1px', visibility: 'hidden' }; + for ( prop in rules ) container.style[prop] = rules[prop]; - // Get next parent - parent = parent.parentNode; - } + container.innerHTML = html; + body.insertBefore(container, body.firstChild); + innerDiv = container.firstChild, checkDiv = innerDiv.firstChild, td = innerDiv.nextSibling.firstChild.firstChild; - // Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild - // Mozilla doubles body offsets with a non-absolutely positioned offsetChild - if ( (safari2 && (fixed || css(offsetChild, "position") == "absolute")) || - (mozilla && css(offsetChild, "position") != "absolute") ) - add( -doc.body.offsetLeft, -doc.body.offsetTop ); + this.doesNotAddBorder = (checkDiv.offsetTop !== 5); + this.doesAddBorderForTableAndCells = (td.offsetTop === 5); - // Add the document scroll offsets if position is fixed - if ( fixed ) - add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft), - Math.max(doc.documentElement.scrollTop, doc.body.scrollTop)); - } + innerDiv.style.overflow = 'hidden', innerDiv.style.position = 'relative'; + this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5); - // Return an object with top and left properties - results = { top: top, left: left }; - } + body.style.marginTop = '1px'; + this.doesNotIncludeMarginInBodyOffset = (body.offsetTop === 0); + body.style.marginTop = bodyMarginTop; - function border(elem) { - add( jQuery.curCSS(elem, "borderLeftWidth", true), jQuery.curCSS(elem, "borderTopWidth", true) ); - } + body.removeChild(container); + this.initialized = true; + }, - function add(l, t) { - left += parseInt(l, 10) || 0; - top += parseInt(t, 10) || 0; + bodyOffset: function(body) { + jQuery.offset.initialized || jQuery.offset.initialize(); + var top = body.offsetTop, left = body.offsetLeft; + if ( jQuery.offset.doesNotIncludeMarginInBodyOffset ) + top += parseInt( jQuery.curCSS(body, 'marginTop', true), 10 ) || 0, + left += parseInt( jQuery.curCSS(body, 'marginLeft', true), 10 ) || 0; + return { top: top, left: left }; } - - return results; }; @@ -3471,11 +4136,11 @@ jQuery.fn.extend({ // Subtract element margins // note: when an element has margin: auto the offsetLeft and marginLeft // are the same in Safari causing offset.left to incorrectly be 0 - offset.top -= num( this, 'marginTop' ); + offset.top -= num( this, 'marginTop' ); offset.left -= num( this, 'marginLeft' ); // Add offsetParent borders - parentOffset.top += num( offsetParent, 'borderTopWidth' ); + parentOffset.top += num( offsetParent, 'borderTopWidth' ); parentOffset.left += num( offsetParent, 'borderLeftWidth' ); // Subtract the two offsets @@ -3489,7 +4154,7 @@ jQuery.fn.extend({ }, offsetParent: function() { - var offsetParent = this[0].offsetParent; + var offsetParent = this[0].offsetParent || document.body; while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') ) offsetParent = offsetParent.offsetParent; return jQuery(offsetParent); @@ -3502,9 +4167,9 @@ jQuery.each( ['Left', 'Top'], function(i, name) { var method = 'scroll' + name; jQuery.fn[ method ] = function(val) { - if (!this[0]) return; + if (!this[0]) return null; - return val != undefined ? + return val !== undefined ? // Set the scroll offset this.each(function() { @@ -3545,5 +4210,32 @@ jQuery.each([ "Height", "Width" ], function(i, name){ (margin ? num(this, "margin" + tl) + num(this, "margin" + br) : 0); }; + + var type = name.toLowerCase(); + + jQuery.fn[ type ] = function( size ) { + // Get window width or height + return this[0] == window ? + // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode + document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || + document.body[ "client" + name ] : + + // Get document width or height + this[0] == document ? + // Either scroll[Width/Height] or offset[Width/Height], whichever is greater + Math.max( + document.documentElement["client" + name], + document.body["scroll" + name], document.documentElement["scroll" + name], + document.body["offset" + name], document.documentElement["offset" + name] + ) : + + // Get or set width or height on the element + size === undefined ? + // Get width or height on the element + (this.length ? jQuery.css( this[0], type ) : null) : + + // Set the width or height on the element (default to pixels if value is unitless) + this.css( type, typeof size === "string" ? size : size + "px" ); + }; });})(); diff --git a/js/jquery.min.js b/js/jquery.min.js index 82b98e1d7..396646c84 100644 --- a/js/jquery.min.js +++ b/js/jquery.min.js @@ -1,32 +1,19 @@ /* - * jQuery 1.2.6 - New Wave Javascript + * jQuery JavaScript Library v1.3 + * http://jquery.com/ * - * Copyright (c) 2008 John Resig (jquery.com) - * Dual licensed under the MIT (MIT-LICENSE.txt) - * and GPL (GPL-LICENSE.txt) licenses. + * Copyright (c) 2009 John Resig + * Dual licensed under the MIT and GPL licenses. + * http://docs.jquery.com/License * - * $Date: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) $ - * $Rev: 5685 $ + * Date: 2009-01-13 12:50:31 -0500 (Tue, 13 Jan 2009) + * Revision: 6104 */ -(function(){var _jQuery=window.jQuery,_$=window.$;var jQuery=window.jQuery=window.$=function(selector,context){return new jQuery.fn.init(selector,context);};var quickExpr=/^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/,isSimple=/^.[^:#\[\.]*$/,undefined;jQuery.fn=jQuery.prototype={init:function(selector,context){selector=selector||document;if(selector.nodeType){this[0]=selector;this.length=1;return this;}if(typeof selector=="string"){var match=quickExpr.exec(selector);if(match&&(match[1]||!context)){if(match[1])selector=jQuery.clean([match[1]],context);else{var elem=document.getElementById(match[3]);if(elem){if(elem.id!=match[3])return jQuery().find(selector);return jQuery(elem);}selector=[];}}else -return jQuery(context).find(selector);}else if(jQuery.isFunction(selector))return jQuery(document)[jQuery.fn.ready?"ready":"load"](selector);return this.setArray(jQuery.makeArray(selector));},jquery:"1.2.6",size:function(){return this.length;},length:0,get:function(num){return num==undefined?jQuery.makeArray(this):this[num];},pushStack:function(elems){var ret=jQuery(elems);ret.prevObject=this;return ret;},setArray:function(elems){this.length=0;Array.prototype.push.apply(this,elems);return this;},each:function(callback,args){return jQuery.each(this,callback,args);},index:function(elem){var ret=-1;return jQuery.inArray(elem&&elem.jquery?elem[0]:elem,this);},attr:function(name,value,type){var options=name;if(name.constructor==String)if(value===undefined)return this[0]&&jQuery[type||"attr"](this[0],name);else{options={};options[name]=value;}return this.each(function(i){for(name in options)jQuery.attr(type?this.style:this,name,jQuery.prop(this,options[name],type,i,name));});},css:function(key,value){if((key=='width'||key=='height')&&parseFloat(value)<0)value=undefined;return this.attr(key,value,"curCSS");},text:function(text){if(typeof text!="object"&&text!=null)return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(text));var ret="";jQuery.each(text||this,function(){jQuery.each(this.childNodes,function(){if(this.nodeType!=8)ret+=this.nodeType!=1?this.nodeValue:jQuery.fn.text([this]);});});return ret;},wrapAll:function(html){if(this[0])jQuery(html,this[0].ownerDocument).clone().insertBefore(this[0]).map(function(){var elem=this;while(elem.firstChild)elem=elem.firstChild;return elem;}).append(this);return this;},wrapInner:function(html){return this.each(function(){jQuery(this).contents().wrapAll(html);});},wrap:function(html){return this.each(function(){jQuery(this).wrapAll(html);});},append:function(){return this.domManip(arguments,true,false,function(elem){if(this.nodeType==1)this.appendChild(elem);});},prepend:function(){return this.domManip(arguments,true,true,function(elem){if(this.nodeType==1)this.insertBefore(elem,this.firstChild);});},before:function(){return this.domManip(arguments,false,false,function(elem){this.parentNode.insertBefore(elem,this);});},after:function(){return this.domManip(arguments,false,true,function(elem){this.parentNode.insertBefore(elem,this.nextSibling);});},end:function(){return this.prevObject||jQuery([]);},find:function(selector){var elems=jQuery.map(this,function(elem){return jQuery.find(selector,elem);});return this.pushStack(/[^+>] [^+>]/.test(selector)||selector.indexOf("..")>-1?jQuery.unique(elems):elems);},clone:function(events){var ret=this.map(function(){if(jQuery.browser.msie&&!jQuery.isXMLDoc(this)){var clone=this.cloneNode(true),container=document.createElement("div");container.appendChild(clone);return jQuery.clean([container.innerHTML])[0];}else -return this.cloneNode(true);});var clone=ret.find("*").andSelf().each(function(){if(this[expando]!=undefined)this[expando]=null;});if(events===true)this.find("*").andSelf().each(function(i){if(this.nodeType==3)return;var events=jQuery.data(this,"events");for(var type in events)for(var handler in events[type])jQuery.event.add(clone[i],type,events[type][handler],events[type][handler].data);});return ret;},filter:function(selector){return this.pushStack(jQuery.isFunction(selector)&&jQuery.grep(this,function(elem,i){return selector.call(elem,i);})||jQuery.multiFilter(selector,this));},not:function(selector){if(selector.constructor==String)if(isSimple.test(selector))return this.pushStack(jQuery.multiFilter(selector,this,true));else -selector=jQuery.multiFilter(selector,this);var isArrayLike=selector.length&&selector[selector.length-1]!==undefined&&!selector.nodeType;return this.filter(function(){return isArrayLike?jQuery.inArray(this,selector)<0:this!=selector;});},add:function(selector){return this.pushStack(jQuery.unique(jQuery.merge(this.get(),typeof selector=='string'?jQuery(selector):jQuery.makeArray(selector))));},is:function(selector){return!!selector&&jQuery.multiFilter(selector,this).length>0;},hasClass:function(selector){return this.is("."+selector);},val:function(value){if(value==undefined){if(this.length){var elem=this[0];if(jQuery.nodeName(elem,"select")){var index=elem.selectedIndex,values=[],options=elem.options,one=elem.type=="select-one";if(index<0)return null;for(var i=one?index:0,max=one?index+1:options.length;i<max;i++){var option=options[i];if(option.selected){value=jQuery.browser.msie&&!option.attributes.value.specified?option.text:option.value;if(one)return value;values.push(value);}}return values;}else -return(this[0].value||"").replace(/\r/g,"");}return undefined;}if(value.constructor==Number)value+='';return this.each(function(){if(this.nodeType!=1)return;if(value.constructor==Array&&/radio|checkbox/.test(this.type))this.checked=(jQuery.inArray(this.value,value)>=0||jQuery.inArray(this.name,value)>=0);else if(jQuery.nodeName(this,"select")){var values=jQuery.makeArray(value);jQuery("option",this).each(function(){this.selected=(jQuery.inArray(this.value,values)>=0||jQuery.inArray(this.text,values)>=0);});if(!values.length)this.selectedIndex=-1;}else -this.value=value;});},html:function(value){return value==undefined?(this[0]?this[0].innerHTML:null):this.empty().append(value);},replaceWith:function(value){return this.after(value).remove();},eq:function(i){return this.slice(i,i+1);},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments));},map:function(callback){return this.pushStack(jQuery.map(this,function(elem,i){return callback.call(elem,i,elem);}));},andSelf:function(){return this.add(this.prevObject);},data:function(key,value){var parts=key.split(".");parts[1]=parts[1]?"."+parts[1]:"";if(value===undefined){var data=this.triggerHandler("getData"+parts[1]+"!",[parts[0]]);if(data===undefined&&this.length)data=jQuery.data(this[0],key);return data===undefined&&parts[1]?this.data(parts[0]):data;}else -return this.trigger("setData"+parts[1]+"!",[parts[0],value]).each(function(){jQuery.data(this,key,value);});},removeData:function(key){return this.each(function(){jQuery.removeData(this,key);});},domManip:function(args,table,reverse,callback){var clone=this.length>1,elems;return this.each(function(){if(!elems){elems=jQuery.clean(args,this.ownerDocument);if(reverse)elems.reverse();}var obj=this;if(table&&jQuery.nodeName(this,"table")&&jQuery.nodeName(elems[0],"tr"))obj=this.getElementsByTagName("tbody")[0]||this.appendChild(this.ownerDocument.createElement("tbody"));var scripts=jQuery([]);jQuery.each(elems,function(){var elem=clone?jQuery(this).clone(true)[0]:this;if(jQuery.nodeName(elem,"script"))scripts=scripts.add(elem);else{if(elem.nodeType==1)scripts=scripts.add(jQuery("script",elem).remove());callback.call(obj,elem);}});scripts.each(evalScript);});}};jQuery.fn.init.prototype=jQuery.fn;function evalScript(i,elem){if(elem.src)jQuery.ajax({url:elem.src,async:false,dataType:"script"});else -jQuery.globalEval(elem.text||elem.textContent||elem.innerHTML||"");if(elem.parentNode)elem.parentNode.removeChild(elem);}function now(){return+new Date;}jQuery.extend=jQuery.fn.extend=function(){var target=arguments[0]||{},i=1,length=arguments.length,deep=false,options;if(target.constructor==Boolean){deep=target;target=arguments[1]||{};i=2;}if(typeof target!="object"&&typeof target!="function")target={};if(length==i){target=this;--i;}for(;i<length;i++)if((options=arguments[i])!=null)for(var name in options){var src=target[name],copy=options[name];if(target===copy)continue;if(deep&©&&typeof copy=="object"&&!copy.nodeType)target[name]=jQuery.extend(deep,src||(copy.length!=null?[]:{}),copy);else if(copy!==undefined)target[name]=copy;}return target;};var expando="jQuery"+now(),uuid=0,windowData={},exclude=/z-?index|font-?weight|opacity|zoom|line-?height/i,defaultView=document.defaultView||{};jQuery.extend({noConflict:function(deep){window.$=_$;if(deep)window.jQuery=_jQuery;return jQuery;},isFunction:function(fn){return!!fn&&typeof fn!="string"&&!fn.nodeName&&fn.constructor!=Array&&/^[\s[]?function/.test(fn+"");},isXMLDoc:function(elem){return elem.documentElement&&!elem.body||elem.tagName&&elem.ownerDocument&&!elem.ownerDocument.body;},globalEval:function(data){data=jQuery.trim(data);if(data){var head=document.getElementsByTagName("head")[0]||document.documentElement,script=document.createElement("script");script.type="text/javascript";if(jQuery.browser.msie)script.text=data;else -script.appendChild(document.createTextNode(data));head.insertBefore(script,head.firstChild);head.removeChild(script);}},nodeName:function(elem,name){return elem.nodeName&&elem.nodeName.toUpperCase()==name.toUpperCase();},cache:{},data:function(elem,name,data){elem=elem==window?windowData:elem;var id=elem[expando];if(!id)id=elem[expando]=++uuid;if(name&&!jQuery.cache[id])jQuery.cache[id]={};if(data!==undefined)jQuery.cache[id][name]=data;return name?jQuery.cache[id][name]:id;},removeData:function(elem,name){elem=elem==window?windowData:elem;var id=elem[expando];if(name){if(jQuery.cache[id]){delete jQuery.cache[id][name];name="";for(name in jQuery.cache[id])break;if(!name)jQuery.removeData(elem);}}else{try{delete elem[expando];}catch(e){if(elem.removeAttribute)elem.removeAttribute(expando);}delete jQuery.cache[id];}},each:function(object,callback,args){var name,i=0,length=object.length;if(args){if(length==undefined){for(name in object)if(callback.apply(object[name],args)===false)break;}else -for(;i<length;)if(callback.apply(object[i++],args)===false)break;}else{if(length==undefined){for(name in object)if(callback.call(object[name],name,object[name])===false)break;}else -for(var value=object[0];i<length&&callback.call(value,i,value)!==false;value=object[++i]){}}return object;},prop:function(elem,value,type,i,name){if(jQuery.isFunction(value))value=value.call(elem,i);return value&&value.constructor==Number&&type=="curCSS"&&!exclude.test(name)?value+"px":value;},className:{add:function(elem,classNames){jQuery.each((classNames||"").split(/\s+/),function(i,className){if(elem.nodeType==1&&!jQuery.className.has(elem.className,className))elem.className+=(elem.className?" ":"")+className;});},remove:function(elem,classNames){if(elem.nodeType==1)elem.className=classNames!=undefined?jQuery.grep(elem.className.split(/\s+/),function(className){return!jQuery.className.has(classNames,className);}).join(" "):"";},has:function(elem,className){return jQuery.inArray(className,(elem.className||elem).toString().split(/\s+/))>-1;}},swap:function(elem,options,callback){var old={};for(var name in options){old[name]=elem.style[name];elem.style[name]=options[name];}callback.call(elem);for(var name in options)elem.style[name]=old[name];},css:function(elem,name,force){if(name=="width"||name=="height"){var val,props={position:"absolute",visibility:"hidden",display:"block"},which=name=="width"?["Left","Right"]:["Top","Bottom"];function getWH(){val=name=="width"?elem.offsetWidth:elem.offsetHeight;var padding=0,border=0;jQuery.each(which,function(){padding+=parseFloat(jQuery.curCSS(elem,"padding"+this,true))||0;border+=parseFloat(jQuery.curCSS(elem,"border"+this+"Width",true))||0;});val-=Math.round(padding+border);}if(jQuery(elem).is(":visible"))getWH();else -jQuery.swap(elem,props,getWH);return Math.max(0,val);}return jQuery.curCSS(elem,name,force);},curCSS:function(elem,name,force){var ret,style=elem.style;function color(elem){if(!jQuery.browser.safari)return false;var ret=defaultView.getComputedStyle(elem,null);return!ret||ret.getPropertyValue("color")=="";}if(name=="opacity"&&jQuery.browser.msie){ret=jQuery.attr(style,"opacity");return ret==""?"1":ret;}if(jQuery.browser.opera&&name=="display"){var save=style.outline;style.outline="0 solid black";style.outline=save;}if(name.match(/float/i))name=styleFloat;if(!force&&style&&style[name])ret=style[name];else if(defaultView.getComputedStyle){if(name.match(/float/i))name="float";name=name.replace(/([A-Z])/g,"-$1").toLowerCase();var computedStyle=defaultView.getComputedStyle(elem,null);if(computedStyle&&!color(elem))ret=computedStyle.getPropertyValue(name);else{var swap=[],stack=[],a=elem,i=0;for(;a&&color(a);a=a.parentNode)stack.unshift(a);for(;i<stack.length;i++)if(color(stack[i])){swap[i]=stack[i].style.display;stack[i].style.display="block";}ret=name=="display"&&swap[stack.length-1]!=null?"none":(computedStyle&&computedStyle.getPropertyValue(name))||"";for(i=0;i<swap.length;i++)if(swap[i]!=null)stack[i].style.display=swap[i];}if(name=="opacity"&&ret=="")ret="1";}else if(elem.currentStyle){var camelCase=name.replace(/\-(\w)/g,function(all,letter){return letter.toUpperCase();});ret=elem.currentStyle[name]||elem.currentStyle[camelCase];if(!/^\d+(px)?$/i.test(ret)&&/^\d/.test(ret)){var left=style.left,rsLeft=elem.runtimeStyle.left;elem.runtimeStyle.left=elem.currentStyle.left;style.left=ret||0;ret=style.pixelLeft+"px";style.left=left;elem.runtimeStyle.left=rsLeft;}}return ret;},clean:function(elems,context){var ret=[];context=context||document;if(typeof context.createElement=='undefined')context=context.ownerDocument||context[0]&&context[0].ownerDocument||document;jQuery.each(elems,function(i,elem){if(!elem)return;if(elem.constructor==Number)elem+='';if(typeof elem=="string"){elem=elem.replace(/(<(\w+)[^>]*?)\/>/g,function(all,front,tag){return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?all:front+"></"+tag+">";});var tags=jQuery.trim(elem).toLowerCase(),div=context.createElement("div");var wrap=!tags.indexOf("<opt")&&[1,"<select multiple='multiple'>","</select>"]||!tags.indexOf("<leg")&&[1,"<fieldset>","</fieldset>"]||tags.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"<table>","</table>"]||!tags.indexOf("<tr")&&[2,"<table><tbody>","</tbody></table>"]||(!tags.indexOf("<td")||!tags.indexOf("<th"))&&[3,"<table><tbody><tr>","</tr></tbody></table>"]||!tags.indexOf("<col")&&[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"]||jQuery.browser.msie&&[1,"div<div>","</div>"]||[0,"",""];div.innerHTML=wrap[1]+elem+wrap[2];while(wrap[0]--)div=div.lastChild;if(jQuery.browser.msie){var tbody=!tags.indexOf("<table")&&tags.indexOf("<tbody")<0?div.firstChild&&div.firstChild.childNodes:wrap[1]=="<table>"&&tags.indexOf("<tbody")<0?div.childNodes:[];for(var j=tbody.length-1;j>=0;--j)if(jQuery.nodeName(tbody[j],"tbody")&&!tbody[j].childNodes.length)tbody[j].parentNode.removeChild(tbody[j]);if(/^\s/.test(elem))div.insertBefore(context.createTextNode(elem.match(/^\s*/)[0]),div.firstChild);}elem=jQuery.makeArray(div.childNodes);}if(elem.length===0&&(!jQuery.nodeName(elem,"form")&&!jQuery.nodeName(elem,"select")))return;if(elem[0]==undefined||jQuery.nodeName(elem,"form")||elem.options)ret.push(elem);else -ret=jQuery.merge(ret,elem);});return ret;},attr:function(elem,name,value){if(!elem||elem.nodeType==3||elem.nodeType==8)return undefined;var notxml=!jQuery.isXMLDoc(elem),set=value!==undefined,msie=jQuery.browser.msie;name=notxml&&jQuery.props[name]||name;if(elem.tagName){var special=/href|src|style/.test(name);if(name=="selected"&&jQuery.browser.safari)elem.parentNode.selectedIndex;if(name in elem&¬xml&&!special){if(set){if(name=="type"&&jQuery.nodeName(elem,"input")&&elem.parentNode)throw"type property can't be changed";elem[name]=value;}if(jQuery.nodeName(elem,"form")&&elem.getAttributeNode(name))return elem.getAttributeNode(name).nodeValue;return elem[name];}if(msie&¬xml&&name=="style")return jQuery.attr(elem.style,"cssText",value);if(set)elem.setAttribute(name,""+value);var attr=msie&¬xml&&special?elem.getAttribute(name,2):elem.getAttribute(name);return attr===null?undefined:attr;}if(msie&&name=="opacity"){if(set){elem.zoom=1;elem.filter=(elem.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(value)+''=="NaN"?"":"alpha(opacity="+value*100+")");}return elem.filter&&elem.filter.indexOf("opacity=")>=0?(parseFloat(elem.filter.match(/opacity=([^)]*)/)[1])/100)+'':"";}name=name.replace(/-([a-z])/ig,function(all,letter){return letter.toUpperCase();});if(set)elem[name]=value;return elem[name];},trim:function(text){return(text||"").replace(/^\s+|\s+$/g,"");},makeArray:function(array){var ret=[];if(array!=null){var i=array.length;if(i==null||array.split||array.setInterval||array.call)ret[0]=array;else -while(i)ret[--i]=array[i];}return ret;},inArray:function(elem,array){for(var i=0,length=array.length;i<length;i++)if(array[i]===elem)return i;return-1;},merge:function(first,second){var i=0,elem,pos=first.length;if(jQuery.browser.msie){while(elem=second[i++])if(elem.nodeType!=8)first[pos++]=elem;}else -while(elem=second[i++])first[pos++]=elem;return first;},unique:function(array){var ret=[],done={};try{for(var i=0,length=array.length;i<length;i++){var id=jQuery.data(array[i]);if(!done[id]){done[id]=true;ret.push(array[i]);}}}catch(e){ret=array;}return ret;},grep:function(elems,callback,inv){var ret=[];for(var i=0,length=elems.length;i<length;i++)if(!inv!=!callback(elems[i],i))ret.push(elems[i]);return ret;},map:function(elems,callback){var ret=[];for(var i=0,length=elems.length;i<length;i++){var value=callback(elems[i],i);if(value!=null)ret[ret.length]=value;}return ret.concat.apply([],ret);}});var userAgent=navigator.userAgent.toLowerCase();jQuery.browser={version:(userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(userAgent),opera:/opera/.test(userAgent),msie:/msie/.test(userAgent)&&!/opera/.test(userAgent),mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)};var styleFloat=jQuery.browser.msie?"styleFloat":"cssFloat";jQuery.extend({boxModel:!jQuery.browser.msie||document.compatMode=="CSS1Compat",props:{"for":"htmlFor","class":"className","float":styleFloat,cssFloat:styleFloat,styleFloat:styleFloat,readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing"}});jQuery.each({parent:function(elem){return elem.parentNode;},parents:function(elem){return jQuery.dir(elem,"parentNode");},next:function(elem){return jQuery.nth(elem,2,"nextSibling");},prev:function(elem){return jQuery.nth(elem,2,"previousSibling");},nextAll:function(elem){return jQuery.dir(elem,"nextSibling");},prevAll:function(elem){return jQuery.dir(elem,"previousSibling");},siblings:function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},children:function(elem){return jQuery.sibling(elem.firstChild);},contents:function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}},function(name,fn){jQuery.fn[name]=function(selector){var ret=jQuery.map(this,fn);if(selector&&typeof selector=="string")ret=jQuery.multiFilter(selector,ret);return this.pushStack(jQuery.unique(ret));};});jQuery.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(name,original){jQuery.fn[name]=function(){var args=arguments;return this.each(function(){for(var i=0,length=args.length;i<length;i++)jQuery(args[i])[original](this);});};});jQuery.each({removeAttr:function(name){jQuery.attr(this,name,"");if(this.nodeType==1)this.removeAttribute(name);},addClass:function(classNames){jQuery.className.add(this,classNames);},removeClass:function(classNames){jQuery.className.remove(this,classNames);},toggleClass:function(classNames){jQuery.className[jQuery.className.has(this,classNames)?"remove":"add"](this,classNames);},remove:function(selector){if(!selector||jQuery.filter(selector,[this]).r.length){jQuery("*",this).add(this).each(function(){jQuery.event.remove(this);jQuery.removeData(this);});if(this.parentNode)this.parentNode.removeChild(this);}},empty:function(){jQuery(">*",this).remove();while(this.firstChild)this.removeChild(this.firstChild);}},function(name,fn){jQuery.fn[name]=function(){return this.each(fn,arguments);};});jQuery.each(["Height","Width"],function(i,name){var type=name.toLowerCase();jQuery.fn[type]=function(size){return this[0]==window?jQuery.browser.opera&&document.body["client"+name]||jQuery.browser.safari&&window["inner"+name]||document.compatMode=="CSS1Compat"&&document.documentElement["client"+name]||document.body["client"+name]:this[0]==document?Math.max(Math.max(document.body["scroll"+name],document.documentElement["scroll"+name]),Math.max(document.body["offset"+name],document.documentElement["offset"+name])):size==undefined?(this.length?jQuery.css(this[0],type):null):this.css(type,size.constructor==String?size:size+"px");};});function num(elem,prop){return elem[0]&&parseInt(jQuery.curCSS(elem[0],prop,true),10)||0;}var chars=jQuery.browser.safari&&parseInt(jQuery.browser.version)<417?"(?:[\\w*_-]|\\\\.)":"(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",quickChild=new RegExp("^>\\s*("+chars+"+)"),quickID=new RegExp("^("+chars+"+)(#)("+chars+"+)"),quickClass=new RegExp("^([#.]?)("+chars+"*)");jQuery.extend({expr:{"":function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},"#":function(a,i,m){return a.getAttribute("id")==m[2];},":":{lt:function(a,i,m){return i<m[3]-0;},gt:function(a,i,m){return i>m[3]-0;},nth:function(a,i,m){return m[3]-0==i;},eq:function(a,i,m){return m[3]-0==i;},first:function(a,i){return i==0;},last:function(a,i,m,r){return i==r.length-1;},even:function(a,i){return i%2==0;},odd:function(a,i){return i%2;},"first-child":function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},"last-child":function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},"only-child":function(a){return!jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},parent:function(a){return a.firstChild;},empty:function(a){return!a.firstChild;},contains:function(a,i,m){return(a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},visible:function(a){return"hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},hidden:function(a){return"hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},enabled:function(a){return!a.disabled;},disabled:function(a){return a.disabled;},checked:function(a){return a.checked;},selected:function(a){return a.selected||jQuery.attr(a,"selected");},text:function(a){return"text"==a.type;},radio:function(a){return"radio"==a.type;},checkbox:function(a){return"checkbox"==a.type;},file:function(a){return"file"==a.type;},password:function(a){return"password"==a.type;},submit:function(a){return"submit"==a.type;},image:function(a){return"image"==a.type;},reset:function(a){return"reset"==a.type;},button:function(a){return"button"==a.type||jQuery.nodeName(a,"button");},input:function(a){return/input|select|textarea|button/i.test(a.nodeName);},has:function(a,i,m){return jQuery.find(m[3],a).length;},header:function(a){return/h\d/i.test(a.nodeName);},animated:function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}}},parse:[/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,new RegExp("^([:.#]*)("+chars+"+)")],multiFilter:function(expr,elems,not){var old,cur=[];while(expr&&expr!=old){old=expr;var f=jQuery.filter(expr,elems,not);expr=f.t.replace(/^\s*,\s*/,"");cur=not?elems=f.r:jQuery.merge(cur,f.r);}return cur;},find:function(t,context){if(typeof t!="string")return[t];if(context&&context.nodeType!=1&&context.nodeType!=9)return[];context=context||document;var ret=[context],done=[],last,nodeName;while(t&&last!=t){var r=[];last=t;t=jQuery.trim(t);var foundToken=false,re=quickChild,m=re.exec(t);if(m){nodeName=m[1].toUpperCase();for(var i=0;ret[i];i++)for(var c=ret[i].firstChild;c;c=c.nextSibling)if(c.nodeType==1&&(nodeName=="*"||c.nodeName.toUpperCase()==nodeName))r.push(c);ret=r;t=t.replace(re,"");if(t.indexOf(" ")==0)continue;foundToken=true;}else{re=/^([>+~])\s*(\w*)/i;if((m=re.exec(t))!=null){r=[];var merge={};nodeName=m[2].toUpperCase();m=m[1];for(var j=0,rl=ret.length;j<rl;j++){var n=m=="~"||m=="+"?ret[j].nextSibling:ret[j].firstChild;for(;n;n=n.nextSibling)if(n.nodeType==1){var id=jQuery.data(n);if(m=="~"&&merge[id])break;if(!nodeName||n.nodeName.toUpperCase()==nodeName){if(m=="~")merge[id]=true;r.push(n);}if(m=="+")break;}}ret=r;t=jQuery.trim(t.replace(re,""));foundToken=true;}}if(t&&!foundToken){if(!t.indexOf(",")){if(context==ret[0])ret.shift();done=jQuery.merge(done,ret);r=ret=[context];t=" "+t.substr(1,t.length);}else{var re2=quickID;var m=re2.exec(t);if(m){m=[0,m[2],m[3],m[1]];}else{re2=quickClass;m=re2.exec(t);}m[2]=m[2].replace(/\\/g,"");var elem=ret[ret.length-1];if(m[1]=="#"&&elem&&elem.getElementById&&!jQuery.isXMLDoc(elem)){var oid=elem.getElementById(m[2]);if((jQuery.browser.msie||jQuery.browser.opera)&&oid&&typeof oid.id=="string"&&oid.id!=m[2])oid=jQuery('[@id="'+m[2]+'"]',elem)[0];ret=r=oid&&(!m[3]||jQuery.nodeName(oid,m[3]))?[oid]:[];}else{for(var i=0;ret[i];i++){var tag=m[1]=="#"&&m[3]?m[3]:m[1]!=""||m[0]==""?"*":m[2];if(tag=="*"&&ret[i].nodeName.toLowerCase()=="object")tag="param";r=jQuery.merge(r,ret[i].getElementsByTagName(tag));}if(m[1]==".")r=jQuery.classFilter(r,m[2]);if(m[1]=="#"){var tmp=[];for(var i=0;r[i];i++)if(r[i].getAttribute("id")==m[2]){tmp=[r[i]];break;}r=tmp;}ret=r;}t=t.replace(re2,"");}}if(t){var val=jQuery.filter(t,r);ret=r=val.r;t=jQuery.trim(val.t);}}if(t)ret=[];if(ret&&context==ret[0])ret.shift();done=jQuery.merge(done,ret);return done;},classFilter:function(r,m,not){m=" "+m+" ";var tmp=[];for(var i=0;r[i];i++){var pass=(" "+r[i].className+" ").indexOf(m)>=0;if(!not&&pass||not&&!pass)tmp.push(r[i]);}return tmp;},filter:function(t,r,not){var last;while(t&&t!=last){last=t;var p=jQuery.parse,m;for(var i=0;p[i];i++){m=p[i].exec(t);if(m){t=t.substring(m[0].length);m[2]=m[2].replace(/\\/g,"");break;}}if(!m)break;if(m[1]==":"&&m[2]=="not")r=isSimple.test(m[3])?jQuery.filter(m[3],r,true).r:jQuery(r).not(m[3]);else if(m[1]==".")r=jQuery.classFilter(r,m[2],not);else if(m[1]=="["){var tmp=[],type=m[3];for(var i=0,rl=r.length;i<rl;i++){var a=r[i],z=a[jQuery.props[m[2]]||m[2]];if(z==null||/href|src|selected/.test(m[2]))z=jQuery.attr(a,m[2])||'';if((type==""&&!!z||type=="="&&z==m[5]||type=="!="&&z!=m[5]||type=="^="&&z&&!z.indexOf(m[5])||type=="$="&&z.substr(z.length-m[5].length)==m[5]||(type=="*="||type=="~=")&&z.indexOf(m[5])>=0)^not)tmp.push(a);}r=tmp;}else if(m[1]==":"&&m[2]=="nth-child"){var merge={},tmp=[],test=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(m[3]=="even"&&"2n"||m[3]=="odd"&&"2n+1"||!/\D/.test(m[3])&&"0n+"+m[3]||m[3]),first=(test[1]+(test[2]||1))-0,last=test[3]-0;for(var i=0,rl=r.length;i<rl;i++){var node=r[i],parentNode=node.parentNode,id=jQuery.data(parentNode);if(!merge[id]){var c=1;for(var n=parentNode.firstChild;n;n=n.nextSibling)if(n.nodeType==1)n.nodeIndex=c++;merge[id]=true;}var add=false;if(first==0){if(node.nodeIndex==last)add=true;}else if((node.nodeIndex-last)%first==0&&(node.nodeIndex-last)/first>=0)add=true;if(add^not)tmp.push(node);}r=tmp;}else{var fn=jQuery.expr[m[1]];if(typeof fn=="object")fn=fn[m[2]];if(typeof fn=="string")fn=eval("false||function(a,i){return "+fn+";}");r=jQuery.grep(r,function(elem,i){return fn(elem,i,m,r);},not);}}return{r:r,t:t};},dir:function(elem,dir){var matched=[],cur=elem[dir];while(cur&&cur!=document){if(cur.nodeType==1)matched.push(cur);cur=cur[dir];}return matched;},nth:function(cur,result,dir,elem){result=result||1;var num=0;for(;cur;cur=cur[dir])if(cur.nodeType==1&&++num==result)break;return cur;},sibling:function(n,elem){var r=[];for(;n;n=n.nextSibling){if(n.nodeType==1&&n!=elem)r.push(n);}return r;}});jQuery.event={add:function(elem,types,handler,data){if(elem.nodeType==3||elem.nodeType==8)return;if(jQuery.browser.msie&&elem.setInterval)elem=window;if(!handler.guid)handler.guid=this.guid++;if(data!=undefined){var fn=handler;handler=this.proxy(fn,function(){return fn.apply(this,arguments);});handler.data=data;}var events=jQuery.data(elem,"events")||jQuery.data(elem,"events",{}),handle=jQuery.data(elem,"handle")||jQuery.data(elem,"handle",function(){if(typeof jQuery!="undefined"&&!jQuery.event.triggered)return jQuery.event.handle.apply(arguments.callee.elem,arguments);});handle.elem=elem;jQuery.each(types.split(/\s+/),function(index,type){var parts=type.split(".");type=parts[0];handler.type=parts[1];var handlers=events[type];if(!handlers){handlers=events[type]={};if(!jQuery.event.special[type]||jQuery.event.special[type].setup.call(elem)===false){if(elem.addEventListener)elem.addEventListener(type,handle,false);else if(elem.attachEvent)elem.attachEvent("on"+type,handle);}}handlers[handler.guid]=handler;jQuery.event.global[type]=true;});elem=null;},guid:1,global:{},remove:function(elem,types,handler){if(elem.nodeType==3||elem.nodeType==8)return;var events=jQuery.data(elem,"events"),ret,index;if(events){if(types==undefined||(typeof types=="string"&&types.charAt(0)=="."))for(var type in events)this.remove(elem,type+(types||""));else{if(types.type){handler=types.handler;types=types.type;}jQuery.each(types.split(/\s+/),function(index,type){var parts=type.split(".");type=parts[0];if(events[type]){if(handler)delete events[type][handler.guid];else -for(handler in events[type])if(!parts[1]||events[type][handler].type==parts[1])delete events[type][handler];for(ret in events[type])break;if(!ret){if(!jQuery.event.special[type]||jQuery.event.special[type].teardown.call(elem)===false){if(elem.removeEventListener)elem.removeEventListener(type,jQuery.data(elem,"handle"),false);else if(elem.detachEvent)elem.detachEvent("on"+type,jQuery.data(elem,"handle"));}ret=null;delete events[type];}}});}for(ret in events)break;if(!ret){var handle=jQuery.data(elem,"handle");if(handle)handle.elem=null;jQuery.removeData(elem,"events");jQuery.removeData(elem,"handle");}}},trigger:function(type,data,elem,donative,extra){data=jQuery.makeArray(data);if(type.indexOf("!")>=0){type=type.slice(0,-1);var exclusive=true;}if(!elem){if(this.global[type])jQuery("*").add([window,document]).trigger(type,data);}else{if(elem.nodeType==3||elem.nodeType==8)return undefined;var val,ret,fn=jQuery.isFunction(elem[type]||null),event=!data[0]||!data[0].preventDefault;if(event){data.unshift({type:type,target:elem,preventDefault:function(){},stopPropagation:function(){},timeStamp:now()});data[0][expando]=true;}data[0].type=type;if(exclusive)data[0].exclusive=true;var handle=jQuery.data(elem,"handle");if(handle)val=handle.apply(elem,data);if((!fn||(jQuery.nodeName(elem,'a')&&type=="click"))&&elem["on"+type]&&elem["on"+type].apply(elem,data)===false)val=false;if(event)data.shift();if(extra&&jQuery.isFunction(extra)){ret=extra.apply(elem,val==null?data:data.concat(val));if(ret!==undefined)val=ret;}if(fn&&donative!==false&&val!==false&&!(jQuery.nodeName(elem,'a')&&type=="click")){this.triggered=true;try{elem[type]();}catch(e){}}this.triggered=false;}return val;},handle:function(event){var val,ret,namespace,all,handlers;event=arguments[0]=jQuery.event.fix(event||window.event);namespace=event.type.split(".");event.type=namespace[0];namespace=namespace[1];all=!namespace&&!event.exclusive;handlers=(jQuery.data(this,"events")||{})[event.type];for(var j in handlers){var handler=handlers[j];if(all||handler.type==namespace){event.handler=handler;event.data=handler.data;ret=handler.apply(this,arguments);if(val!==false)val=ret;if(ret===false){event.preventDefault();event.stopPropagation();}}}return val;},fix:function(event){if(event[expando]==true)return event;var originalEvent=event;event={originalEvent:originalEvent};var props="altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" ");for(var i=props.length;i;i--)event[props[i]]=originalEvent[props[i]];event[expando]=true;event.preventDefault=function(){if(originalEvent.preventDefault)originalEvent.preventDefault();originalEvent.returnValue=false;};event.stopPropagation=function(){if(originalEvent.stopPropagation)originalEvent.stopPropagation();originalEvent.cancelBubble=true;};event.timeStamp=event.timeStamp||now();if(!event.target)event.target=event.srcElement||document;if(event.target.nodeType==3)event.target=event.target.parentNode;if(!event.relatedTarget&&event.fromElement)event.relatedTarget=event.fromElement==event.target?event.toElement:event.fromElement;if(event.pageX==null&&event.clientX!=null){var doc=document.documentElement,body=document.body;event.pageX=event.clientX+(doc&&doc.scrollLeft||body&&body.scrollLeft||0)-(doc.clientLeft||0);event.pageY=event.clientY+(doc&&doc.scrollTop||body&&body.scrollTop||0)-(doc.clientTop||0);}if(!event.which&&((event.charCode||event.charCode===0)?event.charCode:event.keyCode))event.which=event.charCode||event.keyCode;if(!event.metaKey&&event.ctrlKey)event.metaKey=event.ctrlKey;if(!event.which&&event.button)event.which=(event.button&1?1:(event.button&2?3:(event.button&4?2:0)));return event;},proxy:function(fn,proxy){proxy.guid=fn.guid=fn.guid||proxy.guid||this.guid++;return proxy;},special:{ready:{setup:function(){bindReady();return;},teardown:function(){return;}},mouseenter:{setup:function(){if(jQuery.browser.msie)return false;jQuery(this).bind("mouseover",jQuery.event.special.mouseenter.handler);return true;},teardown:function(){if(jQuery.browser.msie)return false;jQuery(this).unbind("mouseover",jQuery.event.special.mouseenter.handler);return true;},handler:function(event){if(withinElement(event,this))return true;event.type="mouseenter";return jQuery.event.handle.apply(this,arguments);}},mouseleave:{setup:function(){if(jQuery.browser.msie)return false;jQuery(this).bind("mouseout",jQuery.event.special.mouseleave.handler);return true;},teardown:function(){if(jQuery.browser.msie)return false;jQuery(this).unbind("mouseout",jQuery.event.special.mouseleave.handler);return true;},handler:function(event){if(withinElement(event,this))return true;event.type="mouseleave";return jQuery.event.handle.apply(this,arguments);}}}};jQuery.fn.extend({bind:function(type,data,fn){return type=="unload"?this.one(type,data,fn):this.each(function(){jQuery.event.add(this,type,fn||data,fn&&data);});},one:function(type,data,fn){var one=jQuery.event.proxy(fn||data,function(event){jQuery(this).unbind(event,one);return(fn||data).apply(this,arguments);});return this.each(function(){jQuery.event.add(this,type,one,fn&&data);});},unbind:function(type,fn){return this.each(function(){jQuery.event.remove(this,type,fn);});},trigger:function(type,data,fn){return this.each(function(){jQuery.event.trigger(type,data,this,true,fn);});},triggerHandler:function(type,data,fn){return this[0]&&jQuery.event.trigger(type,data,this[0],false,fn);},toggle:function(fn){var args=arguments,i=1;while(i<args.length)jQuery.event.proxy(fn,args[i++]);return this.click(jQuery.event.proxy(fn,function(event){this.lastToggle=(this.lastToggle||0)%i;event.preventDefault();return args[this.lastToggle++].apply(this,arguments)||false;}));},hover:function(fnOver,fnOut){return this.bind('mouseenter',fnOver).bind('mouseleave',fnOut);},ready:function(fn){bindReady();if(jQuery.isReady)fn.call(document,jQuery);else -jQuery.readyList.push(function(){return fn.call(this,jQuery);});return this;}});jQuery.extend({isReady:false,readyList:[],ready:function(){if(!jQuery.isReady){jQuery.isReady=true;if(jQuery.readyList){jQuery.each(jQuery.readyList,function(){this.call(document);});jQuery.readyList=null;}jQuery(document).triggerHandler("ready");}}});var readyBound=false;function bindReady(){if(readyBound)return;readyBound=true;if(document.addEventListener&&!jQuery.browser.opera)document.addEventListener("DOMContentLoaded",jQuery.ready,false);if(jQuery.browser.msie&&window==top)(function(){if(jQuery.isReady)return;try{document.documentElement.doScroll("left");}catch(error){setTimeout(arguments.callee,0);return;}jQuery.ready();})();if(jQuery.browser.opera)document.addEventListener("DOMContentLoaded",function(){if(jQuery.isReady)return;for(var i=0;i<document.styleSheets.length;i++)if(document.styleSheets[i].disabled){setTimeout(arguments.callee,0);return;}jQuery.ready();},false);if(jQuery.browser.safari){var numStyles;(function(){if(jQuery.isReady)return;if(document.readyState!="loaded"&&document.readyState!="complete"){setTimeout(arguments.callee,0);return;}if(numStyles===undefined)numStyles=jQuery("style, link[rel=stylesheet]").length;if(document.styleSheets.length!=numStyles){setTimeout(arguments.callee,0);return;}jQuery.ready();})();}jQuery.event.add(window,"load",jQuery.ready);}jQuery.each(("blur,focus,load,resize,scroll,unload,click,dblclick,"+"mousedown,mouseup,mousemove,mouseover,mouseout,change,select,"+"submit,keydown,keypress,keyup,error").split(","),function(i,name){jQuery.fn[name]=function(fn){return fn?this.bind(name,fn):this.trigger(name);};});var withinElement=function(event,elem){var parent=event.relatedTarget;while(parent&&parent!=elem)try{parent=parent.parentNode;}catch(error){parent=elem;}return parent==elem;};jQuery(window).bind("unload",function(){jQuery("*").add(document).unbind();});jQuery.fn.extend({_load:jQuery.fn.load,load:function(url,params,callback){if(typeof url!='string')return this._load(url);var off=url.indexOf(" ");if(off>=0){var selector=url.slice(off,url.length);url=url.slice(0,off);}callback=callback||function(){};var type="GET";if(params)if(jQuery.isFunction(params)){callback=params;params=null;}else{params=jQuery.param(params);type="POST";}var self=this;jQuery.ajax({url:url,type:type,dataType:"html",data:params,complete:function(res,status){if(status=="success"||status=="notmodified")self.html(selector?jQuery("<div/>").append(res.responseText.replace(/<script(.|\s)*?\/script>/g,"")).find(selector):res.responseText);self.each(callback,[res.responseText,status,res]);}});return this;},serialize:function(){return jQuery.param(this.serializeArray());},serializeArray:function(){return this.map(function(){return jQuery.nodeName(this,"form")?jQuery.makeArray(this.elements):this;}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password/i.test(this.type));}).map(function(i,elem){var val=jQuery(this).val();return val==null?null:val.constructor==Array?jQuery.map(val,function(val,i){return{name:elem.name,value:val};}):{name:elem.name,value:val};}).get();}});jQuery.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(i,o){jQuery.fn[o]=function(f){return this.bind(o,f);};});var jsc=now();jQuery.extend({get:function(url,data,callback,type){if(jQuery.isFunction(data)){callback=data;data=null;}return jQuery.ajax({type:"GET",url:url,data:data,success:callback,dataType:type});},getScript:function(url,callback){return jQuery.get(url,null,callback,"script");},getJSON:function(url,data,callback){return jQuery.get(url,data,callback,"json");},post:function(url,data,callback,type){if(jQuery.isFunction(data)){callback=data;data={};}return jQuery.ajax({type:"POST",url:url,data:data,success:callback,dataType:type});},ajaxSetup:function(settings){jQuery.extend(jQuery.ajaxSettings,settings);},ajaxSettings:{url:location.href,global:true,type:"GET",timeout:0,contentType:"application/x-www-form-urlencoded",processData:true,async:true,data:null,username:null,password:null,accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(s){s=jQuery.extend(true,s,jQuery.extend(true,{},jQuery.ajaxSettings,s));var jsonp,jsre=/=\?(&|$)/g,status,data,type=s.type.toUpperCase();if(s.data&&s.processData&&typeof s.data!="string")s.data=jQuery.param(s.data);if(s.dataType=="jsonp"){if(type=="GET"){if(!s.url.match(jsre))s.url+=(s.url.match(/\?/)?"&":"?")+(s.jsonp||"callback")+"=?";}else if(!s.data||!s.data.match(jsre))s.data=(s.data?s.data+"&":"")+(s.jsonp||"callback")+"=?";s.dataType="json";}if(s.dataType=="json"&&(s.data&&s.data.match(jsre)||s.url.match(jsre))){jsonp="jsonp"+jsc++;if(s.data)s.data=(s.data+"").replace(jsre,"="+jsonp+"$1");s.url=s.url.replace(jsre,"="+jsonp+"$1");s.dataType="script";window[jsonp]=function(tmp){data=tmp;success();complete();window[jsonp]=undefined;try{delete window[jsonp];}catch(e){}if(head)head.removeChild(script);};}if(s.dataType=="script"&&s.cache==null)s.cache=false;if(s.cache===false&&type=="GET"){var ts=now();var ret=s.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+ts+"$2");s.url=ret+((ret==s.url)?(s.url.match(/\?/)?"&":"?")+"_="+ts:"");}if(s.data&&type=="GET"){s.url+=(s.url.match(/\?/)?"&":"?")+s.data;s.data=null;}if(s.global&&!jQuery.active++)jQuery.event.trigger("ajaxStart");var remote=/^(?:\w+:)?\/\/([^\/?#]+)/;if(s.dataType=="script"&&type=="GET"&&remote.test(s.url)&&remote.exec(s.url)[1]!=location.host){var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.src=s.url;if(s.scriptCharset)script.charset=s.scriptCharset;if(!jsonp){var done=false;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){done=true;success();complete();head.removeChild(script);}};}head.appendChild(script);return undefined;}var requestDone=false;var xhr=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();if(s.username)xhr.open(type,s.url,s.async,s.username,s.password);else -xhr.open(type,s.url,s.async);try{if(s.data)xhr.setRequestHeader("Content-Type",s.contentType);if(s.ifModified)xhr.setRequestHeader("If-Modified-Since",jQuery.lastModified[s.url]||"Thu, 01 Jan 1970 00:00:00 GMT");xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");xhr.setRequestHeader("Accept",s.dataType&&s.accepts[s.dataType]?s.accepts[s.dataType]+", */*":s.accepts._default);}catch(e){}if(s.beforeSend&&s.beforeSend(xhr,s)===false){s.global&&jQuery.active--;xhr.abort();return false;}if(s.global)jQuery.event.trigger("ajaxSend",[xhr,s]);var onreadystatechange=function(isTimeout){if(!requestDone&&xhr&&(xhr.readyState==4||isTimeout=="timeout")){requestDone=true;if(ival){clearInterval(ival);ival=null;}status=isTimeout=="timeout"&&"timeout"||!jQuery.httpSuccess(xhr)&&"error"||s.ifModified&&jQuery.httpNotModified(xhr,s.url)&&"notmodified"||"success";if(status=="success"){try{data=jQuery.httpData(xhr,s.dataType,s.dataFilter);}catch(e){status="parsererror";}}if(status=="success"){var modRes;try{modRes=xhr.getResponseHeader("Last-Modified");}catch(e){}if(s.ifModified&&modRes)jQuery.lastModified[s.url]=modRes;if(!jsonp)success();}else -jQuery.handleError(s,xhr,status);complete();if(s.async)xhr=null;}};if(s.async){var ival=setInterval(onreadystatechange,13);if(s.timeout>0)setTimeout(function(){if(xhr){xhr.abort();if(!requestDone)onreadystatechange("timeout");}},s.timeout);}try{xhr.send(s.data);}catch(e){jQuery.handleError(s,xhr,null,e);}if(!s.async)onreadystatechange();function success(){if(s.success)s.success(data,status);if(s.global)jQuery.event.trigger("ajaxSuccess",[xhr,s]);}function complete(){if(s.complete)s.complete(xhr,status);if(s.global)jQuery.event.trigger("ajaxComplete",[xhr,s]);if(s.global&&!--jQuery.active)jQuery.event.trigger("ajaxStop");}return xhr;},handleError:function(s,xhr,status,e){if(s.error)s.error(xhr,status,e);if(s.global)jQuery.event.trigger("ajaxError",[xhr,s,e]);},active:0,httpSuccess:function(xhr){try{return!xhr.status&&location.protocol=="file:"||(xhr.status>=200&&xhr.status<300)||xhr.status==304||xhr.status==1223||jQuery.browser.safari&&xhr.status==undefined;}catch(e){}return false;},httpNotModified:function(xhr,url){try{var xhrRes=xhr.getResponseHeader("Last-Modified");return xhr.status==304||xhrRes==jQuery.lastModified[url]||jQuery.browser.safari&&xhr.status==undefined;}catch(e){}return false;},httpData:function(xhr,type,filter){var ct=xhr.getResponseHeader("content-type"),xml=type=="xml"||!type&&ct&&ct.indexOf("xml")>=0,data=xml?xhr.responseXML:xhr.responseText;if(xml&&data.documentElement.tagName=="parsererror")throw"parsererror";if(filter)data=filter(data,type);if(type=="script")jQuery.globalEval(data);if(type=="json")data=eval("("+data+")");return data;},param:function(a){var s=[];if(a.constructor==Array||a.jquery)jQuery.each(a,function(){s.push(encodeURIComponent(this.name)+"="+encodeURIComponent(this.value));});else -for(var j in a)if(a[j]&&a[j].constructor==Array)jQuery.each(a[j],function(){s.push(encodeURIComponent(j)+"="+encodeURIComponent(this));});else -s.push(encodeURIComponent(j)+"="+encodeURIComponent(jQuery.isFunction(a[j])?a[j]():a[j]));return s.join("&").replace(/%20/g,"+");}});jQuery.fn.extend({show:function(speed,callback){return speed?this.animate({height:"show",width:"show",opacity:"show"},speed,callback):this.filter(":hidden").each(function(){this.style.display=this.oldblock||"";if(jQuery.css(this,"display")=="none"){var elem=jQuery("<"+this.tagName+" />").appendTo("body");this.style.display=elem.css("display");if(this.style.display=="none")this.style.display="block";elem.remove();}}).end();},hide:function(speed,callback){return speed?this.animate({height:"hide",width:"hide",opacity:"hide"},speed,callback):this.filter(":visible").each(function(){this.oldblock=this.oldblock||jQuery.css(this,"display");this.style.display="none";}).end();},_toggle:jQuery.fn.toggle,toggle:function(fn,fn2){return jQuery.isFunction(fn)&&jQuery.isFunction(fn2)?this._toggle.apply(this,arguments):fn?this.animate({height:"toggle",width:"toggle",opacity:"toggle"},fn,fn2):this.each(function(){jQuery(this)[jQuery(this).is(":hidden")?"show":"hide"]();});},slideDown:function(speed,callback){return this.animate({height:"show"},speed,callback);},slideUp:function(speed,callback){return this.animate({height:"hide"},speed,callback);},slideToggle:function(speed,callback){return this.animate({height:"toggle"},speed,callback);},fadeIn:function(speed,callback){return this.animate({opacity:"show"},speed,callback);},fadeOut:function(speed,callback){return this.animate({opacity:"hide"},speed,callback);},fadeTo:function(speed,to,callback){return this.animate({opacity:to},speed,callback);},animate:function(prop,speed,easing,callback){var optall=jQuery.speed(speed,easing,callback);return this[optall.queue===false?"each":"queue"](function(){if(this.nodeType!=1)return false;var opt=jQuery.extend({},optall),p,hidden=jQuery(this).is(":hidden"),self=this;for(p in prop){if(prop[p]=="hide"&&hidden||prop[p]=="show"&&!hidden)return opt.complete.call(this);if(p=="height"||p=="width"){opt.display=jQuery.css(this,"display");opt.overflow=this.style.overflow;}}if(opt.overflow!=null)this.style.overflow="hidden";opt.curAnim=jQuery.extend({},prop);jQuery.each(prop,function(name,val){var e=new jQuery.fx(self,opt,name);if(/toggle|show|hide/.test(val))e[val=="toggle"?hidden?"show":"hide":val](prop);else{var parts=val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),start=e.cur(true)||0;if(parts){var end=parseFloat(parts[2]),unit=parts[3]||"px";if(unit!="px"){self.style[name]=(end||1)+unit;start=((end||1)/e.cur(true))*start;self.style[name]=start+unit;}if(parts[1])end=((parts[1]=="-="?-1:1)*end)+start;e.custom(start,end,unit);}else -e.custom(start,val,"");}});return true;});},queue:function(type,fn){if(jQuery.isFunction(type)||(type&&type.constructor==Array)){fn=type;type="fx";}if(!type||(typeof type=="string"&&!fn))return queue(this[0],type);return this.each(function(){if(fn.constructor==Array)queue(this,type,fn);else{queue(this,type).push(fn);if(queue(this,type).length==1)fn.call(this);}});},stop:function(clearQueue,gotoEnd){var timers=jQuery.timers;if(clearQueue)this.queue([]);this.each(function(){for(var i=timers.length-1;i>=0;i--)if(timers[i].elem==this){if(gotoEnd)timers[i](true);timers.splice(i,1);}});if(!gotoEnd)this.dequeue();return this;}});var queue=function(elem,type,array){if(elem){type=type||"fx";var q=jQuery.data(elem,type+"queue");if(!q||array)q=jQuery.data(elem,type+"queue",jQuery.makeArray(array));}return q;};jQuery.fn.dequeue=function(type){type=type||"fx";return this.each(function(){var q=queue(this,type);q.shift();if(q.length)q[0].call(this);});};jQuery.extend({speed:function(speed,easing,fn){var opt=speed&&speed.constructor==Object?speed:{complete:fn||!fn&&easing||jQuery.isFunction(speed)&&speed,duration:speed,easing:fn&&easing||easing&&easing.constructor!=Function&&easing};opt.duration=(opt.duration&&opt.duration.constructor==Number?opt.duration:jQuery.fx.speeds[opt.duration])||jQuery.fx.speeds.def;opt.old=opt.complete;opt.complete=function(){if(opt.queue!==false)jQuery(this).dequeue();if(jQuery.isFunction(opt.old))opt.old.call(this);};return opt;},easing:{linear:function(p,n,firstNum,diff){return firstNum+diff*p;},swing:function(p,n,firstNum,diff){return((-Math.cos(p*Math.PI)/2)+0.5)*diff+firstNum;}},timers:[],timerId:null,fx:function(elem,options,prop){this.options=options;this.elem=elem;this.prop=prop;if(!options.orig)options.orig={};}});jQuery.fx.prototype={update:function(){if(this.options.step)this.options.step.call(this.elem,this.now,this);(jQuery.fx.step[this.prop]||jQuery.fx.step._default)(this);if(this.prop=="height"||this.prop=="width")this.elem.style.display="block";},cur:function(force){if(this.elem[this.prop]!=null&&this.elem.style[this.prop]==null)return this.elem[this.prop];var r=parseFloat(jQuery.css(this.elem,this.prop,force));return r&&r>-10000?r:parseFloat(jQuery.curCSS(this.elem,this.prop))||0;},custom:function(from,to,unit){this.startTime=now();this.start=from;this.end=to;this.unit=unit||this.unit||"px";this.now=this.start;this.pos=this.state=0;this.update();var self=this;function t(gotoEnd){return self.step(gotoEnd);}t.elem=this.elem;jQuery.timers.push(t);if(jQuery.timerId==null){jQuery.timerId=setInterval(function(){var timers=jQuery.timers;for(var i=0;i<timers.length;i++)if(!timers[i]())timers.splice(i--,1);if(!timers.length){clearInterval(jQuery.timerId);jQuery.timerId=null;}},13);}},show:function(){this.options.orig[this.prop]=jQuery.attr(this.elem.style,this.prop);this.options.show=true;this.custom(0,this.cur());if(this.prop=="width"||this.prop=="height")this.elem.style[this.prop]="1px";jQuery(this.elem).show();},hide:function(){this.options.orig[this.prop]=jQuery.attr(this.elem.style,this.prop);this.options.hide=true;this.custom(this.cur(),0);},step:function(gotoEnd){var t=now();if(gotoEnd||t>this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var done=true;for(var i in this.options.curAnim)if(this.options.curAnim[i]!==true)done=false;if(done){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(jQuery.css(this.elem,"display")=="none")this.elem.style.display="block";}if(this.options.hide)this.elem.style.display="none";if(this.options.hide||this.options.show)for(var p in this.options.curAnim)jQuery.attr(this.elem.style,p,this.options.orig[p]);}if(done)this.options.complete.call(this.elem);return false;}else{var n=t-this.startTime;this.state=n/this.options.duration;this.pos=jQuery.easing[this.options.easing||(jQuery.easing.swing?"swing":"linear")](this.state,n,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update();}return true;}};jQuery.extend(jQuery.fx,{speeds:{slow:600,fast:200,def:400},step:{scrollLeft:function(fx){fx.elem.scrollLeft=fx.now;},scrollTop:function(fx){fx.elem.scrollTop=fx.now;},opacity:function(fx){jQuery.attr(fx.elem.style,"opacity",fx.now);},_default:function(fx){fx.elem.style[fx.prop]=fx.now+fx.unit;}}});jQuery.fn.offset=function(){var left=0,top=0,elem=this[0],results;if(elem)with(jQuery.browser){var parent=elem.parentNode,offsetChild=elem,offsetParent=elem.offsetParent,doc=elem.ownerDocument,safari2=safari&&parseInt(version)<522&&!/adobeair/i.test(userAgent),css=jQuery.curCSS,fixed=css(elem,"position")=="fixed";if(elem.getBoundingClientRect){var box=elem.getBoundingClientRect();add(box.left+Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),box.top+Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));add(-doc.documentElement.clientLeft,-doc.documentElement.clientTop);}else{add(elem.offsetLeft,elem.offsetTop);while(offsetParent){add(offsetParent.offsetLeft,offsetParent.offsetTop);if(mozilla&&!/^t(able|d|h)$/i.test(offsetParent.tagName)||safari&&!safari2)border(offsetParent);if(!fixed&&css(offsetParent,"position")=="fixed")fixed=true;offsetChild=/^body$/i.test(offsetParent.tagName)?offsetChild:offsetParent;offsetParent=offsetParent.offsetParent;}while(parent&&parent.tagName&&!/^body|html$/i.test(parent.tagName)){if(!/^inline|table.*$/i.test(css(parent,"display")))add(-parent.scrollLeft,-parent.scrollTop);if(mozilla&&css(parent,"overflow")!="visible")border(parent);parent=parent.parentNode;}if((safari2&&(fixed||css(offsetChild,"position")=="absolute"))||(mozilla&&css(offsetChild,"position")!="absolute"))add(-doc.body.offsetLeft,-doc.body.offsetTop);if(fixed)add(Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));}results={top:top,left:left};}function border(elem){add(jQuery.curCSS(elem,"borderLeftWidth",true),jQuery.curCSS(elem,"borderTopWidth",true));}function add(l,t){left+=parseInt(l,10)||0;top+=parseInt(t,10)||0;}return results;};jQuery.fn.extend({position:function(){var left=0,top=0,results;if(this[0]){var offsetParent=this.offsetParent(),offset=this.offset(),parentOffset=/^body|html$/i.test(offsetParent[0].tagName)?{top:0,left:0}:offsetParent.offset();offset.top-=num(this,'marginTop');offset.left-=num(this,'marginLeft');parentOffset.top+=num(offsetParent,'borderTopWidth');parentOffset.left+=num(offsetParent,'borderLeftWidth');results={top:offset.top-parentOffset.top,left:offset.left-parentOffset.left};}return results;},offsetParent:function(){var offsetParent=this[0].offsetParent;while(offsetParent&&(!/^body|html$/i.test(offsetParent.tagName)&&jQuery.css(offsetParent,'position')=='static'))offsetParent=offsetParent.offsetParent;return jQuery(offsetParent);}});jQuery.each(['Left','Top'],function(i,name){var method='scroll'+name;jQuery.fn[method]=function(val){if(!this[0])return;return val!=undefined?this.each(function(){this==window||this==document?window.scrollTo(!i?val:jQuery(window).scrollLeft(),i?val:jQuery(window).scrollTop()):this[method]=val;}):this[0]==window||this[0]==document?self[i?'pageYOffset':'pageXOffset']||jQuery.boxModel&&document.documentElement[method]||document.body[method]:this[0][method];};});jQuery.each(["Height","Width"],function(i,name){var tl=i?"Left":"Top",br=i?"Right":"Bottom";jQuery.fn["inner"+name]=function(){return this[name.toLowerCase()]()+num(this,"padding"+tl)+num(this,"padding"+br);};jQuery.fn["outer"+name]=function(margin){return this["inner"+name]()+num(this,"border"+tl+"Width")+num(this,"border"+br+"Width")+(margin?num(this,"margin"+tl)+num(this,"margin"+br):0);};});})();
\ No newline at end of file +(function(){var l=this,g,x=l.jQuery,o=l.$,n=l.jQuery=l.$=function(D,E){return new n.fn.init(D,E)},C=/^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,f=/^.[^:#\[\.,]*$/;n.fn=n.prototype={init:function(D,G){D=D||document;if(D.nodeType){this[0]=D;this.length=1;this.context=D;return this}if(typeof D==="string"){var F=C.exec(D);if(F&&(F[1]||!G)){if(F[1]){D=n.clean([F[1]],G)}else{var H=document.getElementById(F[3]);if(H){if(H.id!=F[3]){return n().find(D)}var E=n(H);E.context=document;E.selector=D;return E}D=[]}}else{return n(G).find(D)}}else{if(n.isFunction(D)){return n(document).ready(D)}}if(D.selector&&D.context){this.selector=D.selector;this.context=D.context}return this.setArray(n.makeArray(D))},selector:"",jquery:"1.3",size:function(){return this.length},get:function(D){return D===g?n.makeArray(this):this[D]},pushStack:function(E,G,D){var F=n(E);F.prevObject=this;F.context=this.context;if(G==="find"){F.selector=this.selector+(this.selector?" ":"")+D}else{if(G){F.selector=this.selector+"."+G+"("+D+")"}}return F},setArray:function(D){this.length=0;Array.prototype.push.apply(this,D);return this},each:function(E,D){return n.each(this,E,D)},index:function(D){return n.inArray(D&&D.jquery?D[0]:D,this)},attr:function(E,G,F){var D=E;if(typeof E==="string"){if(G===g){return this[0]&&n[F||"attr"](this[0],E)}else{D={};D[E]=G}}return this.each(function(H){for(E in D){n.attr(F?this.style:this,E,n.prop(this,D[E],F,H,E))}})},css:function(D,E){if((D=="width"||D=="height")&&parseFloat(E)<0){E=g}return this.attr(D,E,"curCSS")},text:function(E){if(typeof E!=="object"&&E!=null){return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(E))}var D="";n.each(E||this,function(){n.each(this.childNodes,function(){if(this.nodeType!=8){D+=this.nodeType!=1?this.nodeValue:n.fn.text([this])}})});return D},wrapAll:function(D){if(this[0]){var E=n(D,this[0].ownerDocument).clone();if(this[0].parentNode){E.insertBefore(this[0])}E.map(function(){var F=this;while(F.firstChild){F=F.firstChild}return F}).append(this)}return this},wrapInner:function(D){return this.each(function(){n(this).contents().wrapAll(D)})},wrap:function(D){return this.each(function(){n(this).wrapAll(D)})},append:function(){return this.domManip(arguments,true,function(D){if(this.nodeType==1){this.appendChild(D)}})},prepend:function(){return this.domManip(arguments,true,function(D){if(this.nodeType==1){this.insertBefore(D,this.firstChild)}})},before:function(){return this.domManip(arguments,false,function(D){this.parentNode.insertBefore(D,this)})},after:function(){return this.domManip(arguments,false,function(D){this.parentNode.insertBefore(D,this.nextSibling)})},end:function(){return this.prevObject||n([])},push:[].push,find:function(D){if(this.length===1&&!/,/.test(D)){var F=this.pushStack([],"find",D);F.length=0;n.find(D,this[0],F);return F}else{var E=n.map(this,function(G){return n.find(D,G)});return this.pushStack(/[^+>] [^+>]/.test(D)?n.unique(E):E,"find",D)}},clone:function(E){var D=this.map(function(){if(!n.support.noCloneEvent&&!n.isXMLDoc(this)){var H=this.cloneNode(true),G=document.createElement("div");G.appendChild(H);return n.clean([G.innerHTML])[0]}else{return this.cloneNode(true)}});var F=D.find("*").andSelf().each(function(){if(this[h]!==g){this[h]=null}});if(E===true){this.find("*").andSelf().each(function(H){if(this.nodeType==3){return}var G=n.data(this,"events");for(var J in G){for(var I in G[J]){n.event.add(F[H],J,G[J][I],G[J][I].data)}}})}return D},filter:function(D){return this.pushStack(n.isFunction(D)&&n.grep(this,function(F,E){return D.call(F,E)})||n.multiFilter(D,n.grep(this,function(E){return E.nodeType===1})),"filter",D)},closest:function(D){var E=n.expr.match.POS.test(D)?n(D):null;return this.map(function(){var F=this;while(F&&F.ownerDocument){if(E?E.index(F)>-1:n(F).is(D)){return F}F=F.parentNode}})},not:function(D){if(typeof D==="string"){if(f.test(D)){return this.pushStack(n.multiFilter(D,this,true),"not",D)}else{D=n.multiFilter(D,this)}}var E=D.length&&D[D.length-1]!==g&&!D.nodeType;return this.filter(function(){return E?n.inArray(this,D)<0:this!=D})},add:function(D){return this.pushStack(n.unique(n.merge(this.get(),typeof D==="string"?n(D):n.makeArray(D))))},is:function(D){return !!D&&n.multiFilter(D,this).length>0},hasClass:function(D){return !!D&&this.is("."+D)},val:function(J){if(J===g){var D=this[0];if(D){if(n.nodeName(D,"option")){return(D.attributes.value||{}).specified?D.value:D.text}if(n.nodeName(D,"select")){var H=D.selectedIndex,K=[],L=D.options,G=D.type=="select-one";if(H<0){return null}for(var E=G?H:0,I=G?H+1:L.length;E<I;E++){var F=L[E];if(F.selected){J=n(F).val();if(G){return J}K.push(J)}}return K}return(D.value||"").replace(/\r/g,"")}return g}if(typeof J==="number"){J+=""}return this.each(function(){if(this.nodeType!=1){return}if(n.isArray(J)&&/radio|checkbox/.test(this.type)){this.checked=(n.inArray(this.value,J)>=0||n.inArray(this.name,J)>=0)}else{if(n.nodeName(this,"select")){var M=n.makeArray(J);n("option",this).each(function(){this.selected=(n.inArray(this.value,M)>=0||n.inArray(this.text,M)>=0)});if(!M.length){this.selectedIndex=-1}}else{this.value=J}}})},html:function(D){return D===g?(this[0]?this[0].innerHTML:null):this.empty().append(D)},replaceWith:function(D){return this.after(D).remove()},eq:function(D){return this.slice(D,+D+1)},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments),"slice",Array.prototype.slice.call(arguments).join(","))},map:function(D){return this.pushStack(n.map(this,function(F,E){return D.call(F,E,F)}))},andSelf:function(){return this.add(this.prevObject)},domManip:function(J,M,L){if(this[0]){var I=(this[0].ownerDocument||this[0]).createDocumentFragment(),F=n.clean(J,(this[0].ownerDocument||this[0]),I),H=I.firstChild,D=this.length>1?I.cloneNode(true):I;if(H){for(var G=0,E=this.length;G<E;G++){L.call(K(this[G],H),G>0?D.cloneNode(true):I)}}if(F){n.each(F,y)}}return this;function K(N,O){return M&&n.nodeName(N,"table")&&n.nodeName(O,"tr")?(N.getElementsByTagName("tbody")[0]||N.appendChild(N.ownerDocument.createElement("tbody"))):N}}};n.fn.init.prototype=n.fn;function y(D,E){if(E.src){n.ajax({url:E.src,async:false,dataType:"script"})}else{n.globalEval(E.text||E.textContent||E.innerHTML||"")}if(E.parentNode){E.parentNode.removeChild(E)}}function e(){return +new Date}n.extend=n.fn.extend=function(){var I=arguments[0]||{},G=1,H=arguments.length,D=false,F;if(typeof I==="boolean"){D=I;I=arguments[1]||{};G=2}if(typeof I!=="object"&&!n.isFunction(I)){I={}}if(H==G){I=this;--G}for(;G<H;G++){if((F=arguments[G])!=null){for(var E in F){var J=I[E],K=F[E];if(I===K){continue}if(D&&K&&typeof K==="object"&&!K.nodeType){I[E]=n.extend(D,J||(K.length!=null?[]:{}),K)}else{if(K!==g){I[E]=K}}}}}return I};var b=/z-?index|font-?weight|opacity|zoom|line-?height/i,p=document.defaultView||{},r=Object.prototype.toString;n.extend({noConflict:function(D){l.$=o;if(D){l.jQuery=x}return n},isFunction:function(D){return r.call(D)==="[object Function]"},isArray:function(D){return r.call(D)==="[object Array]"},isXMLDoc:function(D){return D.documentElement&&!D.body||D.tagName&&D.ownerDocument&&!D.ownerDocument.body},globalEval:function(F){F=n.trim(F);if(F){var E=document.getElementsByTagName("head")[0]||document.documentElement,D=document.createElement("script");D.type="text/javascript";if(n.support.scriptEval){D.appendChild(document.createTextNode(F))}else{D.text=F}E.insertBefore(D,E.firstChild);E.removeChild(D)}},nodeName:function(E,D){return E.nodeName&&E.nodeName.toUpperCase()==D.toUpperCase()},each:function(F,J,E){var D,G=0,H=F.length;if(E){if(H===g){for(D in F){if(J.apply(F[D],E)===false){break}}}else{for(;G<H;){if(J.apply(F[G++],E)===false){break}}}}else{if(H===g){for(D in F){if(J.call(F[D],D,F[D])===false){break}}}else{for(var I=F[0];G<H&&J.call(I,G,I)!==false;I=F[++G]){}}}return F},prop:function(G,H,F,E,D){if(n.isFunction(H)){H=H.call(G,E)}return typeof H==="number"&&F=="curCSS"&&!b.test(D)?H+"px":H},className:{add:function(D,E){n.each((E||"").split(/\s+/),function(F,G){if(D.nodeType==1&&!n.className.has(D.className,G)){D.className+=(D.className?" ":"")+G}})},remove:function(D,E){if(D.nodeType==1){D.className=E!==g?n.grep(D.className.split(/\s+/),function(F){return !n.className.has(E,F)}).join(" "):""}},has:function(E,D){return n.inArray(D,(E.className||E).toString().split(/\s+/))>-1}},swap:function(G,F,H){var D={};for(var E in F){D[E]=G.style[E];G.style[E]=F[E]}H.call(G);for(var E in F){G.style[E]=D[E]}},css:function(F,D,H){if(D=="width"||D=="height"){var J,E={position:"absolute",visibility:"hidden",display:"block"},I=D=="width"?["Left","Right"]:["Top","Bottom"];function G(){J=D=="width"?F.offsetWidth:F.offsetHeight;var L=0,K=0;n.each(I,function(){L+=parseFloat(n.curCSS(F,"padding"+this,true))||0;K+=parseFloat(n.curCSS(F,"border"+this+"Width",true))||0});J-=Math.round(L+K)}if(n(F).is(":visible")){G()}else{n.swap(F,E,G)}return Math.max(0,J)}return n.curCSS(F,D,H)},curCSS:function(H,E,F){var K,D=H.style;if(E=="opacity"&&!n.support.opacity){K=n.attr(D,"opacity");return K==""?"1":K}if(E.match(/float/i)){E=v}if(!F&&D&&D[E]){K=D[E]}else{if(p.getComputedStyle){if(E.match(/float/i)){E="float"}E=E.replace(/([A-Z])/g,"-$1").toLowerCase();var L=p.getComputedStyle(H,null);if(L){K=L.getPropertyValue(E)}if(E=="opacity"&&K==""){K="1"}}else{if(H.currentStyle){var I=E.replace(/\-(\w)/g,function(M,N){return N.toUpperCase()});K=H.currentStyle[E]||H.currentStyle[I];if(!/^\d+(px)?$/i.test(K)&&/^\d/.test(K)){var G=D.left,J=H.runtimeStyle.left;H.runtimeStyle.left=H.currentStyle.left;D.left=K||0;K=D.pixelLeft+"px";D.left=G;H.runtimeStyle.left=J}}}}return K},clean:function(E,J,H){J=J||document;if(typeof J.createElement==="undefined"){J=J.ownerDocument||J[0]&&J[0].ownerDocument||document}if(!H&&E.length===1&&typeof E[0]==="string"){var G=/^<(\w+)\s*\/?>$/.exec(E[0]);if(G){return[J.createElement(G[1])]}}var F=[],D=[],K=J.createElement("div");n.each(E,function(O,Q){if(typeof Q==="number"){Q+=""}if(!Q){return}if(typeof Q==="string"){Q=Q.replace(/(<(\w+)[^>]*?)\/>/g,function(S,T,R){return R.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?S:T+"></"+R+">"});var N=n.trim(Q).toLowerCase();var P=!N.indexOf("<opt")&&[1,"<select multiple='multiple'>","</select>"]||!N.indexOf("<leg")&&[1,"<fieldset>","</fieldset>"]||N.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"<table>","</table>"]||!N.indexOf("<tr")&&[2,"<table><tbody>","</tbody></table>"]||(!N.indexOf("<td")||!N.indexOf("<th"))&&[3,"<table><tbody><tr>","</tr></tbody></table>"]||!N.indexOf("<col")&&[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"]||!n.support.htmlSerialize&&[1,"div<div>","</div>"]||[0,"",""];K.innerHTML=P[1]+Q+P[2];while(P[0]--){K=K.lastChild}if(!n.support.tbody){var M=!N.indexOf("<table")&&N.indexOf("<tbody")<0?K.firstChild&&K.firstChild.childNodes:P[1]=="<table>"&&N.indexOf("<tbody")<0?K.childNodes:[];for(var L=M.length-1;L>=0;--L){if(n.nodeName(M[L],"tbody")&&!M[L].childNodes.length){M[L].parentNode.removeChild(M[L])}}}if(!n.support.leadingWhitespace&&/^\s/.test(Q)){K.insertBefore(J.createTextNode(Q.match(/^\s*/)[0]),K.firstChild)}Q=n.makeArray(K.childNodes)}if(Q.nodeType){F.push(Q)}else{F=n.merge(F,Q)}});if(H){for(var I=0;F[I];I++){if(n.nodeName(F[I],"script")&&(!F[I].type||F[I].type.toLowerCase()==="text/javascript")){D.push(F[I].parentNode?F[I].parentNode.removeChild(F[I]):F[I])}else{if(F[I].nodeType===1){F.splice.apply(F,[I+1,0].concat(n.makeArray(F[I].getElementsByTagName("script"))))}H.appendChild(F[I])}}return D}return F},attr:function(I,F,J){if(!I||I.nodeType==3||I.nodeType==8){return g}var G=!n.isXMLDoc(I),K=J!==g;F=G&&n.props[F]||F;if(I.tagName){var E=/href|src|style/.test(F);if(F=="selected"&&I.parentNode){I.parentNode.selectedIndex}if(F in I&&G&&!E){if(K){if(F=="type"&&n.nodeName(I,"input")&&I.parentNode){throw"type property can't be changed"}I[F]=J}if(n.nodeName(I,"form")&&I.getAttributeNode(F)){return I.getAttributeNode(F).nodeValue}if(F=="tabIndex"){var H=I.getAttributeNode("tabIndex");return H&&H.specified?H.value:I.nodeName.match(/^(a|area|button|input|object|select|textarea)$/i)?0:g}return I[F]}if(!n.support.style&&G&&F=="style"){return n.attr(I.style,"cssText",J)}if(K){I.setAttribute(F,""+J)}var D=!n.support.hrefNormalized&&G&&E?I.getAttribute(F,2):I.getAttribute(F);return D===null?g:D}if(!n.support.opacity&&F=="opacity"){if(K){I.zoom=1;I.filter=(I.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(J)+""=="NaN"?"":"alpha(opacity="+J*100+")")}return I.filter&&I.filter.indexOf("opacity=")>=0?(parseFloat(I.filter.match(/opacity=([^)]*)/)[1])/100)+"":""}F=F.replace(/-([a-z])/ig,function(L,M){return M.toUpperCase()});if(K){I[F]=J}return I[F]},trim:function(D){return(D||"").replace(/^\s+|\s+$/g,"")},makeArray:function(F){var D=[];if(F!=null){var E=F.length;if(E==null||typeof F==="string"||n.isFunction(F)||F.setInterval){D[0]=F}else{while(E){D[--E]=F[E]}}}return D},inArray:function(F,G){for(var D=0,E=G.length;D<E;D++){if(G[D]===F){return D}}return -1},merge:function(G,D){var E=0,F,H=G.length;if(!n.support.getAll){while((F=D[E++])!=null){if(F.nodeType!=8){G[H++]=F}}}else{while((F=D[E++])!=null){G[H++]=F}}return G},unique:function(J){var E=[],D={};try{for(var F=0,G=J.length;F<G;F++){var I=n.data(J[F]);if(!D[I]){D[I]=true;E.push(J[F])}}}catch(H){E=J}return E},grep:function(E,I,D){var F=[];for(var G=0,H=E.length;G<H;G++){if(!D!=!I(E[G],G)){F.push(E[G])}}return F},map:function(D,I){var E=[];for(var F=0,G=D.length;F<G;F++){var H=I(D[F],F);if(H!=null){E[E.length]=H}}return E.concat.apply([],E)}});var B=navigator.userAgent.toLowerCase();n.browser={version:(B.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[0,"0"])[1],safari:/webkit/.test(B),opera:/opera/.test(B),msie:/msie/.test(B)&&!/opera/.test(B),mozilla:/mozilla/.test(B)&&!/(compatible|webkit)/.test(B)};n.each({parent:function(D){return D.parentNode},parents:function(D){return n.dir(D,"parentNode")},next:function(D){return n.nth(D,2,"nextSibling")},prev:function(D){return n.nth(D,2,"previousSibling")},nextAll:function(D){return n.dir(D,"nextSibling")},prevAll:function(D){return n.dir(D,"previousSibling")},siblings:function(D){return n.sibling(D.parentNode.firstChild,D)},children:function(D){return n.sibling(D.firstChild)},contents:function(D){return n.nodeName(D,"iframe")?D.contentDocument||D.contentWindow.document:n.makeArray(D.childNodes)}},function(D,E){n.fn[D]=function(F){var G=n.map(this,E);if(F&&typeof F=="string"){G=n.multiFilter(F,G)}return this.pushStack(n.unique(G),D,F)}});n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(D,E){n.fn[D]=function(){var F=arguments;return this.each(function(){for(var G=0,H=F.length;G<H;G++){n(F[G])[E](this)}})}});n.each({removeAttr:function(D){n.attr(this,D,"");if(this.nodeType==1){this.removeAttribute(D)}},addClass:function(D){n.className.add(this,D)},removeClass:function(D){n.className.remove(this,D)},toggleClass:function(E,D){if(typeof D!=="boolean"){D=!n.className.has(this,E)}n.className[D?"add":"remove"](this,E)},remove:function(D){if(!D||n.filter(D,[this]).length){n("*",this).add([this]).each(function(){n.event.remove(this);n.removeData(this)});if(this.parentNode){this.parentNode.removeChild(this)}}},empty:function(){n(">*",this).remove();while(this.firstChild){this.removeChild(this.firstChild)}}},function(D,E){n.fn[D]=function(){return this.each(E,arguments)}});function j(D,E){return D[0]&&parseInt(n.curCSS(D[0],E,true),10)||0}var h="jQuery"+e(),u=0,z={};n.extend({cache:{},data:function(E,D,F){E=E==l?z:E;var G=E[h];if(!G){G=E[h]=++u}if(D&&!n.cache[G]){n.cache[G]={}}if(F!==g){n.cache[G][D]=F}return D?n.cache[G][D]:G},removeData:function(E,D){E=E==l?z:E;var G=E[h];if(D){if(n.cache[G]){delete n.cache[G][D];D="";for(D in n.cache[G]){break}if(!D){n.removeData(E)}}}else{try{delete E[h]}catch(F){if(E.removeAttribute){E.removeAttribute(h)}}delete n.cache[G]}},queue:function(E,D,G){if(E){D=(D||"fx")+"queue";var F=n.data(E,D);if(!F||n.isArray(G)){F=n.data(E,D,n.makeArray(G))}else{if(G){F.push(G)}}}return F},dequeue:function(G,F){var D=n.queue(G,F),E=D.shift();if(!F||F==="fx"){E=D[0]}if(E!==g){E.call(G)}}});n.fn.extend({data:function(D,F){var G=D.split(".");G[1]=G[1]?"."+G[1]:"";if(F===g){var E=this.triggerHandler("getData"+G[1]+"!",[G[0]]);if(E===g&&this.length){E=n.data(this[0],D)}return E===g&&G[1]?this.data(G[0]):E}else{return this.trigger("setData"+G[1]+"!",[G[0],F]).each(function(){n.data(this,D,F)})}},removeData:function(D){return this.each(function(){n.removeData(this,D)})},queue:function(D,E){if(typeof D!=="string"){E=D;D="fx"}if(E===g){return n.queue(this[0],D)}return this.each(function(){var F=n.queue(this,D,E);if(D=="fx"&&F.length==1){F[0].call(this)}})},dequeue:function(D){return this.each(function(){n.dequeue(this,D)})}}); +/* + * Sizzle CSS Selector Engine - v0.9.1 + * Copyright 2009, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){var N=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g,I=0,F=Object.prototype.toString;var E=function(ae,S,aa,V){aa=aa||[];S=S||document;if(S.nodeType!==1&&S.nodeType!==9){return[]}if(!ae||typeof ae!=="string"){return aa}var ab=[],ac,Y,ah,ag,Z,R,Q=true;N.lastIndex=0;while((ac=N.exec(ae))!==null){ab.push(ac[1]);if(ac[2]){R=RegExp.rightContext;break}}if(ab.length>1&&G.match.POS.exec(ae)){if(ab.length===2&&G.relative[ab[0]]){var U="",X;while((X=G.match.POS.exec(ae))){U+=X[0];ae=ae.replace(G.match.POS,"")}Y=E.filter(U,E(/\s$/.test(ae)?ae+"*":ae,S))}else{Y=G.relative[ab[0]]?[S]:E(ab.shift(),S);while(ab.length){var P=[];ae=ab.shift();if(G.relative[ae]){ae+=ab.shift()}for(var af=0,ad=Y.length;af<ad;af++){E(ae,Y[af],P)}Y=P}}}else{var ai=V?{expr:ab.pop(),set:D(V)}:E.find(ab.pop(),ab.length===1&&S.parentNode?S.parentNode:S);Y=E.filter(ai.expr,ai.set);if(ab.length>0){ah=D(Y)}else{Q=false}while(ab.length){var T=ab.pop(),W=T;if(!G.relative[T]){T=""}else{W=ab.pop()}if(W==null){W=S}G.relative[T](ah,W,M(S))}}if(!ah){ah=Y}if(!ah){throw"Syntax error, unrecognized expression: "+(T||ae)}if(F.call(ah)==="[object Array]"){if(!Q){aa.push.apply(aa,ah)}else{if(S.nodeType===1){for(var af=0;ah[af]!=null;af++){if(ah[af]&&(ah[af]===true||ah[af].nodeType===1&&H(S,ah[af]))){aa.push(Y[af])}}}else{for(var af=0;ah[af]!=null;af++){if(ah[af]&&ah[af].nodeType===1){aa.push(Y[af])}}}}}else{D(ah,aa)}if(R){E(R,S,aa,V)}return aa};E.matches=function(P,Q){return E(P,null,null,Q)};E.find=function(V,S){var W,Q;if(!V){return[]}for(var R=0,P=G.order.length;R<P;R++){var T=G.order[R],Q;if((Q=G.match[T].exec(V))){var U=RegExp.leftContext;if(U.substr(U.length-1)!=="\\"){Q[1]=(Q[1]||"").replace(/\\/g,"");W=G.find[T](Q,S);if(W!=null){V=V.replace(G.match[T],"");break}}}}if(!W){W=S.getElementsByTagName("*")}return{set:W,expr:V}};E.filter=function(S,ac,ad,T){var Q=S,Y=[],ah=ac,V,ab;while(S&&ac.length){for(var U in G.filter){if((V=G.match[U].exec(S))!=null){var Z=G.filter[U],R=null,X=0,aa,ag;ab=false;if(ah==Y){Y=[]}if(G.preFilter[U]){V=G.preFilter[U](V,ah,ad,Y,T);if(!V){ab=aa=true}else{if(V===true){continue}else{if(V[0]===true){R=[];var W=null,af;for(var ae=0;(af=ah[ae])!==g;ae++){if(af&&W!==af){R.push(af);W=af}}}}}}if(V){for(var ae=0;(ag=ah[ae])!==g;ae++){if(ag){if(R&&ag!=R[X]){X++}aa=Z(ag,V,X,R);var P=T^!!aa;if(ad&&aa!=null){if(P){ab=true}else{ah[ae]=false}}else{if(P){Y.push(ag);ab=true}}}}}if(aa!==g){if(!ad){ah=Y}S=S.replace(G.match[U],"");if(!ab){return[]}break}}}S=S.replace(/\s*,\s*/,"");if(S==Q){if(ab==null){throw"Syntax error, unrecognized expression: "+S}else{break}}Q=S}return ah};var G=E.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF_-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF_-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(P){return P.getAttribute("href")}},relative:{"+":function(T,Q){for(var R=0,P=T.length;R<P;R++){var S=T[R];if(S){var U=S.previousSibling;while(U&&U.nodeType!==1){U=U.previousSibling}T[R]=typeof Q==="string"?U||false:U===Q}}if(typeof Q==="string"){E.filter(Q,T,true)}},">":function(U,Q,V){if(typeof Q==="string"&&!/\W/.test(Q)){Q=V?Q:Q.toUpperCase();for(var R=0,P=U.length;R<P;R++){var T=U[R];if(T){var S=T.parentNode;U[R]=S.nodeName===Q?S:false}}}else{for(var R=0,P=U.length;R<P;R++){var T=U[R];if(T){U[R]=typeof Q==="string"?T.parentNode:T.parentNode===Q}}if(typeof Q==="string"){E.filter(Q,U,true)}}},"":function(S,Q,U){var R="done"+(I++),P=O;if(!Q.match(/\W/)){var T=Q=U?Q:Q.toUpperCase();P=L}P("parentNode",Q,R,S,T,U)},"~":function(S,Q,U){var R="done"+(I++),P=O;if(typeof Q==="string"&&!Q.match(/\W/)){var T=Q=U?Q:Q.toUpperCase();P=L}P("previousSibling",Q,R,S,T,U)}},find:{ID:function(Q,R){if(R.getElementById){var P=R.getElementById(Q[1]);return P?[P]:[]}},NAME:function(P,Q){return Q.getElementsByName?Q.getElementsByName(P[1]):null},TAG:function(P,Q){return Q.getElementsByTagName(P[1])}},preFilter:{CLASS:function(S,Q,R,P,U){S=" "+S[1].replace(/\\/g,"")+" ";for(var T=0;Q[T];T++){if(U^(" "+Q[T].className+" ").indexOf(S)>=0){if(!R){P.push(Q[T])}}else{if(R){Q[T]=false}}}return false},ID:function(P){return P[1].replace(/\\/g,"")},TAG:function(Q,P){for(var R=0;!P[R];R++){}return M(P[R])?Q[1]:Q[1].toUpperCase()},CHILD:function(P){if(P[1]=="nth"){var Q=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(P[2]=="even"&&"2n"||P[2]=="odd"&&"2n+1"||!/\D/.test(P[2])&&"0n+"+P[2]||P[2]);P[2]=(Q[1]+(Q[2]||1))-0;P[3]=Q[3]-0}P[0]="done"+(I++);return P},ATTR:function(Q){var P=Q[1];if(G.attrMap[P]){Q[1]=G.attrMap[P]}if(Q[2]==="~="){Q[4]=" "+Q[4]+" "}return Q},PSEUDO:function(T,Q,R,P,U){if(T[1]==="not"){if(T[3].match(N).length>1){T[3]=E(T[3],null,null,Q)}else{var S=E.filter(T[3],Q,R,true^U);if(!R){P.push.apply(P,S)}return false}}else{if(G.match.POS.test(T[0])){return true}}return T},POS:function(P){P.unshift(true);return P}},filters:{enabled:function(P){return P.disabled===false&&P.type!=="hidden"},disabled:function(P){return P.disabled===true},checked:function(P){return P.checked===true},selected:function(P){P.parentNode.selectedIndex;return P.selected===true},parent:function(P){return !!P.firstChild},empty:function(P){return !P.firstChild},has:function(R,Q,P){return !!E(P[3],R).length},header:function(P){return/h\d/i.test(P.nodeName)},text:function(P){return"text"===P.type},radio:function(P){return"radio"===P.type},checkbox:function(P){return"checkbox"===P.type},file:function(P){return"file"===P.type},password:function(P){return"password"===P.type},submit:function(P){return"submit"===P.type},image:function(P){return"image"===P.type},reset:function(P){return"reset"===P.type},button:function(P){return"button"===P.type||P.nodeName.toUpperCase()==="BUTTON"},input:function(P){return/input|select|textarea|button/i.test(P.nodeName)}},setFilters:{first:function(Q,P){return P===0},last:function(R,Q,P,S){return Q===S.length-1},even:function(Q,P){return P%2===0},odd:function(Q,P){return P%2===1},lt:function(R,Q,P){return Q<P[3]-0},gt:function(R,Q,P){return Q>P[3]-0},nth:function(R,Q,P){return P[3]-0==Q},eq:function(R,Q,P){return P[3]-0==Q}},filter:{CHILD:function(P,S){var V=S[1],W=P.parentNode;var U="child"+W.childNodes.length;if(W&&(!W[U]||!P.nodeIndex)){var T=1;for(var Q=W.firstChild;Q;Q=Q.nextSibling){if(Q.nodeType==1){Q.nodeIndex=T++}}W[U]=T-1}if(V=="first"){return P.nodeIndex==1}else{if(V=="last"){return P.nodeIndex==W[U]}else{if(V=="only"){return W[U]==1}else{if(V=="nth"){var Y=false,R=S[2],X=S[3];if(R==1&&X==0){return true}if(R==0){if(P.nodeIndex==X){Y=true}}else{if((P.nodeIndex-X)%R==0&&(P.nodeIndex-X)/R>=0){Y=true}}return Y}}}}},PSEUDO:function(V,R,S,W){var Q=R[1],T=G.filters[Q];if(T){return T(V,S,R,W)}else{if(Q==="contains"){return(V.textContent||V.innerText||"").indexOf(R[3])>=0}else{if(Q==="not"){var U=R[3];for(var S=0,P=U.length;S<P;S++){if(U[S]===V){return false}}return true}}}},ID:function(Q,P){return Q.nodeType===1&&Q.getAttribute("id")===P},TAG:function(Q,P){return(P==="*"&&Q.nodeType===1)||Q.nodeName===P},CLASS:function(Q,P){return P.test(Q.className)},ATTR:function(T,R){var P=G.attrHandle[R[1]]?G.attrHandle[R[1]](T):T[R[1]]||T.getAttribute(R[1]),U=P+"",S=R[2],Q=R[4];return P==null?false:S==="="?U===Q:S==="*="?U.indexOf(Q)>=0:S==="~="?(" "+U+" ").indexOf(Q)>=0:!R[4]?P:S==="!="?U!=Q:S==="^="?U.indexOf(Q)===0:S==="$="?U.substr(U.length-Q.length)===Q:S==="|="?U===Q||U.substr(0,Q.length+1)===Q+"-":false},POS:function(T,Q,R,U){var P=Q[2],S=G.setFilters[P];if(S){return S(T,R,Q,U)}}}};for(var K in G.match){G.match[K]=RegExp(G.match[K].source+/(?![^\[]*\])(?![^\(]*\))/.source)}var D=function(Q,P){Q=Array.prototype.slice.call(Q);if(P){P.push.apply(P,Q);return P}return Q};try{Array.prototype.slice.call(document.documentElement.childNodes)}catch(J){D=function(T,S){var Q=S||[];if(F.call(T)==="[object Array]"){Array.prototype.push.apply(Q,T)}else{if(typeof T.length==="number"){for(var R=0,P=T.length;R<P;R++){Q.push(T[R])}}else{for(var R=0;T[R];R++){Q.push(T[R])}}}return Q}}(function(){var Q=document.createElement("form"),R="script"+(new Date).getTime();Q.innerHTML="<input name='"+R+"'/>";var P=document.documentElement;P.insertBefore(Q,P.firstChild);if(!!document.getElementById(R)){G.find.ID=function(T,U){if(U.getElementById){var S=U.getElementById(T[1]);return S?S.id===T[1]||S.getAttributeNode&&S.getAttributeNode("id").nodeValue===T[1]?[S]:g:[]}};G.filter.ID=function(U,S){var T=U.getAttributeNode&&U.getAttributeNode("id");return U.nodeType===1&&T&&T.nodeValue===S}}P.removeChild(Q)})();(function(){var P=document.createElement("div");P.appendChild(document.createComment(""));if(P.getElementsByTagName("*").length>0){G.find.TAG=function(Q,U){var T=U.getElementsByTagName(Q[1]);if(Q[1]==="*"){var S=[];for(var R=0;T[R];R++){if(T[R].nodeType===1){S.push(T[R])}}T=S}return T}}P.innerHTML="<a href='#'></a>";if(P.firstChild.getAttribute("href")!=="#"){G.attrHandle.href=function(Q){return Q.getAttribute("href",2)}}})();if(document.querySelectorAll){(function(){var P=E;E=function(T,S,Q,R){S=S||document;if(!R&&S.nodeType===9){try{return D(S.querySelectorAll(T),Q)}catch(U){}}return P(T,S,Q,R)};E.find=P.find;E.filter=P.filter;E.selectors=P.selectors;E.matches=P.matches})()}if(document.documentElement.getElementsByClassName){G.order.splice(1,0,"CLASS");G.find.CLASS=function(P,Q){return Q.getElementsByClassName(P[1])}}function L(Q,W,V,Z,X,Y){for(var T=0,R=Z.length;T<R;T++){var P=Z[T];if(P){P=P[Q];var U=false;while(P&&P.nodeType){var S=P[V];if(S){U=Z[S];break}if(P.nodeType===1&&!Y){P[V]=T}if(P.nodeName===W){U=P;break}P=P[Q]}Z[T]=U}}}function O(Q,V,U,Y,W,X){for(var S=0,R=Y.length;S<R;S++){var P=Y[S];if(P){P=P[Q];var T=false;while(P&&P.nodeType){if(P[U]){T=Y[P[U]];break}if(P.nodeType===1){if(!X){P[U]=S}if(typeof V!=="string"){if(P===V){T=true;break}}else{if(E.filter(V,[P]).length>0){T=P;break}}}P=P[Q]}Y[S]=T}}}var H=document.compareDocumentPosition?function(Q,P){return Q.compareDocumentPosition(P)&16}:function(Q,P){return Q!==P&&(Q.contains?Q.contains(P):true)};var M=function(P){return P.documentElement&&!P.body||P.tagName&&P.ownerDocument&&!P.ownerDocument.body};n.find=E;n.filter=E.filter;n.expr=E.selectors;n.expr[":"]=n.expr.filters;E.selectors.filters.hidden=function(P){return"hidden"===P.type||n.css(P,"display")==="none"||n.css(P,"visibility")==="hidden"};E.selectors.filters.visible=function(P){return"hidden"!==P.type&&n.css(P,"display")!=="none"&&n.css(P,"visibility")!=="hidden"};E.selectors.filters.animated=function(P){return n.grep(n.timers,function(Q){return P===Q.elem}).length};n.multiFilter=function(R,P,Q){if(Q){R=":not("+R+")"}return E.matches(R,P)};n.dir=function(R,Q){var P=[],S=R[Q];while(S&&S!=document){if(S.nodeType==1){P.push(S)}S=S[Q]}return P};n.nth=function(T,P,R,S){P=P||1;var Q=0;for(;T;T=T[R]){if(T.nodeType==1&&++Q==P){break}}return T};n.sibling=function(R,Q){var P=[];for(;R;R=R.nextSibling){if(R.nodeType==1&&R!=Q){P.push(R)}}return P};return;l.Sizzle=E})();n.event={add:function(H,E,G,J){if(H.nodeType==3||H.nodeType==8){return}if(H.setInterval&&H!=l){H=l}if(!G.guid){G.guid=this.guid++}if(J!==g){var F=G;G=this.proxy(F);G.data=J}var D=n.data(H,"events")||n.data(H,"events",{}),I=n.data(H,"handle")||n.data(H,"handle",function(){return typeof n!=="undefined"&&!n.event.triggered?n.event.handle.apply(arguments.callee.elem,arguments):g});I.elem=H;n.each(E.split(/\s+/),function(L,M){var N=M.split(".");M=N.shift();G.type=N.slice().sort().join(".");var K=D[M];if(n.event.specialAll[M]){n.event.specialAll[M].setup.call(H,J,N)}if(!K){K=D[M]={};if(!n.event.special[M]||n.event.special[M].setup.call(H,J,N)===false){if(H.addEventListener){H.addEventListener(M,I,false)}else{if(H.attachEvent){H.attachEvent("on"+M,I)}}}}K[G.guid]=G;n.event.global[M]=true});H=null},guid:1,global:{},remove:function(J,G,I){if(J.nodeType==3||J.nodeType==8){return}var F=n.data(J,"events"),E,D;if(F){if(G===g||(typeof G==="string"&&G.charAt(0)==".")){for(var H in F){this.remove(J,H+(G||""))}}else{if(G.type){I=G.handler;G=G.type}n.each(G.split(/\s+/),function(L,N){var P=N.split(".");N=P.shift();var M=RegExp("(^|\\.)"+P.slice().sort().join(".*\\.")+"(\\.|$)");if(F[N]){if(I){delete F[N][I.guid]}else{for(var O in F[N]){if(M.test(F[N][O].type)){delete F[N][O]}}}if(n.event.specialAll[N]){n.event.specialAll[N].teardown.call(J,P)}for(E in F[N]){break}if(!E){if(!n.event.special[N]||n.event.special[N].teardown.call(J,P)===false){if(J.removeEventListener){J.removeEventListener(N,n.data(J,"handle"),false)}else{if(J.detachEvent){J.detachEvent("on"+N,n.data(J,"handle"))}}}E=null;delete F[N]}}})}for(E in F){break}if(!E){var K=n.data(J,"handle");if(K){K.elem=null}n.removeData(J,"events");n.removeData(J,"handle")}}},trigger:function(H,J,G,D){var F=H.type||H;if(!D){H=typeof H==="object"?H[h]?H:n.extend(n.Event(F),H):n.Event(F);if(F.indexOf("!")>=0){H.type=F=F.slice(0,-1);H.exclusive=true}if(!G){H.stopPropagation();if(this.global[F]){n.each(n.cache,function(){if(this.events&&this.events[F]){n.event.trigger(H,J,this.handle.elem)}})}}if(!G||G.nodeType==3||G.nodeType==8){return g}H.result=g;H.target=G;J=n.makeArray(J);J.unshift(H)}H.currentTarget=G;var I=n.data(G,"handle");if(I){I.apply(G,J)}if((!G[F]||(n.nodeName(G,"a")&&F=="click"))&&G["on"+F]&&G["on"+F].apply(G,J)===false){H.result=false}if(!D&&G[F]&&!H.isDefaultPrevented()&&!(n.nodeName(G,"a")&&F=="click")){this.triggered=true;try{G[F]()}catch(K){}}this.triggered=false;if(!H.isPropagationStopped()){var E=G.parentNode||G.ownerDocument;if(E){n.event.trigger(H,J,E,true)}}},handle:function(J){var I,D;J=arguments[0]=n.event.fix(J||l.event);var K=J.type.split(".");J.type=K.shift();I=!K.length&&!J.exclusive;var H=RegExp("(^|\\.)"+K.slice().sort().join(".*\\.")+"(\\.|$)");D=(n.data(this,"events")||{})[J.type];for(var F in D){var G=D[F];if(I||H.test(G.type)){J.handler=G;J.data=G.data;var E=G.apply(this,arguments);if(E!==g){J.result=E;if(E===false){J.preventDefault();J.stopPropagation()}}if(J.isImmediatePropagationStopped()){break}}}},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(G){if(G[h]){return G}var E=G;G=n.Event(E);for(var F=this.props.length,I;F;){I=this.props[--F];G[I]=E[I]}if(!G.target){G.target=G.srcElement||document}if(G.target.nodeType==3){G.target=G.target.parentNode}if(!G.relatedTarget&&G.fromElement){G.relatedTarget=G.fromElement==G.target?G.toElement:G.fromElement}if(G.pageX==null&&G.clientX!=null){var H=document.documentElement,D=document.body;G.pageX=G.clientX+(H&&H.scrollLeft||D&&D.scrollLeft||0)-(H.clientLeft||0);G.pageY=G.clientY+(H&&H.scrollTop||D&&D.scrollTop||0)-(H.clientTop||0)}if(!G.which&&((G.charCode||G.charCode===0)?G.charCode:G.keyCode)){G.which=G.charCode||G.keyCode}if(!G.metaKey&&G.ctrlKey){G.metaKey=G.ctrlKey}if(!G.which&&G.button){G.which=(G.button&1?1:(G.button&2?3:(G.button&4?2:0)))}return G},proxy:function(E,D){D=D||function(){return E.apply(this,arguments)};D.guid=E.guid=E.guid||D.guid||this.guid++;return D},special:{ready:{setup:A,teardown:function(){}}},specialAll:{live:{setup:function(D,E){n.event.add(this,E[0],c)},teardown:function(F){if(F.length){var D=0,E=RegExp("(^|\\.)"+F[0]+"(\\.|$)");n.each((n.data(this,"events").live||{}),function(){if(E.test(this.type)){D++}});if(D<1){n.event.remove(this,F[0],c)}}}}}};n.Event=function(D){if(!this.preventDefault){return new n.Event(D)}if(D&&D.type){this.originalEvent=D;this.type=D.type;this.timeStamp=D.timeStamp}else{this.type=D}if(!this.timeStamp){this.timeStamp=e()}this[h]=true};function k(){return false}function t(){return true}n.Event.prototype={preventDefault:function(){this.isDefaultPrevented=t;var D=this.originalEvent;if(!D){return}if(D.preventDefault){D.preventDefault()}D.returnValue=false},stopPropagation:function(){this.isPropagationStopped=t;var D=this.originalEvent;if(!D){return}if(D.stopPropagation){D.stopPropagation()}D.cancelBubble=true},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=t;this.stopPropagation()},isDefaultPrevented:k,isPropagationStopped:k,isImmediatePropagationStopped:k};var a=function(E){var D=E.relatedTarget;while(D&&D!=this){try{D=D.parentNode}catch(F){D=this}}if(D!=this){E.type=E.data;n.event.handle.apply(this,arguments)}};n.each({mouseover:"mouseenter",mouseout:"mouseleave"},function(E,D){n.event.special[D]={setup:function(){n.event.add(this,E,a,D)},teardown:function(){n.event.remove(this,E,a)}}});n.fn.extend({bind:function(E,F,D){return E=="unload"?this.one(E,F,D):this.each(function(){n.event.add(this,E,D||F,D&&F)})},one:function(F,G,E){var D=n.event.proxy(E||G,function(H){n(this).unbind(H,D);return(E||G).apply(this,arguments)});return this.each(function(){n.event.add(this,F,D,E&&G)})},unbind:function(E,D){return this.each(function(){n.event.remove(this,E,D)})},trigger:function(D,E){return this.each(function(){n.event.trigger(D,E,this)})},triggerHandler:function(D,F){if(this[0]){var E=n.Event(D);E.preventDefault();E.stopPropagation();n.event.trigger(E,F,this[0]);return E.result}},toggle:function(F){var D=arguments,E=1;while(E<D.length){n.event.proxy(F,D[E++])}return this.click(n.event.proxy(F,function(G){this.lastToggle=(this.lastToggle||0)%E;G.preventDefault();return D[this.lastToggle++].apply(this,arguments)||false}))},hover:function(D,E){return this.mouseenter(D).mouseleave(E)},ready:function(D){A();if(n.isReady){D.call(document,n)}else{n.readyList.push(D)}return this},live:function(F,E){var D=n.event.proxy(E);D.guid+=this.selector+F;n(document).bind(i(F,this.selector),this.selector,D);return this},die:function(E,D){n(document).unbind(i(E,this.selector),D?{guid:D.guid+this.selector+E}:null);return this}});function c(G){var D=RegExp("(^|\\.)"+G.type+"(\\.|$)"),F=true,E=[];n.each(n.data(this,"events").live||[],function(H,I){if(D.test(I.type)){var J=n(G.target).closest(I.data)[0];if(J){E.push({elem:J,fn:I})}}});n.each(E,function(){if(!G.isImmediatePropagationStopped()&&this.fn.call(this.elem,G,this.fn.data)===false){F=false}});return F}function i(E,D){return["live",E,D.replace(/\./g,"`").replace(/ /g,"|")].join(".")}n.extend({isReady:false,readyList:[],ready:function(){if(!n.isReady){n.isReady=true;if(n.readyList){n.each(n.readyList,function(){this.call(document,n)});n.readyList=null}n(document).triggerHandler("ready")}}});var w=false;function A(){if(w){return}w=true;if(document.addEventListener){document.addEventListener("DOMContentLoaded",function(){document.removeEventListener("DOMContentLoaded",arguments.callee,false);n.ready()},false)}else{if(document.attachEvent){document.attachEvent("onreadystatechange",function(){if(document.readyState==="complete"){document.detachEvent("onreadystatechange",arguments.callee);n.ready()}});if(document.documentElement.doScroll&&!l.frameElement){(function(){if(n.isReady){return}try{document.documentElement.doScroll("left")}catch(D){setTimeout(arguments.callee,0);return}n.ready()})()}}}n.event.add(l,"load",n.ready)}n.each(("blur,focus,load,resize,scroll,unload,click,dblclick,mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,change,select,submit,keydown,keypress,keyup,error").split(","),function(E,D){n.fn[D]=function(F){return F?this.bind(D,F):this.trigger(D)}});n(l).bind("unload",function(){for(var D in n.cache){if(D!=1&&n.cache[D].handle){n.event.remove(n.cache[D].handle.elem)}}});(function(){n.support={};var E=document.documentElement,F=document.createElement("script"),J=document.createElement("div"),I="script"+(new Date).getTime();J.style.display="none";J.innerHTML=' <link/><table></table><a href="/a" style="color:red;float:left;opacity:.5;">a</a><select><option>text</option></select><object><param/></object>';var G=J.getElementsByTagName("*"),D=J.getElementsByTagName("a")[0];if(!G||!G.length||!D){return}n.support={leadingWhitespace:J.firstChild.nodeType==3,tbody:!J.getElementsByTagName("tbody").length,objectAll:!!J.getElementsByTagName("object")[0].getElementsByTagName("*").length,htmlSerialize:!!J.getElementsByTagName("link").length,style:/red/.test(D.getAttribute("style")),hrefNormalized:D.getAttribute("href")==="/a",opacity:D.style.opacity==="0.5",cssFloat:!!D.style.cssFloat,scriptEval:false,noCloneEvent:true,boxModel:null};F.type="text/javascript";try{F.appendChild(document.createTextNode("window."+I+"=1;"))}catch(H){}E.insertBefore(F,E.firstChild);if(l[I]){n.support.scriptEval=true;delete l[I]}E.removeChild(F);if(J.attachEvent&&J.fireEvent){J.attachEvent("onclick",function(){n.support.noCloneEvent=false;J.detachEvent("onclick",arguments.callee)});J.cloneNode(true).fireEvent("onclick")}n(function(){var K=document.createElement("div");K.style.width="1px";K.style.paddingLeft="1px";document.body.appendChild(K);n.boxModel=n.support.boxModel=K.offsetWidth===2;document.body.removeChild(K)})})();var v=n.support.cssFloat?"cssFloat":"styleFloat";n.props={"for":"htmlFor","class":"className","float":v,cssFloat:v,styleFloat:v,readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",tabindex:"tabIndex"};n.fn.extend({_load:n.fn.load,load:function(F,I,J){if(typeof F!=="string"){return this._load(F)}var H=F.indexOf(" ");if(H>=0){var D=F.slice(H,F.length);F=F.slice(0,H)}var G="GET";if(I){if(n.isFunction(I)){J=I;I=null}else{if(typeof I==="object"){I=n.param(I);G="POST"}}}var E=this;n.ajax({url:F,type:G,dataType:"html",data:I,complete:function(L,K){if(K=="success"||K=="notmodified"){E.html(D?n("<div/>").append(L.responseText.replace(/<script(.|\s)*?\/script>/g,"")).find(D):L.responseText)}if(J){E.each(J,[L.responseText,K,L])}}});return this},serialize:function(){return n.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?n.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password/i.test(this.type))}).map(function(D,E){var F=n(this).val();return F==null?null:n.isArray(F)?n.map(F,function(H,G){return{name:E.name,value:H}}):{name:E.name,value:F}}).get()}});n.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(D,E){n.fn[E]=function(F){return this.bind(E,F)}});var q=e();n.extend({get:function(D,F,G,E){if(n.isFunction(F)){G=F;F=null}return n.ajax({type:"GET",url:D,data:F,success:G,dataType:E})},getScript:function(D,E){return n.get(D,null,E,"script")},getJSON:function(D,E,F){return n.get(D,E,F,"json")},post:function(D,F,G,E){if(n.isFunction(F)){G=F;F={}}return n.ajax({type:"POST",url:D,data:F,success:G,dataType:E})},ajaxSetup:function(D){n.extend(n.ajaxSettings,D)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return l.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(L){L=n.extend(true,L,n.extend(true,{},n.ajaxSettings,L));var V,E=/=\?(&|$)/g,Q,U,F=L.type.toUpperCase();if(L.data&&L.processData&&typeof L.data!=="string"){L.data=n.param(L.data)}if(L.dataType=="jsonp"){if(F=="GET"){if(!L.url.match(E)){L.url+=(L.url.match(/\?/)?"&":"?")+(L.jsonp||"callback")+"=?"}}else{if(!L.data||!L.data.match(E)){L.data=(L.data?L.data+"&":"")+(L.jsonp||"callback")+"=?"}}L.dataType="json"}if(L.dataType=="json"&&(L.data&&L.data.match(E)||L.url.match(E))){V="jsonp"+q++;if(L.data){L.data=(L.data+"").replace(E,"="+V+"$1")}L.url=L.url.replace(E,"="+V+"$1");L.dataType="script";l[V]=function(W){U=W;H();K();l[V]=g;try{delete l[V]}catch(X){}if(G){G.removeChild(S)}}}if(L.dataType=="script"&&L.cache==null){L.cache=false}if(L.cache===false&&F=="GET"){var D=e();var T=L.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+D+"$2");L.url=T+((T==L.url)?(L.url.match(/\?/)?"&":"?")+"_="+D:"")}if(L.data&&F=="GET"){L.url+=(L.url.match(/\?/)?"&":"?")+L.data;L.data=null}if(L.global&&!n.active++){n.event.trigger("ajaxStart")}var P=/^(\w+:)?\/\/([^\/?#]+)/.exec(L.url);if(L.dataType=="script"&&F=="GET"&&P&&(P[1]&&P[1]!=location.protocol||P[2]!=location.host)){var G=document.getElementsByTagName("head")[0];var S=document.createElement("script");S.src=L.url;if(L.scriptCharset){S.charset=L.scriptCharset}if(!V){var N=false;S.onload=S.onreadystatechange=function(){if(!N&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){N=true;H();K();G.removeChild(S)}}}G.appendChild(S);return g}var J=false;var I=L.xhr();if(L.username){I.open(F,L.url,L.async,L.username,L.password)}else{I.open(F,L.url,L.async)}try{if(L.data){I.setRequestHeader("Content-Type",L.contentType)}if(L.ifModified){I.setRequestHeader("If-Modified-Since",n.lastModified[L.url]||"Thu, 01 Jan 1970 00:00:00 GMT")}I.setRequestHeader("X-Requested-With","XMLHttpRequest");I.setRequestHeader("Accept",L.dataType&&L.accepts[L.dataType]?L.accepts[L.dataType]+", */*":L.accepts._default)}catch(R){}if(L.beforeSend&&L.beforeSend(I,L)===false){if(L.global&&!--n.active){n.event.trigger("ajaxStop")}I.abort();return false}if(L.global){n.event.trigger("ajaxSend",[I,L])}var M=function(W){if(I.readyState==0){if(O){clearInterval(O);O=null;if(L.global&&!--n.active){n.event.trigger("ajaxStop")}}}else{if(!J&&I&&(I.readyState==4||W=="timeout")){J=true;if(O){clearInterval(O);O=null}Q=W=="timeout"?"timeout":!n.httpSuccess(I)?"error":L.ifModified&&n.httpNotModified(I,L.url)?"notmodified":"success";if(Q=="success"){try{U=n.httpData(I,L.dataType,L)}catch(Y){Q="parsererror"}}if(Q=="success"){var X;try{X=I.getResponseHeader("Last-Modified")}catch(Y){}if(L.ifModified&&X){n.lastModified[L.url]=X}if(!V){H()}}else{n.handleError(L,I,Q)}K();if(L.async){I=null}}}};if(L.async){var O=setInterval(M,13);if(L.timeout>0){setTimeout(function(){if(I){if(!J){M("timeout")}if(I){I.abort()}}},L.timeout)}}try{I.send(L.data)}catch(R){n.handleError(L,I,null,R)}if(!L.async){M()}function H(){if(L.success){L.success(U,Q)}if(L.global){n.event.trigger("ajaxSuccess",[I,L])}}function K(){if(L.complete){L.complete(I,Q)}if(L.global){n.event.trigger("ajaxComplete",[I,L])}if(L.global&&!--n.active){n.event.trigger("ajaxStop")}}return I},handleError:function(E,G,D,F){if(E.error){E.error(G,D,F)}if(E.global){n.event.trigger("ajaxError",[G,E,F])}},active:0,httpSuccess:function(E){try{return !E.status&&location.protocol=="file:"||(E.status>=200&&E.status<300)||E.status==304||E.status==1223}catch(D){}return false},httpNotModified:function(F,D){try{var G=F.getResponseHeader("Last-Modified");return F.status==304||G==n.lastModified[D]}catch(E){}return false},httpData:function(I,G,F){var E=I.getResponseHeader("content-type"),D=G=="xml"||!G&&E&&E.indexOf("xml")>=0,H=D?I.responseXML:I.responseText;if(D&&H.documentElement.tagName=="parsererror"){throw"parsererror"}if(F&&F.dataFilter){H=F.dataFilter(H,G)}if(typeof H==="string"){if(G=="script"){n.globalEval(H)}if(G=="json"){H=l["eval"]("("+H+")")}}return H},param:function(D){var F=[];function G(H,I){F[F.length]=encodeURIComponent(H)+"="+encodeURIComponent(I)}if(n.isArray(D)||D.jquery){n.each(D,function(){G(this.name,this.value)})}else{for(var E in D){if(n.isArray(D[E])){n.each(D[E],function(){G(E,this)})}else{G(E,n.isFunction(D[E])?D[E]():D[E])}}}return F.join("&").replace(/%20/g,"+")}});var m={},d=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];function s(E,D){var F={};n.each(d.concat.apply([],d.slice(0,D)),function(){F[this]=E});return F}n.fn.extend({show:function(I,K){if(I){return this.animate(s("show",3),I,K)}else{for(var G=0,E=this.length;G<E;G++){var D=n.data(this[G],"olddisplay");this[G].style.display=D||"";if(n.css(this[G],"display")==="none"){var F=this[G].tagName,J;if(m[F]){J=m[F]}else{var H=n("<"+F+" />").appendTo("body");J=H.css("display");if(J==="none"){J="block"}H.remove();m[F]=J}this[G].style.display=n.data(this[G],"olddisplay",J)}}return this}},hide:function(G,H){if(G){return this.animate(s("hide",3),G,H)}else{for(var F=0,E=this.length;F<E;F++){var D=n.data(this[F],"olddisplay");if(!D&&D!=="none"){n.data(this[F],"olddisplay",n.css(this[F],"display"))}this[F].style.display="none"}return this}},_toggle:n.fn.toggle,toggle:function(F,E){var D=typeof F==="boolean";return n.isFunction(F)&&n.isFunction(E)?this._toggle.apply(this,arguments):F==null||D?this.each(function(){var G=D?F:n(this).is(":hidden");n(this)[G?"show":"hide"]()}):this.animate(s("toggle",3),F,E)},fadeTo:function(D,F,E){return this.animate({opacity:F},D,E)},animate:function(H,E,G,F){var D=n.speed(E,G,F);return this[D.queue===false?"each":"queue"](function(){var J=n.extend({},D),L,K=this.nodeType==1&&n(this).is(":hidden"),I=this;for(L in H){if(H[L]=="hide"&&K||H[L]=="show"&&!K){return J.complete.call(this)}if((L=="height"||L=="width")&&this.style){J.display=n.css(this,"display");J.overflow=this.style.overflow}}if(J.overflow!=null){this.style.overflow="hidden"}J.curAnim=n.extend({},H);n.each(H,function(N,R){var Q=new n.fx(I,J,N);if(/toggle|show|hide/.test(R)){Q[R=="toggle"?K?"show":"hide":R](H)}else{var P=R.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),S=Q.cur(true)||0;if(P){var M=parseFloat(P[2]),O=P[3]||"px";if(O!="px"){I.style[N]=(M||1)+O;S=((M||1)/Q.cur(true))*S;I.style[N]=S+O}if(P[1]){M=((P[1]=="-="?-1:1)*M)+S}Q.custom(S,M,O)}else{Q.custom(S,R,"")}}});return true})},stop:function(E,D){var F=n.timers;if(E){this.queue([])}this.each(function(){for(var G=F.length-1;G>=0;G--){if(F[G].elem==this){if(D){F[G](true)}F.splice(G,1)}}});if(!D){this.dequeue()}return this}});n.each({slideDown:s("show",1),slideUp:s("hide",1),slideToggle:s("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(D,E){n.fn[D]=function(F,G){return this.animate(E,F,G)}});n.extend({speed:function(F,G,E){var D=typeof F==="object"?F:{complete:E||!E&&G||n.isFunction(F)&&F,duration:F,easing:E&&G||G&&!n.isFunction(G)&&G};D.duration=n.fx.off?0:typeof D.duration==="number"?D.duration:n.fx.speeds[D.duration]||n.fx.speeds._default;D.old=D.complete;D.complete=function(){if(D.queue!==false){n(this).dequeue()}if(n.isFunction(D.old)){D.old.call(this)}};return D},easing:{linear:function(F,G,D,E){return D+E*F},swing:function(F,G,D,E){return((-Math.cos(F*Math.PI)/2)+0.5)*E+D}},timers:[],timerId:null,fx:function(E,D,F){this.options=D;this.elem=E;this.prop=F;if(!D.orig){D.orig={}}}});n.fx.prototype={update:function(){if(this.options.step){this.options.step.call(this.elem,this.now,this)}(n.fx.step[this.prop]||n.fx.step._default)(this);if((this.prop=="height"||this.prop=="width")&&this.elem.style){this.elem.style.display="block"}},cur:function(E){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop]}var D=parseFloat(n.css(this.elem,this.prop,E));return D&&D>-10000?D:parseFloat(n.curCSS(this.elem,this.prop))||0},custom:function(H,G,F){this.startTime=e();this.start=H;this.end=G;this.unit=F||this.unit||"px";this.now=this.start;this.pos=this.state=0;var D=this;function E(I){return D.step(I)}E.elem=this.elem;n.timers.push(E);if(E()&&n.timerId==null){n.timerId=setInterval(function(){var J=n.timers;for(var I=0;I<J.length;I++){if(!J[I]()){J.splice(I--,1)}}if(!J.length){clearInterval(n.timerId);n.timerId=null}},13)}},show:function(){this.options.orig[this.prop]=n.attr(this.elem.style,this.prop);this.options.show=true;this.custom(this.prop=="width"||this.prop=="height"?1:0,this.cur());n(this.elem).show()},hide:function(){this.options.orig[this.prop]=n.attr(this.elem.style,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(G){var F=e();if(G||F>=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var D=true;for(var E in this.options.curAnim){if(this.options.curAnim[E]!==true){D=false}}if(D){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(n.css(this.elem,"display")=="none"){this.elem.style.display="block"}}if(this.options.hide){n(this.elem).hide()}if(this.options.hide||this.options.show){for(var H in this.options.curAnim){n.attr(this.elem.style,H,this.options.orig[H])}}}if(D){this.options.complete.call(this.elem)}return false}else{var I=F-this.startTime;this.state=I/this.options.duration;this.pos=n.easing[this.options.easing||(n.easing.swing?"swing":"linear")](this.state,I,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update()}return true}};n.extend(n.fx,{speeds:{slow:600,fast:200,_default:400},step:{opacity:function(D){n.attr(D.elem.style,"opacity",D.now)},_default:function(D){if(D.elem.style&&D.elem.style[D.prop]!=null){D.elem.style[D.prop]=D.now+D.unit}else{D.elem[D.prop]=D.now}}}});if(document.documentElement.getBoundingClientRect){n.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return n.offset.bodyOffset(this[0])}var F=this[0].getBoundingClientRect(),I=this[0].ownerDocument,E=I.body,D=I.documentElement,K=D.clientTop||E.clientTop||0,J=D.clientLeft||E.clientLeft||0,H=F.top+(self.pageYOffset||n.boxModel&&D.scrollTop||E.scrollTop)-K,G=F.left+(self.pageXOffset||n.boxModel&&D.scrollLeft||E.scrollLeft)-J;return{top:H,left:G}}}else{n.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return n.offset.bodyOffset(this[0])}n.offset.initialized||n.offset.initialize();var I=this[0],F=I.offsetParent,E=I,N=I.ownerDocument,L,G=N.documentElement,J=N.body,K=N.defaultView,D=K.getComputedStyle(I,null),M=I.offsetTop,H=I.offsetLeft;while((I=I.parentNode)&&I!==J&&I!==G){L=K.getComputedStyle(I,null);M-=I.scrollTop,H-=I.scrollLeft;if(I===F){M+=I.offsetTop,H+=I.offsetLeft;if(n.offset.doesNotAddBorder&&!(n.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(I.tagName))){M+=parseInt(L.borderTopWidth,10)||0,H+=parseInt(L.borderLeftWidth,10)||0}E=F,F=I.offsetParent}if(n.offset.subtractsBorderForOverflowNotVisible&&L.overflow!=="visible"){M+=parseInt(L.borderTopWidth,10)||0,H+=parseInt(L.borderLeftWidth,10)||0}D=L}if(D.position==="relative"||D.position==="static"){M+=J.offsetTop,H+=J.offsetLeft}if(D.position==="fixed"){M+=Math.max(G.scrollTop,J.scrollTop),H+=Math.max(G.scrollLeft,J.scrollLeft)}return{top:M,left:H}}}n.offset={initialize:function(){if(this.initialized){return}var K=document.body,E=document.createElement("div"),G,F,M,H,L,D,I=K.style.marginTop,J='<div style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"><div></div></div><table style="position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;"cellpadding="0"cellspacing="0"><tr><td></td></tr></table>';L={position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"};for(D in L){E.style[D]=L[D]}E.innerHTML=J;K.insertBefore(E,K.firstChild);G=E.firstChild,F=G.firstChild,H=G.nextSibling.firstChild.firstChild;this.doesNotAddBorder=(F.offsetTop!==5);this.doesAddBorderForTableAndCells=(H.offsetTop===5);G.style.overflow="hidden",G.style.position="relative";this.subtractsBorderForOverflowNotVisible=(F.offsetTop===-5);K.style.marginTop="1px";this.doesNotIncludeMarginInBodyOffset=(K.offsetTop===0);K.style.marginTop=I;K.removeChild(E);this.initialized=true},bodyOffset:function(D){n.offset.initialized||n.offset.initialize();var F=D.offsetTop,E=D.offsetLeft;if(n.offset.doesNotIncludeMarginInBodyOffset){F+=parseInt(n.curCSS(D,"marginTop",true),10)||0,E+=parseInt(n.curCSS(D,"marginLeft",true),10)||0}return{top:F,left:E}}};n.fn.extend({position:function(){var H=0,G=0,E;if(this[0]){var F=this.offsetParent(),I=this.offset(),D=/^body|html$/i.test(F[0].tagName)?{top:0,left:0}:F.offset();I.top-=j(this,"marginTop");I.left-=j(this,"marginLeft");D.top+=j(F,"borderTopWidth");D.left+=j(F,"borderLeftWidth");E={top:I.top-D.top,left:I.left-D.left}}return E},offsetParent:function(){var D=this[0].offsetParent||document.body;while(D&&(!/^body|html$/i.test(D.tagName)&&n.css(D,"position")=="static")){D=D.offsetParent}return n(D)}});n.each(["Left","Top"],function(E,D){var F="scroll"+D;n.fn[F]=function(G){if(!this[0]){return null}return G!==g?this.each(function(){this==l||this==document?l.scrollTo(!E?G:n(l).scrollLeft(),E?G:n(l).scrollTop()):this[F]=G}):this[0]==l||this[0]==document?self[E?"pageYOffset":"pageXOffset"]||n.boxModel&&document.documentElement[F]||document.body[F]:this[0][F]}});n.each(["Height","Width"],function(G,E){var D=G?"Left":"Top",F=G?"Right":"Bottom";n.fn["inner"+E]=function(){return this[E.toLowerCase()]()+j(this,"padding"+D)+j(this,"padding"+F)};n.fn["outer"+E]=function(I){return this["inner"+E]()+j(this,"border"+D+"Width")+j(this,"border"+F+"Width")+(I?j(this,"margin"+D)+j(this,"margin"+F):0)};var H=E.toLowerCase();n.fn[H]=function(I){return this[0]==l?document.compatMode=="CSS1Compat"&&document.documentElement["client"+E]||document.body["client"+E]:this[0]==document?Math.max(document.documentElement["client"+E],document.body["scroll"+E],document.documentElement["scroll"+E],document.body["offset"+E],document.documentElement["offset"+E]):I===g?(this.length?n.css(this[0],H):null):this.css(H,typeof I==="string"?I:I+"px")}})})();
\ No newline at end of file diff --git a/js/util.js b/js/util.js index 38a958968..391e4653d 100644 --- a/js/util.js +++ b/js/util.js @@ -20,21 +20,21 @@ $(document).ready(function(){ // count character on keyup function counter(event){ var maxLength = 140; - var currentLength = $("#status_textarea").val().length; + var currentLength = $("#notice_data-text").val().length; var remaining = maxLength - currentLength; - var counter = $("#counter"); + var counter = $("#notice_text-count"); counter.text(remaining); - + if (remaining <= 0) { - $("#status_form").addClass("response_error"); + $("#form_notice").addClass("warning"); } else { - $("#status_form").removeClass("response_error"); + $("#form_notice").removeClass("warning"); } } function submitonreturn(event) { if (event.keyCode == 13) { - $("#status_form").submit(); + $("#form_notice").submit(); event.preventDefault(); event.stopPropagation(); return false; @@ -42,15 +42,15 @@ $(document).ready(function(){ return true; } - if ($("#status_textarea").length) { - $("#status_textarea").bind("keyup", counter); - $("#status_textarea").bind("keydown", submitonreturn); - + if ($("#notice_data-text").length) { + $("#notice_data-text").bind("keyup", counter); + $("#notice_data-text").bind("keydown", submitonreturn); + // run once in case there's something in there counter(); - + // set the focus - $("#status_textarea").focus(); + $("#notice_data-text").focus(); } // XXX: refactor this code @@ -73,6 +73,24 @@ $(document).ready(function(){ } }; + var joinoptions = { dataType: 'xml', + success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); + var leave = new_form.id; + var join = leave.replace('leave', 'join'); + $('form#'+join).replaceWith(new_form); + $('form#'+leave).ajaxForm(leaveoptions).each(addAjaxHidden); + } + }; + + var leaveoptions = { dataType: 'xml', + success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true); + var join = new_form.id; + var leave = join.replace('join', 'leave'); + $('form#'+leave).replaceWith(new_form); + $('form#'+join).ajaxForm(joinoptions).each(addAjaxHidden); + } + }; + function addAjaxHidden() { var ajax = document.createElement('input'); ajax.setAttribute('type', 'hidden'); @@ -81,25 +99,29 @@ $(document).ready(function(){ this.appendChild(ajax); } - $("form.favor").ajaxForm(favoptions); - $("form.disfavor").ajaxForm(disoptions); - $("form.favor").each(addAjaxHidden); - $("form.disfavor").each(addAjaxHidden); - - $("#nudge").ajaxForm ({ dataType: 'xml', - beforeSubmit: function(xml) { $("form#nudge input[type=submit]").attr("disabled", "disabled"); - $("form#nudge input[type=submit]").addClass("disabled"); - }, - success: function(xml) { $("#nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true)); - $("#nudge input[type=submit]").removeAttr("disabled"); - $("#nudge input[type=submit]").removeClass("disabled"); - } - }); - $("#nudge").each(addAjaxHidden); + $("form.form_favor").ajaxForm(favoptions); + $("form.form_disfavor").ajaxForm(disoptions); + $("form.form_group_join").ajaxForm(joinoptions); + $("form.form_group_leave").ajaxForm(leaveoptions); + $("form.form_favor").each(addAjaxHidden); + $("form.form_disfavor").each(addAjaxHidden); + $("form.form_group_join").each(addAjaxHidden); + $("form.form_group_leave").each(addAjaxHidden); + + $("#form_user_nudge").ajaxForm ({ dataType: 'xml', + beforeSubmit: function(xml) { $("#form_user_nudge input[type=submit]").attr("disabled", "disabled"); + $("#form_user_nudge input[type=submit]").addClass("disabled"); + }, + success: function(xml) { $("#form_user_nudge").replaceWith(document._importNode($("#nudge_response", xml).get(0),true)); + $("#form_user_nudge input[type=submit]").removeAttr("disabled"); + $("#form_user_nudge input[type=submit]").removeClass("disabled"); + } + }); + $("#form_user_nudge").each(addAjaxHidden); var Subscribe = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { $("form.subscribe input[type=submit]").attr("disabled", "disabled"); - $("form.subscribe input[type=submit]").addClass("disabled"); + beforeSubmit: function(formData, jqForm, options) { $(".form_user_subscribe input[type=submit]").attr("disabled", "disabled"); + $(".form_user_subscribe input[type=submit]").addClass("disabled"); }, success: function(xml) { var form_unsubscribe = document._importNode($('form', xml).get(0), true); var form_unsubscribe_id = form_unsubscribe.id; @@ -107,14 +129,14 @@ $(document).ready(function(){ $("form#"+form_subscribe_id).replaceWith(form_unsubscribe); $("form#"+form_unsubscribe_id).ajaxForm(UnSubscribe).each(addAjaxHidden); $("dd.subscribers").text(parseInt($("dd.subscribers").text())+1); - $("form.subscribe input[type=submit]").removeAttr("disabled"); - $("form.subscribe input[type=submit]").removeClass("disabled"); + $(".form_user_subscribe input[type=submit]").removeAttr("disabled"); + $(".form_user_subscribe input[type=submit]").removeClass("disabled"); } }; var UnSubscribe = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { $("form.unsubscribe input[type=submit]").attr("disabled", "disabled"); - $("form.unsubscribe input[type=submit]").addClass("disabled"); + beforeSubmit: function(formData, jqForm, options) { $(".form_user_unsubscribe input[type=submit]").attr("disabled", "disabled"); + $(".form_user_unsubscribe input[type=submit]").addClass("disabled"); }, success: function(xml) { var form_subscribe = document._importNode($('form', xml).get(0), true); var form_subscribe_id = form_subscribe.id; @@ -124,24 +146,23 @@ $(document).ready(function(){ $("#profile_send_a_new_message").remove(); $("#profile_nudge").remove(); $("dd.subscribers").text(parseInt($("dd.subscribers").text())-1); - $("form.unsubscribe input[type=submit]").removeAttr("disabled"); - $("form.unsubscribe input[type=submit]").removeClass("disabled"); + $(".form_user_unsubscribe input[type=submit]").removeAttr("disabled"); + $(".form_user_unsubscribe input[type=submit]").removeClass("disabled"); } }; - $("form.subscribe").ajaxForm(Subscribe); - $("form.unsubscribe").ajaxForm(UnSubscribe); - $("form.subscribe").each(addAjaxHidden); - $("form.unsubscribe").each(addAjaxHidden); - + $(".form_user_subscribe").ajaxForm(Subscribe); + $(".form_user_unsubscribe").ajaxForm(UnSubscribe); + $(".form_user_subscribe").each(addAjaxHidden); + $(".form_user_unsubscribe").each(addAjaxHidden); var PostNotice = { dataType: 'xml', - beforeSubmit: function(formData, jqForm, options) { if ($("#status_textarea").get(0).value.length == 0) { - $("#status_form").addClass("response_error"); + beforeSubmit: function(formData, jqForm, options) { if ($("#notice_data-text").get(0).value.length == 0) { + $("#form_notice").addClass("warning"); return false; } - $("#status_form input[type=submit]").attr("disabled", "disabled"); - $("#status_form input[type=submit]").addClass("disabled"); + $("#notice_action-submit").attr("disabled", "disabled"); + $("#notice_action-submit").addClass("disabled"); return true; }, success: function(xml) { if ($("#error", xml).length > 0 || $("#command_result", xml).length > 0) { @@ -150,28 +171,55 @@ $(document).ready(function(){ alert(result); } else { - $("#notices").prepend(document._importNode($("li", xml).get(0), true)); - $("#status_textarea").val(""); + $("#notices_primary .notices").prepend(document._importNode($("li", xml).get(0), true)); + $("#notice_data-text").val(""); counter(); - $(".notice_single:first").css({display:"none"}); - $(".notice_single:first").fadeIn(2500); + $("#notices_primary .notice:first").css({display:"none"}); + $("#notices_primary .notice:first").fadeIn(2500); + NoticeHover(); + NoticeReply(); } - $("#status_form input[type=submit]").removeAttr("disabled"); - $("#status_form input[type=submit]").removeClass("disabled"); + $("#notice_action-submit").removeAttr("disabled"); + $("#notice_action-submit").removeClass("disabled"); } }; - $("#status_form").ajaxForm(PostNotice); - $("#status_form").each(addAjaxHidden); + $("#form_notice").ajaxForm(PostNotice); + $("#form_notice").each(addAjaxHidden); + + NoticeHover(); + NoticeReply(); }); -function doreply(nick,id) { +function NoticeHover() { + $("#content .notice").hover( + function () { + $(this).addClass('hover'); + }, + function () { + $(this).removeClass('hover'); + } + ); +} + +function NoticeReply() { + $('#content .notice').each(function() { + var notice = $(this); + $('.notice_reply', $(this)).click(function() { + var nickname = ($('.author .nickname', notice).length > 0) ? $('.author .nickname', notice) : $('.author .nickname'); + NoticeReplySet(nickname.text(), $('.notice_id', notice).text()); + return false; + }); + }); +} + +function NoticeReplySet(nick,id) { rgx_username = /^[0-9a-zA-Z\-_.]*$/; if (nick.match(rgx_username)) { replyto = "@" + nick + " "; - if ($("#status_textarea").length) { - $("#status_textarea").val(replyto); - $("form#status_form input#inreplyto").val(id); - $("#status_textarea").focus(); + if ($("#notice_data-text").length) { + $("#notice_data-text").val(replyto); + $("#form_notice input#notice_in-reply-to").val(id); + $("#notice_data-text").focus(); return false; } } diff --git a/js/xbImportNode.js b/js/xbImportNode.js index 1da6bae69..f600a4789 100644 --- a/js/xbImportNode.js +++ b/js/xbImportNode.js @@ -44,3 +44,4 @@ document._importNode = function(node, allChildren) { break; } }; + diff --git a/lib/Shorturl_api.php b/lib/Shorturl_api.php index 7beae0ec6..fe106cb83 100644 --- a/lib/Shorturl_api.php +++ b/lib/Shorturl_api.php @@ -19,14 +19,17 @@ if (!defined('LACONICA')) { exit(1); } -class ShortUrlApi { +class ShortUrlApi +{ protected $service_url; - function __construct($service_url) { + function __construct($service_url) + { $this->service_url = $service_url; } - function shorten($url) { + function shorten($url) + { if ($this->is_long($url)) return $this->shorten_imp($url); return $url; } @@ -67,8 +70,10 @@ class ShortUrlApi { } } -class LilUrl extends ShortUrlApi { - function __construct() { +class LilUrl extends ShortUrlApi +{ + function __construct() + { parent::__construct('http://ur1.ca/'); } @@ -85,8 +90,10 @@ class LilUrl extends ShortUrlApi { } -class PtitUrl extends ShortUrlApi { - function __construct() { +class PtitUrl extends ShortUrlApi +{ + function __construct() + { parent::__construct('http://ptiturl.com/?creer=oui&action=Reduire&url='); } @@ -102,8 +109,10 @@ class PtitUrl extends ShortUrlApi { } } -class TightUrl extends ShortUrlApi { - function __construct() { +class TightUrl extends ShortUrlApi +{ + function __construct() + { parent::__construct('http://2tu.us/?save=y&url='); } diff --git a/lib/accountsettingsaction.php b/lib/accountsettingsaction.php new file mode 100644 index 000000000..46090b8c1 --- /dev/null +++ b/lib/accountsettingsaction.php @@ -0,0 +1,134 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for account settings actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/settingsaction.php'; + +/** + * Base class for account settings actions + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class AccountSettingsAction extends SettingsAction +{ + /** + * Show the local navigation menu + * + * This is the same for all settings, so we show it here. + * + * @return void + */ + + function showLocalNav() + { + $menu = new AccountSettingsNav($this); + $menu->show(); + } +} + +/** + * A widget for showing the settings group local nav menu + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class AccountSettingsNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + # action => array('prompt', 'title') + $menu = + array('profilesettings' => + array(_('Profile'), + _('Change your profile settings')), + 'avatarsettings' => + array(_('Avatar'), + _('Upload an avatar')), + 'passwordsettings' => + array(_('Password'), + _('Change your password')), + 'emailsettings' => + array(_('Email'), + _('Change email handling')), + 'openidsettings' => + array(_('OpenID'), + _('Add or remove OpenIDs')), + 'othersettings' => + array(_('Other'), + _('Other options'))); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + } +} diff --git a/lib/action.php b/lib/action.php index 7a2461bb5..8f02b36bf 100644 --- a/lib/action.php +++ b/lib/action.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Base class for all actions (~views) + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,128 +18,880 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -class Action { // lawsuit - - var $args; - - function Action() { - } - - # For initializing members of the class - - function prepare($argarray) { - $this->args =& common_copy_args($argarray); - return true; - } - - # For comparison with If-Last-Modified - # If not applicable, return NULL - - function last_modified() { - return NULL; - } - - function etag() { - return NULL; - } - - function is_readonly() { - return false; - } - - function arg($key, $def=NULL) { - if (array_key_exists($key, $this->args)) { - return $this->args[$key]; - } else { - return $def; - } - } - - function trimmed($key, $def=NULL) { - $arg = $this->arg($key, $def); - return (is_string($arg)) ? trim($arg) : $arg; - } - - # Note: argarray ignored, since it's now passed in in prepare() - - function handle($argarray=NULL) { - - $lm = $this->last_modified(); - $etag = $this->etag(); - - if ($etag) { - header('ETag: ' . $etag); - } - - if ($lm) { - header('Last-Modified: ' . date(DATE_RFC1123, $lm)); - $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE']; - if ($if_modified_since) { - $ims = strtotime($if_modified_since); - if ($lm <= $ims) { - if (!$etag || $this->_has_etag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) { - header('HTTP/1.1 304 Not Modified'); - # Better way to do this? - exit(0); - } - } - } - } - } - - function _has_etag($etag, $if_none_match) { - return ($if_none_match) && in_array($etag, explode(',', $if_none_match)); - } - - function boolean($key, $def=false) { - $arg = strtolower($this->trimmed($key)); - - if (is_null($arg)) { - return $def; - } else if (in_array($arg, array('true', 'yes', '1'))) { - return true; - } else if (in_array($arg, array('false', 'no', '0'))) { - return false; - } else { - return $def; - } - } - - function server_error($msg, $code=500) { - $action = $this->trimmed('action'); - common_debug("Server error '$code' on '$action': $msg", __FILE__); - common_server_error($msg, $code); - } - - function client_error($msg, $code=400) { - $action = $this->trimmed('action'); - common_debug("User error '$code' on '$action': $msg", __FILE__); - common_user_error($msg, $code); - } - - function self_url() { - $action = $this->trimmed('action'); - $args = $this->args; - unset($args['action']); - foreach (array_keys($_COOKIE) as $cookie) { - unset($args[$cookie]); - } - return common_local_url($action, $args); - } - - function nav_menu($menu) { +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/noticeform.php'; +require_once INSTALLDIR.'/lib/htmloutputter.php'; + +/** + * Base class for all actions + * + * This is the base class for all actions in the package. An action is + * more or less a "view" in an MVC framework. + * + * Actions are responsible for extracting and validating parameters; using + * model classes to read and write to the database; and doing ouput. + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ +class Action extends HTMLOutputter // lawsuit +{ + var $args; + + /** + * Constructor + * + * Just wraps the HTMLOutputter constructor. + * + * @param string $output URI to output to, default = stdout + * @param boolean $indent Whether to indent output, default true + * + * @see XMLOutputter::__construct + * @see HTMLOutputter::__construct + */ + function __construct($output='php://output', $indent=true) + { + parent::__construct($output, $indent); + } + + + /** + * For initializing members of the class. + * + * @param array $argarray misc. arguments + * + * @return boolean true + */ + function prepare($argarray) + { + $this->args =& common_copy_args($argarray); + return true; + } + + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage() + { + $this->startHTML(); + $this->showHead(); + $this->showBody(); + $this->endHTML(); + } + + /** + * Show head, a template method. + * + * @return nothing + */ + function showHead() + { + // XXX: attributes (profile?) + $this->elementStart('head'); + $this->showTitle(); + $this->showStylesheets(); + $this->showScripts(); + $this->showOpenSearch(); + $this->showFeeds(); + $this->showDescription(); + $this->extraHead(); + $this->elementEnd('head'); + } + + /** + * Show title, a template method. + * + * @return nothing + */ + function showTitle() + { + $this->element('title', null, + sprintf(_("%s - %s"), + $this->title(), + common_config('site', 'name'))); + } + + /** + * Returns the page title + * + * SHOULD overload + * + * @return string page title + */ + + function title() + { + return _("Untitled page"); + } + + /** + * Show stylesheets + * + * @return nothing + */ + function showStylesheets() + { + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => theme_path('css/display.css', 'base') . '?version=' . LACONICA_VERSION, + 'media' => 'screen, projection, tv')); + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => theme_path('css/display.css', null) . '?version=' . LACONICA_VERSION, + 'media' => 'screen, projection, tv')); + $this->comment('[if IE]><link rel="stylesheet" type="text/css" '. + 'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]'); + foreach (array(6,7) as $ver) { + if (file_exists(theme_file('ie'.$ver.'.css'))) { + // Yes, IE people should be put in jail. + $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '. + 'href="'.theme_path('css/ie'.$ver.'.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]'); + } + } + } + + /** + * Show javascript headers + * + * @return nothing + */ + function showScripts() + { + $this->element('script', array('type' => 'text/javascript', + 'src' => common_path('js/jquery.min.js')), + ' '); + $this->element('script', array('type' => 'text/javascript', + 'src' => common_path('js/jquery.form.js')), + ' '); + $this->element('script', array('type' => 'text/javascript', + 'src' => common_path('js/xbImportNode.js')), + ' '); + $this->element('script', array('type' => 'text/javascript', + 'src' => common_path('js/util.js?version='.LACONICA_VERSION)), + ' '); + } + + /** + * Show OpenSearch headers + * + * @return nothing + */ + function showOpenSearch() + { + $this->element('link', array('rel' => 'search', + 'type' => 'application/opensearchdescription+xml', + 'href' => common_local_url('opensearch', array('type' => 'people')), + 'title' => common_config('site', 'name').' People Search')); + $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', + 'href' => common_local_url('opensearch', array('type' => 'notice')), + 'title' => common_config('site', 'name').' Notice Search')); + } + + /** + * Show feed headers + * + * MAY overload + * + * @return nothing + */ + function showFeeds() + { + // does nothing by default + } + + /** + * Show description. + * + * SHOULD overload + * + * @return nothing + */ + function showDescription() + { + // does nothing by default + } + + /** + * Show extra stuff in <head>. + * + * MAY overload + * + * @return nothing + */ + function extraHead() + { + // does nothing by default + } + + + /** + * Show body. + * + * Calls template methods + * + * @return nothing + */ + function showBody() + { + $this->elementStart('body', array('id' => $this->trimmed('action'))); + $this->elementStart('div', 'wrap'); + $this->showHeader(); + $this->showCore(); + $this->showFooter(); + $this->elementEnd('div'); + $this->elementEnd('body'); + } + + /** + * Show header of the page. + * + * Calls template methods + * + * @return nothing + */ + function showHeader() + { + $this->elementStart('div', array('id' => 'header')); + $this->showLogo(); + $this->showPrimaryNav(); + $this->showSiteNotice(); + if (common_logged_in()) { + $this->showNoticeForm(); + } else { + $this->showAnonymousMessage(); + } + $this->elementEnd('div'); + } + + /** + * Show configured logo. + * + * @return nothing + */ + function showLogo() + { + $this->elementStart('address', array('id' => 'site_contact', + 'class' => 'vcard')); + $this->elementStart('a', array('class' => 'url home bookmark', + 'href' => common_local_url('public'))); + if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) { + $this->element('img', array('class' => 'logo photo', + 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : theme_path('logo.png'), + 'alt' => common_config('site', 'name'))); + } + $this->element('span', array('class' => 'fn org'), common_config('site', 'name')); + $this->elementEnd('a'); + $this->elementEnd('address'); + } + + /** + * Show primary navigation. + * + * @return nothing + */ + function showPrimaryNav() + { + $this->elementStart('dl', array('id' => 'site_nav_global_primary')); + $this->element('dt', null, _('Primary site navigation')); + $this->elementStart('dd'); + $user = common_current_user(); + $this->elementStart('ul', array('class' => 'nav')); + if ($user) { + $this->menuItem(common_local_url('all', array('nickname' => $user->nickname)), + _('Home'), _('Personal profile and friends timeline'), false, 'nav_home'); + } + $this->menuItem(common_local_url('peoplesearch'), + _('Search'), _('Search for people or text'), false, 'nav_search'); + if ($user) { + $this->menuItem(common_local_url('profilesettings'), + _('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account'); + $this->menuItem(common_local_url('imsettings'), + _('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect'); + $this->menuItem(common_local_url('logout'), + _('Logout'), _('Logout from the site'), false, 'nav_logout'); + } else { + $this->menuItem(common_local_url('login'), + _('Login'), _('Login to the site'), false, 'nav_login'); + if (!common_config('site', 'closed')) { + $this->menuItem(common_local_url('register'), + _('Register'), _('Create an account'), false, 'nav_register'); + } + $this->menuItem(common_local_url('openidlogin'), + _('OpenID'), _('Login with OpenID'), false, 'nav_openid'); + } + $this->menuItem(common_local_url('doc', array('title' => 'help')), + _('Help'), _('Help me!'), false, 'nav_help'); + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + /** + * Show site notice. + * + * @return nothing + */ + function showSiteNotice() + { + // Revist. Should probably do an hAtom pattern here + $text = common_config('site', 'notice'); + if ($text) { + $this->elementStart('dl', array('id' => 'site_notice', + 'class' => 'system_notice')); + $this->element('dt', null, _('Site notice')); + $this->element('dd', null, $text); + $this->elementEnd('dl'); + } + } + + /** + * Show notice form. + * + * MAY overload if no notice form needed... or direct message box???? + * + * @return nothing + */ + function showNoticeForm() + { + $notice_form = new NoticeForm($this); + $notice_form->show(); + } + + /** + * Show anonymous message. + * + * SHOULD overload + * + * @return nothing + */ + function showAnonymousMessage() + { + // needs to be defined by the class + } + + /** + * Show core. + * + * Shows local navigation, content block and aside. + * + * @return nothing + */ + function showCore() + { + $this->elementStart('div', array('id' => 'core')); + $this->showLocalNavBlock(); + $this->showContentBlock(); + $this->showAside(); + $this->elementEnd('div'); + } + + /** + * Show local navigation block. + * + * @return nothing + */ + function showLocalNavBlock() + { + $this->elementStart('dl', array('id' => 'site_nav_local_views')); + $this->element('dt', null, _('Local views')); + $this->elementStart('dd'); + $this->showLocalNav(); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + /** + * Show local navigation. + * + * SHOULD overload + * + * @return nothing + */ + function showLocalNav() + { + // does nothing by default + } + + /** + * Show content block. + * + * @return nothing + */ + function showContentBlock() + { + $this->elementStart('div', array('id' => 'content')); + $this->showPageTitle(); + $this->showPageNoticeBlock(); + $this->elementStart('div', array('id' => 'content_inner')); + // show the actual content (forms, lists, whatever) + $this->showContent(); + $this->elementEnd('div'); + $this->elementEnd('div'); + } + + /** + * Show page title. + * + * @return nothing + */ + function showPageTitle() + { + $this->element('h1', null, $this->title()); + } + + /** + * Show page notice block. + * + * @return nothing + */ + function showPageNoticeBlock() + { + $this->elementStart('dl', array('id' => 'page_notice', + 'class' => 'system_notice')); + $this->element('dt', null, _('Page notice')); + $this->elementStart('dd'); + $this->showPageNotice(); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + /** + * Show page notice. + * + * SHOULD overload (unless there's not a notice) + * + * @return nothing + */ + function showPageNotice() + { + } + + /** + * Show content. + * + * MUST overload (unless there's not a notice) + * + * @return nothing + */ + function showContent() + { + } + + /** + * Show Aside. + * + * @return nothing + */ + function showAside() + { + $this->elementStart('div', array('id' => 'aside_primary', + 'class' => 'aside')); + $this->showExportData(); + $this->showSections(); + $this->elementEnd('div'); + } + + /** + * Show export data feeds. + * + * MAY overload if there are feeds + * + * @return nothing + */ + function showExportData() + { + // is there structure to this? + // list of (visible!) feed links + // can we reuse list of feeds from showFeeds() ? + } + + /** + * Show sections. + * + * SHOULD overload + * + * @return nothing + */ + function showSections() + { + // for each section, show it + } + + /** + * Show footer. + * + * @return nothing + */ + function showFooter() + { + $this->elementStart('div', array('id' => 'footer')); + $this->showSecondaryNav(); + $this->showLicenses(); + $this->elementEnd('div'); + } + + /** + * Show secondary navigation. + * + * @return nothing + */ + function showSecondaryNav() + { + $this->elementStart('dl', array('id' => 'site_nav_global_secondary')); + $this->element('dt', null, _('Secondary site navigation')); + $this->elementStart('dd', null); + $this->elementStart('ul', array('class' => 'nav')); + $this->menuItem(common_local_url('doc', array('title' => 'help')), + _('Help')); + $this->menuItem(common_local_url('doc', array('title' => 'about')), + _('About')); + $this->menuItem(common_local_url('doc', array('title' => 'faq')), + _('FAQ')); + $this->menuItem(common_local_url('doc', array('title' => 'privacy')), + _('Privacy')); + $this->menuItem(common_local_url('doc', array('title' => 'source')), + _('Source')); + $this->menuItem(common_local_url('doc', array('title' => 'contact')), + _('Contact')); + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + /** + * Show licenses. + * + * @return nothing + */ + function showLicenses() + { + $this->elementStart('dl', array('id' => 'licenses')); + $this->showLaconicaLicense(); + $this->showContentLicense(); + $this->elementEnd('dl'); + } + + /** + * Show Laconica license. + * + * @return nothing + */ + function showLaconicaLicense() + { + $this->element('dt', array('id' => 'site_laconica_license'), _('Laconica software license')); + $this->elementStart('dd', null); + if (common_config('site', 'broughtby')) { + $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). '); + } else { + $instr = _('**%%site.name%%** is a microblogging service. '); + } + $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION); + $output = common_markup_to_html($instr); + $this->raw($output); + $this->elementEnd('dd'); + // do it + } + + /** + * Show content license. + * + * @return nothing + */ + function showContentLicense() + { + $this->element('dt', array('id' => 'site_content_license'), _('Laconica software license')); + $this->elementStart('dd', array('id' => 'site_content_license_cc')); + $this->elementStart('p'); + $this->element('img', array('id' => 'license_cc', + 'src' => common_config('license', 'image'), + 'alt' => common_config('license', 'title'))); + //TODO: This is dirty: i18n + $this->text(_('All '.common_config('site', 'name').' content and data are available under the ')); + $this->element('a', array('class' => 'license', + 'rel' => 'external license', + 'href' => common_config('license', 'url')), + common_config('license', 'title')); + $this->text(_('license.')); + $this->elementEnd('p'); + $this->elementEnd('dd'); + } + + /** + * Return last modified, if applicable. + * + * MAY override + * + * @return string last modified http header + */ + function lastModified() + { + // For comparison with If-Last-Modified + // If not applicable, return null + return null; + } + + /** + * Return etag, if applicable. + * + * MAY override + * + * @return string etag http header + */ + function etag() + { + return null; + } + + /** + * Return true if read only. + * + * MAY override + * + * @return boolean is read only action? + */ + function isReadOnly() + { + return false; + } + + /** + * Returns query argument or default value if not found + * + * @param string $key requested argument + * @param string $def default value to return if $key is not provided + * + * @return boolean is read only action? + */ + function arg($key, $def=null) + { + if (array_key_exists($key, $this->args)) { + return $this->args[$key]; + } else { + return $def; + } + } + + /** + * Returns trimmed query argument or default value if not found + * + * @param string $key requested argument + * @param string $def default value to return if $key is not provided + * + * @return boolean is read only action? + */ + function trimmed($key, $def=null) + { + $arg = $this->arg($key, $def); + return is_string($arg) ? trim($arg) : $arg; + } + + /** + * Handler method + * + * @param array $argarray is ignored since it's now passed in in prepare() + * + * @return boolean is read only action? + */ + function handle($argarray=null) + { + $lm = $this->lastModified(); + $etag = $this->etag(); + if ($etag) { + header('ETag: ' . $etag); + } + if ($lm) { + header('Last-Modified: ' . date(DATE_RFC1123, $lm)); + $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE']; + if ($if_modified_since) { + $ims = strtotime($if_modified_since); + if ($lm <= $ims) { + if (!$etag || + $this->_hasEtag($etag, $_SERVER['HTTP_IF_NONE_MATCH'])) { + header('HTTP/1.1 304 Not Modified'); + // Better way to do this? + exit(0); + } + } + } + } + } + + /** + * Has etag? (private) + * + * @param string $etag etag http header + * @param string $if_none_match ifNoneMatch http header + * + * @return boolean + */ + function _hasEtag($etag, $if_none_match) + { + return ($if_none_match) && in_array($etag, explode(',', $if_none_match)); + } + + /** + * Boolean understands english (yes, no, true, false) + * + * @param string $key query key we're interested in + * @param string $def default value + * + * @return boolean interprets yes/no strings as boolean + */ + function boolean($key, $def=false) + { + $arg = strtolower($this->trimmed($key)); + + if (is_null($arg)) { + return $def; + } else if (in_array($arg, array('true', 'yes', '1'))) { + return true; + } else if (in_array($arg, array('false', 'no', '0'))) { + return false; + } else { + return $def; + } + } + + /** + * Server error + * + * @param string $msg error message to display + * @param integer $code http error code, 500 by default + * + * @return nothing + */ + function serverError($msg, $code=500) + { $action = $this->trimmed('action'); - common_element_start('ul', array('id' => 'nav_views')); - foreach ($menu as $menuaction => $menudesc) { - common_menu_item(common_local_url($menuaction, isset($menudesc[2]) ? $menudesc[2] : NULL), - $menudesc[0], - $menudesc[1], - $action == $menuaction); - } - common_element_end('ul'); - } + common_debug("Server error '$code' on '$action': $msg", __FILE__); + common_server_error($msg, $code); + } + + /** + * Client error + * + * @param string $msg error message to display + * @param integer $code http error code, 400 by default + * + * @return nothing + */ + function clientError($msg, $code=400) + { + $action = $this->trimmed('action'); + common_debug("User error '$code' on '$action': $msg", __FILE__); + common_user_error($msg, $code); + } + + /** + * Returns the current URL + * + * @return string current URL + */ + function selfUrl() + { + $action = $this->trimmed('action'); + $args = $this->args; + unset($args['action']); + foreach (array_keys($_COOKIE) as $cookie) { + unset($args[$cookie]); + } + return common_local_url($action, $args); + } + + /** + * Generate a menu item + * + * @param string $url menu URL + * @param string $text menu name + * @param string $title title attribute, null by default + * @param boolean $is_selected current menu item, false by default + * @param string $id element id, null by default + * + * @return nothing + */ + function menuItem($url, $text, $title=null, $is_selected=false, $id=null) + { + // Added @id to li for some control. + // XXX: We might want to move this to htmloutputter.php + $lattrs = array(); + if ($is_selected) { + $lattrs['class'] = 'current'; + } + + (is_null($id)) ? $lattrs : $lattrs['id'] = $id; + + $this->elementStart('li', $lattrs); + $attrs['href'] = $url; + if ($title) { + $attrs['title'] = $title; + } + $this->element('a', $attrs, $text); + $this->elementEnd('li'); + } + + /** + * Generate pagination links + * + * @param boolean $have_before is there something before? + * @param boolean $have_after is there something after? + * @param integer $page current page + * @param string $action current action + * @param array $args rest of query arguments + * + * @return nothing + */ + function pagination($have_before, $have_after, $page, $action, $args=null) + { + // Does a little before-after block for next/prev page + if ($have_before || $have_after) { + $this->elementStart('div', array('class' => 'pagination')); + $this->elementStart('dl', null); + $this->element('dt', null, _('Pagination')); + $this->elementStart('dd', null); + $this->elementStart('ul', array('class' => 'nav')); + } + if ($have_before) { + $pargs = array('page' => $page-1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_prev')); + $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'), + _('After')); + $this->elementEnd('li'); + } + if ($have_after) { + $pargs = array('page' => $page+1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_next')); + $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'), + _('Before')); + $this->elementEnd('li'); + } + if ($have_before || $have_after) { + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + $this->elementEnd('div'); + } + } } diff --git a/lib/arraywrapper.php b/lib/arraywrapper.php new file mode 100644 index 000000000..ef0eeffa5 --- /dev/null +++ b/lib/arraywrapper.php @@ -0,0 +1,79 @@ +<?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('LACONICA')) { + exit(1); +} + +class ArrayWrapper +{ + var $_items = null; + var $_count = 0; + var $_i = -1; + + function __construct($items) + { + $this->_items = $items; + $this->_count = count($this->_items); + } + + function fetch() + { + if (!$this->_items) { + return false; + } + $this->_i++; + if ($this->_i < $this->_count) { + return true; + } else { + return false; + } + } + + function __set($name, $value) + { + $item =& $this->_items[$this->_i]; + $item->$name = $value; + return $item->$name; + } + + function __get($name) + { + $item =& $this->_items[$this->_i]; + return $item->$name; + } + + function __isset($name) + { + $item =& $this->_items[$this->_i]; + return isset($item->$name); + } + + function __unset($name) + { + $item =& $this->_items[$this->_i]; + unset($item->$name); + } + + function __call($name, $args) + { + $item =& $this->_items[$this->_i]; + return call_user_func_array(array($item, $name), $args); + } +}
\ No newline at end of file diff --git a/lib/blockform.php b/lib/blockform.php new file mode 100644 index 000000000..af766b823 --- /dev/null +++ b/lib/blockform.php @@ -0,0 +1,155 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for blocking a user + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for blocking a user + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see UnblockForm + */ + +class BlockForm extends Form +{ + /** + * Profile of user to block + */ + + var $profile = null; + + /** + * Return-to args + */ + + var $args = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to block + * @param array $args return-to args + */ + + function __construct($out=null, $profile=null, $args=null) + { + parent::__construct($out); + + $this->profile = $profile; + $this->args = $args; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'block-' . $this->profile->id; + } + + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_user_block'; + } + + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('block'); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Block this user')); + } + + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->hidden('blockto-' . $this->profile->id, + $this->profile->id, + 'blockto'); + if ($this->args) { + foreach ($this->args as $k => $v) { + $this->out->hidden('returnto-' . $k, $v); + } + } + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user')); + } +} diff --git a/lib/clienterroraction.php b/lib/clienterroraction.php new file mode 100644 index 000000000..ef6fd51df --- /dev/null +++ b/lib/clienterroraction.php @@ -0,0 +1,94 @@ +<?php + +/** + * Client error action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/error.php'; + +/** + * Class for displaying HTTP client errors + * + * @category Action + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class ClientErrorAction extends ErrorAction +{ + function __construct($message='Error', $code=400) + { + parent::__construct($message, $code); + + $this->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'); + $this->default = 400; + } + + // XXX: Should these error actions even be invokable via URI? + + function handle($args) + { + parent::handle($args); + + $this->code = $this->trimmed('code'); + + if (!$this->code || $code < 400 || $code > 499) { + $this->code = $this->default; + } + + $this->message = $this->trimmed('message'); + + if (!$this->message) { + $this->message = "Client Error $this->code"; + } + + $this->showPage(); + } +} diff --git a/lib/common.php b/lib/common.php index f7308d0b4..a2f9b9bfe 100644 --- a/lib/common.php +++ b/lib/common.php @@ -19,7 +19,7 @@ if (!defined('LACONICA')) { exit(1); } -define('LACONICA_VERSION', '0.6.4.3'); +define('LACONICA_VERSION', '0.7.0'); define('AVATAR_PROFILE_SIZE', 96); define('AVATAR_STREAM_SIZE', 48); @@ -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/80x15.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'); @@ -163,10 +163,17 @@ require_once(INSTALLDIR.'/lib/subs.php'); 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')) { +// XXX: other formats here + +define('NICKNAME_FMT', VALIDATE_NUM.VALIDATE_ALPHA_LOWER); + +function __autoload($class) +{ + if ($class == 'OAuthRequest') { + require_once('OAuth.php'); + } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) { require_once(INSTALLDIR.'/classes/' . $class . '.php'); + } else if (file_exists(INSTALLDIR.'/lib/' . strtolower($class) . '.php')) { + require_once(INSTALLDIR.'/lib/' . strtolower($class) . '.php'); } } diff --git a/lib/connectsettingsaction.php b/lib/connectsettingsaction.php new file mode 100644 index 000000000..30629680e --- /dev/null +++ b/lib/connectsettingsaction.php @@ -0,0 +1,129 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for connection settings actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/settingsaction.php'; + +/** + * Base class for connection settings actions + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class ConnectSettingsAction extends SettingsAction +{ + /** + * Show the local navigation menu + * + * This is the same for all settings, so we show it here. + * + * @return void + */ + + function showLocalNav() + { + $menu = new ConnectSettingsNav($this); + $menu->show(); + } +} + +/** + * A widget for showing the connect group local nav menu + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class ConnectSettingsNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + # action => array('prompt', 'title') + $menu = + array('imsettings' => + array(_('IM'), + _('Updates by instant messenger (IM)')), + 'smssettings' => + array(_('SMS'), + _('Updates by SMS')), + 'twittersettings' => + array(_('Twitter'), + _('Twitter integration options'))); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + if ($menuaction == 'imsettings' && + !common_config('xmpp', 'enabled')) { + continue; + } + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + } +} diff --git a/lib/daemon.php b/lib/daemon.php index 359a4343b..9c1ae50a0 100644 --- a/lib/daemon.php +++ b/lib/daemon.php @@ -1,5 +1,5 @@ <?php -/* +/** * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,117 +17,128 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } - -class Daemon { - - function name() { - return NULL; - } - - function background() { - $pid = pcntl_fork(); - if ($pid < 0) { # error - common_log(LOG_ERR, "Could not fork."); - return false; - } else if ($pid > 0) { # parent - common_log(LOG_INFO, "Successfully forked."); - exit(0); - } else { # child - return true; - } - } - - function alreadyRunning() { - - $pidfilename = $this->pidFilename(); - - if (!$pidfilename) { - return false; - } - - if (!file_exists($pidfilename)) { - return false; - } - $contents = file_get_contents($pidfilename); - if (posix_kill(trim($contents),0)) { - return true; - } else { - return false; - } - } - - function writePidFile() { - $pidfilename = $this->pidFilename(); - - if (!$pidfilename) { - return false; - } - - return file_put_contents($pidfilename, posix_getpid() . "\n"); - } - - function clearPidFile() { - $pidfilename = $this->pidFilename(); - if (!$pidfilename) { - return false; - } - return unlink($pidfilename); - } - - function pidFilename() { - $piddir = common_config('daemon', 'piddir'); - if (!$piddir) { - return NULL; - } - $name = $this->name(); - if (!$name) { - return NULL; - } - return $piddir . '/' . $name . '.pid'; - } - - function changeUser() { - - $username = common_config('daemon', 'user'); - - if ($username) { - $user_info = posix_getpwnam($username); - if (!$user_info) { - common_log(LOG_WARNING, 'Ignoring unknown user for daemon: ' . $username); - } else { - common_log(LOG_INFO, "Setting user to " . $username); - posix_setuid($user_info['uid']); - } - } - - $groupname = common_config('daemon', 'group'); - - if ($groupname) { - $group_info = posix_getgrnam($groupname); - if (!$group_info) { - common_log(LOG_WARNING, 'Ignoring unknown group for daemon: ' . $groupname); - } else { - common_log(LOG_INFO, "Setting group to " . $groupname); - posix_setgid($group_info['gid']); - } - } - } - - function runOnce() { - if ($this->alreadyRunning()) { - common_log(LOG_INFO, $this->name() . ' already running. Exiting.'); - exit(0); - } - if ($this->background()) { - $this->writePidFile(); - $this->changeUser(); - $this->run(); - $this->clearPidFile(); - } - } - - function run() { - return true; - } +if (!defined('LACONICA')) { + exit(1); +} + +class Daemon +{ + function name() + { + return null; + } + + function background() + { + $pid = pcntl_fork(); + if ($pid < 0) { // error + common_log(LOG_ERR, "Could not fork."); + return false; + } else if ($pid > 0) { // parent + common_log(LOG_INFO, "Successfully forked."); + exit(0); + } else { // child + return true; + } + } + + function alreadyRunning() + { + $pidfilename = $this->pidFilename(); + + if (!$pidfilename) { + return false; + } + + if (!file_exists($pidfilename)) { + return false; + } + $contents = file_get_contents($pidfilename); + if (posix_kill(trim($contents), 0)) { + return true; + } else { + return false; + } + } + + function writePidFile() + { + $pidfilename = $this->pidFilename(); + + if (!$pidfilename) { + return false; + } + + return file_put_contents($pidfilename, posix_getpid() . "\n"); + } + + function clearPidFile() + { + $pidfilename = $this->pidFilename(); + if (!$pidfilename) { + return false; + } + return unlink($pidfilename); + } + + function pidFilename() + { + $piddir = common_config('daemon', 'piddir'); + if (!$piddir) { + return null; + } + $name = $this->name(); + if (!$name) { + return null; + } + return $piddir . '/' . $name . '.pid'; + } + + function changeUser() + { + $username = common_config('daemon', 'user'); + + if ($username) { + $user_info = posix_getpwnam($username); + if (!$user_info) { + common_log(LOG_WARNING, + 'Ignoring unknown user for daemon: ' . $username); + } else { + common_log(LOG_INFO, "Setting user to " . $username); + posix_setuid($user_info['uid']); + } + } + + $groupname = common_config('daemon', 'group'); + + if ($groupname) { + $group_info = posix_getgrnam($groupname); + if (!$group_info) { + common_log(LOG_WARNING, + 'Ignoring unknown group for daemon: ' . $groupname); + } else { + common_log(LOG_INFO, "Setting group to " . $groupname); + posix_setgid($group_info['gid']); + } + } + } + + function runOnce() + { + if ($this->alreadyRunning()) { + common_log(LOG_INFO, $this->name() . ' already running. Exiting.'); + exit(0); + } + if ($this->background()) { + $this->writePidFile(); + $this->changeUser(); + $this->run(); + $this->clearPidFile(); + } + } + + function run() + { + return true; + } } diff --git a/lib/deleteaction.php b/lib/deleteaction.php index 5ba0e7e44..91c6487a9 100644 --- a/lib/deleteaction.php +++ b/lib/deleteaction.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Base class for deleting things + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,47 +18,57 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -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; - } +if (!defined('LACONICA')) { + exit(1); +} + +class DeleteAction extends Action +{ + var $user = null; + var $notice = null; + var $profile = null; + var $user_profile = null; + + function prepare($args) + { + parent::prepare($args); + + $this->user = common_current_user(); + $notice_id = $this->trimmed('notice'); + $this->notice = Notice::staticGet($notice_id); + + if (!$this->notice) { + common_user_error(_('No such notice.')); + exit; + } + + $this->profile = $this->notice->getProfile(); + $this->user_profile = $this->user->getProfile(); + + return true; + } + + function handle($args) + { + parent::handle($args); + + if (!common_logged_in()) { + common_user_error(_('Not logged in.')); + exit; + } else if ($this->notice->profile_id != $this->user_profile->id) { + common_user_error(_('Can\'t delete this notice.')); + exit; + } + } + } diff --git a/lib/disfavorform.php b/lib/disfavorform.php new file mode 100644 index 000000000..45a9ddb1d --- /dev/null +++ b/lib/disfavorform.php @@ -0,0 +1,154 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for disfavoring a notice + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for disfavoring a notice + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see FavorForm + */ + +class DisfavorForm extends Form +{ + /** + * Notice to disfavor + */ + + var $notice = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Notice $notice notice to disfavor + */ + + function __construct($out=null, $notice=null) + { + parent::__construct($out); + + $this->notice = $notice; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'disfavor-' . $this->notice->id; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('disfavor'); + } + + /** + * Include a session token for CSRF protection + * + * @return void + */ + + function sessionToken() + { + $this->out->hidden('token-' . $this->notice->id, + common_session_token()); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Disfavor this notice')); + } + + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $this->out->hidden('notice-n'.$this->notice->id, + $this->notice->id, + 'notice'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('disfavor-submit-' . $this->notice->id, + _('Disfavor favorite'), 'submit', null, _('Disfavor this notice')); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_disfavor'; + } + +} diff --git a/lib/error.php b/lib/error.php new file mode 100644 index 000000000..9842053d8 --- /dev/null +++ b/lib/error.php @@ -0,0 +1,136 @@ +<?php + +/** + * Error action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Base class for displaying HTTP errors + * + * @category Action + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class ErrorAction extends Action +{ + var $code = null; + var $message = null; + var $status = null; + var $default = null; + + function __construct($message, $code, $output='php://output', $indent=true) + { + parent::__construct($output, $indent); + + $this->code = $code; + $this->message = $message; + + // XXX: hack alert: usually we aren't going to + // call this page directly, but because it's + // an action it needs an args array anyway + $this->prepare($_REQUEST); + } + + /** + * To specify additional HTTP headers for the action + * + * @return void + */ + function extraHeaders() + { + $status_string = $this->status[$this->code]; + header('HTTP/1.1 '.$this->code.' '.$status_string); + } + + /** + * Display content. + * + * @return nothing + */ + function showContent() + { + $this->element('div', array('class' => 'error'), $this->message); + } + + /** + * Page title. + * + * @return page title + */ + function title() + { + return $this->message; + } + + function isReadOnly() + { + return true; + } + + function showPage() + { + parent::showPage(); + + // We don't want to have any more output after this + exit(); + } + + // Overload a bunch of stuff so the page isn't too bloated + + function showBody() + { + $this->elementStart('body', array('id' => 'error')); + $this->elementStart('div', 'wrap'); + $this->showHeader(); + $this->showCore(); + $this->showFooter(); + $this->elementEnd('div'); + $this->elementEnd('body'); + } + + function showCore() + { + $this->elementStart('div', array('id' => 'core')); + $this->showContentBlock(); + $this->elementEnd('div'); + } + + function showHeader() + { + $this->elementStart('div', array('id' => 'header')); + $this->showLogo(); + $this->elementEnd('div'); + } + +} diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 87a82ba01..2dbe15970 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -1,283 +1,572 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Low-level generator for HTML + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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/>. + * + * @category Faceboook + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/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}"; - } +if (!defined('LACONICA')) +{ + exit(1); +} + +require_once INSTALLDIR.'/lib/facebookutil.php'; +require_once INSTALLDIR.'/lib/noticeform.php'; + + +class FacebookAction extends Action +{ + + var $facebook = null; + var $fbuid = null; + var $flink = null; + var $action = null; + var $app_uri = null; + var $app_name = null; + + /** + * Constructor + * + * Just wraps the HTMLOutputter constructor. + * + * @param string $output URI to output to, default = stdout + * @param boolean $indent Whether to indent output, default true + * + * @see XMLOutputter::__construct + * @see HTMLOutputter::__construct + */ + function __construct($output='php://output', $indent=true, $facebook=null, $flink=null) + { + parent::__construct($output, $indent); + + $this->facebook = $facebook; + $this->flink = $flink; + + if ($this->flink) { + $this->fbuid = $flink->foreign_id; + $this->user = $flink->getUser(); + } + + $this->args = array(); + } + + function prepare($argarray) + { + parent::prepare($argarray); + + $this->facebook = getFacebook(); + $this->fbuid = $this->facebook->require_login(); + + $this->action = $this->trimmed('action'); + + $app_props = $this->facebook->api_client->Admin_getAppProperties( + array('canvas_name', 'application_name')); + + $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name']; + $this->app_name = $app_props['application_name']; + + $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); + + return true; + + } + + function showStylesheets() + { + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookBaseCSS())); + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookThemeCSS())); + } + + function showScripts() + { + $this->element('script', array('type' => 'text/javascript', + 'src' => getFacebookJS()), + ' '); + } + + /** + * Start an Facebook ready HTML document + * + * For Facebook we don't want to actually output any headers, + * DTD info, etc. + * + * If $type isn't specified, will attempt to do content negotiation. + * + * @param string $type MIME type to use; default is to do negotation. + * + * @return void + */ + + function startHTML($type=null) + { + $this->elementStart('div', array('class' => 'facebook-page')); + } + + /** + * Ends a Facebook ready HTML document + * + * @return void + */ + function endHTML() + { + $this->elementEnd('div'); + $this->endXML(); + } + + /** + * Show notice form. + * + * MAY overload if no notice form needed... or direct message box???? + * + * @return nothing + */ + function showNoticeForm() + { + // don't do it for most of the Facebook pages + } + + function showBody() + { + $this->elementStart('div', 'wrap'); + $this->showHeader(); + $this->showCore(); + $this->showFooter(); + $this->elementEnd('div'); + } + + function showAside() + { + } + + function showHead($error, $success) + { + $this->showStylesheets(); + $this->showScripts(); + + if ($error) { + $this->element("h1", null, $error); + } + + if ($success) { + $this->element("h1", null, $success); + } + + $this->elementStart('fb:if-section-not-added', array('section' => 'profile')); + $this->elementStart('span', array('id' => 'add_to_profile')); + $this->element('fb:add-section-button', array('section' => 'profile')); + $this->elementEnd('span'); + $this->elementEnd('fb:if-section-not-added'); + + } + + + // Make this into a widget later + function showLocalNav() + { + + $this->elementStart('ul', array('class' => 'nav')); + + $this->elementStart('li', array('class' => + ($this->action == 'facebookhome') ? 'current' : 'facebook_home')); + $this->element('a', + array('href' => 'index.php', 'title' => _('Home')), _('Home')); + $this->elementEnd('li'); + + $this->elementStart('li', + array('class' => + ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite')); + $this->element('a', + array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); + $this->elementEnd('li'); + + $this->elementStart('li', + array('class' => + ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings')); + $this->element('a', + array('href' => 'settings.php', + 'title' => _('Settings')), _('Settings')); + $this->elementEnd('li'); + + $this->elementEnd('ul'); + + } + + /** + * Show primary navigation. + * + * @return nothing + */ + function showPrimaryNav() + { + // we don't want to show anything for this + } + + /** + * Show header of the page. + * + * Calls template methods + * + * @return nothing + */ + function showHeader() + { + $this->elementStart('div', array('id' => 'header')); + $this->showLogo(); + $this->showNoticeForm(); + $this->showPrimaryNav(); + $this->elementEnd('div'); + } + + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage($error = null, $success = null) + { + $this->startHTML(); + $this->showHead($error, $success); + $this->showBody(); + $this->endHTML(); + } + + + function showInstructions() + { + + $this->elementStart('dl', array('class' => 'system_notice')); + $this->element('dt', null, 'Page Notice'); + + $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' . + 'with your username and password. Don\'t have a username yet? '); + + $loginmsg_part2 = _(' a new account.'); + + $this->elementStart('dd'); + $this->elementStart('p'); + $this->text(sprintf($loginmsg_part1, common_config('site', 'name'))); + $this->element('a', + array('href' => common_local_url('register')), _('Register')); + $this->text($loginmsg_part2); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + + + function showLoginForm($msg = null) + { + + $this->elementStart('div', array('class' => 'content')); + $this->element('h1', null, _('Login')); + + if ($msg) { + $this->element('fb:error', array('message' => $msg)); + } + + $this->showInstructions(); + + $this->elementStart('div', array('id' => 'content_inner')); + + $this->elementStart('form', array('method' => 'post', + 'class' => 'form_settings', + 'id' => 'login', + 'action' => 'index.php')); + + $this->elementStart('fieldset'); + $this->element('legend', null, _('Login to site')); + + $this->elementStart('ul', array('class' => 'form_datas')); + $this->elementStart('li'); + $this->input('nickname', _('Nickname')); + $this->elementEnd('li'); + $this->elementStart('li'); + $this->password('password', _('Password')); + $this->elementEnd('li'); + $this->elementEnd('ul'); + + $this->submit('submit', _('Login')); + $this->elementEnd('form'); + + $this->elementStart('p'); + $this->element('a', array('href' => common_local_url('recoverpassword')), + _('Lost or forgotten password?')); + $this->elementEnd('p'); + + $this->elementEnd('div'); + + } + + + function updateProfileBox($notice) + { + + // 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>'; + + $this->xw->openMemory(); + + $item = new FacebookNoticeListItem($notice, $this); + $item->show(); + + $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>"; + $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>"; + + $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>"; + + $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main); + + $this->xw->openURI('php://output'); + } + + + /** + * Generate pagination links + * + * @param boolean $have_before is there something before? + * @param boolean $have_after is there something after? + * @param integer $page current page + * @param string $action current action + * @param array $args rest of query arguments + * + * @return nothing + */ + function pagination($have_before, $have_after, $page, $action, $args=null) + { + // Does a little before-after block for next/prev page + if ($have_before || $have_after) { + $this->elementStart('div', array('class' => 'pagination')); + $this->elementStart('dl', null); + $this->element('dt', null, _('Pagination')); + $this->elementStart('dd', null); + $this->elementStart('ul', array('class' => 'nav')); + } + if ($have_before) { + $pargs = array('page' => $page-1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_prev')); + $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'prev'), + _('After')); + $this->elementEnd('li'); + } + if ($have_after) { + $pargs = array('page' => $page+1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_next')); + $this->element('a', array('href' => "$this->app_uri/$action?page=$newargs[page]", 'rel' => 'next'), + _('Before')); + $this->elementEnd('li'); + } + if ($have_before || $have_after) { + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + $this->elementEnd('div'); + } + } + + +} + +class FacebookNoticeForm extends NoticeForm +{ + + var $post_action = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param string $action action to return to, if any + * @param string $content content to pre-fill + */ + + function __construct($out=null, $action=null, $content=null, + $post_action=null, $user=null) + { + parent::__construct($out, $action, $content, $user); + $this->post_action = $post_action; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return $this->post_action; + } + +} + +class FacebookNoticeList extends NoticeList +{ + /** + * show the list of notices + * + * "Uses up" the stream by looping through it. So, probably can't + * be called twice on the same list. + * + * @return int count of notices listed. + */ + + function show() + { + $this->out->elementStart('div', array('id' =>'notices_primary')); + $this->out->element('h2', null, _('Notices')); + $this->out->elementStart('ul', array('class' => 'notices')); + + $cnt = 0; + + while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) { + $cnt++; + + if ($cnt > NOTICES_PER_PAGE) { + break; + } + + $item = $this->newListItem($this->notice); + $item->show(); + } + + $this->out->elementEnd('ul'); + $this->out->elementEnd('div'); + + return $cnt; + } + + /** + * returns a new list item for the current notice + * + * Overridden to return a Facebook specific list item. + * + * @param Notice $notice the current notice + * + * @return FacebookNoticeListItem a list item for displaying the notice + * formatted for display in the Facebook App. + */ + + function newListItem($notice) + { + return new FacebookNoticeListItem($notice, $this); + } + +} + +class FacebookNoticeListItem extends NoticeListItem +{ + /** + * recipe function for displaying a single notice in the Facebook App. + * + * Overridden to strip out some of the controls that we don't + * want to be available. + * + * @return void + */ + + function show() + { + $this->showStart(); + + $this->out->elementStart('div', 'entry-title'); + $this->showAuthor(); + $this->showContent(); + $this->out->elementEnd('div'); + + $this->out->elementStart('div', 'entry-content'); + $this->showNoticeLink(); + $this->showNoticeSource(); + $this->showReplyTo(); + $this->out->elementEnd('div'); + + $this->showEnd(); + } + + function showNoticeLink() + { + $noticeurl = common_local_url('shownotice', + array('notice' => $this->notice->id)); + // XXX: we need to figure this out better. Is this right? + if (strcmp($this->notice->uri, $noticeurl) != 0 && + preg_match('/^http/', $this->notice->uri)) { + $noticeurl = $this->notice->uri; + } + + $this->out->elementStart('dl', 'timestamp'); + $this->out->element('dt', null, _('Published')); + $this->out->elementStart('dd', null); + $this->out->elementStart('a', array('rel' => 'bookmark', + 'href' => $noticeurl)); + $dt = common_date_iso8601($this->notice->created); + $this->out->element('abbr', array('class' => 'published', + 'title' => $dt), + common_date_string($this->notice->created)); + $this->out->elementEnd('a'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } } diff --git a/lib/facebookutil.php b/lib/facebookutil.php new file mode 100644 index 000000000..a2a2d7cb1 --- /dev/null +++ b/lib/facebookutil.php @@ -0,0 +1,84 @@ +<?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +require_once INSTALLDIR.'/extlib/facebook/facebook.php'; +require_once INSTALLDIR.'/lib/facebookaction.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; + +define("FACEBOOK_SERVICE", 2); // Facebook is foreign_service ID 2 +define("FACEBOOK_NOTICE_PREFIX", 1); +define("FACEBOOK_PROMPTED_UPDATE_PREF", 2); + +// Gets all the notices from users with a Facebook link since a given ID +function getFacebookNotices($since) +{ + $qry = 'SELECT notice.* ' . + 'FROM notice ' . + 'JOIN foreign_link ' . + 'WHERE notice.profile_id = foreign_link.user_id ' . + 'AND foreign_link.service = 2'; + + // XXX: What should the limit be? + return Notice::getStreamDirect($qry, 0, 100, 0, 0, null, $since); +} + +function getFacebook() +{ + $apikey = common_config('facebook', 'apikey'); + $secret = common_config('facebook', 'secret'); + return new Facebook($apikey, $secret); +} + +function startFBML($indent = true) +{ + global $xw; + $xw = new XMLWriter(); + $xw->openURI('php://output'); + $xw->setIndent($indent); +} + +function getFacebookBaseCSS() +{ + # Add a timestamp to the CSS file so Facebook cache wont ignore our changes + $ts = filemtime(INSTALLDIR.'/theme/base/css/facebookapp.base.css'); + $cssurl = theme_path('css/facebookapp.base.css', 'base') . "?ts=$ts"; + return $cssurl; +} + +function getFacebookThemeCSS() +{ + # Add a timestamp to the CSS file so Facebook cache wont ignore our changes + $ts = filemtime(theme_file('css/facebookapp.theme.css')); + $cssurl = theme_path('css/facebookapp.theme.css') . "?ts=$ts"; + return $cssurl; +} + +function getFacebookJS() { + + # Add a timestamp to the FBJS file so Facebook cache wont ignore our changes + $ts = filemtime(INSTALLDIR.'/js/facebookapp.js'); + $jsurl = common_path('js/facebookapp.js') . "?ts=$ts"; + return $jsurl; +} + +function updateProfileBox($facebook, $flink, $notice) { + $fbaction = new FacebookAction($output='php://output', $indent=true, $facebook, $flink); + $fbaction->updateProfileBox($notice); +} + diff --git a/lib/favorform.php b/lib/favorform.php new file mode 100644 index 000000000..f3a7a9756 --- /dev/null +++ b/lib/favorform.php @@ -0,0 +1,153 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for favoring a notice + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for favoring a notice + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see DisfavorForm + */ + +class FavorForm extends Form +{ + /** + * Notice to favor + */ + + var $notice = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Notice $notice notice to favor + */ + + function __construct($out=null, $notice=null) + { + parent::__construct($out); + + $this->notice = $notice; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'favor-' . $this->notice->id; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('favor'); + } + + /** + * Include a session token for CSRF protection + * + * @return void + */ + + function sessionToken() + { + $this->out->hidden('token-' . $this->notice->id, + common_session_token()); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Favor this notice')); + } + + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $this->out->hidden('notice-n'.$this->notice->id, + $this->notice->id, + 'notice'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('favor-submit-' . $this->notice->id, + _('Favor'), 'submit', null, _('Favor this notice')); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_favor'; + } +} diff --git a/lib/featureduserssection.php b/lib/featureduserssection.php new file mode 100644 index 000000000..2935d8363 --- /dev/null +++ b/lib/featureduserssection.php @@ -0,0 +1,89 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Section for featured users + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Section for featured users + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class FeaturedUsersSection extends ProfileSection +{ + function getProfiles() + { + $featured_nicks = common_config('nickname', 'featured'); + + if (!$featured_nicks) { + return null; + } + + $quoted = array(); + + foreach ($featured_nicks as $nick) { + $quoted[] = "'$nick'"; + } + + $qry = 'SELECT profile.* ' . + 'FROM profile JOIN user on profile.id = user.id ' . + 'WHERE user.nickname in (' . implode(',', $quoted) . ') ' . + 'ORDER BY profile.created DESC '; + + $limit = PROFILES_PER_SECTION + 1; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile = Memcached_DataObject::cachedQuery('Profile', + $qry, + 6 * 3600); + return $profile; + } + + function title() + { + return _('Featured users'); + } + + function divId() + { + return 'featured_users'; + } +} diff --git a/lib/feedlist.php b/lib/feedlist.php new file mode 100644 index 000000000..47d909e96 --- /dev/null +++ b/lib/feedlist.php @@ -0,0 +1,158 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Widget for showing a list of feeds + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Widget for showing a list of feeds + * + * Typically used for Action::showExportList() + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Action::showExportList() + */ + +class FeedList extends Widget +{ + var $action = null; + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + function show($feeds) + { + $this->out->elementStart('div', array('id' => 'export_data', + 'class' => 'section')); + $this->out->element('h2', null, _('Export data')); + $this->out->elementStart('ul', array('class' => 'xoxo')); + + foreach ($feeds as $key => $value) { + $this->feedItem($feeds[$key]); + } + + $this->out->elementEnd('ul'); + $this->out->elementEnd('div'); + } + + function feedItem($feed) + { + $nickname = $this->action->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; + } + $this->out->elementStart('li'); + $this->out->element('a', array('href' => $feed['href'], + 'class' => $feed_classname, + 'type' => $feed_mimetype, + 'title' => $feed_title), + $feed['textContent']); + $this->out->elementEnd('li'); + } +} diff --git a/lib/form.php b/lib/form.php new file mode 100644 index 000000000..5317df471 --- /dev/null +++ b/lib/form.php @@ -0,0 +1,166 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for forms + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Base class for forms + * + * We have a lot of common forms (subscribe, fave, delete) and this superclass + * lets us abstract out the basic features of the form. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class Form extends Widget +{ + /** + * Show the form + * + * Uses a recipe to output the form. + * + * @return void + * @see Widget::show() + */ + + function show() + { + $this->out->elementStart('form', + array('id' => $this->id(), + 'class' => $this->formClass(), + 'method' => 'post', + 'action' => $this->action())); + $this->out->elementStart('fieldset'); + $this->formLegend(); + $this->sessionToken(); + $this->formData(); + $this->formActions(); + $this->out->elementEnd('fieldset'); + $this->out->elementEnd('form'); + } + + /** + * Include a session token for CSRF protection + * + * @return void + */ + + function sessionToken() + { + $this->out->hidden('token', common_session_token()); + } + + /** + * Name of the form + * + * Sub-classes should overload this with the name of their form. + * + * @return void + */ + + function formLegend() + { + } + + /** + * Visible or invisible data elements + * + * Display the form fields that make up the data of the form. + * Sub-classes should overload this to show their data. + * + * @return void + */ + + function formData() + { + } + + /** + * Buttons for form actions + * + * Submit and cancel buttons (or whatever) + * Sub-classes should overload this to show their own buttons. + * + * @return void + */ + + function formActions() + { + } + + /** + * ID of the form + * + * Should be unique on the page. Sub-classes should overload this + * to show their own IDs. + * + * @return int ID of the form + */ + + function id() + { + return null; + } + + /** + * Action of the form. + * + * URL to post to. Should be overloaded by subclasses to give + * somewhere to post to. + * + * @return string URL to post to + */ + + function action() + { + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form'; + } +} diff --git a/lib/gallery.php b/lib/gallery.php deleted file mode 100644 index 0dd351bab..000000000 --- a/lib/gallery.php +++ /dev/null @@ -1,320 +0,0 @@ -<?php - -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/profilelist.php'); - -# 10x8 - -define('AVATARS_PER_PAGE', 80); - -class GalleryAction extends Action { - - function is_readonly() { - return true; - } - - function handle($args) { - parent::handle($args); - - # Post from the tag dropdown; redirect to a GET - - if ($_SERVER['REQUEST_METHOD'] == 'POST') { - common_redirect($this->self_url(), 307); - } - - $nickname = common_canonical_nickname($this->arg('nickname')); - $user = User::staticGet('nickname', $nickname); - - if (!$user) { - $this->no_such_user(); - return; - } - - $profile = $user->getProfile(); - - if (!$profile) { - $this->server_error(_('User without matching profile in system.')); - return; - } - - $page = $this->arg('page'); - - if (!$page) { - $page = 1; - } - - $display = $this->arg('display'); - - if (!$display) { - $display = 'list'; - } - - $tag = $this->arg('tag'); - - common_show_header($profile->nickname . ": " . $this->gallery_type(), - NULL, $profile, - array($this, 'show_top')); - - $this->display_links($profile, $page, $display); - $this->show_tags_dropdown($profile); - - $this->show_gallery($profile, $page, $display, $tag); - common_show_footer(); - } - - function no_such_user() { - $this->client_error(_('No such user.')); - } - - function show_tags_dropdown($profile) { - $tag = $this->trimmed('tag'); - list($lst, $usr) = $this->fields(); - $tags = $this->get_all_tags($profile, $lst, $usr); - $content = array(); - foreach ($tags as $t) { - $content[$t] = $t; - } - if ($tags) { - common_element_start('dl', array('id'=>'filter_tags')); - common_element('dt', null, _('Filter tags')); - common_element_start('dd'); - common_element_start('ul'); - common_element_start('li', array('id'=>'filter_tags_all', 'class'=>'child_1')); - common_element('a', array('href' => common_local_url($this->trimmed('action'), - array('nickname' => $profile->nickname))), - _('All')); - common_element_end('li'); - common_element_start('li', array('id'=>'filter_tags_item')); - common_element_start('form', array('name' => 'bytag', 'id' => 'bytag', 'method' => 'post')); - common_dropdown('tag', _('Tag'), $content, - _('Choose a tag to narrow list'), FALSE, $tag); - common_submit('go', _('Go')); - common_element_end('form'); - common_element_end('li'); - common_element_end('ul'); - common_element_end('dd'); - common_element_end('dl'); - } - } - - function show_top($profile) { - common_element('div', 'instructions', - $this->get_instructions($profile)); - $this->show_menu(); - } - - function show_menu() { - # action => array('prompt', 'title', $args) - $action = $this->trimmed('action'); - $nickname = $this->trimmed('nickname'); - $menu = - array('subscriptions' => - array( _('Subscriptions'), - _('Subscriptions'), - array('nickname' => $nickname)), - 'subscribers' => - array( - _('Subscribers'), - _('Subscribers'), - array('nickname' => $nickname)), - ); - $this->nav_menu($menu); - } - - function show_gallery($profile, $page, $display='list', $tag=NULL) { - - $other = new Profile(); - - list($lst, $usr) = $this->fields(); - - $per_page = ($display == 'list') ? PROFILES_PER_PAGE : AVATARS_PER_PAGE; - - $offset = ($page-1)*$per_page; - $limit = $per_page + 1; - - if (common_config('db','type') == 'pgsql') { - $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $lim = ' LIMIT ' . $offset . ', ' . $limit; - } - - # XXX: memcached results - # FIXME: SQL injection on $tag - - $other->query('SELECT profile.* ' . - 'FROM profile JOIN subscription ' . - 'ON profile.id = subscription.' . $lst . ' ' . - (($tag) ? 'JOIN profile_tag ON (profile.id = profile_tag.tagged AND subscription.'.$usr.'= profile_tag.tagger) ' : '') . - 'WHERE ' . $usr . ' = ' . $profile->id . ' ' . - 'AND subscriber != subscribed ' . - (($tag) ? 'AND profile_tag.tag= "' . $tag . '" ': '') . - 'ORDER BY subscription.created DESC, profile.id DESC ' . - $lim); - - if ($display == 'list') { - $cls = $this->profile_list_class(); - $profile_list = new $cls($other, $profile, $this->trimmed('action')); - $cnt = $profile_list->show_list(); - } else { - $cnt = $this->icon_list($other); - } - - # For building the pagination URLs - - $args = array('nickname' => $profile->nickname); - - if ($display != 'list') { - $args['display'] = $display; - } - - common_pagination($page > 1, - $cnt > $per_page, - $page, - $this->trimmed('action'), - $args); - } - - function profile_list_class() { - return 'ProfileList'; - } - - function icon_list($other) { - - common_element_start('ul', $this->div_class()); - - $cnt = 0; - - while ($other->fetch()) { - - $cnt++; - - if ($cnt > AVATARS_PER_PAGE) { - break; - } - - common_element_start('li'); - - common_element_start('a', array('title' => ($other->fullname) ? - $other->fullname : - $other->nickname, - 'href' => $other->profileurl, - 'class' => 'subscription')); - $avatar = $other->getAvatar(AVATAR_STREAM_SIZE); - common_element('img', - array('src' => - (($avatar) ? common_avatar_display_url($avatar) : - common_default_avatar(AVATAR_STREAM_SIZE)), - 'width' => AVATAR_STREAM_SIZE, - 'height' => AVATAR_STREAM_SIZE, - 'class' => 'avatar stream', - 'alt' => ($other->fullname) ? - $other->fullname : - $other->nickname)); - common_element_end('a'); - - # XXX: subscribe form here - - common_element_end('li'); - } - - common_element_end('ul'); - - return $cnt; - } - - function gallery_type() { - return NULL; - } - - function get_instructions(&$profile) { - return NULL; - } - - function fields() { - return NULL; - } - - function div_class() { - return ''; - } - - function display_links($profile, $page, $display) { - $tag = $this->trimmed('tag'); - - common_element_start('dl', array('id'=>'subscriptions_nav')); - common_element('dt', null, _('Subscriptions navigation')); - common_element_start('dd'); - common_element_start('ul', array('class'=>'nav')); - - switch ($display) { - case 'list': - common_element('li', array('class'=>'child_1'), _('List')); - common_element_start('li'); - $url_args = array('display' => 'icons', - 'nickname' => $profile->nickname, - 'page' => 1 + floor((($page - 1) * PROFILES_PER_PAGE) / AVATARS_PER_PAGE)); - if ($tag) { - $url_args['tag'] = $tag; - } - $url = common_local_url($this->trimmed('action'), $url_args); - common_element('a', array('href' => $url), - _('Icons')); - common_element_end('li'); - break; - default: - common_element_start('li', array('class'=>'child_1')); - $url_args = array('nickname' => $profile->nickname, - 'page' => 1 + floor((($page - 1) * AVATARS_PER_PAGE) / PROFILES_PER_PAGE)); - if ($tag) { - $url_args['tag'] = $tag; - } - $url = common_local_url($this->trimmed('action'), $url_args); - common_element('a', array('href' => $url), - _('List')); - common_element_end('li'); - common_element('li', NULL, _('Icons')); - break; - } - - common_element_end('ul'); - common_element_end('dd'); - common_element_end('dl'); - } - - # Get list of tags we tagged other users with - - function get_all_tags($profile, $lst, $usr) { - $profile_tag = new Notice_tag(); - $profile_tag->query('SELECT DISTINCT(tag) ' . - 'FROM profile_tag, subscription ' . - 'WHERE tagger = ' . $profile->id . ' ' . - 'AND ' . $usr . ' = ' . $profile->id . ' ' . - 'AND ' . $lst . ' = tagged ' . - 'AND tagger != tagged'); - $tags = array(); - while ($profile_tag->fetch()) { - $tags[] = $profile_tag->tag; - } - $profile_tag->free(); - return $tags; - } -}
\ No newline at end of file diff --git a/lib/galleryaction.php b/lib/galleryaction.php new file mode 100644 index 000000000..25a5e3fd5 --- /dev/null +++ b/lib/galleryaction.php @@ -0,0 +1,171 @@ +<?php +/** + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/profilelist.php'; + +// 10x8 + +define('AVATARS_PER_PAGE', 80); + +class GalleryAction extends Action +{ + var $profile = null; + var $user = null; + var $page = null; + var $tag = null; + + function prepare($args) + { + parent::prepare($args); + + // FIXME very similar code below + + $nickname_arg = $this->arg('nickname'); + $nickname = common_canonical_nickname($nickname_arg); + + // Permanent redirect on non-canonical nickname + + if ($nickname_arg != $nickname) { + $args = array('nickname' => $nickname); + if ($this->arg('page') && $this->arg('page') != 1) { + $args['page'] = $this->arg['page']; + } + common_redirect(common_local_url('subscriptions', $args), 301); + return false; + } + + $this->user = User::staticGet('nickname', $nickname); + + if (!$this->user) { + $this->clientError(_('No such user.'), 404); + return false; + } + + $this->profile = $this->user->getProfile(); + + if (!$this->profile) { + $this->serverError(_('User has no profile.')); + return false; + } + + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + $this->tag = $this->trimmed('tag'); + + return true; + } + + function isReadOnly() + { + return true; + } + + function handle($args) + { + parent::handle($args); + + # Post from the tag dropdown; redirect to a GET + + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + common_redirect($this->selfUrl(), 307); + return; + } + + $this->showPage(); + } + + function showLocalNav() + { + $nav = new SubGroupNav($this, $this->user); + $nav->show(); + } + + function showContent() + { + $this->showTagsDropdown(); + } + + function showTagsDropdown() + { + $tag = $this->trimmed('tag'); + + $tags = $this->getAllTags(); + + $content = array(); + + foreach ($tags as $t) { + $content[$t] = $t; + } + if ($tags) { + $this->elementStart('dl', array('id'=>'filter_tags')); + $this->element('dt', null, _('Filter tags')); + $this->elementStart('dd'); + $this->elementStart('ul'); + $this->elementStart('li', array('id' => 'filter_tags_all', + 'class' => 'child_1')); + $this->element('a', + array('href' => + common_local_url($this->trimmed('action'), + array('nickname' => + $this->user->nickname))), + _('All')); + $this->elementEnd('li'); + $this->elementStart('li', array('id'=>'filter_tags_item')); + $this->elementStart('form', array('name' => 'bytag', + 'id' => 'bytag', + 'method' => 'post')); + $this->dropdown('tag', _('Tag'), $content, + _('Choose a tag to narrow list'), false, $tag); + $this->submit('go', _('Go')); + $this->elementEnd('form'); + $this->elementEnd('li'); + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + } + } + + // Get list of tags we tagged other users with + + function getTags($lst, $usr) + { + $profile_tag = new Notice_tag(); + $profile_tag->query('SELECT DISTINCT(tag) ' . + 'FROM profile_tag, subscription ' . + 'WHERE tagger = ' . $this->profile->id . ' ' . + 'AND ' . $usr . ' = ' . $this->profile->id . ' ' . + 'AND ' . $lst . ' = tagged ' . + 'AND tagger != tagged'); + $tags = array(); + while ($profile_tag->fetch()) { + $tags[] = $profile_tag->tag; + } + $profile_tag->free(); + return $tags; + } + + function getAllTags() + { + return array(); + } +}
\ No newline at end of file diff --git a/lib/groupeditform.php b/lib/groupeditform.php new file mode 100644 index 000000000..ca674f3c8 --- /dev/null +++ b/lib/groupeditform.php @@ -0,0 +1,173 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for editing a group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for editing a group + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see UnsubscribeForm + */ + +class GroupEditForm extends Form +{ + /** + * group for user to join + */ + + var $group = null; + + /** + * Constructor + * + * @param Action $out output channel + * @param User_group $group group to join + */ + + function __construct($out=null, $group=null) + { + parent::__construct($out); + + $this->group = $group; + } + + /** + * ID of the form + * + * @return string ID of the form + */ + + function id() + { + if ($this->group) { + return 'form_group_edit-' . $this->group->id; + } else { + return 'form_group_add'; + } + } + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_settings'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + if ($this->group) { + return common_local_url('editgroup', + array('nickname' => $this->group->nickname)); + } else { + return common_local_url('newgroup'); + } + } + + + /** + * Name of the form + * + * @return void + */ + + function formLegend() + { + $this->out->element('legend', null, _('Create a new group')); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->elementStart('ul', 'form_data'); + $this->out->elementStart('li'); + $this->out->hidden('groupid', $this->group->id); + $this->out->input('nickname', _('Nickname'), + ($this->out->arg('nickname')) ? $this->out->arg('nickname') : $this->group->nickname, + _('1-64 lowercase letters or numbers, no punctuation or spaces')); + $this->out->elementEnd('li'); + $this->out->elementStart('li'); + $this->out->input('fullname', _('Full name'), + ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $this->group->fullname); + $this->out->elementEnd('li'); + $this->out->elementStart('li'); + $this->out->input('homepage', _('Homepage'), + ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $this->group->homepage, + _('URL of the homepage or blog of the group or topic')); + $this->out->elementEnd('li'); + $this->out->elementStart('li'); + $this->out->textarea('description', _('Description'), + ($this->out->arg('description')) ? $this->out->arg('description') : $this->group->description, + _('Describe the group or topic in 140 chars')); + $this->out->elementEnd('li'); + $this->out->elementStart('li'); + $this->out->input('location', _('Location'), + ($this->out->arg('location')) ? $this->out->arg('location') : $this->group->location, + _('Location for the group, if any, like "City, State (or Region), Country"')); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Save')); + } +} diff --git a/lib/grouplist.php b/lib/grouplist.php new file mode 100644 index 000000000..629bdd05d --- /dev/null +++ b/lib/grouplist.php @@ -0,0 +1,186 @@ +<?php + +/** + * Laconica, the distributed open-source microblogging tool + * + * Widget to show a list of groups + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +define('GROUPS_PER_PAGE', 20); + +/** + * Widget to show a list of groups + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupList extends Widget +{ + /** Current group, group query. */ + var $group = null; + /** Owner of this list */ + var $owner = null; + /** Action object using us. */ + var $action = null; + + function __construct($group, $owner=null, $action=null) + { + parent::__construct($action); + + $this->group = $group; + $this->owner = $owner; + $this->action = $action; + } + + function show() + { + $this->out->elementStart('ul', 'profiles groups xoxo'); + + $cnt = 0; + + while ($this->group->fetch()) { + $cnt++; + if($cnt > GROUPS_PER_PAGE) { + break; + } + $this->showgroup(); + } + + $this->out->elementEnd('ul'); + + return $cnt; + } + + function showGroup() + { + $this->out->elementStart('li', array('class' => 'profile', + 'id' => 'group-' . $this->group->id)); + + $user = common_current_user(); + + $this->out->elementStart('div', 'entity_profile vcard'); + + $logo = ($this->group->stream_logo) ? + $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE); + + $this->out->elementStart('a', array('href' => $this->group->homeUrl(), + 'class' => 'url', + 'rel' => 'group')); + $this->out->element('img', array('src' => $logo, + 'class' => 'photo avatar', + 'width' => AVATAR_STREAM_SIZE, + 'height' => AVATAR_STREAM_SIZE, + 'alt' => + ($this->group->fullname) ? $this->group->fullname : + $this->group->nickname)); + $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid'; + $this->out->elementStart('span', $hasFN); + $this->out->raw($this->highlight($this->group->nickname)); + $this->out->elementEnd('span'); + $this->out->elementEnd('a'); + + if ($this->group->fullname) { + $this->out->elementStart('dl', 'entity_fn'); + $this->out->element('dt', null, 'Full name'); + $this->out->elementStart('dd'); + $this->out->elementStart('span', 'fn org'); + $this->out->raw($this->highlight($this->group->fullname)); + $this->out->elementEnd('span'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + if ($this->group->location) { + $this->out->elementStart('dl', 'entity_location'); + $this->out->element('dt', null, _('Location')); + $this->out->elementStart('dd', 'location'); + $this->out->raw($this->highlight($this->group->location)); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + if ($this->group->homepage) { + $this->out->elementStart('dl', 'entity_url'); + $this->out->element('dt', null, _('URL')); + $this->out->elementStart('dd'); + $this->out->elementStart('a', array('href' => $this->group->homepage, + 'class' => 'url')); + $this->out->raw($this->highlight($this->group->homepage)); + $this->out->elementEnd('a'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + if ($this->group->description) { + $this->out->elementStart('dl', 'entity_note'); + $this->out->element('dt', null, _('Note')); + $this->out->elementStart('dd', 'note'); + $this->out->raw($this->highlight($this->group->description)); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + + # If we're on a list with an owner (subscriptions or subscribers)... + + if ($user && $user->id == $this->owner->id) { + $this->showOwnerControls(); + } + + $this->out->elementEnd('div'); + + if ($user) { + # XXX: special-case for user looking at own + # subscriptions page + if ($user->isMember($this->group)) { + $lf = new LeaveForm($this->out, $this->group); + $lf->show(); + } else { + $jf = new JoinForm($this->out, $this->group); + $jf->show(); + } + } + + $this->out->elementEnd('li'); + } + + /* Override this in subclasses. */ + + function showOwnerControls() + { + return; + } + + function highlight($text) + { + return htmlspecialchars($text); + } +} diff --git a/lib/groupminilist.php b/lib/groupminilist.php new file mode 100644 index 000000000..fe38d0340 --- /dev/null +++ b/lib/groupminilist.php @@ -0,0 +1,92 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Widget to show a mini-list of groups + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/grouplist.php'; + +define('GROUPS_PER_MINILIST', 80); + +/** + * Widget to show a list of groups, good for sidebar + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupMiniList extends GroupList +{ + function show() + { + $this->out->elementStart('ul', 'entities groups xoxo'); + + $cnt = 0; + + while ($this->group->fetch()) { + $cnt++; + if($cnt > GROUPS_PER_MINILIST) { + break; + } + $this->showGroup(); + } + + $this->out->elementEnd('ul'); + + return $cnt; + } + + function showGroup() + { + $this->out->elementStart('li', 'vcard'); + $this->out->elementStart('a', array('title' => ($this->group->fullname) ? + $this->group->fullname : + $this->group->nickname, + 'href' => $this->group->homeUrl(), + 'rel' => 'contact group', + 'class' => 'url')); + $logo = ($this->group->stream_logo) ? + $this->group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE); + + $this->out->element('img', array('src' => $logo, + 'width' => AVATAR_MINI_SIZE, + 'height' => AVATAR_MINI_SIZE, + 'class' => 'avatar photo', + 'alt' => ($this->group->fullname) ? + $this->group->fullname : + $this->group->nickname)); + $this->out->element('span', 'fn org nickname', $this->group->nickname); + $this->out->elementEnd('a'); + $this->out->elementEnd('li'); + } +} diff --git a/lib/groupnav.php b/lib/groupnav.php new file mode 100644 index 000000000..90bdc1014 --- /dev/null +++ b/lib/groupnav.php @@ -0,0 +1,113 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Tabset for a particular group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Tabset for a group + * + * Shows a group of tabs for a particular user group + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class GroupNav extends Widget +{ + var $action = null; + var $group = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null, $group=null) + { + parent::__construct($action); + $this->action = $action; + $this->group = $group; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $action_name = $this->action->trimmed('action'); + $nickname = $this->group->nickname; + + $this->out->elementStart('ul', array('class' => 'nav')); + $this->out->menuItem(common_local_url('showgroup', array('nickname' => + $nickname)), + _('Group'), + sprintf(_('%s group'), $nickname), + $action_name == 'showgroup', + 'nav_group_group'); + $this->out->menuItem(common_local_url('groupmembers', array('nickname' => + $nickname)), + _('Members'), + sprintf(_('%s group members'), $nickname), + $action_name == 'groupmembers', + 'nav_group_members'); + + $cur = common_current_user(); + + if ($cur && $cur->isAdmin($this->group)) { + $this->out->menuItem(common_local_url('editgroup', array('nickname' => + $nickname)), + _('Admin'), + sprintf(_('Edit %s group properties'), $nickname), + $action_name == 'editgroup', + 'nav_group_admin'); + $this->out->menuItem(common_local_url('grouplogo', array('nickname' => + $nickname)), + _('Logo'), + sprintf(_('Add or edit %s logo'), $nickname), + $action_name == 'grouplogo', + 'nav_group_logo'); + } + $this->out->elementEnd('ul'); + } +} diff --git a/lib/groupsbymemberssection.php b/lib/groupsbymemberssection.php new file mode 100644 index 000000000..4fa07a244 --- /dev/null +++ b/lib/groupsbymemberssection.php @@ -0,0 +1,78 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Groups with the most members section + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Groups with the most members section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupsByMembersSection extends GroupSection +{ + function getGroups() + { + $qry = 'SELECT user_group.*, count(*) as value ' . + 'FROM user_group JOIN group_member '. + 'ON user_group.id = group_member.group_id ' . + 'GROUP BY user_group.id ' . + 'ORDER BY value DESC '; + + $limit = GROUPS_PER_SECTION; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $group = Memcached_DataObject::cachedQuery('User_group', + $qry, + 3600); + return $group; + } + + function title() + { + return _('Groups with most members'); + } + + function divId() + { + return 'top_groups_by_member'; + } +} diff --git a/lib/groupsbypostssection.php b/lib/groupsbypostssection.php new file mode 100644 index 000000000..a5e33a93d --- /dev/null +++ b/lib/groupsbypostssection.php @@ -0,0 +1,78 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Groups with the most posts section + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Groups with the most posts section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupsByPostsSection extends GroupSection +{ + function getGroups() + { + $qry = 'SELECT user_group.*, count(*) as value ' . + 'FROM user_group JOIN group_inbox '. + 'ON user_group.id = group_inbox.group_id ' . + 'GROUP BY user_group.id ' . + 'ORDER BY value DESC '; + + $limit = GROUPS_PER_SECTION; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $group = Memcached_DataObject::cachedQuery('User_group', + $qry, + 3600); + return $group; + } + + function title() + { + return _('Groups with most posts'); + } + + function divId() + { + return 'top_groups_by_post'; + } +} diff --git a/lib/groupsection.php b/lib/groupsection.php new file mode 100644 index 000000000..c19299493 --- /dev/null +++ b/lib/groupsection.php @@ -0,0 +1,107 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections showing lists of groups + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('GROUPS_PER_SECTION', 6); + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupSection extends Section +{ + function showContent() + { + $profiles = $this->getGroups(); + + if (!$profiles) { + return false; + } + + $cnt = 0; + + $this->out->elementStart('table'); + + while ($profiles->fetch() && ++$cnt <= GROUPS_PER_SECTION) { + $this->showGroup($profiles); + } + + $this->out->elementEnd('table'); + + return ($cnt > GROUPS_PER_SECTION); + } + + function getGroups() + { + return null; + } + + function showGroup($group) + { + $this->out->elementStart('tr'); + $this->out->elementStart('td'); + $this->out->elementStart('span', 'vcard'); + $this->out->elementStart('a', array('title' => ($group->fullname) ? + $group->fullname : + $group->nickname, + 'href' => $group->homeUrl(), + 'rel' => 'contact group', + 'class' => 'url')); + $logo = ($group->stream_logo) ? + $group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE); + + $this->out->element('img', array('src' => $logo, + 'width' => AVATAR_MINI_SIZE, + 'height' => AVATAR_MINI_SIZE, + 'class' => 'avatar photo', + 'alt' => ($group->fullname) ? + $group->fullname : + $group->nickname)); + $this->out->element('span', 'fn org nickname', $group->nickname); + $this->out->elementEnd('a'); + $this->out->elementEnd('span'); + $this->out->elementEnd('td'); + if ($group->value) { + $this->out->element('td', 'value', $group->value); + } + $this->out->elementEnd('tr'); + } +} diff --git a/lib/grouptagcloudsection.php b/lib/grouptagcloudsection.php new file mode 100644 index 000000000..f05be85cb --- /dev/null +++ b/lib/grouptagcloudsection.php @@ -0,0 +1,87 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Personal tag cloud section + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class GroupTagCloudSection extends TagCloudSection +{ + var $group = null; + + function __construct($out=null, $group=null) + { + parent::__construct($out); + $this->group = $group; + } + + function title() + { + return sprintf(_('Tags in %s group\'s notices'), $this->group->nickname); + } + + function getTags() + { + $qry = 'SELECT notice_tag.tag, '. + 'sum(exp(-(now() - notice_tag.created)/%s)) as weight ' . + 'FROM notice_tag JOIN notice ' . + 'ON notice_tag.notice_id = notice.id ' . + 'JOIN group_inbox on group_inbox.notice_id = notice.id ' . + 'WHERE group_inbox.group_id = %d ' . + 'GROUP BY notice_tag.tag ' . + 'ORDER BY weight DESC '; + + $limit = TAGS_PER_SECTION; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $tag = Memcached_DataObject::cachedQuery('Notice_tag', + sprintf($qry, + common_config('tag', 'dropoff'), + $this->group->id), + 3600); + return $tag; + } + +} diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php new file mode 100644 index 000000000..f9245414f --- /dev/null +++ b/lib/htmloutputter.php @@ -0,0 +1,365 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Low-level generator for HTML + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/xmloutputter.php'; + +define('PAGE_TYPE_PREFS', + 'text/html,application/xhtml+xml,'. + 'application/xml;q=0.3,text/xml;q=0.2'); + +/** + * Low-level generator for HTML + * + * Abstracts some of the code necessary for HTML generation. Especially + * has methods for generating HTML form elements. Note that these have + * been created kind of haphazardly, not with an eye to making a general + * HTML-creation class. + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Action + * @see XMLOutputter + */ + +class HTMLOutputter extends XMLOutputter +{ + /** + * Constructor + * + * Just wraps the XMLOutputter constructor. + * + * @param string $output URI to output to, default = stdout + * @param boolean $indent Whether to indent output, default true + */ + + function __construct($output='php://output', $indent=true) + { + parent::__construct($output, $indent); + } + + /** + * Start an HTML document + * + * If $type isn't specified, will attempt to do content negotiation. + * + * Attempts to do content negotiation for language, also. + * + * @param string $type MIME type to use; default is to do negotation. + * + * @todo extract content negotiation code to an HTTP module or class. + * + * @return void + */ + + function startHTML($type=null) + { + if (!$type) { + $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? + $_SERVER['HTTP_ACCEPT'] : null; + + // XXX: allow content negotiation for RDF, RSS, or XRDS + + $cp = common_accept_to_prefs($httpaccept); + $sp = common_accept_to_prefs(PAGE_TYPE_PREFS); + + $type = common_negotiate_type($cp, $sp); + + if (!$type) { + common_user_error(_('This page is not available in a '. + 'media type you accept'), 406); + exit(0); + } + } + + header('Content-Type: '.$type); + + $this->extraHeaders(); + + $this->startXML('html', + '-//W3C//DTD XHTML 1.0 Strict//EN', + 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); + + // FIXME: correct language for interface + + $language = common_language(); + + $this->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', + 'xml:lang' => $language, + 'lang' => $language)); + } + + /** + * Ends an HTML document + * + * @return void + */ + function endHTML() + { + $this->elementEnd('html'); + $this->endXML(); + } + + /** + * To specify additional HTTP headers for the action + * + * @return void + */ + function extraHeaders() + { + // Needs to be overloaded + } + + /** + * Output an HTML text input element + * + * Despite the name, it is specifically for outputting a + * text input element, not other <input> elements. It outputs + * a cluster of elements, including a <label> and an associated + * instructions span. + * + * @param string $id element ID, must be unique on page + * @param string $label text of label for the element + * @param string $value value of the element, default null + * @param string $instructions instructions for valid input + * + * @todo add a $name parameter + * @todo add a $maxLength parameter + * @todo add a $size parameter + * + * @return void + */ + + function input($id, $label, $value=null, $instructions=null) + { + $this->element('label', array('for' => $id), $label); + $attrs = array('name' => $id, + 'type' => 'text', + 'id' => $id); + if ($value) { + $attrs['value'] = htmlspecialchars($value); + } + $this->element('input', $attrs); + if ($instructions) { + $this->element('p', 'form_guide', $instructions); + } + } + + /** + * output an HTML checkbox and associated elements + * + * Note that the value is default 'true' (the string), which can + * be used by Action::boolean() + * + * @param string $id element ID, must be unique on page + * @param string $label text of label for the element + * @param string $checked if the box is checked, default false + * @param string $instructions instructions for valid input + * @param string $value value of the checkbox, default 'true' + * @param string $disabled show the checkbox disabled, default false + * + * @return void + * + * @todo add a $name parameter + */ + + function checkbox($id, $label, $checked=false, $instructions=null, + $value='true', $disabled=false) + { + $attrs = array('name' => $id, + 'type' => 'checkbox', + 'class' => 'checkbox', + 'id' => $id); + if ($value) { + $attrs['value'] = htmlspecialchars($value); + } + if ($checked) { + $attrs['checked'] = 'checked'; + } + if ($disabled) { + $attrs['disabled'] = 'true'; + } + $this->element('input', $attrs); + $this->text(' '); + $this->element('label', array('class' => 'checkbox', + 'for' => $id), + $label); + $this->text(' '); + if ($instructions) { + $this->element('p', 'form_guide', $instructions); + } + } + + /** + * output an HTML combobox/select and associated elements + * + * $content is an array of key-value pairs for the dropdown, where + * the key is the option value attribute and the value is the option + * text. (Careful on the overuse of 'value' here.) + * + * @param string $id element ID, must be unique on page + * @param string $label text of label for the element + * @param array $content options array, value => text + * @param string $instructions instructions for valid input + * @param string $blank_select whether to have a blank entry, default false + * @param string $selected selected value, default null + * + * @return void + * + * @todo add a $name parameter + */ + + function dropdown($id, $label, $content, $instructions=null, + $blank_select=false, $selected=null) + { + $this->element('label', array('for' => $id), $label); + $this->elementStart('select', array('id' => $id, 'name' => $id)); + if ($blank_select) { + $this->element('option', array('value' => '')); + } + foreach ($content as $value => $option) { + if ($value == $selected) { + $this->element('option', array('value' => $value, + 'selected' => $value), + $option); + } else { + $this->element('option', array('value' => $value), $option); + } + } + $this->elementEnd('select'); + if ($instructions) { + $this->element('p', 'form_guide', $instructions); + } + } + + /** + * output an HTML hidden element + * + * $id is re-used as name + * + * @param string $id element ID, must be unique on page + * @param string $value hidden element value, default null + * @param string $name name, if different than ID + * + * @return void + */ + + function hidden($id, $value, $name=null) + { + $this->element('input', array('name' => ($name) ? $name : $id, + 'type' => 'hidden', + 'id' => $id, + 'value' => $value)); + } + + /** + * output an HTML password input and associated elements + * + * @param string $id element ID, must be unique on page + * @param string $label text of label for the element + * @param string $instructions instructions for valid input + * + * @return void + * + * @todo add a $name parameter + */ + + function password($id, $label, $instructions=null) + { + $this->element('label', array('for' => $id), $label); + $attrs = array('name' => $id, + 'type' => 'password', + 'class' => 'password', + 'id' => $id); + $this->element('input', $attrs); + if ($instructions) { + $this->element('p', 'form_guide', $instructions); + } + } + + /** + * output an HTML submit input and associated elements + * + * @param string $id element ID, must be unique on page + * @param string $label text of the button + * @param string $cls class of the button, default 'submit' + * @param string $name name, if different than ID + * + * @return void + * + * @todo add a $name parameter + */ + + function submit($id, $label, $cls='submit', $name=null, $title=null) + { + $this->element('input', array('type' => 'submit', + 'id' => $id, + 'name' => ($name) ? $name : $id, + 'class' => $cls, + 'value' => $label, + 'title' => $title)); + } + + /** + * output an HTML textarea and associated elements + * + * @param string $id element ID, must be unique on page + * @param string $label text of label for the element + * @param string $content content of the textarea, default none + * @param string $instructions instructions for valid input + * + * @return void + * + * @todo add a $name parameter + * @todo add a $cols parameter + * @todo add a $rows parameter + */ + + function textarea($id, $label, $content=null, $instructions=null) + { + $this->element('label', array('for' => $id), $label); + $this->element('textarea', array('rows' => 3, + 'cols' => 40, + 'name' => $id, + 'id' => $id), + ($content) ? $content : ''); + if ($instructions) { + $this->element('p', 'form_guide', $instructions); + } + } +} diff --git a/lib/imagefile.php b/lib/imagefile.php new file mode 100644 index 000000000..7f1db892c --- /dev/null +++ b/lib/imagefile.php @@ -0,0 +1,113 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Abstraction for an image file + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Image + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * A wrapper on uploaded files + * + * Makes it slightly easier to accept an image file from upload. + * + * @category Image + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class ImageFile +{ + var $filename = null; + var $barename = null; + var $type = null; + var $height = null; + var $width = null; + + function __construct($filename=null, $type=null, $width=null, $height=null) + { + $this->filename = $filename; + $this->type = $type; + $this->width = $type; + $this->height = $type; + } + + static function fromUpload($param='upload') + { + switch ($_FILES[$param]['error']) { + case UPLOAD_ERR_OK: // success, jump out + break; + case UPLOAD_ERR_INI_SIZE: + case UPLOAD_ERR_FORM_SIZE: + throw new Exception(_('That file is too big.')); + return; + case UPLOAD_ERR_PARTIAL: + @unlink($_FILES[$param]['tmp_name']); + throw new Exception(_('Partial upload.')); + return; + default: + throw new Exception(_('System error uploading file.')); + return; + } + + $imagefile = new ImageFile($_FILES[$param]['tmp_name']); + $info = @getimagesize($imagefile->filename); + + if (!$info) { + @unlink($imagefile->filename); + throw new Exception(_('Not an image or corrupt file.')); + return; + } + + $imagefile->width = $info[0]; + $imagefile->height = $info[1]; + + switch ($info[2]) { + case IMAGETYPE_GIF: + case IMAGETYPE_JPEG: + case IMAGETYPE_PNG: + $imagefile->type = $info[2]; + break; + default: + @unlink($imagefile->filename); + throw new Exception(_('Unsupported image file format.')); + return; + } + + return $imagefile; + } + + function unlink() + { + @unlink($this->filename); + } +}
\ No newline at end of file diff --git a/lib/jabber.php b/lib/jabber.php index ab0fd6af8..84d2a562c 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * utility functions for Jabber/GTalk/XMPP messages + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,286 +18,471 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Network + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once('XMPPHP/XMPP.php'); +require_once 'XMPPHP/XMPP.php'; -function jabber_valid_base_jid($jid) { - # Cheap but effective - return Validate::email($jid); -} +/** + * checks whether a string is a syntactically valid Jabber ID (JID) + * + * @param string $jid string to check + * + * @return boolean whether the string is a valid JID + */ -function jabber_normalize_jid($jid) { - if (preg_match("/(?:([^\@]+)\@)?([^\/]+)(?:\/(.*))?$/", $jid, $matches)) { - $node = $matches[1]; - $server = $matches[2]; - return strtolower($node.'@'.$server); - } else { - return NULL; - } +function jabber_valid_base_jid($jid) +{ + // Cheap but effective + return Validate::email($jid); } -function jabber_daemon_address() { - return common_config('xmpp', 'user') . '@' . common_config('xmpp', 'server'); +/** + * normalizes a Jabber ID for comparison + * + * @param string $jid JID to check + * + * @return string an equivalent JID in normalized (lowercase) form + */ + +function jabber_normalize_jid($jid) +{ + if (preg_match("/(?:([^\@]+)\@)?([^\/]+)(?:\/(.*))?$/", $jid, $matches)) { + $node = $matches[1]; + $server = $matches[2]; + return strtolower($node.'@'.$server); + } else { + return null; + } } -function jabber_connect($resource=NULL) { - static $conn = NULL; - if (!$conn) { - $conn = new XMPPHP_XMPP(common_config('xmpp', 'host') ? - common_config('xmpp', 'host') : - common_config('xmpp', 'server'), - common_config('xmpp', 'port'), - common_config('xmpp', 'user'), - common_config('xmpp', 'password'), - ($resource) ? $resource : - common_config('xmpp', 'resource'), - common_config('xmpp', 'server'), - common_config('xmpp', 'debug') ? - true : false, - common_config('xmpp', 'debug') ? - XMPPHP_Log::LEVEL_VERBOSE : NULL - ); - - if (!$conn) { - return false; - } - - $conn->autoSubscribe(); - $conn->useEncryption(common_config('xmpp', 'encryption')); - - try { - $conn->connect(true); # true = persistent connection - } catch (XMPPHP_Exception $e) { - common_log(LOG_ERROR, $e->getMessage()); - return false; - } - - $conn->processUntil('session_start'); - } - return $conn; +/** + * the JID of the Jabber daemon for this Laconica instance + * + * @return string JID of the Jabber daemon + */ + +function jabber_daemon_address() +{ + return common_config('xmpp', 'user') . '@' . common_config('xmpp', 'server'); } -function jabber_send_notice($to, $notice) { - $conn = jabber_connect(); - if (!$conn) { - return false; - } - $profile = Profile::staticGet($notice->profile_id); - if (!$profile) { - common_log(LOG_WARNING, 'Refusing to send notice with ' . - 'unknown profile ' . common_log_objstring($notice), - __FILE__); - return false; - } - $msg = jabber_format_notice($profile, $notice); - $entry = jabber_format_entry($profile, $notice); - $conn->message($to, $msg, 'chat', NULL, $entry); - $profile->free(); - return true; +/** + * connect the configured Jabber account to the configured server + * + * @param string $resource Resource to connect (defaults to configured resource) + * + * @return XMPPHP connection to the configured server + */ + +function jabber_connect($resource=null) +{ + static $conn = null; + if (!$conn) { + $conn = new XMPPHP_XMPP(common_config('xmpp', 'host') ? + common_config('xmpp', 'host') : + common_config('xmpp', 'server'), + common_config('xmpp', 'port'), + common_config('xmpp', 'user'), + common_config('xmpp', 'password'), + ($resource) ? $resource : + common_config('xmpp', 'resource'), + common_config('xmpp', 'server'), + common_config('xmpp', 'debug') ? + true : false, + common_config('xmpp', 'debug') ? + XMPPHP_Log::LEVEL_VERBOSE : null + ); + + if (!$conn) { + return false; + } + + $conn->autoSubscribe(); + $conn->useEncryption(common_config('xmpp', 'encryption')); + + try { + $conn->connect(true); // true = persistent connection + } catch (XMPPHP_Exception $e) { + common_log(LOG_ERROR, $e->getMessage()); + return false; + } + + $conn->processUntil('session_start'); + } + return $conn; } -# Extra stuff defined by Twitter, needed by twitter clients - -function jabber_format_entry($profile, $notice) { - - # FIXME: notice url might be remote - - $noticeurl = common_local_url('shownotice', - array('notice' => $notice->id)); - $msg = jabber_format_notice($profile, $notice); - $entry = "\n<entry xmlns='http://www.w3.org/2005/Atom'>\n"; - $entry .= "<source>\n"; - $entry .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n"; - $entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n"; - $entry .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n"; - $entry .= "<author><name>" . $profile->nickname . "</name></author>\n"; - $entry .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n"; - $entry .= "</source>\n"; - $entry .= "<title>" . htmlspecialchars($msg) . "</title>\n"; - $entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n"; - $entry .= "<link rel='alternate' href='" . $noticeurl . "' />\n"; - $entry .= "<id>". $notice->uri . "</id>\n"; - $entry .= "<published>".common_date_w3dtf($notice->created)."</published>\n"; - $entry .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n"; - $entry .= "</entry>\n"; - - $html = "\n<html xmlns='http://jabber.org/protocol/xhtml-im'>\n"; - $html .= "<body xmlns='http://www.w3.org/1999/xhtml'>\n"; - $html .= "<a href='".htmlspecialchars($profile->profileurl)."'>".$profile->nickname."</a>: "; - $html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice); - $html .= "\n</body>\n"; - $html .= "\n</html>\n"; - - $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n"; - $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n"; - $address .= "</addresses>\n"; - - # FIXME: include a pubsub event, too. - - return $html . $entry . $address; +/** + * send a single notice to a given Jabber address + * + * @param string $to JID to send the notice to + * @param Notice $notice notice to send + * + * @return boolean success value + */ + +function jabber_send_notice($to, $notice) +{ + $conn = jabber_connect(); + if (!$conn) { + return false; + } + $profile = Profile::staticGet($notice->profile_id); + if (!$profile) { + common_log(LOG_WARNING, 'Refusing to send notice with ' . + 'unknown profile ' . common_log_objstring($notice), + __FILE__); + return false; + } + $msg = jabber_format_notice($profile, $notice); + $entry = jabber_format_entry($profile, $notice); + $conn->message($to, $msg, 'chat', null, $entry); + $profile->free(); + return true; } -function jabber_send_message($to, $body, $type='chat', $subject=NULL) { - $conn = jabber_connect(); - if (!$conn) { - return false; - } - $conn->message($to, $body, $type, $subject); - return true; +/** + * extra information for XMPP messages, as defined by Twitter + * + * @param Profile $profile Profile of the sending user + * @param Notice $notice Notice being sent + * + * @return string Extra information (Atom, HTML, addresses) in string format + */ + +function jabber_format_entry($profile, $notice) +{ + // FIXME: notice url might be remote + + $noticeurl = common_local_url('shownotice', + array('notice' => $notice->id)); + + $msg = jabber_format_notice($profile, $notice); + + $self_url = common_local_url('userrss', array('nickname' => $profile->nickname)); + + $entry = "\n<entry xmlns='http://www.w3.org/2005/Atom'>\n"; + $entry .= "<source>\n"; + $entry .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n"; + $entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n"; + $entry .= "<link rel='self' type='application/rss+xml' href='" . $self_url . "'/>\n"; + $entry .= "<author><name>" . $profile->nickname . "</name></author>\n"; + $entry .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n"; + $entry .= "</source>\n"; + $entry .= "<title>" . htmlspecialchars($msg) . "</title>\n"; + $entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n"; + $entry .= "<link rel='alternate' href='" . $noticeurl . "' />\n"; + $entry .= "<id>". $notice->uri . "</id>\n"; + $entry .= "<published>".common_date_w3dtf($notice->created)."</published>\n"; + $entry .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n"; + $entry .= "</entry>\n"; + + $html = "\n<html xmlns='http://jabber.org/protocol/xhtml-im'>\n"; + $html .= "<body xmlns='http://www.w3.org/1999/xhtml'>\n"; + $html .= "<a href='".htmlspecialchars($profile->profileurl)."'>".$profile->nickname."</a>: "; + $html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice); + $html .= "\n</body>\n"; + $html .= "\n</html>\n"; + + $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n"; + $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n"; + $address .= "</addresses>\n"; + + // FIXME: include a pubsub event, too. + + return $html . $entry . $address; } -function jabber_send_presence($status, $show='available', $to=NULL, - $type = 'available', $priority=NULL) +/** + * sends a single text message to a given JID + * + * @param string $to JID to send the message to + * @param string $body body of the message + * @param string $type type of the message + * @param string $subject subject of the message + * + * @return boolean success flag + */ + +function jabber_send_message($to, $body, $type='chat', $subject=null) { - $conn = jabber_connect(); - if (!$conn) { - return false; - } - $conn->presence($status, $show, $to, $type, $priority); - return true; + $conn = jabber_connect(); + if (!$conn) { + return false; + } + $conn->message($to, $body, $type, $subject); + return true; } -function jabber_confirm_address($code, $nickname, $address) { - $body = 'User "' . $nickname . '" on ' . common_config('site', 'name') . ' ' . - 'has said that your Jabber ID belongs to them. ' . - 'If that\'s true, you can confirm by clicking on this URL: ' . - common_local_url('confirmaddress', array('code' => $code)) . - ' . (If you cannot click it, copy-and-paste it into the ' . - 'address bar of your browser). If that user isn\'t you, ' . - 'or if you didn\'t request this confirmation, just ignore this message.'; +/** + * sends a presence stanza on the Jabber network + * + * @param string $status current status, free-form string + * @param string $show structured status value + * @param string $to recipient of presence, null for general + * @param string $type type of status message, related to $show + * @param int $priority priority of the presence + * + * @return boolean success value + */ - return jabber_send_message($address, $body); +function jabber_send_presence($status, $show='available', $to=null, + $type = 'available', $priority=null) +{ + $conn = jabber_connect(); + if (!$conn) { + return false; + } + $conn->presence($status, $show, $to, $type, $priority); + return true; } -function jabber_special_presence($type, $to=NULL, $show=NULL, $status=NULL) { - $conn = jabber_connect(); - - $to = htmlspecialchars($to); - $status = htmlspecialchars($status); - $out = "<presence"; - if($to) $out .= " to='$to'"; - if($type) $out .= " type='$type'"; - if($show == 'available' and !$status) { - $out .= "/>"; - } else { - $out .= ">"; - if($show && ($show != 'available')) $out .= "<show>$show</show>"; - if($status) $out .= "<status>$status</status>"; - $out .= "</presence>"; - } - $conn->send($out); +/** + * sends a confirmation request to a JID + * + * @param string $code confirmation code for confirmation URL + * @param string $nickname nickname of confirming user + * @param string $address JID to send confirmation to + * + * @return boolean success flag + */ + +function jabber_confirm_address($code, $nickname, $address) +{ + $body = 'User "' . $nickname . '" on ' . common_config('site', 'name') . ' ' . + 'has said that your Jabber ID belongs to them. ' . + 'If that\'s true, you can confirm by clicking on this URL: ' . + common_local_url('confirmaddress', array('code' => $code)) . + ' . (If you cannot click it, copy-and-paste it into the ' . + 'address bar of your browser). If that user isn\'t you, ' . + 'or if you didn\'t request this confirmation, just ignore this message.'; + + return jabber_send_message($address, $body); } -function jabber_broadcast_notice($notice) { - - if (!common_config('xmpp', 'enabled')) { - return true; - } - $profile = Profile::staticGet($notice->profile_id); - - if (!$profile) { - common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . - 'unknown profile ' . common_log_objstring($notice), - __FILE__); - return false; - } - - $msg = jabber_format_notice($profile, $notice); - $entry = jabber_format_entry($profile, $notice); - - $profile->free(); - unset($profile); - - $sent_to = array(); - $conn = jabber_connect(); - - # First, get users to whom this is a direct reply - $user = new User(); - $user->query('SELECT user.id, user.jabber ' . - 'FROM user JOIN reply ON user.id = reply.profile_id ' . - 'WHERE reply.notice_id = ' . $notice->id . ' ' . - 'AND user.jabber is not null ' . - 'AND user.jabbernotify = 1 ' . - 'AND user.jabberreplies = 1 '); - - while ($user->fetch()) { - common_log(LOG_INFO, - 'Sending reply notice ' . $notice->id . ' to ' . $user->jabber, - __FILE__); - $conn->message($user->jabber, $msg, 'chat', NULL, $entry); - $conn->processTime(0); - $sent_to[$user->id] = 1; - } - - $user->free(); - - # Now, get users subscribed to this profile - - $user = new User(); - $user->query('SELECT user.id, user.jabber ' . - 'FROM user JOIN subscription ON user.id = subscription.subscriber ' . - 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' . - 'AND user.jabber is not null ' . - 'AND user.jabbernotify = 1 ' . - 'AND subscription.jabber = 1 '); +/** + * sends a "special" presence stanza on the Jabber network + * + * @param string $type Type of presence + * @param string $to JID to send presence to + * @param string $show show value for presence + * @param string $status status value for presence + * + * @return boolean success flag + * + * @see jabber_send_presence() + */ - while ($user->fetch()) { - if (!array_key_exists($user->id, $sent_to)) { - common_log(LOG_INFO, - 'Sending notice ' . $notice->id . ' to ' . $user->jabber, - __FILE__); - $conn->message($user->jabber, $msg, 'chat', NULL, $entry); - # To keep the incoming queue from filling up, we service it after each send. - $conn->processTime(0); - } - } +function jabber_special_presence($type, $to=null, $show=null, $status=null) +{ + // FIXME: why use this instead of jabber_send_presence()? + $conn = jabber_connect(); + + $to = htmlspecialchars($to); + $status = htmlspecialchars($status); + + $out = "<presence"; + if ($to) { + $out .= " to='$to'"; + } + if ($type) { + $out .= " type='$type'"; + } + if ($show == 'available' and !$status) { + $out .= "/>"; + } else { + $out .= ">"; + if ($show && ($show != 'available')) { + $out .= "<show>$show</show>"; + } + if ($status) { + $out .= "<status>$status</status>"; + } + $out .= "</presence>"; + } + $conn->send($out); +} - $user->free(); +/** + * broadcast a notice to all subscribers and reply recipients + * + * This function will send a notice to all subscribers on the local server + * who have Jabber addresses, and have Jabber notification enabled, and + * have this subscription enabled for Jabber. It also sends the notice to + * all recipients of @-replies who have Jabber addresses and Jabber notification + * enabled. This is really the heart of Jabber distribution in Laconica. + * + * @param Notice $notice The notice to broadcast + * + * @return boolean success flag + */ - return true; +function jabber_broadcast_notice($notice) +{ + if (!common_config('xmpp', 'enabled')) { + return true; + } + $profile = Profile::staticGet($notice->profile_id); + + if (!$profile) { + common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . + 'unknown profile ' . common_log_objstring($notice), + __FILE__); + return false; + } + + $msg = jabber_format_notice($profile, $notice); + $entry = jabber_format_entry($profile, $notice); + + $profile->free(); + unset($profile); + + $sent_to = array(); + + $conn = jabber_connect(); + + // First, get users to whom this is a direct reply + $user = new User(); + $user->query('SELECT user.id, user.jabber ' . + 'FROM user JOIN reply ON user.id = reply.profile_id ' . + 'WHERE reply.notice_id = ' . $notice->id . ' ' . + 'AND user.jabber is not null ' . + 'AND user.jabbernotify = 1 ' . + 'AND user.jabberreplies = 1 '); + + while ($user->fetch()) { + common_log(LOG_INFO, + 'Sending reply notice ' . $notice->id . ' to ' . $user->jabber, + __FILE__); + $conn->message($user->jabber, $msg, 'chat', null, $entry); + $conn->processTime(0); + $sent_to[$user->id] = 1; + } + + $user->free(); + + // Now, get users subscribed to this profile + + $user = new User(); + $user->query('SELECT user.id, user.jabber ' . + 'FROM user JOIN subscription ' . + 'ON user.id = subscription.subscriber ' . + 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' . + 'AND user.jabber is not null ' . + 'AND user.jabbernotify = 1 ' . + 'AND subscription.jabber = 1 '); + + while ($user->fetch()) { + if (!array_key_exists($user->id, $sent_to)) { + common_log(LOG_INFO, + 'Sending notice ' . $notice->id . ' to ' . $user->jabber, + __FILE__); + $conn->message($user->jabber, $msg, 'chat', null, $entry); + // To keep the incoming queue from filling up, + // we service it after each send. + $conn->processTime(0); + $sent_to[$user->id] = 1; + } + } + + // Now, get users who have it in their inbox because of groups + + $user = new User(); + $user->query('SELECT user.id, user.jabber ' . + 'FROM user JOIN notice_inbox ' . + 'ON user.id = notice_inbox.user_id ' . + 'WHERE notice_inbox.notice_id = ' . $notice->id . ' ' . + 'AND notice_inbox.source = 2 '); + + while ($user->fetch()) { + if (!array_key_exists($user->id, $sent_to)) { + common_log(LOG_INFO, + 'Sending notice ' . $notice->id . ' to ' . $user->jabber, + __FILE__); + $conn->message($user->jabber, $msg, 'chat', null, $entry); + // To keep the incoming queue from filling up, + // we service it after each send. + $conn->processTime(0); + $sent_to[$user->id] = 1; + } + } + + $user->free(); + + return true; } -function jabber_public_notice($notice) { +/** + * send a notice to all public listeners + * + * For notices that are generated on the local system (by users), we can optionally + * forward them to remote listeners by XMPP. + * + * @param Notice $notice notice to broadcast + * + * @return boolean success flag + */ - # Now, users who want everything +function jabber_public_notice($notice) +{ + // Now, users who want everything - $public = common_config('xmpp', 'public'); + $public = common_config('xmpp', 'public'); - # FIXME PRIV don't send out private messages here - # XXX: should we send out non-local messages if public,localonly - # = false? I think not + // FIXME PRIV don't send out private messages here + // XXX: should we send out non-local messages if public,localonly + // = false? I think not - if ($public && $notice->is_local) { - $profile = Profile::staticGet($notice->profile_id); + if ($public && $notice->is_local) { + $profile = Profile::staticGet($notice->profile_id); - if (!$profile) { - common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . - 'unknown profile ' . common_log_objstring($notice), - __FILE__); - return false; - } + if (!$profile) { + common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . + 'unknown profile ' . common_log_objstring($notice), + __FILE__); + return false; + } - $msg = jabber_format_notice($profile, $notice); - $entry = jabber_format_entry($profile, $notice); + $msg = jabber_format_notice($profile, $notice); + $entry = jabber_format_entry($profile, $notice); - $conn = jabber_connect(); + $conn = jabber_connect(); - foreach ($public as $address) { - common_log(LOG_INFO, - 'Sending notice ' . $notice->id . ' to public listener ' . $address, - __FILE__); - $conn->message($address, $msg, 'chat', NULL, $entry); - $conn->processTime(0); - } - $profile->free(); - } + foreach ($public as $address) { + common_log(LOG_INFO, + 'Sending notice ' . $notice->id . + ' to public listener ' . $address, + __FILE__); + $conn->message($address, $msg, 'chat', null, $entry); + $conn->processTime(0); + } + $profile->free(); + } - return true; + return true; } -function jabber_format_notice(&$profile, &$notice) { - return $profile->nickname . ': ' . $notice->content; +/** + * makes a plain-text formatted version of a notice, suitable for Jabber distribution + * + * @param Profile &$profile profile of the sending user + * @param Notice &$notice notice being sent + * + * @return string plain-text version of the notice, with user nickname prefixed + */ + +function jabber_format_notice(&$profile, &$notice) +{ + return $profile->nickname . ': ' . $notice->content; } diff --git a/lib/joinform.php b/lib/joinform.php new file mode 100644 index 000000000..1edb2f72d --- /dev/null +++ b/lib/joinform.php @@ -0,0 +1,116 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for joining a group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for joining a group + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see UnsubscribeForm + */ + +class JoinForm extends Form +{ + /** + * group for user to join + */ + + var $group = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param group $group group to join + */ + + function __construct($out=null, $group=null) + { + parent::__construct($out); + + $this->group = $group; + } + + /** + * ID of the form + * + * @return string ID of the form + */ + + function id() + { + return 'group-join-' . $this->group->id; + } + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_group_join'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('joingroup', + array('nickname' => $this->group->nickname)); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Join')); + } +} diff --git a/lib/language.php b/lib/language.php index f474c4999..a73b73f28 100644 --- a/lib/language.php +++ b/lib/language.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * utility functions for i18n + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,49 +18,87 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category I18n + * @package Laconica + * @author Matthew Gregg <matthew.gregg@gmail.com> + * @author Ciaran Gultnieks <ciaran@ciarang.com> + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Content negotiation for language codes + * + * @param string $httplang HTTP Accept-Language header + * + * @return string language code for best language match */ -if (!defined('LACONICA')) { exit(1); } +function client_prefered_language($httplang) +{ + $client_langs = array(); -function client_prefered_language($httplang) { - $client_langs = array(); - $all_languages = common_config('site','languages'); + $all_languages = common_config('site', 'languages'); - preg_match_all('"(((\S\S)-?(\S\S)?)(;q=([0-9.]+))?)\s*(,\s*|$)"',strtolower($httplang),$httplang); - for ($i = 0; $i < count($httplang); $i++) { - if(!empty($httplang[2][$i])) { - #if no q default to 1.0 - $client_langs[$httplang[2][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i] : 1.0); - } - if(!empty($httplang[3][$i]) && empty($client_langs[$httplang[3][$i]])) { - #if a catchall default 0.01 lower - $client_langs[$httplang[3][$i]] = ($httplang[6][$i]? (float) $httplang[6][$i]-0.01 : 0.99); - } - } - #sort in decending q - arsort($client_langs); + preg_match_all('"(((\S\S)-?(\S\S)?)(;q=([0-9.]+))?)\s*(,\s*|$)"', + strtolower($httplang), $httplang); - foreach ($client_langs as $lang => $q) { - if (isset($all_languages[$lang])) { - return($all_languages[$lang]['lang']); - } - } - return FALSE; -} + for ($i = 0; $i < count($httplang); $i++) { + if (!empty($httplang[2][$i])) { + // if no q default to 1.0 + $client_langs[$httplang[2][$i]] = + ($httplang[6][$i]? (float) $httplang[6][$i] : 1.0); + } + if (!empty($httplang[3][$i]) && empty($client_langs[$httplang[3][$i]])) { + // if a catchall default 0.01 lower + $client_langs[$httplang[3][$i]] = + ($httplang[6][$i]? (float) $httplang[6][$i]-0.01 : 0.99); + } + } + // sort in decending q + arsort($client_langs); -function get_nice_language_list() { - $nice_lang = array(); - $all_languages = common_config('site','languages'); - foreach ($all_languages as $lang) { - $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']); + foreach ($client_langs as $lang => $q) { + if (isset($all_languages[$lang])) { + return($all_languages[$lang]['lang']); } - return $nice_lang; + } + return false; } -// Get a list of all languages that are enabled in the default config. This -// should ONLY be called when setting up the default config in common.php. -// Any other attempt to get a list of lanugages should instead call -// common_config('site','languages') +/** + * returns a simple code -> name mapping for languages + * + * @return array map of available languages by code to language name. + */ + +function get_nice_language_list() +{ + $nice_lang = array(); + + $all_languages = common_config('site', 'languages'); + + foreach ($all_languages as $lang) { + $nice_lang = $nice_lang + array($lang['lang'] => $lang['name']); + } + return $nice_lang; +} + +/** + * Get a list of all languages that are enabled in the default config + * + * This should ONLY be called when setting up the default config in common.php. + * Any other attempt to get a list of lanugages should instead call + * common_config('site','languages') + * + * @return array mapping of language codes to language info + */ function get_all_languages() { return array( 'bg' => array('q' => 0.8, 'lang' => 'bg_BG', 'name' => 'Bulgarian', 'direction' => 'ltr'), @@ -90,4 +131,3 @@ function get_all_languages() { 'zh-hant' => array('q' => 0.2, 'lang' => 'zh_hant', 'name' => 'Chinese (Taiwanese)', 'direction' => 'ltr'), ); } - diff --git a/lib/leaveform.php b/lib/leaveform.php new file mode 100644 index 000000000..696559a25 --- /dev/null +++ b/lib/leaveform.php @@ -0,0 +1,116 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for leaving a group + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for leaving a group + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see UnsubscribeForm + */ + +class LeaveForm extends Form +{ + /** + * group for user to leave + */ + + var $group = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param group $group group to leave + */ + + function __construct($out=null, $group=null) + { + parent::__construct($out); + + $this->group = $group; + } + + /** + * ID of the form + * + * @return string ID of the form + */ + + function id() + { + return 'group-leave-' . $this->group->id; + } + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_group_leave'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('leavegroup', + array('nickname' => $this->group->nickname)); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Leave')); + } +} diff --git a/lib/logingroupnav.php b/lib/logingroupnav.php new file mode 100644 index 000000000..8c03eccea --- /dev/null +++ b/lib/logingroupnav.php @@ -0,0 +1,96 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Menu for login group of actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Menu for login group of actions + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class LoginGroupNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + // action => array('prompt', 'title') + $menu = + array('login' => + array(_('Login'), + _('Login with a username and password')), + 'register' => + array(_('Register'), + _('Sign up for a new account')), + 'openid' => + array(_('OpenID'), + _('Login or register with OpenID'))); + + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + + foreach ($menu as $menuaction => $menudesc) { + $this->action->menuItem(common_local_url($menuaction), + $menudesc[0], + $menudesc[1], + $action_name === $menuaction); + } + + $this->action->elementEnd('ul'); + } +} diff --git a/lib/mail.php b/lib/mail.php index a7cbab858..5638ae9bf 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * utilities for sending email + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,295 +18,557 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Mail + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once('Mail.php'); +require_once 'Mail.php'; -function mail_backend() { - static $backend = NULL; +/** + * return the configured mail backend + * + * Uses the $config array to make a mail backend. Cached so it is safe to call + * more than once. + * + * @return Mail backend + */ - if (!$backend) { - global $config; - $backend = Mail::factory($config['mail']['backend'], - ($config['mail']['params']) ? $config['mail']['params'] : array()); - if (PEAR::isError($backend)) { - common_server_error($backend->getMessage(), 500); - } - } - return $backend; +function mail_backend() +{ + static $backend = null; + + if (!$backend) { + global $config; + $backend = Mail::factory($config['mail']['backend'], + ($config['mail']['params']) ? + $config['mail']['params'] : + array()); + if (PEAR::isError($backend)) { + common_server_error($backend->getMessage(), 500); + } + } + return $backend; } -# XXX: use Mail_Queue... maybe +/** + * send an email to one or more recipients + * + * @param array $recipients array of strings with email addresses of recipients + * @param array $headers array mapping strings to strings for email headers + * @param string $body body of the email + * + * @return boolean success flag + */ -function mail_send($recipients, $headers, $body) { - $backend = mail_backend(); +function mail_send($recipients, $headers, $body) +{ + // XXX: use Mail_Queue... maybe + $backend = mail_backend(); if (!isset($headers['Content-Type'])) { $headers['Content-Type'] = 'text/plain; charset=UTF-8'; } - assert($backend); # throws an error if it's bad - $sent = $backend->send($recipients, $headers, $body); - if (PEAR::isError($sent)) { - common_log(LOG_ERR, 'Email error: ' . $sent->getMessage()); - return false; - } - return true; + assert($backend); // throws an error if it's bad + $sent = $backend->send($recipients, $headers, $body); + if (PEAR::isError($sent)) { + common_log(LOG_ERR, 'Email error: ' . $sent->getMessage()); + return false; + } + return true; } -function mail_domain() { - $maildomain = common_config('mail', 'domain'); - if (!$maildomain) { - $maildomain = common_config('site', 'server'); - } - return $maildomain; -} +/** + * returns the configured mail domain + * + * Defaults to the server name. + * + * @return string mail domain, suitable for making email addresses. + */ -function mail_notify_from() { - $notifyfrom = common_config('mail', 'notifyfrom'); - if (!$notifyfrom) { - $domain = mail_domain(); - $notifyfrom = common_config('site', 'name') .' <noreply@'.$domain.'>'; - } - return $notifyfrom; +function mail_domain() +{ + $maildomain = common_config('mail', 'domain'); + if (!$maildomain) { + $maildomain = common_config('site', 'server'); + } + return $maildomain; } -function mail_to_user(&$user, $subject, $body, $address=NULL) { - if (!$address) { - $address = $user->email; - } +/** + * returns a good address for sending email from this server + * + * Uses either the configured value or a faked-up value made + * from the mail domain. + * + * @return string notify from address + */ - $recipients = $address; - $profile = $user->getProfile(); +function mail_notify_from() +{ + $notifyfrom = common_config('mail', 'notifyfrom'); - $headers['From'] = mail_notify_from(); - $headers['To'] = $profile->getBestName() . ' <' . $address . '>'; - $headers['Subject'] = $subject; + if (!$notifyfrom) { - return mail_send($recipients, $headers, $body); + $domain = mail_domain(); + + $notifyfrom = common_config('site', 'name') .' <noreply@'.$domain.'>'; + } + + return $notifyfrom; } -# For confirming a Jabber address +/** + * sends email to a user + * + * @param User &$user user to send email to + * @param string $subject subject of the email + * @param string $body body of the email + * @param string $address optional specification of email address + * + * @return boolean success flag + */ -function mail_confirm_address($user, $code, $nickname, $address) { +function mail_to_user(&$user, $subject, $body, $address=null) +{ + if (!$address) { + $address = $user->email; + } + + $recipients = $address; + $profile = $user->getProfile(); - $subject = _('Email address confirmation'); + $headers['From'] = mail_notify_from(); + $headers['To'] = $profile->getBestName() . ' <' . $address . '>'; + $headers['Subject'] = $subject; - $body = sprintf(_("Hey, %s.\n\nSomeone just entered this email address on %s.\n\n" . - "If it was you, and you want to confirm your entry, use the URL below:\n\n\t%s\n\n" . - "If not, just ignore this message.\n\nThanks for your time, \n%s\n") - , $nickname, common_config('site', 'name') - , common_local_url('confirmaddress', array('code' => $code)), common_config('site', 'name')); - return mail_to_user($user, $subject, $body, $address); + return mail_send($recipients, $headers, $body); } -function mail_subscribe_notify($listenee, $listener) { - $other = $listener->getProfile(); - mail_subscribe_notify_profile($listenee, $other); +/** + * Send an email to confirm a user's control of an email address + * + * @param User $user User claiming the email address + * @param string $code Confirmation code + * @param string $nickname Nickname of user + * @param string $address email address to confirm + * + * @see common_confirmation_code() + * + * @return success flag + */ + +function mail_confirm_address($user, $code, $nickname, $address) +{ + $subject = _('Email address confirmation'); + + $body = sprintf(_("Hey, %s.\n\n". + "Someone just entered this email address on %s.\n\n" . + "If it was you, and you want to confirm your entry, ". + "use the URL below:\n\n\t%s\n\n" . + "If not, just ignore this message.\n\n". + "Thanks for your time, \n%s\n"), + $nickname, common_config('site', 'name'), + common_local_url('confirmaddress', array('code' => $code)), + common_config('site', 'name')); + return mail_to_user($user, $subject, $body, $address); } -function mail_subscribe_notify_profile($listenee, $other) { - if ($listenee->email && $listenee->emailnotifysub) { - // use the recipients localization +/** + * notify a user of subscription by another user + * + * This is just a wrapper around the profile-based version. + * + * @param User $listenee user who is being subscribed to + * @param User $listener user who is subscribing + * + * @see mail_subscribe_notify_profile() + * + * @return void + */ + +function mail_subscribe_notify($listenee, $listener) +{ + $other = $listener->getProfile(); + mail_subscribe_notify_profile($listenee, $other); +} + +/** + * notify a user of subscription by a profile (remote or local) + * + * This function checks to see if the listenee has an email + * address and wants subscription notices. + * + * @param User $listenee user who's being subscribed to + * @param Profile $other profile of person who's listening + * + * @return void + */ + +function mail_subscribe_notify_profile($listenee, $other) +{ + if ($listenee->email && $listenee->emailnotifysub) { + + // use the recipient's localization common_init_locale($listenee->language); - $profile = $listenee->getProfile(); - $name = $profile->getBestName(); - $long_name = ($other->fullname) ? ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname; - $recipients = $listenee->email; - $headers['From'] = mail_notify_from(); - $headers['To'] = $name . ' <' . $listenee->email . '>'; - $headers['Subject'] = sprintf(_('%1$s is now listening to your notices on %2$s.'), $other->getBestName(), - common_config('site', 'name')); - $body = sprintf(_('%1$s is now listening to your notices on %2$s.'."\n\n". - "\t".'%3$s'."\n\n". - 'Faithfully yours,'."\n".'%4$s.'."\n"), - $long_name, - common_config('site', 'name'), - $other->profileurl, - common_config('site', 'name')); + + $profile = $listenee->getProfile(); + + $name = $profile->getBestName(); + + $long_name = ($other->fullname) ? + ($other->fullname . ' (' . $other->nickname . ')') : $other->nickname; + + $recipients = $listenee->email; + + $headers['From'] = mail_notify_from(); + $headers['To'] = $name . ' <' . $listenee->email . '>'; + $headers['Subject'] = sprintf(_('%1$s is now listening to '. + 'your notices on %2$s.'), + $other->getBestName(), + common_config('site', 'name')); + + $body = sprintf(_('%1$s is now listening to your notices on %2$s.'."\n\n". + "\t".'%3$s'."\n\n". + '%4$s'. + '%5$s'. + '%6$s'. + "\n".'Faithfully yours,'."\n".'%7$s.'."\n\n". + "----\n". + "Change your email address or ". + "notification options at %8$s\n"), + $long_name, + common_config('site', 'name'), + $other->profileurl, + ($other->location) ? + sprintf(_("Location: %s\n"), $other->location) : '', + ($other->homepage) ? + sprintf(_("Homepage: %s\n"), $other->homepage) : '', + ($other->bio) ? + sprintf(_("Bio: %s\n\n"), $other->bio) : '', + common_config('site', 'name'), + common_local_url('emailsettings')); // reset localization common_init_locale(); - mail_send($recipients, $headers, $body); - } + mail_send($recipients, $headers, $body); + } } -function mail_new_incoming_notify($user) { +/** + * notify a user of their new incoming email address + * + * User's email and incoming fields should already be updated. + * + * @param User $user user with the new address + * + * @return void + */ - $profile = $user->getProfile(); - $name = $profile->getBestName(); +function mail_new_incoming_notify($user) +{ + $profile = $user->getProfile(); - $headers['From'] = $user->incomingemail; - $headers['To'] = $name . ' <' . $user->email . '>'; - $headers['Subject'] = sprintf(_('New email address for posting to %s'), - common_config('site', 'name')); + $name = $profile->getBestName(); - $body = sprintf(_("You have a new posting address on %1\$s.\n\n". - "Send email to %2\$s to post new messages.\n\n". - "More email instructions at %3\$s.\n\n". - "Faithfully yours,\n%4\$s"), - common_config('site', 'name'), - $user->incomingemail, - common_local_url('doc', array('title' => 'email')), - common_config('site', 'name')); + $headers['From'] = $user->incomingemail; + $headers['To'] = $name . ' <' . $user->email . '>'; + $headers['Subject'] = sprintf(_('New email address for posting to %s'), + common_config('site', 'name')); - mail_send($user->email, $headers, $body); + $body = sprintf(_("You have a new posting address on %1\$s.\n\n". + "Send email to %2\$s to post new messages.\n\n". + "More email instructions at %3\$s.\n\n". + "Faithfully yours,\n%4\$s"), + common_config('site', 'name'), + $user->incomingemail, + common_local_url('doc', array('title' => 'email')), + common_config('site', 'name')); + + mail_send($user->email, $headers, $body); } -function mail_new_incoming_address() { - $prefix = common_confirmation_code(64); - $suffix = mail_domain(); - return $prefix . '@' . $suffix; +/** + * generate a new address for incoming messages + * + * @todo check the database for uniqueness + * + * @return string new email address for incoming messages + */ + +function mail_new_incoming_address() +{ + $prefix = common_confirmation_code(64); + $suffix = mail_domain(); + return $prefix . '@' . $suffix; } -function mail_broadcast_notice_sms($notice) { +/** + * broadcast a notice to all subscribers with SMS notification on + * + * This function sends SMS messages to all users who have sms addresses; + * have sms notification on; and have sms enabled for this particular + * subscription. + * + * @param Notice $notice The notice to broadcast + * + * @return success flag + */ - # Now, get users subscribed to this profile +function mail_broadcast_notice_sms($notice) +{ + // Now, get users subscribed to this profile - $user = new User(); + $user = new User(); - $user->query('SELECT nickname, smsemail, incomingemail ' . - 'FROM user JOIN subscription ' . - 'ON user.id = subscription.subscriber ' . - 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' . - 'AND user.smsemail IS NOT NULL ' . - 'AND user.smsnotify = 1 ' . + $user->query('SELECT nickname, smsemail, incomingemail ' . + 'FROM user JOIN subscription ' . + 'ON user.id = subscription.subscriber ' . + 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' . + 'AND user.smsemail IS NOT null ' . + 'AND user.smsnotify = 1 ' . 'AND subscription.sms = 1 '); - while ($user->fetch()) { - common_log(LOG_INFO, - 'Sending notice ' . $notice->id . ' to ' . $user->smsemail, - __FILE__); - $success = mail_send_sms_notice_address($notice, $user->smsemail, $user->incomingemail); - if (!$success) { - # XXX: Not sure, but I think that's the right thing to do - common_log(LOG_WARNING, - 'Sending notice ' . $notice->id . ' to ' . $user->smsemail . ' FAILED, cancelling.', - __FILE__); - return false; - } - } - - $user->free(); - unset($user); - - return true; + while ($user->fetch()) { + common_log(LOG_INFO, + 'Sending notice ' . $notice->id . ' to ' . $user->smsemail, + __FILE__); + $success = mail_send_sms_notice_address($notice, + $user->smsemail, + $user->incomingemail); + if (!$success) { + // XXX: Not sure, but I think that's the right thing to do + common_log(LOG_WARNING, + 'Sending notice ' . $notice->id . ' to ' . + $user->smsemail . ' FAILED, cancelling.', + __FILE__); + return false; + } + } + + $user->free(); + unset($user); + + return true; } -function mail_send_sms_notice($notice, $user) { - return mail_send_sms_notice_address($notice, $user->smsemail, $user->incomingemail); +/** + * send a notice to a user via SMS + * + * A convenience wrapper around mail_send_sms_notice_address() + * + * @param Notice $notice notice to send + * @param User $user user to receive notice + * + * @see mail_send_sms_notice_address() + * + * @return boolean success flag + */ + +function mail_send_sms_notice($notice, $user) +{ + return mail_send_sms_notice_address($notice, + $user->smsemail, + $user->incomingemail); } -function mail_send_sms_notice_address($notice, $smsemail, $incomingemail) { +/** + * send a notice to an SMS email address from a given address + * + * We use the user's incoming email address as the "From" address to make + * replying to notices easier. + * + * @param Notice $notice notice to send + * @param string $smsemail email address to send to + * @param string $incomingemail email address to set as 'from' + * + * @return boolean success flag + */ + +function mail_send_sms_notice_address($notice, $smsemail, $incomingemail) +{ + $to = $nickname . ' <' . $smsemail . '>'; - $to = $nickname . ' <' . $smsemail . '>'; - $other = $notice->getProfile(); + $other = $notice->getProfile(); - common_log(LOG_INFO, "Sending notice " . $notice->id . " to " . $smsemail, __FILE__); + common_log(LOG_INFO, 'Sending notice ' . $notice->id . + ' to ' . $smsemail, __FILE__); - $headers = array(); - $headers['From'] = (isset($incomingemail)) ? $incomingemail : mail_notify_from(); - $headers['To'] = $to; - $headers['Subject'] = sprintf(_('%s status'), - $other->getBestName()); - $body = $notice->content; + $headers = array(); - return mail_send($smsemail, $headers, $body); + $headers['From'] = ($incomingemail) ? $incomingemail : mail_notify_from(); + $headers['To'] = $to; + $headers['Subject'] = sprintf(_('%s status'), + $other->getBestName()); + + $body = $notice->content; + + return mail_send($smsemail, $headers, $body); } -function mail_confirm_sms($code, $nickname, $address) { +/** + * send a message to confirm a claim for an SMS number + * + * @param string $code confirmation code + * @param string $nickname nickname of user claiming number + * @param string $address email address to send the confirmation to + * + * @see common_confirmation_code() + * + * @return void + */ + +function mail_confirm_sms($code, $nickname, $address) +{ + $recipients = $address; - $recipients = $address; + $headers['From'] = mail_notify_from(); + $headers['To'] = $nickname . ' <' . $address . '>'; + $headers['Subject'] = _('SMS confirmation'); - $headers['From'] = mail_notify_from(); - $headers['To'] = $nickname . ' <' . $address . '>'; - $headers['Subject'] = _('SMS confirmation'); + // FIXME: I18N - $body = "$nickname: confirm you own this phone number with this code:"; - $body .= "\n\n"; - $body .= $code; - $body .= "\n\n"; + $body = "$nickname: confirm you own this phone number with this code:"; + $body .= "\n\n"; + $body .= $code; + $body .= "\n\n"; - mail_send($recipients, $headers, $body); + mail_send($recipients, $headers, $body); } -function mail_notify_nudge($from, $to) { +/** + * send a mail message to notify a user of a 'nudge' + * + * @param User $from user nudging + * @param User $to user being nudged + * + * @return boolean success flag + */ + +function mail_notify_nudge($from, $to) +{ common_init_locale($to->language); - $subject = sprintf(_('You\'ve been nudged by %s'), $from->nickname); - - $from_profile = $from->getProfile(); - - $body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to these days and is inviting you to post some news.\n\n". - "So let's hear from you :)\n\n". - "%3\$s\n\n". - "Don't reply to this email; it won't get to them.\n\n". - "With kind regards,\n". - "%4\$s\n"), - $from_profile->getBestName(), - $from->nickname, - common_local_url('all', array('nickname' => $to->nickname)), - common_config('site', 'name')); + $subject = sprintf(_('You\'ve been nudged by %s'), $from->nickname); + + $from_profile = $from->getProfile(); + + $body = sprintf(_("%1\$s (%2\$s) is wondering what you are up to ". + "these days and is inviting you to post some news.\n\n". + "So let's hear from you :)\n\n". + "%3\$s\n\n". + "Don't reply to this email; it won't get to them.\n\n". + "With kind regards,\n". + "%4\$s\n"), + $from_profile->getBestName(), + $from->nickname, + common_local_url('all', array('nickname' => $to->nickname)), + common_config('site', 'name')); common_init_locale(); - return mail_to_user($to, $subject, $body); + return mail_to_user($to, $subject, $body); } -function mail_notify_message($message, $from=NULL, $to=NULL) { +/** + * send a message to notify a user of a direct message (DM) + * + * This function checks to see if the recipient wants notification + * of DMs and has a configured email address. + * + * @param Message $message message to notify about + * @param User $from user sending message; default to sender + * @param User $to user receiving message; default to recipient + * + * @return boolean success code + */ - if (is_null($from)) { - $from = User::staticGet('id', $message->from_profile); - } +function mail_notify_message($message, $from=null, $to=null) +{ + if (is_null($from)) { + $from = User::staticGet('id', $message->from_profile); + } - if (is_null($to)) { - $to = User::staticGet('id', $message->to_profile); - } + if (is_null($to)) { + $to = User::staticGet('id', $message->to_profile); + } - if (is_null($to->email) || !$to->emailnotifymsg) { - return true; - } + if (is_null($to->email) || !$to->emailnotifymsg) { + return true; + } common_init_locale($to->language); - $subject = sprintf(_('New private message from %s'), $from->nickname); - - $from_profile = $from->getProfile(); - - $body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n". - "------------------------------------------------------\n". - "%3\$s\n". - "------------------------------------------------------\n\n". - "You can reply to their message here:\n\n". - "%4\$s\n\n". - "Don't reply to this email; it won't get to them.\n\n". - "With kind regards,\n". - "%5\$s\n"), - $from_profile->getBestName(), - $from->nickname, - $message->content, - common_local_url('newmessage', array('to' => $from->id)), - common_config('site', 'name')); + $subject = sprintf(_('New private message from %s'), $from->nickname); + + $from_profile = $from->getProfile(); + + $body = sprintf(_("%1\$s (%2\$s) sent you a private message:\n\n". + "------------------------------------------------------\n". + "%3\$s\n". + "------------------------------------------------------\n\n". + "You can reply to their message here:\n\n". + "%4\$s\n\n". + "Don't reply to this email; it won't get to them.\n\n". + "With kind regards,\n". + "%5\$s\n"), + $from_profile->getBestName(), + $from->nickname, + $message->content, + common_local_url('newmessage', array('to' => $from->id)), + common_config('site', 'name')); common_init_locale(); - return mail_to_user($to, $subject, $body); + return mail_to_user($to, $subject, $body); } -function mail_notify_fave($other, $user, $notice) { +/** + * notify a user that one of their notices has been chosen as a 'fave' + * + * Doesn't check that the user has an email address nor if they + * want to receive notification of faves. Maybe this happens higher + * up the stack...? + * + * @param User $other The user whose notice was faved + * @param User $user The user who faved the notice + * @param Notice $notice The notice that was faved + * + * @return void + */ + +function mail_notify_fave($other, $user, $notice) +{ + $profile = $user->getProfile(); + + $bestname = $profile->getBestName(); - $profile = $user->getProfile(); - $bestname = $profile->getBestName(); common_init_locale($other->language); - $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')); + + $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')); common_init_locale(); - mail_to_user($other, $subject, $body); + mail_to_user($other, $subject, $body); } diff --git a/lib/mailbox.php b/lib/mailbox.php index 4ed8d1758..8d5d44e49 100644 --- a/lib/mailbox.php +++ b/lib/mailbox.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * common superclass for direct messages inbox and outbox + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,158 +18,278 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Message + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/personal.php'); +require_once INSTALLDIR.'/lib/personal.php'; define('MESSAGES_PER_PAGE', 20); -class MailboxAction extends PersonalAction { - - function handle($args) { - - parent::handle($args); - - $nickname = common_canonical_nickname($this->arg('nickname')); - $user = User::staticGet('nickname', $nickname); - - if (!$user) { - $this->client_error(_('No such user.'), 404); - return; - } - - $cur = common_current_user(); - - if (!$cur || $cur->id != $user->id) { - $this->client_error(_('Only the user can read their own mailboxes.'), 403); - return; - } - - $profile = $user->getProfile(); - - if (!$profile) { - $this->server_error(_('User has no profile.')); - return; - } - - $page = $this->trimmed('page'); - - if (!$page) { - $page = 1; - } - - $this->show_page($user, $page); - } - - function get_title($user, $page) { - return ''; - } - - function get_instructions() { - return ''; - } - - function show_top() { - - $cur = common_current_user(); - - common_message_form(NULL, $cur, NULL); - - $this->views_menu(); - } - - function show_page($user, $page) { - - common_show_header($this->get_title($user, $page), - NULL, NULL, - array($this, 'show_top')); - - $this->show_box($user, $page); - - common_show_footer(); - } - - function show_box($user, $page) { - - $message = $this->get_messages($user, $page); - - if ($message) { - - $cnt = 0; - common_element_start('ul', array('id' => 'messages')); - - while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) { - $cnt++; - - if ($cnt > MESSAGES_PER_PAGE) { - break; - } - - $this->show_message($message); - } - - common_element_end('ul'); - - common_pagination($page > 1, $cnt > MESSAGES_PER_PAGE, - $page, $this->trimmed('action'), - array('nickname' => $user->nickname)); - - $message->free(); - unset($message); - } - } - - # returns the profile we want to show with the message - - function get_message_profile($message) { - return NULL; - } - - function show_message($message) { - - common_element_start('li', array('class' => 'message_single', - 'id' => 'message-' . $message->id)); - - $profile = $this->get_message_profile($message); - - $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')); - common_raw($message->rendered); - common_element_end('p'); - - $messageurl = common_local_url('showmessage', array('message' => $message->id)); - - # XXX: we need to figure this out better. Is this right? - if (strcmp($message->uri, $messageurl) != 0 && preg_match('/^http/', $message->uri)) { - $messageurl = $message->uri; - } - common_element_start('p', 'time'); - common_element('a', array('class' => 'permalink', - 'href' => $messageurl, - 'title' => common_exact_date($message->created)), - common_date_string($message->created)); - if ($message->source) { - common_text(_(' from ')); - $this->source_link($message->source); - } - - common_element_end('p'); - - common_element_end('li'); - } +/** + * common superclass for direct messages inbox and outbox + * + * @category Message + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see InboxAction + * @see OutboxAction + */ + +class MailboxAction extends PersonalAction +{ + var $page = null; + + function prepare($args) + { + parent::prepare($args); + + $nickname = common_canonical_nickname($this->arg('nickname')); + $this->user = User::staticGet('nickname', $nickname); + $this->page = $this->trimmed('page'); + + if (!$this->page) { + $this->page = 1; + } + + return true; + } + + /** + * output page based on arguments + * + * @param array $args HTTP arguments (from $_REQUEST) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if (!$this->user) { + $this->clientError(_('No such user.'), 404); + return; + } + + $cur = common_current_user(); + + if (!$cur || $cur->id != $this->user->id) { + $this->clientError(_('Only the user can read their own mailboxes.'), + 403); + return; + } + + $this->showPage(); + } + + function showLocalNav() + { + $nav = new PersonalGroupNav($this); + $nav->show(); + } + + function showNoticeForm() + { + $message_form = new MessageForm($this); + $message_form->show(); + } + + function showContent() + { + $message = $this->getMessages(); + + if ($message) { + $cnt = 0; + $this->elementStart('div', array('id' =>'notices_primary')); + $this->element('h2', null, _('Notices')); + $this->elementStart('ul', 'notices'); + + while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) { + $cnt++; + + if ($cnt > MESSAGES_PER_PAGE) { + break; + } + + $this->showMessage($message); + } + + $this->elementEnd('ul'); + + $this->pagination($this->page > 1, $cnt > MESSAGES_PER_PAGE, + $this->page, $this->trimmed('action'), + array('nickname' => $this->user->nickname)); + $this->elementEnd('div'); + $message->free(); + unset($message); + } + } + + function getMessages() + { + return null; + } + + /** + * returns the profile we want to show with the message + * + * For inboxes, we show the sender; for outboxes, the recipient. + * + * @param Message $message The message to get the profile for + * + * @return Profile The profile that matches the message + */ + + function getMessageProfile($message) + { + return null; + } + + /** + * show a single message in the list format + * + * XXX: This needs to be extracted out into a MessageList similar + * to NoticeList. + * + * @param Message $message the message to show + * + * @return void + */ + + function showMessage($message) + { + $this->elementStart('li', array('class' => 'hentry notice', + 'id' => 'message-' . $message->id)); + + $profile = $this->getMessageProfile($message); + + $this->elementStart('div', 'entry-title'); + $this->elementStart('span', 'vcard author'); + $this->elementStart('a', array('href' => $profile->profileurl, + 'class' => 'url')); + $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); + $this->element('img', array('src' => ($avatar) ? + common_avatar_display_url($avatar) : + common_default_avatar(AVATAR_STREAM_SIZE), + 'class' => 'photo avatar', + 'width' => AVATAR_STREAM_SIZE, + 'height' => AVATAR_STREAM_SIZE, + 'alt' => + ($profile->fullname) ? $profile->fullname : + $profile->nickname)); + $this->element('span', array('class' => 'nickname fn'), + $profile->nickname); + $this->elementEnd('a'); + $this->elementEnd('span'); + + // FIXME: URL, image, video, audio + $this->elementStart('p', array('class' => 'entry-content')); + $this->raw($message->rendered); + $this->elementEnd('p'); + $this->elementEnd('div'); + + $messageurl = common_local_url('showmessage', + array('message' => $message->id)); + + // XXX: we need to figure this out better. Is this right? + if (strcmp($message->uri, $messageurl) != 0 && + preg_match('/^http/', $message->uri)) { + $messageurl = $message->uri; + } + + $this->elementStart('div', 'entry-content'); + $this->elementStart('dl', 'timestamp'); + $this->element('dt', null, _('Published')); + $this->elementStart('dd', null); + $dt = common_date_iso8601($message->created); + $this->elementStart('a', array('rel' => 'bookmark', + 'href' => $messageurl)); + $this->element('abbr', array('class' => 'published', + 'title' => $dt), + common_date_string($message->created)); + $this->elementEnd('a'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + + if ($message->source) { + $this->elementStart('dl', 'device'); + $this->elementStart('dt'); + $this->text(_('From')); + $this->elementEnd('dt'); + $this->showSource($message->source); + $this->elementEnd('dl'); + } + $this->elementEnd('div'); + + $this->elementEnd('li'); + } + + /** + * Show the page notice + * + * Shows instructions for the page + * + * @return void + */ + + function showPageNotice() + { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + + /** + * Show the source of the message + * + * Returns either the name (and link) of the API client that posted the notice, + * or one of other other channels. + * + * @param string $source the source of the message + * + * @return void + */ + + function showSource($source) + { + $source_name = _($source); + switch ($source) { + case 'web': + case 'xmpp': + case 'mail': + case 'omb': + case 'api': + $this->element('dd', null, $source_name); + break; + default: + $ns = Notice_source::staticGet($source); + if ($ns) { + $this->elementStart('dd', null); + $this->element('a', array('href' => $ns->url, + 'rel' => 'external'), + $ns->name); + $this->elementEnd('dd'); + } else { + $this->element('dd', null, $source_name); + } + break; + } + return; + } + } diff --git a/lib/messageform.php b/lib/messageform.php new file mode 100644 index 000000000..61d3d75af --- /dev/null +++ b/lib/messageform.php @@ -0,0 +1,171 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for posting a direct message + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for posting a direct message + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class MessageForm extends Form +{ + /** + * User to send a direct message to + */ + + var $to = null; + + /** + * Pre-filled content of the form + */ + + var $content = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param User $to user to send a message to + * @param string $content content to pre-fill + */ + + function __construct($out=null, $to=null, $content=null) + { + parent::__construct($out); + + $this->to = $to; + $this->content = $content; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'form_notice'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('newmessage'); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Send a direct notice')); + } + + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $user = common_current_user(); + + $mutual_users = $user->mutuallySubscribedUsers(); + + $mutual = array(); + + while ($mutual_users->fetch()) { + if ($mutual_users->id != $user->id) { + $mutual[$mutual_users->id] = $mutual_users->nickname; + } + } + + $mutual_users->free(); + unset($mutual_users); + + $this->out->elementStart('ul', 'form_data'); + $this->out->elementStart('li', array('id' => 'notice_to')); + $this->out->dropdown('to', _('To'), $mutual, null, false, + $this->to->id); + $this->out->elementEnd('li'); + + $this->out->elementStart('li', array('id' => 'notice_text')); + $this->out->element('textarea', array('id' => 'notice_data-text', + 'cols' => 35, + 'rows' => 4, + 'name' => 'content'), + ($this->content) ? $this->content : ''); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->elementStart('ul', 'form_actions'); + $this->out->elementStart('li', array('id' => 'notice_submit')); + $this->out->element('input', array('id' => 'notice_action-submit', + 'class' => 'submit', + 'name' => 'message_send', + 'type' => 'submit', + 'value' => _('Send'))); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + } +} diff --git a/lib/microid.php b/lib/microid.php new file mode 100644 index 000000000..806b7ee7d --- /dev/null +++ b/lib/microid.php @@ -0,0 +1,97 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Microid class + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category ID + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * A class for microids + * + * @category ID + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see http://microid.org/ + */ + +class Microid +{ + /** Agent part of the ID. */ + + var $agent = null; + + /** Resource part of the ID. */ + + var $resource = null; + + /** + * Constructor + * + * @param string $agent Agent of the ID + * @param string $resource Resource part + */ + + function __construct($agent, $resource) + { + $this->agent = $agent; + $this->resource = $resource; + + } + + /** + * Generate a MicroID string + * + * @return string MicroID for agent and resource + */ + + function toString() + { + $agent_proto = $this->_getProto($this->agent); + $resource_proto = $this->_getProto($this->resource); + + return $agent_proto.'+'.$resource_proto.':sha1:'. + sha1(sha1($this->agent).sha1($this->resource)); + } + + /** + * Utility for getting the protocol part of a URI + * + * @param string $uri URI to parse + * + * @return string scheme part of the URI + */ + + function _getProto($uri) + { + $colon = strpos($uri, ':'); + return substr($uri, 0, $colon); + } +} diff --git a/lib/noticeform.php b/lib/noticeform.php new file mode 100644 index 000000000..0c991c969 --- /dev/null +++ b/lib/noticeform.php @@ -0,0 +1,181 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for posting a notice + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for posting a notice + * + * Frequently-used form for posting a notice + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class NoticeForm extends Form +{ + /** + * Current action, used for returning to this page. + */ + + var $action = null; + + /** + * Pre-filled content of the form + */ + + var $content = null; + + /** + * The current user + */ + + var $user = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param string $action action to return to, if any + * @param string $content content to pre-fill + */ + + function __construct($out=null, $action=null, $content=null, $user=null) + { + parent::__construct($out); + + $this->action = $action; + $this->content = $content; + + if ($user) { + $this->user = $user; + } else { + $this->user = common_current_user(); + } + + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'form_notice'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('newnotice'); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Send a notice')); + } + + + /** + * Data elements + * + * @return void + */ + + function formData() + { + + $this->out->elementStart('ul', 'form_data'); + $this->out->elementStart('li', array('id' => 'notice_text')); + $this->out->element('label', array('for' => 'notice_data-text'), + sprintf(_('What\'s up, %s?'), $this->user->nickname)); + // XXX: vary by defined max size + $this->out->element('textarea', array('id' => 'notice_data-text', + 'cols' => 35, + 'rows' => 4, + 'name' => 'status_textarea'), + ($this->content) ? $this->content : ''); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + + $this->out->elementStart('dl', 'form_note'); + $this->out->element('dt', null, _('Available characters')); + $this->out->element('dd', array('id' => 'notice_text-count'), + '140'); + $this->out->elementEnd('dl'); + + if ($this->action) { + $this->out->hidden('notice_return-to', $this->action, 'returnto'); + } + $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->elementStart('ul', 'form_actions'); + $this->out->elementStart('li', array('id' => 'notice_submit')); + $this->out->element('input', array('id' => 'notice_action-submit', + 'class' => 'submit', + 'name' => 'status_submit', + 'type' => 'submit', + 'value' => _('Send'))); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + } +} diff --git a/lib/noticelist.php b/lib/noticelist.php index 415c062e4..20bf3c9f1 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -1,163 +1,383 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * widget for displaying a list of notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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/>. + * + * @category UI + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/favorform.php'; +require_once INSTALLDIR.'/lib/disfavorform.php'; + +/** + * widget for displaying a list of notices + * + * There are a number of actions that display a list of notices, in + * reverse chronological order. This widget abstracts out most of the + * code for UI for notice lists. It's overridden to hide some + * data for e.g. the profile page. + * + * @category UI + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see Notice + * @see StreamAction + * @see NoticeListItem + * @see ProfileNoticeList */ -if (!defined('LACONICA')) { exit(1); } +class NoticeList extends Widget +{ + /** the current stream of notices being displayed. */ -class NoticeList { + var $notice = null; - var $notice = NULL; + /** + * constructor + * + * @param Notice $notice stream of notices from DB_DataObject + */ - function __construct($notice) { + function __construct($notice, $out=null) + { + parent::__construct($out); $this->notice = $notice; } - function show() { + /** + * show the list of notices + * + * "Uses up" the stream by looping through it. So, probably can't + * be called twice on the same list. + * + * @return int count of notices listed. + */ - common_element_start('ul', array('id' => 'notices')); + function show() + { + $this->out->elementStart('div', array('id' =>'notices_primary')); + $this->out->element('h2', null, _('Notices')); + $this->out->elementStart('ul', array('class' => 'notices')); - $cnt = 0; + $cnt = 0; - while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) { - $cnt++; + while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) { + $cnt++; - if ($cnt > NOTICES_PER_PAGE) { - break; - } + if ($cnt > NOTICES_PER_PAGE) { + break; + } - $item = $this->new_list_item($this->notice); + $item = $this->newListItem($this->notice); $item->show(); - } + } - common_element_end('ul'); + $this->out->elementEnd('ul'); + $this->out->elementEnd('div'); return $cnt; - } + } + + /** + * returns a new list item for the current notice + * + * Recipe (factory?) method; overridden by sub-classes to give + * a different list item class. + * + * @param Notice $notice the current notice + * + * @return NoticeListItem a list item for displaying the notice + */ - function new_list_item($notice) { - return new NoticeListItem($notice); + function newListItem($notice) + { + return new NoticeListItem($notice, $this->out); } } -class NoticeListItem { +/** + * widget for displaying a single notice + * + * This widget has the core smarts for showing a single notice: what to display, + * where, and under which circumstances. Its key method is show(); this is a recipe + * that calls all the other show*() methods to build up a single notice. The + * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip + * author info (since that's implicit by the data in the page). + * + * @category UI + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see NoticeList + * @see ProfileNoticeListItem + */ - var $notice = NULL; - var $profile = NULL; +class NoticeListItem extends Widget +{ + /** The notice this item will show. */ - function __construct($notice) { - $this->notice = $notice; - $this->profile = $notice->getProfile(); - } - - function show() { - $this->show_start(); - $this->show_fave_form(); - $this->show_author(); - $this->show_content(); - $this->show_start_time_section(); - $this->show_notice_link(); - $this->show_notice_source(); - $this->show_reply_to(); - $this->show_reply_link(); - $this->show_delete_link(); - $this->show_end_time_section(); - $this->show_end(); - } - - function show_start() { - # XXX: RDFa - common_element_start('li', array('class' => 'notice_single hentry', - 'id' => 'notice-' . $this->notice->id)); - } - - function show_fave_form() { + var $notice = null; + + /** The profile of the author of the notice, extracted once for convenience. */ + + var $profile = null; + + /** + * constructor + * + * Also initializes the profile attribute. + * + * @param Notice $notice The notice we'll display + */ + + function __construct($notice, $out=null) + { + parent::__construct($out); + $this->notice = $notice; + $this->profile = $notice->getProfile(); + } + + /** + * recipe function for displaying a single notice. + * + * This uses all the other methods to correctly display a notice. Override + * it or one of the others to fine-tune the output. + * + * @return void + */ + + function show() + { + $this->showStart(); + $this->showNotice(); + $this->showNoticeInfo(); + $this->showNoticeOptions(); + $this->showEnd(); + } + + function showNotice() + { + $this->out->elementStart('div', 'entry-title'); + $this->showAuthor(); + $this->showContent(); + $this->out->elementEnd('div'); + } + + function showNoticeInfo() + { + $this->out->elementStart('div', 'entry-content'); + $this->showNoticeLink(); + $this->showNoticeSource(); + $this->showReplyTo(); + $this->out->elementEnd('div'); + } + + function showNoticeOptions() + { + $this->out->elementStart('div', 'notice-options'); + $this->showFaveForm(); + $this->showReplyLink(); + $this->showDeleteLink(); + $this->out->elementEnd('div'); + } + + /** + * start a single notice. + * + * @return void + */ + + function showStart() + { + // XXX: RDFa + // TODO: add notice_type class e.g., notice_video, notice_image + $this->out->elementStart('li', array('class' => 'hentry notice', + 'id' => 'notice-' . $this->notice->id)); + } + + /** + * show the "favorite" form + * + * @return void + */ + + function showFaveForm() + { $user = common_current_user(); - if ($user) { - if ($user->hasFave($this->notice)) { - common_disfavor_form($this->notice); - } else { - common_favor_form($this->notice); - } - } - } - - function show_author() { - common_element_start('span', 'vcard author'); - $this->show_avatar(); - $this->show_nickname(); - common_element_end('span'); - } - - function show_avatar() { - $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 photo', - 'width' => AVATAR_STREAM_SIZE, - 'height' => AVATAR_STREAM_SIZE, - 'alt' => - ($this->profile->fullname) ? $this->profile->fullname : - $this->profile->nickname)); - common_element_end('a'); - } - - function show_nickname() { - common_element('a', array('href' => $this->profile->profileurl, - 'class' => 'nickname fn url'), - $this->profile->nickname); - } - - function show_content() { - # FIXME: URL, image, video, audio - common_element_start('p', array('class' => 'content entry-title')); - if ($this->notice->rendered) { - common_raw($this->notice->rendered); - } 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(common_render_content($this->notice->content, $this->notice)); - } - common_element_end('p'); - } - - function show_start_time_section() { - common_element_start('p', 'time'); - } - - function show_notice_link() { - $noticeurl = common_local_url('shownotice', array('notice' => $this->notice->id)); - # XXX: we need to figure this out better. Is this right? - if (strcmp($this->notice->uri, $noticeurl) != 0 && preg_match('/^http/', $this->notice->uri)) { - $noticeurl = $this->notice->uri; - } - common_element_start('a', array('class' => 'permalink', - 'rel' => 'bookmark', - 'href' => $noticeurl)); - common_element('abbr', array('class' => 'published', - 'title' => common_date_iso8601($this->notice->created)), - common_date_string($this->notice->created)); - common_element_end('a'); - } - - function show_notice_source() { - if ($this->notice->source) { - common_element('span', null, _(' from ')); + if ($user) { + if ($user->hasFave($this->notice)) { + $disfavor = new DisfavorForm($this->out, $this->notice); + $disfavor->show(); + } else { + $favor = new FavorForm($this->out, $this->notice); + $favor->show(); + } + } + } + + /** + * show the author of a notice + * + * By default, this shows the avatar and (linked) nickname of the author. + * + * @return void + */ + + function showAuthor() + { + $this->out->elementStart('span', 'vcard author'); + $this->out->elementStart('a', array('href' => $this->profile->profileurl, + 'class' => 'url')); + $this->showAvatar(); + $this->showNickname(); + $this->out->elementEnd('a'); + $this->out->elementEnd('span'); + } + + /** + * show the avatar of the notice's author + * + * This will use the default avatar if no avatar is assigned for the author. + * It makes a link to the author's profile. + * + * @return void + */ + + function showAvatar() + { + if ('shownotice' === $this->out->trimmed('action')) { + $avatar_size = AVATAR_PROFILE_SIZE; + } else { + $avatar_size = AVATAR_STREAM_SIZE; + } + $avatar = $this->profile->getAvatar($avatar_size); + + $this->out->element('img', array('src' => ($avatar) ? + common_avatar_display_url($avatar) : + common_default_avatar($avatar_size), + 'class' => 'avatar photo', + 'width' => $avatar_size, + 'height' => $avatar_size, + 'alt' => + ($this->profile->fullname) ? + $this->profile->fullname : + $this->profile->nickname)); + } + + /** + * show the nickname of the author + * + * Links to the author's profile page + * + * @return void + */ + + function showNickname() + { + $this->out->element('span', array('class' => 'nickname fn'), + $this->profile->nickname); + } + + /** + * show the content of the notice + * + * Shows the content of the notice. This is pre-rendered for efficiency + * at save time. Some very old notices might not be pre-rendered, so + * they're rendered on the spot. + * + * @return void + */ + + function showContent() + { + // FIXME: URL, image, video, audio + $this->out->elementStart('p', array('class' => 'entry-content')); + if ($this->notice->rendered) { + $this->out->raw($this->notice->rendered); + } else { + // XXX: may be some uncooked notices in the DB, + // we cook them right now. This should probably disappear in future + // versions (>> 0.4.x) + $this->out->raw(common_render_content($this->notice->content, $this->notice)); + } + $this->out->elementEnd('p'); + } + + /** + * show the link to the main page for the notice + * + * Displays a link to the page for a notice, with "relative" time. Tries to + * get remote notice URLs correct, but doesn't always succeed. + * + * @return void + */ + + function showNoticeLink() + { + $noticeurl = common_local_url('shownotice', + array('notice' => $this->notice->id)); + // XXX: we need to figure this out better. Is this right? + if (strcmp($this->notice->uri, $noticeurl) != 0 && + preg_match('/^http/', $this->notice->uri)) { + $noticeurl = $this->notice->uri; + } + $this->out->elementStart('dl', 'timestamp'); + $this->out->element('dt', null, _('Published')); + $this->out->elementStart('dd', null); + $this->out->elementStart('a', array('rel' => 'bookmark', + 'href' => $noticeurl)); + $dt = common_date_iso8601($this->notice->created); + $this->out->element('abbr', array('class' => 'published', + 'title' => $dt), + common_date_string($this->notice->created)); + $this->out->elementEnd('a'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + + /** + * Show the source of the notice + * + * Either the name (and link) of the API client that posted the notice, + * or one of other other channels. + * + * @return void + */ + + function showNoticeSource() + { + if ($this->notice->source) { + $this->out->elementStart('dl', 'device'); + $this->out->element('dt', null, _('From')); $source_name = _($this->notice->source); switch ($this->notice->source) { case 'web': @@ -165,60 +385,108 @@ class NoticeListItem { case 'mail': case 'omb': case 'api': - common_element('span', 'noticesource', $source_name); + $this->out->element('dd', null, $source_name); break; default: $ns = Notice_source::staticGet($this->notice->source); if ($ns) { - common_element('a', array('href' => $ns->url), - $ns->name); + $this->out->elementStart('dd', null); + $this->out->element('a', array('href' => $ns->url, + 'rel' => 'external'), + $ns->name); + $this->out->elementEnd('dd'); } else { - common_element('span', 'noticesource', $source_name); + $this->out->element('dd', null, $source_name); } break; } - } + $this->out->elementEnd('dl'); + } } - function show_reply_to() { - if ($this->notice->reply_to) { - $replyurl = common_local_url('shownotice', array('notice' => $this->notice->reply_to)); - common_text(' ('); - common_element('a', array('class' => 'inreplyto', - 'href' => $replyurl), - _('in reply to...')); - common_text(')'); - } + /** + * show link to notice this notice is a reply to + * + * If this notice is a reply, show a link to the notice it is replying to. The + * heavy lifting for figuring out replies happens at save time. + * + * @return void + */ + + function showReplyTo() + { + if ($this->notice->reply_to) { + $replyurl = common_local_url('shownotice', + array('notice' => $this->notice->reply_to)); + $this->out->elementStart('dl', 'response'); + $this->out->element('dt', null, _('To')); + $this->out->elementStart('dd'); + $this->out->element('a', array('href' => $replyurl, + 'rel' => 'in-reply-to'), + _('in reply to')); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } } - function show_reply_link() { - common_element_start('a', - array('href' => common_local_url('newnotice', - array('replyto' => $this->profile->nickname)), - 'onclick' => 'return doreply("'.$this->profile->nickname.'", '.$this->notice->id.');', - 'title' => _('reply'), - 'class' => 'replybutton')); - common_raw(' →'); - common_element_end('a'); + /** + * show a link to reply to the current notice + * + * Should either do the reply in the current notice form (if available), or + * link out to the notice-posting form. A little flakey, doesn't always work. + * + * @return void + */ + + function showReplyLink() + { + $reply_url = common_local_url('newnotice', + array('replyto' => $this->profile->nickname)); + + $this->out->elementStart('dl', 'notice_reply'); + $this->out->element('dt', null, _('Reply to this notice')); + $this->out->elementStart('dd'); + $this->out->elementStart('a', array('href' => $reply_url, + 'title' => _('Reply to this notice'))); + $this->out->text(_('Reply')); + $this->out->element('span', 'notice_id', $this->notice->id); + $this->out->elementEnd('a'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); } - function show_delete_link() { + /** + * if the user is the author, let them delete the notice + * + * @return void + */ + + function showDeleteLink() + { $user = common_current_user(); - if ($user && $this->notice->profile_id == $user->id) { - $deleteurl = common_local_url('deletenotice', array('notice' => $this->notice->id)); - common_element_start('a', array('class' => 'deletenotice', - 'href' => $deleteurl, - 'title' => _('delete'))); - common_raw(' ×'); - common_element_end('a'); - } + if ($user && $this->notice->profile_id == $user->id) { + $deleteurl = common_local_url('deletenotice', + array('notice' => $this->notice->id)); + $this->out->elementStart('dl', 'notice_delete'); + $this->out->element('dt', null, _('Delete this notice')); + $this->out->elementStart('dd'); + $this->out->element('a', array('href' => $deleteurl, + 'title' => _('Delete this notice')), _('Delete')); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } } - function show_end_time_section() { - common_element_end('p'); - } + /** + * finish the notice + * + * Close the last elements in the notice list item + * + * @return void + */ - function show_end() { - common_element_end('li'); + function showEnd() + { + $this->out->elementEnd('li'); } } diff --git a/lib/noticesection.php b/lib/noticesection.php new file mode 100644 index 000000000..7dfa0472d --- /dev/null +++ b/lib/noticesection.php @@ -0,0 +1,107 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections showing lists of notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('NOTICES_PER_SECTION', 6); + +/** + * Base class for sections showing lists of notices + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class NoticeSection extends Section +{ + function showContent() + { + $notices = $this->getNotices(); + + $cnt = 0; + + $this->out->elementStart('ul', 'notices'); + + while ($notices->fetch() && ++$cnt <= NOTICES_PER_SECTION) { + $this->showNotice($notices); + } + + $this->out->elementEnd('ul'); + + return ($cnt > NOTICES_PER_SECTION); + } + + function getNotices() + { + return null; + } + + function showNotice($notice) + { + $profile = $notice->getProfile(); + $this->out->elementStart('li', 'hentry notice'); + $this->out->elementStart('div', 'entry-title'); + $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); + $this->out->elementStart('span', 'vcard author'); + $this->out->elementStart('a', array('title' => ($profile->fullname) ? + $profile->fullname : + $profile->nickname, + 'href' => $profile->noticeurl, + 'class' => 'url')); + $this->out->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 photo', + 'alt' => ($profile->fullname) ? + $profile->fullname : + $profile->nickname)); + $this->out->element('span', 'fn nickname', $profile->nickname); + $this->out->elementEnd('a'); + $this->out->elementEnd('span'); + + $this->out->elementStart('p', 'entry-content'); + $this->out->raw($notice->rendered); + $this->out->elementEnd('p'); + if ($notice->value) { + $this->out->elementStart('p'); + $this->out->text($notice->value); + $this->out->elementEnd('p'); + } + $this->out->elementEnd('div'); + $this->out->elementEnd('li'); + } +} diff --git a/lib/nudgeform.php b/lib/nudgeform.php new file mode 100644 index 000000000..7380462a7 --- /dev/null +++ b/lib/nudgeform.php @@ -0,0 +1,130 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for nudging a user + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for nudging a user + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see DisfavorForm + */ + +class NudgeForm extends Form +{ + /** + * Profile of user to nudge + */ + + var $profile = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to nudge + */ + + function __construct($out=null, $profile=null) + { + parent::__construct($out); + + $this->profile = $profile; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'form_user_nudge'; + } + + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_user_nudge'; + } + + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('nudge', + array('nickname' => $this->profile->nickname)); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Nudge this user')); + } + + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Nudge'), 'submit', null, _('Send a nudge to this user')); + } +} diff --git a/lib/oauthstore.php b/lib/oauthstore.php index d7f9c9ff1..7ad3be20e 100644 --- a/lib/oauthstore.php +++ b/lib/oauthstore.php @@ -21,124 +21,132 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/omb.php'); -class LaconicaOAuthDataStore extends OAuthDataStore { +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/lib/omb.php b/lib/omb.php index 96736b4d4..f2dbef5ba 100644 --- a/lib/omb.php +++ b/lib/omb.php @@ -43,257 +43,271 @@ define('OAUTH_AUTH_HEADER', OAUTH_NAMESPACE.'parameters/auth-header'); 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; +function omb_oauth_consumer() +{ + 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; +function omb_oauth_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; +function omb_oauth_datastore() +{ + 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; +function omb_hmac_sha1() +{ + 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))); +function omb_get_services($xrd, $type) +{ + return $xrd->services(array(omb_service_filter($type))); } -function omb_service_filter($type) { - return create_function('$s', - 'return omb_match_service($s, \''.$type.'\');'); +function omb_service_filter($type) +{ + return create_function('$s', + 'return omb_match_service($s, \''.$type.'\');'); } -function omb_match_service($service, $type) { - return in_array($type, $service->getTypes()); +function omb_match_service($service, $type) +{ + 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]; +function omb_service_uri($service) +{ + 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); +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); } -function omb_broadcast_remote_subscribers($notice) { +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); +function omb_post_notice($notice, $remote_profile, $subscription) +{ + return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret); } -function omb_post_notice_keys($notice, $postnoticeurl, $tk, $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; - } - } - } - } - } +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; + } + } + } + } + } } -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(), +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(), 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/lib/openid.php b/lib/openid.php index 6e501c2b1..860573702 100644 --- a/lib/openid.php +++ b/lib/openid.php @@ -31,212 +31,247 @@ require_once('Auth/OpenID/MySQLStore.php'); define('OPENID_COOKIE_EXPIRY', round(365.25 * 24 * 60 * 60)); 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; +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; } -function oid_consumer() { - $store = oid_store(); - $consumer = new Auth_OpenID_Consumer($store); - return $consumer; +function oid_consumer() +{ + $store = oid_store(); + $consumer = new Auth_OpenID_Consumer($store); + return $consumer; } -function oid_clear_last() { - oid_set_last(''); +function oid_clear_last() +{ + oid_set_last(''); } -function oid_set_last($openid_url) { - common_set_cookie(OPENID_COOKIE_KEY, - $openid_url, - time() + OPENID_COOKIE_EXPIRY); +function oid_set_last($openid_url) +{ + 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; - } +function oid_get_last() +{ + $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) { +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; +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; } -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); +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); } -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('/&/', '&', $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(); - } - } +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('/&/', '&', $form_html); + + // Display an error if the form markup couldn't be generated; + // otherwise, render the HTML. + if (Auth_OpenID::isFailure($form_html)) { + common_server_error(sprintf(_('Could not create OpenID form: %s'), $form_html->message)); + } else { + $action = new AutosubmitAction(); // see below + $action->form_html = $form_html; + $action->form_id = $form_id; + $action->prepare(array('action' => 'autosubmit')); + $action->handle(array('action' => 'autosubmit')); + } + } } # 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.')); +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.')); } # update a user from sreg parameters -function oid_update_user(&$user, &$sreg) { +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; +class AutosubmitAction extends Action +{ + var $form_html = null; + var $form_id = null; + + function handle($args) + { + parent::handle($args); + $this->showPage(); + } + + function title() + { + return _('OpenID Auto-Submit'); + } + + function showContent() + { + $this->raw($this->form_html); + $this->element('script', null, + '$(document).ready(function() { ' . + ' $(\'#'. $this->form_id .'\').submit(); '. + '});'); + } } diff --git a/lib/personal.php b/lib/personal.php index 86433b486..900df0257 100644 --- a/lib/personal.php +++ b/lib/personal.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * User profile page + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,192 +18,44 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -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; +if (!defined('LACONICA')) { + exit(1); +} - case 'tagrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = $feed['version']." feed for this tag"; - $feed['textContent'] = "RSS"; - break; +/** + * Base class for user profile page + * + * @category Personal + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - case 'favoritedrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "Favorited ".$feed['version']." feed"; - $feed['textContent'] = "RSS"; - break; +class PersonalAction extends Action +{ - case 'foaf': - $feed_classname = "foaf"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "$nickname's FOAF file"; - $feed['textContent'] = "FOAF"; - break; + var $user = null; - case 'favoritesrss': - $feed_classname = "favorites"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "Feed for favorites of $nickname"; - $feed['textContent'] = "RSS"; - break; + function isReadOnly() + { + return true; + } - 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 handle($args) + { + parent::handle($args); + common_set_returnto($this->selfUrl()); + } - - 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/lib/personalgroupnav.php b/lib/personalgroupnav.php new file mode 100644 index 000000000..63e6138df --- /dev/null +++ b/lib/personalgroupnav.php @@ -0,0 +1,135 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for all actions (~views) + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Base class for all actions + * + * This is the base class for all actions in the package. An action is + * more or less a "view" in an MVC framework. + * + * Actions are responsible for extracting and validating parameters; using + * model classes to read and write to the database; and doing ouput. + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class PersonalGroupNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $user = null; + + // FIXME: we should probably pass this in + + $action = $this->action->trimmed('action'); + $nickname = $this->action->trimmed('nickname'); + + if ($nickname) { + $user = User::staticGet('nickname', $nickname); + $user_profile = $user->getProfile(); + } else { + $user_profile = false; + } + + $this->out->elementStart('ul', array('class' => 'nav')); + + $this->out->menuItem(common_local_url('all', array('nickname' => + $nickname)), + _('Personal'), + sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + $action == 'all', 'nav_timeline_personal'); + $this->out->menuItem(common_local_url('replies', array('nickname' => + $nickname)), + _('Replies'), + sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + $action == 'replies', 'nav_timeline_replies'); + $this->out->menuItem(common_local_url('showstream', array('nickname' => + $nickname)), + _('Profile'), + ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname, + $action == 'showstream', 'nav_profile'); + $this->out->menuItem(common_local_url('showfavorites', array('nickname' => + $nickname)), + _('Favorites'), + sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), + $action == 'showfavorites', 'nav_timeline_favorites'); + + $cur = common_current_user(); + + if ($cur && $cur->id == $user->id) { + + $this->out->menuItem(common_local_url('inbox', array('nickname' => + $nickname)), + _('Inbox'), + _('Your incoming messages'), + $action == 'inbox'); + $this->out->menuItem(common_local_url('outbox', array('nickname' => + $nickname)), + _('Outbox'), + _('Your sent messages'), + $action == 'outbox'); + } + + $this->out->elementEnd('ul'); + } +} diff --git a/lib/personaltagcloudsection.php b/lib/personaltagcloudsection.php new file mode 100644 index 000000000..0882822db --- /dev/null +++ b/lib/personaltagcloudsection.php @@ -0,0 +1,86 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Personal tag cloud section + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Personal tag cloud section + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class PersonalTagCloudSection extends TagCloudSection +{ + var $user = null; + + function __construct($out=null, $user=null) + { + parent::__construct($out); + $this->user = $user; + } + + function title() + { + return sprintf(_('Tags in %s\'s notices'), $this->user->nickname); + } + + function getTags() + { + $qry = 'SELECT notice_tag.tag, '. + 'sum(exp(-(now() - notice_tag.created)/%s)) as weight ' . + 'FROM notice_tag JOIN notice ' . + 'ON notice_tag.notice_id = notice.id ' . + 'WHERE notice.profile_id = %d ' . + 'GROUP BY notice_tag.tag ' . + 'ORDER BY weight DESC '; + + $limit = TAGS_PER_SECTION; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $tag = Memcached_DataObject::cachedQuery('Notice_tag', + sprintf($qry, + common_config('tag', 'dropoff'), + $this->user->id), + 3600); + return $tag; + } + +} diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php new file mode 100644 index 000000000..89daaa563 --- /dev/null +++ b/lib/popularnoticesection.php @@ -0,0 +1,83 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections showing lists of notices + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('NOTICES_PER_SECTION', 6); + +/** + * Base class for sections showing lists of notices + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class PopularNoticeSection extends NoticeSection +{ + function getNotices() + { + $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 = 0; + $limit = NOTICES_PER_SECTION + 1; + + if (common_config('db', 'type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $notice = Memcached_DataObject::cachedQuery('Notice', + sprintf($qry, common_config('popular', 'dropoff')), + 1200); + return $notice; + } + + function title() + { + return _('Popular notices'); + } + + function divId() + { + return 'popular_notices'; + } +} diff --git a/lib/profilelist.php b/lib/profilelist.php index 9079ea9d7..499d74f7b 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -1,10 +1,13 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Widget to show a list of profiles + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -16,154 +19,202 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; 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'); - } +/** + * Widget to show a list of profiles + * + * @category Public + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class ProfileList extends Widget +{ + /** Current profile, profile query. */ + var $profile = null; + /** Owner of this list */ + var $owner = null; + /** Action object using us. */ + var $action = null; + + function __construct($profile, $owner=null, $action=null) + { + parent::__construct($action); + + $this->profile = $profile; + $this->owner = $owner; + $this->action = $action; + } + + function show() + { + + $this->out->elementStart('ul', 'profiles'); + + $cnt = 0; + + while ($this->profile->fetch()) { + $cnt++; + if($cnt > PROFILES_PER_PAGE) { + break; + } + $this->showProfile(); + } + + $this->out->elementEnd('ul'); + + return $cnt; + } + + function showProfile() + { + $this->out->elementStart('li', array('class' => 'profile', + 'id' => 'profile-' . $this->profile->id)); + + $user = common_current_user(); + + $this->out->elementStart('div', 'entity_profile vcard'); + + $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE); + $this->out->elementStart('a', array('href' => $this->profile->profileurl, + 'class' => 'url')); + $this->out->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE), + 'class' => 'photo avatar', + 'width' => AVATAR_STREAM_SIZE, + 'height' => AVATAR_STREAM_SIZE, + 'alt' => + ($this->profile->fullname) ? $this->profile->fullname : + $this->profile->nickname)); + $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn nickname'; + $this->out->elementStart('span', $hasFN); + $this->out->raw($this->highlight($this->profile->nickname)); + $this->out->elementEnd('span'); + $this->out->elementEnd('a'); + + if ($this->profile->fullname) { + $this->out->elementStart('dl', 'entity_fn'); + $this->out->element('dt', null, 'Full name'); + $this->out->elementStart('dd'); + $this->out->elementStart('span', 'fn'); + $this->out->raw($this->highlight($this->profile->fullname)); + $this->out->elementEnd('span'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + if ($this->profile->location) { + $this->out->elementStart('dl', 'entity_location'); + $this->out->element('dt', null, _('Location')); + $this->out->elementStart('dd', 'location'); + $this->out->raw($this->highlight($this->profile->location)); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + if ($this->profile->homepage) { + $this->out->elementStart('dl', 'entity_url'); + $this->out->element('dt', null, _('URL')); + $this->out->elementStart('dd'); + $this->out->elementStart('a', array('href' => $this->profile->homepage, + 'class' => 'url')); + $this->out->raw($this->highlight($this->profile->homepage)); + $this->out->elementEnd('a'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + if ($this->profile->bio) { + $this->out->elementStart('dl', 'entity_note'); + $this->out->element('dt', null, _('Note')); + $this->out->elementStart('dd', 'note'); + $this->out->raw($this->highlight($this->profile->bio)); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } + + # 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); + + $this->out->elementStart('dl', 'entity_tags'); + $this->out->elementStart('dt'); + if ($user->id == $this->owner->id) { + $this->out->element('a', array('href' => common_local_url('tagother', + array('id' => $this->profile->id))), + _('Tags')); + } else { + $this->out->text(_('Tags')); + } + $this->out->elementEnd('dt'); + $this->out->elementStart('dd'); + if ($tags) { + $this->out->elementStart('ul', 'tags xoxo'); + foreach ($tags as $tag) { + $this->out->elementStart('li'); + $this->out->element('span', 'mark_hash', '#'); + $this->out->element('a', array('rel' => 'tag', + 'href' => common_local_url($this->action->trimmed('action'), + array('nickname' => $this->owner->nickname, + 'tag' => $tag))), + $tag); + $this->out->elementEnd('li'); + } + $this->out->elementEnd('ul'); + } else { + $this->out->text(_('(none)')); + } + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); + } if ($user && $user->id == $this->owner->id) { - $this->show_owner_controls($this->profile); + $this->showOwnerControls($this->profile); + } + + $this->out->elementEnd('div'); + + if ($user && $user->id != $this->profile->id) { + # XXX: special-case for user looking at own + # subscriptions page + if ($user->isSubscribed($this->profile)) { + $usf = new UnsubscribeForm($this->out, $this->profile); + $usf->show(); + } else { + $sf = new SubscribeForm($this->out, $this->profile); + $sf->show(); + } } - common_element_end('li'); - } + $this->out->elementEnd('li'); + } /* Override this in subclasses. */ - function show_owner_controls($profile) { + function showOwnerControls($profile) + { return; } - function highlight($text) { - return htmlspecialchars($text); - } -}
\ No newline at end of file + function highlight($text) + { + return htmlspecialchars($text); + } +} diff --git a/lib/profileminilist.php b/lib/profileminilist.php new file mode 100644 index 000000000..56b768419 --- /dev/null +++ b/lib/profileminilist.php @@ -0,0 +1,90 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Widget to show a list of profiles + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/profilelist.php'; + +define('PROFILES_PER_MINILIST', 80); + +/** + * Widget to show a list of profiles, good for sidebar + * + * @category Public + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class ProfileMiniList extends ProfileList +{ + function show() + { + $this->out->elementStart('ul', 'entities users xoxo'); + + $cnt = 0; + + while ($this->profile->fetch()) { + $cnt++; + if($cnt > PROFILES_PER_MINILIST) { + break; + } + $this->showProfile(); + } + + $this->out->elementEnd('ul'); + + return $cnt; + } + + function showProfile() + { + $this->out->elementStart('li', 'vcard'); + $this->out->elementStart('a', array('title' => ($this->profile->fullname) ? + $this->profile->fullname : + $this->profile->nickname, + 'href' => $this->profile->profileurl, + 'rel' => 'contact member', + 'class' => 'url')); + $avatar = $this->profile->getAvatar(AVATAR_MINI_SIZE); + $this->out->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 photo', + 'alt' => ($this->profile->fullname) ? + $this->profile->fullname : + $this->profile->nickname)); + $this->out->element('span', 'fn nickname', $this->profile->nickname); + $this->out->elementEnd('a'); + $this->out->elementEnd('li'); + } +} diff --git a/lib/profilesection.php b/lib/profilesection.php new file mode 100644 index 000000000..3642ae164 --- /dev/null +++ b/lib/profilesection.php @@ -0,0 +1,106 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections showing lists of people + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('PROFILES_PER_SECTION', 6); + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class ProfileSection extends Section +{ + function showContent() + { + $profiles = $this->getProfiles(); + + if (!$profiles) { + return false; + } + + $cnt = 0; + + $this->out->elementStart('table'); + $this->out->elementStart('tbody'); + while ($profiles->fetch() && ++$cnt <= PROFILES_PER_SECTION) { + $this->showProfile($profiles); + } + $this->out->elementEnd('tbody'); + $this->out->elementEnd('table'); + + return ($cnt > PROFILES_PER_SECTION); + } + + function getProfiles() + { + return null; + } + + function showProfile($profile) + { + $this->out->elementStart('tr'); + $this->out->elementStart('td'); + $this->out->elementStart('span', 'vcard'); + $this->out->elementStart('a', array('title' => ($profile->fullname) ? + $profile->fullname : + $profile->nickname, + 'href' => $profile->profileurl, + 'rel' => 'contact member', + 'class' => 'url')); + $avatar = $profile->getAvatar(AVATAR_MINI_SIZE); + $this->out->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 photo', + 'alt' => ($profile->fullname) ? + $profile->fullname : + $profile->nickname)); + $this->out->element('span', 'fn nickname', $profile->nickname); + $this->out->elementEnd('span'); + $this->out->elementEnd('a'); + $this->out->elementEnd('td'); + if ($profile->value) { + $this->out->element('td', 'value', $profile->value); + } + + $this->out->elementEnd('tr'); + } +} diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php new file mode 100644 index 000000000..d72475e20 --- /dev/null +++ b/lib/publicgroupnav.php @@ -0,0 +1,95 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Menu for public group of actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Menu for public group of actions + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class PublicGroupNav extends Widget +{ + var $action = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null) + { + parent::__construct($action); + $this->action = $action; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $action_name = $this->action->trimmed('action'); + + $this->action->elementStart('ul', array('class' => 'nav')); + + $this->out->menuItem(common_local_url('public'), _('Public'), + _('Public timeline'), $action_name == 'public', 'nav_timeline_public'); + + $this->out->menuItem(common_local_url('groups'), _('Groups'), + _('User groups'), $action_name == 'groups', 'nav_groups'); + + $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'), + _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags'); + + if (count(common_config('nickname', 'featured')) > 0) { + $this->out->menuItem(common_local_url('featured'), _('Featured'), + _('Featured users'), $action_name == 'featured', 'nav_featured'); + } + + $this->out->menuItem(common_local_url('favorited'), _('Popular'), + _("Popular notices"), $action_name == 'favorited', 'nav_timeline_favorited'); + + $this->action->elementEnd('ul'); + } +} diff --git a/lib/queuehandler.php b/lib/queuehandler.php index 23f295c45..9ce9e32b3 100644 --- a/lib/queuehandler.php +++ b/lib/queuehandler.php @@ -25,108 +25,122 @@ require_once(INSTALLDIR.'/lib/daemon.php'); require_once(INSTALLDIR.'/classes/Queue_item.php'); require_once(INSTALLDIR.'/classes/Notice.php'); -class QueueHandler extends Daemon { +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/lib/rssaction.php b/lib/rssaction.php index 777511506..f19c8e1c5 100644 --- a/lib/rssaction.php +++ b/lib/rssaction.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Base class for RSS 1.0 feed actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,175 +18,245 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Mail + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Earle Martin <earle@downlode.org> + * @copyright 2008-9 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ if (!defined('LACONICA')) { exit(1); } 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/', +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(); + var $limit = DEFAULT_RSS_LIMIT; + + /** + * Constructor + * + * Just wraps the Action constructor. + * + * @param string $output URI to output to, default = stdout + * @param boolean $indent Whether to indent output, default true + * + * @see Action::__construct + */ + + function __construct($output='php://output', $indent=true) + { + parent::__construct($output, $indent); + } + + /** + * Do we need to write to the database? + * + * @return boolean true + */ + + function isReadonly() + { + return true; + } + + /** + * Read arguments and initialize members + * + * @param array $args Arguments from $_REQUEST + * @return boolean success + */ + + function prepare($args) + { + parent::prepare($args); + $this->limit = (int) $this->trimmed('limit'); + if ($this->limit == 0) { + $this->limit = DEFAULT_RSS_LIMIT; + } + return true; + } + + /** + * Handle a request + * + * @param array $args Arguments from $_REQUEST + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + $this->showRss($this->limit); + } + + /** + * Get the notices to output in this stream + * + * @return array an array of Notice objects sorted in reverse chron + */ + + function getNotices() + { + return array(); + } + + /** + * Get a description of the channel + * + * Returns an array with the following + * @return array + */ + + function getChannel() + { + return array('url' => '', + 'title' => '', + 'link' => '', + 'description' => ''); + } + + function getImage() + { + return null; + } + + function showRss($limit=0) + { + $notices = $this->getNotices($limit); + + $this->initRss(); + $this->showChannel($notices); + $this->showImage(); + + foreach ($notices as $n) { + $this->showItem($n); + } + + $this->showCreators(); + $this->endRss(); + } + + function showChannel($notices) + { + + $channel = $this->getChannel(); + $image = $this->getImage(); + + $this->elementStart('channel', array('rdf:about' => $channel['url'])); + $this->element('title', null, $channel['title']); + $this->element('link', null, $channel['link']); + $this->element('description', null, $channel['description']); + $this->element('cc:licence', array('rdf:resource' => common_config('license','url'))); + + if ($image) { + $this->element('image', array('rdf:resource' => $image)); + } + + $this->elementStart('items'); + $this->elementStart('rdf:Seq'); + + foreach ($notices as $notice) { + $this->element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri)); + } + + $this->elementEnd('rdf:Seq'); + $this->elementEnd('items'); + + $this->elementEnd('channel'); + } + + function showImage() + { + $image = $this->getImage(); + if ($image) { + $channel = $this->getChannel(); + 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 showItem($notice) + { + $profile = Profile::staticGet($notice->profile_id); + $nurl = common_local_url('shownotice', array('notice' => $notice->id)); + $creator_uri = common_profile_uri($profile); + $this->elementStart('item', array('rdf:about' => $notice->uri)); + $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); + $this->element('title', null, $title); + $this->element('link', null, $nurl); + $this->element('description', null, $profile->nickname."'s status on ".common_exact_date($notice->created)); + $this->element('dc:date', null, common_date_w3dtf($notice->created)); + $this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname); + $this->element('sioc:has_creator', array('rdf:resource' => $creator_uri)); + $this->element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile))); + $this->element('cc:licence', array('rdf:resource' => common_config('license', 'url'))); + $this->elementEnd('item'); + $this->creators[$creator_uri] = $profile; + } + + function showCreators() + { + foreach ($this->creators as $uri => $profile) { + $id = $profile->id; + $nickname = $profile->nickname; + $this->elementStart('sioc:User', array('rdf:about' => $uri)); + $this->element('foaf:nick', null, $nickname); + if ($profile->fullname) { + $this->element('foaf:name', null, $profile->fullname); + } + $this->element('sioc:id', null, $id); + $avatar = common_profile_avatar_url($profile); + $this->element('sioc:avatar', array('rdf:resource' => $avatar)); + $this->elementEnd('sioc:User'); + } + } + + function initRss() + { + $channel = $this->getChannel(); + header('Content-Type: application/rdf+xml'); + + $this->startXml(); + $this->elementStart('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/')); + $this->elementStart('sioc:Site', array('rdf:about' => common_root_url())); + $this->element('sioc:name', null, common_config('site', 'name')); + $this->elementStart('sioc:container_of'); + $this->element('sioc:Container', array('rdf:about' => + $channel['url'])); + $this->elementEnd('sioc:container_of'); + $this->elementEnd('sioc:Site'); + } + + function endRss() + { + $this->elementEnd('rdf:RDF'); + } } + diff --git a/lib/search_engines.php b/lib/search_engines.php index 7fcc1ffcb..559107910 100644 --- a/lib/search_engines.php +++ b/lib/search_engines.php @@ -19,33 +19,40 @@ if (!defined('LACONICA')) { exit(1); } -class SearchEngine { +class SearchEngine +{ protected $target; protected $table; - function __construct($target, $table) { + function __construct($target, $table) + { $this->target = $target; $this->table = $table; } - function query($q) { + function query($q) + { } - function limit($offset, $count, $rss = false) { + function limit($offset, $count, $rss = false) + { return $this->target->limit($offset, $count); } - function set_sort_mode($mode) { + function set_sort_mode($mode) + { if ('chron' === $mode) return $this->target->orderBy('created desc'); } } -class SphinxSearch extends SearchEngine { +class SphinxSearch extends SearchEngine +{ private $sphinx; private $connected; - function __construct($target, $table) { + function __construct($target, $table) + { $fp = @fsockopen(common_config('sphinx', 'server'), common_config('sphinx', 'port')); if (!$fp) { $this->connected = false; @@ -58,11 +65,13 @@ class SphinxSearch extends SearchEngine { $this->connected = true; } - function is_connected() { + function is_connected() + { return $this->connected; } - function limit($offset, $count, $rss = false) { + function limit($offset, $count, $rss = false) + { //FIXME without LARGEST_POSSIBLE, the most recent results aren't returned // this probably has a large impact on performance $LARGEST_POSSIBLE = 1e6; @@ -78,7 +87,8 @@ class SphinxSearch extends SearchEngine { return $this->target->limit(0, $count); } - function query($q) { + function query($q) + { $result = $this->sphinx->query($q, $this->table); if (!isset($result['matches'])) return false; $id_set = join(', ', array_keys($result['matches'])); @@ -86,7 +96,8 @@ class SphinxSearch extends SearchEngine { return true; } - function set_sort_mode($mode) { + function set_sort_mode($mode) + { if ('chron' === $mode) { $this->sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'created_ts'); return $this->target->orderBy('created desc'); @@ -94,19 +105,23 @@ class SphinxSearch extends SearchEngine { } } -class MySQLSearch extends SearchEngine { - function query($q) { +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).'\')'); } } -class PGSearch extends SearchEngine { - function query($q) { +class PGSearch extends SearchEngine +{ + function query($q) + { if ('identica_people' === $this->table) return $this->target->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')'); if ('identica_notices' === $this->table) diff --git a/lib/searchaction.php b/lib/searchaction.php index f99883b25..70e63146a 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -1,5 +1,16 @@ <?php -/* +/** + * Base search action class. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * * Laconica - a distributed open-source microblogging tool * Copyright (C) 2008, Controlez-Vous, Inc. * @@ -17,94 +28,107 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/searchgroupnav.php'; -class SearchAction extends Action { +/** + * Base search action class. + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Robin Millette <millette@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class SearchAction extends Action +{ + /** + * Return true if read only. + * + * @return boolean true + */ + function isReadOnly() + { + return true; + } - function is_readonly() { - return true; - } + function handle($args) + { + parent::handle($args); + $this->showPage(); + } - function handle($args) { - parent::handle($args); - $this->show_form(); - } + /** + * Show tabset for this page + * + * Uses the SearchGroupNav widget + * + * @return void + * @see SearchGroupNav + */ - 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 showLocalNav() + { + $nav = new SearchGroupNav($this, $this->trimmed('q')); + $nav->show(); + } - function get_title() { - return NULL; - } + function showTop($arr=null) + { + if ($arr) { + $error = $arr[1]; + } + if ($error) { + $this->element('p', 'error', $error); + } else { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + } - function show_header($arr) { - return; - } + function title() + { + return null; + } - function show_form($error=NULL) { - global $config; + function showNoticeForm() { + // remote post notice form + } - $q = $this->trimmed('q'); - $page = $this->trimmed('page', 1); + function showContent() { + $this->showTop(); + $this->showForm(); + } - 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'))); + function showForm($error=null) + { + global $config; - common_element_end('p'); - common_element_end('form'); - if ($q) { - $this->show_results($q, $page); - } - common_show_footer(); - } + $q = $this->trimmed('q'); + $page = $this->trimmed('page', 1); + $this->elementStart('form', array('method' => 'get', + 'id' => 'login', + 'action' => common_local_url($this->trimmed('action')))); + $this->elementStart('p'); + if (!isset($config['site']['fancy']) || !$config['site']['fancy']) { + $this->hidden('action', $this->trimmed('action')); + } + $this->input('q', '', $q); + $this->text(' '); + $this->submit('search', 'Search'); - 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); - } + $this->elementEnd('p'); + $this->elementEnd('form'); + if ($q) { + $this->showResults($q, $page); + } + } } + diff --git a/lib/searchgroupnav.php b/lib/searchgroupnav.php new file mode 100644 index 000000000..4ea226692 --- /dev/null +++ b/lib/searchgroupnav.php @@ -0,0 +1,87 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Menu for search actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Menu + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Menu for public group of actions + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class SearchGroupNav extends Widget +{ + var $action = null; + var $q = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null, $q = null) + { + parent::__construct($action); + $this->action = $action; + $this->q = $q; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $action_name = $this->action->trimmed('action'); + $this->action->elementStart('ul', array('class' => 'nav')); + $args = array(); + if ($this->q) { + $args['q'] = $this->q; + } + $this->out->menuItem(common_local_url('peoplesearch', $args), _('People'), + _('Find people on this site'), $action_name == 'peoplesearch', 'nav_search_people'); + $this->out->menuItem(common_local_url('noticesearch', $args), _('Notice'), + _('Find content of notices'), $action_name == 'noticesearch', 'nav_search_notice'); + $this->action->elementEnd('ul'); + } +} + diff --git a/lib/section.php b/lib/section.php new file mode 100644 index 000000000..0c32ddcf8 --- /dev/null +++ b/lib/section.php @@ -0,0 +1,108 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections (sidebar widgets) + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class Section extends Widget +{ + /** + * Show the form + * + * Uses a recipe to output the form. + * + * @return void + * @see Widget::show() + */ + + function show() + { + $this->out->elementStart('div', + array('id' => $this->divId(), + 'class' => 'section')); + + $this->out->element('h2', null, + $this->title()); + + $have_more = $this->showContent(); + + if ($have_more) { + $this->out->elementStart('p'); + $this->out->element('a', array('href' => $this->moreUrl(), + 'class' => 'more'), + $this->moreTitle()); + $this->out->elementEnd('p'); + } + + $this->out->elementEnd('div'); + } + + function divId() + { + return 'generic_section'; + } + + function title() + { + return _('Untitled section'); + } + + function showContent() + { + $this->out->element('p', null, + _('(None)')); + return false; + } + + function moreUrl() + { + return null; + } + + function moreTitle() + { + return null; + } +} diff --git a/lib/servererroraction.php b/lib/servererroraction.php new file mode 100644 index 000000000..a39886591 --- /dev/null +++ b/lib/servererroraction.php @@ -0,0 +1,92 @@ +<?php + +/** + * Server error action. + * + * PHP version 5 + * + * @category Action + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + * + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/error.php'; + +/** + * Class for displaying HTTP server errors + * + * Note: The older util.php class simply printed a string, but the spec + * says that 500 errors should be treated similarly to 400 errors, and + * it's easier to give an HTML response. Maybe we can customize these + * to display some funny animal cartoons. If not, we can probably role + * these classes up into a single class. + * + * See: http://tools.ietf.org/html/rfc2616#section-10 + * + * @category Action + * @package Laconica + * @author Zach Copley <zach@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://laconi.ca/ + */ +class ServerErrorAction extends ErrorAction +{ + function __construct($message='Error', $code=500) + { + parent::__construct($message, $code); + + $this->status = array(500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported'); + + $this->default = 500; + } + + // XXX: Should these error actions even be invokable via URI? + + function handle($args) + { + parent::handle($args); + + $this->code = $this->trimmed('code'); + + if (!$this->code || $code < 500 || $code > 599) { + $this->code = $this->default; + } + + $this->message = $this->trimmed('message'); + + if (!$this->message) { + $this->message = "Server Error $this->code"; + } + + $this->showPage(); + } + +} diff --git a/lib/settingsaction.php b/lib/settingsaction.php index 9e783431f..dfe1f114b 100644 --- a/lib/settingsaction.php +++ b/lib/settingsaction.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Base class for settings actions + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,105 +18,133 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Base class for settings group of actions + * + * @category Settings + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Widget + */ + +class SettingsAction extends Action +{ + /** + * A message for the user. + */ + + var $msg = null; + + /** + * Whether the message is a good one or a bad one. + */ -class SettingsAction extends Action { + var $success = false; - function handle($args) { + /** + * Handle input and output a page + * + * @param array $args $_REQUEST arguments + * + * @return void + */ + + function handle($args) + { parent::handle($args); if (!common_logged_in()) { - common_user_error(_('Not logged in.')); + $this->clientError(_('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 - common_set_returnto($this->self_url()); + // 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->selfUrl()); common_redirect(common_local_url('login')); } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { - $this->handle_post(); + $this->handlePost(); } else { - $this->show_form(); + $this->showForm(); } } - # override! - function handle_post() { + /** + * Handle a POST request + * + * @return boolean success flag + */ + + function handlePost() + { return false; } - function show_form($msg=NULL, $success=false) { - return false; + /** + * show the settings form + * + * @param string $msg an extra message for the user + * @param string $success good message or bad message? + * + * @return void + */ + + function showForm($msg=null, $success=false) + { + $this->msg = $msg; + $this->success = $success; + + $this->showPage(); } - function message($msg, $success) { - if ($msg) { - common_element('div', ($success) ? 'success' : 'error', - $msg); + /** + * show human-readable instructions for the page + * + * @return void + */ + + function showPageNotice() + { + if ($this->msg) { + $this->element('div', ($this->success) ? 'success' : 'error', + $this->msg); + } else { + $inst = $this->getInstructions(); + $output = common_markup_to_html($inst); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); } } - 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 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'))); - - $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; - } - common_menu_item(common_local_url($menuaction), - $menudesc[0], - $menudesc[1], - $action == $menuaction); - } - common_element_end('ul'); + /** + * instructions recipe for sub-classes + * + * Subclasses should override this to return readable instructions. They'll + * be processed by common_markup_to_html(). + * + * @return string instructions text + */ + + function getInstructions() + { + return ''; } + } diff --git a/lib/stream.php b/lib/stream.php index 27ab78137..0cb9e0bf4 100644 --- a/lib/stream.php +++ b/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); } @@ -22,33 +22,10 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/personal.php'); require_once(INSTALLDIR.'/lib/noticelist.php'); -class StreamAction extends PersonalAction { - - function public_views_menu() { - - $action = $this->trimmed('action'); - - 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('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'); - } - - common_menu_item(common_local_url('favorited'), _('Popular'), - _("Popular notices"), $action == 'favorited'); - - common_element_end('ul'); - - } - - function show_notice_list($notice) { +class StreamAction extends PersonalAction +{ + function show_notice_list($notice) + { $nl = new NoticeList($notice); return $nl->show(); } diff --git a/lib/subgroupnav.php b/lib/subgroupnav.php new file mode 100644 index 000000000..5fd8a72a2 --- /dev/null +++ b/lib/subgroupnav.php @@ -0,0 +1,111 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Local navigation for subscriptions group of pages + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Subs + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Local nav menu for subscriptions, subscribers + * + * @category Subs + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class SubGroupNav extends Widget +{ + var $action = null; + var $user = null; + + /** + * Construction + * + * @param Action $action current action, used for output + */ + + function __construct($action=null, $user=null) + { + parent::__construct($action); + $this->action = $action; + $this->user = $user; + } + + /** + * Show the menu + * + * @return void + */ + + function show() + { + $cur = common_current_user(); + $action = $this->action->trimmed('action'); + + $this->out->elementStart('ul', array('class' => 'nav')); + + $this->out->menuItem(common_local_url('subscriptions', + array('nickname' => + $this->user->nickname)), + _('Subscriptions'), + sprintf(_('People %s subscribes to'), + $this->user->nickname), + $action == 'subscriptions', + 'nav_subscriptions'); + $this->out->menuItem(common_local_url('subscribers', + array('nickname' => + $this->user->nickname)), + _('Subscribers'), + sprintf(_('People subscribed to %s'), + $this->user->nickname), + $action == 'subscribers', + 'nav_subscribers'); + $this->out->menuItem(common_local_url('usergroups', + array('nickname' => + $this->user->nickname)), + _('Groups'), + sprintf(_('Groups %s is a member of'), + $this->user->nickname), + $action == 'usergroups', + 'nav_usergroups'); + if ($this->user->id == $cur->id) { + $this->out->menuItem(common_local_url('invite'), + _('Invite'), + sprintf(_('Invite friends and colleagues to join you on %s'), + common_config('site', 'name')), + $action == 'invite', + 'nav_invite'); + } + $this->out->elementEnd('ul'); + } +} diff --git a/lib/subs.php b/lib/subs.php index 483b2f78e..0e7b9ded5 100644 --- a/lib/subs.php +++ b/lib/subs.php @@ -25,15 +25,16 @@ require_once('XMPPHP/XMPP.php'); Returns true or an error message. */ -function subs_subscribe_user($user, $other_nickname) { +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. @@ -41,90 +42,96 @@ function subs_subscribe_user($user, $other_nickname) { * Because the other way is quite a bit more complicated. */ -function subs_subscribe_to($user, $other) { +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); - $cache = common_memcache(); + $cache = common_memcache(); if ($cache) { $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 ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) { + if (!$other->subscribeTo($user)) { + return _('Could not subscribe other to you.'); + } $cache = common_memcache(); if ($cache) { $cache->delete(common_cache_key('user:notices_with_friends:' . $other->id)); } - subs_notify($user, $other); - } + subs_notify($user, $other); + } - return true; + 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); +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); } -function subs_notify_email($listenee, $listener) { - mail_subscribe_notify($listenee, $listener); +function subs_notify_email($listenee, $listener) +{ + mail_subscribe_notify($listenee, $listener); } /* Unsubscribe $user from nickname $other_nickname Returns true or an error message. */ -function subs_unsubscribe_user($user, $other_nickname) { +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 * NB: other can be a remote user. */ -function subs_unsubscribe_to($user, $other) { +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.'); $cache = common_memcache(); @@ -132,6 +139,6 @@ function subs_unsubscribe_to($user, $other) { $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); } - return true; + return true; } diff --git a/lib/subscribeform.php b/lib/subscribeform.php new file mode 100644 index 000000000..c65134e46 --- /dev/null +++ b/lib/subscribeform.php @@ -0,0 +1,141 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for subscribing to a user + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for subscribing to a user + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see UnsubscribeForm + */ + +class SubscribeForm extends Form +{ + /** + * Profile of user to subscribe to + */ + + var $profile = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to subscribe to + */ + + function __construct($out=null, $profile=null) + { + parent::__construct($out); + + $this->profile = $profile; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'subscribe-' . $this->profile->id; + } + + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_user_subscribe'; + } + + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('subscribe'); + } + + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Subscribe to this user')); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->hidden('subscribeto-' . $this->profile->id, + $this->profile->id, + 'subscribeto'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Subscribe'), 'submit', null, _('Subscribe to this user')); + } +} diff --git a/lib/tagcloudsection.php b/lib/tagcloudsection.php new file mode 100644 index 000000000..ff2aca6d6 --- /dev/null +++ b/lib/tagcloudsection.php @@ -0,0 +1,124 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections showing tag clouds + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('TAGS_PER_SECTION', 20); + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class TagCloudSection extends Section +{ + function showContent() + { + $tags = $this->getTags(); + + if (!$tags) { + $this->out->element('p', null, _('None')); + return false; + } + + $cnt = 0; + + $tw = array(); + $sum = 0; + + while ($tags->fetch() && ++$cnt <= TAGS_PER_SECTION) { + $tw[$tags->tag] = $tags->weight; + $sum += $tags->weight; + } + + if ($cnt == 0) { + $this->out->element('p', null, _('(None)')); + return false; + } + + ksort($tw); + + $this->out->elementStart('ul', 'tags xoxo tag-cloud'); + foreach ($tw as $tag => $weight) { + $this->showTag($tag, $weight, ($sum == 0) ? 0 : $weight/$sum); + } + $this->out->elementEnd('ul'); + + return ($cnt > TAGS_PER_SECTION); + } + + function getTags() + { + return null; + } + + function showTag($tag, $weight, $relative) + { + if ($relative > 0.1) { + $rel = 'tag-cloud-7'; + } else if ($relative > 0.05) { + $rel = 'tag-cloud-6'; + } else if ($relative > 0.02) { + $rel = 'tag-cloud-5'; + } else if ($relative > 0.01) { + $rel = 'tag-cloud-4'; + } else if ($relative > 0.005) { + $rel = 'tag-cloud-3'; + } else if ($relative > 0.002) { + $rel = 'tag-cloud-2'; + } else { + $rel = 'tag-cloud-1'; + } + + $this->out->elementStart('li', $rel); + $this->out->element('a', array('href' => $this->tagUrl($tag)), + $tag); + $this->out->elementEnd('li'); + } + + function tagUrl($tag) + { + return common_local_url('tag', array('tag' => $tag)); + } + + function divId() + { + return 'tagcloud'; + } +} diff --git a/lib/theme.php b/lib/theme.php index 80982aa82..95030affe 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -1,9 +1,12 @@ <?php -/* - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2008, Controlez-Vous, Inc. +/** + * Laconica, the distributed open-source microblogging tool * - * This program is free software: you can redistribute it and/or modify + * Utilities for theme files and paths + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -15,21 +18,55 @@ * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Paths + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Gets the full path of a file in a theme dir based on its relative name + * + * @param string $relative relative path within the theme directory + * @param string $theme name of the theme; defaults to current theme + * + * @return string File path to the theme file + */ -function theme_file($relative) { - $theme = common_config('site', 'theme'); - return INSTALLDIR.'/theme/'.$theme.'/'.$relative; +function theme_file($relative, $theme=null) +{ + if (!$theme) { + $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); - } +/** + * Gets the full URL of a file in a theme dir based on its relative name + * + * @param string $relative relative path within the theme directory + * @param string $theme name of the theme; defaults to current theme + * + * @return string URL of the file + */ + +function theme_path($relative, $theme=null) +{ + if (!$theme) { + $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/lib/topposterssection.php b/lib/topposterssection.php new file mode 100644 index 000000000..4bd59ac79 --- /dev/null +++ b/lib/topposterssection.php @@ -0,0 +1,81 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for sections showing lists of people + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Base class for sections + * + * These are the widgets that show interesting data about a person + * group, or site. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +class TopPostersSection extends ProfileSection +{ + function getProfiles() + { + $qry = 'SELECT profile.*, count(*) as value ' . + 'FROM profile JOIN notice ON profile.id = notice.profile_id ' . + (common_config('public', 'localonly') ? 'WHERE is_local = 1 ' : '') . + 'GROUP BY profile.id ' . + 'ORDER BY value DESC '; + + $limit = PROFILES_PER_SECTION; + $offset = 0; + + if (common_config('db','type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $profile = Memcached_DataObject::cachedQuery('Profile', + $qry, + 6 * 3600); + return $profile; + } + + function title() + { + return _('Top posters'); + } + + function divId() + { + return 'top_posters'; + } +} diff --git a/lib/twitter.php b/lib/twitter.php index 7f75a1afd..5eb15005a 100644 --- a/lib/twitter.php +++ b/lib/twitter.php @@ -19,184 +19,190 @@ 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, +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, - # Twitter is strict about accepting invalid "Expect" headers CURLOPT_HTTPHEADER => array('Expect:') - ); + ); - $ch = curl_init($uri); + $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) { +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) { +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) { +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) { +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) { +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) { +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/lib/twitterapi.php b/lib/twitterapi.php index 2083e8961..3d2c74feb 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -19,565 +19,675 @@ if (!defined('LACONICA')) { exit(1); } -class TwitterapiAction extends Action { +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; - } - -}
\ No newline at end of file + $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'); + } + + } + +} diff --git a/lib/unblockform.php b/lib/unblockform.php new file mode 100644 index 000000000..6a8831b29 --- /dev/null +++ b/lib/unblockform.php @@ -0,0 +1,152 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for unblocking a user + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for unblocking a user + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see BlockForm + */ + +class UnblockForm extends Form +{ + /** + * Profile of user to unblock + */ + + var $profile = null; + + /** + * Return-to args + */ + + var $args = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to unblock + * @param array $args return-to args + */ + + function __construct($out=null, $profile=null, $args=null) + { + parent::__construct($out); + + $this->profile = $profile; + $this->args = $args; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'unblock-' . $this->profile->id; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_user_unblock'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('unblock'); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Unblock this user')); + } + + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->hidden('unblockto-' . $this->profile->id, + $this->profile->id, + 'unblockto'); + if ($this->args) { + foreach ($this->args as $k => $v) { + $this->out->hidden('returnto-' . $k, $v); + } + } + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Unblock'), 'submit', null, _('Unblock this user')); + } +} diff --git a/lib/unsubscribeform.php b/lib/unsubscribeform.php new file mode 100644 index 000000000..ce91a1340 --- /dev/null +++ b/lib/unsubscribeform.php @@ -0,0 +1,139 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Form for unsubscribing from a user + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for unsubscribing from a user + * + * @category Form + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see SubscribeForm + */ + +class UnsubscribeForm extends Form +{ + /** + * Profile of user to unsubscribe from + */ + + var $profile = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Profile $profile profile of user to unsub from + */ + + function __construct($out=null, $profile=null) + { + parent::__construct($out); + + $this->profile = $profile; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'unsubscribe-' . $this->profile->id; + } + + + /** + * class of the form + * + * @return string of the form class + */ + + function formClass() + { + return 'form_user_unsubscribe'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('unsubscribe'); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Unsubscribe from this user')); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->hidden('unsubscribeto-' . $this->profile->id, + $this->profile->id, + 'unsubscribeto'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Unsubscribe'), 'submit', null, _('Unsubscribe from this user')); + } +} diff --git a/lib/util.php b/lib/util.php index fc45311fc..03d6b6199 100644 --- a/lib/util.php +++ b/lib/util.php @@ -17,647 +17,237 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* XXX: break up into separate modules (HTTP, HTML, user, files) */ - -# Show a server error - -function common_server_error($msg, $code=500) { - static $status = array(500 => 'Internal Server Error', - 501 => 'Not Implemented', - 502 => 'Bad Gateway', - 503 => 'Service Unavailable', - 504 => 'Gateway Timeout', - 505 => 'HTTP Version Not Supported'); - - if (!array_key_exists($code, $status)) { - $code = 500; - } - - $status_string = $status[$code]; - - header('HTTP/1.1 '.$code.' '.$status_string); - header('Content-type: text/plain'); - - print $msg; - print "\n"; - exit(); -} - -# Show a user error -function common_user_error($msg, $code=400) { - 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'); - - if (!array_key_exists($code, $status)) { - $code = 400; - } - - $status_string = $status[$code]; - - header('HTTP/1.1 '.$code.' '.$status_string); - - common_show_header('Error'); - common_element('div', array('class' => 'error'), $msg); - common_show_footer(); -} - -$xw = null; - -# Start an HTML element -function common_element_start($tag, $attrs=NULL) { - global $xw; - $xw->startElement($tag); - if (is_array($attrs)) { - foreach ($attrs as $name => $value) { - $xw->writeAttribute($name, $value); - } - } else if (is_string($attrs)) { - $xw->writeAttribute('class', $attrs); - } -} - -function common_element_end($tag) { - static $empty_tag = array('base', 'meta', 'link', 'hr', - 'br', 'param', 'img', 'area', - 'input', 'col'); - global $xw; - # XXX: check namespace - if (in_array($tag, $empty_tag)) { - $xw->endElement(); - } else { - $xw->fullEndElement(); - } -} - -function common_element($tag, $attrs=NULL, $content=NULL) { - common_element_start($tag, $attrs); - global $xw; - if (!is_null($content)) { - $xw->text($content); - } - common_element_end($tag); -} - -function common_start_xml($doc=NULL, $public=NULL, $system=NULL, $indent=true) { - global $xw; - $xw = new XMLWriter(); - $xw->openURI('php://output'); - $xw->setIndent($indent); - $xw->startDocument('1.0', 'UTF-8'); - if ($doc) { - $xw->writeDTD($doc, $public, $system); - } -} - -function common_end_xml() { - global $xw; - $xw->endDocument(); - $xw->flush(); -} - -function common_init_locale($language=null) { +/* XXX: break up into separate modules (HTTP, user, files) */ + +// Show a server error + +function common_server_error($msg, $code=500) +{ + $err = new ServerErrorAction($msg, $code); + $err->showPage(); +} + +// Show a user error +function common_user_error($msg, $code=400) +{ + $err = new ClientErrorAction($msg, $code); + $err->showPage(); +} + +function common_init_locale($language=null) +{ if(!$language) { $language = common_language(); } putenv('LANGUAGE='.$language); putenv('LANG='.$language); return setlocale(LC_ALL, $language . ".utf8", - $language . ".UTF8", - $language . ".utf-8", - $language . ".UTF-8", - $language); -} - -function common_init_language() { - mb_internal_encoding('UTF-8'); - $language = common_language(); - # So we don't have to make people install the gettext locales - $locale_set = common_init_locale($language); - bindtextdomain("laconica", common_config('site','locale_path')); - bind_textdomain_codeset("laconica", "UTF-8"); - textdomain("laconica"); - setlocale(LC_CTYPE, 'C'); - if(!$locale_set) { - common_log(LOG_INFO,'Language requested:'.$language.' - locale could not be set:',__FILE__); - } -} - -define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2'); - -function common_show_header($pagetitle, $callable=NULL, $data=NULL, $headercall=NULL) { - - global $config, $xw; - global $action; /* XXX: kind of cheating here. */ - - common_start_html(); - - common_element_start('head'); - common_element('title', NULL, - $pagetitle . " - " . $config['site']['name']); - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => theme_path('display.css') . '?version=' . LACONICA_VERSION, - 'media' => 'screen, projection, tv')); - foreach (array(6,7) as $ver) { - if (file_exists(theme_file('ie'.$ver.'.css'))) { - # Yes, IE people should be put in jail. - $xw->writeComment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '. - 'href="'.theme_path('ie'.$ver.'.css').'?version='.LACONICA_VERSION.'" /><![endif]'); - } - } - - common_element('script', array('type' => 'text/javascript', - 'src' => common_path('js/jquery.min.js')), - ' '); - common_element('script', array('type' => 'text/javascript', - 'src' => common_path('js/jquery.form.js')), - ' '); - common_element('script', array('type' => 'text/javascript', - 'src' => common_path('js/xbImportNode.js')), - ' '); - common_element('script', array('type' => 'text/javascript', - 'src' => common_path('js/util.js?version='.LACONICA_VERSION)), - ' '); - common_element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', - 'href' => common_local_url('opensearch', array('type' => 'people')), - 'title' => common_config('site', 'name').' People Search')); - - common_element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', - 'href' => common_local_url('opensearch', array('type' => 'notice')), - 'title' => common_config('site', 'name').' Notice Search')); - - if ($callable) { - if ($data) { - call_user_func($callable, $data); - } else { - call_user_func($callable); - } - } - common_element_end('head'); - common_element_start('body', $action); - common_element_start('div', array('id' => 'wrap')); - common_element_start('div', array('id' => 'header')); - common_nav_menu(); - if ((isset($config['site']['logo']) && is_string($config['site']['logo']) && (strlen($config['site']['logo']) > 0)) - || file_exists(theme_file('logo.png'))) - { - common_element_start('a', array('href' => common_local_url('public'))); - common_element('img', array('src' => isset($config['site']['logo']) ? - ($config['site']['logo']) : theme_path('logo.png'), - 'alt' => $config['site']['name'], - 'id' => 'logo')); - common_element_end('a'); - } else { - common_element_start('p', array('id' => 'branding')); - common_element('a', array('href' => common_local_url('public')), - $config['site']['name']); - common_element_end('p'); - } - - common_element('h1', 'pagetitle', $pagetitle); - - if ($headercall) { - if ($data) { - call_user_func($headercall, $data); - } else { - call_user_func($headercall); - } - } - common_element_end('div'); - common_element_start('div', array('id' => 'content')); -} - -function common_start_html($type=NULL, $indent=true) { - - if (!$type) { - $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : NULL; - - # XXX: allow content negotiation for RDF, RSS, or XRDS - - $type = common_negotiate_type(common_accept_to_prefs($httpaccept), - common_accept_to_prefs(PAGE_TYPE_PREFS)); - - if (!$type) { - common_user_error(_('This page is not available in a media type you accept'), 406); - exit(0); - } - } - - header('Content-Type: '.$type); - - common_start_xml('html', - '-//W3C//DTD XHTML 1.0 Strict//EN', - 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd', $indent); - - # FIXME: correct language for interface - - $language = common_language(); - - common_element_start('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', - 'xml:lang' => $language, - 'lang' => $language)); -} - -function common_show_footer() { - global $xw, $config; - common_element_end('div'); # content div - common_foot_menu(); - common_element_start('div', array('id' => 'footer')); - common_element_start('div', 'laconica'); - if (common_config('site', 'broughtby')) { - $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%). '); - } else { - $instr = _('**%%site.name%%** is a microblogging service. '); - } - $instr .= sprintf(_('It runs the [Laconica](http://laconi.ca/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), LACONICA_VERSION); - $output = common_markup_to_html($instr); - common_raw($output); - common_element_end('div'); - common_element('img', array('id' => 'cc', - 'src' => $config['license']['image'], - 'alt' => $config['license']['title'])); - common_element_start('p'); - common_text(_('Unless otherwise specified, contents of this site are copyright by the contributors and available under the ')); - common_element('a', array('class' => 'license', - 'rel' => 'license', - 'href' => $config['license']['url']), - $config['license']['title']); - common_text(_('. Contributors should be attributed by full name or nickname.')); - common_element_end('p'); - common_element_end('div'); - common_element_end('div'); - common_element_end('body'); - common_element_end('html'); - common_end_xml(); -} - -function common_text($txt) { - global $xw; - $xw->text($txt); -} - -function common_raw($xml) { - global $xw; - $xw->writeRaw($xml); -} - -function common_nav_menu() { - $user = common_current_user(); - common_element_start('ul', array('id' => 'nav')); - if ($user) { - common_menu_item(common_local_url('all', array('nickname' => $user->nickname)), - _('Home')); - } - common_menu_item(common_local_url('peoplesearch'), _('Search')); - if ($user) { - common_menu_item(common_local_url('profilesettings'), - _('Settings')); - common_menu_item(common_local_url('invite'), - _('Invite')); - common_menu_item(common_local_url('logout'), - _('Logout')); - } else { - common_menu_item(common_local_url('login'), _('Login')); - if (!common_config('site', 'closed')) { - common_menu_item(common_local_url('register'), _('Register')); - } - common_menu_item(common_local_url('openidlogin'), _('OpenID')); - } - common_menu_item(common_local_url('doc', array('title' => 'help')), - _('Help')); - common_element_end('ul'); -} - -function common_foot_menu() { - common_element_start('ul', array('id' => 'nav_sub')); - common_menu_item(common_local_url('doc', array('title' => 'help')), - _('Help')); - common_menu_item(common_local_url('doc', array('title' => 'about')), - _('About')); - common_menu_item(common_local_url('doc', array('title' => 'faq')), - _('FAQ')); - common_menu_item(common_local_url('doc', array('title' => 'privacy')), - _('Privacy')); - common_menu_item(common_local_url('doc', array('title' => 'source')), - _('Source')); - common_menu_item(common_local_url('doc', array('title' => 'contact')), - _('Contact')); - common_element_end('ul'); -} - -function common_menu_item($url, $text, $title=NULL, $is_selected=false) { - $lattrs = array(); - if ($is_selected) { - $lattrs['class'] = 'current'; - } - common_element_start('li', $lattrs); - $attrs['href'] = $url; - if ($title) { - $attrs['title'] = $title; - } - common_element('a', $attrs, $text); - common_element_end('li'); -} - -function common_input($id, $label, $value=NULL,$instructions=NULL) { - common_element_start('p'); - common_element('label', array('for' => $id), $label); - $attrs = array('name' => $id, - 'type' => 'text', - 'class' => 'input_text', - 'id' => $id); - if ($value) { - $attrs['value'] = htmlspecialchars($value); - } - common_element('input', $attrs); - if ($instructions) { - common_element('span', 'input_instructions', $instructions); - } - common_element_end('p'); -} - -function common_checkbox($id, $label, $checked=false, $instructions=NULL, $value='true', $disabled=false) -{ - common_element_start('p'); - $attrs = array('name' => $id, - 'type' => 'checkbox', - 'class' => 'checkbox', - 'id' => $id); - if ($value) { - $attrs['value'] = htmlspecialchars($value); - } - if ($checked) { - $attrs['checked'] = 'checked'; - } - if ($disabled) { - $attrs['disabled'] = 'true'; - } - common_element('input', $attrs); - common_text(' '); - common_element('label', array('class' => 'checkbox_label', 'for' => $id), $label); - common_text(' '); - if ($instructions) { - common_element('span', 'input_instructions', $instructions); - } - common_element_end('p'); -} - -function common_dropdown($id, $label, $content, $instructions=NULL, $blank_select=FALSE, $selected=NULL) { - common_element_start('p'); - common_element('label', array('for' => $id), $label); - common_element_start('select', array('id' => $id, 'name' => $id)); - if ($blank_select) { - common_element('option', array('value' => '')); - } - foreach ($content as $value => $option) { - if ($value == $selected) { - common_element('option', array('value' => $value, 'selected' => $value), $option); - } else { - common_element('option', array('value' => $value), $option); - } - } - common_element_end('select'); - if ($instructions) { - common_element('span', 'input_instructions', $instructions); - } - common_element_end('p'); -} -function common_hidden($id, $value) { - common_element('input', array('name' => $id, - 'type' => 'hidden', - 'id' => $id, - 'value' => $value)); -} - -function common_password($id, $label, $instructions=NULL) { - common_element_start('p'); - common_element('label', array('for' => $id), $label); - $attrs = array('name' => $id, - 'type' => 'password', - 'class' => 'password', - 'id' => $id); - common_element('input', $attrs); - if ($instructions) { - common_element('span', 'input_instructions', $instructions); - } - common_element_end('p'); -} - -function common_submit($id, $label, $cls='submit') { - global $xw; - common_element_start('p'); - common_element('input', array('type' => 'submit', - 'id' => $id, - 'name' => $id, - 'class' => $cls, - 'value' => $label)); - common_element_end('p'); -} - -function common_textarea($id, $label, $content=NULL, $instructions=NULL) { - common_element_start('p'); - common_element('label', array('for' => $id), $label); - common_element('textarea', array('rows' => 3, - 'cols' => 40, - 'name' => $id, - 'id' => $id), - ($content) ? $content : ''); - if ($instructions) { - common_element('span', 'input_instructions', $instructions); - } - common_element_end('p'); -} - -function common_timezone() { - if (common_logged_in()) { - $user = common_current_user(); - if ($user->timezone) { - return $user->timezone; - } - } - - global $config; - return $config['site']['timezone']; -} - -function common_language() { - - // If there is a user logged in and they've set a language preference - // then return that one... - if (common_logged_in()) { - $user = common_current_user(); - $user_language = $user->language; - if ($user_language) - return $user_language; + $language . ".UTF8", + $language . ".utf-8", + $language . ".UTF-8", + $language); +} + +function common_init_language() +{ + mb_internal_encoding('UTF-8'); + $language = common_language(); + // So we don't have to make people install the gettext locales + $locale_set = common_init_locale($language); + bindtextdomain("laconica", common_config('site','locale_path')); + bind_textdomain_codeset("laconica", "UTF-8"); + textdomain("laconica"); + setlocale(LC_CTYPE, 'C'); + if(!$locale_set) { + common_log(LOG_INFO,'Language requested:'.$language.' - locale could not be set:',__FILE__); + } +} + +function common_timezone() +{ + if (common_logged_in()) { + $user = common_current_user(); + if ($user->timezone) { + return $user->timezone; } + } - // Otherwise, find the best match for the languages requested by the - // user's browser... - $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : NULL; - if (!empty($httplang)) { - $language = client_prefered_language($httplang); - if ($language) - return $language; - } + global $config; + return $config['site']['timezone']; +} + +function common_language() +{ + + // If there is a user logged in and they've set a language preference + // then return that one... + if (common_logged_in()) { + $user = common_current_user(); + $user_language = $user->language; + if ($user_language) + return $user_language; + } - // Finally, if none of the above worked, use the site's default... - return common_config('site', 'language'); + // Otherwise, find the best match for the languages requested by the + // user's browser... + $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; + if (!empty($httplang)) { + $language = client_prefered_language($httplang); + if ($language) + return $language; + } + + // Finally, if none of the above worked, use the site's default... + return common_config('site', 'language'); } -# salted, hashed passwords are stored in the DB +// salted, hashed passwords are stored in the DB -function common_munge_password($password, $id) { - return md5($password . $id); +function common_munge_password($password, $id) +{ + return md5($password . $id); } -# check if a username exists and has matching password -function common_check_user($nickname, $password) { - # NEVER allow blank passwords, even if they match the DB - if (mb_strlen($password) == 0) { - return false; - } - $user = User::staticGet('nickname', $nickname); - if (is_null($user)) { - return false; - } else { - if (0 == strcmp(common_munge_password($password, $user->id), - $user->password)) { - return $user; - } else { - return false; - } - } +// check if a username exists and has matching password +function common_check_user($nickname, $password) +{ + // NEVER allow blank passwords, even if they match the DB + if (mb_strlen($password) == 0) { + return false; + } + $user = User::staticGet('nickname', $nickname); + if (is_null($user)) { + return false; + } else { + if (0 == strcmp(common_munge_password($password, $user->id), + $user->password)) { + return $user; + } else { + return false; + } + } } -# is the current user logged in? -function common_logged_in() { - return (!is_null(common_current_user())); +// is the current user logged in? +function common_logged_in() +{ + return (!is_null(common_current_user())); } -function common_have_session() { - return (0 != strcmp(session_id(), '')); +function common_have_session() +{ + return (0 != strcmp(session_id(), '')); } -function common_ensure_session() { - if (!common_have_session()) { - @session_start(); - } +function common_ensure_session() +{ + if (!common_have_session()) { + @session_start(); + } } -# Three kinds of arguments: -# 1) a user object -# 2) a nickname -# 3) NULL to clear +// Three kinds of arguments: +// 1) a user object +// 2) a nickname +// 3) null to clear -# Initialize to false; set to NULL if none found +// Initialize to false; set to null if none found $_cur = false; -function common_set_user($user) { +function common_set_user($user) +{ global $_cur; - if (is_null($user) && common_have_session()) { - $_cur = NULL; - unset($_SESSION['userid']); - return true; - } else if (is_string($user)) { - $nickname = $user; - $user = User::staticGet('nickname', $nickname); - } else if (!($user instanceof User)) { - return false; - } - - if ($user) { - common_ensure_session(); - $_SESSION['userid'] = $user->id; + if (is_null($user) && common_have_session()) { + $_cur = null; + unset($_SESSION['userid']); + return true; + } else if (is_string($user)) { + $nickname = $user; + $user = User::staticGet('nickname', $nickname); + } else if (!($user instanceof User)) { + return false; + } + + if ($user) { + common_ensure_session(); + $_SESSION['userid'] = $user->id; $_cur = $user; - return $_cur; - } - return false; + return $_cur; + } + return false; } -function common_set_cookie($key, $value, $expiration=0) { - $path = common_config('site', 'path'); - $server = common_config('site', 'server'); +function common_set_cookie($key, $value, $expiration=0) +{ + $path = common_config('site', 'path'); + $server = common_config('site', 'server'); - if ($path && ($path != '/')) { - $cookiepath = '/' . $path . '/'; - } else { - $cookiepath = '/'; - } - return setcookie($key, - $value, - $expiration, - $cookiepath, - $server); + if ($path && ($path != '/')) { + $cookiepath = '/' . $path . '/'; + } else { + $cookiepath = '/'; + } + return setcookie($key, + $value, + $expiration, + $cookiepath, + $server); } define('REMEMBERME', 'rememberme'); -define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); # 30 days +define('REMEMBERME_EXPIRY', 30 * 24 * 60 * 60); // 30 days -function common_rememberme($user=NULL) { - if (!$user) { - $user = common_current_user(); - if (!$user) { - common_debug('No current user to remember', __FILE__); - return false; - } - } +function common_rememberme($user=null) +{ + if (!$user) { + $user = common_current_user(); + if (!$user) { + common_debug('No current user to remember', __FILE__); + return false; + } + } - $rm = new Remember_me(); + $rm = new Remember_me(); - $rm->code = common_good_rand(16); - $rm->user_id = $user->id; + $rm->code = common_good_rand(16); + $rm->user_id = $user->id; - # Wrap the insert in some good ol' fashioned transaction code + // Wrap the insert in some good ol' fashioned transaction code $rm->query('BEGIN'); - $result = $rm->insert(); + $result = $rm->insert(); - if (!$result) { - common_log_db_error($rm, 'INSERT', __FILE__); - common_debug('Error adding rememberme record for ' . $user->nickname, __FILE__); - return false; + if (!$result) { + common_log_db_error($rm, 'INSERT', __FILE__); + common_debug('Error adding rememberme record for ' . $user->nickname, __FILE__); + return false; } $rm->query('COMMIT'); - common_debug('Inserted rememberme record (' . $rm->code . ', ' . $rm->user_id . '); result = ' . $result . '.', __FILE__); + common_debug('Inserted rememberme record (' . $rm->code . ', ' . $rm->user_id . '); result = ' . $result . '.', __FILE__); $cookieval = $rm->user_id . ':' . $rm->code; - common_log(LOG_INFO, 'adding rememberme cookie "' . $cookieval . '" for ' . $user->nickname); + common_log(LOG_INFO, 'adding rememberme cookie "' . $cookieval . '" for ' . $user->nickname); - common_set_cookie(REMEMBERME, $cookieval, time() + REMEMBERME_EXPIRY); + common_set_cookie(REMEMBERME, $cookieval, time() + REMEMBERME_EXPIRY); - return true; + return true; } -function common_remembered_user() { +function common_remembered_user() +{ - $user = NULL; + $user = null; - $packed = isset($_COOKIE[REMEMBERME]) ? $_COOKIE[REMEMBERME] : NULL; + $packed = isset($_COOKIE[REMEMBERME]) ? $_COOKIE[REMEMBERME] : null; - if (!$packed) { - return NULL; + if (!$packed) { + return null; } list($id, $code) = explode(':', $packed); @@ -665,7 +255,7 @@ function common_remembered_user() { if (!$id || !$code) { common_log(LOG_WARNING, 'Malformed rememberme cookie: ' . $packed); common_forgetme(); - return NULL; + return null; } $rm = Remember_me::staticGet($code); @@ -673,13 +263,13 @@ function common_remembered_user() { if (!$rm) { common_log(LOG_WARNING, 'No such remember code: ' . $code); common_forgetme(); - return NULL; + return null; } if ($rm->user_id != $id) { common_log(LOG_WARNING, 'Rememberme code for wrong user: ' . $rm->user_id . ' != ' . $id); common_forgetme(); - return NULL; + return null; } $user = User::staticGet($rm->user_id); @@ -687,17 +277,17 @@ function common_remembered_user() { if (!$user) { common_log(LOG_WARNING, 'No such user for rememberme: ' . $rm->user_id); common_forgetme(); - return NULL; + return null; } - # successful! + // successful! $result = $rm->delete(); if (!$result) { common_log_db_error($rm, 'DELETE', __FILE__); common_log(LOG_WARNING, 'Could not delete rememberme: ' . $code); common_forgetme(); - return NULL; + return null; } common_log(LOG_INFO, 'logging in ' . $user->nickname . ' using rememberme code ' . $rm->code); @@ -705,22 +295,24 @@ function common_remembered_user() { common_set_user($user); common_real_login(false); - # We issue a new cookie, so they can log in - # automatically again after this session + // We issue a new cookie, so they can log in + // automatically again after this session common_rememberme($user); - return $user; + return $user; } -# must be called with a valid user! +// must be called with a valid user! -function common_forgetme() { - common_set_cookie(REMEMBERME, '', 0); +function common_forgetme() +{ + common_set_cookie(REMEMBERME, '', 0); } -# who is the current user? -function common_current_user() { +// who is the current user? +function common_current_user() +{ global $_cur; if ($_cur === false) { @@ -734,585 +326,646 @@ function common_current_user() { } } - # that didn't work; try to remember; will init $_cur to NULL on failure + // that didn't work; try to remember; will init $_cur to null on failure $_cur = common_remembered_user(); if ($_cur) { common_debug("Got User " . $_cur->nickname); common_debug("Faking session on remembered user"); - # XXX: Is this necessary? + // XXX: Is this necessary? $_SESSION['userid'] = $_cur->id; } } - return $_cur; + return $_cur; } -# Logins that are 'remembered' aren't 'real' -- they're subject to -# cookie-stealing. So, we don't let them do certain things. New reg, -# OpenID, and password logins _are_ real. +// Logins that are 'remembered' aren't 'real' -- they're subject to +// cookie-stealing. So, we don't let them do certain things. New reg, +// OpenID, and password logins _are_ real. -function common_real_login($real=true) { - common_ensure_session(); - $_SESSION['real_login'] = $real; +function common_real_login($real=true) +{ + common_ensure_session(); + $_SESSION['real_login'] = $real; } -function common_is_real_login() { - return common_logged_in() && $_SESSION['real_login']; +function common_is_real_login() +{ + return common_logged_in() && $_SESSION['real_login']; } -# get canonical version of nickname for comparison -function common_canonical_nickname($nickname) { - # XXX: UTF-8 canonicalization (like combining chars) - return strtolower($nickname); +// get canonical version of nickname for comparison +function common_canonical_nickname($nickname) +{ + // XXX: UTF-8 canonicalization (like combining chars) + return strtolower($nickname); } -# get canonical version of email for comparison -function common_canonical_email($email) { - # XXX: canonicalize UTF-8 - # XXX: lcase the domain part - return $email; +// get canonical version of email for comparison +function common_canonical_email($email) +{ + // XXX: canonicalize UTF-8 + // XXX: lcase the domain part + return $email; } define('URL_REGEX', '^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))'); -function common_render_content($text, $notice) { - $r = common_render_text($text); - $id = $notice->profile_id; - $r = preg_replace('/(^|\s+)@([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r); - $r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r); - $r = preg_replace('/(^|\s+)@#([A-Za-z0-9]{1,64})/e', "'\\1@#'.common_at_hash_link($id, '\\2')", $r); - return $r; -} - -function common_render_text($text) { - $r = htmlspecialchars($text); - - $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r); - $r = preg_replace_callback('@https?://[^\]>\s]+@', 'common_render_uri_thingy', $r); - $r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r); - # XXX: machine tags - return $r; -} - -function common_render_uri_thingy($matches) { - $uri = $matches[0]; - $trailer = ''; - - # Some heuristics for extracting URIs from surrounding punctuation - # Strip from trailing text... - if (preg_match('/^(.*)([,.:"\']+)$/', $uri, $matches)) { - $uri = $matches[1]; - $trailer = $matches[2]; - } - - $pairs = array( - ']' => '[', # technically disallowed in URIs, but used in Java docs - ')' => '(', # far too frequent in Wikipedia and MSDN - ); - $final = substr($uri, -1, 1); - if (isset($pairs[$final])) { - $openers = substr_count($uri, $pairs[$final]); - $closers = substr_count($uri, $final); - if ($closers > $openers) { - // Assume the paren was opened outside the URI - $uri = substr($uri, 0, -1); - $trailer = $final . $trailer; - } - } - if ($longurl = common_longurl($uri)) { - $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8'); - $title = " title='$longurl'"; - } - else $title = ''; - - return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer; -} - -function common_longurl($short_url) { +function common_render_content($text, $notice) +{ + $r = common_render_text($text); + $id = $notice->profile_id; + $r = preg_replace('/(^|\s+)@([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r); + $r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r); + $r = preg_replace('/(^|\s+)@#([A-Za-z0-9]{1,64})/e', "'\\1@#'.common_at_hash_link($id, '\\2')", $r); + $r = preg_replace('/(^|\s)!([A-Za-z0-9]{1,64})/e', "'\\1!'.common_group_link($id, '\\2')", $r); + return $r; +} + +function common_render_text($text) +{ + $r = htmlspecialchars($text); + + $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r); + $r = preg_replace_callback('@https?://[^\]>\s]+@', 'common_render_uri_thingy', $r); + $r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r); + // XXX: machine tags + return $r; +} + +function common_render_uri_thingy($matches) +{ + $uri = $matches[0]; + $trailer = ''; + + // Some heuristics for extracting URIs from surrounding punctuation + // Strip from trailing text... + if (preg_match('/^(.*)([,.:"\']+)$/', $uri, $matches)) { + $uri = $matches[1]; + $trailer = $matches[2]; + } + + $pairs = array( + ']' => '[', // technically disallowed in URIs, but used in Java docs + ')' => '(', // far too frequent in Wikipedia and MSDN + ); + $final = substr($uri, -1, 1); + if (isset($pairs[$final])) { + $openers = substr_count($uri, $pairs[$final]); + $closers = substr_count($uri, $final); + if ($closers > $openers) { + // Assume the paren was opened outside the URI + $uri = substr($uri, 0, -1); + $trailer = $final . $trailer; + } + } + if ($longurl = common_longurl($uri)) { + $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8'); + $title = " title='$longurl'"; + } + else $title = ''; + + return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer; +} + +function common_longurl($short_url) +{ $long_url = common_shorten_link($short_url, true); if ($long_url === $short_url) return false; return $long_url; } -function common_longurl2($uri) { - $uri_e = urlencode($uri); - $longurl = unserialize(file_get_contents("http://api.longurl.org/v1/expand?format=php&url=$uri_e")); - if (empty($longurl['long_url']) || $uri === $longurl['long_url']) return false; - return stripslashes($longurl['long_url']); +function common_longurl2($uri) +{ + $uri_e = urlencode($uri); + $longurl = unserialize(file_get_contents("http://api.longurl.org/v1/expand?format=php&url=$uri_e")); + if (empty($longurl['long_url']) || $uri === $longurl['long_url']) return false; + return stripslashes($longurl['long_url']); } -function common_shorten_links($text) { +function common_shorten_links($text) +{ if (mb_strlen($text) <= 140) return $text; static $cache = array(); if (isset($cache[$text])) return $cache[$text]; // \s = not a horizontal whitespace character (since PHP 5.2.4) - return $cache[$text] = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $text); + return $cache[$text] = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $text); } -function common_shorten_link($url, $reverse = false) { - static $url_cache = array(); +function common_shorten_link($url, $reverse = false) +{ + static $url_cache = array(); if ($reverse) return isset($url_cache[$url]) ? $url_cache[$url] : $url; - $user = common_current_user(); - - $curlh = curl_init(); - curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait - curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); - curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); - - switch($user->urlshorteningservice) { - case 'ur1.ca': - $short_url_service = new LilUrl; - $short_url = $short_url_service->shorten($url); - break; - - case '2tu.us': - $short_url_service = new TightUrl; - $short_url = $short_url_service->shorten($url); - break; - - case 'ptiturl.com': - $short_url_service = new PtitUrl; - $short_url = $short_url_service->shorten($url); - break; - - case 'bit.ly': - curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($url)); - $short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl; - break; - - case 'is.gd': - curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - case 'snipr.com': - curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - case 'metamark.net': - curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - case 'tinyurl.com': - curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($url)); - $short_url = curl_exec($curlh); - break; - default: - $short_url = false; - } - - curl_close($curlh); - - if ($short_url) { + $user = common_current_user(); + + $curlh = curl_init(); + curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait + curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); + curl_setopt($curlh, CURLOPT_RETURNTRANSFER, true); + + switch($user->urlshorteningservice) { + case 'ur1.ca': + $short_url_service = new LilUrl; + $short_url = $short_url_service->shorten($url); + break; + + case '2tu.us': + $short_url_service = new TightUrl; + $short_url = $short_url_service->shorten($url); + break; + + case 'ptiturl.com': + $short_url_service = new PtitUrl; + $short_url = $short_url_service->shorten($url); + break; + + case 'bit.ly': + curl_setopt($curlh, CURLOPT_URL, 'http://bit.ly/api?method=shorten&long_url='.urlencode($url)); + $short_url = current(json_decode(curl_exec($curlh))->results)->hashUrl; + break; + + case 'is.gd': + curl_setopt($curlh, CURLOPT_URL, 'http://is.gd/api.php?longurl='.urlencode($url)); + $short_url = curl_exec($curlh); + break; + case 'snipr.com': + curl_setopt($curlh, CURLOPT_URL, 'http://snipr.com/site/snip?r=simple&link='.urlencode($url)); + $short_url = curl_exec($curlh); + break; + case 'metamark.net': + curl_setopt($curlh, CURLOPT_URL, 'http://metamark.net/api/rest/simple?long_url='.urlencode($url)); + $short_url = curl_exec($curlh); + break; + case 'tinyurl.com': + curl_setopt($curlh, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url='.urlencode($url)); + $short_url = curl_exec($curlh); + break; + default: + $short_url = false; + } + + curl_close($curlh); + + if ($short_url) { $url_cache[(string)$short_url] = $url; - return (string)$short_url; - } - return $url; -} - -function common_xml_safe_str($str) { - $xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8'); - - // Replace control, formatting, and surrogate characters with '*', ala Twitter - return preg_replace('/[\p{Cc}\p{Cf}\p{Cs}]/u', '*', $str); -} - -function common_tag_link($tag) { - $canonical = common_canonical_tag($tag); - $url = common_local_url('tag', array('tag' => $canonical)); - return '<a href="' . htmlspecialchars($url) . '" rel="tag" class="hashlink">' . htmlspecialchars($tag) . '</a>'; -} - -function common_canonical_tag($tag) { - return strtolower(str_replace(array('-', '_', '.'), '', $tag)); -} - -function common_valid_profile_tag($str) { - return preg_match('/^[A-Za-z0-9_\-\.]{1,64}$/', $str); -} - -function common_at_link($sender_id, $nickname) { - $sender = Profile::staticGet($sender_id); - $recipient = common_relative_profile($sender, common_canonical_nickname($nickname)); - if ($recipient) { - return '<a href="'.htmlspecialchars($recipient->profileurl).'" class="atlink">'.$nickname.'</a>'; - } else { - return $nickname; - } -} - -function common_at_hash_link($sender_id, $tag) { - $user = User::staticGet($sender_id); - if (!$user) { - return $tag; - } - $tagged = Profile_tag::getTagged($user->id, common_canonical_tag($tag)); - if ($tagged) { - $url = common_local_url('subscriptions', - array('nickname' => $user->nickname, - 'tag' => $tag)); - return '<a href="'.htmlspecialchars($url).'" class="atlink">'.$tag.'</a>'; - } else { - return $tag; - } -} - -function common_relative_profile($sender, $nickname, $dt=NULL) { - # Try to find profiles this profile is subscribed to that have this nickname - $recipient = new Profile(); - # XXX: use a join instead of a subquery - $recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender->id.' and subscribed = id)', 'AND'); - $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND'); - if ($recipient->find(TRUE)) { - # XXX: should probably differentiate between profiles with - # the same name by date of most recent update - return $recipient; - } - # Try to find profiles that listen to this profile and that have this nickname - $recipient = new Profile(); - # XXX: use a join instead of a subquery - $recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender->id.' and subscriber = id)', 'AND'); - $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND'); - if ($recipient->find(TRUE)) { - # XXX: should probably differentiate between profiles with - # the same name by date of most recent update - return $recipient; - } - # If this is a local user, try to find a local user with that nickname. - $sender = User::staticGet($sender->id); - if ($sender) { - $recipient_user = User::staticGet('nickname', $nickname); - if ($recipient_user) { - return $recipient_user->getProfile(); - } - } - # Otherwise, no links. @messages from local users to remote users, - # or from remote users to other remote users, are just - # outside our ability to make intelligent guesses about - return NULL; + return (string)$short_url; + } + return $url; +} + +function common_xml_safe_str($str) +{ + $xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8'); + + // Replace control, formatting, and surrogate characters with '*', ala Twitter + return preg_replace('/[\p{Cc}\p{Cf}\p{Cs}]/u', '*', $str); +} + +function common_tag_link($tag) +{ + $canonical = common_canonical_tag($tag); + $url = common_local_url('tag', array('tag' => $canonical)); + return '<span class="tag"><a href="' . htmlspecialchars($url) . '" rel="tag">' . htmlspecialchars($tag) . '</a></span>'; +} + +function common_canonical_tag($tag) +{ + return strtolower(str_replace(array('-', '_', '.'), '', $tag)); +} + +function common_valid_profile_tag($str) +{ + return preg_match('/^[A-Za-z0-9_\-\.]{1,64}$/', $str); +} + +function common_at_link($sender_id, $nickname) +{ + $sender = Profile::staticGet($sender_id); + $recipient = common_relative_profile($sender, common_canonical_nickname($nickname)); + if ($recipient) { + return '<span class="vcard"><a href="'.htmlspecialchars($recipient->profileurl).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>'; + } else { + return $nickname; + } +} + +function common_group_link($sender_id, $nickname) +{ + $sender = Profile::staticGet($sender_id); + $group = User_group::staticGet('nickname', common_canonical_nickname($nickname)); + if ($group && $sender->isMember($group)) { + return '<span class="vcard"><a href="'.htmlspecialchars($group->permalink()).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>'; + } else { + return $nickname; + } +} + +function common_at_hash_link($sender_id, $tag) +{ + $user = User::staticGet($sender_id); + if (!$user) { + return $tag; + } + $tagged = Profile_tag::getTagged($user->id, common_canonical_tag($tag)); + if ($tagged) { + $url = common_local_url('subscriptions', + array('nickname' => $user->nickname, + 'tag' => $tag)); + return '<span class="tag"><a href="'.htmlspecialchars($url).'" rel="tag">'.$tag.'</a></span>'; + } else { + return $tag; + } +} + +function common_relative_profile($sender, $nickname, $dt=null) +{ + // Try to find profiles this profile is subscribed to that have this nickname + $recipient = new Profile(); + // XXX: use a join instead of a subquery + $recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender->id.' and subscribed = id)', 'AND'); + $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND'); + if ($recipient->find(true)) { + // XXX: should probably differentiate between profiles with + // the same name by date of most recent update + return $recipient; + } + // Try to find profiles that listen to this profile and that have this nickname + $recipient = new Profile(); + // XXX: use a join instead of a subquery + $recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender->id.' and subscriber = id)', 'AND'); + $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND'); + if ($recipient->find(true)) { + // XXX: should probably differentiate between profiles with + // the same name by date of most recent update + return $recipient; + } + // If this is a local user, try to find a local user with that nickname. + $sender = User::staticGet($sender->id); + if ($sender) { + $recipient_user = User::staticGet('nickname', $nickname); + if ($recipient_user) { + return $recipient_user->getProfile(); + } + } + // Otherwise, no links. @messages from local users to remote users, + // or from remote users to other remote users, are just + // outside our ability to make intelligent guesses about + return null; } // where should the avatar go for this user? -function common_avatar_filename($id, $extension, $size=NULL, $extra=NULL) { - global $config; - - if ($size) { - return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension; - } else { - return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension; - } -} - -function common_avatar_path($filename) { - global $config; - return INSTALLDIR . '/avatar/' . $filename; -} - -function common_avatar_url($filename) { - return common_path('avatar/'.$filename); -} - -function common_avatar_display_url($avatar) { - $server = common_config('avatar', 'server'); - if ($server) { - return 'http://'.$server.'/'.$avatar->filename; - } else { - return $avatar->url; - } -} - -function common_default_avatar($size) { - static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile', - AVATAR_STREAM_SIZE => 'stream', - AVATAR_MINI_SIZE => 'mini'); - return theme_path('default-avatar-'.$sizenames[$size].'.png'); -} - -function common_local_url($action, $args=NULL, $fragment=NULL) { - $url = NULL; - if (common_config('site','fancy')) { - $url = common_fancy_url($action, $args); - } else { - $url = common_simple_url($action, $args); - } - if (!is_null($fragment)) { - $url .= '#'.$fragment; - } - return $url; -} - -function common_fancy_url($action, $args=NULL) { - switch (strtolower($action)) { - case 'public': - if ($args && isset($args['page'])) { - return common_path('?page=' . $args['page']); - } else { - return common_path(''); - } - case 'featured': - if ($args && isset($args['page'])) { - return common_path('featured?page=' . $args['page']); - } else { - return common_path('featured'); - } - case 'favorited': - if ($args && isset($args['page'])) { - return common_path('favorited?page=' . $args['page']); - } else { - return common_path('favorited'); - } - case 'publicrss': - return common_path('rss'); - case 'publicatom': - return common_path("api/statuses/public_timeline.atom"); - case 'publicxrds': - return common_path('xrds'); - case 'featuredrss': - return common_path('featuredrss'); - case 'favoritedrss': - return common_path('favoritedrss'); - case 'opensearch': - if ($args && $args['type']) { - return common_path('opensearch/'.$args['type']); - } else { - return common_path('opensearch/people'); - } - case 'doc': - return common_path('doc/'.$args['title']); +function common_avatar_filename($id, $extension, $size=null, $extra=null) +{ + global $config; + + if ($size) { + return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension; + } else { + return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension; + } +} + +function common_avatar_path($filename) +{ + global $config; + return INSTALLDIR . '/avatar/' . $filename; +} + +function common_avatar_url($filename) +{ + return common_path('avatar/'.$filename); +} + +function common_avatar_display_url($avatar) +{ + $server = common_config('avatar', 'server'); + if ($server) { + return 'http://'.$server.'/'.$avatar->filename; + } else { + return $avatar->url; + } +} + +function common_default_avatar($size) +{ + static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile', + AVATAR_STREAM_SIZE => 'stream', + AVATAR_MINI_SIZE => 'mini'); + return theme_path('default-avatar-'.$sizenames[$size].'.png'); +} + +function common_local_url($action, $args=null, $fragment=null) +{ + $url = null; + if (common_config('site','fancy')) { + $url = common_fancy_url($action, $args); + } else { + $url = common_simple_url($action, $args); + } + if (!is_null($fragment)) { + $url .= '#'.$fragment; + } + return $url; +} + +function common_fancy_url($action, $args=null) +{ + switch (strtolower($action)) { + case 'public': + if ($args && isset($args['page'])) { + return common_path('?page=' . $args['page']); + } else { + return common_path(''); + } + case 'featured': + if ($args && isset($args['page'])) { + return common_path('featured?page=' . $args['page']); + } else { + return common_path('featured'); + } + case 'favorited': + if ($args && isset($args['page'])) { + return common_path('favorited?page=' . $args['page']); + } else { + return common_path('favorited'); + } + case 'publicrss': + return common_path('rss'); + case 'publicatom': + return common_path("api/statuses/public_timeline.atom"); + case 'publicxrds': + return common_path('xrds'); + case 'featuredrss': + return common_path('featuredrss'); + case 'favoritedrss': + return common_path('favoritedrss'); + case 'opensearch': + if ($args && $args['type']) { + return common_path('opensearch/'.$args['type']); + } else { + return common_path('opensearch/people'); + } + case 'doc': + return common_path('doc/'.$args['title']); case 'block': - case 'login': - case 'logout': - case 'subscribe': - case 'unsubscribe': - case 'invite': - return common_path('main/'.$action); - case 'tagother': - return common_path('main/tagother?id='.$args['id']); - case 'register': - if ($args && $args['code']) { - return common_path('main/register/'.$args['code']); - } else { - return common_path('main/register'); - } - case 'remotesubscribe': - if ($args && $args['nickname']) { - return common_path('main/remote?nickname=' . $args['nickname']); - } else { - return common_path('main/remote'); - } - case 'nudge': - return common_path($args['nickname'].'/nudge'); - case 'openidlogin': - return common_path('main/openid'); - case 'profilesettings': - return common_path('settings/profile'); - case 'emailsettings': - return common_path('settings/email'); - case 'openidsettings': - return common_path('settings/openid'); - case 'smssettings': - return common_path('settings/sms'); - case 'twittersettings': - return common_path('settings/twitter'); - case 'othersettings': - return common_path('settings/other'); + case 'login': + case 'logout': + case 'subscribe': + case 'unsubscribe': + case 'invite': + return common_path('main/'.$action); + case 'tagother': + return common_path('main/tagother?id='.$args['id']); + case 'register': + if ($args && $args['code']) { + return common_path('main/register/'.$args['code']); + } else { + return common_path('main/register'); + } + case 'remotesubscribe': + if ($args && $args['nickname']) { + return common_path('main/remote?nickname=' . $args['nickname']); + } else { + return common_path('main/remote'); + } + case 'nudge': + return common_path($args['nickname'].'/nudge'); + case 'openidlogin': + return common_path('main/openid'); + case 'profilesettings': + return common_path('settings/profile'); + case 'passwordsettings': + return common_path('settings/password'); + case 'emailsettings': + return common_path('settings/email'); + case 'openidsettings': + return common_path('settings/openid'); + case 'smssettings': + return common_path('settings/sms'); + case 'twittersettings': + return common_path('settings/twitter'); + case 'othersettings': + return common_path('settings/other'); case 'deleteprofile': return common_path('settings/delete'); - case 'newnotice': - if ($args && $args['replyto']) { - return common_path('notice/new?replyto='.$args['replyto']); - } else { - return common_path('notice/new'); - } - case 'shownotice': - return common_path('notice/'.$args['notice']); - case 'deletenotice': - if ($args && $args['notice']) { - return common_path('notice/delete/'.$args['notice']); - } else { - return common_path('notice/delete'); - } - case 'microsummary': - case 'xrds': - case 'foaf': - return common_path($args['nickname'].'/'.$action); - case 'all': - case 'replies': - case 'inbox': - case 'outbox': - if ($args && isset($args['page'])) { - return common_path($args['nickname'].'/'.$action.'?page=' . $args['page']); - } else { - return common_path($args['nickname'].'/'.$action); - } - case 'subscriptions': - case 'subscribers': - $nickname = $args['nickname']; - unset($args['nickname']); - if (isset($args['tag'])) { - $tag = $args['tag']; - unset($args['tag']); - } - $params = http_build_query($args); - if ($params) { - return common_path($nickname.'/'.$action . (($tag) ? '/' . $tag : '') . '?' . $params); - } else { - return common_path($nickname.'/'.$action . (($tag) ? '/' . $tag : '')); - } - case 'allrss': - return common_path($args['nickname'].'/all/rss'); - case 'repliesrss': - return common_path($args['nickname'].'/replies/rss'); - case 'userrss': + case 'newnotice': + if ($args && $args['replyto']) { + return common_path('notice/new?replyto='.$args['replyto']); + } else { + return common_path('notice/new'); + } + case 'shownotice': + return common_path('notice/'.$args['notice']); + case 'deletenotice': + if ($args && $args['notice']) { + return common_path('notice/delete/'.$args['notice']); + } else { + return common_path('notice/delete'); + } + case 'microsummary': + case 'xrds': + case 'foaf': + return common_path($args['nickname'].'/'.$action); + case 'all': + case 'replies': + case 'inbox': + case 'outbox': + if ($args && isset($args['page'])) { + return common_path($args['nickname'].'/'.$action.'?page=' . $args['page']); + } else { + return common_path($args['nickname'].'/'.$action); + } + case 'subscriptions': + case 'subscribers': + $nickname = $args['nickname']; + unset($args['nickname']); + if (isset($args['tag'])) { + $tag = $args['tag']; + unset($args['tag']); + } + $params = http_build_query($args); + if ($params) { + return common_path($nickname.'/'.$action . (($tag) ? '/' . $tag : '') . '?' . $params); + } else { + return common_path($nickname.'/'.$action . (($tag) ? '/' . $tag : '')); + } + case 'allrss': + return common_path($args['nickname'].'/all/rss'); + case 'repliesrss': + return common_path($args['nickname'].'/replies/rss'); + case 'userrss': if (isset($args['limit'])) - return common_path($args['nickname'].'/rss?limit=' . $args['limit']); - return common_path($args['nickname'].'/rss'); - case 'showstream': - if ($args && isset($args['page'])) { - return common_path($args['nickname'].'?page=' . $args['page']); - } else { - return common_path($args['nickname']); - } - - case 'usertimeline': - return common_path("api/statuses/user_timeline/".$args['nickname'].".atom"); - case 'confirmaddress': - return common_path('main/confirmaddress/'.$args['code']); - case 'userbyid': - return common_path('user/'.$args['id']); - case 'recoverpassword': - $path = 'main/recoverpassword'; - if ($args['code']) { - $path .= '/' . $args['code']; - } - return common_path($path); - case 'imsettings': - return common_path('settings/im'); - case 'peoplesearch': - return common_path('search/people' . (($args) ? ('?' . http_build_query($args)) : '')); - case 'noticesearch': - return common_path('search/notice' . (($args) ? ('?' . http_build_query($args)) : '')); - case 'noticesearchrss': - return common_path('search/notice/rss' . (($args) ? ('?' . http_build_query($args)) : '')); - case 'avatarbynickname': - return common_path($args['nickname'].'/avatar/'.$args['size']); - case 'tag': - if (isset($args['tag']) && $args['tag']) { - $path = 'tag/' . $args['tag']; - unset($args['tag']); - } else { - $path = 'tags'; - } - return common_path($path . (($args) ? ('?' . http_build_query($args)) : '')); - case 'tagrss': - $path = 'tag/' . $args['tag'] . '/rss'; + return common_path($args['nickname'].'/rss?limit=' . $args['limit']); + return common_path($args['nickname'].'/rss'); + case 'showstream': + if ($args && isset($args['page'])) { + return common_path($args['nickname'].'?page=' . $args['page']); + } else { + return common_path($args['nickname']); + } + + case 'usertimeline': + return common_path("api/statuses/user_timeline/".$args['nickname'].".atom"); + case 'confirmaddress': + return common_path('main/confirmaddress/'.$args['code']); + case 'userbyid': + return common_path('user/'.$args['id']); + case 'recoverpassword': + $path = 'main/recoverpassword'; + if ($args['code']) { + $path .= '/' . $args['code']; + } + return common_path($path); + case 'imsettings': + return common_path('settings/im'); + case 'avatarsettings': + return common_path('settings/avatar'); + case 'peoplesearch': + return common_path('search/people' . (($args) ? ('?' . http_build_query($args)) : '')); + case 'noticesearch': + return common_path('search/notice' . (($args) ? ('?' . http_build_query($args)) : '')); + case 'noticesearchrss': + return common_path('search/notice/rss' . (($args) ? ('?' . http_build_query($args)) : '')); + case 'avatarbynickname': + return common_path($args['nickname'].'/avatar/'.$args['size']); + case 'tag': + $path = 'tag/' . $args['tag']; + unset($args['tag']); + return common_path($path . (($args) ? ('?' . http_build_query($args)) : '')); + case 'publictagcloud': + return common_path('tags'); + case 'peopletag': + $path = 'peopletag/' . $args['tag']; unset($args['tag']); - return common_path($path . (($args) ? ('?' . http_build_query($args)) : '')); - case 'peopletag': - $path = 'peopletag/' . $args['tag']; - unset($args['tag']); - return common_path($path . (($args) ? ('?' . http_build_query($args)) : '')); - case 'tags': - return common_path('tags' . (($args) ? ('?' . http_build_query($args)) : '')); - case 'favor': - return common_path('main/favor'); - case 'disfavor': - return common_path('main/disfavor'); - case 'showfavorites': - if ($args && isset($args['page'])) { - return common_path($args['nickname'].'/favorites?page=' . $args['page']); - } else { - return common_path($args['nickname'].'/favorites'); - } - case 'favoritesrss': - return common_path($args['nickname'].'/favorites/rss'); - case 'showmessage': - return common_path('message/' . $args['message']); - case 'newmessage': - return common_path('message/new' . (($args) ? ('?' . http_build_query($args)) : '')); - case 'api': - # XXX: do fancy URLs for all the API methods - switch (strtolower($args['apiaction'])) { - case 'statuses': - switch (strtolower($args['method'])) { - case 'user_timeline.rss': - return common_path('api/statuses/user_timeline/'.$args['argument'].'.rss'); - case 'user_timeline.atom': - return common_path('api/statuses/user_timeline/'.$args['argument'].'.atom'); - case 'user_timeline.json': - return common_path('api/statuses/user_timeline/'.$args['argument'].'.json'); - case 'user_timeline.xml': - return common_path('api/statuses/user_timeline/'.$args['argument'].'.xml'); - default: return common_simple_url($action, $args); - } - default: return common_simple_url($action, $args); - } - case 'sup': - if ($args && isset($args['seconds'])) { - return common_path('main/sup?seconds='.$args['seconds']); - } else { - return common_path('main/sup'); - } - default: - return common_simple_url($action, $args); - } -} - -function common_simple_url($action, $args=NULL) { - global $config; - /* XXX: pretty URLs */ - $extra = ''; - if ($args) { - foreach ($args as $key => $value) { - $extra .= "&${key}=${value}"; - } - } - return common_path("index.php?action=${action}${extra}"); -} - -function common_path($relative) { - global $config; - $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : ''; - return "http://".$config['site']['server'].'/'.$pathpart.$relative; -} - -function common_date_string($dt) { - // XXX: do some sexy date formatting - // return date(DATE_RFC822, $dt); - $t = strtotime($dt); - $now = time(); - $diff = $now - $t; - - if ($now < $t) { # that shouldn't happen! - return common_exact_date($dt); - } else if ($diff < 60) { - return _('a few seconds ago'); - } else if ($diff < 92) { - return _('about a minute ago'); - } else if ($diff < 3300) { - return sprintf(_('about %d minutes ago'), round($diff/60)); - } else if ($diff < 5400) { - return _('about an hour ago'); - } else if ($diff < 22 * 3600) { - return sprintf(_('about %d hours ago'), round($diff/3600)); - } else if ($diff < 37 * 3600) { - return _('about a day ago'); - } else if ($diff < 24 * 24 * 3600) { - return sprintf(_('about %d days ago'), round($diff/(24*3600))); - } else if ($diff < 46 * 24 * 3600) { - return _('about a month ago'); - } else if ($diff < 330 * 24 * 3600) { - return sprintf(_('about %d months ago'), round($diff/(30*24*3600))); - } else if ($diff < 480 * 24 * 3600) { - return _('about a year ago'); - } else { - return common_exact_date($dt); - } -} - -function common_exact_date($dt) { + return common_path($path . (($args) ? ('?' . http_build_query($args)) : '')); + case 'tags': + return common_path('tags' . (($args) ? ('?' . http_build_query($args)) : '')); + case 'favor': + return common_path('main/favor'); + case 'disfavor': + return common_path('main/disfavor'); + case 'showfavorites': + if ($args && isset($args['page'])) { + return common_path($args['nickname'].'/favorites?page=' . $args['page']); + } else { + return common_path($args['nickname'].'/favorites'); + } + case 'favoritesrss': + return common_path($args['nickname'].'/favorites/rss'); + case 'showmessage': + return common_path('message/' . $args['message']); + case 'newmessage': + return common_path('message/new' . (($args) ? ('?' . http_build_query($args)) : '')); + case 'api': + // XXX: do fancy URLs for all the API methods + switch (strtolower($args['apiaction'])) { + case 'statuses': + switch (strtolower($args['method'])) { + case 'user_timeline.rss': + return common_path('api/statuses/user_timeline/'.$args['argument'].'.rss'); + case 'user_timeline.atom': + return common_path('api/statuses/user_timeline/'.$args['argument'].'.atom'); + case 'user_timeline.json': + return common_path('api/statuses/user_timeline/'.$args['argument'].'.json'); + case 'user_timeline.xml': + return common_path('api/statuses/user_timeline/'.$args['argument'].'.xml'); + default: return common_simple_url($action, $args); + } + default: return common_simple_url($action, $args); + } + case 'sup': + if ($args && isset($args['seconds'])) { + return common_path('main/sup?seconds='.$args['seconds']); + } else { + return common_path('main/sup'); + } + case 'newgroup': + return common_path('group/new'); + case 'showgroup': + return common_path('group/'.$args['nickname']); + case 'editgroup': + return common_path('group/'.$args['nickname'].'/edit'); + case 'joingroup': + return common_path('group/'.$args['nickname'].'/join'); + case 'leavegroup': + return common_path('group/'.$args['nickname'].'/leave'); + case 'groupbyid': + return common_path('group/'.$args['id'].'/id'); + case 'grouprss': + return common_path('group/'.$args['nickname'].'/rss'); + case 'groupmembers': + return common_path('group/'.$args['nickname'].'/members'); + case 'grouplogo': + return common_path('group/'.$args['nickname'].'/logo'); + case 'usergroups': + return common_path($args['nickname'].'/groups'); + case 'groups': + return common_path('group'); + default: + return common_simple_url($action, $args); + } +} + +function common_simple_url($action, $args=null) +{ + global $config; + /* XXX: pretty URLs */ + $extra = ''; + if ($args) { + foreach ($args as $key => $value) { + $extra .= "&${key}=${value}"; + } + } + return common_path("index.php?action=${action}${extra}"); +} + +function common_path($relative) +{ + global $config; + $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : ''; + return "http://".$config['site']['server'].'/'.$pathpart.$relative; +} + +function common_date_string($dt) +{ + // XXX: do some sexy date formatting + // return date(DATE_RFC822, $dt); + $t = strtotime($dt); + $now = time(); + $diff = $now - $t; + + if ($now < $t) { // that shouldn't happen! + return common_exact_date($dt); + } else if ($diff < 60) { + return _('a few seconds ago'); + } else if ($diff < 92) { + return _('about a minute ago'); + } else if ($diff < 3300) { + return sprintf(_('about %d minutes ago'), round($diff/60)); + } else if ($diff < 5400) { + return _('about an hour ago'); + } else if ($diff < 22 * 3600) { + return sprintf(_('about %d hours ago'), round($diff/3600)); + } else if ($diff < 37 * 3600) { + return _('about a day ago'); + } else if ($diff < 24 * 24 * 3600) { + return sprintf(_('about %d days ago'), round($diff/(24*3600))); + } else if ($diff < 46 * 24 * 3600) { + return _('about a month ago'); + } else if ($diff < 330 * 24 * 3600) { + return sprintf(_('about %d months ago'), round($diff/(30*24*3600))); + } else if ($diff < 480 * 24 * 3600) { + return _('about a year ago'); + } else { + return common_exact_date($dt); + } +} + +function common_exact_date($dt) +{ static $_utc; static $_siteTz; @@ -1321,907 +974,614 @@ function common_exact_date($dt) { $_siteTz = new DateTimeZone(common_timezone()); } - $dateStr = date('d F Y H:i:s', strtotime($dt)); - $d = new DateTime($dateStr, $_utc); - $d->setTimezone($_siteTz); - return $d->format(DATE_RFC850); + $dateStr = date('d F Y H:i:s', strtotime($dt)); + $d = new DateTime($dateStr, $_utc); + $d->setTimezone($_siteTz); + return $d->format(DATE_RFC850); } -function common_date_w3dtf($dt) { - $dateStr = date('d F Y H:i:s', strtotime($dt)); - $d = new DateTime($dateStr, new DateTimeZone('UTC')); - $d->setTimezone(new DateTimeZone(common_timezone())); - return $d->format(DATE_W3C); +function common_date_w3dtf($dt) +{ + $dateStr = date('d F Y H:i:s', strtotime($dt)); + $d = new DateTime($dateStr, new DateTimeZone('UTC')); + $d->setTimezone(new DateTimeZone(common_timezone())); + return $d->format(DATE_W3C); } -function common_date_rfc2822($dt) { - $dateStr = date('d F Y H:i:s', strtotime($dt)); - $d = new DateTime($dateStr, new DateTimeZone('UTC')); - $d->setTimezone(new DateTimeZone(common_timezone())); - return $d->format('r'); +function common_date_rfc2822($dt) +{ + $dateStr = date('d F Y H:i:s', strtotime($dt)); + $d = new DateTime($dateStr, new DateTimeZone('UTC')); + $d->setTimezone(new DateTimeZone(common_timezone())); + return $d->format('r'); } -function common_date_iso8601($dt) { - $dateStr = date('d F Y H:i:s', strtotime($dt)); - $d = new DateTime($dateStr, new DateTimeZone('UTC')); - $d->setTimezone(new DateTimeZone(common_timezone())); - return $d->format('c'); +function common_date_iso8601($dt) +{ + $dateStr = date('d F Y H:i:s', strtotime($dt)); + $d = new DateTime($dateStr, new DateTimeZone('UTC')); + $d->setTimezone(new DateTimeZone(common_timezone())); + return $d->format('c'); } -function common_sql_now() { - return strftime('%Y-%m-%d %H:%M:%S', time()); +function common_sql_now() +{ + return strftime('%Y-%m-%d %H:%M:%S', time()); } -function common_redirect($url, $code=307) { - static $status = array(301 => "Moved Permanently", - 302 => "Found", - 303 => "See Other", - 307 => "Temporary Redirect"); - header("Status: ${code} $status[$code]"); - header("Location: $url"); - - common_start_xml('a', - '-//W3C//DTD XHTML 1.0 Strict//EN', - 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); - common_element('a', array('href' => $url), $url); - common_end_xml(); +function common_redirect($url, $code=307) +{ + static $status = array(301 => "Moved Permanently", + 302 => "Found", + 303 => "See Other", + 307 => "Temporary Redirect"); + + header("Status: ${code} $status[$code]"); + header("Location: $url"); + + $xo = new XMLOutputter(); + $xo->startXML('a', + '-//W3C//DTD XHTML 1.0 Strict//EN', + 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'); + $xo->element('a', array('href' => $url), $url); + $xo->endXML(); exit; } -function common_save_replies($notice) { - # Alternative reply format - $tname = false; - if (preg_match('/^T ([A-Z0-9]{1,64}) /', $notice->content, $match)) { - $tname = $match[1]; - } - # extract all @messages - $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match); - - $names = array(); - - if ($cnt || $tname) { - # XXX: is there another way to make an array copy? - $names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]); - } - - $sender = Profile::staticGet($notice->profile_id); - - $replied = array(); - - # store replied only for first @ (what user/notice what the reply directed, - # we assume first @ is it) - - for ($i=0; $i<count($names); $i++) { - $nickname = $names[$i]; - $recipient = common_relative_profile($sender, $nickname, $notice->created); - if (!$recipient) { - continue; - } - if ($i == 0 && ($recipient->id != $sender->id) && !$notice->reply_to) { # Don't save reply to self - $reply_for = $recipient; - $recipient_notice = $reply_for->getCurrentNotice(); - if ($recipient_notice) { - $orig = clone($notice); - $notice->reply_to = $recipient_notice->id; - $notice->update($orig); - } - } - # Don't save replies from blocked profile to local user - $recipient_user = User::staticGet('id', $recipient->id); - if ($recipient_user && $recipient_user->hasBlocked($sender)) { - continue; +function common_broadcast_notice($notice, $remote=false) +{ + + // Check to see if notice should go to Twitter + $flink = Foreign_link::getByUserID($notice->profile_id, 1); // 1 == Twitter + if (($flink->noticesync & FOREIGN_NOTICE_SEND) == FOREIGN_NOTICE_SEND) { + + // If it's not a Twitter-style reply, or if the user WANTS to send replies... + + if (!preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) || + (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) { + + $result = common_twitter_broadcast($notice, $flink); + + if (!$result) { + common_debug('Unable to send notice: ' . $notice->id . ' to Twitter.', __FILE__); + } } - $reply = new Reply(); - $reply->notice_id = $notice->id; - $reply->profile_id = $recipient->id; - $id = $reply->insert(); - if (!$id) { - $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); - common_log(LOG_ERR, 'DB error inserting reply: ' . $last_error->message); - common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message)); - return; - } else { - $replied[$recipient->id] = 1; - } - } - - # Hash format replies, too - $cnt = preg_match_all('/(?:^|\s)@#([a-z0-9]{1,64})/', $notice->content, $match); - if ($cnt) { - foreach ($match[1] as $tag) { - $tagged = Profile_tag::getTagged($sender->id, $tag); - foreach ($tagged as $t) { - if (!$replied[$t->id]) { - # Don't save replies from blocked profile to local user - $t_user = User::staticGet('id', $t->id); - if ($t_user && $t_user->hasBlocked($sender)) { - continue; - } - $reply = new Reply(); - $reply->notice_id = $notice->id; - $reply->profile_id = $t->id; - $id = $reply->insert(); - if (!$id) { - common_log_db_error($reply, 'INSERT', __FILE__); - return; - } - } - } - } - } -} - -function common_broadcast_notice($notice, $remote=false) { - - // Check to see if notice should go to Twitter - $flink = Foreign_link::getByUserID($notice->profile_id, 1); // 1 == Twitter - if (($flink->noticesync & FOREIGN_NOTICE_SEND) == FOREIGN_NOTICE_SEND) { - - // If it's not a Twitter-style reply, or if the user WANTS to send replies... - - if (!preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) || - (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) { - - $result = common_twitter_broadcast($notice, $flink); - - if (!$result) { - common_debug('Unable to send notice: ' . $notice->id . ' to Twitter.', __FILE__); - } - } - } - - if (common_config('queue', 'enabled')) { - # Do it later! - return common_enqueue_notice($notice); - } else { - return common_real_broadcast($notice, $remote); - } -} - -function common_twitter_broadcast($notice, $flink) { - global $config; - $success = true; - $fuser = $flink->getForeignUser(); - $twitter_user = $fuser->nickname; - $twitter_password = $flink->credentials; - $uri = 'http://www.twitter.com/statuses/update.json'; - - // XXX: Hack to get around PHP cURL's use of @ being a a meta character - $statustxt = preg_replace('/^@/', ' @', $notice->content); - - $options = array( - CURLOPT_USERPWD => "$twitter_user:$twitter_password", - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => array( - 'status' => $statustxt, - 'source' => $config['integration']['source'] - ), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FAILONERROR => true, - CURLOPT_HEADER => false, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_USERAGENT => "Laconica", - CURLOPT_CONNECTTIMEOUT => 120, // XXX: Scary!!!! How long should this be? - CURLOPT_TIMEOUT => 120, - - # Twitter is strict about accepting invalid "Expect" headers - CURLOPT_HTTPHEADER => array('Expect:') - ); - - $ch = curl_init($uri); + } + + if (common_config('queue', 'enabled')) { + // Do it later! + return common_enqueue_notice($notice); + } else { + return common_real_broadcast($notice, $remote); + } +} + +function common_twitter_broadcast($notice, $flink) +{ + global $config; + $success = true; + $fuser = $flink->getForeignUser(); + $twitter_user = $fuser->nickname; + $twitter_password = $flink->credentials; + $uri = 'http://www.twitter.com/statuses/update.json'; + + // XXX: Hack to get around PHP cURL's use of @ being a a meta character + $statustxt = preg_replace('/^@/', ' @', $notice->content); + + $options = array( + CURLOPT_USERPWD => "$twitter_user:$twitter_password", + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => array( + 'status' => $statustxt, + 'source' => $config['integration']['source'] + ), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FAILONERROR => true, + CURLOPT_HEADER => false, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_USERAGENT => "Laconica", + CURLOPT_CONNECTTIMEOUT => 120, // XXX: Scary!!!! How long should this be? + CURLOPT_TIMEOUT => 120, + + # Twitter is strict about accepting invalid "Expect" headers + CURLOPT_HTTPHEADER => array('Expect:') + ); + + $ch = curl_init($uri); curl_setopt_array($ch, $options); $data = curl_exec($ch); $errmsg = curl_error($ch); - if ($errmsg) { - common_debug("cURL error: $errmsg - trying to send notice for $twitter_user.", - __FILE__); - $success = false; - } + if ($errmsg) { + common_debug("cURL error: $errmsg - trying to send notice for $twitter_user.", + __FILE__); + $success = false; + } - curl_close($ch); + curl_close($ch); - if (!$data) { - common_debug("No data returned by Twitter's API trying to send update for $twitter_user", - __FILE__); - $success = false; - } + if (!$data) { + common_debug("No data returned by Twitter's API trying to send update for $twitter_user", + __FILE__); + $success = false; + } - // Twitter should return a status - $status = json_decode($data); + // Twitter should return a status + $status = json_decode($data); - if (!$status->id) { - common_debug("Unexpected data returned by Twitter API trying to send update for $twitter_user", - __FILE__); - $success = false; - } + if (!$status->id) { + common_debug("Unexpected data returned by Twitter API trying to send update for $twitter_user", + __FILE__); + $success = false; + } - return $success; + return $success; } -# Stick the notice on the queue +// Stick the notice on the queue -function common_enqueue_notice($notice) { - foreach (array('jabber', 'omb', 'sms', 'public') as $transport) { - $qi = new Queue_item(); - $qi->notice_id = $notice->id; - $qi->transport = $transport; - $qi->created = $notice->created; +function common_enqueue_notice($notice) +{ + foreach (array('jabber', 'omb', 'sms', 'public') as $transport) { + $qi = new Queue_item(); + $qi->notice_id = $notice->id; + $qi->transport = $transport; + $qi->created = $notice->created; $result = $qi->insert(); - if (!$result) { - $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); - common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message); - return false; - } - common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport); - } - return $result; -} - -function common_dequeue_notice($notice) { - $qi = Queue_item::staticGet($notice->id); - if ($qi) { - $result = $qi->delete(); - if (!$result) { - $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); - common_log(LOG_ERR, 'DB error deleting queue item: ' . $last_error->message); - return false; - } - common_log(LOG_DEBUG, 'complete dequeueing notice ID = ' . $notice->id); - return $result; - } else { + if (!$result) { + $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); + common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message); return false; } + common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport); + } + return $result; } -function common_real_broadcast($notice, $remote=false) { - $success = true; - if (!$remote) { - # Make sure we have the OMB stuff - require_once(INSTALLDIR.'/lib/omb.php'); - $success = omb_broadcast_remote_subscribers($notice); - if (!$success) { - common_log(LOG_ERR, 'Error in OMB broadcast for notice ' . $notice->id); - } - } - if ($success) { - require_once(INSTALLDIR.'/lib/jabber.php'); - $success = jabber_broadcast_notice($notice); - if (!$success) { - common_log(LOG_ERR, 'Error in jabber broadcast for notice ' . $notice->id); - } - } - if ($success) { - require_once(INSTALLDIR.'/lib/mail.php'); - $success = mail_broadcast_notice_sms($notice); - if (!$success) { - common_log(LOG_ERR, 'Error in sms broadcast for notice ' . $notice->id); - } - } - if ($success) { - $success = jabber_public_notice($notice); - if (!$success) { - common_log(LOG_ERR, 'Error in public broadcast for notice ' . $notice->id); - } - } - // XXX: broadcast notices to other IM - return $success; -} - -function common_broadcast_profile($profile) { - // XXX: optionally use a queue system like http://code.google.com/p/microapps/wiki/NQDQ - require_once(INSTALLDIR.'/lib/omb.php'); - omb_broadcast_profile($profile); - // XXX: Other broadcasts...? - return true; -} - -function common_profile_url($nickname) { - return common_local_url('showstream', array('nickname' => $nickname)); -} - -# Don't call if nobody's logged in - -function common_notice_form($action=NULL, $content=NULL) { - $user = common_current_user(); - assert(!is_null($user)); - common_element_start('form', array('id' => 'status_form', - 'method' => 'post', - 'action' => common_local_url('newnotice'))); - common_element_start('p'); - common_element('label', array('for' => 'status_textarea', - 'id' => 'status_label'), - sprintf(_('What\'s up, %s?'), $user->nickname)); - common_element('span', array('id' => 'counter', 'class' => 'counter'), '140'); - common_element('textarea', array('id' => 'status_textarea', - 'cols' => 60, - 'rows' => 3, - 'name' => 'status_textarea'), - ($content) ? $content : ''); - common_hidden('token', common_session_token()); - if ($action) { - common_hidden('returnto', $action); - } - # set by JavaScript - common_hidden('inreplyto', 'false'); - common_element('input', array('id' => 'status_submit', - 'name' => 'status_submit', - 'type' => 'submit', - 'value' => _('Send'))); - common_element_end('p'); - common_element_end('form'); -} - -# Should make up a reasonable root URL - -function common_root_url() { - return common_path(''); -} - -# returns $bytes bytes of random data as a hexadecimal string -# "good" here is a goal and not a guarantee - -function common_good_rand($bytes) { - # XXX: use random.org...? - if (file_exists('/dev/urandom')) { - return common_urandom($bytes); - } else { # FIXME: this is probably not good enough - return common_mtrand($bytes); - } -} - -function common_urandom($bytes) { - $h = fopen('/dev/urandom', 'rb'); - # should not block - $src = fread($h, $bytes); - fclose($h); - $enc = ''; - for ($i = 0; $i < $bytes; $i++) { - $enc .= sprintf("%02x", (ord($src[$i]))); - } - return $enc; -} - -function common_mtrand($bytes) { - $enc = ''; - for ($i = 0; $i < $bytes; $i++) { - $enc .= sprintf("%02x", mt_rand(0, 255)); - } - return $enc; -} - -function common_set_returnto($url) { - common_ensure_session(); - $_SESSION['returnto'] = $url; -} - -function common_get_returnto() { - common_ensure_session(); - return $_SESSION['returnto']; -} - -function common_timestamp() { - return date('YmdHis'); -} - -function common_ensure_syslog() { - static $initialized = false; - if (!$initialized) { - global $config; - openlog($config['syslog']['appname'], 0, LOG_USER); - $initialized = true; - } -} - -function common_log($priority, $msg, $filename=NULL) { - $logfile = common_config('site', 'logfile'); - if ($logfile) { - $log = fopen($logfile, "a"); - if ($log) { - static $syslog_priorities = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR', - 'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG'); - $output = date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n"; - fwrite($log, $output); - fclose($log); - } - } else { - common_ensure_syslog(); - syslog($priority, $msg); - } -} - -function common_debug($msg, $filename=NULL) { - if ($filename) { - common_log(LOG_DEBUG, basename($filename).' - '.$msg); - } else { - common_log(LOG_DEBUG, $msg); - } -} - -function common_log_db_error(&$object, $verb, $filename=NULL) { - $objstr = common_log_objstring($object); - $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); - common_log(LOG_ERR, $last_error->message . '(' . $verb . ' on ' . $objstr . ')', $filename); +function common_dequeue_notice($notice) +{ + $qi = Queue_item::staticGet($notice->id); + if ($qi) { + $result = $qi->delete(); + if (!$result) { + $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); + common_log(LOG_ERR, 'DB error deleting queue item: ' . $last_error->message); + return false; + } + common_log(LOG_DEBUG, 'complete dequeueing notice ID = ' . $notice->id); + return $result; + } else { + return false; + } } -function common_log_objstring(&$object) { - if (is_null($object)) { - return "NULL"; - } - $arr = $object->toArray(); - $fields = array(); - foreach ($arr as $k => $v) { - $fields[] = "$k='$v'"; - } - $objstring = $object->tableName() . '[' . implode(',', $fields) . ']'; - return $objstring; +function common_real_broadcast($notice, $remote=false) +{ + $success = true; + if (!$remote) { + // Make sure we have the OMB stuff + require_once(INSTALLDIR.'/lib/omb.php'); + $success = omb_broadcast_remote_subscribers($notice); + if (!$success) { + common_log(LOG_ERR, 'Error in OMB broadcast for notice ' . $notice->id); + } + } + if ($success) { + require_once(INSTALLDIR.'/lib/jabber.php'); + $success = jabber_broadcast_notice($notice); + if (!$success) { + common_log(LOG_ERR, 'Error in jabber broadcast for notice ' . $notice->id); + } + } + if ($success) { + require_once(INSTALLDIR.'/lib/mail.php'); + $success = mail_broadcast_notice_sms($notice); + if (!$success) { + common_log(LOG_ERR, 'Error in sms broadcast for notice ' . $notice->id); + } + } + if ($success) { + $success = jabber_public_notice($notice); + if (!$success) { + common_log(LOG_ERR, 'Error in public broadcast for notice ' . $notice->id); + } + } + // XXX: broadcast notices to other IM + return $success; } -function common_valid_http_url($url) { - return Validate::uri($url, array('allowed_schemes' => array('http', 'https'))); -} +function common_broadcast_profile($profile) +{ + // XXX: optionally use a queue system like http://code.google.com/p/microapps/wiki/NQDQ + require_once(INSTALLDIR.'/lib/omb.php'); + omb_broadcast_profile($profile); + // XXX: Other broadcasts...? + return true; +} -function common_valid_tag($tag) { - if (preg_match('/^tag:(.*?),(\d{4}(-\d{2}(-\d{2})?)?):(.*)$/', $tag, $matches)) { - return (Validate::email($matches[1]) || - preg_match('/^([\w-\.]+)$/', $matches[1])); - } - return false; +function common_profile_url($nickname) +{ + return common_local_url('showstream', array('nickname' => $nickname)); } -# Does a little before-after block for next/prev page - -function common_pagination($have_before, $have_after, $page, $action, $args=NULL) { +// Should make up a reasonable root URL - if ($have_before || $have_after) { - common_element_start('div', array('id' => 'pagination')); - common_element_start('ul', array('id' => 'nav_pagination')); - } +function common_root_url() +{ + return common_path(''); +} - if ($have_before) { - $pargs = array('page' => $page-1); - $newargs = ($args) ? array_merge($args,$pargs) : $pargs; +// returns $bytes bytes of random data as a hexadecimal string +// "good" here is a goal and not a guarantee - common_element_start('li', 'before'); - common_element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'), - _('« After')); - common_element_end('li'); - } +function common_good_rand($bytes) +{ + // XXX: use random.org...? + if (file_exists('/dev/urandom')) { + return common_urandom($bytes); + } else { // FIXME: this is probably not good enough + return common_mtrand($bytes); + } +} - if ($have_after) { - $pargs = array('page' => $page+1); - $newargs = ($args) ? array_merge($args,$pargs) : $pargs; - common_element_start('li', 'after'); - common_element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'), - _('Before »')); - common_element_end('li'); - } +function common_urandom($bytes) +{ + $h = fopen('/dev/urandom', 'rb'); + // should not block + $src = fread($h, $bytes); + fclose($h); + $enc = ''; + for ($i = 0; $i < $bytes; $i++) { + $enc .= sprintf("%02x", (ord($src[$i]))); + } + return $enc; +} - if ($have_before || $have_after) { - common_element_end('ul'); - common_element_end('div'); - } +function common_mtrand($bytes) +{ + $enc = ''; + for ($i = 0; $i < $bytes; $i++) { + $enc .= sprintf("%02x", mt_rand(0, 255)); + } + return $enc; } -/* Following functions are copied from MediaWiki GlobalFunctions.php - * and written by Evan Prodromou. */ +function common_set_returnto($url) +{ + common_ensure_session(); + $_SESSION['returnto'] = $url; +} -function common_accept_to_prefs($accept, $def = '*/*') { - # No arg means accept anything (per HTTP spec) - if(!$accept) { - return array($def => 1); - } - - $prefs = array(); - - $parts = explode(',', $accept); - - foreach($parts as $part) { - # FIXME: doesn't deal with params like 'text/html; level=1' - @list($value, $qpart) = explode(';', $part); - $match = array(); - if(!isset($qpart)) { - $prefs[$value] = 1; - } elseif(preg_match('/q\s*=\s*(\d*\.\d+)/', $qpart, $match)) { - $prefs[$value] = $match[1]; - } - } - - return $prefs; -} - -function common_mime_type_match($type, $avail) { - if(array_key_exists($type, $avail)) { - return $type; - } else { - $parts = explode('/', $type); - if(array_key_exists($parts[0] . '/*', $avail)) { - return $parts[0] . '/*'; - } elseif(array_key_exists('*/*', $avail)) { - return '*/*'; - } else { - return NULL; - } - } -} - -function common_negotiate_type($cprefs, $sprefs) { - $combine = array(); - - foreach(array_keys($sprefs) as $type) { - $parts = explode('/', $type); - if($parts[1] != '*') { - $ckey = common_mime_type_match($type, $cprefs); - if($ckey) { - $combine[$type] = $sprefs[$type] * $cprefs[$ckey]; - } - } - } - - foreach(array_keys($cprefs) as $type) { - $parts = explode('/', $type); - if($parts[1] != '*' && !array_key_exists($type, $sprefs)) { - $skey = common_mime_type_match($type, $sprefs); - if($skey) { - $combine[$type] = $sprefs[$skey] * $cprefs[$type]; - } - } - } - - $bestq = 0; - $besttype = "text/html"; - - foreach(array_keys($combine) as $type) { - if($combine[$type] > $bestq) { - $besttype = $type; - $bestq = $combine[$type]; - } - } - - return $besttype; -} - -function common_config($main, $sub) { - global $config; - return isset($config[$main][$sub]) ? $config[$main][$sub] : false; -} - -function common_copy_args($from) { - $to = array(); - $strip = get_magic_quotes_gpc(); - foreach ($from as $k => $v) { - $to[$k] = ($strip) ? stripslashes($v) : $v; - } - return $to; +function common_get_returnto() +{ + common_ensure_session(); + return $_SESSION['returnto']; } -// Neutralise the evil effects of magic_quotes_gpc in the current request. -// This is used before handing a request off to OAuthRequest::from_request. -function common_remove_magic_from_request() { - if(get_magic_quotes_gpc()) { - $_POST=array_map('stripslashes',$_POST); - $_GET=array_map('stripslashes',$_GET); - } +function common_timestamp() +{ + return date('YmdHis'); } -function common_user_uri(&$user) { - return common_local_url('userbyid', array('id' => $user->id)); +function common_ensure_syslog() +{ + static $initialized = false; + if (!$initialized) { + global $config; + openlog($config['syslog']['appname'], 0, LOG_USER); + $initialized = true; + } } -function common_notice_uri(&$notice) { - return common_local_url('shownotice', - array('notice' => $notice->id)); +function common_log($priority, $msg, $filename=null) +{ + $logfile = common_config('site', 'logfile'); + if ($logfile) { + $log = fopen($logfile, "a"); + if ($log) { + static $syslog_priorities = array('LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR', + 'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG'); + $output = date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n"; + fwrite($log, $output); + fclose($log); + } + } else { + common_ensure_syslog(); + syslog($priority, $msg); + } } -# 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits +function common_debug($msg, $filename=null) +{ + if ($filename) { + common_log(LOG_DEBUG, basename($filename).' - '.$msg); + } else { + common_log(LOG_DEBUG, $msg); + } +} -function common_confirmation_code($bits) { - # 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits - static $codechars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; - $chars = ceil($bits/5); - $code = ''; - for ($i = 0; $i < $chars; $i++) { - # XXX: convert to string and back - $num = hexdec(common_good_rand(1)); - # XXX: randomness is too precious to throw away almost - # 40% of the bits we get! - $code .= $codechars[$num%32]; - } - return $code; +function common_log_db_error(&$object, $verb, $filename=null) +{ + $objstr = common_log_objstring($object); + $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); + common_log(LOG_ERR, $last_error->message . '(' . $verb . ' on ' . $objstr . ')', $filename); } -# convert markup to HTML +function common_log_objstring(&$object) +{ + if (is_null($object)) { + return "null"; + } + $arr = $object->toArray(); + $fields = array(); + foreach ($arr as $k => $v) { + $fields[] = "$k='$v'"; + } + $objstring = $object->tableName() . '[' . implode(',', $fields) . ']'; + return $objstring; +} -function common_markup_to_html($c) { - $c = preg_replace('/%%action.(\w+)%%/e', "common_local_url('\\1')", $c); - $c = preg_replace('/%%doc.(\w+)%%/e', "common_local_url('doc', array('title'=>'\\1'))", $c); - $c = preg_replace('/%%(\w+).(\w+)%%/e', 'common_config(\'\\1\', \'\\2\')', $c); - return Markdown($c); +function common_valid_http_url($url) +{ + return Validate::uri($url, array('allowed_schemes' => array('http', 'https'))); } -function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) { - $avatar = $profile->getAvatar($size); - if ($avatar) { - return common_avatar_display_url($avatar); - } else { - return common_default_avatar($size); - } +function common_valid_tag($tag) +{ + if (preg_match('/^tag:(.*?),(\d{4}(-\d{2}(-\d{2})?)?):(.*)$/', $tag, $matches)) { + return (Validate::email($matches[1]) || + preg_match('/^([\w-\.]+)$/', $matches[1])); + } + return false; } -function common_profile_uri($profile) { - if (!$profile) { - return NULL; - } - $user = User::staticGet($profile->id); - if ($user) { - return $user->uri; - } +/* Following functions are copied from MediaWiki GlobalFunctions.php + * and written by Evan Prodromou. */ + +function common_accept_to_prefs($accept, $def = '*/*') +{ + // No arg means accept anything (per HTTP spec) + if(!$accept) { + return array($def => 1); + } + + $prefs = array(); + + $parts = explode(',', $accept); - $remote = Remote_profile::staticGet($profile->id); - if ($remote) { - return $remote->uri; - } - # XXX: this is a very bad profile! - return NULL; + foreach($parts as $part) { + // FIXME: doesn't deal with params like 'text/html; level=1' + @list($value, $qpart) = explode(';', $part); + $match = array(); + if(!isset($qpart)) { + $prefs[$value] = 1; + } elseif(preg_match('/q\s*=\s*(\d*\.\d+)/', $qpart, $match)) { + $prefs[$value] = $match[1]; + } + } + + return $prefs; } -function common_canonical_sms($sms) { - # strip non-digits - preg_replace('/\D/', '', $sms); - return $sms; +function common_mime_type_match($type, $avail) +{ + if(array_key_exists($type, $avail)) { + return $type; + } else { + $parts = explode('/', $type); + if(array_key_exists($parts[0] . '/*', $avail)) { + return $parts[0] . '/*'; + } elseif(array_key_exists('*/*', $avail)) { + return '*/*'; + } else { + return null; + } + } } -function common_error_handler($errno, $errstr, $errfile, $errline, $errcontext) { - switch ($errno) { - case E_USER_ERROR: - common_log(LOG_ERR, "[$errno] $errstr ($errfile:$errline)"); - exit(1); - break; +function common_negotiate_type($cprefs, $sprefs) +{ + $combine = array(); + + foreach(array_keys($sprefs) as $type) { + $parts = explode('/', $type); + if($parts[1] != '*') { + $ckey = common_mime_type_match($type, $cprefs); + if($ckey) { + $combine[$type] = $sprefs[$type] * $cprefs[$ckey]; + } + } + } - case E_USER_WARNING: - common_log(LOG_WARNING, "[$errno] $errstr ($errfile:$errline)"); - break; + foreach(array_keys($cprefs) as $type) { + $parts = explode('/', $type); + if($parts[1] != '*' && !array_key_exists($type, $sprefs)) { + $skey = common_mime_type_match($type, $sprefs); + if($skey) { + $combine[$type] = $sprefs[$skey] * $cprefs[$type]; + } + } + } - case E_USER_NOTICE: - common_log(LOG_NOTICE, "[$errno] $errstr ($errfile:$errline)"); - break; + $bestq = 0; + $besttype = "text/html"; + + foreach(array_keys($combine) as $type) { + if($combine[$type] > $bestq) { + $besttype = $type; + $bestq = $combine[$type]; + } } - # FIXME: show error page if we're on the Web - /* Don't execute PHP internal error handler */ - return true; + return $besttype; } -function common_session_token() { - common_ensure_session(); - if (!array_key_exists('token', $_SESSION)) { - $_SESSION['token'] = common_good_rand(64); - } - return $_SESSION['token']; -} - -function common_disfavor_form($notice) { - common_element_start('form', array('id' => 'disfavor-' . $notice->id, - 'method' => 'post', - 'class' => 'disfavor', - 'action' => common_local_url('disfavor'))); - - common_element('input', array('type' => 'hidden', - 'name' => 'token-'. $notice->id, - 'id' => 'token-'. $notice->id, - 'class' => 'token', - 'value' => common_session_token())); - - common_element('input', array('type' => 'hidden', - 'name' => 'notice', - 'id' => 'notice-n'. $notice->id, - 'class' => 'notice', - 'value' => $notice->id)); - - common_element('input', array('type' => 'submit', - 'id' => 'disfavor-submit-' . $notice->id, - 'name' => 'disfavor-submit-' . $notice->id, - 'class' => 'disfavor', - 'value' => 'Disfavor favorite', - 'title' => 'Remove this message from favorites')); - common_element_end('form'); -} - -function common_favor_form($notice) { - common_element_start('form', array('id' => 'favor-' . $notice->id, - 'method' => 'post', - 'class' => 'favor', - 'action' => common_local_url('favor'))); - - common_element('input', array('type' => 'hidden', - 'name' => 'token-'. $notice->id, - 'id' => 'token-'. $notice->id, - 'class' => 'token', - 'value' => common_session_token())); - - common_element('input', array('type' => 'hidden', - 'name' => 'notice', - 'id' => 'notice-n'. $notice->id, - 'class' => 'notice', - 'value' => $notice->id)); - - common_element('input', array('type' => 'submit', - 'id' => 'favor-submit-' . $notice->id, - 'name' => 'favor-submit-' . $notice->id, - 'class' => 'favor', - 'value' => 'Add to favorites', - 'title' => 'Add this message to favorites')); - common_element_end('form'); -} - -function common_nudge_form($profile) { - common_element_start('form', array('id' => 'nudge', 'method' => 'post', - 'action' => common_local_url('nudge', array('nickname' => $profile->nickname)))); - common_hidden('token', common_session_token()); - common_element('input', array('type' => 'submit', - 'class' => 'submit', - 'value' => _('Send a nudge'))); - common_element_end('form'); -} -function common_nudge_response() { - common_element('p', array('id' => 'nudge_response'), _('Nudge sent!')); -} - -function common_subscribe_form($profile) { - common_element_start('form', array('id' => 'subscribe-' . $profile->id, - 'method' => 'post', - 'class' => 'subscribe', - 'action' => common_local_url('subscribe'))); - common_hidden('token', common_session_token()); - common_element('input', array('id' => 'subscribeto-' . $profile->id, - 'name' => 'subscribeto', - 'type' => 'hidden', - 'value' => $profile->id)); - common_element('input', array('type' => 'submit', - 'class' => 'submit', - 'value' => _('Subscribe'))); - common_element_end('form'); -} - -function common_unsubscribe_form($profile) { - common_element_start('form', array('id' => 'unsubscribe-' . $profile->id, - 'method' => 'post', - 'class' => 'unsubscribe', - 'action' => common_local_url('unsubscribe'))); - common_hidden('token', common_session_token()); - common_element('input', array('id' => 'unsubscribeto-' . $profile->id, - 'name' => 'unsubscribeto', - 'type' => 'hidden', - 'value' => $profile->id)); - common_element('input', array('type' => 'submit', - 'class' => 'submit', - 'value' => _('Unsubscribe'))); - common_element_end('form'); -} - -// XXX: Refactor this code -function common_profile_new_message_nudge ($cur, $profile) { - $user = User::staticGet('id', $profile->id); - - if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) { - common_element_start('li', array('id' => 'profile_send_a_new_message')); - common_element('a', array('href' => common_local_url('newmessage', array('to' => $user->id))), - _('Send a message')); - common_element_end('li'); - - if ($user->email && $user->emailnotifynudge) { - common_element_start('li', array('id' => 'profile_nudge')); - common_nudge_form($user); - common_element_end('li'); - } - } +function common_config($main, $sub) +{ + global $config; + return isset($config[$main][$sub]) ? $config[$main][$sub] : false; } -function common_cache_key($extra) { - return 'laconica:' . common_keyize(common_config('site', 'name')) . ':' . $extra; +function common_copy_args($from) +{ + $to = array(); + $strip = get_magic_quotes_gpc(); + foreach ($from as $k => $v) { + $to[$k] = ($strip) ? stripslashes($v) : $v; + } + return $to; } -function common_keyize($str) { - $str = strtolower($str); - $str = preg_replace('/\s/', '_', $str); - return $str; +// Neutralise the evil effects of magic_quotes_gpc in the current request. +// This is used before handing a request off to OAuthRequest::from_request. +function common_remove_magic_from_request() +{ + if(get_magic_quotes_gpc()) { + $_POST=array_map('stripslashes',$_POST); + $_GET=array_map('stripslashes',$_GET); + } } -function common_message_form($content, $user, $to) { +function common_user_uri(&$user) +{ + return common_local_url('userbyid', array('id' => $user->id)); +} - common_element_start('form', array('id' => 'message_form', - 'method' => 'post', - 'action' => common_local_url('newmessage'))); +function common_notice_uri(&$notice) +{ + return common_local_url('shownotice', + array('notice' => $notice->id)); +} - $mutual_users = $user->mutuallySubscribedUsers(); +// 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits - $mutual = array(); +function common_confirmation_code($bits) +{ + // 36 alphanums - lookalikes (0, O, 1, I) = 32 chars = 5 bits + static $codechars = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ'; + $chars = ceil($bits/5); + $code = ''; + for ($i = 0; $i < $chars; $i++) { + // XXX: convert to string and back + $num = hexdec(common_good_rand(1)); + // XXX: randomness is too precious to throw away almost + // 40% of the bits we get! + $code .= $codechars[$num%32]; + } + return $code; +} - while ($mutual_users->fetch()) { - if ($mutual_users->id != $user->id) { - $mutual[$mutual_users->id] = $mutual_users->nickname; - } - } +// convert markup to HTML - $mutual_users->free(); - unset($mutual_users); +function common_markup_to_html($c) +{ + $c = preg_replace('/%%action.(\w+)%%/e', "common_local_url('\\1')", $c); + $c = preg_replace('/%%doc.(\w+)%%/e', "common_local_url('doc', array('title'=>'\\1'))", $c); + $c = preg_replace('/%%(\w+).(\w+)%%/e', 'common_config(\'\\1\', \'\\2\')', $c); + return Markdown($c); +} + +function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE) +{ + $avatar = $profile->getAvatar($size); + if ($avatar) { + return common_avatar_display_url($avatar); + } else { + return common_default_avatar($size); + } +} - common_dropdown('to', _('To'), $mutual, NULL, FALSE, $to->id); +function common_profile_uri($profile) +{ + if (!$profile) { + return null; + } + $user = User::staticGet($profile->id); + if ($user) { + return $user->uri; + } - common_element_start('p'); + $remote = Remote_profile::staticGet($profile->id); + if ($remote) { + return $remote->uri; + } + // XXX: this is a very bad profile! + return null; +} - common_element('textarea', array('id' => 'message_content', - 'cols' => 60, - 'rows' => 3, - 'name' => 'content'), - ($content) ? $content : ''); +function common_canonical_sms($sms) +{ + // strip non-digits + preg_replace('/\D/', '', $sms); + return $sms; +} - common_element('input', array('id' => 'message_send', - 'name' => 'message_send', - 'type' => 'submit', - 'value' => _('Send'))); +function common_error_handler($errno, $errstr, $errfile, $errline, $errcontext) +{ + switch ($errno) { + case E_USER_ERROR: + common_log(LOG_ERR, "[$errno] $errstr ($errfile:$errline)"); + exit(1); + break; - common_hidden('token', common_session_token()); + case E_USER_WARNING: + common_log(LOG_WARNING, "[$errno] $errstr ($errfile:$errline)"); + break; - common_element_end('p'); - common_element_end('form'); -} + case E_USER_NOTICE: + common_log(LOG_NOTICE, "[$errno] $errstr ($errfile:$errline)"); + break; + } -function common_memcache() { - static $cache = NULL; - if (!common_config('memcached', 'enabled')) { - return NULL; - } else { - if (!$cache) { - $cache = new Memcache(); - $servers = common_config('memcached', 'server'); - if (is_array($servers)) { - foreach($servers as $server) { - $cache->addServer($server); - } - } else { - $cache->addServer($servers); - } - } - return $cache; - } + // FIXME: show error page if we're on the Web + /* Don't execute PHP internal error handler */ + return true; } -function common_compatible_license($from, $to) { - # XXX: better compatibility check needed here! - return ($from == $to); +function common_session_token() +{ + common_ensure_session(); + if (!array_key_exists('token', $_SESSION)) { + $_SESSION['token'] = common_good_rand(64); + } + return $_SESSION['token']; } -/* These are almost identical, so we use a helper function */ - -function common_block_form($profile, $args=NULL) { - common_blocking_form('block', _('Block'), $profile, $args); +function common_cache_key($extra) +{ + return 'laconica:' . common_keyize(common_config('site', 'name')) . ':' . $extra; } -function common_unblock_form($profile, $args=NULL) { - common_blocking_form('unblock', _('Unblock'), $profile, $args); +function common_keyize($str) +{ + $str = strtolower($str); + $str = preg_replace('/\s/', '_', $str); + return $str; } -function common_blocking_form($type, $label, $profile, $args=NULL) { - common_element_start('form', array('id' => $type . '-' . $profile->id, - 'method' => 'post', - 'class' => $type, - 'action' => common_local_url($type))); - common_hidden('token', common_session_token()); - common_element('input', array('id' => $type . 'to-' . $profile->id, - 'name' => $type . 'to', - 'type' => 'hidden', - 'value' => $profile->id)); - common_element('input', array('type' => 'submit', - 'class' => 'submit', - 'name' => $type, - 'value' => $label)); - if ($args) { - foreach ($args as $k => $v) { - common_hidden('returnto-' . $k, $v); +function common_memcache() +{ + static $cache = null; + if (!common_config('memcached', 'enabled')) { + return null; + } else { + if (!$cache) { + $cache = new Memcache(); + $servers = common_config('memcached', 'server'); + if (is_array($servers)) { + foreach($servers as $server) { + $cache->addServer($server); + } + } else { + $cache->addServer($servers); + } } + return $cache; } - common_element_end('form'); - return; } +function common_compatible_license($from, $to) +{ + // XXX: better compatibility check needed here! + return ($from == $to); +} diff --git a/lib/widget.php b/lib/widget.php new file mode 100644 index 000000000..c70505c44 --- /dev/null +++ b/lib/widget.php @@ -0,0 +1,82 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Base class for UI widgets + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Base class for UI widgets + * + * A widget is a cluster of HTML elements that provide some functionality + * that's used on different parts of the site. Examples would be profile + * lists, notice lists, navigation menus (tabsets) and common forms. + * + * @category Widget + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class Widget +{ + /** + * HTMLOutputter to use for output + */ + + var $out = null; + + /** + * Prepare the widget for use + * + * @param HTMLOutputter $out output helper, defaults to null + */ + + function __construct($out=null) + { + $this->out = $out; + } + + /** + * Show the widget + * + * Emit the HTML for the widget, using the configured outputter. + * + * @return void + */ + + function show() + { + } +} diff --git a/lib/xmloutputter.php b/lib/xmloutputter.php new file mode 100644 index 000000000..64935da40 --- /dev/null +++ b/lib/xmloutputter.php @@ -0,0 +1,242 @@ +<?php +/** + * Laconica, the distributed open-source microblogging tool + * + * Low-level generator for XML + * + * PHP version 5 + * + * LICENCE: This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Low-level generator for XML + * + * This is a thin wrapper around PHP's XMLWriter. The main + * advantage is the element() method, which simplifies outputting + * an element. + * + * @category Output + * @package Laconica + * @author Evan Prodromou <evan@controlyourself.ca> + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * @see Action + * @see HTMLOutputter + */ + +class XMLOutputter +{ + /** + * Wrapped XMLWriter object, which does most of the heavy lifting + * for output. + */ + + var $xw = null; + + /** + * Constructor + * + * Initializes the wrapped XMLWriter. + * + * @param string $output URL for outputting, defaults to stdout + * @param boolean $indent Whether to indent output, default true + */ + + function __construct($output='php://output', $indent=true) + { + $this->xw = new XMLWriter(); + $this->xw->openURI($output); + $this->xw->setIndent($indent); + } + + /** + * Start a new XML document + * + * @param string $doc document element + * @param string $public public identifier + * @param string $system system identifier + * + * @return void + */ + + function startXML($doc=null, $public=null, $system=null) + { + $this->xw->startDocument('1.0', 'UTF-8'); + if ($doc) { + $this->xw->writeDTD($doc, $public, $system); + } + } + + /** + * finish an XML document + * + * It's probably a bad idea to continue to use this object + * after calling endXML(). + * + * @return void + */ + + function endXML() + { + $this->xw->endDocument(); + $this->xw->flush(); + } + + /** + * output an XML element + * + * Utility for outputting an XML element. A convenient wrapper + * for a bunch of longer XMLWriter calls. This is best for + * when an element doesn't have any sub-elements; if that's the + * case, use elementStart() and elementEnd() instead. + * + * The $content element will be escaped for XML. If you need + * raw output, use elementStart() and elementEnd() with a call + * to raw() in the middle. + * + * If $attrs is a string instead of an array, it will be treated + * as the class attribute of the element. + * + * @param string $tag Element type or tagname + * @param array $attrs Array of element attributes, as + * key-value pairs + * @param string $content string content of the element + * + * @return void + */ + + function element($tag, $attrs=null, $content=null) + { + $this->elementStart($tag, $attrs); + if (!is_null($content)) { + $this->xw->text($content); + } + $this->elementEnd($tag); + } + + /** + * output a start tag for an element + * + * Mostly used for when an element has content that's + * not a simple string. + * + * If $attrs is a string instead of an array, it will be treated + * as the class attribute of the element. + * + * @param string $tag Element type or tagname + * @param array $attrs Array of element attributes + * + * @return void + */ + + function elementStart($tag, $attrs=null) + { + $this->xw->startElement($tag); + if (is_array($attrs)) { + foreach ($attrs as $name => $value) { + $this->xw->writeAttribute($name, $value); + } + } else if (is_string($attrs)) { + $this->xw->writeAttribute('class', $attrs); + } + } + + /** + * output an end tag for an element + * + * Used in conjunction with elementStart(). $tag param + * should match the elementStart() param. + * + * For HTML 4 compatibility, this method will force + * a full end element (</tag>) even if the element is + * empty, except for a handful of exception tagnames. + * This is a hack. + * + * @param string $tag Element type or tagname. + * + * @return void + */ + + function elementEnd($tag) + { + static $empty_tag = array('base', 'meta', 'link', 'hr', + 'br', 'param', 'img', 'area', + 'input', 'col'); + // XXX: check namespace + if (in_array($tag, $empty_tag)) { + $this->xw->endElement(); + } else { + $this->xw->fullEndElement(); + } + } + + /** + * output plain text + * + * Text will be escaped. If you need it not to be, + * use raw() instead. + * + * @param string $txt Text to output. + * + * @return void + */ + + function text($txt) + { + $this->xw->text($txt); + } + + /** + * output raw xml + * + * This will spit out its argument verbatim -- no escaping is + * done. + * + * @param string $xml XML to output. + * + * @return void + */ + + function raw($xml) + { + $this->xw->writeRaw($xml); + } + + /** + * output a comment + * + * @param string $txt text of the comment + * + * @return void + */ + + function comment($txt) + { + $this->xw->writeComment($txt); + } +} diff --git a/lib/xmppqueuehandler.php b/lib/xmppqueuehandler.php index cfc9642e4..91015fd45 100644 --- a/lib/xmppqueuehandler.php +++ b/lib/xmppqueuehandler.php @@ -28,64 +28,71 @@ require_once(INSTALLDIR.'/lib/queuehandler.php'); * superclass. */ -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); - } +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 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/scripts/enjitqueuehandler.php b/scripts/enjitqueuehandler.php index 8538ae09a..3a4f8315d 100755 --- a/scripts/enjitqueuehandler.php +++ b/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__) . '/..')); @@ -33,21 +33,25 @@ require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); -class EnjitQueueHandler extends QueueHandler { - - function transport() { - return 'enjit'; - } +class EnjitQueueHandler extends QueueHandler +{ + + 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 +64,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,43 +90,43 @@ 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; - } - + } + } mb_internal_encoding('UTF-8'); -$id = ($argc > 1) ? $argv[1] : NULL; +$id = ($argc > 1) ? $argv[1] : null; $handler = new EnjitQueueHandler($id); if ($handler->start()) { - $handler->handle_queue(); + $handler->handle_queue(); } $handler->finish(); diff --git a/scripts/fixup_hashtags.php b/scripts/fixup_hashtags.php index 88f385798..6f65c78a1 100755 --- a/scripts/fixup_hashtags.php +++ b/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/scripts/fixup_inboxes.php b/scripts/fixup_inboxes.php index 1715b0bc1..a5c8a0a5a 100755 --- a/scripts/fixup_inboxes.php +++ b/scripts/fixup_inboxes.php @@ -34,14 +34,14 @@ define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); -$start_at = ($argc > 1) ? $argv[1] : NULL; +$start_at = ($argc > 1) ? $argv[1] : null; 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/scripts/fixup_notices_rendered.php b/scripts/fixup_notices_rendered.php index c6c925729..c27185546 100755 --- a/scripts/fixup_notices_rendered.php +++ b/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__) . '/..')); @@ -31,20 +31,20 @@ require_once(INSTALLDIR . '/lib/common.php'); common_log(LOG_INFO, 'Starting to render old notices.'); -$start_at = ($argc > 1) ? $argv[1] : NULL; +$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/scripts/getpiddir.php b/scripts/getpiddir.php index b4dda2254..4f5704249 100755 --- a/scripts/getpiddir.php +++ b/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/scripts/jabberqueuehandler.php b/scripts/jabberqueuehandler.php index 59cdb94ad..924fc4545 100755 --- a/scripts/jabberqueuehandler.php +++ b/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__) . '/..')); @@ -33,22 +33,25 @@ require_once(INSTALLDIR . '/lib/xmppqueuehandler.php'); set_error_handler('common_error_handler'); -class JabberQueueHandler extends XmppQueueHandler { +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/scripts/maildaemon.php b/scripts/maildaemon.php index 8b809f646..b9facec1a 100755 --- a/scripts/maildaemon.php +++ b/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__) . '/..')); @@ -34,181 +34,194 @@ require_once('Mail/mimeDecode.php'); # FIXME: we use both Mail_mimeDecode and mailparse # Need to move everything to mailparse -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) { +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) + { // 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/scripts/ombqueuehandler.php b/scripts/ombqueuehandler.php index 1df816d14..cdcea51dc 100755 --- a/scripts/ombqueuehandler.php +++ b/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__) . '/..')); @@ -33,33 +33,39 @@ 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; - } +class OmbQueueHandler extends QueueHandler +{ + + 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"); @@ -67,7 +73,7 @@ ini_set("max_input_time", "0"); set_time_limit(0); mb_internal_encoding('UTF-8'); -$id = ($argc > 1) ? $argv[1] : NULL; +$id = ($argc > 1) ? $argv[1] : null; $handler = new OmbQueueHandler($id); diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php index b1ae1d581..5075c12df 100755 --- a/scripts/publicqueuehandler.php +++ b/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__) . '/..')); @@ -33,20 +33,23 @@ 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()); - } - } +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()); + } + } } ini_set("max_execution_time", "0"); diff --git a/scripts/sitemap.php b/scripts/sitemap.php index 6b845beae..51a9bbd75 100755 --- a/scripts/sitemap.php +++ b/scripts/sitemap.php @@ -18,189 +18,193 @@ 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']; - - foreach (glob("$output_dir*.xml") as $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' - ) - ); - } - - write_file($output_paths['index_file'], sitemapindex($index_urls)); +function index_map() +{ + global $output_paths; + $output_dir = $output_paths['output_dir']; + $output_url = $output_paths['output_url']; + + foreach (glob("$output_dir*.xml") as $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' + ) + ); + } + + 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)); +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)); } # Generate sitemaps of all notices. -function notices_map() { - global $output_paths; - - $notices = DB_DataObject::factory('notice'); - - $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1'); - - $notice_count = 0; - $map_count = 1; - - while ($notices->fetch()) { - - # 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', - ); - - $notice_list[$map_count] .= url($notice); - $notice_count++; - } - } - - # Make full sitemaps from the lists and save them. - array_to_map($notice_list, 'notice'); +function notices_map() +{ + global $output_paths; + + $notices = DB_DataObject::factory('notice'); + + $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1'); + + $notice_count = 0; + $map_count = 1; + + while ($notices->fetch()) { + + # 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', + ); + + $notice_list[$map_count] .= url($notice); + $notice_count++; + } + } + + # 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'); +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'); } # ------------------------------------------------------------------------------ @@ -208,88 +212,93 @@ function user_map() { # ------------------------------------------------------------------------------ # Generate a <url></url> element. -function url($url_args) { - $url = preg_replace('/&/', '&', $url_args['url']); # escape ampersands for XML - $lastmod = $url_args['lastmod']; - $changefreq = $url_args['changefreq']; - $priority = $url_args['priority']; +function url($url_args) +{ + $url = preg_replace('/&/', '&', $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('/&/', '&', $sitemap_args['url']); # escape ampersands for XML - $lastmod = $sitemap_args['lastmod']; +function sitemap($sitemap_args) +{ + $url = preg_replace('/&/', '&', $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>'; - - return $urlset; +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>'; + + 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>'; - - return $sitemapindex; +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>'; + + 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)); - } - } +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)); + } + } } # ------------------------------------------------------------------------------ @@ -297,80 +306,84 @@ 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; +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; } # Ensure paths end with a "/". -function trailing_slash($path) { - if (preg_match('/\/$/', $path) == 0) { - $path .= '/'; - } +function trailing_slash($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."); - } +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."); + } } # Display an error message and exit. -function error ($error_msg) { - if (is_null($error_msg)) { - $error_msg = 'error() was called without any explanation!'; - } - - echo "Error: $error_msg\n"; - exit(1); +function error ($error_msg) +{ + if (is_null($error_msg)) { + $error_msg = 'error() was called without any explanation!'; + } + + echo "Error: $error_msg\n"; + exit(1); } ?>
\ No newline at end of file diff --git a/scripts/smsqueuehandler.php b/scripts/smsqueuehandler.php index 8f0d02d9b..38f2f11fe 100755 --- a/scripts/smsqueuehandler.php +++ b/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__) . '/..')); @@ -33,23 +33,28 @@ require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); -class SmsQueueHandler extends QueueHandler { - - function transport() { - return 'sms'; - } +class SmsQueueHandler extends QueueHandler +{ + + 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"); @@ -57,7 +62,7 @@ ini_set("max_input_time", "0"); set_time_limit(0); mb_internal_encoding('UTF-8'); -$id = ($argc > 1) ? $argv[1] : NULL; +$id = ($argc > 1) ? $argv[1] : null; $handler = new SmsQueueHandler($id); diff --git a/scripts/synctwitterfriends.php b/scripts/synctwitterfriends.php index 070eb9bbb..0ce34c2ae 100755 --- a/scripts/synctwitterfriends.php +++ b/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/scripts/update_facebook.php b/scripts/update_facebook.php new file mode 100755 index 000000000..d2c1c3ffb --- /dev/null +++ b/scripts/update_facebook.php @@ -0,0 +1,139 @@ +#!/usr/bin/env php +<?php +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +# 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(); +} + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); +define('LACONICA', true); + +require_once INSTALLDIR . '/lib/common.php'; +require_once INSTALLDIR . '/lib/facebookutil.php'; + +// For storing the last run date-time +$last_updated_file = INSTALLDIR . '/scripts/facebook_last_updated'; + +// Lock file name +$tmp_file = INSTALLDIR . '/scripts/update_facebook.lock'; + +// Make sure only one copy of the script is running at a time +if (!($tmp_file = @fopen($tmp_file, "w"))) +{ + die("Can't open lock file. Script already running?"); +} + +$facebook = getFacebook(); + +$current_time = time(); + +$notice = getFacebookNotices(getLastUpdated()); + +print date('r', $current_time) . " Looking for notices to send to Facebook...\n"; + +$cnt = 0; + +while($notice->fetch()) { + + $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE); + $user = $flink->getUser(); + $fbuid = $flink->foreign_id; + + if (!userCanUpdate($fbuid)) { + continue; + } + + $prefix = $facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid); + $content = "$prefix $notice->content"; + + if (($flink->noticesync & FOREIGN_NOTICE_SEND) == FOREIGN_NOTICE_SEND) { + + // If it's not a reply, or if the user WANTS to send replies... + if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) || + (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) { + + // Avoid a Loop + if ($notice->source != 'Facebook') { + updateStatus($fbuid, $content); + updateProfileBox($facebook, $flink, $notice); + $cnt++; + } + } + } +} + +updateLastUpdated($current_time); + +print "Sent $cnt notices to Facebook.\n"; + +exit(0); + + +function userCanUpdate($fbuid) { + + global $facebook; + + $result = false; + + try { + $result = $facebook->api_client->users_hasAppPermission('status_update', $fbuid); + } catch(FacebookRestClientException $e){ + print_r($e); + } + + return $result; +} + + +function updateStatus($fbuid, $content) { + global $facebook; + + try { + $result = $facebook->api_client->users_setStatus($content, $fbuid, false, true); + } catch(FacebookRestClientException $e){ + print_r($e); + } +} + +function getLastUpdated(){ + global $last_updated_file, $current_time; + + $file = fopen($last_updated_file, 'r'); + + if ($file) { + $last = fgets($file); + } else { + print "Unable to read $last_updated_file. Using current time.\n"; + return $current_time; + } + + fclose($file); + + return $last; +} + +function updateLastUpdated($time){ + global $last_updated_file; + $file = fopen($last_updated_file, 'w') or die("Can't open $last_updated_file for writing!"); + fwrite($file, $time); + fclose($file); +} diff --git a/scripts/xmppconfirmhandler.php b/scripts/xmppconfirmhandler.php index 8961b0b6e..2b8b085ce 100755 --- a/scripts/xmppconfirmhandler.php +++ b/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__) . '/..')); @@ -35,104 +35,109 @@ set_error_handler('common_error_handler'); define('CLAIM_TIMEOUT', 1200); -class XmppConfirmHandler extends XmppQueueHandler { +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/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 9a60970a6..01fe8914f 100755 --- a/scripts/xmppdaemon.php +++ b/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__) . '/..')); @@ -37,205 +37,221 @@ set_error_handler('common_error_handler'); # in jabber.php, which create a new XMPP class. A more elegant (?) solution # might be to use make this a subclass of XMPP. -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) { +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) + { $body = trim($pl['body']); $content_shortened = common_shorten_link($body); if (mb_strlen($content_shortened) > 140) { @@ -245,59 +261,62 @@ 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"); diff --git a/theme/base/css/display.css b/theme/base/css/display.css new file mode 100644 index 000000000..1769dc1c1 --- /dev/null +++ b/theme/base/css/display.css @@ -0,0 +1,1105 @@ +/** theme: base + * + * @package Laconica + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { font-size: 87.5%; background-color:#fff; height:100%; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +margin:0 auto; +width:71.714em; +} +h1,h2,h3,h4,h5,h6 { +text-transform:uppercase; +margin-bottom:7px; +} +h1 { +font-size:1.4em; +line-height:1; +margin-bottom:18px; +} +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +legend { +font-weight:bold; +font-size:1.3em; +text-transform:uppercase; +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +input.submit { +font-weight:bold; +} +textarea { +overflow:auto; +} +option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +} +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +#page_notice .error, +#page_notice .success { +padding:4px 7px; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +form label.submit { +display:none; +} + +.form_settings { +clear:both; +} + +.form_settings fieldset { +margin-bottom:29px; +} +.form_settings input.remove { +margin-left:11px; +} +.form_settings .form_data li { +width:100%; +float:left; +} +.form_settings .form_data label { +float:left; +} +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { +margin-left:11px; +float:left; +} +.form_settings label { +margin-top:2px; +width:152px; +} + +.form_actions label { +display:none; +} +.form_guide { +font-style:italic; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend, +#form_password legend, +#form_settings_avatar legend, +#newgroup legend, +#editgroup legend, +#form_tag_user legend, +#form_remote_subscribe legend { +display:none; +} + +.form_settings .form_data p.form_guide { +clear:both; +margin-left:163px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide { +margin-left:0; +} + +.form_settings .form_note { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +padding:0 7px; +} + + +address { +float:left; +margin-bottom:18px; +margin-left:18px; +} +address.vcard img.logo { +margin-right:0; +} +address .fn { +font-weight:bold; +} + +#header { +width:100%; +position:relative; +float:left; +padding-top:18px; +margin-bottom:29px; +} + +#site_nav_global_primary { +float:right; +margin-right:18px; +margin-bottom:11px; +} +#site_nav_global_primary ul li { +display:inline; +margin-left:11px; +} + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +position:absolute; +right:0; +top:49px; +float:right; +width:300px; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + +#anon_notice { +float:left; +width:432px; +padding:11px; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +border-width:2px; +border-style:solid; +line-height:1.5; +font-size:1.1em; +font-weight:bold; +} + + +#footer { +float:left; +width:64%; +padding:18px; +} + +#site_nav_local_views { +width:100%; +float:left; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +float:left; +margin-right:18px; +list-style-type:none; +} +#site_nav_local_views a { +float:left; +text-decoration:none; +padding:4px 11px; +-moz-border-radius-topleft:4px; +-moz-border-radius-topright:4px; +-webkit-border-top-left-radius:4px; +-webkit-border-top-right-radius:4px; +border-width:1px; +border-style:solid; +border-bottom:0; +text-shadow: 4px 4px 4px #ddd; +font-weight:bold; +} +#site_nav_local_views .nav { +float:left; +width:100%; +} + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} + +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + +#wrap { +float:left; +margin:0 auto; +width:71.714em; +} + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:644px; +width:46em; +padding:18px; +float:left; +border-radius:7px; +-moz-border-radius:7px; +-moz-border-radius-topleft:0; +-webkit-border-radius:7px; +-webkit-border-top-left-radius:0; +} + +#content_inner { +position:relative; +width:100%; +float:left; +} + +#aside_primary { +width:300px; +width:21.429em; +float:left; +margin-left:2px; +padding:18px 4px 18px 18px; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} + +/*Start: FORM NOTICE*/ +#form_notice { +width:458px; +float:left; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +width:370px; +height:67px; +line-height:1.5; +padding:7px 7px 16px 7px; +} +#form_notice label { +display:block; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice .form_data li { +float:left; +} + +#form_notice #notice_attach_file label, +#form_notice #notice_submit label { +display:none; +} + +#form_notice #notice_attachment { +margin-top:25px; +margin-left:4px; +} + +#form_notice .form_note { +position:absolute; +top:99px; +right:98px; +z-index:9; +} + +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +padding:1px 2px; +} + +#form_notice #notice_data-attach_view { +position:absolute; +top:25px; +right:30px; +margin-left:4px; +padding:0; +cursor:pointer; +width:16px; +height:16px; +border:0; +text-indent:-9999px; +} +#form_notice .form_actions { +position:absolute; +bottom:0; +right:0; +} +#form_notice .form_actions input.submit { +width:60px; +padding:8px; +} + +#form_notice li { +margin-bottom:0; +} + +#form_notice #notice_to { +margin-bottom:7px; +} + +#notice_to label { +float:left; +margin-right:18px; +margin-top:11px; +} +#notice_to select { +float:left; +} +/*end FORM NOTICE*/ + + +/* entity_profile */ +.entity_profile { +position:relative; +width:475px; +min-height:123px; +float:left; +margin-bottom:17px; +margin-left:0; +} +.entity_profile dt, +#entity_statistics dt { +font-weight:bold; +} +.entity_profile .entity_depiction { +float:left; +position:absolute; +top:0; +left:0; +width:96px; +} +.entity_profile .entity_fn, +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +float:left; +clear:left; +margin-left:113px; +width:322px; +margin-bottom:4px; +} + +.entity_profile .entity_fn, +.entity_profile .entity_nickname { +width:auto; +clear:none; +} + +.entity_profile .entity_fn { +margin-left:11px; +margin-right:4px; +} +.entity_profile .entity_fn .fn { +font-weight:bold; +font-style:normal; +} +.entity_profile .nickname { +font-style:italic; +font-weight:bold; +} + +.entity_profile .entity_fn dd:before { +content: "("; +font-weight:normal; +} +.entity_profile .entity_fn dd:after { +content: ")"; +font-weight:normal; +} + +.entity_profile dt { +display:none; +} +.entity_profile h2 { +display:none; +} +/* entity_profile */ + + +/*entity_actions*/ +.entity_actions { +float:right; + +} +.entity_actions h2 { +display:none; +} +.entity_actions ul { +list-style-type:none; +} +.entity_actions li { +margin-bottom:4px; +} +.entity_actions li:first-child { +border-top:0; +} +.entity_actions fieldset { +border:0; +padding:0; +} +.entity_actions legend { +display:none; +} + +.entity_actions input.submit { +display:block; +text-align:left; +cursor:pointer; +width:100%; +} +.entity_actions a, +#entity_nudge p, +.entity_remote_subscribe { +text-decoration:none; +font-weight:bold; +display:block; +} + +.form_user_block input.submit, +.form_user_unblock input.submit, +#entity_send-a-message a, +.form_user_nudge input.submit, +#entity_nudge p { +border:0; +padding-left:20px; +} + +#entity_send-a-message a, +#entity_nudge p { +padding:4px 4px 4px 23px; +} + +.entity_remote_subscribe { +padding:4px; +border-width:2px; +border-style:solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + + +.entity_tags ul { +list-style-type:none; +} +.entity_tags li { +display:inline; +margin-right:1em; +float:left; +} + +.aside .section { +margin-bottom:29px; +clear:both; +float:left; +width:100%; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#entity_statistics dt, +#entity_statistics dd { +display:inline; +} +#entity_statistics dt:after { +content: ":"; +} + +.section ul.entities { +width:220px; +float:left; +} +.section .entities li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +.section .entities li .photo { +margin-right:0; +margin-bottom:0; +} +.section .entities li .fn { +display:none; +} +.aside .section .more { +clear:both; +} + +.profile .entity_profile { +margin-bottom:0; +min-height:60px; +} + + +.profile .form_group_join, +.profile .form_group_leave, +.profile .form_user_subscribe, +.profile .form_user_unsubscribe { +float:right; +} +.profile .form_group_join legend, +.profile .form_group_leave legend, +.profile .form_user_subscribe legend, +.profile .form_user_unsubscribe legend { +display:none; +} + +.profiles { +list-style-type:none; +} +.profile .entity_profile .entity_location { +width:auto; +clear:none; +margin-left:11px; +} +.profile .entity_profile dl, +.profile .entity_profile dd { +display:inline; +float:none; +} +.profile .entity_profile .entity_note, +.profile .entity_profile .entity_url, +.profile .entity_profile .entity_tags, +.profile .entity_profile .form_subcription_edit { +margin-left:59px; +clear:none; +display:block; +width:auto; +} +.profile .entity_profile .entity_tags dt { +display:inline; +margin-right:11px; +} + + +.profile .entity_profile .form_subcription_edit label { +font-weight:normal; +margin-right:11px; +} + + +/* NOTICE */ +.notice, +.profile { +position:relative; +padding-top:11px; +padding-bottom:11px; +clear:both; +float:left; +width:100%; +border-top-width:1px; +border-top-style:dashed; +} +.notices li { +list-style-type:none; +} +.notices li.hover { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +/* NOTICES */ +#notices_primary { +float:left; +width:644px; +width:46em; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + +.notice .author { +margin-right:11px; +} + +.notice .author .fn { +font-weight:bold; +} + +.notice .author .photo { +margin-bottom:0; +} + +.vcard .photo { +display:inline; +margin-right:11px; +margin-bottom:11px; +float:left; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} +.vcard .fn { +font-style:italic; +} + +.notice .entry-title { +float:left; +width:100%; +} +#shownotice .notice .entry-title { +font-size:2.2em; +} + +.notice p.entry-content { +display:inline; +} + +#content .notice p.entry-content a:visited { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.notice p.entry-content .vcard a { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + +.notice div.entry-content { +clear:left; +float:left; +font-size:0.95em; +margin-left:59px; +width:70%; +} +#showstream .notice div.entry-content { +margin-left:0; +} + +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} + +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} + + + +.notice-data { +position:absolute; +top:18px; +right:0; +min-height:50px; +margin-bottom:4px; +} +.notice .entry-content .notice-data dt { +display:none; +} + +.notice-data a { +display:block; +outline:none; +} + +.notice-options { +padding-left:2%; +float:left; +width:50%; +position:relative; +font-size:0.95em; +width:12.5%; +float:right; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +top:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +left:0; +} +.notice-options .notice_reply { +left:29px; +} +.notice-options .notice_delete { +left:76px; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options form input.submit { +cursor:pointer; +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} +/*END: NOTICES */ + + + +#groups p { +margin-bottom:18px; +} +#groups #new_group a { +padding-left:20px; +} + + + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border:1px dotted #D1D9E4; +border-bottom:0; +} + +.pagination .nav_prev a { +-moz-border-radius-topright:7px; +-webkit-border-top-right-radius:7px; +padding-left:20px; +border-left:0; +} +.pagination .nav_next a { +-moz-border-radius-topleft:7px; +-webkit-border-top-left-radius:7px; +padding-right:20px; +border-right:0; +} +/* END: NOTICE */ + + +.hentry .entry-content p { +margin-bottom:18px; +} +.hentry entry-content ol, +.hentry .entry-content ul { +list-style-position:inside; +} +.hentry .entry-content li { +margin-bottom:18px; +} +.hentry .entry-content li li { +margin-left:18px; +} + + + + +/* TOP_POSTERS */ +.section tbody td { +padding-right:11px; +padding-bottom:11px; +} +.section .vcard .photo { +margin-right:7px; +margin-bottom:0; +} + +.section .notice { +padding-top:11px; +padding-bottom:11px; +} + +.section .notice:first-child { +padding-top:0; +border-top:0; +} + + +/* tagcloud */ +.tag-cloud { +list-style-type:none; +text-align:center; +} +.aside .tag-cloud { +font-size:0.8em; +} +.tag-cloud li { +display:inline; +margin-right:7px; +line-height:1.25; +} +.aside .tag-cloud li { +line-height:1.5; +} +.tag-cloud li a { +text-decoration:none; +} +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +.tag-cloud-1 { +font-size:1em; +} +.tag-cloud-2 { +font-size:1.25em; +} +.tag-cloud-3 { +font-size:1.75em; +} +.tag-cloud-4 { +font-size:2em; +} +.tag-cloud-5 { +font-size:2.25em; +} +.tag-cloud-6 { +font-size:2.75em; +} +.tag-cloud-7 { +font-size:3.25em; +} + +#publictagcloud #tagcloud.section dt { +display:none; +} + +#form_settings_photo .form_data { +clear:both; +} + +#form_settings_avatar li { +width:auto; +} +#form_settings_avatar input { +margin-left:0; +} +#avatar_original, +#avatar_preview { +float:left; +} +#avatar_preview { +margin-left:29px; +} +#avatar_preview_view { +height:96px; +width:96px; +margin-bottom:18px; +overflow:hidden; +} + +#settings_attach, +#form_settings_avatar .form_actions { +clear:both; +} + +#form_settings_avatar .form_actions { +margin-bottom:0; +} diff --git a/theme/base/css/facebookapp.base.css b/theme/base/css/facebookapp.base.css new file mode 100644 index 000000000..eb7b47a12 --- /dev/null +++ b/theme/base/css/facebookapp.base.css @@ -0,0 +1,285 @@ +/* theme: identica */ +html { +background-color:#ddd; +} +body { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +font-size:1em; +background-color:#ddd; +} +input, textarea, select, option { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} +input, textarea, select { +border-color:#aaa; +} + +input:focus, textarea:focus, select:focus { +border-color:#A9BF4F; +} +input.submit { +background-color:#A9BF4F; +color:#fff; +} + +a { +color:#002E6E; +} +a:active { +background-color:#ddd; +} +.notice p.entry-content a:visited { +background-color:#fcfcfc; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +.notice p.entry-content .vcard a { +background-color:#fcfffc; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} + + + +#aside_primary { +background-color:#CEE1E9; +} + +#form_notice textarea { +} + +#form_notice label { +color:#88171A; +} +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +background-color:#A9BF4F; +} +#form_notice.warning #notice_data-text { +border-color:#A9BF4F; +} + +#form_notice #notice_data-attach_view { +background-image:url(../images/icons/twotone/green/paper-clip.gif); +background-repeat:no-repeat; +background-position:0 45%; +background-color:transparent; +} + + +#site_nav_global_primary a { +} +#form_notice .form_actions input.submit { +} +#nav_register a { +background-color:#A9BF4F; +color:#fff; +text-decoration:none; +font-weight:bold; +padding:2px 4px; + +} +#nav_login a { +} + + +#site_nav_local_views a { +border-color:#fff; +background-color:rgba(255, 255, 255, 0.2); +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.7); +} + + +#content, +#site_nav_local_views .current a { +background-color:#fff; +} + + +#page_notice .error { +background-color:#F7E8E8; +} +#page_notice .success { +background-color:#EFF3DC; +} + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.jpg); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.jpg); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} +#export_data li a.export_vcard { +background-image:url(../../base/images/icons/icon_vcard.gif); +} + + +/*user_actions*/ +#user_actions li { +border-top-color:#eee; +} +#user_actions a { +color:#000; +} +#user_subscribe a, +#TB_window input.submit, +.form_user_subscribe input.submit { +background:#CEE1E9 url(../images/icons/twotone/green/shield.gif) 0 45% no-repeat; +} +.form_user_unsubscribe input.submit { +background-color:#647819; +color:#fff; +} +#user_send-a-message a { +background:url(../images/icons/twotone/green/quote.gif) 0 45% no-repeat; +} +.form_user_nudge input.submit { +background:url(../images/icons/twotone/green/mail.gif) 0 45% no-repeat; +} +.form_user_block input.submit { +background:url(../images/icons/twotone/green/against.gif) 0 45% no-repeat; +} + + +.user_tags .mark_hash { +color:#555; +} + + + +.vcard .fn { +} +.vcard .fn:hover { +} + + + + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + + +.notice div.entry-content a { + +} +.notice div.entry-content a:hover { +} + + +.notice-data a span { +background-color:transparent; +background-repeat:no-repeat; +background-position:0 45%; +} +.notice_video .notice-data a span { +background-image:url(../images/icons/twotone/green/camera.gif); +} +.notice_audio .notice-data a span { +background-image:url(../images/icons/twotone/green/music.gif); +} +.notice_image .notice-data a span { +background-image:url(../images/icons/twotone/green/search.gif); +} +.notice_event .notice-data a span { +background-image:url(../images/icons/twotone/green/calendar.gif); +} +.notice_location .notice-data a span { +background-image:url(../images/icons/twotone/green/flag.gif); +} +.notice_document .notice-data a span { +background-image:url(../images/icons/twotone/green/document.gif); +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +div.notice-options { +opacity:0.3; +} + +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +div.notice-options input { +color:#002E6E; + +} +.notices li.hover { +background-color:#fcfcfc; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} + +.form_settings .form_note { +background-color:#A9BF4F; +} + +/*END: NOTICES */ + + + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +} +.pagination .nav_prev a { +background-image:url(../images/icons/twotone/green/arrow-left.gif); +background-position:0 45%; +} +.pagination .nav_next a { +background-image:url(../images/icons/twotone/green/arrow-right.gif); +background-position:100% 45%; +} + + + +#home #intro #guide_steps li a { +border-color:#ccc; +color:#fff; +} +#home #intro #step_join-now a { +background-color:#f00; +} +#home #intro #step_start-a-group a { +background-color:#0f0; +} +#home #intro #step_create-a-community a { +background-color:#00f; +} + diff --git a/theme/base/css/ie.css b/theme/base/css/ie.css new file mode 100644 index 000000000..08b027b59 --- /dev/null +++ b/theme/base/css/ie.css @@ -0,0 +1,30 @@ +/* IE specific styles */ + +#aside_primary { +padding-left:11px; +} +.notice-options input.submit { +font-size:0; +margin-top:3px; +height:16px; +text-align:right; +text-indent:0; +color:#fff; +width:24px; +} + +input.checkbox { +top:0; +} + +legend { +margin-left:-7px; +} + +.notice div.entry-content .timestamp a { +margin-right:4px; +} + +.entity_profile .entity_nickname { +padding-right:3px; +} diff --git a/theme/base/css/ie6.css b/theme/base/css/ie6.css new file mode 100644 index 000000000..4a2316903 --- /dev/null +++ b/theme/base/css/ie6.css @@ -0,0 +1,8 @@ +/* IE6 specific styles */ +.entity_profile .entity_nickname, +.entity_profile .entity_location, +.entity_profile .entity_url, +.entity_profile .entity_note, +.entity_profile .entity_tags { +margin-left:55px; +} diff --git a/theme/base/css/ie7.css b/theme/base/css/ie7.css new file mode 100644 index 000000000..a6ee001e2 --- /dev/null +++ b/theme/base/css/ie7.css @@ -0,0 +1,5 @@ +/* IE7 specific styles */ + +#form_notice textarea { +width:370px; +} diff --git a/theme/base/css/jquery.Jcrop.css b/theme/base/css/jquery.Jcrop.css new file mode 100644 index 000000000..6c6dfb503 --- /dev/null +++ b/theme/base/css/jquery.Jcrop.css @@ -0,0 +1,45 @@ +/* Fixes issue here http://code.google.com/p/jcrop/issues/detail?id=1 */ +.jcrop-holder +{ + text-align: left; +} + +.jcrop-vline, .jcrop-hline +{ + font-size: 0; + position: absolute; + background: #fff url(../images/illustrations/illu_jcrop.gif) top left repeat; + /* + opacity: .5; + *filter:alpha(opacity=50); + */ +} +.jcrop-vline { height: 100%; width: 1px !important; } +.jcrop-hline { width: 100%; height: 1px !important; } +.jcrop-handle { + font-size: 1px; + width: 7px !important; + height: 7px !important; + border: 1px #eee solid; + background-color: #333; + /*width: 9px; + height: 9px;*/ +} + +.jcrop-tracker { + /*background-color: gray;*/ + width: 100%; height: 100%; +} + +.custom .jcrop-vline, +.custom .jcrop-hline +{ + background: yellow; +} +.custom .jcrop-handle +{ + border-color: black; + background-color: #C7BB00; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; +} diff --git a/theme/base/css/thickbox.css b/theme/base/css/thickbox.css new file mode 100644 index 000000000..d24b9bedf --- /dev/null +++ b/theme/base/css/thickbox.css @@ -0,0 +1,163 @@ +/* ----------------------------------------------------------------------------------------------------------------*/ +/* ---------->>> global settings needed for thickbox <<<-----------------------------------------------------------*/ +/* ----------------------------------------------------------------------------------------------------------------*/ +*{padding: 0; margin: 0;} + +/* ----------------------------------------------------------------------------------------------------------------*/ +/* ---------->>> thickbox specific link and font settings <<<------------------------------------------------------*/ +/* ----------------------------------------------------------------------------------------------------------------*/ +#TB_window { + font: 12px Arial, Helvetica, sans-serif; + color: #333333; +} + +#TB_secondLine { + font: 10px Arial, Helvetica, sans-serif; + color:#666666; +} + +#TB_window a:link {color: #666666;} +#TB_window a:visited {color: #666666;} +#TB_window a:hover {color: #000;} +#TB_window a:active {color: #666666;} +#TB_window a:focus{color: #666666;} + +/* ----------------------------------------------------------------------------------------------------------------*/ +/* ---------->>> thickbox settings <<<-----------------------------------------------------------------------------*/ +/* ----------------------------------------------------------------------------------------------------------------*/ +#TB_overlay { + position: fixed; + z-index:100; + top: 0px; + left: 0px; + height:100%; + width:100%; +} + +.TB_overlayMacFFBGHack {background: url(macFFBgHack.png) repeat;} +.TB_overlayBG { + background-color:#000; + filter:alpha(opacity=75); + -moz-opacity: 0.75; + opacity: 0.75; +} + +* html #TB_overlay { /* ie6 hack */ + position: absolute; + height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'); +} + +#TB_window { + position: fixed; + background: #ffffff; + z-index: 102; + color:#000000; + display:none; + border: 4px solid #525252; + text-align:left; + top:50%; + left:50%; +} + +* html #TB_window { /* ie6 hack */ +position: absolute; +margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px'); +} + +#TB_window img#TB_Image { + display:block; + margin: 15px 0 0 15px; + border-right: 1px solid #ccc; + border-bottom: 1px solid #ccc; + border-top: 1px solid #666; + border-left: 1px solid #666; +} + +#TB_caption{ + height:25px; + padding:7px 30px 10px 25px; + float:left; +} + +#TB_closeWindow{ + height:25px; + padding:11px 25px 10px 0; + float:right; +} + +#TB_closeAjaxWindow{ + padding:7px 10px 5px 0; + margin-bottom:1px; + text-align:right; + float:right; +} + +#TB_ajaxWindowTitle{ + float:left; + padding:7px 0 5px 10px; + margin-bottom:1px; +} + +#TB_title{ + background-color:#e8e8e8; + height:27px; +} + +#TB_ajaxContent{ + clear:both; + padding:2px 15px 15px 15px; + overflow:auto; + text-align:left; + line-height:1.4em; +} + +#TB_ajaxContent.TB_modal{ + padding:15px; +} + +#TB_ajaxContent p{ + padding:5px 0px 5px 0px; +} + +#TB_load{ + position: fixed; + display:none; + height:13px; + width:208px; + z-index:103; + top: 50%; + left: 50%; + margin: -6px 0 0 -104px; /* -height/2 0 0 -width/2 */ +} + +* html #TB_load { /* ie6 hack */ +position: absolute; +margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + 'px'); +} + +#TB_HideSelect{ + z-index:99; + position:fixed; + top: 0; + left: 0; + background-color:#fff; + border:none; + filter:alpha(opacity=0); + -moz-opacity: 0; + opacity: 0; + height:100%; + width:100%; +} + +* html #TB_HideSelect { /* ie6 hack */ + position: absolute; + height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'); +} + +#TB_iframeContent{ + clear:both; + border:none; + margin-bottom:-1px; + margin-top:1px; + _margin-bottom:1px; +} diff --git a/theme/base/images/icons/icon_atom.jpg b/theme/base/images/icons/icon_atom.jpg Binary files differnew file mode 100644 index 000000000..22853edc4 --- /dev/null +++ b/theme/base/images/icons/icon_atom.jpg diff --git a/theme/base/images/icons/icon_foaf.gif b/theme/base/images/icons/icon_foaf.gif Binary files differnew file mode 100644 index 000000000..f8f784423 --- /dev/null +++ b/theme/base/images/icons/icon_foaf.gif diff --git a/theme/base/images/icons/icon_rss.jpg b/theme/base/images/icons/icon_rss.jpg Binary files differnew file mode 100644 index 000000000..da23422d0 --- /dev/null +++ b/theme/base/images/icons/icon_rss.jpg diff --git a/theme/base/images/icons/icon_vcard.gif b/theme/base/images/icons/icon_vcard.gif Binary files differnew file mode 100644 index 000000000..6d52947f3 --- /dev/null +++ b/theme/base/images/icons/icon_vcard.gif diff --git a/theme/base/images/illustrations/illu_jcrop.gif b/theme/base/images/illustrations/illu_jcrop.gif Binary files differnew file mode 100644 index 000000000..72ea7ccb5 --- /dev/null +++ b/theme/base/images/illustrations/illu_jcrop.gif diff --git a/theme/base/images/illustrations/illu_progress_loading-01.gif b/theme/base/images/illustrations/illu_progress_loading-01.gif Binary files differnew file mode 100644 index 000000000..82290f483 --- /dev/null +++ b/theme/base/images/illustrations/illu_progress_loading-01.gif diff --git a/theme/default/css/display.css b/theme/default/css/display.css new file mode 100644 index 000000000..c68b0a3c4 --- /dev/null +++ b/theme/default/css/display.css @@ -0,0 +1,281 @@ +/** theme: default + * + * @package Laconica + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +html, +body, +a:active { +background-color:#97BFD1; +} +body { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +font-size:1em; +} +address { +margin-right:71px; +} +address .fn { +display:none; +} + +input, textarea, select, option { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +} + + +input.submit, +#form_notice.warning #notice_text-count, +#nav_register a, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:#A9BF4F; +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#A9BF4F; +} +input.submit, +#nav_register a, +.entity_remote_subscribe { +color:#fff; +} + +a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +#entity_send-a-message a, +.form_user_nudge input.submit, +#entity_nudge p { +color:#002E6E; +} + +.notice, +.profile { +border-top-color:#D1D9E4; +} +.section .notice, +.section .profile { +border-top-color:#97BFD1; +} + + +#content .notice p.entry-content a:visited { +background-color:#fcfcfc; +} +#content .notice p.entry-content .vcard a { +background-color:#fcfffc; +} + +#aside_primary { +background-color:#CEE1E9; +} + + +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +} + +#form_notice #notice_data-attach_view { +background-image:url(../images/icons/twotone/green/paper-clip.gif); +background-repeat:no-repeat; +background-position:0 45%; +background-color:transparent; +} + +#nav_register a { +text-decoration:none; +font-weight:bold; +padding:2px 4px; +} + +#content, +#site_nav_local_views a { +border-color:#fff; +} +#content, +#site_nav_local_views .current a { +background-color:#fff; +} + +#site_nav_local_views a { +background-color:rgba(255, 255, 255, 0.2); +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.7); +} + + + + +#page_notice .error { +background-color:#F7E8E8; +} +#page_notice .success { +background-color:#EFF3DC; +} + + +#anon_notice { +background-color:#97BFD1; +color:#fff; +border-color:#fff; +} + +#showstream #anon_notice { +background-color:#A9BF4F; +} + + + + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.jpg); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.jpg); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} +#export_data li a.export_vcard { +background-image:url(../../base/images/icons/icon_vcard.gif); +} + + +#entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +#entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#A9BF4F; +color:#fff; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit { +background-color:#97BFD1; +} + +#entity_send-a-message a { +background-image:url(../images/icons/twotone/green/quote.gif); +} +#entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../images/icons/twotone/green/shield.gif); +} + + + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-data a span { +background-color:transparent; +background-repeat:no-repeat; +background-position:0 45%; +} +.notice_video .notice-data a span { +background-image:url(../images/icons/twotone/green/camera.gif); +} +.notice_audio .notice-data a span { +background-image:url(../images/icons/twotone/green/music.gif); +} +.notice_image .notice-data a span { +background-image:url(../images/icons/twotone/green/search.gif); +} +.notice_event .notice-data a span { +background-image:url(../images/icons/twotone/green/calendar.gif); +} +.notice_location .notice-data a span { +background-image:url(../images/icons/twotone/green/flag.gif); +} +.notice_document .notice-data a span { +background-image:url(../images/icons/twotone/green/document.gif); +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +.notices li.hover { +background-color:#fcfcfc; +} +/*END: NOTICES */ + + +#groups #new_group a { +background:transparent url(../images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +} +.pagination .nav_prev a { +background-image:url(../images/icons/twotone/green/arrow-left.gif); +background-position:0 45%; +} +.pagination .nav_next a { +background-image:url(../images/icons/twotone/green/arrow-right.gif); +background-position:100% 45%; +} diff --git a/theme/default/display.css b/theme/default/display.css index 0b894550c..f22f9aa69 100644 --- a/theme/default/display.css +++ b/theme/default/display.css @@ -440,6 +440,32 @@ p.time a { float: left; margin: 0 10px 18px 0; } + +#profilesettings { + margin-bottom:2em; +} + + +.avatar_view { + float:left; + margin-bottom:1em; + margin-right:1em; +} + +#avatar_preview_view { + overflow:hidden; + width:96px; + height:96px; +} +#avatar_crop { + margin-bottom:2em; +} + +#avatar_crop, +#avatarfile { + clear:both; +} + a.nickname { font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; diff --git a/theme/default/images/icons/icon_atom.jpg b/theme/default/images/icons/icon_atom.jpg Binary files differnew file mode 100644 index 000000000..22853edc4 --- /dev/null +++ b/theme/default/images/icons/icon_atom.jpg diff --git a/theme/default/images/icons/icon_foaf.gif b/theme/default/images/icons/icon_foaf.gif Binary files differnew file mode 100644 index 000000000..f8f784423 --- /dev/null +++ b/theme/default/images/icons/icon_foaf.gif diff --git a/theme/default/images/icons/icon_rss.jpg b/theme/default/images/icons/icon_rss.jpg Binary files differnew file mode 100644 index 000000000..da23422d0 --- /dev/null +++ b/theme/default/images/icons/icon_rss.jpg diff --git a/theme/default/images/icons/icon_vcard.gif b/theme/default/images/icons/icon_vcard.gif Binary files differnew file mode 100644 index 000000000..6d52947f3 --- /dev/null +++ b/theme/default/images/icons/icon_vcard.gif diff --git a/theme/default/images/icons/twotone/green/against.gif b/theme/default/images/icons/twotone/green/against.gif Binary files differnew file mode 100644 index 000000000..ca796c8a3 --- /dev/null +++ b/theme/default/images/icons/twotone/green/against.gif diff --git a/theme/default/images/icons/twotone/green/arrow-down.gif b/theme/default/images/icons/twotone/green/arrow-down.gif Binary files differnew file mode 100644 index 000000000..c709e5877 --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-down.gif diff --git a/theme/default/images/icons/twotone/green/arrow-downleft.gif b/theme/default/images/icons/twotone/green/arrow-downleft.gif Binary files differnew file mode 100644 index 000000000..a4a98035d --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-downleft.gif diff --git a/theme/default/images/icons/twotone/green/arrow-downright.gif b/theme/default/images/icons/twotone/green/arrow-downright.gif Binary files differnew file mode 100644 index 000000000..3e6001a61 --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-downright.gif diff --git a/theme/default/images/icons/twotone/green/arrow-left.gif b/theme/default/images/icons/twotone/green/arrow-left.gif Binary files differnew file mode 100644 index 000000000..afed19084 --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-left.gif diff --git a/theme/default/images/icons/twotone/green/arrow-right.gif b/theme/default/images/icons/twotone/green/arrow-right.gif Binary files differnew file mode 100644 index 000000000..ee1707ed9 --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-right.gif diff --git a/theme/default/images/icons/twotone/green/arrow-up.gif b/theme/default/images/icons/twotone/green/arrow-up.gif Binary files differnew file mode 100644 index 000000000..d0f5fbeaa --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-up.gif diff --git a/theme/default/images/icons/twotone/green/arrow-upleft.gif b/theme/default/images/icons/twotone/green/arrow-upleft.gif Binary files differnew file mode 100644 index 000000000..1e9e6935b --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-upleft.gif diff --git a/theme/default/images/icons/twotone/green/arrow-upright.gif b/theme/default/images/icons/twotone/green/arrow-upright.gif Binary files differnew file mode 100644 index 000000000..c7fecc8a0 --- /dev/null +++ b/theme/default/images/icons/twotone/green/arrow-upright.gif diff --git a/theme/default/images/icons/twotone/green/back-forth.gif b/theme/default/images/icons/twotone/green/back-forth.gif Binary files differnew file mode 100644 index 000000000..33a9540c8 --- /dev/null +++ b/theme/default/images/icons/twotone/green/back-forth.gif diff --git a/theme/default/images/icons/twotone/green/bookmark.gif b/theme/default/images/icons/twotone/green/bookmark.gif Binary files differnew file mode 100644 index 000000000..23f318ecc --- /dev/null +++ b/theme/default/images/icons/twotone/green/bookmark.gif diff --git a/theme/default/images/icons/twotone/green/bulb.gif b/theme/default/images/icons/twotone/green/bulb.gif Binary files differnew file mode 100644 index 000000000..f70652c03 --- /dev/null +++ b/theme/default/images/icons/twotone/green/bulb.gif diff --git a/theme/default/images/icons/twotone/green/calendar.gif b/theme/default/images/icons/twotone/green/calendar.gif Binary files differnew file mode 100644 index 000000000..a09b65aca --- /dev/null +++ b/theme/default/images/icons/twotone/green/calendar.gif diff --git a/theme/default/images/icons/twotone/green/calendar2.gif b/theme/default/images/icons/twotone/green/calendar2.gif Binary files differnew file mode 100644 index 000000000..7884b02dd --- /dev/null +++ b/theme/default/images/icons/twotone/green/calendar2.gif diff --git a/theme/default/images/icons/twotone/green/camera.gif b/theme/default/images/icons/twotone/green/camera.gif Binary files differnew file mode 100644 index 000000000..1a85fbad0 --- /dev/null +++ b/theme/default/images/icons/twotone/green/camera.gif diff --git a/theme/default/images/icons/twotone/green/cart.gif b/theme/default/images/icons/twotone/green/cart.gif Binary files differnew file mode 100644 index 000000000..47eaa0a2e --- /dev/null +++ b/theme/default/images/icons/twotone/green/cart.gif diff --git a/theme/default/images/icons/twotone/green/caution.gif b/theme/default/images/icons/twotone/green/caution.gif Binary files differnew file mode 100644 index 000000000..3ad2c322b --- /dev/null +++ b/theme/default/images/icons/twotone/green/caution.gif diff --git a/theme/default/images/icons/twotone/green/chart.gif b/theme/default/images/icons/twotone/green/chart.gif Binary files differnew file mode 100644 index 000000000..136d74517 --- /dev/null +++ b/theme/default/images/icons/twotone/green/chart.gif diff --git a/theme/default/images/icons/twotone/green/checkmark.gif b/theme/default/images/icons/twotone/green/checkmark.gif Binary files differnew file mode 100644 index 000000000..892429d48 --- /dev/null +++ b/theme/default/images/icons/twotone/green/checkmark.gif diff --git a/theme/default/images/icons/twotone/green/clipboard.gif b/theme/default/images/icons/twotone/green/clipboard.gif Binary files differnew file mode 100644 index 000000000..9317bdcd0 --- /dev/null +++ b/theme/default/images/icons/twotone/green/clipboard.gif diff --git a/theme/default/images/icons/twotone/green/clock.gif b/theme/default/images/icons/twotone/green/clock.gif Binary files differnew file mode 100644 index 000000000..d1410f925 --- /dev/null +++ b/theme/default/images/icons/twotone/green/clock.gif diff --git a/theme/default/images/icons/twotone/green/closed-folder.gif b/theme/default/images/icons/twotone/green/closed-folder.gif Binary files differnew file mode 100644 index 000000000..0410fc6e8 --- /dev/null +++ b/theme/default/images/icons/twotone/green/closed-folder.gif diff --git a/theme/default/images/icons/twotone/green/database.gif b/theme/default/images/icons/twotone/green/database.gif Binary files differnew file mode 100644 index 000000000..29ce02492 --- /dev/null +++ b/theme/default/images/icons/twotone/green/database.gif diff --git a/theme/default/images/icons/twotone/green/disfavourite.gif b/theme/default/images/icons/twotone/green/disfavourite.gif Binary files differnew file mode 100644 index 000000000..3946869ae --- /dev/null +++ b/theme/default/images/icons/twotone/green/disfavourite.gif diff --git a/theme/default/images/icons/twotone/green/diskette.gif b/theme/default/images/icons/twotone/green/diskette.gif Binary files differnew file mode 100644 index 000000000..e970b0a30 --- /dev/null +++ b/theme/default/images/icons/twotone/green/diskette.gif diff --git a/theme/default/images/icons/twotone/green/document.gif b/theme/default/images/icons/twotone/green/document.gif Binary files differnew file mode 100644 index 000000000..9c08f4a3a --- /dev/null +++ b/theme/default/images/icons/twotone/green/document.gif diff --git a/theme/default/images/icons/twotone/green/double-arrow.gif b/theme/default/images/icons/twotone/green/double-arrow.gif Binary files differnew file mode 100644 index 000000000..2e8648264 --- /dev/null +++ b/theme/default/images/icons/twotone/green/double-arrow.gif diff --git a/theme/default/images/icons/twotone/green/edit.gif b/theme/default/images/icons/twotone/green/edit.gif Binary files differnew file mode 100644 index 000000000..c746aca60 --- /dev/null +++ b/theme/default/images/icons/twotone/green/edit.gif diff --git a/theme/default/images/icons/twotone/green/eject.gif b/theme/default/images/icons/twotone/green/eject.gif Binary files differnew file mode 100644 index 000000000..7e0906cfe --- /dev/null +++ b/theme/default/images/icons/twotone/green/eject.gif diff --git a/theme/default/images/icons/twotone/green/exclaim.gif b/theme/default/images/icons/twotone/green/exclaim.gif Binary files differnew file mode 100644 index 000000000..588e28c26 --- /dev/null +++ b/theme/default/images/icons/twotone/green/exclaim.gif diff --git a/theme/default/images/icons/twotone/green/fastforward.gif b/theme/default/images/icons/twotone/green/fastforward.gif Binary files differnew file mode 100644 index 000000000..28e495103 --- /dev/null +++ b/theme/default/images/icons/twotone/green/fastforward.gif diff --git a/theme/default/images/icons/twotone/green/favourite.gif b/theme/default/images/icons/twotone/green/favourite.gif Binary files differnew file mode 100644 index 000000000..d93515e37 --- /dev/null +++ b/theme/default/images/icons/twotone/green/favourite.gif diff --git a/theme/default/images/icons/twotone/green/flag.gif b/theme/default/images/icons/twotone/green/flag.gif Binary files differnew file mode 100644 index 000000000..68c8aee25 --- /dev/null +++ b/theme/default/images/icons/twotone/green/flag.gif diff --git a/theme/default/images/icons/twotone/green/graph.gif b/theme/default/images/icons/twotone/green/graph.gif Binary files differnew file mode 100644 index 000000000..0c1794b4e --- /dev/null +++ b/theme/default/images/icons/twotone/green/graph.gif diff --git a/theme/default/images/icons/twotone/green/grow.gif b/theme/default/images/icons/twotone/green/grow.gif Binary files differnew file mode 100644 index 000000000..c4118d53b --- /dev/null +++ b/theme/default/images/icons/twotone/green/grow.gif diff --git a/theme/default/images/icons/twotone/green/headphones.gif b/theme/default/images/icons/twotone/green/headphones.gif Binary files differnew file mode 100644 index 000000000..5be6c67dd --- /dev/null +++ b/theme/default/images/icons/twotone/green/headphones.gif diff --git a/theme/default/images/icons/twotone/green/home.gif b/theme/default/images/icons/twotone/green/home.gif Binary files differnew file mode 100644 index 000000000..d2a3421ef --- /dev/null +++ b/theme/default/images/icons/twotone/green/home.gif diff --git a/theme/default/images/icons/twotone/green/hourglass.gif b/theme/default/images/icons/twotone/green/hourglass.gif Binary files differnew file mode 100644 index 000000000..b62b9480c --- /dev/null +++ b/theme/default/images/icons/twotone/green/hourglass.gif diff --git a/theme/default/images/icons/twotone/green/info.gif b/theme/default/images/icons/twotone/green/info.gif Binary files differnew file mode 100644 index 000000000..86ef1f8b4 --- /dev/null +++ b/theme/default/images/icons/twotone/green/info.gif diff --git a/theme/default/images/icons/twotone/green/key.gif b/theme/default/images/icons/twotone/green/key.gif Binary files differnew file mode 100644 index 000000000..ccf357ab2 --- /dev/null +++ b/theme/default/images/icons/twotone/green/key.gif diff --git a/theme/default/images/icons/twotone/green/lock.gif b/theme/default/images/icons/twotone/green/lock.gif Binary files differnew file mode 100644 index 000000000..db00706b5 --- /dev/null +++ b/theme/default/images/icons/twotone/green/lock.gif diff --git a/theme/default/images/icons/twotone/green/mail.gif b/theme/default/images/icons/twotone/green/mail.gif Binary files differnew file mode 100644 index 000000000..1084c862f --- /dev/null +++ b/theme/default/images/icons/twotone/green/mail.gif diff --git a/theme/default/images/icons/twotone/green/move.gif b/theme/default/images/icons/twotone/green/move.gif Binary files differnew file mode 100644 index 000000000..d2c30b1d2 --- /dev/null +++ b/theme/default/images/icons/twotone/green/move.gif diff --git a/theme/default/images/icons/twotone/green/music.gif b/theme/default/images/icons/twotone/green/music.gif Binary files differnew file mode 100644 index 000000000..64b51d4e1 --- /dev/null +++ b/theme/default/images/icons/twotone/green/music.gif diff --git a/theme/default/images/icons/twotone/green/news.gif b/theme/default/images/icons/twotone/green/news.gif Binary files differnew file mode 100644 index 000000000..712c685dc --- /dev/null +++ b/theme/default/images/icons/twotone/green/news.gif diff --git a/theme/default/images/icons/twotone/green/note.gif b/theme/default/images/icons/twotone/green/note.gif Binary files differnew file mode 100644 index 000000000..bcc0b149b --- /dev/null +++ b/theme/default/images/icons/twotone/green/note.gif diff --git a/theme/default/images/icons/twotone/green/open-folder.gif b/theme/default/images/icons/twotone/green/open-folder.gif Binary files differnew file mode 100644 index 000000000..d41300a08 --- /dev/null +++ b/theme/default/images/icons/twotone/green/open-folder.gif diff --git a/theme/default/images/icons/twotone/green/paper-clip.gif b/theme/default/images/icons/twotone/green/paper-clip.gif Binary files differnew file mode 100644 index 000000000..1d45f1d1e --- /dev/null +++ b/theme/default/images/icons/twotone/green/paper-clip.gif diff --git a/theme/default/images/icons/twotone/green/paper-clip2.gif b/theme/default/images/icons/twotone/green/paper-clip2.gif Binary files differnew file mode 100644 index 000000000..a8c7805be --- /dev/null +++ b/theme/default/images/icons/twotone/green/paper-clip2.gif diff --git a/theme/default/images/icons/twotone/green/pause.gif b/theme/default/images/icons/twotone/green/pause.gif Binary files differnew file mode 100644 index 000000000..ced0b6440 --- /dev/null +++ b/theme/default/images/icons/twotone/green/pause.gif diff --git a/theme/default/images/icons/twotone/green/phone.gif b/theme/default/images/icons/twotone/green/phone.gif Binary files differnew file mode 100644 index 000000000..69359f764 --- /dev/null +++ b/theme/default/images/icons/twotone/green/phone.gif diff --git a/theme/default/images/icons/twotone/green/play.gif b/theme/default/images/icons/twotone/green/play.gif Binary files differnew file mode 100644 index 000000000..794ec85b6 --- /dev/null +++ b/theme/default/images/icons/twotone/green/play.gif diff --git a/theme/default/images/icons/twotone/green/plus.gif b/theme/default/images/icons/twotone/green/plus.gif Binary files differnew file mode 100644 index 000000000..4407d0b2d --- /dev/null +++ b/theme/default/images/icons/twotone/green/plus.gif diff --git a/theme/default/images/icons/twotone/green/print.gif b/theme/default/images/icons/twotone/green/print.gif Binary files differnew file mode 100644 index 000000000..17727d5d7 --- /dev/null +++ b/theme/default/images/icons/twotone/green/print.gif diff --git a/theme/default/images/icons/twotone/green/question-mark.gif b/theme/default/images/icons/twotone/green/question-mark.gif Binary files differnew file mode 100644 index 000000000..1689efcd0 --- /dev/null +++ b/theme/default/images/icons/twotone/green/question-mark.gif diff --git a/theme/default/images/icons/twotone/green/quote.gif b/theme/default/images/icons/twotone/green/quote.gif Binary files differnew file mode 100644 index 000000000..4ba1f0c03 --- /dev/null +++ b/theme/default/images/icons/twotone/green/quote.gif diff --git a/theme/default/images/icons/twotone/green/refresh.gif b/theme/default/images/icons/twotone/green/refresh.gif Binary files differnew file mode 100644 index 000000000..8a8b8144f --- /dev/null +++ b/theme/default/images/icons/twotone/green/refresh.gif diff --git a/theme/default/images/icons/twotone/green/reply.gif b/theme/default/images/icons/twotone/green/reply.gif Binary files differnew file mode 100644 index 000000000..6ff01bb35 --- /dev/null +++ b/theme/default/images/icons/twotone/green/reply.gif diff --git a/theme/default/images/icons/twotone/green/rewind.gif b/theme/default/images/icons/twotone/green/rewind.gif Binary files differnew file mode 100644 index 000000000..aca3ee35b --- /dev/null +++ b/theme/default/images/icons/twotone/green/rewind.gif diff --git a/theme/default/images/icons/twotone/green/search.gif b/theme/default/images/icons/twotone/green/search.gif Binary files differnew file mode 100644 index 000000000..c36463d0d --- /dev/null +++ b/theme/default/images/icons/twotone/green/search.gif diff --git a/theme/default/images/icons/twotone/green/shield.gif b/theme/default/images/icons/twotone/green/shield.gif Binary files differnew file mode 100644 index 000000000..419d5ee4b --- /dev/null +++ b/theme/default/images/icons/twotone/green/shield.gif diff --git a/theme/default/images/icons/twotone/green/skip-back.gif b/theme/default/images/icons/twotone/green/skip-back.gif Binary files differnew file mode 100644 index 000000000..adca7aa3e --- /dev/null +++ b/theme/default/images/icons/twotone/green/skip-back.gif diff --git a/theme/default/images/icons/twotone/green/skip.gif b/theme/default/images/icons/twotone/green/skip.gif Binary files differnew file mode 100644 index 000000000..ae5417f2f --- /dev/null +++ b/theme/default/images/icons/twotone/green/skip.gif diff --git a/theme/default/images/icons/twotone/green/skull.gif b/theme/default/images/icons/twotone/green/skull.gif Binary files differnew file mode 100644 index 000000000..033506732 --- /dev/null +++ b/theme/default/images/icons/twotone/green/skull.gif diff --git a/theme/default/images/icons/twotone/green/statusbar.gif b/theme/default/images/icons/twotone/green/statusbar.gif Binary files differnew file mode 100644 index 000000000..47d61b106 --- /dev/null +++ b/theme/default/images/icons/twotone/green/statusbar.gif diff --git a/theme/default/images/icons/twotone/green/stop.gif b/theme/default/images/icons/twotone/green/stop.gif Binary files differnew file mode 100644 index 000000000..e0b108d35 --- /dev/null +++ b/theme/default/images/icons/twotone/green/stop.gif diff --git a/theme/default/images/icons/twotone/green/template.gif b/theme/default/images/icons/twotone/green/template.gif Binary files differnew file mode 100644 index 000000000..65c0c4a0a --- /dev/null +++ b/theme/default/images/icons/twotone/green/template.gif diff --git a/theme/default/images/icons/twotone/green/text-bigger.gif b/theme/default/images/icons/twotone/green/text-bigger.gif Binary files differnew file mode 100644 index 000000000..45e143b7a --- /dev/null +++ b/theme/default/images/icons/twotone/green/text-bigger.gif diff --git a/theme/default/images/icons/twotone/green/text-smaller.gif b/theme/default/images/icons/twotone/green/text-smaller.gif Binary files differnew file mode 100644 index 000000000..a54d0c1d3 --- /dev/null +++ b/theme/default/images/icons/twotone/green/text-smaller.gif diff --git a/theme/default/images/icons/twotone/green/trash.gif b/theme/default/images/icons/twotone/green/trash.gif Binary files differnew file mode 100644 index 000000000..78dd64a3d --- /dev/null +++ b/theme/default/images/icons/twotone/green/trash.gif diff --git a/theme/default/images/icons/twotone/green/two-docs.gif b/theme/default/images/icons/twotone/green/two-docs.gif Binary files differnew file mode 100644 index 000000000..97e54b964 --- /dev/null +++ b/theme/default/images/icons/twotone/green/two-docs.gif diff --git a/theme/default/images/icons/twotone/green/twotone.gif b/theme/default/images/icons/twotone/green/twotone.gif Binary files differnew file mode 100644 index 000000000..45aad25c4 --- /dev/null +++ b/theme/default/images/icons/twotone/green/twotone.gif diff --git a/theme/default/images/icons/twotone/green/undo.gif b/theme/default/images/icons/twotone/green/undo.gif Binary files differnew file mode 100644 index 000000000..6869b3050 --- /dev/null +++ b/theme/default/images/icons/twotone/green/undo.gif diff --git a/theme/default/images/icons/twotone/green/user.gif b/theme/default/images/icons/twotone/green/user.gif Binary files differnew file mode 100644 index 000000000..c85460fcd --- /dev/null +++ b/theme/default/images/icons/twotone/green/user.gif diff --git a/theme/default/images/icons/twotone/green/vegetable.gif b/theme/default/images/icons/twotone/green/vegetable.gif Binary files differnew file mode 100644 index 000000000..4d421c1bb --- /dev/null +++ b/theme/default/images/icons/twotone/green/vegetable.gif diff --git a/theme/default/images/icons/twotone/green/x.gif b/theme/default/images/icons/twotone/green/x.gif Binary files differnew file mode 100644 index 000000000..ffb2efea0 --- /dev/null +++ b/theme/default/images/icons/twotone/green/x.gif diff --git a/theme/default/images/icons/twotone/green/zoom-in.gif b/theme/default/images/icons/twotone/green/zoom-in.gif Binary files differnew file mode 100644 index 000000000..a59a5bb50 --- /dev/null +++ b/theme/default/images/icons/twotone/green/zoom-in.gif diff --git a/theme/default/images/icons/twotone/green/zoom-out.gif b/theme/default/images/icons/twotone/green/zoom-out.gif Binary files differnew file mode 100644 index 000000000..c61f999fd --- /dev/null +++ b/theme/default/images/icons/twotone/green/zoom-out.gif diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css new file mode 100644 index 000000000..f61d063b6 --- /dev/null +++ b/theme/identica/css/display.css @@ -0,0 +1,281 @@ +/** theme: identica + * + * @package Laconica + * @author Sarven Capadisli <csarven@controlyourself.ca> + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +html, +body, +a:active { +background-color:#ddd; +} +body { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +font-size:1em; +} +address { +margin-right:71px; +} +address .fn { +display:none; +} + +input, textarea, select, option { +font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; +} +input, textarea, select, +.entity_remote_subscribe { +border-color:#aaa; +} + + +input.submit, +#form_notice.warning #notice_text-count, +#nav_register a, +.form_settings .form_note, +.entity_remote_subscribe { +background-color:#A9BF4F; +} + +input:focus, textarea:focus, select:focus, +#form_notice.warning #notice_data-text { +border-color:#A9BF4F; +} +input.submit, +#nav_register a, +.entity_remote_subscribe { +color:#fff; +} + +a, +div.notice-options input, +.form_user_block input.submit, +.form_user_unblock input.submit, +#entity_send-a-message a, +.form_user_nudge input.submit, +#entity_nudge p { +color:#002E6E; +} + +.notice, +.profile { +border-top-color:#D1D9E4; +} +.section .notice, +.section .profile { +border-top-color:#97BFD1; +} + + +#content .notice p.entry-content a:visited { +background-color:#fcfcfc; +} +#content .notice p.entry-content .vcard a { +background-color:#fcfffc; +} + +#aside_primary { +background-color:#CEE1E9; +} + + +#notice_text-count { +color:#333; +} +#form_notice.warning #notice_text-count { +color:#000; +} + +#form_notice #notice_data-attach_view { +background-image:url(../images/icons/twotone/green/paper-clip.gif); +background-repeat:no-repeat; +background-position:0 45%; +background-color:transparent; +} + +#nav_register a { +text-decoration:none; +font-weight:bold; +padding:2px 4px; +} + +#content, +#site_nav_local_views a { +border-color:#fff; +} +#content, +#site_nav_local_views .current a { +background-color:#fff; +} + +#site_nav_local_views a { +background-color:rgba(255, 255, 255, 0.2); +} +#site_nav_local_views a:hover { +background-color:rgba(255, 255, 255, 0.7); +} + + + + +#page_notice .error { +background-color:#F7E8E8; +} +#page_notice .success { +background-color:#EFF3DC; +} + + +#anon_notice { +background-color:#97BFD1; +color:#fff; +border-color:#fff; +} + +#showstream #anon_notice { +background-color:#A9BF4F; +} + + + + +#export_data li a { +background-repeat:no-repeat; +background-position:0 45%; +} +#export_data li a.rss { +background-image:url(../../base/images/icons/icon_rss.jpg); +} +#export_data li a.atom { +background-image:url(../../base/images/icons/icon_atom.jpg); +} +#export_data li a.foaf { +background-image:url(../../base/images/icons/icon_foaf.gif); +} +#export_data li a.export_vcard { +background-image:url(../../base/images/icons/icon_vcard.gif); +} + + +#entity_send-a-message a, +.form_user_nudge input.submit, +.form_user_block input.submit, +.form_user_unblock input.submit, +#entity_nudge p { +background-position: 0 40%; +background-repeat: no-repeat; +background-color:transparent; +} +.form_group_join input.submit, +.form_group_leave input.submit +.form_user_subscribe input.submit, +.form_user_unsubscribe input.submit { +background-color:#A9BF4F; +color:#fff; +} +.form_user_unsubscribe input.submit, +.form_group_leave input.submit { +background-color:#97BFD1; +} + +#entity_send-a-message a { +background-image:url(../images/icons/twotone/green/quote.gif); +} +#entity_nudge p, +.form_user_nudge input.submit { +background-image:url(../images/icons/twotone/green/mail.gif); +} +.form_user_block input.submit, +.form_user_unblock input.submit { +background-image:url(../images/icons/twotone/green/shield.gif); +} + + + +/* NOTICES */ +.notices li.over { +background-color:#fcfcfc; +} + +.notice-data a span { +background-color:transparent; +background-repeat:no-repeat; +background-position:0 45%; +} +.notice_video .notice-data a span { +background-image:url(../images/icons/twotone/green/camera.gif); +} +.notice_audio .notice-data a span { +background-image:url(../images/icons/twotone/green/music.gif); +} +.notice_image .notice-data a span { +background-image:url(../images/icons/twotone/green/search.gif); +} +.notice_event .notice-data a span { +background-image:url(../images/icons/twotone/green/calendar.gif); +} +.notice_location .notice-data a span { +background-image:url(../images/icons/twotone/green/flag.gif); +} +.notice_document .notice-data a span { +background-image:url(../images/icons/twotone/green/document.gif); +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +background-color:transparent; +} +.notice-options .notice_reply a { +background:transparent url(../images/icons/twotone/green/reply.gif) no-repeat 0 45%; +} +.notice-options form.form_favor input.submit { +background:transparent url(../images/icons/twotone/green/favourite.gif) no-repeat 0 45%; +} +.notice-options form.form_disfavor input.submit { +background:transparent url(../images/icons/twotone/green/disfavourite.gif) no-repeat 0 45%; +} +.notice-options .notice_delete a { +background:transparent url(../images/icons/twotone/green/trash.gif) no-repeat 0 45%; +} + +.notices div.entry-content, +.notices div.notice-options { +opacity:0.4; +} +.notices li.hover div.entry-content, +.notices li.hover div.notice-options { +opacity:1; +} +div.entry-content { +color:#333; +} +div.notice-options a, +div.notice-options input { +font-family:sans-serif; +} +.notices li.hover { +background-color:#fcfcfc; +} +/*END: NOTICES */ + + +#groups #new_group a { +background:transparent url(../images/icons/twotone/green/news.gif) no-repeat 0 45%; +} + + +.pagination .nav_prev a, +.pagination .nav_next a { +background-repeat:no-repeat; +} +.pagination .nav_prev a { +background-image:url(../images/icons/twotone/green/arrow-left.gif); +background-position:0 45%; +} +.pagination .nav_next a { +background-image:url(../images/icons/twotone/green/arrow-right.gif); +background-position:100% 45%; +} diff --git a/theme/identica/css/facebookapp.theme.css b/theme/identica/css/facebookapp.theme.css new file mode 100644 index 000000000..716f3256f --- /dev/null +++ b/theme/identica/css/facebookapp.theme.css @@ -0,0 +1,1177 @@ +/* theme: base */ +* { margin:0; padding:0; } +img { display:block; border:0; } +a abbr { cursor: pointer; border-bottom:0; } +table { border-collapse:collapse; } +ol { list-style-position:inside; } +html { font-size: 87.5%; background-color:#fff; height:100%; } +body { +background-color:#fff; +color:#000; +font-family:sans-serif; +font-size:1em; +line-height:1.65; +position:relative; +margin:0 auto; +width:1004px; +width:71.714em; +} +h1,h2,h3,h4,h5,h6 { + text-transform:uppercase; + margin-bottom:7px; +} +h1 { +font-size:1.4em; +line-height:1; +margin-bottom:18px; +} +h2 { font-size:1.3em; } +h3 { font-size:1.2em; } +h4 { font-size:1.1em; } +h5 { font-size:1em; } +h6 { font-size:0.9em; } + +caption { +font-weight:bold; +} +.opened { display: block !important;} +.closed { display: none !important;} + +legend { +font-weight:bold; +font-size:1.3em; +text-transform:uppercase; +} +form { +} +input, textarea, select, option { +padding:4px; +font-family:sans-serif; +font-size:1em; +} +input, textarea, select { +border-width:2px; +border-style: solid; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +input.submit { +font-weight:bold; +} +textarea { +overflow:auto; +} +select, option { +padding-bottom:0; +} +fieldset { +padding:0; +border:0; +} +form ul li { +list-style-type:none; +margin:0 0 18px 0; +} +form label { +font-weight:bold; +/*margin:0 0 11px 0;*/ +} +form ul li input { +} + +input.checkbox { +position:relative; +top:2px; +left:0; +border:0; +} + +#page_notice .error, +#page_notice .success { +padding:4px 7px; +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +} +form label.submit { +display:none; +} +.form_settings input.remove { +margin-left:11px; +} + + + + +/* FORM SETTINGS */ +.form_settings fieldset { +margin-bottom:29px; +} + +.form_guide { +font-style:italic; +} + + +.form_settings .form_datas li { +width:100%; +float:left; +} + +.form_settings .form_datas label { +float:left; +} +.form_settings .form_datas textarea, +.form_settings .form_datas select, +.form_settings .form_datas input { +margin-left:11px; +float:left; +} + +.form_settings label { +margin-top:2px; +width:152px; +} + +.form_actions label { +display:none; +} + +.form_settings #settings_autosubscribe label { +display:inline; +font-weight:bold; +} + +#form_settings_profile legend, +#form_login legend, +#form_register legend { +display:none; +} + +.form_settings .form_datas p.form_guide { +clear:both; +margin-left:163px; +margin-bottom:0; +} + +.form_settings p { +margin-bottom:11px; +} + +.form_settings input.checkbox { +margin-top:3px; +margin-left:0; +} +.form_settings label.checkbox { +font-weight:normal; +margin-top:0; +margin-right:0; +margin-left:11px; +float:left; +width:90%; +} + +#form_login p.form_guide, +#form_register #settings_rememberme p.form_guide { +margin-left:0; +} + + +.form_settings .form_note { +border-radius:4px; +-moz-border-radius:4px; +-webkit-border-radius:4px; +padding:0 7px; +} + +/* FORM SETTINGS */ + + + + +address { +float:left; +margin-bottom:18px; +margin-left:18px; +} +address .fn, +address .email { +display:none; +} + + + +#header { +width:100%; +position:relative; +float:left; +padding-top:18px; +margin-bottom:29px; +} + +#site_nav_global_primary { +float:right; +margin-right:18px; +} +#site_nav_global_primary ul li { +display:inline; +margin-left:11px; +} + + +.system_notice dt { +font-weight:bold; +text-transform:uppercase; +display:none; +} + +#site_notice { +position:absolute; +right:0; +top:49px; +float:right; +width:322px; +} +#page_notice { +clear:both; +margin-bottom:18px; +} + + + + +#footer { +float:left; +width:64%; +padding:18px; +} + + + +#site_nav_local_views { +width:100%; +float:left; +} +#site_nav_local_views dt { +display:none; +} +#site_nav_local_views li { +float:left; +margin-right:18px; +list-style-type:none; +} +#site_nav_local_views a { +float:left; +text-decoration:none; +padding:4px 11px; +-moz-border-radius-topleft:4px; +-moz-border-radius-topright:4px; +-webkit-border-top-left-radius:4px; +-webkit-border-top-right-radius:4px; +border-width:1px; +border-style:solid; +border-bottom:0; +text-shadow: 4px 4px 4px #ddd; +font-weight:bold; +} +#site_nav_local_views .nav { +float:left; +width:100%; +} + + +#site_nav_global_primary dt, +#site_nav_global_secondary dt { +display:none; +} +/* +#site_nav_global_primary .current a { +font-weight:bold; +border-style:solid; +} +*/ +#site_nav_global_secondary { +margin-bottom:11px; +} + +#site_nav_global_secondary ul li { +display:inline; +margin-right:11px; +} +#export_data li a { +padding-left:20px; +} +#export_data li a.foaf { +padding-left:30px; +} +#export_data li a.export_vcard { +padding-left:28px; +} + + + +#export_data ul { +display:inline; +} +#export_data li { +list-style-type:none; +display:inline; +margin-left:11px; +} +#export_data li:first-child { +margin-left:0; +} + + + +#licenses { +font-size:0.9em; +} + +#licenses dt { +font-weight:bold; +display:none; +} +#licenses dd { +margin-bottom:11px; +line-height:1.5; +} + +#site_content_license_cc { +margin-bottom:0; +} +#site_content_license_cc img { +display:inline; +vertical-align:top; +margin-right:4px; +} + + +#wrap { + float:left; + margin:0 auto; + width:1004px; + width:71.714em; +} + + +#core { +position:relative; +width:100%; +float:left; +margin-bottom:1em; +} + +#content { +width:644px; +padding:18px; +float:left; +border-radius:7px; +-moz-border-radius:7px; +-moz-border-radius-topleft:0; +-webkit-border-radius:7px; +-webkit-border-top-left-radius:0; +} + +#content_inner { +position:relative; +width:100%; +float;left; +} + +#aside_primary { +width:300px; +float:left; +margin-left:2px; +padding:18px 4px 18px 18px; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} + + + + +/*Start: FORM NOTICE*/ +#form_notice { +width:384px; +width:458px; +float:left; +margin-left:68px; +position:relative; +line-height:1; +} +#form_notice fieldset { +border:0; +padding:0; +} +#form_notice legend { +display:none; +} +#form_notice textarea { +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +width:377px; +width:370px; +height:86px; +line-height:1.5; +padding:7px 7px 14px 7px; +} +#form_notice label { +display:block; +font-size:1.3em; +margin-bottom:7px; +} +#form_notice .form_datas li { +float:left; +} + +#form_notice #notice_attach_file label, +#form_notice #notice_submit label { +display:none; +} + +#form_notice #notice_attachment { +margin-top:25px; +margin-left:4px; +} + +#form_notice .form_note { +position:absolute; +top:116px; +right:98px; +z-index:9; +} + +#form_notice .form_note dt { +font-weight:bold; +display:none; +} +#notice_text-count { +font-weight:bold; +line-height:1.15; +} + +#form_notice #notice_data-attach_view { +/*position:absolute;*/ +top:25px; +right:30px; +margin-left:4px; +padding:0; +cursor:pointer; +width:16px; +height:16px; +border:0; +text-indent:-9999px; +} +#form_notice .form_actions { +position:absolute; +bottom:0; +right:0; +} +#form_notice .form_actions input.submit { +width:60px; +padding:8px; +} + +#form_notice li { +margin-bottom:0; +} +/*end FORM NOTICE*/ + + + + + +/* user_profile */ +#user_profile { +position:relative; +width:633px; +min-height:123px; +float:left; +margin-bottom:17px; +margin-left:0; +} +#user_profile dt, +#user_statistics dt { +font-weight:bold; +} +#user_profile .user_depiction { +float:left; +position:absolute; +top:0; +left:0; +width:96px; +} +#user_profile .user_fn, +#user_profile .user_nickname, +#user_profile .user_location, +#user_profile .user_url, +#user_profile .user_note, +#user_profile .user_tags { +float:left; +clear:left; +margin-left:125px; +width:322px; +margin-bottom:4px; +} + +#user_profile .user_fn, +#user_profile .user_nickname { +width:auto; +clear:none; +} +#user_profile .user_nickname { +margin-left:11px; +} +#user_profile .user_nickname .nickname { +font-style:italic; +font-weight:bold; +margin-left:4px; +margin-right:4px; +} + +#user_profile .user_nickname dd:before { +content: "("; +} +#user_profile .user_nickname dd:after { +content: ")"; +} + +#user_profile dt { +display:none; +} +#user_profile h2 { +display:none; +} +/* user_profile */ + +/*user_actions*/ +#user_actions { +clear:left; +float:left; +position:absolute; +top:0; +right:0; +} +#user_actions h2 { +display:none; +} +#user_actions ul { +list-style-type:none; +} +#user_actions li { +border-top-width:1px; +border-top-style:dotted; +} +#user_actions li:first-child { +border-top:0; +} +#user_actions fieldset { +border:0; +padding:0; +} +#user_actions legend { +display:none; +} + +#user_actions a, +#user_actions input.submit { +display:block; +text-align:left; +padding:4px 0 4px 19px; +} +#user_actions a { +text-decoration:none; +} +#user_subscribe a, +#TB_window input.submit, +#user_actions input.submit { +border:0; +cursor:pointer; +padding-left:16px; +width:100%; +font-size:0.9em; +} + +#user_subscribe a { +width:auto; +padding-left:20px; +} + +#user_subscribe a, +#TB_window input.submit, +.form_user_subscribe input.submit { +font-weight:bold; +} + + + +#user_send-a-message form { +clear:left; +width:322px; +margin-top:18px; +} + +#user_send-a-message textarea { +width:96%; +} + +.user_tags ul { +list-style-type:none; +} +.user_tags li { +display:inline; +margin-right:1em; +float:left; +} + + + +.aside .section { +margin-bottom:29px; +clear:both; +} +.aside .section h2 { +text-transform:uppercase; +font-size:1em; +} + +#user_statistics dt, +#user_statistics dd { +display:inline; +} +#user_statistics dt:after { +content: ":"; +} + + +#user_subscriptions, +#user_subscriptions-common { +float:left; +} +#user_subscriptions ul.users { +width:220px; +float:left; +} +#user_subscriptions .users li { +list-style-type:none; +float:left; +margin-right:7px; +margin-bottom:7px; +} +#user_subscriptions .users li .photo { +width:24px; +height:24px; +margin-right:0; +} +#user_subscriptions .users li .fn { +display:none; +} +.aside .section .more { +clear:both; +} + + + + + +/* NOTICE */ +.notice { +position:relative; +padding-top:18px; +padding-bottom:18px; +clear:both; +float:left; +width:644px; +width:96.699%; +width:100%; +border-top:1px dashed #D1D9E4; +/*-moz-border-radius:7px;*/ +} +.notices li { +list-style-type:none; +/*margin-bottom:11px;*/ +} + +/* NOTICES */ +#notices_primary { +float:left; +width:644px; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +} +#notices_primary h2 { +display:none; +} +.notice-data a span { +display:block; +padding-left:28px; +} + + +.notice .author { +margin-right:11px; +} +.notice .author a { +} +.notice .author:after { +/*content:":";*/ +} + +.vcard .photo { +display:inline; +margin-right:7px; +margin-bottom:7px; +float:left; +} +.vcard .url { +text-decoration:none; +} +.vcard .url:hover { +text-decoration:underline; +} +.vcard .fn { +font-style:italic; +} +.vcard .fn:hover { + +} + + +.notice .entry-title { +float:left; +width:100%; +} +.notice p.entry-content { +display:inline; +} + +.notice_video p.entry-content, +.notice_audio p.entry-content, +.notice_image p.entry-content, +.notice_location p.entry-content, +.notice_event p.entry-content, +.notice_document p.entry-content { +} +#laconicat .notice p.entry-content { +/*margin-left:199px;*/ +} +.notice p.entry-content a { + +} +.notice p.entry-content a:hover { + +} +.notice p.entry-content .tag a { + +} +.notice p.entry-content .tag a:hover { + +} + + +.notice div.entry-content { +/*border:1px solid blue;*/ +clear:left; +float:left; +width:48%; +font-size:0.95em; +} +.notice div.entry-content a, +.notice .notice-options a, +.notice .notice-options input { + +} +.notice .notice-options a, +.notice .notice-options input { +float:left; +font-size:1.025em; +} + +#laconicat .notice div.entry-content { +/*margin-left:0;*/ +} + +.notice div.entry-content dl, +.notice div.entry-content dt, +.notice div.entry-content dd { +display:inline; +} +.notice div.entry-content .timestamp dt, +.notice div.entry-content .response dt { +display:none; +} +.notice div.entry-content .timestamp a { +display:inline-block; +} +.notice div.entry-content .device dt { +text-transform:lowercase; +} +.notice div.entry-content a { + +} +.notice div.entry-content a:hover { +} + + + +.notice-data { +position:absolute; +top:18px; +right:0; +min-height:50px; +margin-bottom:4px; +} +.notice .entry-content .notice-data dt { +display:none; +} + +.notice-data a { +display:block; +outline:none; +} + +.notice-options { +padding-left:2%; +float:left; +width:50%; +position:relative; +font-size:0.95em; +} + +.notice-options a { +float:left; +} +.notice-options .notice_delete, +.notice-options .notice_reply, +.notice-options .form_favor, +.notice-options .form_disfavor { +position:absolute; +top:0; +} +.notice-options .form_favor, +.notice-options .form_disfavor { +left:0; +} +.notice-options .notice_reply { +left:29px; +} +.notice-options .notice_delete { +left:76px; +} +.notice-options .notice_reply dt { +display:none; +} + +.notice-options input, +.notice-options a { +text-indent:-9999px; +outline:none; +} + +.notice-options .notice_reply a, +.notice-options form input.submit { +display:block; +border:0; +} +.notice-options .notice_reply a, +.notice-options .notice_delete a { +text-decoration:none; +padding-left:16px; +} + +.notice-options .notice_delete { + +} + +.notice-options form input.submit { +cursor:pointer; +width:16px; +padding:2px 0; +} + +.notice-options .notice_delete dt, +.notice-options .form_favor legend, +.notice-options .form_disfavor legend { +display:none; +} +.notice-options .notice_delete fieldset, +.notice-options .form_favor fieldset, +.notice-options .form_disfavor fieldset { +border:0; +padding:0; +} + +/*END: NOTICES */ + + + + + +.pagination dt { +font-weight:bold; +display:none; +} + +.pagination .nav { +float:left; +width:100%; +list-style-type:none; +} + +.pagination .nav_prev { +float:left; +} +.pagination .nav_next { +float:right; +} + +.pagination a { +display:block; +text-decoration:none; +font-weight:bold; +padding:7px; +border:1px dotted #D1D9E4; +border-bottom:0; +} + +.pagination .nav_prev a { +-moz-border-radius-topright:7px; +-webkit-border-top-right-radius:7px; +padding-left:20px; +border-left:0; +} +.pagination .nav_next a { +-moz-border-radius-topleft:7px; +-webkit-border-top-left-radius:7px; +padding-right:20px; +border-right:0; +} + + +/* END: NOTICE */ + + + + + + + +/*START: LOAD ALONG WITH JS*/ +.notice .in-reply-to { + width:98%; + margin-left:2%; +} +.notice .in-reply-to li { +background-color:#F7F9FB; +} +.notice .in-reply-to li .in-reply-to li { +background-color:#E4E9F0; +} +.notice .in-reply-to li .in-reply-to li .in-reply-to li { +background-color:#D1D9E4; +} + + + +#user_actions #user_subscribe .form_note, +#user_actions #user_subscribe .form_datas, +#user_actions #user_subscribe .form_actions label { +display:none; +} +#form_user-relationship .form_note, +#form_user-relationship .form_datas, +#form_user-relationship .form_actions label { +display:block; +} + +#user_actions #user-relationship_submit { +margin-bottom:0; +} +#form_user-relationship .form_datas li label { +margin-right:11px; +} + +#user_relationship_xfn { +/*z-index:1000; +position:absolute; +width:521px; +height:322px;*/ +display:none; +} +#user_relationship_xfn fieldset { +background-color:#fff; +} + +/*END: LOAD ALONG WITH JS*/ + + + +/* TOP_POSTERS */ +#top-posters caption { +text-align:left; +text-transform:uppercase; +} + +#top-posters thead { +display:none; +} +#top-poster_user { +width:199px; +} +#top-poster_number-of-notices { +width:123px; +} +#top-posters tbody td { +padding-right:11px; +padding-bottom:4px; +} +#top-posters img { +margin-right:7px; +height:24px; +width:24px; +} + + + +/* tagcloud */ +#tagcloud ul { +list-style-type:none; +} +#tagcloud ul li { +display:inline; +margin-right:7px; +line-height:1.4; +} + +#tagcloud.section dt { +text-transform:uppercase; +font-weight:bold; +} +#tagcloud .weight_1 { +font-size:1em; +} +#tagcloud .weight_2 { +font-size:1.3em; +} +#tagcloud .weight_3 { +font-size:1.6em; +} +#tagcloud .weight_4 { +font-size:1.9em; +} +#tagcloud .weight_5 { +font-size:2.2em; +} + + + +#form_settings_photo .form_datas { +clear:both; +} + + + + +#photo_original, +#photo_preview { +float:left; +} +#photo_preview, +#settings_photo_action-crop { +margin-left:29px; +} +#photo_preview_view { +height:96px; +width:96px; +overflow:hidden; +} + + + + +.section .groups, +#users_featured ul { +list-style-type:none; +} +.section .groups li, +#users_featured li { +margin-top:11px; +float:left; +width:100%; +} +.section .groups li:first-child, +#users_featured li:first-child { +margin-top:0; +} + +.section .groups .vcard, +#users_featured .vcard { +float:left; +margin-bottom:-23px; +} + +.section .groups dl, +#users_featured dl { +float:left; +margin-left:63px; +clear:left; +} +.section .groups dt, +#users_featured dt { +display:none; +font-weight:bold; +} + + + +#home.logged_out h1 { +display:none; +} + +#home #intro { +margin-bottom:29px; +float:left; +width:100%; +} + +#home #intro p { +margin-bottom:18px; +font-size:1.8em; +} + +#home #intro #guide_steps { +list-style-type:none; +} +#home #intro #guide_steps li { +float:left; +margin-left:18px; +} +#home #intro #guide_steps li:first-child { +margin-left:0; +} +#home #intro #guide_steps li a { +display:block; +float:left; +width:185px; +height:109px; +border-width:1px; +border-style:dotted; +text-decoration:none; +border-radius:7px; +-moz-border-radius:7px; +-webkit-border-radius:7px; +padding:7px; +font-size:1.6em; +font-weight:bold; +text-align:center; +} + + +#testimonials { +clear:both; +} diff --git a/theme/identica/facebookapp.css b/theme/identica/facebookapp.css deleted file mode 100644 index b2bbbac51..000000000 --- a/theme/identica/facebookapp.css +++ /dev/null @@ -1,161 +0,0 @@ - -/* XXX: Most of this just copied out of display.css -- need to factor out what we really neeed -- Zach */ - -body { - color: #193441; -} - -a { -color: #d1451a; -text-decoration: none; -} -a:hover { -text-decoration: underline; -} -img, img a { -border: 0; -} -h1 { -font-size: 14px; -} - -#wrap { -margin: 0 auto; -padding: 0 20px; -width: 760px; -background: url(bg-header.gif) repeat-x #fbf2d7; -} - - -#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; -} -#notice_delete_form #confirmation_text { - display: block; -font-size: 14px; -font-weight: bold; -} - -input#submit_yes, input#submit_no { -margin: 18px 10px 0px 0px; -padding: 4px; -font-weight: bold; -color: #fff6d5; -background-color: #F60; -cursor: pointer; -border: 0; -width: 40px; -} -input#submit_yes:hover, input#submit_no:hover { -background-color: #701238; -} -.avatar.stream { -float: left; -margin: 0 10px 0.5em 0; -} -p.time { -display: block; -font-family: Verdana, Arial, Helvetica, sans-serif; -font-size: 10px; -line-height: 15px; -} -p.time a { -color: #dab134; -} - - -/* ----- Forms General Style ----- */ -form { - margin: 0 auto; - padding: 0; - } -form { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 12px; - } -form label { - display: block; - font-size: 12px; - font-weight: bold; - line-height: 18px; - } -form input { - border: 1px solid #dec5b5; - width: 264px; - } -input#submit, input.submit { - display: block; - margin: 18px 0; - padding: 4px; - font-weight: bold; - color: #fff6d5; - background-color: #F60; - cursor: pointer; - border: 0; - width: auto; - } -input#submit:hover, input.submit:hover { - background-color: #701238; - } -input.checkbox { - /*width: 14px; - height: 14px;*/ - width: auto; - border: 0; - } - -label.checkbox_label { - display: inline; - font-weight: normal; -} - -textarea, input { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 12px; - color: #701238; - padding: 3px; - } -textarea:focus, input:focus { - background-color: #f8ebc0; - } -textarea { - width: 270px; - border: 1px solid #D8E2D7; - } -.input_instructions { - margin-top: 3px; - display: block; - font-size: 11px; - line-height: 15px; - color: #924959; - font-family: Verdana, Arial, Helvetica, sans-serif; - } diff --git a/theme/identica/images/icons/icon_atom.jpg b/theme/identica/images/icons/icon_atom.jpg Binary files differnew file mode 100644 index 000000000..22853edc4 --- /dev/null +++ b/theme/identica/images/icons/icon_atom.jpg diff --git a/theme/identica/images/icons/icon_foaf.gif b/theme/identica/images/icons/icon_foaf.gif Binary files differnew file mode 100644 index 000000000..f8f784423 --- /dev/null +++ b/theme/identica/images/icons/icon_foaf.gif diff --git a/theme/identica/images/icons/icon_rss.jpg b/theme/identica/images/icons/icon_rss.jpg Binary files differnew file mode 100644 index 000000000..da23422d0 --- /dev/null +++ b/theme/identica/images/icons/icon_rss.jpg diff --git a/theme/identica/images/icons/icon_vcard.gif b/theme/identica/images/icons/icon_vcard.gif Binary files differnew file mode 100644 index 000000000..6d52947f3 --- /dev/null +++ b/theme/identica/images/icons/icon_vcard.gif diff --git a/theme/identica/images/icons/twotone/green/against.gif b/theme/identica/images/icons/twotone/green/against.gif Binary files differnew file mode 100644 index 000000000..ca796c8a3 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/against.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-down.gif b/theme/identica/images/icons/twotone/green/arrow-down.gif Binary files differnew file mode 100644 index 000000000..c709e5877 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-down.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-downleft.gif b/theme/identica/images/icons/twotone/green/arrow-downleft.gif Binary files differnew file mode 100644 index 000000000..a4a98035d --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-downleft.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-downright.gif b/theme/identica/images/icons/twotone/green/arrow-downright.gif Binary files differnew file mode 100644 index 000000000..3e6001a61 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-downright.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-left.gif b/theme/identica/images/icons/twotone/green/arrow-left.gif Binary files differnew file mode 100644 index 000000000..afed19084 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-left.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-right.gif b/theme/identica/images/icons/twotone/green/arrow-right.gif Binary files differnew file mode 100644 index 000000000..ee1707ed9 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-right.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-up.gif b/theme/identica/images/icons/twotone/green/arrow-up.gif Binary files differnew file mode 100644 index 000000000..d0f5fbeaa --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-up.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-upleft.gif b/theme/identica/images/icons/twotone/green/arrow-upleft.gif Binary files differnew file mode 100644 index 000000000..1e9e6935b --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-upleft.gif diff --git a/theme/identica/images/icons/twotone/green/arrow-upright.gif b/theme/identica/images/icons/twotone/green/arrow-upright.gif Binary files differnew file mode 100644 index 000000000..c7fecc8a0 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/arrow-upright.gif diff --git a/theme/identica/images/icons/twotone/green/back-forth.gif b/theme/identica/images/icons/twotone/green/back-forth.gif Binary files differnew file mode 100644 index 000000000..33a9540c8 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/back-forth.gif diff --git a/theme/identica/images/icons/twotone/green/bookmark.gif b/theme/identica/images/icons/twotone/green/bookmark.gif Binary files differnew file mode 100644 index 000000000..23f318ecc --- /dev/null +++ b/theme/identica/images/icons/twotone/green/bookmark.gif diff --git a/theme/identica/images/icons/twotone/green/bulb.gif b/theme/identica/images/icons/twotone/green/bulb.gif Binary files differnew file mode 100644 index 000000000..f70652c03 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/bulb.gif diff --git a/theme/identica/images/icons/twotone/green/calendar.gif b/theme/identica/images/icons/twotone/green/calendar.gif Binary files differnew file mode 100644 index 000000000..a09b65aca --- /dev/null +++ b/theme/identica/images/icons/twotone/green/calendar.gif diff --git a/theme/identica/images/icons/twotone/green/calendar2.gif b/theme/identica/images/icons/twotone/green/calendar2.gif Binary files differnew file mode 100644 index 000000000..7884b02dd --- /dev/null +++ b/theme/identica/images/icons/twotone/green/calendar2.gif diff --git a/theme/identica/images/icons/twotone/green/camera.gif b/theme/identica/images/icons/twotone/green/camera.gif Binary files differnew file mode 100644 index 000000000..1a85fbad0 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/camera.gif diff --git a/theme/identica/images/icons/twotone/green/cart.gif b/theme/identica/images/icons/twotone/green/cart.gif Binary files differnew file mode 100644 index 000000000..47eaa0a2e --- /dev/null +++ b/theme/identica/images/icons/twotone/green/cart.gif diff --git a/theme/identica/images/icons/twotone/green/caution.gif b/theme/identica/images/icons/twotone/green/caution.gif Binary files differnew file mode 100644 index 000000000..3ad2c322b --- /dev/null +++ b/theme/identica/images/icons/twotone/green/caution.gif diff --git a/theme/identica/images/icons/twotone/green/chart.gif b/theme/identica/images/icons/twotone/green/chart.gif Binary files differnew file mode 100644 index 000000000..136d74517 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/chart.gif diff --git a/theme/identica/images/icons/twotone/green/checkmark.gif b/theme/identica/images/icons/twotone/green/checkmark.gif Binary files differnew file mode 100644 index 000000000..892429d48 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/checkmark.gif diff --git a/theme/identica/images/icons/twotone/green/clipboard.gif b/theme/identica/images/icons/twotone/green/clipboard.gif Binary files differnew file mode 100644 index 000000000..9317bdcd0 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/clipboard.gif diff --git a/theme/identica/images/icons/twotone/green/clock.gif b/theme/identica/images/icons/twotone/green/clock.gif Binary files differnew file mode 100644 index 000000000..d1410f925 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/clock.gif diff --git a/theme/identica/images/icons/twotone/green/closed-folder.gif b/theme/identica/images/icons/twotone/green/closed-folder.gif Binary files differnew file mode 100644 index 000000000..0410fc6e8 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/closed-folder.gif diff --git a/theme/identica/images/icons/twotone/green/database.gif b/theme/identica/images/icons/twotone/green/database.gif Binary files differnew file mode 100644 index 000000000..29ce02492 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/database.gif diff --git a/theme/identica/images/icons/twotone/green/disfavourite.gif b/theme/identica/images/icons/twotone/green/disfavourite.gif Binary files differnew file mode 100644 index 000000000..3946869ae --- /dev/null +++ b/theme/identica/images/icons/twotone/green/disfavourite.gif diff --git a/theme/identica/images/icons/twotone/green/diskette.gif b/theme/identica/images/icons/twotone/green/diskette.gif Binary files differnew file mode 100644 index 000000000..e970b0a30 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/diskette.gif diff --git a/theme/identica/images/icons/twotone/green/document.gif b/theme/identica/images/icons/twotone/green/document.gif Binary files differnew file mode 100644 index 000000000..9c08f4a3a --- /dev/null +++ b/theme/identica/images/icons/twotone/green/document.gif diff --git a/theme/identica/images/icons/twotone/green/double-arrow.gif b/theme/identica/images/icons/twotone/green/double-arrow.gif Binary files differnew file mode 100644 index 000000000..2e8648264 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/double-arrow.gif diff --git a/theme/identica/images/icons/twotone/green/edit.gif b/theme/identica/images/icons/twotone/green/edit.gif Binary files differnew file mode 100644 index 000000000..c746aca60 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/edit.gif diff --git a/theme/identica/images/icons/twotone/green/eject.gif b/theme/identica/images/icons/twotone/green/eject.gif Binary files differnew file mode 100644 index 000000000..7e0906cfe --- /dev/null +++ b/theme/identica/images/icons/twotone/green/eject.gif diff --git a/theme/identica/images/icons/twotone/green/exclaim.gif b/theme/identica/images/icons/twotone/green/exclaim.gif Binary files differnew file mode 100644 index 000000000..588e28c26 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/exclaim.gif diff --git a/theme/identica/images/icons/twotone/green/fastforward.gif b/theme/identica/images/icons/twotone/green/fastforward.gif Binary files differnew file mode 100644 index 000000000..28e495103 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/fastforward.gif diff --git a/theme/identica/images/icons/twotone/green/favourite.gif b/theme/identica/images/icons/twotone/green/favourite.gif Binary files differnew file mode 100644 index 000000000..d93515e37 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/favourite.gif diff --git a/theme/identica/images/icons/twotone/green/flag.gif b/theme/identica/images/icons/twotone/green/flag.gif Binary files differnew file mode 100644 index 000000000..68c8aee25 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/flag.gif diff --git a/theme/identica/images/icons/twotone/green/graph.gif b/theme/identica/images/icons/twotone/green/graph.gif Binary files differnew file mode 100644 index 000000000..0c1794b4e --- /dev/null +++ b/theme/identica/images/icons/twotone/green/graph.gif diff --git a/theme/identica/images/icons/twotone/green/grow.gif b/theme/identica/images/icons/twotone/green/grow.gif Binary files differnew file mode 100644 index 000000000..c4118d53b --- /dev/null +++ b/theme/identica/images/icons/twotone/green/grow.gif diff --git a/theme/identica/images/icons/twotone/green/headphones.gif b/theme/identica/images/icons/twotone/green/headphones.gif Binary files differnew file mode 100644 index 000000000..5be6c67dd --- /dev/null +++ b/theme/identica/images/icons/twotone/green/headphones.gif diff --git a/theme/identica/images/icons/twotone/green/home.gif b/theme/identica/images/icons/twotone/green/home.gif Binary files differnew file mode 100644 index 000000000..d2a3421ef --- /dev/null +++ b/theme/identica/images/icons/twotone/green/home.gif diff --git a/theme/identica/images/icons/twotone/green/hourglass.gif b/theme/identica/images/icons/twotone/green/hourglass.gif Binary files differnew file mode 100644 index 000000000..b62b9480c --- /dev/null +++ b/theme/identica/images/icons/twotone/green/hourglass.gif diff --git a/theme/identica/images/icons/twotone/green/info.gif b/theme/identica/images/icons/twotone/green/info.gif Binary files differnew file mode 100644 index 000000000..86ef1f8b4 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/info.gif diff --git a/theme/identica/images/icons/twotone/green/key.gif b/theme/identica/images/icons/twotone/green/key.gif Binary files differnew file mode 100644 index 000000000..ccf357ab2 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/key.gif diff --git a/theme/identica/images/icons/twotone/green/lock.gif b/theme/identica/images/icons/twotone/green/lock.gif Binary files differnew file mode 100644 index 000000000..db00706b5 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/lock.gif diff --git a/theme/identica/images/icons/twotone/green/mail.gif b/theme/identica/images/icons/twotone/green/mail.gif Binary files differnew file mode 100644 index 000000000..1084c862f --- /dev/null +++ b/theme/identica/images/icons/twotone/green/mail.gif diff --git a/theme/identica/images/icons/twotone/green/move.gif b/theme/identica/images/icons/twotone/green/move.gif Binary files differnew file mode 100644 index 000000000..d2c30b1d2 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/move.gif diff --git a/theme/identica/images/icons/twotone/green/music.gif b/theme/identica/images/icons/twotone/green/music.gif Binary files differnew file mode 100644 index 000000000..64b51d4e1 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/music.gif diff --git a/theme/identica/images/icons/twotone/green/news.gif b/theme/identica/images/icons/twotone/green/news.gif Binary files differnew file mode 100644 index 000000000..712c685dc --- /dev/null +++ b/theme/identica/images/icons/twotone/green/news.gif diff --git a/theme/identica/images/icons/twotone/green/note.gif b/theme/identica/images/icons/twotone/green/note.gif Binary files differnew file mode 100644 index 000000000..bcc0b149b --- /dev/null +++ b/theme/identica/images/icons/twotone/green/note.gif diff --git a/theme/identica/images/icons/twotone/green/open-folder.gif b/theme/identica/images/icons/twotone/green/open-folder.gif Binary files differnew file mode 100644 index 000000000..d41300a08 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/open-folder.gif diff --git a/theme/identica/images/icons/twotone/green/paper-clip.gif b/theme/identica/images/icons/twotone/green/paper-clip.gif Binary files differnew file mode 100644 index 000000000..1d45f1d1e --- /dev/null +++ b/theme/identica/images/icons/twotone/green/paper-clip.gif diff --git a/theme/identica/images/icons/twotone/green/paper-clip2.gif b/theme/identica/images/icons/twotone/green/paper-clip2.gif Binary files differnew file mode 100644 index 000000000..a8c7805be --- /dev/null +++ b/theme/identica/images/icons/twotone/green/paper-clip2.gif diff --git a/theme/identica/images/icons/twotone/green/pause.gif b/theme/identica/images/icons/twotone/green/pause.gif Binary files differnew file mode 100644 index 000000000..ced0b6440 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/pause.gif diff --git a/theme/identica/images/icons/twotone/green/phone.gif b/theme/identica/images/icons/twotone/green/phone.gif Binary files differnew file mode 100644 index 000000000..69359f764 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/phone.gif diff --git a/theme/identica/images/icons/twotone/green/play.gif b/theme/identica/images/icons/twotone/green/play.gif Binary files differnew file mode 100644 index 000000000..794ec85b6 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/play.gif diff --git a/theme/identica/images/icons/twotone/green/plus.gif b/theme/identica/images/icons/twotone/green/plus.gif Binary files differnew file mode 100644 index 000000000..4407d0b2d --- /dev/null +++ b/theme/identica/images/icons/twotone/green/plus.gif diff --git a/theme/identica/images/icons/twotone/green/print.gif b/theme/identica/images/icons/twotone/green/print.gif Binary files differnew file mode 100644 index 000000000..17727d5d7 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/print.gif diff --git a/theme/identica/images/icons/twotone/green/question-mark.gif b/theme/identica/images/icons/twotone/green/question-mark.gif Binary files differnew file mode 100644 index 000000000..1689efcd0 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/question-mark.gif diff --git a/theme/identica/images/icons/twotone/green/quote.gif b/theme/identica/images/icons/twotone/green/quote.gif Binary files differnew file mode 100644 index 000000000..4ba1f0c03 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/quote.gif diff --git a/theme/identica/images/icons/twotone/green/refresh.gif b/theme/identica/images/icons/twotone/green/refresh.gif Binary files differnew file mode 100644 index 000000000..8a8b8144f --- /dev/null +++ b/theme/identica/images/icons/twotone/green/refresh.gif diff --git a/theme/identica/images/icons/twotone/green/reply.gif b/theme/identica/images/icons/twotone/green/reply.gif Binary files differnew file mode 100644 index 000000000..6ff01bb35 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/reply.gif diff --git a/theme/identica/images/icons/twotone/green/rewind.gif b/theme/identica/images/icons/twotone/green/rewind.gif Binary files differnew file mode 100644 index 000000000..aca3ee35b --- /dev/null +++ b/theme/identica/images/icons/twotone/green/rewind.gif diff --git a/theme/identica/images/icons/twotone/green/search.gif b/theme/identica/images/icons/twotone/green/search.gif Binary files differnew file mode 100644 index 000000000..c36463d0d --- /dev/null +++ b/theme/identica/images/icons/twotone/green/search.gif diff --git a/theme/identica/images/icons/twotone/green/shield.gif b/theme/identica/images/icons/twotone/green/shield.gif Binary files differnew file mode 100644 index 000000000..419d5ee4b --- /dev/null +++ b/theme/identica/images/icons/twotone/green/shield.gif diff --git a/theme/identica/images/icons/twotone/green/skip-back.gif b/theme/identica/images/icons/twotone/green/skip-back.gif Binary files differnew file mode 100644 index 000000000..adca7aa3e --- /dev/null +++ b/theme/identica/images/icons/twotone/green/skip-back.gif diff --git a/theme/identica/images/icons/twotone/green/skip.gif b/theme/identica/images/icons/twotone/green/skip.gif Binary files differnew file mode 100644 index 000000000..ae5417f2f --- /dev/null +++ b/theme/identica/images/icons/twotone/green/skip.gif diff --git a/theme/identica/images/icons/twotone/green/skull.gif b/theme/identica/images/icons/twotone/green/skull.gif Binary files differnew file mode 100644 index 000000000..033506732 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/skull.gif diff --git a/theme/identica/images/icons/twotone/green/statusbar.gif b/theme/identica/images/icons/twotone/green/statusbar.gif Binary files differnew file mode 100644 index 000000000..47d61b106 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/statusbar.gif diff --git a/theme/identica/images/icons/twotone/green/stop.gif b/theme/identica/images/icons/twotone/green/stop.gif Binary files differnew file mode 100644 index 000000000..e0b108d35 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/stop.gif diff --git a/theme/identica/images/icons/twotone/green/template.gif b/theme/identica/images/icons/twotone/green/template.gif Binary files differnew file mode 100644 index 000000000..65c0c4a0a --- /dev/null +++ b/theme/identica/images/icons/twotone/green/template.gif diff --git a/theme/identica/images/icons/twotone/green/text-bigger.gif b/theme/identica/images/icons/twotone/green/text-bigger.gif Binary files differnew file mode 100644 index 000000000..45e143b7a --- /dev/null +++ b/theme/identica/images/icons/twotone/green/text-bigger.gif diff --git a/theme/identica/images/icons/twotone/green/text-smaller.gif b/theme/identica/images/icons/twotone/green/text-smaller.gif Binary files differnew file mode 100644 index 000000000..a54d0c1d3 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/text-smaller.gif diff --git a/theme/identica/images/icons/twotone/green/trash.gif b/theme/identica/images/icons/twotone/green/trash.gif Binary files differnew file mode 100644 index 000000000..78dd64a3d --- /dev/null +++ b/theme/identica/images/icons/twotone/green/trash.gif diff --git a/theme/identica/images/icons/twotone/green/two-docs.gif b/theme/identica/images/icons/twotone/green/two-docs.gif Binary files differnew file mode 100644 index 000000000..97e54b964 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/two-docs.gif diff --git a/theme/identica/images/icons/twotone/green/twotone.gif b/theme/identica/images/icons/twotone/green/twotone.gif Binary files differnew file mode 100644 index 000000000..45aad25c4 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/twotone.gif diff --git a/theme/identica/images/icons/twotone/green/undo.gif b/theme/identica/images/icons/twotone/green/undo.gif Binary files differnew file mode 100644 index 000000000..6869b3050 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/undo.gif diff --git a/theme/identica/images/icons/twotone/green/user.gif b/theme/identica/images/icons/twotone/green/user.gif Binary files differnew file mode 100644 index 000000000..c85460fcd --- /dev/null +++ b/theme/identica/images/icons/twotone/green/user.gif diff --git a/theme/identica/images/icons/twotone/green/vegetable.gif b/theme/identica/images/icons/twotone/green/vegetable.gif Binary files differnew file mode 100644 index 000000000..4d421c1bb --- /dev/null +++ b/theme/identica/images/icons/twotone/green/vegetable.gif diff --git a/theme/identica/images/icons/twotone/green/x.gif b/theme/identica/images/icons/twotone/green/x.gif Binary files differnew file mode 100644 index 000000000..ffb2efea0 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/x.gif diff --git a/theme/identica/images/icons/twotone/green/zoom-in.gif b/theme/identica/images/icons/twotone/green/zoom-in.gif Binary files differnew file mode 100644 index 000000000..a59a5bb50 --- /dev/null +++ b/theme/identica/images/icons/twotone/green/zoom-in.gif diff --git a/theme/identica/images/icons/twotone/green/zoom-out.gif b/theme/identica/images/icons/twotone/green/zoom-out.gif Binary files differnew file mode 100644 index 000000000..c61f999fd --- /dev/null +++ b/theme/identica/images/icons/twotone/green/zoom-out.gif diff --git a/theme/identica/logo.png b/theme/identica/logo.png Binary files differindex 3b271814d..cee36799e 100644 --- a/theme/identica/logo.png +++ b/theme/identica/logo.png |