Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x
This commit is contained in:
commit
033503dc84
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -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. '.
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -21,7 +21,6 @@ if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
class Channel
|
||||
{
|
||||
|
||||
function on($user)
|
||||
{
|
||||
return false;
|
@ -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".
|
@ -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
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
75
lib/util.php
75
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;
|
||||
}
|
||||
|
68
lib/xmlstringer.php
Normal file
68
lib/xmlstringer.php
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user