From 4b5e977a7b1c390555d880d3dc7f8b8c6744646c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 8 Dec 2009 12:17:11 -0800 Subject: New _m() gettext wrapper with smart detection of plugin domains. Plugin base class registers your gettext files if present at initialization. update_pot.sh replaced with update_po_templates.php which can do core, plugins, or all (default). Top-level Makefile added to build .mo files for plugins as well as core. As described on list: http://lists.status.net/pipermail/statusnet-dev/2009-December/002869.html --- lib/language.php | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- lib/plugin.php | 19 +++++++++ 2 files changed, 138 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/language.php b/lib/language.php index 4fc45bafe..ab46f1a65 100644 --- a/lib/language.php +++ b/lib/language.php @@ -36,6 +36,33 @@ if (!function_exists('gettext')) { require_once("php-gettext/gettext.inc"); } + +if (!function_exists('dpgettext')) { + /** + * Context-aware dgettext wrapper; use when messages in different contexts + * won't be distinguished from the English source but need different translations. + * The context string will appear as msgctxt in the .po files. + * + * Not currently exposed in PHP's gettext module; implemented to be compat + * with gettext.h's macros. + * + * @param string $domain domain identifier, or null for default domain + * @param string $context context identifier, should be some key like "menu|file" + * @param string $msgid English source text + * @return string original or translated message + */ + function dpgettext($domain, $context, $msg) + { + $msgid = $context . "\004" . $msg; + $out = dcgettext($domain, $msgid, LC_MESSAGES); + if ($out == $msgid) { + return $msg; + } else { + return $out; + } + } +} + if (!function_exists('pgettext')) { /** * Context-aware gettext wrapper; use when messages in different contexts @@ -50,9 +77,31 @@ if (!function_exists('pgettext')) { * @return string original or translated message */ function pgettext($context, $msg) + { + return dpgettext(textdomain(NULL), $context, $msg); + } +} + +if (!function_exists('dnpgettext')) { + /** + * Context-aware dngettext wrapper; use when messages in different contexts + * won't be distinguished from the English source but need different translations. + * The context string will appear as msgctxt in the .po files. + * + * Not currently exposed in PHP's gettext module; implemented to be compat + * with gettext.h's macros. + * + * @param string $domain domain identifier, or null for default domain + * @param string $context context identifier, should be some key like "menu|file" + * @param string $msg singular English source text + * @param string $plural plural English source text + * @param int $n number of items to control plural selection + * @return string original or translated message + */ + function dnpgettext($domain, $context, $msg, $plural, $n) { $msgid = $context . "\004" . $msg; - $out = dcgettext(textdomain(NULL), $msgid, LC_MESSAGES); + $out = dcngettext($domain, $msgid, $plural, $n, LC_MESSAGES); if ($out == $msgid) { return $msg; } else { @@ -78,14 +127,78 @@ if (!function_exists('npgettext')) { */ function npgettext($context, $msg, $plural, $n) { - $msgid = $context . "\004" . $msg; - $out = dcngettext(textdomain(NULL), $msgid, $plural, $n, LC_MESSAGES); - if ($out == $msgid) { - return $msg; + return dnpgettext(textdomain(NULL), $msgid, $plural, $n, LC_MESSAGES); + } +} + +/** + * Shortcut for *gettext functions with smart domain detection. + * + * If calling from a plugin, this function checks which plugin was + * being called from and uses that as text domain, which will have + * been set up during plugin initialization. + * + * Also handles plurals and contexts depending on what parameters + * are passed to it: + * + * gettext -> _m($msg) + * ngettext -> _m($msg1, $msg2, $n) + * pgettext -> _m($ctx, $msg) + * npgettext -> _m($ctx, $msg1, $msg2, $n) + * + * @fixme may not work properly in eval'd code + * + * @param string $msg + * @return string + */ +function _m($msg/*, ...*/) +{ + $domain = _mdomain(debug_backtrace(false)); + $args = func_get_args(); + switch(count($args)) { + case 1: return dgettext($domain, $msg); + case 2: return dpgettext($domain, $args[0], $args[1]); + case 3: return dngettext($domain, $args[0], $args[1], $args[2]); + case 4: return dnpgettext($domain, $args[0], $args[1], $args[2], $args[3]); + default: throw new Exception("Bad parameter count to _m()"); + } +} + +/** + * Looks for which plugin we've been called from to set the gettext domain. + * + * @param array $backtrace debug_backtrace() output + * @return string + * @private + * @fixme could explode if SN is under a 'plugins' folder or share name. + */ +function _mdomain($backtrace) +{ + /* + 0 => + array + 'file' => string '/var/www/mublog/plugins/FeedSub/FeedSubPlugin.php' (length=49) + 'line' => int 77 + 'function' => string '_m' (length=2) + 'args' => + array + 0 => &string 'Feeds' (length=5) + */ + static $cached; + $path = $backtrace[0]['file']; + if (!isset($cached[$path])) { + if (DIRECTORY_SEPARATOR !== '/') { + $path = strtr($path, DIRECTORY_SEPARATOR, '/'); + } + $cut = strpos($path, '/plugins/') + 9; + $cut2 = strpos($path, '/', $cut); + if ($cut && $cut2) { + $cached[$path] = substr($path, $cut, $cut2 - $cut); } else { - return $out; + return null; } } + return $cached[$path]; } diff --git a/lib/plugin.php b/lib/plugin.php index 2c77c3e12..de7313e59 100644 --- a/lib/plugin.php +++ b/lib/plugin.php @@ -65,6 +65,8 @@ class Plugin Event::addHandler(mb_substr($method, 2), array($this, $method)); } } + + $this->setupGettext(); } function initialize() @@ -77,6 +79,22 @@ class Plugin return true; } + /** + * Checks if this plugin has localization that needs to be set up. + * Gettext localizations can be called via the _m() helper function. + */ + protected function setupGettext() + { + $class = get_class($this); + if (substr($class, -6) == 'Plugin') { + $name = substr($class, 0, -6); + $path = INSTALLDIR . "/plugins/$name/locale"; + if (file_exists($path) && is_dir($path)) { + bindtextdomain($name, $path); + } + } + } + protected function log($level, $msg) { common_log($level, get_class($this) . ': '.$msg); @@ -87,3 +105,4 @@ class Plugin $this->log(LOG_DEBUG, $msg); } } + -- cgit v1.2.3-54-g00ecf From 48a93810abe5fd5098ef4f91e2b9d5991e217748 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 17:20:45 -0500 Subject: action to forward a notice --- actions/forward.php | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/router.php | 2 +- 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 actions/forward.php (limited to 'lib') diff --git a/actions/forward.php b/actions/forward.php new file mode 100644 index 000000000..87365c2d3 --- /dev/null +++ b/actions/forward.php @@ -0,0 +1,117 @@ + + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2008, 2009, StatusNet, 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 . + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Forward action + * + * @category Action + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ + +class ForwardAction extends Action +{ + var $user = null; + var $notice = null; + + function prepare($args) + { + parent::prepare($args); + + $this->user = common_current_user(); + + if (empty($this->user)) { + $this->clientError(_("Only logged-in users can forward notices.")); + return false; + } + + $id = $this->trimmed('notice'); + + if (empty($id)) { + $this->clientError(_("No notice specified.")); + return false; + } + + $this->notice = Notice::staticGet('id', $id); + + if (empty($this->notice)) { + $this->clientError(_("No notice specified.")); + return false; + } + + $token = $this->trimmed('token'); + + if (empty($token) || $token != common_session_token()) { + $this->clientError(_("There was a problem with your session token. Try again, please.")); + return false; + } + + $profile = $this->user->getProfile(); + + if ($profile->hasForwarded($id)) { + $this->clientError(_("You already forwarded that notice.")); + return false; + } + + return true; + } + + /** + * Class handler. + * + * @param array $args query arguments + * + * @return void + */ + + function handle($args) + { + $forward = Forward::saveNew($this->user->id, $this->notice->id); + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, _('Forwarded')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'forward_response'), _('Forwarded!')); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + // FIXME! + } + } +} diff --git a/lib/router.php b/lib/router.php index 37525319f..398135a3e 100644 --- a/lib/router.php +++ b/lib/router.php @@ -99,7 +99,7 @@ class Router 'groupblock', 'groupunblock', 'sandbox', 'unsandbox', 'silence', 'unsilence', - 'deleteuser'); + 'deleteuser', 'forward'); foreach ($main as $a) { $m->connect('main/'.$a, array('action' => $a)); -- cgit v1.2.3-54-g00ecf From 41cbb90faeabc0a6002b41d40d392f45a59a7aba Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 17:31:23 -0500 Subject: add (ugly) form to forward notices --- actions/forward.php | 2 +- js/util.js | 10 ++-- lib/forwardform.php | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/noticelist.php | 21 ++++++++ 4 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 lib/forwardform.php (limited to 'lib') diff --git a/actions/forward.php b/actions/forward.php index 87365c2d3..867ed97d2 100644 --- a/actions/forward.php +++ b/actions/forward.php @@ -72,7 +72,7 @@ class ForwardAction extends Action return false; } - $token = $this->trimmed('token'); + $token = $this->trimmed('token-'.$id); if (empty($token) || $token != common_session_token()) { $this->clientError(_("There was a problem with your session token. Try again, please.")); diff --git a/js/util.js b/js/util.js index ed6a781f7..67df73507 100644 --- a/js/util.js +++ b/js/util.js @@ -208,7 +208,7 @@ var SN = { // StatusNet $('#'+form_id+' .form_response').remove(); var result; if ($('#'+SN.C.S.Error, data).length > 0) { - result = document._importNode($('p', data)[0], true); + result = document._importNode($('p', data)[0], true); result = result.textContent || result.innerHTML; form.append('

