summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/action.php62
-rw-r--r--lib/clienterroraction.php15
-rw-r--r--lib/common.php36
-rw-r--r--lib/groupsbymemberssection.php2
-rw-r--r--lib/groupsbypostssection.php2
-rw-r--r--lib/grouptagcloudsection.php8
-rw-r--r--lib/jabber.php61
-rw-r--r--lib/jsonsearchresultslist.php270
-rw-r--r--lib/language.php30
-rw-r--r--lib/logingroupnav.php20
-rw-r--r--lib/mail.php17
-rw-r--r--lib/messageform.php10
-rw-r--r--lib/noticeform.php9
-rw-r--r--lib/noticelist.php9
-rw-r--r--lib/noticesection.php5
-rw-r--r--lib/oauthstore.php9
-rw-r--r--lib/omb.php5
-rw-r--r--lib/openid.php4
-rw-r--r--lib/personaltagcloudsection.php10
-rw-r--r--lib/ping.php122
-rw-r--r--lib/popularnoticesection.php12
-rw-r--r--lib/profilelist.php24
-rw-r--r--lib/publicgroupnav.php28
-rw-r--r--lib/router.php76
-rw-r--r--lib/rssaction.php18
-rw-r--r--lib/search_engines.php34
-rw-r--r--lib/searchaction.php4
-rw-r--r--lib/servererroraction.php20
-rw-r--r--lib/settingsaction.php4
-rw-r--r--lib/subgroupnav.php2
-rw-r--r--lib/topposterssection.php2
-rw-r--r--lib/twitter.php7
-rw-r--r--lib/twitterapi.php188
-rw-r--r--lib/util.php99
34 files changed, 840 insertions, 384 deletions
diff --git a/lib/action.php b/lib/action.php
index 9c71a153d..5d0d5b758 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -112,6 +112,7 @@ class Action extends HTMLOutputter // lawsuit
// XXX: attributes (profile?)
$this->elementStart('head');
$this->showTitle();
+ $this->showShortcutIcon();
$this->showStylesheets();
$this->showScripts();
$this->showOpenSearch();
@@ -148,6 +149,32 @@ class Action extends HTMLOutputter // lawsuit
}
/**
+ * Show themed shortcut icon
+ *
+ * @return nothing
+ */
+ function showShortcutIcon()
+ {
+ if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
+ $this->element('link', array('rel' => 'shortcut icon',
+ 'href' => theme_path('favicon.ico')));
+ } else {
+ $this->element('link', array('rel' => 'shortcut icon',
+ 'href' => common_path('favicon.ico')));
+ }
+
+ if (common_config('site', 'mobile')) {
+ if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
+ $this->element('link', array('rel' => 'apple-touch-icon',
+ 'href' => theme_path('apple-touch-icon.png')));
+ } else {
+ $this->element('link', array('rel' => 'apple-touch-icon',
+ 'href' => common_path('apple-touch-icon.png')));
+ }
+ }
+ }
+
+ /**
* Show stylesheets
*
* @return nothing
@@ -156,17 +183,12 @@ class Action extends HTMLOutputter // lawsuit
{
if (Event::handle('StartShowStyles', array($this))) {
if (Event::handle('StartShowLaconicaStyles', array($this))) {
-
$this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
'href' => theme_path('css/display.css', 'base') . '?version=' . LACONICA_VERSION,
'media' => 'screen, projection, tv'));
$this->element('link', array('rel' => 'stylesheet',
'type' => 'text/css',
- 'href' => theme_path('css/modal.css', 'base') . '?version=' . LACONICA_VERSION,
- 'media' => 'screen, projection, tv'));
- $this->element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
'href' => theme_path('css/display.css', null) . '?version=' . LACONICA_VERSION,
'media' => 'screen, projection, tv'));
if (common_config('site', 'mobile')) {
@@ -215,11 +237,6 @@ class Action extends HTMLOutputter // lawsuit
$this->element('script', array('type' => 'text/javascript',
'src' => common_path('js/jquery.form.js')),
' ');
-
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/jquery.simplemodal-1.2.2.pack.js')),
- ' ');
-
Event::handle('EndShowJQueryScripts', array($this));
}
if (Event::handle('StartShowLaconicaScripts', array($this))) {
@@ -232,14 +249,6 @@ class Action extends HTMLOutputter // lawsuit
// Frame-busting code to avoid clickjacking attacks.
$this->element('script', array('type' => 'text/javascript'),
'if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
-
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/flowplayer-3.0.5.min.js')),
- ' ');
-
- $this->element('script', array('type' => 'text/javascript',
- 'src' => common_path('js/video.js')),
- ' ');
Event::handle('EndShowLaconicaScripts', array($this));
}
Event::handle('EndShowScripts', array($this));
@@ -317,7 +326,9 @@ class Action extends HTMLOutputter // lawsuit
*/
function showBody()
{
- $this->elementStart('body', array('id' => $this->trimmed('action')));
+ $this->elementStart('body', (common_current_user()) ? array('id' => $this->trimmed('action'),
+ 'class' => 'user_in')
+ : array('id' => $this->trimmed('action')));
$this->elementStart('div', array('id' => 'wrap'));
if (Event::handle('StartShowHeader', array($this))) {
$this->showHeader();
@@ -819,9 +830,8 @@ class Action extends HTMLOutputter // lawsuit
}
if ($lm) {
header('Last-Modified: ' . date(DATE_RFC1123, $lm));
- $if_modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
- if ($if_modified_since) {
- $ims = strtotime($if_modified_since);
+ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
+ $ims = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
if ($lm <= $ims) {
$if_none_match = $_SERVER['HTTP_IF_NONE_MATCH'];
if (!$if_none_match ||
@@ -976,17 +986,17 @@ class Action extends HTMLOutputter // lawsuit
}
if ($have_before) {
$pargs = array('page' => $page-1);
- $newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_prev'));
- $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'prev'),
+ $this->element('a', array('href' => common_local_url($action, $args, $pargs),
+ 'rel' => 'prev'),
_('After'));
$this->elementEnd('li');
}
if ($have_after) {
$pargs = array('page' => $page+1);
- $newargs = $args ? array_merge($args, $pargs) : $pargs;
$this->elementStart('li', array('class' => 'nav_next'));
- $this->element('a', array('href' => common_local_url($action, $newargs), 'rel' => 'next'),
+ $this->element('a', array('href' => common_local_url($action, $args, $pargs),
+ 'rel' => 'next'),
_('Before'));
$this->elementEnd('li');
}
diff --git a/lib/clienterroraction.php b/lib/clienterroraction.php
index 5019dc06d..0c48414d5 100644
--- a/lib/clienterroraction.php
+++ b/lib/clienterroraction.php
@@ -49,7 +49,7 @@ class ClientErrorAction extends ErrorAction
function __construct($message='Error', $code=400)
{
parent::__construct($message, $code);
-
+
$this->status = array(400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
@@ -72,7 +72,7 @@ class ClientErrorAction extends ErrorAction
}
// XXX: Should these error actions even be invokable via URI?
-
+
function handle($args)
{
parent::handle($args);
@@ -84,11 +84,16 @@ class ClientErrorAction extends ErrorAction
}
$this->message = $this->trimmed('message');
-
+
if (!$this->message) {
- $this->message = "Client Error $this->code";
- }
+ $this->message = "Client Error $this->code";
+ }
$this->showPage();
}
+
+ function title()
+ {
+ return $this->status[$this->code];
+ }
}
diff --git a/lib/common.php b/lib/common.php
index 4fc749ca0..c2037c3ad 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
-define('LACONICA_VERSION', '0.7.1');
+define('LACONICA_VERSION', '0.7.2.1');
define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48);
@@ -73,6 +73,8 @@ $config =
'theme' => 'default',
'path' => $_path,
'logfile' => null,
+ 'logo' => null,
+ 'logdebug' => false,
'fancy' => false,
'locale_path' => INSTALLDIR.'/locale',
'language' => 'en_US',
@@ -84,7 +86,10 @@ $config =
'broughtbyurl' => null,
'closed' => false,
'inviteonly' => false,
- 'private' => false),
+ 'private' => false,
+ 'ssl' => 'never',
+ 'sslserver' => null,
+ 'dupelimit' => 60), # default for same person saying the same thing
'syslog' =>
array('appname' => 'laconica', # for syslog
'priority' => 'debug'), # XXX: currently ignored
@@ -138,13 +143,19 @@ $config =
'user' => false,
'group' => false),
'integration' =>
- array('source' => 'Laconica'), # source attribute for Twitter
+ array('source' => 'Laconica', # source attribute for Twitter
+ 'taguri' => $_server.',2009'), # base for tag URIs
'memcached' =>
array('enabled' => false,
'server' => 'localhost',
'port' => 11211),
+ 'ping' =>
+ array('notify' => array()),
'inboxes' =>
array('enabled' => true), # on by default for new sites
+ 'newuser' =>
+ array('subscribe' => null,
+ 'welcome' => null),
);
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
@@ -178,12 +189,31 @@ if (strlen($_path) > 0) {
$_config_files[] = INSTALLDIR.'/config.php';
+$_have_a_config = false;
+
foreach ($_config_files as $_config_file) {
if (file_exists($_config_file)) {
include_once($_config_file);
+ $_have_a_config = true;
}
}
+function _have_config()
+{
+ global $_have_a_config;
+ return $_have_a_config;
+}
+
+// XXX: Throw a conniption if database not installed
+
+// Fixup for laconica.ini
+
+$_db_name = substr($config['db']['database'], strrpos($config['db']['database'], '/') + 1);
+
+if ($_db_name != 'laconica' && !array_key_exists('ini_'.$_db_name, $config['db'])) {
+ $config['db']['ini_'.$_db_name] = INSTALLDIR.'/classes/laconica.ini';
+}
+
// XXX: how many of these could be auto-loaded on use?
require_once('Validate.php');
diff --git a/lib/groupsbymemberssection.php b/lib/groupsbymemberssection.php
index 4fa07a244..963e21f15 100644
--- a/lib/groupsbymemberssection.php
+++ b/lib/groupsbymemberssection.php
@@ -48,7 +48,7 @@ class GroupsByMembersSection extends GroupSection
$qry = 'SELECT user_group.*, count(*) as value ' .
'FROM user_group JOIN group_member '.
'ON user_group.id = group_member.group_id ' .
- 'GROUP BY user_group.id ' .
+ 'GROUP BY user_group.id,user_group.nickname,user_group.fullname,user_group.homepage,user_group.description,user_group.location,user_group.original_logo,user_group.homepage_logo,user_group.stream_logo,user_group.mini_logo,user_group.created,user_group.modified ' .
'ORDER BY value DESC ';
$limit = GROUPS_PER_SECTION;
diff --git a/lib/groupsbypostssection.php b/lib/groupsbypostssection.php
index a5e33a93d..325b4033f 100644
--- a/lib/groupsbypostssection.php
+++ b/lib/groupsbypostssection.php
@@ -48,7 +48,7 @@ class GroupsByPostsSection extends GroupSection
$qry = 'SELECT user_group.*, count(*) as value ' .
'FROM user_group JOIN group_inbox '.
'ON user_group.id = group_inbox.group_id ' .
- 'GROUP BY user_group.id ' .
+ 'GROUP BY user_group.id,user_group.nickname,user_group.fullname,user_group.homepage,user_group.description,user_group.location,user_group.original_logo,user_group.homepage_logo,user_group.stream_logo,user_group.mini_logo,user_group.created,user_group.modified ' .
'ORDER BY value DESC ';
$limit = GROUPS_PER_SECTION;
diff --git a/lib/grouptagcloudsection.php b/lib/grouptagcloudsection.php
index f05be85cb..5d68af28b 100644
--- a/lib/grouptagcloudsection.php
+++ b/lib/grouptagcloudsection.php
@@ -58,8 +58,14 @@ class GroupTagCloudSection extends TagCloudSection
function getTags()
{
+ if (common_config('db', 'type') == 'pgsql') {
+ $weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
+ } else {
+ $weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
+ }
+
$qry = 'SELECT notice_tag.tag, '.
- 'sum(exp(-(now() - notice_tag.created)/%s)) as weight ' .
+ $weightexpr . ' as weight ' .
'FROM notice_tag JOIN notice ' .
'ON notice_tag.notice_id = notice.id ' .
'JOIN group_inbox on group_inbox.notice_id = notice.id ' .
diff --git a/lib/jabber.php b/lib/jabber.php
index 3fbb3e1ab..7d584ad01 100644
--- a/lib/jabber.php
+++ b/lib/jabber.php
@@ -163,50 +163,25 @@ function jabber_send_notice($to, $notice)
function jabber_format_entry($profile, $notice)
{
- // FIXME: notice url might be remote
-
- $noticeurl = common_local_url('shownotice',
- array('notice' => $notice->id));
-
- $msg = jabber_format_notice($profile, $notice);
-
- $self_url = common_local_url('userrss', array('nickname' => $profile->nickname));
-
- $entry = "\n<entry xmlns='http://www.w3.org/2005/Atom'>\n";
- $entry .= "<source>\n";
- $entry .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
- $entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n";
- $entry .= "<link rel='self' type='application/rss+xml' href='" . $self_url . "'/>\n";
- $entry .= "<author><name>" . $profile->nickname . "</name></author>\n";
- $entry .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
- $entry .= "</source>\n";
- $entry .= "<title>" . htmlspecialchars($msg) . "</title>\n";
- $entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
- $entry .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
- $entry .= "<id>". $notice->uri . "</id>\n";
- $entry .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
- $entry .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
- if ($notice->reply_to) {
- $replyurl = common_local_url('shownotice',
- array('notice' => $notice->reply_to));
- $entry .= "<link rel='related' href='" . $replyurl . "'/>\n";
+ $entry = $notice->asAtomEntry(true, true);
+
+ $xs = new XMLStringer();
+ $xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im'));
+ $xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml'));
+ $xs->element('a', array('href' => $profile->profileurl),
+ $profile->nickname);
+ $xs->text(": ");
+ if (!empty($notice->rendered)) {
+ $xs->raw($notice->rendered);
+ } else {
+ $xs->raw(common_render_content($notice->content, $notice));
}
- $entry .= "</entry>\n";
-
- $html = "\n<html xmlns='http://jabber.org/protocol/xhtml-im'>\n";
- $html .= "<body xmlns='http://www.w3.org/1999/xhtml'>\n";
- $html .= "<a href='".htmlspecialchars($profile->profileurl)."'>".$profile->nickname."</a>: ";
- $html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice);
- $html .= "\n</body>\n";
- $html .= "\n</html>\n";
+ $xs->elementEnd('body');
+ $xs->elementEnd('html');
- $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
- $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n";
- $address .= "</addresses>\n";
+ $html = $xs->getString();
- // FIXME: include a pubsub event, too.
-
- return $html . $entry . $address;
+ return $html . ' ' . $entry;
}
/**
@@ -410,8 +385,8 @@ function jabber_broadcast_notice($notice)
"ON $UT.id = notice_inbox.user_id " .
'WHERE notice_inbox.notice_id = ' . $notice->id . ' ' .
'AND notice_inbox.source = 2 ' .
- 'AND user.jabber is not null ' .
- 'AND user.jabbernotify = 1 ');
+ "AND $UT.jabber is not null " .
+ "AND $UT.jabbernotify = 1 ");
while ($user->fetch()) {
if (!array_key_exists($user->id, $sent_to)) {
diff --git a/lib/jsonsearchresultslist.php b/lib/jsonsearchresultslist.php
new file mode 100644
index 000000000..0cdcf0c51
--- /dev/null
+++ b/lib/jsonsearchresultslist.php
@@ -0,0 +1,270 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * widget for displaying a list of notices
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @copyright 2009 Control Yourself, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ */
+
+if (!defined('LACONICA')) {
+ exit(1);
+}
+
+/**
+ * widget-like class for showing JSON search results
+ *
+ * @category Search
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ *
+ */
+
+class JSONSearchResultsList
+{
+ protected $notice; // protected attrs invisible to json_encode()
+ protected $rpp;
+
+ // The below attributes are carefully named so the JSON output from
+ // this obj matches the output from search.twitter.com
+
+ var $results;
+ var $since_id;
+ var $max_id;
+ var $refresh_url;
+ var $results_per_page;
+ var $completed_in;
+ var $page;
+ var $query;
+
+ /**
+ * constructor
+ *
+ * @param Notice $notice stream of notices from DB_DataObject
+ * @param string $query the original search query
+ * @param int $rpp the number of results to display per page
+ * @param int $page a page offset
+ * @param int $since_id only display notices newer than this
+ */
+
+ function __construct($notice, $query, $rpp, $page, $since_id = 0)
+ {
+ $this->notice = $notice;
+ $this->query = urlencode($query);
+ $this->results_per_page = $rpp;
+ $this->rpp = $rpp;
+ $this->page = $page;
+ $this->since_id = $since_id;
+ $this->results = array();
+ }
+
+ /**
+ * show the list of search results
+ *
+ * @return int $count of the search results listed.
+ */
+
+ function show()
+ {
+ $cnt = 0;
+
+ $time_start = microtime(true);
+
+ while ($this->notice->fetch() && $cnt <= $this->rpp) {
+ $cnt++;
+
+ // XXX: Hmmm. this depends on desc sort order
+ if (!$this->max_id) {
+ $this->max_id = (int)$this->notice->id;
+ }
+
+ if ($cnt > $this->rpp) {
+ break;
+ }
+
+ $item = new ResultItem($this->notice);
+ array_push($this->results, $item);
+ }
+
+ $time_end = microtime(true);
+ $this->completed_in = $time_end - $time_start;
+
+ // Set other attrs
+
+ $this->refresh_url = '?since_id=' . $this->max_id .
+ '&q=' . $this->query;
+
+ // pagination stuff
+
+ if ($cnt > $this->rpp) {
+ $this->next_page = '?page=' . ($this->page + 1) .
+ '&max_id=' . $this->max_id;
+ if ($this->rpp != 15) {
+ $this->next_page .= '&rpp=' . $this->rpp;
+ }
+ $this->next_page .= '&q=' . $this->query;
+ }
+
+ if ($this->page > 1) {
+ $this->previous_page = '?page=' . ($this->page - 1) .
+ '&max_id=' . $this->max_id;
+ if ($this->rpp != 15) {
+ $this->previous_page .= '&rpp=' . $this->rpp;
+ }
+ $this->previous_page .= '&q=' . $this->query;
+ }
+
+ print json_encode($this);
+
+ return $cnt;
+ }
+}
+
+/**
+ * widget for displaying a single JSON search result
+ *
+ * @category UI
+ * @package Laconica
+ * @author Zach Copley <zach@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ * @see JSONSearchResultsList
+ */
+
+class ResultItem
+{
+ /** The notice this item is based on. */
+
+ protected $notice; // protected attrs invisible to json_encode()
+
+ /** The profile associated with the notice. */
+
+ protected $profile;
+
+ // The below attributes are carefully named so the JSON output from
+ // this obj matches the output from search.twitter.com
+
+ var $text;
+ var $to_user_id;
+ var $to_user;
+ var $from_user;
+ var $id;
+ var $from_user_id;
+ var $iso_language_code;
+ var $source;
+ var $profile_image_url;
+ var $created_at;
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice)
+ {
+ $this->notice = $notice;
+ $this->profile = $notice->getProfile();
+ $this->buildResult();
+ }
+
+ /**
+ * Build a search result object
+ *
+ * This populates the the result in preparation for JSON encoding.
+ *
+ * @return void
+ */
+
+ function buildResult()
+ {
+ $this->text = $this->notice->content;
+ $replier_profile = null;
+
+ if ($this->notice->reply_to) {
+ $reply = Notice::staticGet(intval($notice->reply_to));
+ if ($reply) {
+ $replier_profile = $reply->getProfile();
+ }
+ }
+
+ $this->to_user_id = ($replier_profile) ?
+ intval($replier_profile->id) : null;
+ $this->to_user = ($replier_profile) ?
+ $replier_profile->nickname : null;
+
+ $this->from_user = $this->profile->nickname;
+ $this->id = $this->notice->id;
+ $this->from_user_id = $this->profile->id;
+
+ $user = User::staticGet('id', $this->profile->id);
+
+ $this->iso_language_code = $this->user->language;
+
+ $this->source = $this->getSourceLink($this->notice->source);
+
+ $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
+
+ $this->profile_image_url = ($avatar) ?
+ $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE);
+
+ $this->created_at = date('r', $this->notice->created);
+ }
+
+ /**
+ * Show the source of the notice
+ *
+ * Either the name (and link) of the API client that posted the notice,
+ * or one of other other channels.
+ *
+ * @param string $source the source of the Notice
+ *
+ * @return string a fully rendered source of the Notice
+ */
+
+ function getSourceLink($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;
+ }
+
+}
diff --git a/lib/language.php b/lib/language.php
index 79e9030ae..cd6498d30 100644
--- a/lib/language.php
+++ b/lib/language.php
@@ -104,33 +104,33 @@ function get_all_languages() {
'bg' => array('q' => 0.8, 'lang' => 'bg_BG', 'name' => 'Bulgarian', 'direction' => 'ltr'),
'ca' => array('q' => 0.5, 'lang' => 'ca_ES', 'name' => 'Catalan', 'direction' => 'ltr'),
'cs' => array('q' => 0.5, 'lang' => 'cs_CZ', 'name' => 'Czech', 'direction' => 'ltr'),
- 'de' => array('q' => 0.5, 'lang' => 'de_DE', 'name' => 'German', 'direction' => 'ltr'),
+ 'de' => array('q' => 0.8, 'lang' => 'de_DE', 'name' => 'German', 'direction' => 'ltr'),
'el' => array('q' => 0.1, 'lang' => 'el', 'name' => 'Greek', 'direction' => 'ltr'),
'en-us' => array('q' => 1, 'lang' => 'en_US', 'name' => 'English (US)', 'direction' => 'ltr'),
- 'en-gb' => array('q' => 0.3, 'lang' => 'en_GB', 'name' => 'English (British)', 'direction' => 'ltr'),
+ 'en-gb' => array('q' => 1, 'lang' => 'en_GB', 'name' => 'English (British)', 'direction' => 'ltr'),
'en' => array('q' => 1, 'lang' => 'en', 'name' => 'English', 'direction' => 'ltr'),
- 'es' => array('q' => 0.5, 'lang' => 'es', 'name' => 'Spanish', 'direction' => 'ltr'),
- 'fi' => array('q' => 0.5, 'lang' => 'fi', 'name' => 'Finnish', 'direction' => 'ltr'),
- 'fr-fr' => array('q' => 0.2, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'),
+ 'es' => array('q' => 1, 'lang' => 'es', 'name' => 'Spanish', 'direction' => 'ltr'),
+ 'fi' => array('q' => 1, 'lang' => 'fi', 'name' => 'Finnish', 'direction' => 'ltr'),
+ 'fr-fr' => array('q' => 1, 'lang' => 'fr_FR', 'name' => 'French', 'direction' => 'ltr'),
'he' => array('q' => 0.5, 'lang' => 'he_IL', 'name' => 'Hebrew', 'direction' => 'rtl'),
- 'it' => array('q' => 0.9, 'lang' => 'it_IT', 'name' => 'Italian', 'direction' => 'ltr'),
+ 'it' => array('q' => 1, 'lang' => 'it_IT', 'name' => 'Italian', 'direction' => 'ltr'),
'jp' => array('q' => 0.5, 'lang' => 'ja_JP', 'name' => 'Japanese', 'direction' => 'ltr'),
-# 'ko' => array('q' => 0, 'lang' => 'ko', 'name' => 'Korean', 'direction' => 'ltr'),
+ 'ko' => array('q' => 0.9, 'lang' => 'ko_KR', 'name' => 'Korean', 'direction' => 'ltr'),
'mk' => array('q' => 0.5, 'lang' => 'mk_MK', 'name' => 'Macedonian', 'direction' => 'ltr'),
'nb' => array('q' => 0.1, 'lang' => 'nb_NO', 'name' => 'Norwegian (Bokmål)', 'direction' => 'ltr'),
'no' => array('q' => 0.1, 'lang' => 'nb_NO', 'name' => 'Norwegian (Bokmål)', 'direction' => 'ltr'),
- 'nn' => array('q' => 0.1, 'lang' => 'nn_NO', 'name' => 'Norwegian (Nynorsk)', 'direction' => 'ltr'),
+ 'nn' => array('q' => 1, 'lang' => 'nn_NO', 'name' => 'Norwegian (Nynorsk)', 'direction' => 'ltr'),
'nl' => array('q' => 0.5, 'lang' => 'nl_NL', 'name' => 'Dutch', 'direction' => 'ltr'),
'pl' => array('q' => 0.5, 'lang' => 'pl_PL', 'name' => 'Polish', 'direction' => 'ltr'),
-# 'pt' => array('q' => 0, 'lang' => 'pt', 'name' => 'Portuguese', 'direction' => 'ltr'),
- 'pt-br' => array('q' => 0.7, 'lang' => 'pt_BR', 'name' => 'Portuguese Brazil', 'direction' => 'ltr'),
- 'ru' => array('q' => 0.1, 'lang' => 'ru_RU', 'name' => 'Russian', 'direction' => 'ltr'),
- 'sv' => array('q' => 0.9, 'lang' => 'sv_SE', 'name' => 'Swedish', 'direction' => 'ltr'),
+ 'pt' => array('q' => 0.1, 'lang' => 'pt', 'name' => 'Portuguese', 'direction' => 'ltr'),
+ 'pt-br' => array('q' => 0.9, 'lang' => 'pt_BR', 'name' => 'Portuguese Brazil', 'direction' => 'ltr'),
+ 'ru' => array('q' => 0.9, 'lang' => 'ru_RU', 'name' => 'Russian', 'direction' => 'ltr'),
+ 'sv' => array('q' => 0.8, 'lang' => 'sv_SE', 'name' => 'Swedish', 'direction' => 'ltr'),
'te' => array('q' => 0.3, 'lang' => 'te_IN', 'name' => 'Telugu', 'direction' => 'ltr'),
'tr' => array('q' => 0.5, 'lang' => 'tr_TR', 'name' => 'Turkish', 'direction' => 'ltr'),
- 'uk' => array('q' => 0.7, 'lang' => 'uk_UA', 'name' => 'Ukrainian', 'direction' => 'ltr'),
- 'vi' => array('q' => 0.7, 'lang' => 'vi_VN', 'name' => 'Vietnamese', 'direction' => 'ltr'),
+ 'uk' => array('q' => 1, 'lang' => 'uk_UA', 'name' => 'Ukrainian', 'direction' => 'ltr'),
+ 'vi' => array('q' => 0.8, 'lang' => 'vi_VN', 'name' => 'Vietnamese', 'direction' => 'ltr'),
'zh-cn' => array('q' => 0.9, 'lang' => 'zh_CN', 'name' => 'Chinese (Simplified)', 'direction' => 'ltr'),
- 'zh-hant' => array('q' => 0.2, 'lang' => 'zh_hant', 'name' => 'Chinese (Taiwanese)', 'direction' => 'ltr'),
+ 'zh-hant' => array('q' => 0.2, 'lang' => 'zh_TW', 'name' => 'Chinese (Taiwanese)', 'direction' => 'ltr'),
);
}
diff --git a/lib/logingroupnav.php b/lib/logingroupnav.php
index fd909581f..f23985f3a 100644
--- a/lib/logingroupnav.php
+++ b/lib/logingroupnav.php
@@ -70,16 +70,16 @@ class LoginGroupNav extends Widget
function show()
{
// action => array('prompt', 'title')
- $menu =
- array('login' =>
- array(_('Login'),
- _('Login with a username and password')),
- 'register' =>
- array(_('Register'),
- _('Sign up for a new account')),
- 'openidlogin' =>
- array(_('OpenID'),
- _('Login or register with OpenID')));
+ $menu = array();
+
+ $menu['login'] = array(_('Login'),
+ _('Login with a username and password'));
+ if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
+ $menu['register'] = array(_('Register'),
+ _('Sign up for a new account'));
+ }
+ $menu['openidlogin'] = array(_('OpenID'),
+ _('Login or register with OpenID'));
$action_name = $this->action->trimmed('action');
$this->action->elementStart('ul', array('class' => 'nav'));
diff --git a/lib/mail.php b/lib/mail.php
index 9fa86de5c..27a1d99dc 100644
--- a/lib/mail.php
+++ b/lib/mail.php
@@ -50,10 +50,9 @@ function mail_backend()
static $backend = null;
if (!$backend) {
- global $config;
- $backend = Mail::factory($config['mail']['backend'],
- ($config['mail']['params']) ?
- $config['mail']['params'] :
+ $backend = Mail::factory(common_config('mail', 'backend'),
+ (common_config('mail', 'params')) ?
+ common_config('mail', 'params') :
array());
if (PEAR::isError($backend)) {
common_server_error($backend->getMessage(), 500);
@@ -555,17 +554,19 @@ function mail_notify_fave($other, $user, $notice)
$body = sprintf(_("%1\$s just added your notice from %2\$s".
" as one of their favorites.\n\n" .
- "In case you forgot, you can see the text".
- " of your notice here:\n\n" .
+ "The URL of your notice is:\n\n" .
"%3\$s\n\n" .
- "You can see the list of %1\$s's favorites here:\n\n" .
+ "The text of your notice is:\n\n" .
"%4\$s\n\n" .
+ "You can see the list of %1\$s's favorites here:\n\n" .
+ "%5\$s\n\n" .
"Faithfully yours,\n" .
- "%5\$s\n"),
+ "%6\$s\n"),
$bestname,
common_exact_date($notice->created),
common_local_url('shownotice',
array('notice' => $notice->id)),
+ $notice->content,
common_local_url('showfavorites',
array('nickname' => $user->nickname)),
common_config('site', 'name'));
diff --git a/lib/messageform.php b/lib/messageform.php
index f41508305..b8878ec1f 100644
--- a/lib/messageform.php
+++ b/lib/messageform.php
@@ -132,20 +132,14 @@ class MessageForm extends Form
$mutual_users->free();
unset($mutual_users);
- $this->out->elementStart('ul', 'form_data');
- $this->out->elementStart('li', array('id' => 'notice_to'));
$this->out->dropdown('to', _('To'), $mutual, null, false,
($this->to) ? $this->to->id : null);
- $this->out->elementEnd('li');
- $this->out->elementStart('li', array('id' => 'notice_text'));
$this->out->element('textarea', array('id' => 'notice_data-text',
'cols' => 35,
'rows' => 4,
'name' => 'content'),
($this->content) ? $this->content : '');
- $this->out->elementEnd('li');
- $this->out->elementEnd('ul');
}
/**
@@ -156,14 +150,10 @@ class MessageForm extends Form
function formActions()
{
- $this->out->elementStart('ul', 'form_actions');
- $this->out->elementStart('li', array('id' => 'notice_submit'));
$this->out->element('input', array('id' => 'notice_action-submit',
'class' => 'submit',
'name' => 'message_send',
'type' => 'submit',
'value' => _('Send')));
- $this->out->elementEnd('li');
- $this->out->elementEnd('ul');
}
}
diff --git a/lib/noticeform.php b/lib/noticeform.php
index 0c991c969..606b5d028 100644
--- a/lib/noticeform.php
+++ b/lib/noticeform.php
@@ -134,9 +134,6 @@ class NoticeForm extends Form
function formData()
{
-
- $this->out->elementStart('ul', 'form_data');
- $this->out->elementStart('li', array('id' => 'notice_text'));
$this->out->element('label', array('for' => 'notice_data-text'),
sprintf(_('What\'s up, %s?'), $this->user->nickname));
// XXX: vary by defined max size
@@ -145,8 +142,6 @@ class NoticeForm extends Form
'rows' => 4,
'name' => 'status_textarea'),
($this->content) ? $this->content : '');
- $this->out->elementEnd('li');
- $this->out->elementEnd('ul');
$this->out->elementStart('dl', 'form_note');
$this->out->element('dt', null, _('Available characters'));
@@ -168,14 +163,10 @@ class NoticeForm extends Form
function formActions()
{
- $this->out->elementStart('ul', 'form_actions');
- $this->out->elementStart('li', array('id' => 'notice_submit'));
$this->out->element('input', array('id' => 'notice_action-submit',
'class' => 'submit',
'name' => 'status_submit',
'type' => 'submit',
'value' => _('Send')));
- $this->out->elementEnd('li');
- $this->out->elementEnd('ul');
}
}
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 9fc0126b3..4182d8808 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -258,8 +258,12 @@ class NoticeListItem extends Widget
function showAuthor()
{
$this->out->elementStart('span', 'vcard author');
- $this->out->elementStart('a', array('href' => $this->profile->profileurl,
- 'class' => 'url'));
+ $attrs = array('href' => $this->profile->profileurl,
+ 'class' => 'url');
+ if (!empty($this->profile->fullname)) {
+ $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ') ';
+ }
+ $this->out->elementStart('a', $attrs);
$this->showAvatar();
$this->showNickname();
$this->out->elementEnd('a');
@@ -387,6 +391,7 @@ class NoticeListItem extends Widget
case 'xmpp':
case 'mail':
case 'omb':
+ case 'system':
case 'api':
$this->out->element('dd', null, $source_name);
break;
diff --git a/lib/noticesection.php b/lib/noticesection.php
index b31f18744..94c2738ef 100644
--- a/lib/noticesection.php
+++ b/lib/noticesection.php
@@ -73,6 +73,11 @@ class NoticeSection extends Section
function showNotice($notice)
{
$profile = $notice->getProfile();
+ if (empty($profile)) {
+ common_log(LOG_WARNING, sprintf("Notice %d has no profile",
+ $notice->id));
+ return;
+ }
$this->out->elementStart('li', 'hentry notice');
$this->out->elementStart('div', 'entry-title');
$avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
diff --git a/lib/oauthstore.php b/lib/oauthstore.php
index 7ad3be20e..183164e17 100644
--- a/lib/oauthstore.php
+++ b/lib/oauthstore.php
@@ -54,16 +54,21 @@ class LaconicaOAuthDataStore extends OAuthDataStore
}
}
+ // http://oauth.net/core/1.0/#nonce
+ // "The Consumer SHALL then generate a Nonce value that is unique for
+ // all requests with that timestamp."
+
+ // XXX: It's not clear why the token is here
+
function lookup_nonce($consumer, $token, $nonce, $timestamp)
{
$n = new Nonce();
$n->consumer_key = $consumer->key;
- $n->tok = $token->key;
+ $n->ts = $timestamp;
$n->nonce = $nonce;
if ($n->find(true)) {
return true;
} else {
- $n->timestamp = $timestamp;
$n->created = DB_DataObject_Cast::dateTime();
$n->insert();
return false;
diff --git a/lib/omb.php b/lib/omb.php
index befcf4666..e8e1acc41 100644
--- a/lib/omb.php
+++ b/lib/omb.php
@@ -251,7 +251,6 @@ function omb_broadcast_profile($profile)
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);
@@ -295,7 +294,7 @@ function omb_update_profile($profile, $remote_profile, $subscription)
common_debug('Got HTTP result "'.print_r($result,true).'"', __FILE__);
- if (empty($result) || $result) {
+ if (empty($result) || !$result) {
common_debug("Unable to contact " . $req->get_normalized_http_url());
} else if ($result->status == 403) { # not authorized, don't send again
common_debug('403 result, deleting subscription', __FILE__);
@@ -306,7 +305,7 @@ function omb_update_profile($profile, $remote_profile, $subscription)
return false;
} else { # success!
parse_str($result->body, $return);
- if ($return['omb_version'] == OMB_VERSION_01) {
+ if (isset($return['omb_version']) && $return['omb_version'] === OMB_VERSION_01) {
return true;
} else {
return false;
diff --git a/lib/openid.php b/lib/openid.php
index 5c3d460da..3af7a39cf 100644
--- a/lib/openid.php
+++ b/lib/openid.php
@@ -160,7 +160,7 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
$auth_request->addExtension($sreg_request);
}
- $trust_root = common_local_url('public');
+ $trust_root = common_root_url(true);
$process_url = common_local_url($returnto);
if ($auth_request->shouldSendRedirect()) {
@@ -171,7 +171,7 @@ function oid_authenticate($openid_url, $returnto, $immediate=false)
} else if (Auth_OpenID::isFailure($redirect_url)) {
return sprintf(_('Could not redirect to server: %s'), $redirect_url->message);
} else {
- common_redirect($redirect_url);
+ common_redirect($redirect_url, 303);
}
} else {
// Generate form markup and render it.
diff --git a/lib/personaltagcloudsection.php b/lib/personaltagcloudsection.php
index 0882822db..978153a84 100644
--- a/lib/personaltagcloudsection.php
+++ b/lib/personaltagcloudsection.php
@@ -58,8 +58,14 @@ class PersonalTagCloudSection extends TagCloudSection
function getTags()
{
- $qry = 'SELECT notice_tag.tag, '.
- 'sum(exp(-(now() - notice_tag.created)/%s)) as weight ' .
+ if (common_config('db', 'type') == 'pgsql') {
+ $weightexpr='sum(exp(-extract(epoch from (now() - notice_tag.created)) / %s))';
+ } else {
+ $weightexpr='sum(exp(-(now() - notice_tag.created) / %s))';
+ }
+
+ $qry = 'SELECT notice_tag.tag, '.
+ $weightexpr . ' as weight ' .
'FROM notice_tag JOIN notice ' .
'ON notice_tag.notice_id = notice.id ' .
'WHERE notice.profile_id = %d ' .
diff --git a/lib/ping.php b/lib/ping.php
new file mode 100644
index 000000000..3de541e9a
--- /dev/null
+++ b/lib/ping.php
@@ -0,0 +1,122 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2009, Control Yourself, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+function ping_broadcast_notice($notice) {
+
+ if (!$notice->is_local) {
+ return true;
+ }
+
+ # Array of servers, URL => type
+ $notify = common_config('ping', 'notify');
+ $profile = $notice->getProfile();
+ $tags = ping_notice_tags($notice);
+
+ foreach ($notify as $notify_url => $type) {
+ switch ($type) {
+ case 'xmlrpc':
+ case 'extended':
+ $req = xmlrpc_encode_request('weblogUpdates.ping',
+ array($profile->nickname, # site name
+ common_local_url('showstream',
+ array('nickname' => $profile->nickname)),
+ common_local_url('shownotice',
+ array('notice' => $notice->id)),
+ common_local_url('userrss',
+ array('nickname' => $profile->nickname)),
+ $tags));
+
+ $context = stream_context_create(array('http' => array('method' => "POST",
+ 'header' =>
+ "Content-Type: text/xml\r\n".
+ "User-Agent: Laconica/".LACONICA_VERSION."\r\n",
+ 'content' => $req)));
+ $file = file_get_contents($notify_url, false, $context);
+
+ if ($file === false || mb_strlen($file) == 0) {
+ common_log(LOG_WARNING,
+ "XML-RPC empty results for ping ($notify_url, $notice->id) ");
+ continue;
+ }
+
+ $response = xmlrpc_decode($file);
+
+ if (xmlrpc_is_fault($response)) {
+ common_log(LOG_WARNING,
+ "XML-RPC error for ping ($notify_url, $notice->id) ".
+ "$response[faultString] ($response[faultCode])");
+ } else {
+ common_log(LOG_INFO,
+ "Ping success for $notify_url $notice->id");
+ }
+ break;
+
+ case 'get':
+ case 'post':
+ $args = array('name' => $profile->nickname,
+ 'url' => common_local_url('showstream',
+ array('nickname' => $profile->nickname)),
+ 'changesURL' => common_local_url('userrss',
+ array('nickname' => $profile->nickname)));
+
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+
+ if ($type === 'get') {
+ $result = $fetcher->get($notify_url . '?' . http_build_query($args),
+ array('User-Agent: Laconica/'.LACONICA_VERSION));
+ } else {
+ $result = $fetcher->post($notify_url,
+ http_build_query($args),
+ array('User-Agent: Laconica/'.LACONICA_VERSION));
+ }
+ if ($result->status != '200') {
+ common_log(LOG_WARNING,
+ "Ping error for '$notify_url' ($notice->id): ".
+ "$result->body");
+ } else {
+ common_log(LOG_INFO,
+ "Ping success for '$notify_url' ($notice->id): ".
+ "'$result->body'");
+ }
+ break;
+
+ default:
+ common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
+ }
+ }
+
+ return true;
+}
+
+function ping_notice_tags($notice) {
+ $tag = new Notice_tag();
+ $tag->notice_id = $notice->id;
+ $tags = array();
+ if ($tag->find()) {
+ while ($tag->fetch()) {
+ $tags[] = $tag->tag;
+ }
+ $tag->free();
+ unset($tag);
+ return implode('|', $tags);
+ }
+ return NULL;
+} \ No newline at end of file
diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php
index c7c7f0215..0505f0fa9 100644
--- a/lib/popularnoticesection.php
+++ b/lib/popularnoticesection.php
@@ -48,10 +48,18 @@ class PopularNoticeSection extends NoticeSection
{
function getNotices()
{
+ if (common_config('db', 'type') == 'pgsql') {
+ $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
+ } else {
+ $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
+ }
+
$qry = 'SELECT notice.*, '.
- 'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
+ $weightexpr . ' as weight ' .
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
- 'GROUP BY fave.notice_id ' .
+ 'GROUP BY notice.id,notice.profile_id,notice.content,notice.uri,' .
+ 'notice.rendered,notice.url,notice.created,notice.modified,' .
+ 'notice.reply_to,notice.is_local,notice.source ' .
'ORDER BY weight DESC';
$offset = 0;
diff --git a/lib/profilelist.php b/lib/profilelist.php
index c2040fbc2..a4cc23555 100644
--- a/lib/profilelist.php
+++ b/lib/profilelist.php
@@ -89,6 +89,7 @@ class ProfileList extends Widget
'id' => 'profile-' . $this->profile->id));
$user = common_current_user();
+ $is_own = !is_null($user) && isset($this->owner) && ($user->id === $this->owner->id);
$this->out->elementStart('div', 'entity_profile vcard');
@@ -102,13 +103,13 @@ class ProfileList extends Widget
'alt' =>
($this->profile->fullname) ? $this->profile->fullname :
$this->profile->nickname));
- $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn nickname';
+ $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
$this->out->elementStart('span', $hasFN);
$this->out->raw($this->highlight($this->profile->nickname));
$this->out->elementEnd('span');
$this->out->elementEnd('a');
- if ($this->profile->fullname) {
+ if (!empty($this->profile->fullname)) {
$this->out->elementStart('dl', 'entity_fn');
$this->out->element('dt', null, 'Full name');
$this->out->elementStart('dd');
@@ -118,7 +119,7 @@ class ProfileList extends Widget
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');
}
- if ($this->profile->location) {
+ if (!empty($this->profile->location)) {
$this->out->elementStart('dl', 'entity_location');
$this->out->element('dt', null, _('Location'));
$this->out->elementStart('dd', 'label');
@@ -126,7 +127,7 @@ class ProfileList extends Widget
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');
}
- if ($this->profile->homepage) {
+ if (!empty($this->profile->homepage)) {
$this->out->elementStart('dl', 'entity_url');
$this->out->element('dt', null, _('URL'));
$this->out->elementStart('dd');
@@ -137,7 +138,7 @@ class ProfileList extends Widget
$this->out->elementEnd('dd');
$this->out->elementEnd('dl');
}
- if ($this->profile->bio) {
+ if (!empty($this->profile->bio)) {
$this->out->elementStart('dl', 'entity_note');
$this->out->element('dt', null, _('Note'));
$this->out->elementStart('dd', 'note');
@@ -154,7 +155,7 @@ class ProfileList extends Widget
$this->out->elementStart('dl', 'entity_tags');
$this->out->elementStart('dt');
- if ($user->id == $this->owner->id) {
+ if ($is_own) {
$this->out->element('a', array('href' => common_local_url('tagother',
array('id' => $this->profile->id))),
_('Tags'));
@@ -183,7 +184,7 @@ class ProfileList extends Widget
$this->out->elementEnd('dl');
}
- if ($user && $user->id == $this->owner->id) {
+ if ($is_own) {
$this->showOwnerControls($this->profile);
}
@@ -193,9 +194,10 @@ class ProfileList extends Widget
$this->out->elementStart('ul');
- if ($user && $user->id != $this->profile->id) {
- # XXX: special-case for user looking at own
- # subscriptions page
+ // Is this a logged-in user, looking at someone else's
+ // profile?
+
+ if (!empty($user) && $this->profile->id != $user->id) {
$this->out->elementStart('li', 'entity_subscribe');
if ($user->isSubscribed($this->profile)) {
$usf = new UnsubscribeForm($this->out, $this->profile);
@@ -206,7 +208,7 @@ class ProfileList extends Widget
}
$this->out->elementEnd('li');
$this->out->elementStart('li', 'entity_block');
- if ($user && $user->id == $this->owner->id) {
+ if ($user->id == $this->owner->id) {
$this->showBlockForm();
}
$this->out->elementEnd('li');
diff --git a/lib/publicgroupnav.php b/lib/publicgroupnav.php
index d72475e20..485d25e20 100644
--- a/lib/publicgroupnav.php
+++ b/lib/publicgroupnav.php
@@ -39,6 +39,7 @@ require_once INSTALLDIR.'/lib/widget.php';
* @category Output
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
+ * @author Sarven Capadisli <csarven@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
@@ -73,23 +74,26 @@ class PublicGroupNav extends Widget
$this->action->elementStart('ul', array('class' => 'nav'));
- $this->out->menuItem(common_local_url('public'), _('Public'),
- _('Public timeline'), $action_name == 'public', 'nav_timeline_public');
+ if (Event::handle('StartPublicGroupNav', array($this))) {
+ $this->out->menuItem(common_local_url('public'), _('Public'),
+ _('Public timeline'), $action_name == 'public', 'nav_timeline_public');
- $this->out->menuItem(common_local_url('groups'), _('Groups'),
- _('User groups'), $action_name == 'groups', 'nav_groups');
+ $this->out->menuItem(common_local_url('groups'), _('Groups'),
+ _('User groups'), $action_name == 'groups', 'nav_groups');
- $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'),
- _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags');
+ $this->out->menuItem(common_local_url('publictagcloud'), _('Recent tags'),
+ _('Recent tags'), $action_name == 'publictagcloud', 'nav_recent-tags');
- if (count(common_config('nickname', 'featured')) > 0) {
- $this->out->menuItem(common_local_url('featured'), _('Featured'),
- _('Featured users'), $action_name == 'featured', 'nav_featured');
- }
+ if (count(common_config('nickname', 'featured')) > 0) {
+ $this->out->menuItem(common_local_url('featured'), _('Featured'),
+ _('Featured users'), $action_name == 'featured', 'nav_featured');
+ }
- $this->out->menuItem(common_local_url('favorited'), _('Popular'),
- _("Popular notices"), $action_name == 'favorited', 'nav_timeline_favorited');
+ $this->out->menuItem(common_local_url('favorited'), _('Popular'),
+ _("Popular notices"), $action_name == 'favorited', 'nav_timeline_favorited');
+ Event::handle('EndPublicGroupNav', array($this));
+ }
$this->action->elementEnd('ul');
}
}
diff --git a/lib/router.php b/lib/router.php
index 4b70c0150..6fb2f9487 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -49,6 +49,9 @@ class Router
{
var $m = null;
static $inst = null;
+ static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
+ 'postnotice', 'updateprofile', 'finishremotesubscribe',
+ 'finishopenidlogin', 'finishaddopenid');
static function get()
{
@@ -65,8 +68,8 @@ class Router
}
}
- function initialize() {
-
+ function initialize()
+ {
$m = Net_URL_Mapper::getInstance();
// In the "root"
@@ -98,12 +101,15 @@ class Router
$main = array('login', 'logout', 'register', 'subscribe',
'unsubscribe', 'confirmaddress', 'recoverpassword',
'invite', 'favor', 'disfavor', 'sup',
- 'block');
+ 'block', 'subedit');
foreach ($main as $a) {
$m->connect('main/'.$a, array('action' => $a));
}
+ $m->connect('main/sup/:seconds', array('action' => 'sup'),
+ array('seconds' => '[0-9]+'));
+
$m->connect('main/tagother/:id', array('action' => 'tagother'));
// these take a code
@@ -118,8 +124,7 @@ class Router
$m->connect('main/remote', array('action' => 'remotesubscribe'));
$m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
- foreach (array('requesttoken', 'accesstoken', 'userauthorization',
- 'postnotice', 'updateprofile', 'finishremotesubscribe') as $action) {
+ foreach (Router::$bare as $action) {
$m->connect('index.php?action=' . $action, array('action' => $action));
}
@@ -134,10 +139,17 @@ class Router
foreach (array('group', 'people', 'notice') as $s) {
$m->connect('search/'.$s, array('action' => $s.'search'));
- $m->connect('search/'.$s.'?q=:q', array('action' => $s.'search'), array('q' => '.+'));
+ $m->connect('search/'.$s.'?q=:q',
+ array('action' => $s.'search'),
+ array('q' => '.+'));
}
+ // The second of these is needed to make the link work correctly
+ // when inserted into the page. The first is needed to match the
+ // route on the way in. Seems to be another Net_URL_Mapper bug to me.
$m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
+ $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
+ array('q' => '.+'));
// notice
@@ -154,7 +166,7 @@ class Router
array('notice' => '[0-9]+'));
$m->connect('message/new', array('action' => 'newmessage'));
- $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]'));
+ $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
$m->connect('message/:message',
array('action' => 'showmessage'),
array('message' => '[0-9]+'));
@@ -224,18 +236,19 @@ class Router
$m->connect('api/statuses/:method/:argument',
array('action' => 'api',
'apiaction' => 'statuses'),
- array('method' => '(user_timeline|friends_timeline|show|destroy|friends|followers)'));
+ array('method' => '(user_timeline|friends_timeline|replies|show|destroy|friends|followers)'));
// users
- $m->connect('api/users/show/:argument',
+ $m->connect('api/users/:method/:argument',
array('action' => 'api',
- 'apiaction' => 'users'));
+ 'apiaction' => 'users'),
+ array('method' => 'show(\.(xml|json))?'));
$m->connect('api/users/:method',
array('action' => 'api',
'apiaction' => 'users'),
- array('method' => 'show(\.(xml|json|atom|rss))?'));
+ array('method' => 'show(\.(xml|json))?'));
// direct messages
@@ -254,10 +267,10 @@ class Router
}
foreach (array('xml', 'json', 'rss', 'atom') as $e) {
- $m->connect('api/direct_message/sent.'.$e,
+ $m->connect('api/direct_messages/sent.'.$e,
array('action' => 'api',
- 'apiaction' => 'direct_messages',
- 'method' => 'sent.'.$e));
+ 'apiaction' => 'direct_messages',
+ 'method' => 'sent.'.$e));
}
$m->connect('api/direct_messages/destroy/:argument',
@@ -274,8 +287,7 @@ class Router
$m->connect('api/friendships/:method',
array('action' => 'api',
'apiaction' => 'friendships'),
- array('method' => 'exists(\.(xml|json|rss|atom))'));
-
+ array('method' => 'exists(\.(xml|json))'));
// Social graph
@@ -283,14 +295,14 @@ class Router
array('action' => 'api',
'apiaction' => 'statuses',
'method' => 'friendsIDs'));
-
+
foreach (array('xml', 'json') as $e) {
$m->connect('api/friends/ids.'.$e,
array('action' => 'api',
'apiaction' => 'statuses',
'method' => 'friendsIDs.'.$e));
}
-
+
$m->connect('api/followers/ids/:argument',
array('action' => 'api',
'apiaction' => 'statuses',
@@ -322,9 +334,9 @@ class Router
foreach (array('xml', 'json', 'rss', 'atom') as $e) {
$m->connect('api/favorites.'.$e,
- array('action' => 'api',
- 'apiaction' => 'favorites',
- 'method' => 'favorites.'.$e));
+ array('action' => 'api',
+ 'apiaction' => 'favorites',
+ 'method' => 'favorites.'.$e));
}
// notifications
@@ -351,6 +363,11 @@ class Router
array('action' => 'api',
'apiaction' => 'laconica'));
+ // search
+ $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
+ $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
+ $m->connect('api/trends.json', array('action' => 'twitapitrends'));
+
// user stuff
foreach (array('subscriptions', 'subscribers',
@@ -393,6 +410,8 @@ class Router
array('action' => 'showstream'),
array('nickname' => '[a-zA-Z0-9]{1,64}'));
+ Event::handle('RouterInitialized', array($m));
+
return $m;
}
@@ -402,7 +421,7 @@ class Router
$match = $this->m->match($path);
} catch (Net_URL_Mapper_InvalidException $e) {
common_log(LOG_ERR, "Problem getting route for $path - " .
- $e->getMessage());
+ $e->getMessage());
$cac = new ClientErrorAction("Page not found.", 404);
$cac->showPage();
}
@@ -420,6 +439,17 @@ class Router
$args = $action_arg;
}
- return $this->m->generate($args, $params, $fragment);
+ $url = $this->m->generate($args, $params, $fragment);
+
+ // Due to a bug in the Net_URL_Mapper code, the returned URL may
+ // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
+ // repair that here rather than modifying the upstream code...
+
+ $qpos = strpos($url, '?');
+ if ($qpos !== false) {
+ $url = substr($url, 0, $qpos+1) .
+ str_replace('?', '&', substr($url, $qpos+1));
+ }
+ return $url;
}
}
diff --git a/lib/rssaction.php b/lib/rssaction.php
index 66c2d9e8c..ddba862dc 100644
--- a/lib/rssaction.php
+++ b/lib/rssaction.php
@@ -94,11 +94,11 @@ class Rss10Action extends Action
function handle($args)
{
- // Get the list of notices
- $this->notices = $this->getNotices();
// Parent handling, including cache check
parent::handle($args);
- $this->showRss($this->limit);
+ // Get the list of notices
+ $this->notices = $this->getNotices($this->limit);
+ $this->showRss();
}
/**
@@ -132,15 +132,13 @@ class Rss10Action extends Action
return null;
}
- function showRss($limit=0)
+ function showRss()
{
- $notices = $this->getNotices($limit);
-
$this->initRss();
- $this->showChannel($notices);
+ $this->showChannel();
$this->showImage();
- foreach ($notices as $n) {
+ foreach ($this->notices as $n) {
$this->showItem($n);
}
@@ -148,7 +146,7 @@ class Rss10Action extends Action
$this->endRss();
}
- function showChannel($notices)
+ function showChannel()
{
$channel = $this->getChannel();
@@ -167,7 +165,7 @@ class Rss10Action extends Action
$this->elementStart('items');
$this->elementStart('rdf:Seq');
- foreach ($notices as $notice) {
+ foreach ($this->notices as $notice) {
$this->element('sioct:MicroblogPost', array('rdf:resource' => $notice->uri));
}
diff --git a/lib/search_engines.php b/lib/search_engines.php
index 559107910..7b9dbb618 100644
--- a/lib/search_engines.php
+++ b/lib/search_engines.php
@@ -74,7 +74,7 @@ class SphinxSearch extends SearchEngine
{
//FIXME without LARGEST_POSSIBLE, the most recent results aren't returned
// this probably has a large impact on performance
- $LARGEST_POSSIBLE = 1e6;
+ $LARGEST_POSSIBLE = 1e6;
if ($rss) {
$this->sphinx->setLimits($offset, $count, $count, $LARGEST_POSSIBLE);
@@ -109,12 +109,25 @@ 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).'\')');
- if ('identica_notices' === $this->table)
- return $this->target->whereAdd('MATCH(content) ' .
- 'against (\''.addslashes($q).'\')');
+ if ('identica_people' === $this->table) {
+ $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
+ 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)');
+ if (strtolower($q) != $q) {
+ $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
+ 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR');
+ }
+ return true;
+ } else if ('identica_notices' === $this->table) {
+ $this->target->whereAdd('MATCH(content) ' .
+ 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)');
+ if (strtolower($q) != $q) {
+ $this->target->whereAdd('MATCH(content) ' .
+ 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR');
+ }
+ return true;
+ } else {
+ throw new ServerException('Unknown table: ' . $this->table);
+ }
}
}
@@ -122,10 +135,13 @@ class PGSearch extends SearchEngine
{
function query($q)
{
- if ('identica_people' === $this->table)
+ if ('identica_people' === $this->table) {
return $this->target->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')');
- if ('identica_notices' === $this->table)
+ } else if ('identica_notices' === $this->table) {
return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')');
+ } else {
+ throw new ServerException('Unknown table: ' . $this->table);
+ }
}
}
diff --git a/lib/searchaction.php b/lib/searchaction.php
index df6876445..c762db16f 100644
--- a/lib/searchaction.php
+++ b/lib/searchaction.php
@@ -110,8 +110,6 @@ class SearchAction extends Action
function showForm($error=null)
{
- global $config;
-
$q = $this->trimmed('q');
$page = $this->trimmed('page', 1);
$this->elementStart('form', array('method' => 'get',
@@ -122,7 +120,7 @@ class SearchAction extends Action
$this->element('legend', null, _('Search site'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
- if (!isset($config['site']['fancy']) || !$config['site']['fancy']) {
+ if (!common_config('site', 'fancy')) {
$this->hidden('action', $this->trimmed('action'));
}
$this->input('q', 'Keyword(s)', $q);
diff --git a/lib/servererroraction.php b/lib/servererroraction.php
index 80a3fdd7b..595dcf147 100644
--- a/lib/servererroraction.php
+++ b/lib/servererroraction.php
@@ -42,7 +42,7 @@ require_once INSTALLDIR.'/lib/error.php';
* says that 500 errors should be treated similarly to 400 errors, and
* it's easier to give an HTML response. Maybe we can customize these
* to display some funny animal cartoons. If not, we can probably role
- * these classes up into a single class.
+ * these classes up into a single class.
*
* See: http://tools.ietf.org/html/rfc2616#section-10
*
@@ -57,19 +57,19 @@ class ServerErrorAction extends ErrorAction
function __construct($message='Error', $code=500)
{
parent::__construct($message, $code);
-
+
$this->status = array(500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported');
-
+
$this->default = 500;
}
// XXX: Should these error actions even be invokable via URI?
-
+
function handle($args)
{
parent::handle($args);
@@ -81,12 +81,16 @@ class ServerErrorAction extends ErrorAction
}
$this->message = $this->trimmed('message');
-
+
if (!$this->message) {
- $this->message = "Server Error $this->code";
- }
+ $this->message = "Server Error $this->code";
+ }
$this->showPage();
}
-
+
+ function title()
+ {
+ return $this->status[$this->code];
+ }
}
diff --git a/lib/settingsaction.php b/lib/settingsaction.php
index 53c807c6f..db20c5804 100644
--- a/lib/settingsaction.php
+++ b/lib/settingsaction.php
@@ -78,9 +78,9 @@ class SettingsAction extends Action
common_set_returnto($this->selfUrl());
$user = common_current_user();
if ($user->hasOpenID()) {
- common_redirect(common_local_url('openidlogin'));
+ common_redirect(common_local_url('openidlogin'), 303);
} else {
- common_redirect(common_local_url('login'));
+ common_redirect(common_local_url('login'), 303);
}
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
diff --git a/lib/subgroupnav.php b/lib/subgroupnav.php
index 5fd8a72a2..31c3ea0b5 100644
--- a/lib/subgroupnav.php
+++ b/lib/subgroupnav.php
@@ -98,7 +98,7 @@ class SubGroupNav extends Widget
$this->user->nickname),
$action == 'usergroups',
'nav_usergroups');
- if ($this->user->id == $cur->id) {
+ if (!is_null($cur) && $this->user->id === $cur->id) {
$this->out->menuItem(common_local_url('invite'),
_('Invite'),
sprintf(_('Invite friends and colleagues to join you on %s'),
diff --git a/lib/topposterssection.php b/lib/topposterssection.php
index 4bd59ac79..1a2ce0014 100644
--- a/lib/topposterssection.php
+++ b/lib/topposterssection.php
@@ -51,7 +51,7 @@ class TopPostersSection extends ProfileSection
$qry = 'SELECT profile.*, count(*) as value ' .
'FROM profile JOIN notice ON profile.id = notice.profile_id ' .
(common_config('public', 'localonly') ? 'WHERE is_local = 1 ' : '') .
- 'GROUP BY profile.id ' .
+ 'GROUP BY profile.id,nickname,fullname,profileurl,homepage,bio,location,profile.created,profile.modified,textsearch ' .
'ORDER BY value DESC ';
$limit = PROFILES_PER_SECTION;
diff --git a/lib/twitter.php b/lib/twitter.php
index deb6fd276..7abb40151 100644
--- a/lib/twitter.php
+++ b/lib/twitter.php
@@ -210,7 +210,7 @@ function save_twitter_friends($user, $twitter_id, $screen_name, $password)
function is_twitter_bound($notice, $flink) {
// Check to see if notice should go to Twitter
- if (($flink->noticesync & FOREIGN_NOTICE_SEND)) {
+ if ($flink->noticesync & FOREIGN_NOTICE_SEND) {
// If it's not a Twitter-style reply, or if the user WANTS to send replies.
if (!preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) ||
@@ -224,7 +224,6 @@ function is_twitter_bound($notice, $flink) {
function broadcast_twitter($notice)
{
- global $config;
$success = true;
$flink = Foreign_link::getByUserID($notice->profile_id,
@@ -232,7 +231,7 @@ function broadcast_twitter($notice)
// XXX: Not sure WHERE to check whether a notice should go to
// Twitter. Should we even put in the queue if it shouldn't? --Zach
- if (is_twitter_bound($notice, $flink)) {
+ if (!is_null($flink) && is_twitter_bound($notice, $flink)) {
$fuser = $flink->getForeignUser();
$twitter_user = $fuser->nickname;
@@ -248,7 +247,7 @@ function broadcast_twitter($notice)
CURLOPT_POSTFIELDS =>
array(
'status' => $statustxt,
- 'source' => $config['integration']['source']
+ 'source' => common_config('integration', 'source')
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FAILONERROR => true,
diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index a4d183fcd..b8357c688 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -24,11 +24,33 @@ class TwitterapiAction extends Action
var $auth_user;
+ /**
+ * Initialization.
+ *
+ * @param array $args Web and URL arguments
+ *
+ * @return boolean false if user doesn't exist
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+ return true;
+ }
+
+ /**
+ * Handle a request
+ *
+ * @param array $args Arguments from $_REQUEST
+ *
+ * @return void
+ */
+
function handle($args)
{
parent::handle($args);
}
-
+
function twitter_user_array($profile, $get_notice=false)
{
@@ -60,20 +82,34 @@ class TwitterapiAction extends Action
function twitter_status_array($notice, $include_user=true)
{
-
$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['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;
+
+ $replier_profile = null;
+
+ if ($notice->reply_to) {
+ $reply = Notice::staticGet(intval($notice->reply_to));
+ if ($reply) {
+ $replier_profile = $reply->getProfile();
+ }
+ }
+
+ $twitter_status['in_reply_to_user_id'] =
+ ($replier_profile) ? intval($replier_profile->id) : null;
+ $twitter_status['in_reply_to_screen_name'] =
+ ($replier_profile) ? $replier_profile->nickname : null;
if (isset($this->auth_user)) {
- $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
+ $twitter_status['favorited'] =
+ ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
} else {
$twitter_status['favorited'] = 'false';
}
@@ -91,8 +127,6 @@ class TwitterapiAction extends Action
{
$profile = $notice->getProfile();
-
- $server = common_config('site', 'server');
$entry = array();
# We trim() to avoid extraneous whitespace in the output
@@ -101,8 +135,12 @@ class TwitterapiAction extends Action
$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]";
+
+ $taguribase = common_config('integration', 'taguri');
+ $entry['id'] = "tag:$taguribase:$entry[link]";
+
$entry['updated'] = $entry['published'];
+ $entry['author'] = $profile->getBestName();
# RSS Item specific
$entry['description'] = $entry['content'];
@@ -115,7 +153,6 @@ class TwitterapiAction extends Action
function twitter_rss_dmsg_array($message)
{
- $server = common_config('site', 'server');
$entry = array();
$entry['title'] = sprintf('Message from %s to %s',
@@ -124,8 +161,12 @@ class TwitterapiAction extends Action
$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]";
+
+ $taguribase = common_config('integration', 'taguri');
+
+ $entry['id'] = "tag:$taguribase,:$entry[link]";
$entry['updated'] = $entry['published'];
+ $entry['author'] = $message->getFrom()->getBestName();
# RSS Item specific
$entry['description'] = $entry['content'];
@@ -137,7 +178,6 @@ class TwitterapiAction extends Action
function twitter_dmsg_array($message)
{
-
$twitter_dm = array();
$from_profile = $message->getFrom();
@@ -198,18 +238,6 @@ class TwitterapiAction extends Action
$this->elementEnd('item');
}
- function show_twitter_atom_entry($entry)
- {
- $this->elementStart('entry');
- $this->element('title', null, $entry['title']);
- $this->element('content', array('type' => 'html'), $entry['content']);
- $this->element('id', null, $entry['id']);
- $this->element('published', null, $entry['published']);
- $this->element('updated', null, $entry['updated']);
- $this->element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), null);
- $this->elementEnd('entry');
- }
-
function show_json_objects($objects)
{
print(json_encode($objects));
@@ -323,7 +351,7 @@ class TwitterapiAction extends Action
$this->end_twitter_rss();
}
- function show_atom_timeline($notice, $title, $id, $link, $subtitle=null, $suplink=null)
+ function show_atom_timeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null)
{
$this->init_document('atom');
@@ -331,23 +359,29 @@ class TwitterapiAction extends Action
$this->element('title', null, $title);
$this->element('id', null, $id);
$this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null);
+
if (!is_null($suplink)) {
# For FriendFeed's SUP protocol
$this->element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup',
'href' => $suplink,
'type' => 'application/json'));
}
+
+ if (!is_null($selfuri)) {
+ $this->element('link', array('href' => $selfuri,
+ 'rel' => 'self', 'type' => 'application/atom+xml'), null);
+ }
+
+ $this->element('updated', null, common_date_iso8601('now'));
$this->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);
+ $this->raw($n->asAtomEntry());
}
} else {
while ($notice->fetch()) {
- $entry = $this->twitter_rss_entry_array($notice);
- $this->show_twitter_atom_entry($entry);
+ $this->raw($notice->asAtomEntry());
}
}
@@ -387,22 +421,6 @@ class TwitterapiAction extends Action
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)
{
@@ -543,13 +561,16 @@ class TwitterapiAction extends Action
function init_twitter_atom()
{
$this->startXML();
- $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US'));
+ // FIXME: don't hardcode the language here!
+ $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom',
+ 'xml:lang' => 'en-US',
+ 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0'));
}
function end_twitter_atom()
{
- $this->endXML();
$this->elementEnd('feed');
+ $this->endXML();
}
function show_profile($profile, $content_type='xml', $notice=null)
@@ -615,79 +636,4 @@ class TwitterapiAction extends Action
return $source_name;
}
- function show_extended_profile($user, $apidata)
- {
-
- $this->auth_user = $apidata['user'];
-
- $profile = $user->getProfile();
-
- if (!$profile) {
- common_server_error(_('User has no profile.'));
- return;
- }
-
- $twitter_user = $this->twitter_user_array($profile, true);
-
- // Add in extended user fields offered up by this method
- $twitter_user['created_at'] = $this->date_twitter($profile->created);
-
- $subbed = DB_DataObject::factory('subscription');
- $subbed->subscriber = $profile->id;
- $subbed_count = (int) $subbed->count() - 1;
-
- $notices = DB_DataObject::factory('notice');
- $notices->profile_id = $profile->id;
- $notice_count = (int) $notices->count();
-
- $twitter_user['friends_count'] = (is_int($subbed_count)) ? $subbed_count : 0;
- $twitter_user['statuses_count'] = (is_int($notice_count)) ? $notice_count : 0;
-
- // Other fields Twitter sends...
- $twitter_user['profile_background_color'] = '';
- $twitter_user['profile_text_color'] = '';
- $twitter_user['profile_link_color'] = '';
- $twitter_user['profile_sidebar_fill_color'] = '';
-
- $faves = DB_DataObject::factory('fave');
- $faves->user_id = $user->id;
- $faves_count = (int) $faves->count();
- $twitter_user['favourites_count'] = $faves_count;
-
- $timezone = 'UTC';
-
- if ($user->timezone) {
- $timezone = $user->timezone;
- }
-
- $t = new DateTime;
- $t->setTimezone(new DateTimeZone($timezone));
- $twitter_user['utc_offset'] = $t->format('Z');
- $twitter_user['time_zone'] = $timezone;
-
- $following = 'false';
-
- if (isset($this->auth_user)) {
- if ($this->auth_user->isSubscribed($profile)) {
- $following = 'true';
- }
-
- // Not implemented yet
- $twitter_user['notifications'] = 'false';
- }
-
- $twitter_user['following'] = $following;
-
- if ($apidata['content-type'] == 'xml') {
- $this->init_document('xml');
- $this->show_twitter_xml_user($twitter_user);
- $this->end_document('xml');
- } elseif ($apidata['content-type'] == 'json') {
- $this->init_document('json');
- $this->show_json_objects($twitter_user);
- $this->end_document('json');
- }
-
- }
-
}
diff --git a/lib/util.php b/lib/util.php
index 18e4f310c..b17a44bd8 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -72,8 +72,7 @@ function common_timezone()
}
}
- global $config;
- return $config['site']['timezone'];
+ return common_config('site', 'timezone');
}
function common_language()
@@ -81,7 +80,7 @@ function common_language()
// If there is a user logged in and they've set a language preference
// then return that one...
- if (common_logged_in()) {
+ if (_have_config() && common_logged_in()) {
$user = common_current_user();
$user_language = $user->language;
if ($user_language)
@@ -315,6 +314,10 @@ function common_current_user()
{
global $_cur;
+ if (!_have_config()) {
+ return null;
+ }
+
if ($_cur === false) {
if (isset($_REQUEST[session_name()]) || (isset($_SESSION['userid']) && $_SESSION['userid'])) {
@@ -463,7 +466,7 @@ function common_replace_urls_callback($text, $callback) {
$url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url);
// Call user specified func
- $modified_url = $callback($url);
+ $modified_url = call_user_func($callback, $url);
// Replace it!
$start = mb_strpos($text, $url, $offset);
@@ -477,18 +480,12 @@ function common_replace_urls_callback($text, $callback) {
function common_linkify($url) {
// It comes in special'd, so we unspecial it before passing to the stringifying
// functions
- $ext = pathinfo($url, PATHINFO_EXTENSION);
$url = htmlspecialchars_decode($url);
- $video_ext = array('mp4', 'flv', 'avi', 'mpg', 'mp3', 'ogg');
$display = $url;
$url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url : $url;
$attrs = array('href' => $url, 'rel' => 'external');
- if (in_array($ext, $video_ext)) {
- $attrs['class'] = 'media';
- }
-
if ($longurl = common_longurl($url)) {
$attrs['title'] = $longurl;
}
@@ -584,10 +581,8 @@ function common_shorten_link($url, $reverse = false)
function common_xml_safe_str($str)
{
- $xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8');
-
- // Replace control, formatting, and surrogate characters with '*', ala Twitter
- return preg_replace('/[\p{Cc}\p{Cf}\p{Cs}]/u', '*', $str);
+ // Neutralize control codes and surrogates
+ return preg_replace('/[\p{Cc}\p{Cs}]/u', '*', $str);
}
function common_tag_link($tag)
@@ -618,10 +613,20 @@ function common_at_link($sender_id, $nickname)
$sender = Profile::staticGet($sender_id);
$recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
if ($recipient) {
+ $user = User::staticGet('id', $recipient->id);
+ if ($user) {
+ $url = common_local_url('userbyid', array('id' => $user->id));
+ } else {
+ $url = $recipient->profileurl;
+ }
$xs = new XMLStringer(false);
+ $attrs = array('href' => $url,
+ 'class' => 'url');
+ if (!empty($recipient->fullname)) {
+ $attrs['title'] = $recipient->fullname . ' (' . $recipient->nickname . ')';
+ }
$xs->elementStart('span', 'vcard');
- $xs->elementStart('a', array('href' => $recipient->profileurl,
- 'class' => 'url'));
+ $xs->elementStart('a', $attrs);
$xs->element('span', 'fn nickname', $nickname);
$xs->elementEnd('a');
$xs->elementEnd('span');
@@ -636,10 +641,14 @@ function common_group_link($sender_id, $nickname)
$sender = Profile::staticGet($sender_id);
$group = User_group::staticGet('nickname', common_canonical_nickname($nickname));
if ($group && $sender->isMember($group)) {
+ $attrs = array('href' => $group->permalink(),
+ 'class' => 'url');
+ if (!empty($group->fullname)) {
+ $attrs['title'] = $group->fullname . ' (' . $group->nickname . ')';
+ }
$xs = new XMLStringer();
$xs->elementStart('span', 'vcard');
- $xs->elementStart('a', array('href' => $group->permalink(),
- 'class' => 'url'));
+ $xs->elementStart('a', $attrs);
$xs->element('span', 'fn nickname', $nickname);
$xs->elementEnd('a');
$xs->elementEnd('span');
@@ -678,7 +687,7 @@ function common_relative_profile($sender, $nickname, $dt=null)
$recipient = new Profile();
// XXX: use a join instead of a subquery
$recipient->whereAdd('EXISTS (SELECT subscribed from subscription where subscriber = '.$sender->id.' and subscribed = id)', 'AND');
- $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
+ $recipient->whereAdd("nickname = '" . trim($nickname) . "'", 'AND');
if ($recipient->find(true)) {
// XXX: should probably differentiate between profiles with
// the same name by date of most recent update
@@ -688,7 +697,7 @@ function common_relative_profile($sender, $nickname, $dt=null)
$recipient = new Profile();
// XXX: use a join instead of a subquery
$recipient->whereAdd('EXISTS (SELECT subscriber from subscription where subscribed = '.$sender->id.' and subscriber = id)', 'AND');
- $recipient->whereAdd('nickname = "' . trim($nickname) . '"', 'AND');
+ $recipient->whereAdd("nickname = '" . trim($nickname) . "'", 'AND');
if ($recipient->find(true)) {
// XXX: should probably differentiate between profiles with
// the same name by date of most recent update
@@ -710,23 +719,46 @@ function common_relative_profile($sender, $nickname, $dt=null)
function common_local_url($action, $args=null, $params=null, $fragment=null)
{
+ static $sensitive = array('login', 'register', 'passwordsettings',
+ 'twittersettings', 'finishopenidlogin',
+ 'finishaddopenid', 'api');
+
$r = Router::get();
$path = $r->build($action, $args, $params, $fragment);
- if ($path) {
- }
+
+ $ssl = in_array($action, $sensitive);
+
if (common_config('site','fancy')) {
- $url = common_path(mb_substr($path, 1));
+ $url = common_path(mb_substr($path, 1), $ssl);
} else {
- $url = common_path('index.php'.$path);
+ if (mb_strpos($path, '/index.php') === 0) {
+ $url = common_path(mb_substr($path, 1), $ssl);
+ } else {
+ $url = common_path('index.php'.$path, $ssl);
+ }
}
return $url;
}
-function common_path($relative)
+function common_path($relative, $ssl=false)
{
- global $config;
- $pathpart = ($config['site']['path']) ? $config['site']['path']."/" : '';
- return "http://".$config['site']['server'].'/'.$pathpart.$relative;
+ $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
+
+ if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
+ || common_config('site', 'ssl') === 'always') {
+ $proto = 'https';
+ if (is_string(common_config('site', 'sslserver')) &&
+ mb_strlen(common_config('site', 'sslserver')) > 0) {
+ $serverpart = common_config('site', 'sslserver');
+ } else {
+ $serverpart = common_config('site', 'server');
+ }
+ } else {
+ $proto = 'http';
+ $serverpart = common_config('site', 'server');
+ }
+
+ return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
}
function common_date_string($dt)
@@ -816,7 +848,7 @@ function common_redirect($url, $code=307)
303 => "See Other",
307 => "Temporary Redirect");
- header("Status: ${code} $status[$code]");
+ header('HTTP/1.1 '.$code.' '.$status[$code]);
header("Location: $url");
$xo = new XMLOutputter();
@@ -842,7 +874,7 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice)
{
- foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook') as $transport) {
+ foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;
@@ -918,9 +950,9 @@ function common_profile_url($nickname)
// Should make up a reasonable root URL
-function common_root_url()
+function common_root_url($ssl=false)
{
- return common_path('');
+ return common_path('', $ssl);
}
// returns $bytes bytes of random data as a hexadecimal string
@@ -979,8 +1011,7 @@ function common_ensure_syslog()
{
static $initialized = false;
if (!$initialized) {
- global $config;
- openlog($config['syslog']['appname'], 0, LOG_USER);
+ openlog(common_config('syslog', 'appname'), 0, LOG_USER);
$initialized = true;
}
}