diff options
author | Evan Prodromou <evan@prodromou.name> | 2008-12-23 14:19:07 -0500 |
---|---|---|
committer | Evan Prodromou <evan@prodromou.name> | 2008-12-23 14:19:07 -0500 |
commit | edbc0c665cc65875b4d14b79939233b1c9c06bb6 (patch) | |
tree | 4daaacb5bb4c52db9131624b4339bd9a60b205dd /_darcs/pristine/lib | |
parent | 17ece0777b22b15c60b27b32f0f7e24ecc447661 (diff) |
replace all tabs with four spaces
The PEAR coding standards decree: no tabs, but indent by four spaces.
I've done a global search-and-replace on all tabs, replacing them by
four spaces. This is a huge change, but it will go a long way to
getting us towards phpcs-compliance. And that means better code
readability, and that means more participation.
darcs-hash:20081223191907-84dde-21e8efe210e6d5d54e935a22d0cee5c7bbfc007d.gz
Diffstat (limited to '_darcs/pristine/lib')
-rw-r--r-- | _darcs/pristine/lib/common.php | 162 | ||||
-rw-r--r-- | _darcs/pristine/lib/deleteaction.php | 74 | ||||
-rw-r--r-- | _darcs/pristine/lib/facebookaction.php | 516 | ||||
-rw-r--r-- | _darcs/pristine/lib/oauthstore.php | 218 | ||||
-rw-r--r-- | _darcs/pristine/lib/omb.php | 378 | ||||
-rw-r--r-- | _darcs/pristine/lib/openid.php | 316 | ||||
-rw-r--r-- | _darcs/pristine/lib/personal.php | 366 | ||||
-rw-r--r-- | _darcs/pristine/lib/profilelist.php | 260 | ||||
-rw-r--r-- | _darcs/pristine/lib/queuehandler.php | 194 | ||||
-rw-r--r-- | _darcs/pristine/lib/rssaction.php | 322 | ||||
-rw-r--r-- | _darcs/pristine/lib/search_engines.php | 4 | ||||
-rw-r--r-- | _darcs/pristine/lib/searchaction.php | 154 | ||||
-rw-r--r-- | _darcs/pristine/lib/settingsaction.php | 100 | ||||
-rw-r--r-- | _darcs/pristine/lib/stream.php | 34 | ||||
-rw-r--r-- | _darcs/pristine/lib/subs.php | 122 | ||||
-rw-r--r-- | _darcs/pristine/lib/theme.php | 18 | ||||
-rw-r--r-- | _darcs/pristine/lib/twitter.php | 216 | ||||
-rw-r--r-- | _darcs/pristine/lib/twitterapi.php | 1224 | ||||
-rw-r--r-- | _darcs/pristine/lib/xmppqueuehandler.php | 112 |
19 files changed, 2395 insertions, 2395 deletions
diff --git a/_darcs/pristine/lib/common.php b/_darcs/pristine/lib/common.php index 5a28c3091..95ba64d0f 100644 --- a/_darcs/pristine/lib/common.php +++ b/_darcs/pristine/lib/common.php @@ -54,100 +54,100 @@ require_once(INSTALLDIR.'/lib/language.php'); $config = array('site' => - array('name' => 'Just another Laconica microblog', - 'server' => 'localhost', - 'theme' => 'default', - 'path' => '/', - 'logfile' => NULL, - 'fancy' => false, - 'locale_path' => INSTALLDIR.'/locale', - 'language' => 'en_US', - 'languages' => get_all_languages(), - 'email' => - array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL, - 'broughtby' => NULL, - 'timezone' => 'UTC', - 'broughtbyurl' => NULL, - 'closed' => false, - 'inviteonly' => false, + array('name' => 'Just another Laconica microblog', + 'server' => 'localhost', + 'theme' => 'default', + 'path' => '/', + 'logfile' => NULL, + 'fancy' => false, + 'locale_path' => INSTALLDIR.'/locale', + 'language' => 'en_US', + 'languages' => get_all_languages(), + 'email' => + array_key_exists('SERVER_ADMIN', $_SERVER) ? $_SERVER['SERVER_ADMIN'] : NULL, + 'broughtby' => NULL, + 'timezone' => 'UTC', + 'broughtbyurl' => NULL, + 'closed' => false, + 'inviteonly' => false, 'private' => false), - 'syslog' => - array('appname' => 'laconica', # for syslog - 'priority' => 'debug'), # XXX: currently ignored - 'queue' => - array('enabled' => false), - 'license' => - array('url' => 'http://creativecommons.org/licenses/by/3.0/', - 'title' => 'Creative Commons Attribution 3.0', - 'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'), - 'mail' => - array('backend' => 'mail', - 'params' => NULL), - 'nickname' => - array('blacklist' => array(), - 'featured' => array()), - 'profile' => - array('banned' => array()), - 'avatar' => - array('server' => NULL), - 'public' => - array('localonly' => true, - 'blacklist' => array()), - 'theme' => - array('server' => NULL), - 'throttle' => + 'syslog' => + array('appname' => 'laconica', # for syslog + 'priority' => 'debug'), # XXX: currently ignored + 'queue' => + array('enabled' => false), + 'license' => + array('url' => 'http://creativecommons.org/licenses/by/3.0/', + 'title' => 'Creative Commons Attribution 3.0', + 'image' => 'http://i.creativecommons.org/l/by/3.0/88x31.png'), + 'mail' => + array('backend' => 'mail', + 'params' => NULL), + 'nickname' => + array('blacklist' => array(), + 'featured' => array()), + 'profile' => + array('banned' => array()), + 'avatar' => + array('server' => NULL), + 'public' => + array('localonly' => true, + 'blacklist' => array()), + 'theme' => + array('server' => NULL), + 'throttle' => array('enabled' => false, // whether to throttle edits; false by default 'count' => 20, // number of allowed messages in timespan 'timespan' => 600), // timespan for throttling - 'xmpp' => - array('enabled' => false, - 'server' => 'INVALID SERVER', - 'port' => 5222, - 'user' => 'update', - 'encryption' => true, - 'resource' => 'uniquename', - 'password' => 'blahblahblah', - 'host' => NULL, # only set if != server - 'debug' => false, # print extra debug info - 'public' => array()), # JIDs of users who want to receive the public stream + 'xmpp' => + array('enabled' => false, + 'server' => 'INVALID SERVER', + 'port' => 5222, + 'user' => 'update', + 'encryption' => true, + 'resource' => 'uniquename', + 'password' => 'blahblahblah', + 'host' => NULL, # only set if != server + 'debug' => false, # print extra debug info + 'public' => array()), # JIDs of users who want to receive the public stream 'sphinx' => array('enabled' => false, 'server' => 'localhost', 'port' => 3312), - 'tag' => - array('dropoff' => 864000.0), - 'popular' => - array('dropoff' => 864000.0), - 'daemon' => - array('piddir' => '/var/run', - 'user' => false, - 'group' => false), - 'integration' => - array('source' => 'Laconica'), # source attribute for Twitter - 'memcached' => - array('enabled' => false, - 'server' => 'localhost', - 'port' => 11211), - 'inboxes' => - array('enabled' => true), # on by default for new sites - ); + 'tag' => + array('dropoff' => 864000.0), + 'popular' => + array('dropoff' => 864000.0), + 'daemon' => + array('piddir' => '/var/run', + 'user' => false, + 'group' => false), + 'integration' => + array('source' => 'Laconica'), # source attribute for Twitter + 'memcached' => + array('enabled' => false, + 'server' => 'localhost', + 'port' => 11211), + 'inboxes' => + array('enabled' => true), # on by default for new sites + ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); $config['db'] = array('database' => 'YOU HAVE TO SET THIS IN config.php', - 'schema_location' => INSTALLDIR . '/classes', - 'class_location' => INSTALLDIR . '/classes', - 'require_prefix' => 'classes/', - 'class_prefix' => '', - 'mirror' => NULL, + 'schema_location' => INSTALLDIR . '/classes', + 'class_location' => INSTALLDIR . '/classes', + 'require_prefix' => 'classes/', + 'class_prefix' => '', + 'mirror' => NULL, 'db_driver' => 'DB', # XXX: JanRain libs only work with DB - 'quote_identifiers' => false, - 'type' => 'mysql' ); + 'quote_identifiers' => false, + 'type' => 'mysql' ); if (function_exists('date_default_timezone_set')) { - /* Work internally in UTC */ - date_default_timezone_set('UTC'); + /* Work internally in UTC */ + date_default_timezone_set('UTC'); } require_once(INSTALLDIR.'/config.php'); @@ -164,9 +164,9 @@ require_once(INSTALLDIR.'/lib/Shorturl_api.php'); require_once(INSTALLDIR.'/lib/twitter.php'); function __autoload($class) { - if ($class == 'OAuthRequest') { - require_once('OAuth.php'); - } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) { + if ($class == 'OAuthRequest') { + require_once('OAuth.php'); + } else if (file_exists(INSTALLDIR.'/classes/' . $class . '.php')) { require_once(INSTALLDIR.'/classes/' . $class . '.php'); } } diff --git a/_darcs/pristine/lib/deleteaction.php b/_darcs/pristine/lib/deleteaction.php index 5ba0e7e44..335070cc4 100644 --- a/_darcs/pristine/lib/deleteaction.php +++ b/_darcs/pristine/lib/deleteaction.php @@ -21,41 +21,41 @@ if (!defined('LACONICA')) { exit(1); } class DeleteAction extends Action { - function handle($args) { - parent::handle($args); - $user = common_current_user(); - $notice_id = $this->trimmed('notice'); - $notice = Notice::staticGet($notice_id); - if (!$notice) { - common_user_error(_('No such notice.')); - exit; - } - - $profile = $notice->getProfile(); - $user_profile = $user->getProfile(); - - if (!common_logged_in()) { - common_user_error(_('Not logged in.')); - exit; - } else if ($notice->profile_id != $user_profile->id) { - common_user_error(_('Can\'t delete this notice.')); - exit; - } - } - - function show_top($arr=NULL) { - $instr = $this->get_instructions(); - $output = common_markup_to_html($instr); - common_element_start('div', 'instructions'); - common_raw($output); - common_element_end('div'); - } - - function get_title() { - return NULL; - } - - function show_header() { - return; - } + function handle($args) { + parent::handle($args); + $user = common_current_user(); + $notice_id = $this->trimmed('notice'); + $notice = Notice::staticGet($notice_id); + if (!$notice) { + common_user_error(_('No such notice.')); + exit; + } + + $profile = $notice->getProfile(); + $user_profile = $user->getProfile(); + + if (!common_logged_in()) { + common_user_error(_('Not logged in.')); + exit; + } else if ($notice->profile_id != $user_profile->id) { + common_user_error(_('Can\'t delete this notice.')); + exit; + } + } + + function show_top($arr=NULL) { + $instr = $this->get_instructions(); + $output = common_markup_to_html($instr); + common_element_start('div', 'instructions'); + common_raw($output); + common_element_end('div'); + } + + function get_title() { + return NULL; + } + + function show_header() { + return; + } } diff --git a/_darcs/pristine/lib/facebookaction.php b/_darcs/pristine/lib/facebookaction.php index 87a82ba01..67595861f 100644 --- a/_darcs/pristine/lib/facebookaction.php +++ b/_darcs/pristine/lib/facebookaction.php @@ -10,11 +10,11 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('LACONICA')) { exit(1); } @@ -23,261 +23,261 @@ require_once(INSTALLDIR.'/extlib/facebook/facebook.php'); class FacebookAction extends Action { - function handle($args) { - parent::handle($args); - } - - function get_facebook() { - $apikey = common_config('facebook', 'apikey'); - $secret = common_config('facebook', 'secret'); - return new Facebook($apikey, $secret); - } - - function update_profile_box($facebook, $fbuid, $user) { - - $notice = $user->getCurrentNotice(); - - # Need to include inline CSS for styling the Profile box - - $style = '<style> - #notices { - clear: both; - margin: 0 auto; - padding: 0; - list-style-type: none; - width: 600px; - border-top: 1px solid #dec5b5; - } - #notices a:hover { - text-decoration: underline; - } - .notice_single { - clear: both; - display: block; - margin: 0; - padding: 5px 5px 5px 0; - min-height: 48px; - font-family: Georgia, "Times New Roman", Times, serif; - font-size: 13px; - line-height: 16px; - border-bottom: 1px solid #dec5b5; - background-color:#FCFFF5; - opacity:1; - } - .notice_single:hover { - background-color: #f7ebcc; - } - .notice_single p { - display: inline; - margin: 0; - padding: 0; - } - </style>'; - - $html = $this->render_notice($notice); - - $fbml = "<fb:wide>$content $html</fb:wide>"; - $fbml .= "<fb:narrow>$content $html</fb:narrow>"; - - $fbml_main = "<fb:narrow>$content $html</fb:narrow>"; - - $facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main); - } - - # Display methods - - function show_header($selected ='Home') { - - # Add a timestamp to the CSS file so Facebook cache wont ignore our changes - $ts = filemtime(theme_file('facebookapp.css')); - $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; - - $header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />'; - # $header .='<script src="" ></script>'; - $header .= '<fb:dashboard/>'; - - $header .= - '<fb:tabs>' - .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />' - .'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />' - .'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />' - .'</fb:tabs>'; - $header .= '<div id="main_body">'; - - echo $header; - - } - - function show_footer() { - $footer = '</div>'; - echo $footer; - } - - function show_login_form() { - - $loginform = - ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>' - .'<a href="http://identi.ca/">' - .' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>' - .'</a>' - .'<h1 class="pagetitle">Login</h1>' - .'<div class="instructions">' - .' <p>Login with your username and password. Don\'t have a username yet?' - .' <a href="http://identi.ca/main/register">Register</a> a new account.' - .' </p>' - .'</div>' - .'<div id="content">' - .' <form method="post" id="login">' - .' <p>' - .' <label for="nickname">Nickname</label>' - .' <input name="nickname" type="text" class="input_text" id="nickname"/>' - .' </p>' - .' <p>' - .' <label for="password">Password</label>' - .' <input name="password" type="password" class="password" id="password"/>' - .' </p>' - .' <p>' - .' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>' - .' </p>' - .' </form>' - .' <p>' - .' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>' - .' </p>' - .'</div'; - - echo $loginform; - } - - function render_notice($notice) { - - global $config; - - $profile = $notice->getProfile(); - $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); - - $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); - - # XXX: we need to figure this out better. Is this right? - if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) { - $noticeurl = $notice->uri; - } - - $html = - '<li class="notice_single" id="' . $notice->id . '">' - .'<a href="' . $profile->profileurl . '">' - .'<img src="'; - - if ($avatar) { - $html .= common_avatar_display_url($avatar); - } else { - $html .= common_default_avatar(AVATAR_STREAM_SIZE); - } - - $html .= - '" class="avatar stream" width="' - . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"' - .' alt="'; - - if ($profile->fullname) { - $html .= $profile->fullname; - } else { - $html .= $profile->nickname; - } - - $html .= - '"></a>' - .'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>' - .'<p class="content">' . $notice->rendered . '</p>' - .'<p class="time">' - .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>'; - - if ($notice->source) { - $html .= _(' from '); - $html .= $this->source_link($notice->source); - } - - if ($notice->reply_to) { - $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to)); - $html .= - ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')'; - } - - $html .= '</p></li>'; - - return $html; - } - - function source_link($source) { - $source_name = _($source); - - $html = '<span class="noticesource">'; - - switch ($source) { - case 'web': - case 'xmpp': - case 'mail': - case 'omb': - case 'api': - $html .= $source_name; - break; - default: - $ns = Notice_source::staticGet($source); - if ($ns) { - $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>'; - } else { - $html .= $source_name; - } - break; - } - - $html .= '</span>'; - - return $html; - } - - function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) { - - $html = ''; - - if ($have_before || $have_after) { - $html = '<div id="pagination">'; - $html .'<ul id="nav_pagination">'; - } - - if ($have_before) { - $pargs = array('page' => $page-1); - $newargs = ($args) ? array_merge($args,$pargs) : $pargs; - $html .= '<li class="before">'; - $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>'; - $html .'</li>'; - } - - if ($have_after) { - $pargs = array('page' => $page+1); - $newargs = ($args) ? array_merge($args,$pargs) : $pargs; - $html .= '<li class="after">'; - $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>'; - $html .'</li>'; - } - - if ($have_before || $have_after) { - $html .= '<ul>'; - $html .'<div>'; - } - } - - function pagination_url($fbaction, $args=NULL) { - global $config; - - $extra = ''; - - if ($args) { - foreach ($args as $key => $value) { - $extra .= "&${key}=${value}"; - } - } - - return "$fbaction?${extra}"; - } + function handle($args) { + parent::handle($args); + } + + function get_facebook() { + $apikey = common_config('facebook', 'apikey'); + $secret = common_config('facebook', 'secret'); + return new Facebook($apikey, $secret); + } + + function update_profile_box($facebook, $fbuid, $user) { + + $notice = $user->getCurrentNotice(); + + # Need to include inline CSS for styling the Profile box + + $style = '<style> + #notices { + clear: both; + margin: 0 auto; + padding: 0; + list-style-type: none; + width: 600px; + border-top: 1px solid #dec5b5; + } + #notices a:hover { + text-decoration: underline; + } + .notice_single { + clear: both; + display: block; + margin: 0; + padding: 5px 5px 5px 0; + min-height: 48px; + font-family: Georgia, "Times New Roman", Times, serif; + font-size: 13px; + line-height: 16px; + border-bottom: 1px solid #dec5b5; + background-color:#FCFFF5; + opacity:1; + } + .notice_single:hover { + background-color: #f7ebcc; + } + .notice_single p { + display: inline; + margin: 0; + padding: 0; + } + </style>'; + + $html = $this->render_notice($notice); + + $fbml = "<fb:wide>$content $html</fb:wide>"; + $fbml .= "<fb:narrow>$content $html</fb:narrow>"; + + $fbml_main = "<fb:narrow>$content $html</fb:narrow>"; + + $facebook->api_client->profile_setFBML(NULL, $fbuid, $fbml, NULL, NULL, $fbml_main); + } + + # Display methods + + function show_header($selected ='Home') { + + # Add a timestamp to the CSS file so Facebook cache wont ignore our changes + $ts = filemtime(theme_file('facebookapp.css')); + $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; + + $header = '<link rel="stylesheet" type="text/css" href="'. $cssurl . '" />'; + # $header .='<script src="" ></script>'; + $header .= '<fb:dashboard/>'; + + $header .= + '<fb:tabs>' + .'<fb:tab-item title="Home" href="index.php" selected="' . ($selected == 'Home') .'" />' + .'<fb:tab-item title="Invite Friends" href="invite.php" selected="' . ($selected == 'Invite') . '" />' + .'<fb:tab-item title="Settings" href="settings.php" selected="' . ($selected == 'Settings') . '" />' + .'</fb:tabs>'; + $header .= '<div id="main_body">'; + + echo $header; + + } + + function show_footer() { + $footer = '</div>'; + echo $footer; + } + + function show_login_form() { + + $loginform = + ' <h2>To add the Identi.ca application, you need to log into your Identi.ca account.</h2>' + .'<a href="http://identi.ca/">' + .' <img src="http://theme.identi.ca/identica/logo.png" alt="Identi.ca" id="logo"/>' + .'</a>' + .'<h1 class="pagetitle">Login</h1>' + .'<div class="instructions">' + .' <p>Login with your username and password. Don\'t have a username yet?' + .' <a href="http://identi.ca/main/register">Register</a> a new account.' + .' </p>' + .'</div>' + .'<div id="content">' + .' <form method="post" id="login">' + .' <p>' + .' <label for="nickname">Nickname</label>' + .' <input name="nickname" type="text" class="input_text" id="nickname"/>' + .' </p>' + .' <p>' + .' <label for="password">Password</label>' + .' <input name="password" type="password" class="password" id="password"/>' + .' </p>' + .' <p>' + .' <input type="submit" id="submit" name="submit" class="submit" value="Login"/>' + .' </p>' + .' </form>' + .' <p>' + .' <a href="http://identi.ca/main/recoverpassword">Lost or forgotten password?</a>' + .' </p>' + .'</div'; + + echo $loginform; + } + + function render_notice($notice) { + + global $config; + + $profile = $notice->getProfile(); + $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); + + $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); + + # XXX: we need to figure this out better. Is this right? + if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) { + $noticeurl = $notice->uri; + } + + $html = + '<li class="notice_single" id="' . $notice->id . '">' + .'<a href="' . $profile->profileurl . '">' + .'<img src="'; + + if ($avatar) { + $html .= common_avatar_display_url($avatar); + } else { + $html .= common_default_avatar(AVATAR_STREAM_SIZE); + } + + $html .= + '" class="avatar stream" width="' + . AVATAR_STREAM_SIZE . '" height="' . AVATAR_STREAM_SIZE .'"' + .' alt="'; + + if ($profile->fullname) { + $html .= $profile->fullname; + } else { + $html .= $profile->nickname; + } + + $html .= + '"></a>' + .'<a href="' . $profile->profileurl . '" class="nickname">' . $profile->nickname . '</a>' + .'<p class="content">' . $notice->rendered . '</p>' + .'<p class="time">' + .'<a class="permalink" href="' . $noticeurl . '" title="' . common_exact_date($notice->created) . '">' . common_date_string($notice->created) . '</a>'; + + if ($notice->source) { + $html .= _(' from '); + $html .= $this->source_link($notice->source); + } + + if ($notice->reply_to) { + $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to)); + $html .= + ' (<a class="inreplyto" href="' . $replyurl . '">' . _('in reply to...') . ')'; + } + + $html .= '</p></li>'; + + return $html; + } + + function source_link($source) { + $source_name = _($source); + + $html = '<span class="noticesource">'; + + switch ($source) { + case 'web': + case 'xmpp': + case 'mail': + case 'omb': + case 'api': + $html .= $source_name; + break; + default: + $ns = Notice_source::staticGet($source); + if ($ns) { + $html .= '<a href="' . $ns->url . '">' . $ns->name . '</a>'; + } else { + $html .= $source_name; + } + break; + } + + $html .= '</span>'; + + return $html; + } + + function pagination($have_before, $have_after, $page, $fbaction, $args=NULL) { + + $html = ''; + + if ($have_before || $have_after) { + $html = '<div id="pagination">'; + $html .'<ul id="nav_pagination">'; + } + + if ($have_before) { + $pargs = array('page' => $page-1); + $newargs = ($args) ? array_merge($args,$pargs) : $pargs; + $html .= '<li class="before">'; + $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('« After') . '</a>'; + $html .'</li>'; + } + + if ($have_after) { + $pargs = array('page' => $page+1); + $newargs = ($args) ? array_merge($args,$pargs) : $pargs; + $html .= '<li class="after">'; + $html .'<a href="' . $this->pagination_url($fbaction, $newargs) . '">' . _('Before »') . '</a>'; + $html .'</li>'; + } + + if ($have_before || $have_after) { + $html .= '<ul>'; + $html .'<div>'; + } + } + + function pagination_url($fbaction, $args=NULL) { + global $config; + + $extra = ''; + + if ($args) { + foreach ($args as $key => $value) { + $extra .= "&${key}=${value}"; + } + } + + return "$fbaction?${extra}"; + } } diff --git a/_darcs/pristine/lib/oauthstore.php b/_darcs/pristine/lib/oauthstore.php index d7f9c9ff1..aa705be30 100644 --- a/_darcs/pristine/lib/oauthstore.php +++ b/_darcs/pristine/lib/oauthstore.php @@ -23,122 +23,122 @@ require_once(INSTALLDIR.'/lib/omb.php'); class LaconicaOAuthDataStore extends OAuthDataStore { - # We keep a record of who's contacted us + # We keep a record of who's contacted us - function lookup_consumer($consumer_key) { - $con = Consumer::staticGet('consumer_key', $consumer_key); - if (!$con) { - $con = new Consumer(); - $con->consumer_key = $consumer_key; - $con->seed = common_good_rand(16); - $con->created = DB_DataObject_Cast::dateTime(); - if (!$con->insert()) { - return NULL; - } - } - return new OAuthConsumer($con->consumer_key, ''); - } + function lookup_consumer($consumer_key) { + $con = Consumer::staticGet('consumer_key', $consumer_key); + if (!$con) { + $con = new Consumer(); + $con->consumer_key = $consumer_key; + $con->seed = common_good_rand(16); + $con->created = DB_DataObject_Cast::dateTime(); + if (!$con->insert()) { + return NULL; + } + } + return new OAuthConsumer($con->consumer_key, ''); + } - function lookup_token($consumer, $token_type, $token_key) { - $t = new Token(); - $t->consumer_key = $consumer->key; - $t->tok = $token_key; - $t->type = ($token_type == 'access') ? 1 : 0; - if ($t->find(true)) { - return new OAuthToken($t->tok, $t->secret); - } else { - return NULL; - } - } + function lookup_token($consumer, $token_type, $token_key) { + $t = new Token(); + $t->consumer_key = $consumer->key; + $t->tok = $token_key; + $t->type = ($token_type == 'access') ? 1 : 0; + if ($t->find(true)) { + return new OAuthToken($t->tok, $t->secret); + } else { + return NULL; + } + } - function lookup_nonce($consumer, $token, $nonce, $timestamp) { - $n = new Nonce(); - $n->consumer_key = $consumer->key; - $n->tok = $token->key; - $n->nonce = $nonce; - if ($n->find(TRUE)) { - return TRUE; - } else { - $n->timestamp = $timestamp; - $n->created = DB_DataObject_Cast::dateTime(); - $n->insert(); - return FALSE; - } - } + function lookup_nonce($consumer, $token, $nonce, $timestamp) { + $n = new Nonce(); + $n->consumer_key = $consumer->key; + $n->tok = $token->key; + $n->nonce = $nonce; + if ($n->find(TRUE)) { + return TRUE; + } else { + $n->timestamp = $timestamp; + $n->created = DB_DataObject_Cast::dateTime(); + $n->insert(); + return FALSE; + } + } - function new_request_token($consumer) { - $t = new Token(); - $t->consumer_key = $consumer->key; - $t->tok = common_good_rand(16); - $t->secret = common_good_rand(16); - $t->type = 0; # request - $t->state = 0; # unauthorized - $t->created = DB_DataObject_Cast::dateTime(); - if (!$t->insert()) { - return NULL; - } else { - return new OAuthToken($t->tok, $t->secret); - } - } + function new_request_token($consumer) { + $t = new Token(); + $t->consumer_key = $consumer->key; + $t->tok = common_good_rand(16); + $t->secret = common_good_rand(16); + $t->type = 0; # request + $t->state = 0; # unauthorized + $t->created = DB_DataObject_Cast::dateTime(); + if (!$t->insert()) { + return NULL; + } else { + return new OAuthToken($t->tok, $t->secret); + } + } - # defined in OAuthDataStore, but not implemented anywhere + # defined in OAuthDataStore, but not implemented anywhere - function fetch_request_token($consumer) { - return $this->new_request_token($consumer); - } + function fetch_request_token($consumer) { + return $this->new_request_token($consumer); + } - function new_access_token($token, $consumer) { - common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__); - $rt = new Token(); - $rt->consumer_key = $consumer->key; - $rt->tok = $token->key; - $rt->type = 0; # request - if ($rt->find(TRUE) && $rt->state == 1) { # authorized - common_debug('request token found.', __FILE__); - $at = new Token(); - $at->consumer_key = $consumer->key; - $at->tok = common_good_rand(16); - $at->secret = common_good_rand(16); - $at->type = 1; # access - $at->created = DB_DataObject_Cast::dateTime(); - if (!$at->insert()) { - $e = $at->_lastError; - common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__); - return NULL; - } else { - common_debug('access token "'.$at->tok.'" inserted', __FILE__); - # burn the old one - $orig_rt = clone($rt); - $rt->state = 2; # used - if (!$rt->update($orig_rt)) { - return NULL; - } - common_debug('request token "'.$rt->tok.'" updated', __FILE__); - # Update subscription - # XXX: mixing levels here - $sub = Subscription::staticGet('token', $rt->tok); - if (!$sub) { - return NULL; - } - common_debug('subscription for request token found', __FILE__); - $orig_sub = clone($sub); - $sub->token = $at->tok; - $sub->secret = $at->secret; - if (!$sub->update($orig_sub)) { - return NULL; - } else { - common_debug('subscription updated to use access token', __FILE__); - return new OAuthToken($at->tok, $at->secret); - } - } - } else { - return NULL; - } - } + function new_access_token($token, $consumer) { + common_debug('new_access_token("'.$token->key.'","'.$consumer->key.'")', __FILE__); + $rt = new Token(); + $rt->consumer_key = $consumer->key; + $rt->tok = $token->key; + $rt->type = 0; # request + if ($rt->find(TRUE) && $rt->state == 1) { # authorized + common_debug('request token found.', __FILE__); + $at = new Token(); + $at->consumer_key = $consumer->key; + $at->tok = common_good_rand(16); + $at->secret = common_good_rand(16); + $at->type = 1; # access + $at->created = DB_DataObject_Cast::dateTime(); + if (!$at->insert()) { + $e = $at->_lastError; + common_debug('access token "'.$at->tok.'" not inserted: "'.$e->message.'"', __FILE__); + return NULL; + } else { + common_debug('access token "'.$at->tok.'" inserted', __FILE__); + # burn the old one + $orig_rt = clone($rt); + $rt->state = 2; # used + if (!$rt->update($orig_rt)) { + return NULL; + } + common_debug('request token "'.$rt->tok.'" updated', __FILE__); + # Update subscription + # XXX: mixing levels here + $sub = Subscription::staticGet('token', $rt->tok); + if (!$sub) { + return NULL; + } + common_debug('subscription for request token found', __FILE__); + $orig_sub = clone($sub); + $sub->token = $at->tok; + $sub->secret = $at->secret; + if (!$sub->update($orig_sub)) { + return NULL; + } else { + common_debug('subscription updated to use access token', __FILE__); + return new OAuthToken($at->tok, $at->secret); + } + } + } else { + return NULL; + } + } - # defined in OAuthDataStore, but not implemented anywhere + # defined in OAuthDataStore, but not implemented anywhere - function fetch_access_token($consumer) { - return $this->new_access_token($consumer); - } + function fetch_access_token($consumer) { + return $this->new_access_token($consumer); + } } diff --git a/_darcs/pristine/lib/omb.php b/_darcs/pristine/lib/omb.php index 96736b4d4..94ccc2ecd 100644 --- a/_darcs/pristine/lib/omb.php +++ b/_darcs/pristine/lib/omb.php @@ -44,256 +44,256 @@ define('OAUTH_POST_BODY', OAUTH_NAMESPACE.'parameters/post-body'); define('OAUTH_HMAC_SHA1', OAUTH_NAMESPACE.'signature/HMAC-SHA1'); function omb_oauth_consumer() { - static $con = NULL; - if (!$con) { - $con = new OAuthConsumer(common_root_url(), ''); - } - return $con; + static $con = NULL; + if (!$con) { + $con = new OAuthConsumer(common_root_url(), ''); + } + return $con; } function omb_oauth_server() { - static $server = null; - if (!$server) { - $server = new OAuthServer(omb_oauth_datastore()); - $server->add_signature_method(omb_hmac_sha1()); - } - return $server; + static $server = null; + if (!$server) { + $server = new OAuthServer(omb_oauth_datastore()); + $server->add_signature_method(omb_hmac_sha1()); + } + return $server; } function omb_oauth_datastore() { - static $store = NULL; - if (!$store) { - $store = new LaconicaOAuthDataStore(); - } - return $store; + static $store = NULL; + if (!$store) { + $store = new LaconicaOAuthDataStore(); + } + return $store; } function omb_hmac_sha1() { - static $hmac_method = NULL; - if (!$hmac_method) { - $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); - } - return $hmac_method; + static $hmac_method = NULL; + if (!$hmac_method) { + $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); + } + return $hmac_method; } function omb_get_services($xrd, $type) { - return $xrd->services(array(omb_service_filter($type))); + return $xrd->services(array(omb_service_filter($type))); } function omb_service_filter($type) { - return create_function('$s', - 'return omb_match_service($s, \''.$type.'\');'); + return create_function('$s', + 'return omb_match_service($s, \''.$type.'\');'); } function omb_match_service($service, $type) { - return in_array($type, $service->getTypes()); + return in_array($type, $service->getTypes()); } function omb_service_uri($service) { - if (!$service) { - return NULL; - } - $uris = $service->getURIs(); - if (!$uris) { - return NULL; - } - return $uris[0]; + if (!$service) { + return NULL; + } + $uris = $service->getURIs(); + if (!$uris) { + return NULL; + } + return $uris[0]; } function omb_local_id($service) { - if (!$service) { - return NULL; - } - $els = $service->getElements('xrd:LocalID'); - if (!$els) { - return NULL; - } - $el = $els[0]; - return $service->parser->content($el); + if (!$service) { + return NULL; + } + $els = $service->getElements('xrd:LocalID'); + if (!$els) { + return NULL; + } + $el = $els[0]; + return $service->parser->content($el); } function omb_broadcast_remote_subscribers($notice) { - # First, get remote users subscribed to this profile - $rp = new Remote_profile(); + # First, get remote users subscribed to this profile + $rp = new Remote_profile(); - $rp->query('SELECT postnoticeurl, token, secret ' . - 'FROM subscription JOIN remote_profile ' . - 'ON subscription.subscriber = remote_profile.id ' . - 'WHERE subscription.subscribed = ' . $notice->profile_id . ' '); + $rp->query('SELECT postnoticeurl, token, secret ' . + 'FROM subscription JOIN remote_profile ' . + 'ON subscription.subscriber = remote_profile.id ' . + 'WHERE subscription.subscribed = ' . $notice->profile_id . ' '); - $posted = array(); + $posted = array(); - while ($rp->fetch()) { - if (!$posted[$rp->postnoticeurl]) { - common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl); - if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) { - common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl); - $posted[$rp->postnoticeurl] = TRUE; - } else { - common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl); - } - } - } + while ($rp->fetch()) { + if (!$posted[$rp->postnoticeurl]) { + common_log(LOG_DEBUG, 'Posting to ' . $rp->postnoticeurl); + if (omb_post_notice_keys($notice, $rp->postnoticeurl, $rp->token, $rp->secret)) { + common_log(LOG_DEBUG, 'Finished to ' . $rp->postnoticeurl); + $posted[$rp->postnoticeurl] = TRUE; + } else { + common_log(LOG_DEBUG, 'Failed posting to ' . $rp->postnoticeurl); + } + } + } - $rp->free(); - unset($rp); + $rp->free(); + unset($rp); - return true; + return true; } function omb_post_notice($notice, $remote_profile, $subscription) { - return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret); + return omb_post_notice_keys($notice, $remote_profile->postnoticeurl, $subscription->token, $subscription->secret); } function omb_post_notice_keys($notice, $postnoticeurl, $tk, $secret) { - common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__); + common_debug('Posting notice ' . $notice->id . ' to ' . $postnoticeurl, __FILE__); - $user = User::staticGet('id', $notice->profile_id); + $user = User::staticGet('id', $notice->profile_id); - if (!$user) { - common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__); - return false; - } + if (!$user) { + common_debug('Failed to get user for notice ' . $notice->id . ', profile = ' . $notice->profile_id, __FILE__); + return false; + } - $con = omb_oauth_consumer(); + $con = omb_oauth_consumer(); - $token = new OAuthToken($tk, $secret); + $token = new OAuthToken($tk, $secret); - $url = $postnoticeurl; - $parsed = parse_url($url); - $params = array(); - parse_str($parsed['query'], $params); + $url = $postnoticeurl; + $parsed = parse_url($url); + $params = array(); + parse_str($parsed['query'], $params); - $req = OAuthRequest::from_consumer_and_token($con, $token, - 'POST', $url, $params); + $req = OAuthRequest::from_consumer_and_token($con, $token, + 'POST', $url, $params); - $req->set_parameter('omb_version', OMB_VERSION_01); - $req->set_parameter('omb_listenee', $user->uri); - $req->set_parameter('omb_notice', $notice->uri); - $req->set_parameter('omb_notice_content', $notice->content); - $req->set_parameter('omb_notice_url', common_local_url('shownotice', - array('notice' => - $notice->id))); - $req->set_parameter('omb_notice_license', common_config('license', 'url')); + $req->set_parameter('omb_version', OMB_VERSION_01); + $req->set_parameter('omb_listenee', $user->uri); + $req->set_parameter('omb_notice', $notice->uri); + $req->set_parameter('omb_notice_content', $notice->content); + $req->set_parameter('omb_notice_url', common_local_url('shownotice', + array('notice' => + $notice->id))); + $req->set_parameter('omb_notice_license', common_config('license', 'url')); - $user->free(); - unset($user); + $user->free(); + unset($user); - $req->sign_request(omb_hmac_sha1(), $con, $token); + $req->sign_request(omb_hmac_sha1(), $con, $token); - # We re-use this tool's fetcher, since it's pretty good + # We re-use this tool's fetcher, since it's pretty good - $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); + $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); - if (!$fetcher) { - common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__); - return false; - } + if (!$fetcher) { + common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__); + return false; + } - $result = $fetcher->post($req->get_normalized_http_url(), - $req->to_postdata(), + $result = $fetcher->post($req->get_normalized_http_url(), + $req->to_postdata(), array('User-Agent' => 'Laconica/' . LACONICA_VERSION)); - common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__); - - if ($result->status == 403) { # not authorized, don't send again - common_debug('403 result, deleting subscription', __FILE__); - # FIXME: figure out how to delete this - # $subscription->delete(); - return false; - } else if ($result->status != 200) { - common_debug('Error status '.$result->status, __FILE__); - return false; - } else { # success! - parse_str($result->body, $return); - if ($return['omb_version'] == OMB_VERSION_01) { - return true; - } else { - return false; - } - } + common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__); + + if ($result->status == 403) { # not authorized, don't send again + common_debug('403 result, deleting subscription', __FILE__); + # FIXME: figure out how to delete this + # $subscription->delete(); + return false; + } else if ($result->status != 200) { + common_debug('Error status '.$result->status, __FILE__); + return false; + } else { # success! + parse_str($result->body, $return); + if ($return['omb_version'] == OMB_VERSION_01) { + return true; + } else { + return false; + } + } } function omb_broadcast_profile($profile) { - # First, get remote users subscribed to this profile - # XXX: use a join here rather than looping through results - $sub = new Subscription(); - $sub->subscribed = $profile->id; - if ($sub->find()) { - $updated = array(); - while ($sub->fetch()) { - $rp = Remote_profile::staticGet('id', $sub->subscriber); - if ($rp) { - if (!$updated[$rp->updateprofileurl]) { - if (omb_update_profile($profile, $rp, $sub)) { - $updated[$rp->updateprofileurl] = TRUE; - } - } - } - } - } + # First, get remote users subscribed to this profile + # XXX: use a join here rather than looping through results + $sub = new Subscription(); + $sub->subscribed = $profile->id; + if ($sub->find()) { + $updated = array(); + while ($sub->fetch()) { + $rp = Remote_profile::staticGet('id', $sub->subscriber); + if ($rp) { + if (!$updated[$rp->updateprofileurl]) { + if (omb_update_profile($profile, $rp, $sub)) { + $updated[$rp->updateprofileurl] = TRUE; + } + } + } + } + } } function omb_update_profile($profile, $remote_profile, $subscription) { - global $config; # for license URL - $user = User::staticGet($profile->id); - $con = omb_oauth_consumer(); - $token = new OAuthToken($subscription->token, $subscription->secret); - $url = $remote_profile->updateprofileurl; - $parsed = parse_url($url); - $params = array(); - parse_str($parsed['query'], $params); - $req = OAuthRequest::from_consumer_and_token($con, $token, - "POST", $url, $params); - $req->set_parameter('omb_version', OMB_VERSION_01); - $req->set_parameter('omb_listenee', $user->uri); - $req->set_parameter('omb_listenee_profile', common_profile_url($profile->nickname)); - $req->set_parameter('omb_listenee_nickname', $profile->nickname); - - # We use blanks to force emptying any existing values in these optional fields - - $req->set_parameter('omb_listenee_fullname', - ($profile->fullname) ? $profile->fullname : ''); - $req->set_parameter('omb_listenee_homepage', - ($profile->homepage) ? $profile->homepage : ''); - $req->set_parameter('omb_listenee_bio', - ($profile->bio) ? $profile->bio : ''); - $req->set_parameter('omb_listenee_location', - ($profile->location) ? $profile->location : ''); - - $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); - $req->set_parameter('omb_listenee_avatar', - ($avatar) ? $avatar->url : ''); - - $req->sign_request(omb_hmac_sha1(), $con, $token); - - # We re-use this tool's fetcher, since it's pretty good - - $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); - - common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__); - common_debug('postdata = '.$req->to_postdata(), __FILE__); - $result = $fetcher->post($req->get_normalized_http_url(), - $req->to_postdata(), + global $config; # for license URL + $user = User::staticGet($profile->id); + $con = omb_oauth_consumer(); + $token = new OAuthToken($subscription->token, $subscription->secret); + $url = $remote_profile->updateprofileurl; + $parsed = parse_url($url); + $params = array(); + parse_str($parsed['query'], $params); + $req = OAuthRequest::from_consumer_and_token($con, $token, + "POST", $url, $params); + $req->set_parameter('omb_version', OMB_VERSION_01); + $req->set_parameter('omb_listenee', $user->uri); + $req->set_parameter('omb_listenee_profile', common_profile_url($profile->nickname)); + $req->set_parameter('omb_listenee_nickname', $profile->nickname); + + # We use blanks to force emptying any existing values in these optional fields + + $req->set_parameter('omb_listenee_fullname', + ($profile->fullname) ? $profile->fullname : ''); + $req->set_parameter('omb_listenee_homepage', + ($profile->homepage) ? $profile->homepage : ''); + $req->set_parameter('omb_listenee_bio', + ($profile->bio) ? $profile->bio : ''); + $req->set_parameter('omb_listenee_location', + ($profile->location) ? $profile->location : ''); + + $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE); + $req->set_parameter('omb_listenee_avatar', + ($avatar) ? $avatar->url : ''); + + $req->sign_request(omb_hmac_sha1(), $con, $token); + + # We re-use this tool's fetcher, since it's pretty good + + $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); + + common_debug('request URL = '.$req->get_normalized_http_url(), __FILE__); + common_debug('postdata = '.$req->to_postdata(), __FILE__); + $result = $fetcher->post($req->get_normalized_http_url(), + $req->to_postdata(), array('User-Agent' => 'Laconica/' . LACONICA_VERSION)); - common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__); - - if ($result->status == 403) { # not authorized, don't send again - common_debug('403 result, deleting subscription', __FILE__); - $subscription->delete(); - return false; - } else if ($result->status != 200) { - common_debug('Error status '.$result->status, __FILE__); - return false; - } else { # success! - parse_str($result->body, $return); - if ($return['omb_version'] == OMB_VERSION_01) { - return true; - } else { - return false; - } - } + common_debug('Got HTTP result "'.print_r($result,TRUE).'"', __FILE__); + + if ($result->status == 403) { # not authorized, don't send again + common_debug('403 result, deleting subscription', __FILE__); + $subscription->delete(); + return false; + } else if ($result->status != 200) { + common_debug('Error status '.$result->status, __FILE__); + return false; + } else { # success! + parse_str($result->body, $return); + if ($return['omb_version'] == OMB_VERSION_01) { + return true; + } else { + return false; + } + } } diff --git a/_darcs/pristine/lib/openid.php b/_darcs/pristine/lib/openid.php index 6e501c2b1..ebc5ed168 100644 --- a/_darcs/pristine/lib/openid.php +++ b/_darcs/pristine/lib/openid.php @@ -33,210 +33,210 @@ define('OPENID_COOKIE_KEY', 'lastusedopenid'); function oid_store() { static $store = NULL; - if (!$store) { - # Can't be called statically - $user = new User(); - $conn = $user->getDatabaseConnection(); - $store = new Auth_OpenID_MySQLStore($conn); - } - return $store; + if (!$store) { + # Can't be called statically + $user = new User(); + $conn = $user->getDatabaseConnection(); + $store = new Auth_OpenID_MySQLStore($conn); + } + return $store; } function oid_consumer() { - $store = oid_store(); - $consumer = new Auth_OpenID_Consumer($store); - return $consumer; + $store = oid_store(); + $consumer = new Auth_OpenID_Consumer($store); + return $consumer; } function oid_clear_last() { - oid_set_last(''); + oid_set_last(''); } function oid_set_last($openid_url) { - common_set_cookie(OPENID_COOKIE_KEY, - $openid_url, - time() + OPENID_COOKIE_EXPIRY); + common_set_cookie(OPENID_COOKIE_KEY, + $openid_url, + time() + OPENID_COOKIE_EXPIRY); } function oid_get_last() { - $openid_url = $_COOKIE[OPENID_COOKIE_KEY]; - if ($openid_url && strlen($openid_url) > 0) { - return $openid_url; - } else { - return NULL; - } + $openid_url = $_COOKIE[OPENID_COOKIE_KEY]; + if ($openid_url && strlen($openid_url) > 0) { + return $openid_url; + } else { + return NULL; + } } function oid_link_user($id, $canonical, $display) { - $oid = new User_openid(); - $oid->user_id = $id; - $oid->canonical = $canonical; - $oid->display = $display; - $oid->created = DB_DataObject_Cast::dateTime(); + $oid = new User_openid(); + $oid->user_id = $id; + $oid->canonical = $canonical; + $oid->display = $display; + $oid->created = DB_DataObject_Cast::dateTime(); - if (!$oid->insert()) { - $err = PEAR::getStaticProperty('DB_DataObject','lastError'); - common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__); - return false; - } + if (!$oid->insert()) { + $err = PEAR::getStaticProperty('DB_DataObject','lastError'); + common_debug('DB error ' . $err->code . ': ' . $err->message, __FILE__); + return false; + } - return true; + return true; } function oid_get_user($openid_url) { - $user = NULL; - $oid = User_openid::staticGet('canonical', $openid_url); - if ($oid) { - $user = User::staticGet('id', $oid->user_id); - } - return $user; + $user = NULL; + $oid = User_openid::staticGet('canonical', $openid_url); + if ($oid) { + $user = User::staticGet('id', $oid->user_id); + } + return $user; } function oid_check_immediate($openid_url, $backto=NULL) { - if (!$backto) { - $action = $_REQUEST['action']; - $args = common_copy_args($_GET); - unset($args['action']); - $backto = common_local_url($action, $args); - } - common_debug('going back to "' . $backto . '"', __FILE__); - - common_ensure_session(); - - $_SESSION['openid_immediate_backto'] = $backto; - common_debug('passed-in variable is "' . $backto . '"', __FILE__); - common_debug('session variable is "' . $_SESSION['openid_immediate_backto'] . '"', __FILE__); - - oid_authenticate($openid_url, - 'finishimmediate', - true); + if (!$backto) { + $action = $_REQUEST['action']; + $args = common_copy_args($_GET); + unset($args['action']); + $backto = common_local_url($action, $args); + } + common_debug('going back to "' . $backto . '"', __FILE__); + + common_ensure_session(); + + $_SESSION['openid_immediate_backto'] = $backto; + common_debug('passed-in variable is "' . $backto . '"', __FILE__); + common_debug('session variable is "' . $_SESSION['openid_immediate_backto'] . '"', __FILE__); + + oid_authenticate($openid_url, + 'finishimmediate', + true); } function oid_authenticate($openid_url, $returnto, $immediate=false) { - $consumer = oid_consumer(); - - if (!$consumer) { - common_server_error(_('Cannot instantiate OpenID consumer object.')); - return false; - } - - common_ensure_session(); - - $auth_request = $consumer->begin($openid_url); - - // Handle failure status return values. - if (!$auth_request) { - return _('Not a valid OpenID.'); - } else if (Auth_OpenID::isFailure($auth_request)) { - return sprintf(_('OpenID failure: %s'), $auth_request->message); - } - - $sreg_request = Auth_OpenID_SRegRequest::build(// Required - array(), - // Optional - array('nickname', - 'email', - 'fullname', - 'language', - 'timezone', - 'postcode', - 'country')); - - if ($sreg_request) { - $auth_request->addExtension($sreg_request); - } - - $trust_root = common_local_url('public'); - $process_url = common_local_url($returnto); - - if ($auth_request->shouldSendRedirect()) { - $redirect_url = $auth_request->redirectURL($trust_root, - $process_url, - $immediate); - if (!$redirect_url) { - } else if (Auth_OpenID::isFailure($redirect_url)) { - return sprintf(_('Could not redirect to server: %s'), $redirect_url->message); - } else { - common_redirect($redirect_url); - } - } else { - // Generate form markup and render it. - $form_id = 'openid_message'; - $form_html = $auth_request->formMarkup($trust_root, $process_url, - $immediate, array('id' => $form_id)); - - # XXX: This is cheap, but things choke if we don't escape ampersands - # in the HTML attributes - - $form_html = preg_replace('/&/', '&', $form_html); - - // Display an error if the form markup couldn't be generated; - // otherwise, render the HTML. - if (Auth_OpenID::isFailure($form_html)) { - $this->show_form(sprintf(_('Could not create OpenID form: %s'), $form_html->message)); - } else { - common_show_header(_('OpenID Auto-Submit'), NULL, NULL, '_oid_print_instructions'); - common_raw($form_html); - common_element('script', NULL, - '$(document).ready(function() { ' . - ' $("#'. $form_id .'").submit(); '. - '});'); - common_show_footer(); - } - } + $consumer = oid_consumer(); + + if (!$consumer) { + common_server_error(_('Cannot instantiate OpenID consumer object.')); + return false; + } + + common_ensure_session(); + + $auth_request = $consumer->begin($openid_url); + + // Handle failure status return values. + if (!$auth_request) { + return _('Not a valid OpenID.'); + } else if (Auth_OpenID::isFailure($auth_request)) { + return sprintf(_('OpenID failure: %s'), $auth_request->message); + } + + $sreg_request = Auth_OpenID_SRegRequest::build(// Required + array(), + // Optional + array('nickname', + 'email', + 'fullname', + 'language', + 'timezone', + 'postcode', + 'country')); + + if ($sreg_request) { + $auth_request->addExtension($sreg_request); + } + + $trust_root = common_local_url('public'); + $process_url = common_local_url($returnto); + + if ($auth_request->shouldSendRedirect()) { + $redirect_url = $auth_request->redirectURL($trust_root, + $process_url, + $immediate); + if (!$redirect_url) { + } else if (Auth_OpenID::isFailure($redirect_url)) { + return sprintf(_('Could not redirect to server: %s'), $redirect_url->message); + } else { + common_redirect($redirect_url); + } + } else { + // Generate form markup and render it. + $form_id = 'openid_message'; + $form_html = $auth_request->formMarkup($trust_root, $process_url, + $immediate, array('id' => $form_id)); + + # XXX: This is cheap, but things choke if we don't escape ampersands + # in the HTML attributes + + $form_html = preg_replace('/&/', '&', $form_html); + + // Display an error if the form markup couldn't be generated; + // otherwise, render the HTML. + if (Auth_OpenID::isFailure($form_html)) { + $this->show_form(sprintf(_('Could not create OpenID form: %s'), $form_html->message)); + } else { + common_show_header(_('OpenID Auto-Submit'), NULL, NULL, '_oid_print_instructions'); + common_raw($form_html); + common_element('script', NULL, + '$(document).ready(function() { ' . + ' $("#'. $form_id .'").submit(); '. + '});'); + common_show_footer(); + } + } } # Half-assed attempt at a module-private function function _oid_print_instructions() { - common_element('div', 'instructions', - _('This form should automatically submit itself. '. - 'If not, click the submit button to go to your '. - 'OpenID provider.')); + common_element('div', 'instructions', + _('This form should automatically submit itself. '. + 'If not, click the submit button to go to your '. + 'OpenID provider.')); } # update a user from sreg parameters function oid_update_user(&$user, &$sreg) { - $profile = $user->getProfile(); + $profile = $user->getProfile(); - $orig_profile = clone($profile); + $orig_profile = clone($profile); - if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) { - $profile->fullname = $sreg['fullname']; - } + if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) { + $profile->fullname = $sreg['fullname']; + } - if ($sreg['country']) { - if ($sreg['postcode']) { - # XXX: use postcode to get city and region - # XXX: also, store postcode somewhere -- it's valuable! - $profile->location = $sreg['postcode'] . ', ' . $sreg['country']; - } else { - $profile->location = $sreg['country']; - } - } + if ($sreg['country']) { + if ($sreg['postcode']) { + # XXX: use postcode to get city and region + # XXX: also, store postcode somewhere -- it's valuable! + $profile->location = $sreg['postcode'] . ', ' . $sreg['country']; + } else { + $profile->location = $sreg['country']; + } + } - # XXX save language if it's passed - # XXX save timezone if it's passed + # XXX save language if it's passed + # XXX save timezone if it's passed - if (!$profile->update($orig_profile)) { - common_server_error(_('Error saving the profile.')); - return false; - } + if (!$profile->update($orig_profile)) { + common_server_error(_('Error saving the profile.')); + return false; + } - $orig_user = clone($user); + $orig_user = clone($user); - if ($sreg['email'] && Validate::email($sreg['email'], true)) { - $user->email = $sreg['email']; - } + if ($sreg['email'] && Validate::email($sreg['email'], true)) { + $user->email = $sreg['email']; + } - if (!$user->update($orig_user)) { - common_server_error(_('Error saving the user.')); - return false; - } + if (!$user->update($orig_user)) { + common_server_error(_('Error saving the user.')); + return false; + } - return true; + return true; } diff --git a/_darcs/pristine/lib/personal.php b/_darcs/pristine/lib/personal.php index 86433b486..1928349a3 100644 --- a/_darcs/pristine/lib/personal.php +++ b/_darcs/pristine/lib/personal.php @@ -20,187 +20,187 @@ if (!defined('LACONICA')) { exit(1); } class PersonalAction extends Action { - - function is_readonly() { - return true; - } - - function handle($args) { - parent::handle($args); - common_set_returnto($this->self_url()); - } - - function views_menu() { - - $user = NULL; - $action = $this->trimmed('action'); - $nickname = $this->trimmed('nickname'); - - if ($nickname) { - $user = User::staticGet('nickname', $nickname); - $user_profile = $user->getProfile(); - } else { - $user_profile = false; - } - - common_element_start('ul', array('id' => 'nav_views')); - - common_menu_item(common_local_url('all', array('nickname' => - $nickname)), - _('Personal'), - sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), - $action == 'all'); - common_menu_item(common_local_url('replies', array('nickname' => - $nickname)), - _('Replies'), - sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), - $action == 'replies'); - common_menu_item(common_local_url('showstream', array('nickname' => - $nickname)), - _('Profile'), - ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname, - $action == 'showstream'); - common_menu_item(common_local_url('showfavorites', array('nickname' => - $nickname)), - _('Favorites'), - sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), - $action == 'showfavorites'); - - $cur = common_current_user(); - - if ($cur && $cur->id == $user->id) { - - common_menu_item(common_local_url('inbox', array('nickname' => - $nickname)), - _('Inbox'), - _('Your incoming messages'), - $action == 'inbox'); - common_menu_item(common_local_url('outbox', array('nickname' => - $nickname)), - _('Outbox'), - _('Your sent messages'), - $action == 'outbox'); - } - - common_element_end('ul'); - } - - function show_feeds_list($feeds) { - common_element_start('div', array('class' => 'feeds')); - common_element('p', null, 'Feeds:'); - common_element_start('ul', array('class' => 'xoxo')); - - foreach ($feeds as $key => $value) { - $this->common_feed_item($feeds[$key]); - } - common_element_end('ul'); - common_element_end('div'); - } - - function common_feed_item($feed) { - $nickname = $this->trimmed('nickname'); - - switch($feed['item']) { - case 'notices': default: - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "$nickname's ".$feed['version']." notice feed"; - $feed['textContent'] = "RSS"; - break; - - case 'allrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = $feed['version']." feed for $nickname and friends"; - $feed['textContent'] = "RSS"; - break; - - case 'repliesrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = $feed['version']." feed for replies to $nickname"; - $feed['textContent'] = "RSS"; - break; - - case 'publicrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "Public timeline ".$feed['version']." feed"; - $feed['textContent'] = "RSS"; - break; - - case 'publicatom': - $feed_classname = "atom"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "Public timeline ".$feed['version']." feed"; - $feed['textContent'] = "Atom"; - break; - - case 'tagrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = $feed['version']." feed for this tag"; - $feed['textContent'] = "RSS"; - break; - - case 'favoritedrss': - $feed_classname = $feed['type']; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "Favorited ".$feed['version']." feed"; - $feed['textContent'] = "RSS"; - break; - - case 'foaf': - $feed_classname = "foaf"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "$nickname's FOAF file"; - $feed['textContent'] = "FOAF"; - break; - - case 'favoritesrss': - $feed_classname = "favorites"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "Feed for favorites of $nickname"; - $feed['textContent'] = "RSS"; - break; - - case 'usertimeline': - $feed_classname = "atom"; - $feed_mimetype = "application/".$feed['type']."+xml"; - $feed_title = "$nickname's ".$feed['version']." notice feed"; - $feed['textContent'] = "Atom"; - break; - } - common_element_start('li'); - common_element('a', array('href' => $feed['href'], - 'class' => $feed_classname, - 'type' => $feed_mimetype, - 'title' => $feed_title), - $feed['textContent']); - common_element_end('li'); - } - - - function source_link($source) { - $source_name = _($source); - switch ($source) { - case 'web': - case 'xmpp': - case 'mail': - case 'omb': - case 'api': - common_element('span', 'noticesource', $source_name); - break; - default: - $ns = Notice_source::staticGet($source); - if ($ns) { - common_element('a', array('href' => $ns->url), - $ns->name); - } else { - common_element('span', 'noticesource', $source_name); - } - break; - } - return; - } + + function is_readonly() { + return true; + } + + function handle($args) { + parent::handle($args); + common_set_returnto($this->self_url()); + } + + function views_menu() { + + $user = NULL; + $action = $this->trimmed('action'); + $nickname = $this->trimmed('nickname'); + + if ($nickname) { + $user = User::staticGet('nickname', $nickname); + $user_profile = $user->getProfile(); + } else { + $user_profile = false; + } + + common_element_start('ul', array('id' => 'nav_views')); + + common_menu_item(common_local_url('all', array('nickname' => + $nickname)), + _('Personal'), + sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + $action == 'all'); + common_menu_item(common_local_url('replies', array('nickname' => + $nickname)), + _('Replies'), + sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + $action == 'replies'); + common_menu_item(common_local_url('showstream', array('nickname' => + $nickname)), + _('Profile'), + ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname, + $action == 'showstream'); + common_menu_item(common_local_url('showfavorites', array('nickname' => + $nickname)), + _('Favorites'), + sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), + $action == 'showfavorites'); + + $cur = common_current_user(); + + if ($cur && $cur->id == $user->id) { + + common_menu_item(common_local_url('inbox', array('nickname' => + $nickname)), + _('Inbox'), + _('Your incoming messages'), + $action == 'inbox'); + common_menu_item(common_local_url('outbox', array('nickname' => + $nickname)), + _('Outbox'), + _('Your sent messages'), + $action == 'outbox'); + } + + common_element_end('ul'); + } + + function show_feeds_list($feeds) { + common_element_start('div', array('class' => 'feeds')); + common_element('p', null, 'Feeds:'); + common_element_start('ul', array('class' => 'xoxo')); + + foreach ($feeds as $key => $value) { + $this->common_feed_item($feeds[$key]); + } + common_element_end('ul'); + common_element_end('div'); + } + + function common_feed_item($feed) { + $nickname = $this->trimmed('nickname'); + + switch($feed['item']) { + case 'notices': default: + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "$nickname's ".$feed['version']." notice feed"; + $feed['textContent'] = "RSS"; + break; + + case 'allrss': + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = $feed['version']." feed for $nickname and friends"; + $feed['textContent'] = "RSS"; + break; + + case 'repliesrss': + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = $feed['version']." feed for replies to $nickname"; + $feed['textContent'] = "RSS"; + break; + + case 'publicrss': + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "Public timeline ".$feed['version']." feed"; + $feed['textContent'] = "RSS"; + break; + + case 'publicatom': + $feed_classname = "atom"; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "Public timeline ".$feed['version']." feed"; + $feed['textContent'] = "Atom"; + break; + + case 'tagrss': + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = $feed['version']." feed for this tag"; + $feed['textContent'] = "RSS"; + break; + + case 'favoritedrss': + $feed_classname = $feed['type']; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "Favorited ".$feed['version']." feed"; + $feed['textContent'] = "RSS"; + break; + + case 'foaf': + $feed_classname = "foaf"; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "$nickname's FOAF file"; + $feed['textContent'] = "FOAF"; + break; + + case 'favoritesrss': + $feed_classname = "favorites"; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "Feed for favorites of $nickname"; + $feed['textContent'] = "RSS"; + break; + + case 'usertimeline': + $feed_classname = "atom"; + $feed_mimetype = "application/".$feed['type']."+xml"; + $feed_title = "$nickname's ".$feed['version']." notice feed"; + $feed['textContent'] = "Atom"; + break; + } + common_element_start('li'); + common_element('a', array('href' => $feed['href'], + 'class' => $feed_classname, + 'type' => $feed_mimetype, + 'title' => $feed_title), + $feed['textContent']); + common_element_end('li'); + } + + + function source_link($source) { + $source_name = _($source); + switch ($source) { + case 'web': + case 'xmpp': + case 'mail': + case 'omb': + case 'api': + common_element('span', 'noticesource', $source_name); + break; + default: + $ns = Notice_source::staticGet($source); + if ($ns) { + common_element('a', array('href' => $ns->url), + $ns->name); + } else { + common_element('span', 'noticesource', $source_name); + } + break; + } + return; + } } diff --git a/_darcs/pristine/lib/profilelist.php b/_darcs/pristine/lib/profilelist.php index 9079ea9d7..e32c5c254 100644 --- a/_darcs/pristine/lib/profilelist.php +++ b/_darcs/pristine/lib/profilelist.php @@ -24,138 +24,138 @@ define('PROFILES_PER_PAGE', 20); class ProfileList { - var $profile = NULL; - var $owner = NULL; - var $action = NULL; - - function __construct($profile, $owner=NULL, $action=NULL) { - $this->profile = $profile; - $this->owner = $owner; - $this->action = $action; - } - - function show_list() { - - common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list')); - - $cnt = 0; - - while ($this->profile->fetch()) { - $cnt++; - if($cnt > PROFILES_PER_PAGE) { - break; - } - $this->show(); - } - - common_element_end('ul'); - - return $cnt; - } - - function show() { - - common_element_start('li', array('class' => 'profile_single', - 'id' => 'profile-' . $this->profile->id)); - - $user = common_current_user(); - - if ($user && $user->id != $this->profile->id) { - # XXX: special-case for user looking at own - # subscriptions page - if ($user->isSubscribed($this->profile)) { - common_unsubscribe_form($this->profile); - } else { - common_subscribe_form($this->profile); - } - } - - $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE); - common_element_start('a', array('href' => $this->profile->profileurl)); - common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE), - 'class' => 'avatar stream', - 'width' => AVATAR_STREAM_SIZE, - 'height' => AVATAR_STREAM_SIZE, - 'alt' => - ($this->profile->fullname) ? $this->profile->fullname : - $this->profile->nickname)); - common_element_end('a'); - common_element_start('p'); - common_element_start('a', array('href' => $this->profile->profileurl, - 'class' => 'nickname')); - common_raw($this->highlight($this->profile->nickname)); - common_element_end('a'); - if ($this->profile->fullname) { - common_text(' | '); - common_element_start('span', 'fullname'); - common_raw($this->highlight($this->profile->fullname)); - common_element_end('span'); - } - if ($this->profile->location) { - common_text(' | '); - common_element_start('span', 'location'); - common_raw($this->highlight($this->profile->location)); - common_element_end('span'); - } - common_element_end('p'); - if ($this->profile->homepage) { - common_element_start('p', 'website'); - common_element_start('a', array('href' => $this->profile->homepage)); - common_raw($this->highlight($this->profile->homepage)); - common_element_end('a'); - common_element_end('p'); - } - if ($this->profile->bio) { - common_element_start('p', 'bio'); - common_raw($this->highlight($this->profile->bio)); - common_element_end('p'); - } - - # If we're on a list with an owner (subscriptions or subscribers)... - - if ($this->owner) { - # Get tags - $tags = Profile_tag::getTags($this->owner->id, $this->profile->id); - - common_element_start('div', 'tags_user'); - common_element_start('dl'); - common_element_start('dt'); - if ($user->id == $this->owner->id) { - common_element('a', array('href' => common_local_url('tagother', - array('id' => $this->profile->id))), - _('Tags')); - } else { - common_text(_('Tags')); - } - common_text(":"); - common_element_end('dt'); - common_element_start('dd'); - if ($tags) { - common_element_start('ul', 'tags xoxo'); - foreach ($tags as $tag) { - common_element_start('li'); - common_element('a', array('rel' => 'tag', - 'href' => common_local_url($this->action, - array('nickname' => $this->owner->nickname, - 'tag' => $tag))), - $tag); - common_element_end('li'); - } - common_element_end('ul'); - } else { - common_text(_('(none)')); - } - common_element_end('dd'); - common_element_end('dl'); - common_element_end('div'); - } + var $profile = NULL; + var $owner = NULL; + var $action = NULL; + + function __construct($profile, $owner=NULL, $action=NULL) { + $this->profile = $profile; + $this->owner = $owner; + $this->action = $action; + } + + function show_list() { + + common_element_start('ul', array('id' => 'profiles', 'class' => 'profile_list')); + + $cnt = 0; + + while ($this->profile->fetch()) { + $cnt++; + if($cnt > PROFILES_PER_PAGE) { + break; + } + $this->show(); + } + + common_element_end('ul'); + + return $cnt; + } + + function show() { + + common_element_start('li', array('class' => 'profile_single', + 'id' => 'profile-' . $this->profile->id)); + + $user = common_current_user(); + + if ($user && $user->id != $this->profile->id) { + # XXX: special-case for user looking at own + # subscriptions page + if ($user->isSubscribed($this->profile)) { + common_unsubscribe_form($this->profile); + } else { + common_subscribe_form($this->profile); + } + } + + $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE); + common_element_start('a', array('href' => $this->profile->profileurl)); + common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE), + 'class' => 'avatar stream', + 'width' => AVATAR_STREAM_SIZE, + 'height' => AVATAR_STREAM_SIZE, + 'alt' => + ($this->profile->fullname) ? $this->profile->fullname : + $this->profile->nickname)); + common_element_end('a'); + common_element_start('p'); + common_element_start('a', array('href' => $this->profile->profileurl, + 'class' => 'nickname')); + common_raw($this->highlight($this->profile->nickname)); + common_element_end('a'); + if ($this->profile->fullname) { + common_text(' | '); + common_element_start('span', 'fullname'); + common_raw($this->highlight($this->profile->fullname)); + common_element_end('span'); + } + if ($this->profile->location) { + common_text(' | '); + common_element_start('span', 'location'); + common_raw($this->highlight($this->profile->location)); + common_element_end('span'); + } + common_element_end('p'); + if ($this->profile->homepage) { + common_element_start('p', 'website'); + common_element_start('a', array('href' => $this->profile->homepage)); + common_raw($this->highlight($this->profile->homepage)); + common_element_end('a'); + common_element_end('p'); + } + if ($this->profile->bio) { + common_element_start('p', 'bio'); + common_raw($this->highlight($this->profile->bio)); + common_element_end('p'); + } + + # If we're on a list with an owner (subscriptions or subscribers)... + + if ($this->owner) { + # Get tags + $tags = Profile_tag::getTags($this->owner->id, $this->profile->id); + + common_element_start('div', 'tags_user'); + common_element_start('dl'); + common_element_start('dt'); + if ($user->id == $this->owner->id) { + common_element('a', array('href' => common_local_url('tagother', + array('id' => $this->profile->id))), + _('Tags')); + } else { + common_text(_('Tags')); + } + common_text(":"); + common_element_end('dt'); + common_element_start('dd'); + if ($tags) { + common_element_start('ul', 'tags xoxo'); + foreach ($tags as $tag) { + common_element_start('li'); + common_element('a', array('rel' => 'tag', + 'href' => common_local_url($this->action, + array('nickname' => $this->owner->nickname, + 'tag' => $tag))), + $tag); + common_element_end('li'); + } + common_element_end('ul'); + } else { + common_text(_('(none)')); + } + common_element_end('dd'); + common_element_end('dl'); + common_element_end('div'); + } if ($user && $user->id == $this->owner->id) { $this->show_owner_controls($this->profile); } - common_element_end('li'); - } + common_element_end('li'); + } /* Override this in subclasses. */ @@ -163,7 +163,7 @@ class ProfileList { return; } - function highlight($text) { - return htmlspecialchars($text); - } + function highlight($text) { + return htmlspecialchars($text); + } }
\ No newline at end of file diff --git a/_darcs/pristine/lib/queuehandler.php b/_darcs/pristine/lib/queuehandler.php index 23f295c45..5e3905f59 100644 --- a/_darcs/pristine/lib/queuehandler.php +++ b/_darcs/pristine/lib/queuehandler.php @@ -27,106 +27,106 @@ require_once(INSTALLDIR.'/classes/Notice.php'); class QueueHandler extends Daemon { - var $_id = 'generic'; + var $_id = 'generic'; - function QueueHandler($id=NULL) { - if ($id) { - $this->set_id($id); - } - } - - function class_name() { - return ucfirst($this->transport()) . 'Handler'; - } + function QueueHandler($id=NULL) { + if ($id) { + $this->set_id($id); + } + } + + function class_name() { + return ucfirst($this->transport()) . 'Handler'; + } - function name() { - return strtolower($this->class_name().'.'.$this->get_id()); - } - - function get_id() { - return $this->_id; - } + function name() { + return strtolower($this->class_name().'.'.$this->get_id()); + } + + function get_id() { + return $this->_id; + } - function set_id($id) { - $this->_id = $id; - } - - function transport() { - return NULL; - } - - function start() { - } - - function finish() { - } + function set_id($id) { + $this->_id = $id; + } + + function transport() { + return NULL; + } + + function start() { + } + + function finish() { + } - function handle_notice($notice) { - return true; - } - - function run() { - if (!$this->start()) { - return false; - } - $this->log(LOG_INFO, 'checking for queued notices'); - $transport = $this->transport(); - do { - $qi = Queue_item::top($transport); - if ($qi) { - $this->log(LOG_INFO, 'Got item enqueued '.common_exact_date($qi->created)); - $notice = Notice::staticGet($qi->notice_id); - if ($notice) { - $this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id); - # XXX: what to do if broadcast fails? - $result = $this->handle_notice($notice); - if (!$result) { - $this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id); - $orig = $qi; - $qi->claimed = NULL; - $qi->update($orig); - $this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id); - continue; - } - $this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id); - $notice->free(); - unset($notice); - $notice = NULL; - } else { - $this->log(LOG_WARNING, 'queue item for notice that does not exist'); - } - $qi->delete(); - $qi->free(); - unset($qi); - $this->idle(0); - } else { - $this->clear_old_claims(); - $this->idle(5); - } - } while (true); - if (!$this->finish()) { - return false; - } - return true; - } + function handle_notice($notice) { + return true; + } + + function run() { + if (!$this->start()) { + return false; + } + $this->log(LOG_INFO, 'checking for queued notices'); + $transport = $this->transport(); + do { + $qi = Queue_item::top($transport); + if ($qi) { + $this->log(LOG_INFO, 'Got item enqueued '.common_exact_date($qi->created)); + $notice = Notice::staticGet($qi->notice_id); + if ($notice) { + $this->log(LOG_INFO, 'broadcasting notice ID = ' . $notice->id); + # XXX: what to do if broadcast fails? + $result = $this->handle_notice($notice); + if (!$result) { + $this->log(LOG_WARNING, 'Failed broadcast for notice ID = ' . $notice->id); + $orig = $qi; + $qi->claimed = NULL; + $qi->update($orig); + $this->log(LOG_WARNING, 'Abandoned claim for notice ID = ' . $notice->id); + continue; + } + $this->log(LOG_INFO, 'finished broadcasting notice ID = ' . $notice->id); + $notice->free(); + unset($notice); + $notice = NULL; + } else { + $this->log(LOG_WARNING, 'queue item for notice that does not exist'); + } + $qi->delete(); + $qi->free(); + unset($qi); + $this->idle(0); + } else { + $this->clear_old_claims(); + $this->idle(5); + } + } while (true); + if (!$this->finish()) { + return false; + } + return true; + } - function idle($timeout=0) { - if ($timeout>0) { - sleep($timeout); - } - } - - function clear_old_claims() { - $qi = new Queue_item(); - $qi->transport = $this->transport(); - $qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT); - $qi->update(DB_DATAOBJECT_WHEREADD_ONLY); - $qi->free(); - unset($qi); - } - - function log($level, $msg) { - common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg); - } + function idle($timeout=0) { + if ($timeout>0) { + sleep($timeout); + } + } + + function clear_old_claims() { + $qi = new Queue_item(); + $qi->transport = $this->transport(); + $qi->whereAdd('now() - claimed > '.CLAIM_TIMEOUT); + $qi->update(DB_DATAOBJECT_WHEREADD_ONLY); + $qi->free(); + unset($qi); + } + + function log($level, $msg) { + common_log($level, $this->class_name() . ' ('. $this->get_id() .'): '.$msg); + } } -
\ No newline at end of file +
\ No newline at end of file diff --git a/_darcs/pristine/lib/rssaction.php b/_darcs/pristine/lib/rssaction.php index 777511506..b64796888 100644 --- a/_darcs/pristine/lib/rssaction.php +++ b/_darcs/pristine/lib/rssaction.php @@ -23,167 +23,167 @@ define('DEFAULT_RSS_LIMIT', 48); class Rss10Action extends Action { - # This will contain the details of each feed item's author and be used to generate SIOC data. - var $creators = array(); - - function is_readonly() { - return true; - } - - function handle($args) { - parent::handle($args); - $limit = (int) $this->trimmed('limit'); - if ($limit == 0) { - $limit = DEFAULT_RSS_LIMIT; - } - $this->show_rss($limit); - } - - function init() { - return true; - } - - function get_notices() { - return array(); - } - - function get_channel() { - return array('url' => '', - 'title' => '', - 'link' => '', - 'description' => ''); - } - - function get_image() { - return NULL; - } - - function show_rss($limit=0) { - - if (!$this->init()) { - return; - } - - $notices = $this->get_notices($limit); - - $this->init_rss(); - $this->show_channel($notices); - $this->show_image(); - - foreach ($notices as $n) { - $this->show_item($n); - } - - $this->show_creators(); - $this->end_rss(); - } - - function show_channel($notices) { - - $channel = $this->get_channel(); - $image = $this->get_image(); - - common_element_start('channel', array('rdf:about' => $channel['url'])); - common_element('title', NULL, $channel['title']); - common_element('link', NULL, $channel['link']); - common_element('description', NULL, $channel['description']); - common_element('cc:licence', array('rdf:resource' => common_config('license','url'))); - - if ($image) { - common_element('image', array('rdf:resource' => $image)); - } - - common_element_start('items'); - common_element_start('rdf:Seq'); - - foreach ($notices as $notice) { - common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri)); - } - - common_element_end('rdf:Seq'); - common_element_end('items'); - - common_element_end('channel'); - } - - function show_image() { - $image = $this->get_image(); - if ($image) { - $channel = $this->get_channel(); - common_element_start('image', array('rdf:about' => $image)); - common_element('title', NULL, $channel['title']); - common_element('link', NULL, $channel['link']); - common_element('url', NULL, $image); - common_element_end('image'); - } - } - - function show_item($notice) { - $profile = Profile::staticGet($notice->profile_id); - $nurl = common_local_url('shownotice', array('notice' => $notice->id)); - $creator_uri = common_profile_uri($profile); - common_element_start('item', array('rdf:about' => $notice->uri)); - $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); - common_element('title', NULL, $title); - common_element('link', NULL, $nurl); - common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created)); - common_element('dc:date', NULL, common_date_w3dtf($notice->created)); - common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname); - common_element('sioc:has_creator', array('rdf:resource' => $creator_uri)); - common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile))); - common_element('cc:licence', array('rdf:resource' => common_config('license', 'url'))); - common_element_end('item'); - $this->creators[$creator_uri] = $profile; - } - - function show_creators() { - foreach ($this->creators as $uri => $profile) { - $id = $profile->id; - $nickname = $profile->nickname; - common_element_start('sioc:User', array('rdf:about' => $uri)); - common_element('foaf:nick', NULL, $nickname); - if ($profile->fullname) { - common_element('foaf:name', NULL, $profile->fullname); - } - common_element('sioc:id', NULL, $id); - $avatar = common_profile_avatar_url($profile); - common_element('sioc:avatar', array('rdf:resource' => $avatar)); - common_element_end('sioc:User'); - } - } - - function init_rss() { - $channel = $this->get_channel(); - header('Content-Type: application/rdf+xml'); - - common_start_xml(); - common_element_start('rdf:RDF', array('xmlns:rdf' => - 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', - 'xmlns:dc' => - 'http://purl.org/dc/elements/1.1/', - 'xmlns:cc' => - 'http://web.resource.org/cc/', + # This will contain the details of each feed item's author and be used to generate SIOC data. + var $creators = array(); + + function is_readonly() { + return true; + } + + function handle($args) { + parent::handle($args); + $limit = (int) $this->trimmed('limit'); + if ($limit == 0) { + $limit = DEFAULT_RSS_LIMIT; + } + $this->show_rss($limit); + } + + function init() { + return true; + } + + function get_notices() { + return array(); + } + + function get_channel() { + return array('url' => '', + 'title' => '', + 'link' => '', + 'description' => ''); + } + + function get_image() { + return NULL; + } + + function show_rss($limit=0) { + + if (!$this->init()) { + return; + } + + $notices = $this->get_notices($limit); + + $this->init_rss(); + $this->show_channel($notices); + $this->show_image(); + + foreach ($notices as $n) { + $this->show_item($n); + } + + $this->show_creators(); + $this->end_rss(); + } + + function show_channel($notices) { + + $channel = $this->get_channel(); + $image = $this->get_image(); + + common_element_start('channel', array('rdf:about' => $channel['url'])); + common_element('title', NULL, $channel['title']); + common_element('link', NULL, $channel['link']); + common_element('description', NULL, $channel['description']); + common_element('cc:licence', array('rdf:resource' => common_config('license','url'))); + + if ($image) { + common_element('image', array('rdf:resource' => $image)); + } + + common_element_start('items'); + common_element_start('rdf:Seq'); + + foreach ($notices as $notice) { + common_element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri)); + } + + common_element_end('rdf:Seq'); + common_element_end('items'); + + common_element_end('channel'); + } + + function show_image() { + $image = $this->get_image(); + if ($image) { + $channel = $this->get_channel(); + common_element_start('image', array('rdf:about' => $image)); + common_element('title', NULL, $channel['title']); + common_element('link', NULL, $channel['link']); + common_element('url', NULL, $image); + common_element_end('image'); + } + } + + function show_item($notice) { + $profile = Profile::staticGet($notice->profile_id); + $nurl = common_local_url('shownotice', array('notice' => $notice->id)); + $creator_uri = common_profile_uri($profile); + common_element_start('item', array('rdf:about' => $notice->uri)); + $title = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); + common_element('title', NULL, $title); + common_element('link', NULL, $nurl); + common_element('description', NULL, $profile->nickname."'s status on ".common_exact_date($notice->created)); + common_element('dc:date', NULL, common_date_w3dtf($notice->created)); + common_element('dc:creator', NULL, ($profile->fullname) ? $profile->fullname : $profile->nickname); + common_element('sioc:has_creator', array('rdf:resource' => $creator_uri)); + common_element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile))); + common_element('cc:licence', array('rdf:resource' => common_config('license', 'url'))); + common_element_end('item'); + $this->creators[$creator_uri] = $profile; + } + + function show_creators() { + foreach ($this->creators as $uri => $profile) { + $id = $profile->id; + $nickname = $profile->nickname; + common_element_start('sioc:User', array('rdf:about' => $uri)); + common_element('foaf:nick', NULL, $nickname); + if ($profile->fullname) { + common_element('foaf:name', NULL, $profile->fullname); + } + common_element('sioc:id', NULL, $id); + $avatar = common_profile_avatar_url($profile); + common_element('sioc:avatar', array('rdf:resource' => $avatar)); + common_element_end('sioc:User'); + } + } + + function init_rss() { + $channel = $this->get_channel(); + header('Content-Type: application/rdf+xml'); + + common_start_xml(); + common_element_start('rdf:RDF', array('xmlns:rdf' => + 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + 'xmlns:dc' => + 'http://purl.org/dc/elements/1.1/', + 'xmlns:cc' => + 'http://web.resource.org/cc/', 'xmlns:content' => 'http://purl.org/rss/1.0/modules/content/', - 'xmlns:foaf' => - 'http://xmlns.com/foaf/0.1/', - 'xmlns:sioc' => - 'http://rdfs.org/sioc/ns#', - 'xmlns:sioct' => - 'http://rdfs.org/sioc/types#', - 'xmlns:laconica' => - 'http://laconi.ca/ont/', - 'xmlns' => 'http://purl.org/rss/1.0/')); - common_element_start('sioc:Site', array('rdf:about' => common_root_url())); - common_element('sioc:name', NULL, common_config('site', 'name')); - common_element_start('sioc:container_of'); - common_element('sioc:Container', array('rdf:about' => - $channel['url'])); - common_element_end('sioc:container_of'); - common_element_end('sioc:Site'); - } - - function end_rss() { - common_element_end('rdf:RDF'); - } + 'xmlns:foaf' => + 'http://xmlns.com/foaf/0.1/', + 'xmlns:sioc' => + 'http://rdfs.org/sioc/ns#', + 'xmlns:sioct' => + 'http://rdfs.org/sioc/types#', + 'xmlns:laconica' => + 'http://laconi.ca/ont/', + 'xmlns' => 'http://purl.org/rss/1.0/')); + common_element_start('sioc:Site', array('rdf:about' => common_root_url())); + common_element('sioc:name', NULL, common_config('site', 'name')); + common_element_start('sioc:container_of'); + common_element('sioc:Container', array('rdf:about' => + $channel['url'])); + common_element_end('sioc:container_of'); + common_element_end('sioc:Site'); + } + + function end_rss() { + common_element_end('rdf:RDF'); + } } diff --git a/_darcs/pristine/lib/search_engines.php b/_darcs/pristine/lib/search_engines.php index 7fcc1ffcb..d53d7d8d8 100644 --- a/_darcs/pristine/lib/search_engines.php +++ b/_darcs/pristine/lib/search_engines.php @@ -98,10 +98,10 @@ class MySQLSearch extends SearchEngine { function query($q) { if ('identica_people' === $this->table) return $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . - 'against (\''.addslashes($q).'\')'); + 'against (\''.addslashes($q).'\')'); if ('identica_notices' === $this->table) return $this->target->whereAdd('MATCH(content) ' . - 'against (\''.addslashes($q).'\')'); + 'against (\''.addslashes($q).'\')'); } } diff --git a/_darcs/pristine/lib/searchaction.php b/_darcs/pristine/lib/searchaction.php index f99883b25..8634bd99c 100644 --- a/_darcs/pristine/lib/searchaction.php +++ b/_darcs/pristine/lib/searchaction.php @@ -21,90 +21,90 @@ if (!defined('LACONICA')) { exit(1); } class SearchAction extends Action { - function is_readonly() { - return true; - } + function is_readonly() { + return true; + } - function handle($args) { - parent::handle($args); - $this->show_form(); - } + function handle($args) { + parent::handle($args); + $this->show_form(); + } - function show_top($arr=NULL) { - if ($arr) { - $error = $arr[1]; - } - if ($error) { - common_element('p', 'error', $error); - } else { - $instr = $this->get_instructions(); - $output = common_markup_to_html($instr); - common_element_start('div', 'instructions'); - common_raw($output); - common_element_end('div'); - } - $this->search_menu(); - } + function show_top($arr=NULL) { + if ($arr) { + $error = $arr[1]; + } + if ($error) { + common_element('p', 'error', $error); + } else { + $instr = $this->get_instructions(); + $output = common_markup_to_html($instr); + common_element_start('div', 'instructions'); + common_raw($output); + common_element_end('div'); + } + $this->search_menu(); + } - function get_title() { - return NULL; - } + function get_title() { + return NULL; + } - function show_header($arr) { - return; - } + function show_header($arr) { + return; + } - function show_form($error=NULL) { - global $config; + function show_form($error=NULL) { + global $config; - $q = $this->trimmed('q'); - $page = $this->trimmed('page', 1); + $q = $this->trimmed('q'); + $page = $this->trimmed('page', 1); - common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error), - array($this, 'show_top')); - common_element_start('form', array('method' => 'get', - 'id' => 'login', - 'action' => common_local_url($this->trimmed('action')))); - common_element_start('p'); - if (!isset($config['site']['fancy']) || !$config['site']['fancy']) { - common_element('input', array('name' => 'action', - 'type' => 'hidden', - 'value' => $this->trimmed('action'))); - } - common_element('input', array('name' => 'q', - 'id' => 'q', - 'type' => 'text', - 'class' => 'input_text', - 'value' => ($q) ? $q : '')); - common_text(' '); - common_element('input', array('type' => 'submit', - 'id' => 'search', - 'name' => 'search', - 'class' => 'submit', - 'value' => _('Search'))); + common_show_header($this->get_title(), array($this, 'show_header'), array($q, $error), + array($this, 'show_top')); + common_element_start('form', array('method' => 'get', + 'id' => 'login', + 'action' => common_local_url($this->trimmed('action')))); + common_element_start('p'); + if (!isset($config['site']['fancy']) || !$config['site']['fancy']) { + common_element('input', array('name' => 'action', + 'type' => 'hidden', + 'value' => $this->trimmed('action'))); + } + common_element('input', array('name' => 'q', + 'id' => 'q', + 'type' => 'text', + 'class' => 'input_text', + 'value' => ($q) ? $q : '')); + common_text(' '); + common_element('input', array('type' => 'submit', + 'id' => 'search', + 'name' => 'search', + 'class' => 'submit', + 'value' => _('Search'))); - common_element_end('p'); - common_element_end('form'); - if ($q) { - $this->show_results($q, $page); - } - common_show_footer(); - } + common_element_end('p'); + common_element_end('form'); + if ($q) { + $this->show_results($q, $page); + } + common_show_footer(); + } - function search_menu() { - # action => array('prompt', 'title', $args) - $action = $this->trimmed('action'); - $menu = - array('peoplesearch' => - array( - _('People'), - _('Find people on this site'), - ($action != 'peoplesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL), - 'noticesearch' => - array( _('Text'), - _('Find content of notices'), - ($action != 'noticesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL) - ); - $this->nav_menu($menu); - } + function search_menu() { + # action => array('prompt', 'title', $args) + $action = $this->trimmed('action'); + $menu = + array('peoplesearch' => + array( + _('People'), + _('Find people on this site'), + ($action != 'peoplesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL), + 'noticesearch' => + array( _('Text'), + _('Find content of notices'), + ($action != 'noticesearch' && $this->trimmed('q')) ? array('q' => $this->trimmed('q')) : NULL) + ); + $this->nav_menu($menu); + } } diff --git a/_darcs/pristine/lib/settingsaction.php b/_darcs/pristine/lib/settingsaction.php index 9e783431f..3021eb192 100644 --- a/_darcs/pristine/lib/settingsaction.php +++ b/_darcs/pristine/lib/settingsaction.php @@ -27,9 +27,9 @@ class SettingsAction extends Action { common_user_error(_('Not logged in.')); return; } else if (!common_is_real_login()) { - # Cookie theft means that automatic logins can't - # change important settings or see private info, and - # _all_ our settings are important + # Cookie theft means that automatic logins can't + # change important settings or see private info, and + # _all_ our settings are important common_set_returnto($this->self_url()); common_redirect(common_local_url('login')); } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { @@ -55,60 +55,60 @@ class SettingsAction extends Action { } } - function form_header($title, $msg=NULL, $success=false) { - common_show_header($title, - NULL, - array($msg, $success), - array($this, 'show_top')); - } + function form_header($title, $msg=NULL, $success=false) { + common_show_header($title, + NULL, + array($msg, $success), + array($this, 'show_top')); + } - function show_top($arr) { - $msg = $arr[0]; - $success = $arr[1]; - if ($msg) { - $this->message($msg, $success); - } else { - $inst = $this->get_instructions(); - $output = common_markup_to_html($inst); - common_element_start('div', 'instructions'); - common_raw($output); - common_element_end('div'); - } - $this->settings_menu(); - } + function show_top($arr) { + $msg = $arr[0]; + $success = $arr[1]; + if ($msg) { + $this->message($msg, $success); + } else { + $inst = $this->get_instructions(); + $output = common_markup_to_html($inst); + common_element_start('div', 'instructions'); + common_raw($output); + common_element_end('div'); + } + $this->settings_menu(); + } function settings_menu() { # action => array('prompt', 'title') - $menu = - array('profilesettings' => - array(_('Profile'), - _('Change your profile settings')), - 'emailsettings' => - array(_('Email'), - _('Change email handling')), - 'openidsettings' => - array(_('OpenID'), - _('Add or remove OpenIDs')), - 'smssettings' => - array(_('SMS'), - _('Updates by SMS')), - 'imsettings' => - array(_('IM'), - _('Updates by instant messenger (IM)')), - 'twittersettings' => - array(_('Twitter'), - _('Twitter integration options')), - 'othersettings' => - array(_('Other'), - _('Other options'))); - + $menu = + array('profilesettings' => + array(_('Profile'), + _('Change your profile settings')), + 'emailsettings' => + array(_('Email'), + _('Change email handling')), + 'openidsettings' => + array(_('OpenID'), + _('Add or remove OpenIDs')), + 'smssettings' => + array(_('SMS'), + _('Updates by SMS')), + 'imsettings' => + array(_('IM'), + _('Updates by instant messenger (IM)')), + 'twittersettings' => + array(_('Twitter'), + _('Twitter integration options')), + 'othersettings' => + array(_('Other'), + _('Other options'))); + $action = $this->trimmed('action'); common_element_start('ul', array('id' => 'nav_views')); foreach ($menu as $menuaction => $menudesc) { - if ($menuaction == 'imsettings' && - !common_config('xmpp', 'enabled')) { - continue; - } + if ($menuaction == 'imsettings' && + !common_config('xmpp', 'enabled')) { + continue; + } common_menu_item(common_local_url($menuaction), $menudesc[0], $menudesc[1], diff --git a/_darcs/pristine/lib/stream.php b/_darcs/pristine/lib/stream.php index 27ab78137..2d45df2d3 100644 --- a/_darcs/pristine/lib/stream.php +++ b/_darcs/pristine/lib/stream.php @@ -10,11 +10,11 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ if (!defined('LACONICA')) { exit(1); } @@ -24,29 +24,29 @@ require_once(INSTALLDIR.'/lib/noticelist.php'); class StreamAction extends PersonalAction { - function public_views_menu() { + function public_views_menu() { - $action = $this->trimmed('action'); + $action = $this->trimmed('action'); - common_element_start('ul', array('id' => 'nav_views')); + common_element_start('ul', array('id' => 'nav_views')); - common_menu_item(common_local_url('public'), _('Public'), - _('Public timeline'), $action == 'public'); + common_menu_item(common_local_url('public'), _('Public'), + _('Public timeline'), $action == 'public'); - common_menu_item(common_local_url('tag'), _('Recent tags'), - _('Recent tags'), $action == 'tag'); + common_menu_item(common_local_url('tag'), _('Recent tags'), + _('Recent tags'), $action == 'tag'); - if (count(common_config('nickname', 'featured')) > 0) { - common_menu_item(common_local_url('featured'), _('Featured'), - _('Featured users'), $action == 'featured'); - } + if (count(common_config('nickname', 'featured')) > 0) { + common_menu_item(common_local_url('featured'), _('Featured'), + _('Featured users'), $action == 'featured'); + } - common_menu_item(common_local_url('favorited'), _('Popular'), - _("Popular notices"), $action == 'favorited'); + common_menu_item(common_local_url('favorited'), _('Popular'), + _("Popular notices"), $action == 'favorited'); - common_element_end('ul'); + common_element_end('ul'); - } + } function show_notice_list($notice) { $nl = new NoticeList($notice); diff --git a/_darcs/pristine/lib/subs.php b/_darcs/pristine/lib/subs.php index 91fc8445d..55e74e0b2 100644 --- a/_darcs/pristine/lib/subs.php +++ b/_darcs/pristine/lib/subs.php @@ -27,13 +27,13 @@ require_once('XMPPHP/XMPP.php'); function subs_subscribe_user($user, $other_nickname) { - $other = User::staticGet('nickname', $other_nickname); + $other = User::staticGet('nickname', $other_nickname); - if (!$other) { - return _('No such user.'); - } + if (!$other) { + return _('No such user.'); + } - return subs_subscribe_to($user, $other); + return subs_subscribe_to($user, $other); } /* Subscribe user $user to other user $other. @@ -43,54 +43,54 @@ function subs_subscribe_user($user, $other_nickname) { function subs_subscribe_to($user, $other) { - if ($user->isSubscribed($other)) { - return _('Already subscribed!.'); - } + if ($user->isSubscribed($other)) { + return _('Already subscribed!.'); + } if ($other->hasBlocked($user)) { - return _('User has blocked you.'); + return _('User has blocked you.'); } - if (!$user->subscribeTo($other)) { - return _('Could not subscribe.'); - return; - } + if (!$user->subscribeTo($other)) { + return _('Could not subscribe.'); + return; + } subs_notify($other, $user); - if (common_config('memcached', 'enabled')) { - $cache = new Memcache(); - if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); - } - } - - if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) { - if (!$other->subscribeTo($user)) { - return _('Could not subscribe other to you.'); - } - if (common_config('memcached', 'enabled')) { - $cache = new Memcache(); - if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $other->id)); - } - } - - subs_notify($user, $other); - } - - return true; + if (common_config('memcached', 'enabled')) { + $cache = new Memcache(); + if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); + } + } + + if ($other->autosubscribe && !$other->isSubscribed($user) && !$user->hasBlocked($other)) { + if (!$other->subscribeTo($user)) { + return _('Could not subscribe other to you.'); + } + if (common_config('memcached', 'enabled')) { + $cache = new Memcache(); + if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $other->id)); + } + } + + subs_notify($user, $other); + } + + return true; } function subs_notify($listenee, $listener) { - # XXX: add other notifications (Jabber, SMS) here - # XXX: queue this and handle it offline - # XXX: Whatever happens, do it in Twitter-like API, too - subs_notify_email($listenee, $listener); + # XXX: add other notifications (Jabber, SMS) here + # XXX: queue this and handle it offline + # XXX: Whatever happens, do it in Twitter-like API, too + subs_notify_email($listenee, $listener); } function subs_notify_email($listenee, $listener) { - mail_subscribe_notify($listenee, $listener); + mail_subscribe_notify($listenee, $listener); } /* Unsubscribe $user from nickname $other_nickname @@ -99,13 +99,13 @@ function subs_notify_email($listenee, $listener) { function subs_unsubscribe_user($user, $other_nickname) { - $other = User::staticGet('nickname', $other_nickname); + $other = User::staticGet('nickname', $other_nickname); - if (!$other) { - return _('No such user.'); - } + if (!$other) { + return _('No such user.'); + } - return subs_unsubscribe_to($user, $other->getProfile()); + return subs_unsubscribe_to($user, $other->getProfile()); } /* Unsubscribe user $user from profile $other @@ -113,28 +113,28 @@ function subs_unsubscribe_user($user, $other_nickname) { function subs_unsubscribe_to($user, $other) { - if (!$user->isSubscribed($other)) - return _('Not subscribed!.'); + if (!$user->isSubscribed($other)) + return _('Not subscribed!.'); - $sub = DB_DataObject::factory('subscription'); + $sub = DB_DataObject::factory('subscription'); - $sub->subscriber = $user->id; - $sub->subscribed = $other->id; + $sub->subscriber = $user->id; + $sub->subscribed = $other->id; - $sub->find(true); + $sub->find(true); - // note we checked for existence above + // note we checked for existence above - if (!$sub->delete()) - return _('Couldn\'t delete subscription.'); + if (!$sub->delete()) + return _('Couldn\'t delete subscription.'); - if (common_config('memcached', 'enabled')) { - $cache = new Memcache(); - if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); - } - } + if (common_config('memcached', 'enabled')) { + $cache = new Memcache(); + if ($cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'))) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); + } + } - return true; + return true; } diff --git a/_darcs/pristine/lib/theme.php b/_darcs/pristine/lib/theme.php index 80982aa82..346cff434 100644 --- a/_darcs/pristine/lib/theme.php +++ b/_darcs/pristine/lib/theme.php @@ -20,16 +20,16 @@ if (!defined('LACONICA')) { exit(1); } function theme_file($relative) { - $theme = common_config('site', 'theme'); - return INSTALLDIR.'/theme/'.$theme.'/'.$relative; + $theme = common_config('site', 'theme'); + return INSTALLDIR.'/theme/'.$theme.'/'.$relative; } function theme_path($relative) { - $theme = common_config('site', 'theme'); - $server = common_config('theme', 'server'); - if ($server) { - return 'http://'.$server.'/'.$theme.'/'.$relative; - } else { - return common_path('theme/'.$theme.'/'.$relative); - } + $theme = common_config('site', 'theme'); + $server = common_config('theme', 'server'); + if ($server) { + return 'http://'.$server.'/'.$theme.'/'.$relative; + } else { + return common_path('theme/'.$theme.'/'.$relative); + } }
\ No newline at end of file diff --git a/_darcs/pristine/lib/twitter.php b/_darcs/pristine/lib/twitter.php index 5c9ef5d6f..c1d2de0ea 100644 --- a/_darcs/pristine/lib/twitter.php +++ b/_darcs/pristine/lib/twitter.php @@ -21,179 +21,179 @@ if (!defined('LACONICA')) { exit(1); } function get_twitter_data($uri, $screen_name, $password) { - $options = array( - CURLOPT_USERPWD => sprintf("%s:%s", $screen_name, $password), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FAILONERROR => true, - CURLOPT_HEADER => false, - CURLOPT_FOLLOWLOCATION => true, - // CURLOPT_USERAGENT => "identi.ca", - CURLOPT_CONNECTTIMEOUT => 120, - CURLOPT_TIMEOUT => 120 - ); - - - $ch = curl_init($uri); + $options = array( + CURLOPT_USERPWD => sprintf("%s:%s", $screen_name, $password), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FAILONERROR => true, + CURLOPT_HEADER => false, + CURLOPT_FOLLOWLOCATION => true, + // CURLOPT_USERAGENT => "identi.ca", + CURLOPT_CONNECTTIMEOUT => 120, + CURLOPT_TIMEOUT => 120 + ); + + + $ch = curl_init($uri); curl_setopt_array($ch, $options); $data = curl_exec($ch); $errmsg = curl_error($ch); - if ($errmsg) { - common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $twit_user.", - __FILE__); - } + if ($errmsg) { + common_debug("Twitter bridge - cURL error: $errmsg - trying to load: $uri with user $twit_user.", + __FILE__); + } - curl_close($ch); + curl_close($ch); - return $data; + return $data; } function twitter_user_info($screen_name, $password) { - $uri = "http://twitter.com/users/show/$screen_name.json"; - $data = get_twitter_data($uri, $screen_name, $password); + $uri = "http://twitter.com/users/show/$screen_name.json"; + $data = get_twitter_data($uri, $screen_name, $password); - if (!$data) { - return false; - } + if (!$data) { + return false; + } - $twit_user = json_decode($data); + $twit_user = json_decode($data); - if (!$twit_user) { - return false; - } + if (!$twit_user) { + return false; + } - return $twit_user; + return $twit_user; } function update_twitter_user($fuser, $twitter_id, $screen_name) { - $original = clone($fuser); - $fuser->nickname = $screen_name; - $fuser->uri = 'http://twitter.com/' . $screen_name; - $result = $fuser->updateKeys($original); + $original = clone($fuser); + $fuser->nickname = $screen_name; + $fuser->uri = 'http://twitter.com/' . $screen_name; + $result = $fuser->updateKeys($original); - if (!$result) { - common_log_db_error($fuser, 'UPDATE', __FILE__); - return false; - } + if (!$result) { + common_log_db_error($fuser, 'UPDATE', __FILE__); + return false; + } - return true; + return true; } function add_twitter_user($twitter_id, $screen_name) { - // Otherwise, create a new Twitter user - $fuser = DB_DataObject::factory('foreign_user'); + // Otherwise, create a new Twitter user + $fuser = DB_DataObject::factory('foreign_user'); - $fuser->nickname = $screen_name; - $fuser->uri = 'http://twitter.com/' . $screen_name; - $fuser->id = $twitter_id; - $fuser->service = 1; // Twitter - $fuser->created = common_sql_now(); - $result = $fuser->insert(); + $fuser->nickname = $screen_name; + $fuser->uri = 'http://twitter.com/' . $screen_name; + $fuser->id = $twitter_id; + $fuser->service = 1; // Twitter + $fuser->created = common_sql_now(); + $result = $fuser->insert(); - if (!$result) { - common_debug("Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name."); - common_log_db_error($fuser, 'INSERT', __FILE__); - return false; - } + if (!$result) { + common_debug("Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name."); + common_log_db_error($fuser, 'INSERT', __FILE__); + return false; + } - common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id)."); + common_debug("Twitter bridge - Added new Twitter user: $screen_name ($twitter_id)."); - return true; + return true; } // Creates or Updates a Twitter user function save_twitter_user($twitter_id, $screen_name) { - // Check to see whether the Twitter user is already in the system, - // and update its screen name and uri if so. - $fuser = Foreign_user::getForeignUser($twitter_id, 1); + // Check to see whether the Twitter user is already in the system, + // and update its screen name and uri if so. + $fuser = Foreign_user::getForeignUser($twitter_id, 1); - if ($fuser) { + if ($fuser) { - // Only update if Twitter screen name has changed - if ($fuser->nickname != $screen_name) { + // Only update if Twitter screen name has changed + if ($fuser->nickname != $screen_name) { - common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' . - "$fuser->id to $screen_name, was $fuser->nickname"); + common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' . + "$fuser->id to $screen_name, was $fuser->nickname"); - return update_twitter_user($fuser, $twitter_id, $screen_name); - } + return update_twitter_user($fuser, $twitter_id, $screen_name); + } - } else { - return add_twitter_user($twitter_id, $screen_name); - } + } else { + return add_twitter_user($twitter_id, $screen_name); + } - return true; + return true; } function retreive_twitter_friends($twitter_id, $screen_name, $password) { - $uri = "http://twitter.com/statuses/friends/$twitter_id.json?page="; - $twitter_user = twitter_user_info($screen_name, $password); + $uri = "http://twitter.com/statuses/friends/$twitter_id.json?page="; + $twitter_user = twitter_user_info($screen_name, $password); - // Calculate how many pages to get... - $pages = ceil($twitter_user->friends_count / 100); + // Calculate how many pages to get... + $pages = ceil($twitter_user->friends_count / 100); - if ($pages == 0) { - common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame."); - } + if ($pages == 0) { + common_debug("Twitter bridge - Twitter user $screen_name has no friends! Lame."); + } - $friends = array(); + $friends = array(); - for ($i = 1; $i <= $pages; $i++) { + for ($i = 1; $i <= $pages; $i++) { - $data = get_twitter_data($uri . $i, $screen_name, $password); + $data = get_twitter_data($uri . $i, $screen_name, $password); - if (!$data) { - return NULL; - } + if (!$data) { + return NULL; + } - $more_friends = json_decode($data); + $more_friends = json_decode($data); - if (!$more_friends) { - return NULL; - } + if (!$more_friends) { + return NULL; + } - $friends = array_merge($friends, $more_friends); - } + $friends = array_merge($friends, $more_friends); + } - return $friends; + return $friends; } function save_twitter_friends($user, $twitter_id, $screen_name, $password) { - $friends = retreive_twitter_friends($twitter_id, $screen_name, $password); + $friends = retreive_twitter_friends($twitter_id, $screen_name, $password); - if (is_null($friends)) { - common_debug("Twitter bridge - Couldn't get friends data from Twitter."); - return false; - } + if (is_null($friends)) { + common_debug("Twitter bridge - Couldn't get friends data from Twitter."); + return false; + } foreach ($friends as $friend) { - $friend_name = $friend->screen_name; - $friend_id = $friend->id; + $friend_name = $friend->screen_name; + $friend_id = $friend->id; - // Update or create the Foreign_user record - if (!save_twitter_user($friend_id, $friend_name)) { - return false; - } + // Update or create the Foreign_user record + if (!save_twitter_user($friend_id, $friend_name)) { + return false; + } - // Check to see if there's a related local user - $flink = Foreign_link::getByForeignID($friend_id, 1); + // Check to see if there's a related local user + $flink = Foreign_link::getByForeignID($friend_id, 1); - if ($flink) { + if ($flink) { - // Get associated user and subscribe her - $friend_user = User::staticGet('id', $flink->user_id); - subs_subscribe_to($user, $friend_user); - common_debug("Twitter bridge - subscribed $friend_user->nickname to $user->nickname."); - } - } + // Get associated user and subscribe her + $friend_user = User::staticGet('id', $flink->user_id); + subs_subscribe_to($user, $friend_user); + common_debug("Twitter bridge - subscribed $friend_user->nickname to $user->nickname."); + } + } - return true; + return true; } diff --git a/_darcs/pristine/lib/twitterapi.php b/_darcs/pristine/lib/twitterapi.php index 2eb127525..3122caf12 100644 --- a/_darcs/pristine/lib/twitterapi.php +++ b/_darcs/pristine/lib/twitterapi.php @@ -21,637 +21,637 @@ if (!defined('LACONICA')) { exit(1); } class TwitterapiAction extends Action { - var $auth_user; + var $auth_user; - function handle($args) { - parent::handle($args); - } + function handle($args) { + parent::handle($args); + } - function twitter_user_array($profile, $get_notice=false) { + function twitter_user_array($profile, $get_notice=false) { - $twitter_user = array(); + $twitter_user = array(); - $twitter_user['name'] = $profile->getBestName(); - $twitter_user['followers_count'] = $this->count_subscriptions($profile); - $twitter_user['screen_name'] = $profile->nickname; - $twitter_user['description'] = ($profile->bio) ? $profile->bio : NULL; - $twitter_user['location'] = ($profile->location) ? $profile->location : NULL; - $twitter_user['id'] = intval($profile->id); + $twitter_user['name'] = $profile->getBestName(); + $twitter_user['followers_count'] = $this->count_subscriptions($profile); + $twitter_user['screen_name'] = $profile->nickname; + $twitter_user['description'] = ($profile->bio) ? $profile->bio : NULL; + $twitter_user['location'] = ($profile->location) ? $profile->location : NULL; + $twitter_user['id'] = intval($profile->id); - $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); + $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE); - $twitter_user['profile_image_url'] = ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE); - $twitter_user['protected'] = 'false'; # not supported by Laconica yet - $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : NULL; + $twitter_user['profile_image_url'] = ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE); + $twitter_user['protected'] = 'false'; # not supported by Laconica yet + $twitter_user['url'] = ($profile->homepage) ? $profile->homepage : NULL; - if ($get_notice) { - $notice = $profile->getCurrentNotice(); - if ($notice) { - # don't get user! - $twitter_user['status'] = $this->twitter_status_array($notice, false); - } - } + if ($get_notice) { + $notice = $profile->getCurrentNotice(); + if ($notice) { + # don't get user! + $twitter_user['status'] = $this->twitter_status_array($notice, false); + } + } - return $twitter_user; - } + return $twitter_user; + } - function twitter_status_array($notice, $include_user=true) { + function twitter_status_array($notice, $include_user=true) { - $profile = $notice->getProfile(); + $profile = $notice->getProfile(); - $twitter_status = array(); - $twitter_status['text'] = $notice->content; - $twitter_status['truncated'] = 'false'; # Not possible on Laconica - $twitter_status['created_at'] = $this->date_twitter($notice->created); - $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL; - $twitter_status['source'] = $this->source_link($notice->source); - $twitter_status['id'] = intval($notice->id); - $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL; + $twitter_status = array(); + $twitter_status['text'] = $notice->content; + $twitter_status['truncated'] = 'false'; # Not possible on Laconica + $twitter_status['created_at'] = $this->date_twitter($notice->created); + $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL; + $twitter_status['source'] = $this->source_link($notice->source); + $twitter_status['id'] = intval($notice->id); + $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL; - if (isset($this->auth_user)) { - $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false'; - } else { - $twitter_status['favorited'] = 'false'; - } + if (isset($this->auth_user)) { + $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false'; + } else { + $twitter_status['favorited'] = 'false'; + } - if ($include_user) { - # Don't get notice (recursive!) - $twitter_user = $this->twitter_user_array($profile, false); - $twitter_status['user'] = $twitter_user; - } + if ($include_user) { + # Don't get notice (recursive!) + $twitter_user = $this->twitter_user_array($profile, false); + $twitter_status['user'] = $twitter_user; + } - return $twitter_status; - } + return $twitter_status; + } - function twitter_rss_entry_array($notice) { + function twitter_rss_entry_array($notice) { - $profile = $notice->getProfile(); + $profile = $notice->getProfile(); - $server = common_config('site', 'server'); - $entry = array(); + $server = common_config('site', 'server'); + $entry = array(); # We trim() to avoid extraneous whitespace in the output - $entry['content'] = common_xml_safe_str(trim($notice->rendered)); - $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); - $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id)); - $entry['published'] = common_date_iso8601($notice->created); - $entry['id'] = "tag:$server,2008:$entry[link]"; - $entry['updated'] = $entry['published']; - - # RSS Item specific - $entry['description'] = $entry['content']; - $entry['pubDate'] = common_date_rfc2822($notice->created); - $entry['guid'] = $entry['link']; - - return $entry; - } - - function twitter_rss_dmsg_array($message) { - - $server = common_config('site', 'server'); - $entry = array(); - - $entry['title'] = sprintf('Message from %s to %s', - $message->getFrom()->nickname, $message->getTo()->nickname); - - $entry['content'] = common_xml_safe_str(trim($message->content)); - $entry['link'] = common_local_url('showmessage', array('message' => $message->id)); - $entry['published'] = common_date_iso8601($message->created); - $entry['id'] = "tag:$server,2008:$entry[link]"; - $entry['updated'] = $entry['published']; - - # RSS Item specific - $entry['description'] = $entry['content']; - $entry['pubDate'] = common_date_rfc2822($message->created); - $entry['guid'] = $entry['link']; - - return $entry; - } - - function twitter_dmsg_array($message) { - - $twitter_dm = array(); - - $from_profile = $message->getFrom(); - $to_profile = $message->getTo(); - - $twitter_dm['id'] = $message->id; - $twitter_dm['sender_id'] = $message->from_profile; - $twitter_dm['text'] = trim($message->content); - $twitter_dm['recipient_id'] = $message->to_profile; - $twitter_dm['created_at'] = $this->date_twitter($message->created); - $twitter_dm['sender_screen_name'] = $from_profile->nickname; - $twitter_dm['recipient_screen_name'] = $to_profile->nickname; - $twitter_dm['sender'] = $this->twitter_user_array($from_profile, false); - $twitter_dm['recipient'] = $this->twitter_user_array($to_profile, false); - - return $twitter_dm; - } - - function show_twitter_xml_status($twitter_status) { - common_element_start('status'); - foreach($twitter_status as $element => $value) { - switch ($element) { - case 'user': - $this->show_twitter_xml_user($twitter_status['user']); - break; - case 'text': - common_element($element, NULL, common_xml_safe_str($value)); - break; - default: - common_element($element, NULL, $value); - } - } - common_element_end('status'); - } - - function show_twitter_xml_user($twitter_user, $role='user') { - common_element_start($role); - foreach($twitter_user as $element => $value) { - if ($element == 'status') { - $this->show_twitter_xml_status($twitter_user['status']); - } else { - common_element($element, NULL, $value); - } - } - common_element_end($role); - } - - function show_twitter_rss_item($entry) { - common_element_start('item'); - common_element('title', NULL, $entry['title']); - common_element('description', NULL, $entry['description']); - common_element('pubDate', NULL, $entry['pubDate']); - common_element('guid', NULL, $entry['guid']); - common_element('link', NULL, $entry['link']); - common_element_end('item'); - } - - function show_twitter_atom_entry($entry) { - common_element_start('entry'); - common_element('title', NULL, $entry['title']); - common_element('content', array('type' => 'html'), $entry['content']); - common_element('id', NULL, $entry['id']); - common_element('published', NULL, $entry['published']); - common_element('updated', NULL, $entry['updated']); - common_element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), NULL); - common_element_end('entry'); - } - - function show_json_objects($objects) { - print(json_encode($objects)); - } - - function show_single_xml_status($notice) { - $this->init_document('xml'); - $twitter_status = $this->twitter_status_array($notice); - $this->show_twitter_xml_status($twitter_status); - $this->end_document('xml'); - } - - function show_single_json_status($notice) { - $this->init_document('json'); - $status = $this->twitter_status_array($notice); - $this->show_json_objects($status); - $this->end_document('json'); - } - - function show_single_xml_dmsg($message) { - $this->init_document('xml'); - $dmsg = $this->twitter_dmsg_array($message); - $this->show_twitter_xml_dmsg($dmsg); - $this->end_document('xml'); - } - - function show_single_json_dmsg($message) { - $this->init_document('json'); - $dmsg = $this->twitter_dmsg_array($message); - $this->show_json_objects($dmsg); - $this->end_document('json'); - } - - function show_twitter_xml_dmsg($twitter_dm) { - common_element_start('direct_message'); - foreach($twitter_dm as $element => $value) { - switch ($element) { - case 'sender': - case 'recipient': - $this->show_twitter_xml_user($value, $element); - break; - case 'text': - common_element($element, NULL, common_xml_safe_str($value)); - break; - default: - common_element($element, NULL, $value); - } - } - common_element_end('direct_message'); - } - - function show_xml_timeline($notice) { - - $this->init_document('xml'); - common_element_start('statuses', array('type' => 'array')); - - if (is_array($notice)) { - foreach ($notice as $n) { - $twitter_status = $this->twitter_status_array($n); - $this->show_twitter_xml_status($twitter_status); - } - } else { - while ($notice->fetch()) { - $twitter_status = $this->twitter_status_array($notice); - $this->show_twitter_xml_status($twitter_status); - } - } - - common_element_end('statuses'); - $this->end_document('xml'); - } - - function show_rss_timeline($notice, $title, $link, $subtitle, $suplink=NULL) { - - $this->init_document('rss'); - - common_element_start('channel'); - common_element('title', NULL, $title); - common_element('link', NULL, $link); - if (!is_null($suplink)) { - # For FriendFeed's SUP protocol - common_element('link', array('xmlns' => 'http://www.w3.org/2005/Atom', - 'rel' => 'http://api.friendfeed.com/2008/03#sup', - 'href' => $suplink, - 'type' => 'application/json')); - } - common_element('description', NULL, $subtitle); - common_element('language', NULL, 'en-us'); - common_element('ttl', NULL, '40'); - - if (is_array($notice)) { - foreach ($notice as $n) { - $entry = $this->twitter_rss_entry_array($n); - $this->show_twitter_rss_item($entry); - } - } else { - while ($notice->fetch()) { - $entry = $this->twitter_rss_entry_array($notice); - $this->show_twitter_rss_item($entry); - } - } - - common_element_end('channel'); - $this->end_twitter_rss(); - } - - function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL, $suplink=NULL) { - - $this->init_document('atom'); - - common_element('title', NULL, $title); - common_element('id', NULL, $id); - common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL); - if (!is_null($suplink)) { - # For FriendFeed's SUP protocol - common_element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', - 'href' => $suplink, - 'type' => 'application/json')); - } - common_element('subtitle', NULL, $subtitle); - - if (is_array($notice)) { - foreach ($notice as $n) { - $entry = $this->twitter_rss_entry_array($n); - $this->show_twitter_atom_entry($entry); - } - } else { - while ($notice->fetch()) { - $entry = $this->twitter_rss_entry_array($notice); - $this->show_twitter_atom_entry($entry); - } - } - - $this->end_document('atom'); - - } - - function show_json_timeline($notice) { - - $this->init_document('json'); - - $statuses = array(); - - if (is_array($notice)) { - foreach ($notice as $n) { - $twitter_status = $this->twitter_status_array($n); - array_push($statuses, $twitter_status); - } - } else { - while ($notice->fetch()) { - $twitter_status = $this->twitter_status_array($notice); - array_push($statuses, $twitter_status); - } - } - - $this->show_json_objects($statuses); - - $this->end_document('json'); - } - - // Anyone know what date format this is? - // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach - function date_twitter($dt) { - $t = strtotime($dt); - return date("D M d G:i:s O Y", $t); - } - - function replier_by_reply($reply_id) { - $notice = Notice::staticGet($reply_id); - if ($notice) { - $profile = $notice->getProfile(); - if ($profile) { - return intval($profile->id); - } else { - common_debug('Can\'t find a profile for notice: ' . $notice->id, __FILE__); - } - } else { - common_debug("Can't get notice: $reply_id", __FILE__); - } - return NULL; - } - - // XXX: Candidate for a general utility method somewhere? - function count_subscriptions($profile) { - - $count = 0; - $sub = new Subscription(); - $sub->subscribed = $profile->id; - - $count = $sub->find(); - - if ($count > 0) { - return $count - 1; - } else { - return 0; - } - } - - function init_document($type='xml') { - switch ($type) { - case 'xml': - header('Content-Type: application/xml; charset=utf-8'); - common_start_xml(); - break; - case 'json': - header('Content-Type: application/json; charset=utf-8'); - - // Check for JSONP callback - $callback = $this->arg('callback'); - if ($callback) { - print $callback . '('; - } - break; - case 'rss': - header("Content-Type: application/rss+xml; charset=utf-8"); - $this->init_twitter_rss(); - break; - case 'atom': - header('Content-Type: application/atom+xml; charset=utf-8'); - $this->init_twitter_atom(); - break; - default: - $this->client_error(_('Not a supported data format.')); - break; - } - - return; - } - - function end_document($type='xml') { - switch ($type) { - case 'xml': - common_end_xml(); - break; - case 'json': - - // Check for JSONP callback - $callback = $this->arg('callback'); - if ($callback) { - print ')'; - } - break; - case 'rss': - $this->end_twitter_rss(); - break; - case 'atom': - $this->end_twitter_rss(); - break; - default: - $this->client_error(_('Not a supported data format.')); - break; - } - return; - } - - function client_error($msg, $code = 400, $content_type = 'json') { - - static $status = array(400 => 'Bad Request', - 401 => 'Unauthorized', - 402 => 'Payment Required', - 403 => 'Forbidden', - 404 => 'Not Found', - 405 => 'Method Not Allowed', - 406 => 'Not Acceptable', - 407 => 'Proxy Authentication Required', - 408 => 'Request Timeout', - 409 => 'Conflict', - 410 => 'Gone', - 411 => 'Length Required', - 412 => 'Precondition Failed', - 413 => 'Request Entity Too Large', - 414 => 'Request-URI Too Long', - 415 => 'Unsupported Media Type', - 416 => 'Requested Range Not Satisfiable', - 417 => 'Expectation Failed'); - - $action = $this->trimmed('action'); - - common_debug("User error '$code' on '$action': $msg", __FILE__); - - if (!array_key_exists($code, $status)) { - $code = 400; - } - - $status_string = $status[$code]; - header('HTTP/1.1 '.$code.' '.$status_string); - - if ($content_type == 'xml') { - $this->init_document('xml'); - common_element_start('hash'); - common_element('error', NULL, $msg); - common_element('request', NULL, $_SERVER['REQUEST_URI']); - common_element_end('hash'); - $this->end_document('xml'); - } else { - $this->init_document('json'); - $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); - print(json_encode($error_array)); - $this->end_document('json'); - } - - } - - function init_twitter_rss() { - common_start_xml(); - common_element_start('rss', array('version' => '2.0')); - } - - function end_twitter_rss() { - common_element_end('rss'); - common_end_xml(); - } - - function init_twitter_atom() { - common_start_xml(); - common_element_start('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US')); - } - - function end_twitter_atom() { - common_end_xml(); - common_element_end('feed'); - } - - function show_profile($profile, $content_type='xml', $notice=NULL) { - $profile_array = $this->twitter_user_array($profile, true); - switch ($content_type) { - case 'xml': - $this->show_twitter_xml_user($profile_array); - break; - case 'json': - $this->show_json_objects($profile_array); - break; - default: - $this->client_error(_('Not a supported data format.')); - return; - } - return; - } - - function get_user($id, $apidata=NULL) { - if (!$id) { - return $apidata['user']; - } else if (is_numeric($id)) { - return User::staticGet($id); - } else { - $nickname = common_canonical_nickname($id); - return User::staticGet('nickname', $nickname); - } - } - - function get_profile($id) { - if (is_numeric($id)) { - return Profile::staticGet($id); - } else { - $user = User::staticGet('nickname', $id); - if ($user) { - return $user->getProfile(); - } else { - return NULL; - } - } - } - - function source_link($source) { - $source_name = _($source); - switch ($source) { - case 'web': - case 'xmpp': - case 'mail': - case 'omb': - case 'api': - break; - default: - $ns = Notice_source::staticGet($source); - if ($ns) { - $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>'; - } - break; - } - return $source_name; - } - - function show_extended_profile($user, $apidata) { - - $this->auth_user = $apidata['user']; - - $profile = $user->getProfile(); - - if (!$profile) { - common_server_error(_('User has no profile.')); - return; - } - - $twitter_user = $this->twitter_user_array($profile, true); - - // Add in extended user fields offered up by this method - $twitter_user['created_at'] = $this->date_twitter($profile->created); - - $subbed = DB_DataObject::factory('subscription'); - $subbed->subscriber = $profile->id; - $subbed_count = (int) $subbed->count() - 1; - - $notices = DB_DataObject::factory('notice'); - $notices->profile_id = $profile->id; - $notice_count = (int) $notices->count(); - - $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0; - $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0; - - // Other fields Twitter sends... - $twitter_user['profile_background_color'] = ''; - $twitter_user['profile_text_color'] = ''; - $twitter_user['profile_link_color'] = ''; - $twitter_user['profile_sidebar_fill_color'] = ''; - - $faves = DB_DataObject::factory('fave'); - $faves->user_id = $user->id; - $faves_count = (int) $faves->count(); - $twitter_user['favourites_count'] = $faves_count; - - $timezone = 'UTC'; - - if ($user->timezone) { - $timezone = $user->timezone; - } - - $t = new DateTime; - $t->setTimezone(new DateTimeZone($timezone)); - $twitter_user['utc_offset'] = $t->format('Z'); - $twitter_user['time_zone'] = $timezone; - - $following = 'false'; - - if (isset($this->auth_user)) { - if ($this->auth_user->isSubscribed($profile)) { - $following = 'true'; - } - - // Not implemented yet - $twitter_user['notifications'] = 'false'; - } - - $twitter_user['following'] = $following; - - if ($apidata['content-type'] == 'xml') { - $this->init_document('xml'); - $this->show_twitter_xml_user($twitter_user); - $this->end_document('xml'); - } elseif ($apidata['content-type'] == 'json') { - $this->init_document('json'); - $this->show_json_objects($twitter_user); - $this->end_document('json'); - } - - } + $entry['content'] = common_xml_safe_str(trim($notice->rendered)); + $entry['title'] = $profile->nickname . ': ' . common_xml_safe_str(trim($notice->content)); + $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id)); + $entry['published'] = common_date_iso8601($notice->created); + $entry['id'] = "tag:$server,2008:$entry[link]"; + $entry['updated'] = $entry['published']; + + # RSS Item specific + $entry['description'] = $entry['content']; + $entry['pubDate'] = common_date_rfc2822($notice->created); + $entry['guid'] = $entry['link']; + + return $entry; + } + + function twitter_rss_dmsg_array($message) { + + $server = common_config('site', 'server'); + $entry = array(); + + $entry['title'] = sprintf('Message from %s to %s', + $message->getFrom()->nickname, $message->getTo()->nickname); + + $entry['content'] = common_xml_safe_str(trim($message->content)); + $entry['link'] = common_local_url('showmessage', array('message' => $message->id)); + $entry['published'] = common_date_iso8601($message->created); + $entry['id'] = "tag:$server,2008:$entry[link]"; + $entry['updated'] = $entry['published']; + + # RSS Item specific + $entry['description'] = $entry['content']; + $entry['pubDate'] = common_date_rfc2822($message->created); + $entry['guid'] = $entry['link']; + + return $entry; + } + + function twitter_dmsg_array($message) { + + $twitter_dm = array(); + + $from_profile = $message->getFrom(); + $to_profile = $message->getTo(); + + $twitter_dm['id'] = $message->id; + $twitter_dm['sender_id'] = $message->from_profile; + $twitter_dm['text'] = trim($message->content); + $twitter_dm['recipient_id'] = $message->to_profile; + $twitter_dm['created_at'] = $this->date_twitter($message->created); + $twitter_dm['sender_screen_name'] = $from_profile->nickname; + $twitter_dm['recipient_screen_name'] = $to_profile->nickname; + $twitter_dm['sender'] = $this->twitter_user_array($from_profile, false); + $twitter_dm['recipient'] = $this->twitter_user_array($to_profile, false); + + return $twitter_dm; + } + + function show_twitter_xml_status($twitter_status) { + common_element_start('status'); + foreach($twitter_status as $element => $value) { + switch ($element) { + case 'user': + $this->show_twitter_xml_user($twitter_status['user']); + break; + case 'text': + common_element($element, NULL, common_xml_safe_str($value)); + break; + default: + common_element($element, NULL, $value); + } + } + common_element_end('status'); + } + + function show_twitter_xml_user($twitter_user, $role='user') { + common_element_start($role); + foreach($twitter_user as $element => $value) { + if ($element == 'status') { + $this->show_twitter_xml_status($twitter_user['status']); + } else { + common_element($element, NULL, $value); + } + } + common_element_end($role); + } + + function show_twitter_rss_item($entry) { + common_element_start('item'); + common_element('title', NULL, $entry['title']); + common_element('description', NULL, $entry['description']); + common_element('pubDate', NULL, $entry['pubDate']); + common_element('guid', NULL, $entry['guid']); + common_element('link', NULL, $entry['link']); + common_element_end('item'); + } + + function show_twitter_atom_entry($entry) { + common_element_start('entry'); + common_element('title', NULL, $entry['title']); + common_element('content', array('type' => 'html'), $entry['content']); + common_element('id', NULL, $entry['id']); + common_element('published', NULL, $entry['published']); + common_element('updated', NULL, $entry['updated']); + common_element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), NULL); + common_element_end('entry'); + } + + function show_json_objects($objects) { + print(json_encode($objects)); + } + + function show_single_xml_status($notice) { + $this->init_document('xml'); + $twitter_status = $this->twitter_status_array($notice); + $this->show_twitter_xml_status($twitter_status); + $this->end_document('xml'); + } + + function show_single_json_status($notice) { + $this->init_document('json'); + $status = $this->twitter_status_array($notice); + $this->show_json_objects($status); + $this->end_document('json'); + } + + function show_single_xml_dmsg($message) { + $this->init_document('xml'); + $dmsg = $this->twitter_dmsg_array($message); + $this->show_twitter_xml_dmsg($dmsg); + $this->end_document('xml'); + } + + function show_single_json_dmsg($message) { + $this->init_document('json'); + $dmsg = $this->twitter_dmsg_array($message); + $this->show_json_objects($dmsg); + $this->end_document('json'); + } + + function show_twitter_xml_dmsg($twitter_dm) { + common_element_start('direct_message'); + foreach($twitter_dm as $element => $value) { + switch ($element) { + case 'sender': + case 'recipient': + $this->show_twitter_xml_user($value, $element); + break; + case 'text': + common_element($element, NULL, common_xml_safe_str($value)); + break; + default: + common_element($element, NULL, $value); + } + } + common_element_end('direct_message'); + } + + function show_xml_timeline($notice) { + + $this->init_document('xml'); + common_element_start('statuses', array('type' => 'array')); + + if (is_array($notice)) { + foreach ($notice as $n) { + $twitter_status = $this->twitter_status_array($n); + $this->show_twitter_xml_status($twitter_status); + } + } else { + while ($notice->fetch()) { + $twitter_status = $this->twitter_status_array($notice); + $this->show_twitter_xml_status($twitter_status); + } + } + + common_element_end('statuses'); + $this->end_document('xml'); + } + + function show_rss_timeline($notice, $title, $link, $subtitle, $suplink=NULL) { + + $this->init_document('rss'); + + common_element_start('channel'); + common_element('title', NULL, $title); + common_element('link', NULL, $link); + if (!is_null($suplink)) { + # For FriendFeed's SUP protocol + common_element('link', array('xmlns' => 'http://www.w3.org/2005/Atom', + 'rel' => 'http://api.friendfeed.com/2008/03#sup', + 'href' => $suplink, + 'type' => 'application/json')); + } + common_element('description', NULL, $subtitle); + common_element('language', NULL, 'en-us'); + common_element('ttl', NULL, '40'); + + if (is_array($notice)) { + foreach ($notice as $n) { + $entry = $this->twitter_rss_entry_array($n); + $this->show_twitter_rss_item($entry); + } + } else { + while ($notice->fetch()) { + $entry = $this->twitter_rss_entry_array($notice); + $this->show_twitter_rss_item($entry); + } + } + + common_element_end('channel'); + $this->end_twitter_rss(); + } + + function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL, $suplink=NULL) { + + $this->init_document('atom'); + + common_element('title', NULL, $title); + common_element('id', NULL, $id); + common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL); + if (!is_null($suplink)) { + # For FriendFeed's SUP protocol + common_element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', + 'href' => $suplink, + 'type' => 'application/json')); + } + common_element('subtitle', NULL, $subtitle); + + if (is_array($notice)) { + foreach ($notice as $n) { + $entry = $this->twitter_rss_entry_array($n); + $this->show_twitter_atom_entry($entry); + } + } else { + while ($notice->fetch()) { + $entry = $this->twitter_rss_entry_array($notice); + $this->show_twitter_atom_entry($entry); + } + } + + $this->end_document('atom'); + + } + + function show_json_timeline($notice) { + + $this->init_document('json'); + + $statuses = array(); + + if (is_array($notice)) { + foreach ($notice as $n) { + $twitter_status = $this->twitter_status_array($n); + array_push($statuses, $twitter_status); + } + } else { + while ($notice->fetch()) { + $twitter_status = $this->twitter_status_array($notice); + array_push($statuses, $twitter_status); + } + } + + $this->show_json_objects($statuses); + + $this->end_document('json'); + } + + // Anyone know what date format this is? + // Twitter's dates look like this: "Mon Jul 14 23:52:38 +0000 2008" -- Zach + function date_twitter($dt) { + $t = strtotime($dt); + return date("D M d G:i:s O Y", $t); + } + + function replier_by_reply($reply_id) { + $notice = Notice::staticGet($reply_id); + if ($notice) { + $profile = $notice->getProfile(); + if ($profile) { + return intval($profile->id); + } else { + common_debug('Can\'t find a profile for notice: ' . $notice->id, __FILE__); + } + } else { + common_debug("Can't get notice: $reply_id", __FILE__); + } + return NULL; + } + + // XXX: Candidate for a general utility method somewhere? + function count_subscriptions($profile) { + + $count = 0; + $sub = new Subscription(); + $sub->subscribed = $profile->id; + + $count = $sub->find(); + + if ($count > 0) { + return $count - 1; + } else { + return 0; + } + } + + function init_document($type='xml') { + switch ($type) { + case 'xml': + header('Content-Type: application/xml; charset=utf-8'); + common_start_xml(); + break; + case 'json': + header('Content-Type: application/json; charset=utf-8'); + + // Check for JSONP callback + $callback = $this->arg('callback'); + if ($callback) { + print $callback . '('; + } + break; + case 'rss': + header("Content-Type: application/rss+xml; charset=utf-8"); + $this->init_twitter_rss(); + break; + case 'atom': + header('Content-Type: application/atom+xml; charset=utf-8'); + $this->init_twitter_atom(); + break; + default: + $this->client_error(_('Not a supported data format.')); + break; + } + + return; + } + + function end_document($type='xml') { + switch ($type) { + case 'xml': + common_end_xml(); + break; + case 'json': + + // Check for JSONP callback + $callback = $this->arg('callback'); + if ($callback) { + print ')'; + } + break; + case 'rss': + $this->end_twitter_rss(); + break; + case 'atom': + $this->end_twitter_rss(); + break; + default: + $this->client_error(_('Not a supported data format.')); + break; + } + return; + } + + function client_error($msg, $code = 400, $content_type = 'json') { + + static $status = array(400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed'); + + $action = $this->trimmed('action'); + + common_debug("User error '$code' on '$action': $msg", __FILE__); + + if (!array_key_exists($code, $status)) { + $code = 400; + } + + $status_string = $status[$code]; + header('HTTP/1.1 '.$code.' '.$status_string); + + if ($content_type == 'xml') { + $this->init_document('xml'); + common_element_start('hash'); + common_element('error', NULL, $msg); + common_element('request', NULL, $_SERVER['REQUEST_URI']); + common_element_end('hash'); + $this->end_document('xml'); + } else { + $this->init_document('json'); + $error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']); + print(json_encode($error_array)); + $this->end_document('json'); + } + + } + + function init_twitter_rss() { + common_start_xml(); + common_element_start('rss', array('version' => '2.0')); + } + + function end_twitter_rss() { + common_element_end('rss'); + common_end_xml(); + } + + function init_twitter_atom() { + common_start_xml(); + common_element_start('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US')); + } + + function end_twitter_atom() { + common_end_xml(); + common_element_end('feed'); + } + + function show_profile($profile, $content_type='xml', $notice=NULL) { + $profile_array = $this->twitter_user_array($profile, true); + switch ($content_type) { + case 'xml': + $this->show_twitter_xml_user($profile_array); + break; + case 'json': + $this->show_json_objects($profile_array); + break; + default: + $this->client_error(_('Not a supported data format.')); + return; + } + return; + } + + function get_user($id, $apidata=NULL) { + if (!$id) { + return $apidata['user']; + } else if (is_numeric($id)) { + return User::staticGet($id); + } else { + $nickname = common_canonical_nickname($id); + return User::staticGet('nickname', $nickname); + } + } + + function get_profile($id) { + if (is_numeric($id)) { + return Profile::staticGet($id); + } else { + $user = User::staticGet('nickname', $id); + if ($user) { + return $user->getProfile(); + } else { + return NULL; + } + } + } + + function source_link($source) { + $source_name = _($source); + switch ($source) { + case 'web': + case 'xmpp': + case 'mail': + case 'omb': + case 'api': + break; + default: + $ns = Notice_source::staticGet($source); + if ($ns) { + $source_name = '<a href="' . $ns->url . '">' . $ns->name . '</a>'; + } + break; + } + return $source_name; + } + + function show_extended_profile($user, $apidata) { + + $this->auth_user = $apidata['user']; + + $profile = $user->getProfile(); + + if (!$profile) { + common_server_error(_('User has no profile.')); + return; + } + + $twitter_user = $this->twitter_user_array($profile, true); + + // Add in extended user fields offered up by this method + $twitter_user['created_at'] = $this->date_twitter($profile->created); + + $subbed = DB_DataObject::factory('subscription'); + $subbed->subscriber = $profile->id; + $subbed_count = (int) $subbed->count() - 1; + + $notices = DB_DataObject::factory('notice'); + $notices->profile_id = $profile->id; + $notice_count = (int) $notices->count(); + + $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0; + $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0; + + // Other fields Twitter sends... + $twitter_user['profile_background_color'] = ''; + $twitter_user['profile_text_color'] = ''; + $twitter_user['profile_link_color'] = ''; + $twitter_user['profile_sidebar_fill_color'] = ''; + + $faves = DB_DataObject::factory('fave'); + $faves->user_id = $user->id; + $faves_count = (int) $faves->count(); + $twitter_user['favourites_count'] = $faves_count; + + $timezone = 'UTC'; + + if ($user->timezone) { + $timezone = $user->timezone; + } + + $t = new DateTime; + $t->setTimezone(new DateTimeZone($timezone)); + $twitter_user['utc_offset'] = $t->format('Z'); + $twitter_user['time_zone'] = $timezone; + + $following = 'false'; + + if (isset($this->auth_user)) { + if ($this->auth_user->isSubscribed($profile)) { + $following = 'true'; + } + + // Not implemented yet + $twitter_user['notifications'] = 'false'; + } + + $twitter_user['following'] = $following; + + if ($apidata['content-type'] == 'xml') { + $this->init_document('xml'); + $this->show_twitter_xml_user($twitter_user); + $this->end_document('xml'); + } elseif ($apidata['content-type'] == 'json') { + $this->init_document('json'); + $this->show_json_objects($twitter_user); + $this->end_document('json'); + } + + } }
\ No newline at end of file diff --git a/_darcs/pristine/lib/xmppqueuehandler.php b/_darcs/pristine/lib/xmppqueuehandler.php index cfc9642e4..33b987291 100644 --- a/_darcs/pristine/lib/xmppqueuehandler.php +++ b/_darcs/pristine/lib/xmppqueuehandler.php @@ -29,63 +29,63 @@ require_once(INSTALLDIR.'/lib/queuehandler.php'); */ class XmppQueueHandler extends QueueHandler { - - function start() { - # Low priority; we don't want to receive messages - $this->log(LOG_INFO, "INITIALIZE"); - $this->conn = jabber_connect($this->_id); - if ($this->conn) { - $this->conn->addEventHandler('message', 'forward_message', $this); - $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); - $this->conn->setReconnectTimeout(600); - jabber_send_presence("Send me a message to post a notice", 'available', NULL, 'available', -1); - } - return !is_null($this->conn); - } - - function handle_reconnect(&$pl) { - $this->conn->processUntil('session_start'); - $this->conn->presence(NULL, 'available', NULL, 'available', -1); - } + + function start() { + # Low priority; we don't want to receive messages + $this->log(LOG_INFO, "INITIALIZE"); + $this->conn = jabber_connect($this->_id); + if ($this->conn) { + $this->conn->addEventHandler('message', 'forward_message', $this); + $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); + $this->conn->setReconnectTimeout(600); + jabber_send_presence("Send me a message to post a notice", 'available', NULL, 'available', -1); + } + return !is_null($this->conn); + } + + function handle_reconnect(&$pl) { + $this->conn->processUntil('session_start'); + $this->conn->presence(NULL, 'available', NULL, 'available', -1); + } - function idle($timeout=0) { - # Process the queue for as long as needed - try { - if ($this->conn) { - $this->conn->processTime($timeout); - } - } catch (XMPPHP_Exception $e) { - $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); - die($e->getMessage()); - } - } - - function forward_message(&$pl) { - if ($pl['type'] != 'chat') { - $this->log(LOG_DEBUG, 'Ignoring message of type ' . $pl['type'] . ' from ' . $pl['from']); - return; - } - $listener = $this->listener(); - if (strtolower($listener) == strtolower($pl['from'])) { - $this->log(LOG_WARNING, 'Ignoring loop message.'); - return; - } - $this->log(LOG_INFO, 'Forwarding message from ' . $pl['from'] . ' to ' . $listener); - $this->conn->message($this->listener(), $pl['body'], 'chat', NULL, $this->ofrom($pl['from'])); - } + function idle($timeout=0) { + # Process the queue for as long as needed + try { + if ($this->conn) { + $this->conn->processTime($timeout); + } + } catch (XMPPHP_Exception $e) { + $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); + die($e->getMessage()); + } + } + + function forward_message(&$pl) { + if ($pl['type'] != 'chat') { + $this->log(LOG_DEBUG, 'Ignoring message of type ' . $pl['type'] . ' from ' . $pl['from']); + return; + } + $listener = $this->listener(); + if (strtolower($listener) == strtolower($pl['from'])) { + $this->log(LOG_WARNING, 'Ignoring loop message.'); + return; + } + $this->log(LOG_INFO, 'Forwarding message from ' . $pl['from'] . ' to ' . $listener); + $this->conn->message($this->listener(), $pl['body'], 'chat', NULL, $this->ofrom($pl['from'])); + } - function ofrom($from) { - $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n"; - $address .= "<address type='ofrom' jid='$from' />\n"; - $address .= "</addresses>\n"; - return $address; - } + function ofrom($from) { + $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n"; + $address .= "<address type='ofrom' jid='$from' />\n"; + $address .= "</addresses>\n"; + return $address; + } - function listener() { - if (common_config('xmpp', 'listener')) { - return common_config('xmpp', 'listener'); - } else { - return jabber_daemon_address() . '/' . common_config('xmpp','resource') . '-listener'; - } - } + function listener() { + if (common_config('xmpp', 'listener')) { + return common_config('xmpp', 'listener'); + } else { + return jabber_daemon_address() . '/' . common_config('xmpp','resource') . '-listener'; + } + } } |