'+result+'

'); } @@ -306,8 +306,12 @@ var SN = { // StatusNet $('.form_disfavor').each(function() { SN.U.FormXHR($(this)); }); }, + NoticeForward: function() { + $('.form_forward').each(function() { SN.U.FormXHR($(this)); }); + }, + NoticeAttachments: function() { - $('.notice a.attachment').each(function() { + $('.notice a.attachment').each(function() { SN.U.NoticeWithAttachment($(this).closest('.notice')); }); }, @@ -439,7 +443,7 @@ var SN = { // StatusNet Notices: function() { if ($('body.user_in').length > 0) { SN.U.NoticeFavor(); - + SN.U.NoticeForward(); SN.U.NoticeReply(); } diff --git a/lib/forwardform.php b/lib/forwardform.php new file mode 100644 index 000000000..2052856ae --- /dev/null +++ b/lib/forwardform.php @@ -0,0 +1,147 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for forwarding a notice + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class ForwardForm extends Form +{ + /** + * Notice to forward + */ + + var $notice = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Notice $notice notice to forward + */ + + function __construct($out=null, $notice=null) + { + parent::__construct($out); + + $this->notice = $notice; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'forward-' . $this->notice->id; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('forward'); + } + + /** + * Include a session token for CSRF protection + * + * @return void + */ + + function sessionToken() + { + $this->out->hidden('token-' . $this->notice->id, + common_session_token()); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Forward this notice')); + } + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $this->out->hidden('notice-n'.$this->notice->id, + $this->notice->id, + 'notice'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('forward-submit-' . $this->notice->id, + _('Forward'), 'submit', null, _('Forward this notice')); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_forward'; + } +} diff --git a/lib/noticelist.php b/lib/noticelist.php index 21cec528f..b38860880 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -212,6 +212,7 @@ class NoticeListItem extends Widget $this->out->elementStart('div', 'notice-options'); $this->showFaveForm(); $this->showReplyLink(); + $this->showForwardForm(); $this->showDeleteLink(); $this->out->elementEnd('div'); } @@ -530,6 +531,26 @@ class NoticeListItem extends Widget } } + /** + * show the form to forward a notice + * + * @return void + */ + + function showForwardForm() + { + $user = common_current_user(); + if ($user) { + $profile = $user->getProfile(); + if ($profile->hasForwarded($this->notice->id)) { + $this->out->text(_('Forwarded')); + } else { + $ff = new ForwardForm($this->out, $this->notice); + $ff->show(); + } + } + } + /** * if the user is the author, let them delete the notice * -- cgit v1.2.3-54-g00ecf From 21757186e9a7ffd2e3330fd4ef61ffeb2dc0229b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 8 Dec 2009 17:52:20 -0500 Subject: don't allow forwarding your own notice --- actions/forward.php | 5 +++++ lib/noticelist.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/actions/forward.php b/actions/forward.php index 867ed97d2..194833fe0 100644 --- a/actions/forward.php +++ b/actions/forward.php @@ -72,6 +72,11 @@ class ForwardAction extends Action return false; } + if ($this->user->id == $this->notice->profile_id) { + $this->clientError(_("You can't forward your own notice.")); + return false; + } + $token = $this->trimmed('token-'.$id); if (empty($token) || $token != common_session_token()) { diff --git a/lib/noticelist.php b/lib/noticelist.php index b38860880..d6ffc9ca9 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -540,7 +540,7 @@ class NoticeListItem extends Widget function showForwardForm() { $user = common_current_user(); - if ($user) { + if ($user && $user->id != $this->notice->profile_id) { $profile = $user->getProfile(); if ($profile->hasForwarded($this->notice->id)) { $this->out->text(_('Forwarded')); -- cgit v1.2.3-54-g00ecf From 2f59f0ddb5cc6030671af7e751e0ae85e4751497 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 8 Dec 2009 17:35:27 -0800 Subject: Compat fix for PHP 5.2.4 -- drop unneeded new param to debug_backtrace(), caused error spew on older PHP (introduced PHP 5.2.5) Fix for regression in 4b5e977a7b1c390555d880d3dc7f8b8c6744646c --- lib/language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/language.php b/lib/language.php index ab46f1a65..916cee7ed 100644 --- a/lib/language.php +++ b/lib/language.php @@ -153,7 +153,7 @@ if (!function_exists('npgettext')) { */ function _m($msg/*, ...*/) { - $domain = _mdomain(debug_backtrace(false)); + $domain = _mdomain(debug_backtrace()); $args = func_get_args(); switch(count($args)) { case 1: return dgettext($domain, $msg); -- cgit v1.2.3-54-g00ecf From 1e166e1bc4a8b16ad2ef8e99db6a112f47803eda Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 10 Dec 2009 14:16:07 +0100 Subject: Updated FormNoticeEnhancements and Counter to use the max text value from HTML. It also allows each .form_notice to have its own counter. --- js/util.js | 38 ++++++++++++++++++++++---------------- lib/messageform.php | 2 -- lib/noticeform.php | 2 -- 3 files changed, 22 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/js/util.js b/js/util.js index 67df73507..60865d352 100644 --- a/js/util.js +++ b/js/util.js @@ -57,21 +57,28 @@ var SN = { // StatusNet U: { // Utils FormNoticeEnhancements: function(form) { form_id = form.attr('id'); - $('#'+form_id+' #'+SN.C.S.NoticeDataText).unbind('keyup'); - $('#'+form_id+' #'+SN.C.S.NoticeDataText).unbind('keydown'); - if (maxLength > 0) { - $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keyup', function(e) { + + if (jQuery.data(form[0], 'ElementData') === undefined) { + MaxLength = $('#'+form_id+' #'+SN.C.S.NoticeTextCount).text(); + if (typeof(MaxLength) == 'undefined') { + MaxLength = SN.C.I.MaxLength; + } + jQuery.data(form[0], 'ElementData', {MaxLength:MaxLength}); + + SN.U.Counter(form); + + NDT = $('#'+form_id+' #'+SN.C.S.NoticeDataText); + + NDT.bind('keyup', function(e) { SN.U.Counter(form); }); - // run once in case there's something in there - SN.U.Counter(form); - } - $('#'+form_id+' #'+SN.C.S.NoticeDataText).bind('keydown', function(e) { - SN.U.SubmitOnReturn(e, form); - }); + NDT.bind('keydown', function(e) { + SN.U.SubmitOnReturn(e, form); + }); + } - if($('body')[0].id != 'conversation') { + if ($('body')[0].id != 'conversation') { $('#'+form_id+' textarea').focus(); } }, @@ -91,15 +98,14 @@ var SN = { // StatusNet Counter: function(form) { SN.C.I.FormNoticeCurrent = form; form_id = form.attr('id'); - if (typeof(maxLength) == "undefined") { - maxLength = SN.C.I.MaxLength; - } - if (maxLength <= 0) { + var MaxLength = jQuery.data(form[0], 'ElementData').MaxLength; + + if (MaxLength <= 0) { return; } - var remaining = maxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length; + var remaining = MaxLength - $('#'+form_id+' #'+SN.C.S.NoticeDataText).val().length; var counter = $('#'+form_id+' #'+SN.C.S.NoticeTextCount); if (remaining.toString() != counter.text()) { diff --git a/lib/messageform.php b/lib/messageform.php index 4df193c6d..0c568e1bd 100644 --- a/lib/messageform.php +++ b/lib/messageform.php @@ -154,8 +154,6 @@ class MessageForm extends Form $contentLimit = Message::maxContent(); - $this->out->inlineScript('maxLength = ' . $contentLimit . ';'); - if ($contentLimit > 0) { $this->out->elementStart('dl', 'form_note'); $this->out->element('dt', null, _('Available characters')); diff --git a/lib/noticeform.php b/lib/noticeform.php index 0dd3f2d77..593a1e932 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -178,8 +178,6 @@ class NoticeForm extends Form $contentLimit = Notice::maxContent(); - $this->out->inlineScript('maxLength = ' . $contentLimit . ';'); - if ($contentLimit > 0) { $this->out->elementStart('dl', 'form_note'); $this->out->element('dt', null, _('Available characters')); -- cgit v1.2.3-54-g00ecf From b07e1143cc8f07bf0613835debe08be227970c73 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 10 Dec 2009 13:08:24 -0500 Subject: Override login_token's sequenceKey() so that it behaves correctly --- classes/Login_token.php | 13 +++++++++++++ lib/command.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/classes/Login_token.php b/classes/Login_token.php index c172b30ab..746cd7f22 100644 --- a/classes/Login_token.php +++ b/classes/Login_token.php @@ -39,4 +39,17 @@ class Login_token extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + /* + DB_DataObject calculates the sequence key(s) by taking the first key returned by the keys() function. + In this case, the keys() function returns user_id as the first key. user_id is not a sequence, but + DB_DataObject's sequenceKey() will incorrectly think it is. Then, since the sequenceKey() is a numeric + type, but is not set to autoincrement in the database, DB_DataObject will create a _seq table and + manage the sequence itself. This is not the correct behavior for the user_id in this class. + So we override that incorrect behavior, and simply say there is no sequence key. + */ + function sequenceKey() + { + return array(false,false); + } } diff --git a/lib/command.php b/lib/command.php index e2a665511..af8855a7f 100644 --- a/lib/command.php +++ b/lib/command.php @@ -584,7 +584,7 @@ class LoginCommand extends Command function execute($channel) { $disabled = common_config('logincommand','disabled'); - if(isset($disabled)) { + if(isset($disabled) && $disabled) { $channel->error($this->user, _('Login command is disabled')); return; } -- cgit v1.2.3-54-g00ecf From b36ec6da87056324ce0cdf98a4745cdc992c5d52 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Thu, 10 Dec 2009 13:22:46 -0500 Subject: Fixed incorrect disabling of login_token. --- actions/login.php | 3 ++- lib/command.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/actions/login.php b/actions/login.php index a6f86c0ca..c775fa692 100644 --- a/actions/login.php +++ b/actions/login.php @@ -77,12 +77,13 @@ class LoginAction extends Action parent::handle($args); $disabled = common_config('logincommand','disabled'); + $disabled = isset($disabled) && $disabled; if (common_is_real_login()) { $this->clientError(_('Already logged in.')); } else if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->checkLogin(); - } else if (!isset($disabled) && isset($args['user_id']) && isset($args['token'])){ + } else if (!$disabled && isset($args['user_id']) && isset($args['token'])){ $this->checkLogin($args['user_id'],$args['token']); } else { common_ensure_session(); diff --git a/lib/command.php b/lib/command.php index af8855a7f..450db9da3 100644 --- a/lib/command.php +++ b/lib/command.php @@ -584,7 +584,8 @@ class LoginCommand extends Command function execute($channel) { $disabled = common_config('logincommand','disabled'); - if(isset($disabled) && $disabled) { + $disabled = isset($disabled) && $disabled; + if($disabled) { $channel->error($this->user, _('Login command is disabled')); return; } -- cgit v1.2.3-54-g00ecf From 37b0852fdb8b82741b327af57d898d4d89c2f177 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 10 Dec 2009 14:33:15 -0500 Subject: move forward form to plugin --- lib/forwardform.php | 147 ----------------------------------------- lib/noticelist.php | 21 ------ plugins/Repeat/forwardform.php | 147 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+), 168 deletions(-) delete mode 100644 lib/forwardform.php create mode 100644 plugins/Repeat/forwardform.php (limited to 'lib') diff --git a/lib/forwardform.php b/lib/forwardform.php deleted file mode 100644 index 2052856ae..000000000 --- a/lib/forwardform.php +++ /dev/null @@ -1,147 +0,0 @@ -. - * - * @category Form - * @package StatusNet - * @author Evan Prodromou - * @copyright 2009 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ - -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/lib/form.php'; - -/** - * Form for forwarding a notice - * - * @category Form - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://status.net/ - */ - -class ForwardForm extends Form -{ - /** - * Notice to forward - */ - - var $notice = null; - - /** - * Constructor - * - * @param HTMLOutputter $out output channel - * @param Notice $notice notice to forward - */ - - function __construct($out=null, $notice=null) - { - parent::__construct($out); - - $this->notice = $notice; - } - - /** - * ID of the form - * - * @return int ID of the form - */ - - function id() - { - return 'forward-' . $this->notice->id; - } - - /** - * Action of the form - * - * @return string URL of the action - */ - - function action() - { - return common_local_url('forward'); - } - - /** - * Include a session token for CSRF protection - * - * @return void - */ - - function sessionToken() - { - $this->out->hidden('token-' . $this->notice->id, - common_session_token()); - } - - /** - * Legend of the Form - * - * @return void - */ - function formLegend() - { - $this->out->element('legend', null, _('Forward this notice')); - } - - /** - * Data elements - * - * @return void - */ - - function formData() - { - $this->out->hidden('notice-n'.$this->notice->id, - $this->notice->id, - 'notice'); - } - - /** - * Action elements - * - * @return void - */ - - function formActions() - { - $this->out->submit('forward-submit-' . $this->notice->id, - _('Forward'), 'submit', null, _('Forward this notice')); - } - - /** - * Class of the form. - * - * @return string the form's class - */ - - function formClass() - { - return 'form_forward'; - } -} diff --git a/lib/noticelist.php b/lib/noticelist.php index d6ffc9ca9..21cec528f 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -212,7 +212,6 @@ class NoticeListItem extends Widget $this->out->elementStart('div', 'notice-options'); $this->showFaveForm(); $this->showReplyLink(); - $this->showForwardForm(); $this->showDeleteLink(); $this->out->elementEnd('div'); } @@ -531,26 +530,6 @@ class NoticeListItem extends Widget } } - /** - * show the form to forward a notice - * - * @return void - */ - - function showForwardForm() - { - $user = common_current_user(); - if ($user && $user->id != $this->notice->profile_id) { - $profile = $user->getProfile(); - if ($profile->hasForwarded($this->notice->id)) { - $this->out->text(_('Forwarded')); - } else { - $ff = new ForwardForm($this->out, $this->notice); - $ff->show(); - } - } - } - /** * if the user is the author, let them delete the notice * diff --git a/plugins/Repeat/forwardform.php b/plugins/Repeat/forwardform.php new file mode 100644 index 000000000..2052856ae --- /dev/null +++ b/plugins/Repeat/forwardform.php @@ -0,0 +1,147 @@ +. + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/form.php'; + +/** + * Form for forwarding a notice + * + * @category Form + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class ForwardForm extends Form +{ + /** + * Notice to forward + */ + + var $notice = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Notice $notice notice to forward + */ + + function __construct($out=null, $notice=null) + { + parent::__construct($out); + + $this->notice = $notice; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'forward-' . $this->notice->id; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('forward'); + } + + /** + * Include a session token for CSRF protection + * + * @return void + */ + + function sessionToken() + { + $this->out->hidden('token-' . $this->notice->id, + common_session_token()); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Forward this notice')); + } + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $this->out->hidden('notice-n'.$this->notice->id, + $this->notice->id, + 'notice'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('forward-submit-' . $this->notice->id, + _('Forward'), 'submit', null, _('Forward this notice')); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_forward'; + } +} -- cgit v1.2.3-54-g00ecf From eceb5e8a0fbf798e42fb9c1d0598d9dc0f4b7550 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 10 Dec 2009 14:42:13 -0500 Subject: remove forward action from router --- lib/router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/router.php b/lib/router.php index 398135a3e..37525319f 100644 --- a/lib/router.php +++ b/lib/router.php @@ -99,7 +99,7 @@ class Router 'groupblock', 'groupunblock', 'sandbox', 'unsandbox', 'silence', 'unsilence', - 'deleteuser', 'forward'); + 'deleteuser'); foreach ($main as $a) { $m->connect('main/'.$a, array('action' => $a)); -- cgit v1.2.3-54-g00ecf