Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x

This commit is contained in:
Sarven Capadisli 2009-02-12 18:30:10 +00:00
commit 033503dc84
10 changed files with 239 additions and 67 deletions

View File

@ -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);
}
}
}

View File

@ -228,6 +228,27 @@ class RegisterAction extends Action
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?
*

View File

@ -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. '.

View File

@ -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;
}
@ -844,6 +849,32 @@ class Action extends HTMLOutputter // lawsuit
throw new ClientException($msg, $code);
}
/**
* 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
*

View File

@ -21,7 +21,6 @@ if (!defined('LACONICA')) { exit(1); }
class Channel
{
function on($user)
{
return false;

View File

@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
require_once(INSTALLDIR.'/classes/Channel.php');
require_once(INSTALLDIR.'/lib/channel.php');
class Command
{

View File

@ -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

View File

@ -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 '.
throw new ClientException(_('This page is not available in a '.
'media type you accept'), 406);
exit(0);
}
}

View File

@ -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;
}

68
lib/xmlstringer.php Normal file
View File

@ -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();
}
}