summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarven Capadisli <csarven@controlyourself.ca>2009-02-12 18:30:10 +0000
committerSarven Capadisli <csarven@controlyourself.ca>2009-02-12 18:30:10 +0000
commit033503dc84c5a31408345f61cd6c8ca79239e25b (patch)
tree7679efb9ccbdde739f29b1d8f7bb050956df5020
parent3c8c0572efef97c25037545e1e971f0ce3cd7cc8 (diff)
parentab8d27b8d1e25bd1058b904d03fedf97148f4b89 (diff)
Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x
-rw-r--r--actions/emailsettings.php22
-rw-r--r--actions/register.php23
-rw-r--r--index.php4
-rw-r--r--lib/action.php31
-rw-r--r--lib/channel.php (renamed from classes/Channel.php)1
-rw-r--r--lib/command.php (renamed from classes/Command.php)74
-rw-r--r--lib/commandinterpreter.php (renamed from classes/CommandInterpreter.php)3
-rw-r--r--lib/htmloutputter.php5
-rw-r--r--lib/util.php75
-rw-r--r--lib/xmlstringer.php68
10 files changed, 239 insertions, 67 deletions
diff --git a/actions/emailsettings.php b/actions/emailsettings.php
index b84acb214..0a86aa66d 100644
--- a/actions/emailsettings.php
+++ b/actions/emailsettings.php
@@ -487,4 +487,26 @@ class EmailsettingsAction extends AccountSettingsAction
return $other->id != $user->id;
}
}
+
+ /**
+ * Handle old fashioned PEAR_Error msgs coming from DB_DataObject
+ *
+ * In this case email don't exist in the DB yet, so DB_DataObject
+ * throws an error. Overrided from Action.
+ *
+ * @param PEAR_Error
+ *
+ * @return nothing
+ */
+
+ function handleError($error) {
+ if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
+
+ // Do nothing.
+
+ } else {
+ parent::handleError($error);
+ }
+ }
+
}
diff --git a/actions/register.php b/actions/register.php
index 5d7a8ce69..aafb54ebb 100644
--- a/actions/register.php
+++ b/actions/register.php
@@ -223,10 +223,31 @@ class RegisterAction extends Action
*/
function nicknameExists($nickname)
- {
+ {
$user = User::staticGet('nickname', $nickname);
return ($user !== false);
}
+
+ /**
+ * Handle old fashioned PEAR_Error msgs coming from DB_DataObject
+ *
+ * In this case nickname and email don't exist in the DB yet,
+ * so DB_DataObject throws an error. Overrided from Action.
+ *
+ * @param PEAR_Error
+ *
+ * @return nothing
+ */
+
+ function handleError($error) {
+ if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
+
+ // Do nothing.
+
+ } else {
+ parent::handleError($error);
+ }
+ }
/**
* Does the given email address already exist?
diff --git a/index.php b/index.php
index 4db0e7555..b180e2b65 100644
--- a/index.php
+++ b/index.php
@@ -38,6 +38,10 @@ function getPath($req)
function handleError($error)
{
+ if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
+ return;
+ }
+
common_log(LOG_ERR, "PEAR error: " . $error->getMessage());
$msg = sprintf(_('The database for %s isn\'t responding correctly, '.
'so the site won\'t work properly. '.
diff --git a/lib/action.php b/lib/action.php
index bd38bf79c..926fe93fb 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -82,6 +82,11 @@ class Action extends HTMLOutputter // lawsuit
*/
function prepare($argarray)
{
+
+ // For PEAR_Errors comming from DB_DataObject
+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK,
+ array($this, "handleError"));
+
$this->args =& common_copy_args($argarray);
return true;
}
@@ -845,6 +850,32 @@ class Action extends HTMLOutputter // lawsuit
}
/**
+ * Handle old fashioned PEAR_Error msgs coming from DB_DataObject
+ *
+ * Logs the DB_DataObject error. Override to do something else.
+ *
+ * @param PEAR_Error
+ *
+ * @return nothing
+ */
+
+ function handleError($error) {
+
+ common_log(LOG_ERR, "PEAR error: " . $error->getMessage());
+ $msg = sprintf(_('The database for %s isn\'t responding correctly, '.
+ 'so the site won\'t work properly. '.
+ 'The site admins probably know about the problem, '.
+ 'but you can contact them at %s to make sure. '.
+ 'Otherwise, wait a few minutes and try again.'),
+ common_config('site', 'name'),
+ common_config('site', 'email'));
+
+ $dac = new DBErrorAction($msg, 500);
+ $dac->showPage();
+ exit(-1);
+ }
+
+ /**
* Returns the current URL
*
* @return string current URL
diff --git a/classes/Channel.php b/lib/channel.php
index fdeff21fc..f1e205546 100644
--- a/classes/Channel.php
+++ b/lib/channel.php
@@ -21,7 +21,6 @@ if (!defined('LACONICA')) { exit(1); }
class Channel
{
-
function on($user)
{
return false;
diff --git a/classes/Command.php b/lib/command.php
index eacbdacb3..507990a0b 100644
--- a/classes/Command.php
+++ b/lib/command.php
@@ -19,18 +19,18 @@
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/classes/Channel.php');
+require_once(INSTALLDIR.'/lib/channel.php');
class Command
{
-
+
var $user = null;
-
+
function __construct($user=null)
{
$this->user = $user;
}
-
+
function execute($channel)
{
return false;
@@ -109,7 +109,7 @@ class StatsCommand extends Command
$notices = new Notice();
$notices->profile_id = $this->user->id;
$notice_count = (int) $notices->count();
-
+
$channel->output($this->user, sprintf(_("Subscriptions: %1\$s\n".
"Subscribers: %2\$s\n".
"Notices: %3\$s"),
@@ -121,21 +121,21 @@ class StatsCommand extends Command
class FavCommand extends Command
{
-
+
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
-
- $recipient =
+
+ $recipient =
common_relative_profile($this->user, common_canonical_nickname($this->other));
-
+
if (!$recipient) {
$channel->error($this->user, _('No such user.'));
return;
@@ -145,7 +145,7 @@ class FavCommand extends Command
$channel->error($this->user, _('User has no last notice'));
return;
}
-
+
$fave = Fave::addNew($this->user, $notice);
if (!$fave) {
@@ -154,15 +154,15 @@ class FavCommand extends Command
}
$other = User::staticGet('id', $recipient->id);
-
+
if ($other && $other->id != $user->id) {
if ($other->email && $other->emailnotifyfav) {
mail_notify_fave($other, $this->user, $notice);
}
}
-
+
$this->user->blowFavesCache();
-
+
$channel->output($this->user, _('Notice marked as fave.'));
}
}
@@ -175,17 +175,17 @@ class WhoisCommand extends Command
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
- $recipient =
+ $recipient =
common_relative_profile($this->user, common_canonical_nickname($this->other));
-
+
if (!$recipient) {
$channel->error($this->user, _('No such user.'));
return;
}
-
+
$whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname,
$recipient->profileurl);
if ($recipient->fullname) {
@@ -214,7 +214,7 @@ class MessageCommand extends Command
$this->other = $other;
$this->text = $text;
}
-
+
function execute($channel)
{
$other = User::staticGet('nickname', common_canonical_nickname($this->other));
@@ -229,7 +229,7 @@ class MessageCommand extends Command
return;
}
}
-
+
if (!$other) {
$channel->error($this->user, _('No such user.'));
return;
@@ -251,19 +251,19 @@ class MessageCommand extends Command
class GetCommand extends Command
{
-
+
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
$target_nickname = common_canonical_nickname($this->other);
-
+
$target =
common_relative_profile($this->user, $target_nickname);
@@ -277,32 +277,32 @@ class GetCommand extends Command
return;
}
$notice_content = $notice->content;
-
+
$channel->output($this->user, $target_nickname . ": " . $notice_content);
}
}
class SubCommand extends Command
{
-
+
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
-
+
if (!$this->other) {
$channel->error($this->user, _('Specify the name of the user to subscribe to'));
return;
}
-
+
$result = subs_subscribe_user($this->user, $this->other);
-
+
if ($result == 'true') {
$channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other));
} else {
@@ -315,7 +315,7 @@ class UnsubCommand extends Command
{
var $other = null;
-
+
function __construct($user, $other)
{
parent::__construct($user);
@@ -328,9 +328,9 @@ class UnsubCommand extends Command
$channel->error($this->user, _('Specify the name of the user to unsubscribe from'));
return;
}
-
+
$result=subs_unsubscribe_user($this->user, $this->other);
-
+
if ($result) {
$channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other));
} else {
@@ -369,7 +369,7 @@ class OnCommand extends Command
parent::__construct($user);
$this->other = $other;
}
-
+
function execute($channel)
{
if ($other) {
@@ -406,7 +406,7 @@ class HelpCommand extends Command
"unsub <nickname> - same as 'leave'\n".
"last <nickname> - same as 'get'\n".
"on <nickname> - not yet implemented.\n".
- "off <nickname> - not yet implemented.\n".
+ "off <nickname> - not yet implemented.\n".
"nudge <nickname> - not yet implemented.\n".
"invite <phone number> - not yet implemented.\n".
"track <word> - not yet implemented.\n".
diff --git a/classes/CommandInterpreter.php b/lib/commandinterpreter.php
index 0679f5462..49c733c03 100644
--- a/classes/CommandInterpreter.php
+++ b/lib/commandinterpreter.php
@@ -19,11 +19,10 @@
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/classes/Command.php');
+require_once INSTALLDIR.'/lib/command.php';
class CommandInterpreter
{
-
function handle_command($user, $text)
{
# XXX: localise
diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php
index 45e61d2fc..06603ac05 100644
--- a/lib/htmloutputter.php
+++ b/lib/htmloutputter.php
@@ -101,9 +101,8 @@ class HTMLOutputter extends XMLOutputter
$type = common_negotiate_type($cp, $sp);
if (!$type) {
- common_user_error(_('This page is not available in a '.
- 'media type you accept'), 406);
- exit(0);
+ throw new ClientException(_('This page is not available in a '.
+ 'media type you accept'), 406);
}
}
diff --git a/lib/util.php b/lib/util.php
index c0c980111..37c941cdb 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -394,20 +394,20 @@ function common_render_text($text)
function common_replace_urls_callback($text, $callback) {
// Start off with a regex
- $regex = '#
- (?:
- (?:
- (?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://
- |
- (?:mailto|aim|tel):
- )
- [^.\s]+\.[^\s]+
- |
- (?:[^.\s/:]+\.)+
- (?:museum|travel|[a-z]{2,4})
- (?:[:/][^\s]*)?
- )
- #ix';
+ $regex = '#'.
+ '(?:'.
+ '(?:'.
+ '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://'.
+ '|'.
+ '(?:mailto|aim|tel):'.
+ ')'.
+ '[^.\s]+\.[^\s]+'.
+ '|'.
+ '(?:[^.\s/:]+\.)+'.
+ '(?:museum|travel|[a-z]{2,4})'.
+ '(?:[:/][^\s]*)?'.
+ ')'.
+ '#ix';
preg_match_all($regex, $text, $matches);
// Then clean up what the regex left behind
@@ -472,16 +472,19 @@ 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
+ $url = htmlspecialchars_decode($url);
$display = $url;
- $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url:$url;
+ $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url : $url;
+
+ $attrs = array('href' => $url, 'rel' => 'external');
if ($longurl = common_longurl($url)) {
- $longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8');
- $title = "title=\"$longurl\"";
+ $attrs['title'] = $longurl;
}
- else $title = '';
- return "<a href=\"$url\" $title rel=\"external\">$display</a>";
+ return XMLStringer::estring('a', $attrs, $display);
}
function common_longurl($short_url)
@@ -582,7 +585,13 @@ function common_tag_link($tag)
{
$canonical = common_canonical_tag($tag);
$url = common_local_url('tag', array('tag' => $canonical));
- return '<span class="tag"><a href="' . htmlspecialchars($url) . '" rel="tag">' . htmlspecialchars($tag) . '</a></span>';
+ $xs = new XMLStringer();
+ $xs->elementStart('span', 'tag');
+ $xs->element('a', array('href' => $url,
+ 'rel' => 'tag'),
+ $tag);
+ $xs->elementEnd();
+ return $xs->getString();
}
function common_canonical_tag($tag)
@@ -600,7 +609,14 @@ function common_at_link($sender_id, $nickname)
$sender = Profile::staticGet($sender_id);
$recipient = common_relative_profile($sender, common_canonical_nickname($nickname));
if ($recipient) {
- return '<span class="vcard"><a href="'.htmlspecialchars($recipient->profileurl).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>';
+ $xs = new XMLStringer(false);
+ $xs->elementStart('span', 'vcard');
+ $xs->elementStart('a', array('href' => $recipient->profileurl,
+ 'class' => 'url'));
+ $xs->element('span', 'fn nickname', $nickname);
+ $xs->elementEnd('a');
+ $xs->elementEnd('span');
+ return $xs->getString();
} else {
return $nickname;
}
@@ -611,7 +627,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)) {
- return '<span class="vcard"><a href="'.htmlspecialchars($group->permalink()).'" class="url"><span class="fn nickname">'.$nickname.'</span></a></span>';
+ $xs = new XMLStringer();
+ $xs->elementStart('span', 'vcard');
+ $xs->elementStart('a', array('href' => $group->permalink(),
+ 'class' => 'url'));
+ $xs->element('span', 'fn nickname', $nickname);
+ $xs->elementEnd('a');
+ $xs->elementEnd('span');
+ return $xs->getString();
} else {
return $nickname;
}
@@ -628,7 +651,13 @@ function common_at_hash_link($sender_id, $tag)
$url = common_local_url('subscriptions',
array('nickname' => $user->nickname,
'tag' => $tag));
- return '<span class="tag"><a href="'.htmlspecialchars($url).'" rel="tag">'.$tag.'</a></span>';
+ $xs = new XMLStringer();
+ $xs->elementStart('span', 'tag');
+ $xs->element('a', array('href' => $url,
+ 'rel' => $tag),
+ $tag);
+ $xs->elementEnd('span');
+ return $xs->getString();
} else {
return $tag;
}
diff --git a/lib/xmlstringer.php b/lib/xmlstringer.php
new file mode 100644
index 000000000..951b13b67
--- /dev/null
+++ b/lib/xmlstringer.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Laconica, the distributed open-source microblogging tool
+ *
+ * Generator for in-memory XML
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Output
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @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);
+}
+
+/**
+ * Create in-memory XML
+ *
+ * @category Output
+ * @package Laconica
+ * @author Evan Prodromou <evan@controlyourself.ca>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://laconi.ca/
+ * @see Action
+ * @see HTMLOutputter
+ */
+
+class XMLStringer extends XMLOutputter
+{
+ function __construct($indent=false)
+ {
+ $this->xw = new XMLWriter();
+ $this->xw->openMemory();
+ $this->xw->setIndent($indent);
+ }
+
+ function getString()
+ {
+ return $this->xw->outputMemory();
+ }
+
+ // utility for quickly creating XML-strings
+
+ static function estring($tag, $attrs=null, $content=null)
+ {
+ $xs = new XMLStringer();
+ $xs->element($tag, $attrs, $content);
+ return $xs->getString();
+ }
+} \ No newline at end of file