summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-11-19 09:04:56 -0500
committerEvan Prodromou <evan@status.net>2009-11-19 09:04:56 -0500
commitb657e49ec772aec2b60ae193252edd53d85e1df5 (patch)
tree71f6054ac22b8355f434fd9bf4c2ccfc1afc5140 /lib
parentfa35dab2265aba78f7c704c34eaef4100bddfd70 (diff)
parent269781280903d80141788225ec858fbf6501971d (diff)
Merge branch '0.9.x' into mapstraction
Diffstat (limited to 'lib')
-rw-r--r--lib/adminform.php86
-rw-r--r--lib/adminpanelaction.php27
-rw-r--r--lib/apiauth.php6
-rw-r--r--lib/common.php4
-rw-r--r--lib/form.php10
-rw-r--r--lib/language.php57
-rw-r--r--lib/unblockform.php2
-rw-r--r--lib/util.php13
8 files changed, 195 insertions, 10 deletions
diff --git a/lib/adminform.php b/lib/adminform.php
new file mode 100644
index 000000000..3934f6351
--- /dev/null
+++ b/lib/adminform.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Base class for administrative forms
+ *
+ * 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 Widget
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @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);
+}
+
+/**
+ * Base class for Administrative forms
+ *
+ * Just a place holder for some utility methods to simply some
+ * repetitive form building code
+ *
+ * @category Widget
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ *
+ * @see Form
+ */
+
+class AdminForm extends Form
+{
+ /**
+ * Utility to simplify some of the duplicated code around
+ * params and settings.
+ *
+ * @param string $setting Name of the setting
+ * @param string $title Title to use for the input
+ * @param string $instructions Instructions for this field
+ * @param string $section config section, default = 'site'
+ *
+ * @return void
+ */
+
+ function input($setting, $title, $instructions, $section='site')
+ {
+ $this->out->input($setting, $title, $this->value($setting, $section), $instructions);
+ }
+
+ /**
+ * Utility to simplify getting the posted-or-stored setting value
+ *
+ * @param string $setting Name of the setting
+ * @param string $main configuration section, default = 'site'
+ *
+ * @return string param value if posted, or current config value
+ */
+
+ function value($setting, $main='site')
+ {
+ $value = $this->out->trimmed($setting);
+ if (empty($value)) {
+ $value = common_config($main, $setting);
+ }
+ return $value;
+ }
+
+}
diff --git a/lib/adminpanelaction.php b/lib/adminpanelaction.php
index 33b210da3..e0c253ccf 100644
--- a/lib/adminpanelaction.php
+++ b/lib/adminpanelaction.php
@@ -224,6 +224,33 @@ class AdminPanelAction extends Action
$this->clientError(_('saveSettings() not implemented.'));
return;
}
+
+ /**
+ * Delete a design setting
+ *
+ * // XXX: Maybe this should go in Design? --Z
+ *
+ * @return mixed $result false if something didn't work
+ */
+
+ function deleteSetting($section, $setting)
+ {
+ $config = new Config();
+
+ $config->section = $section;
+ $config->setting = $setting;
+
+ if ($config->find(true)) {
+ $result = $config->delete();
+ if (!$result) {
+ common_log_db_error($config, 'DELETE', __FILE__);
+ $this->clientError(_("Unable to delete design setting."));
+ return null;
+ }
+ }
+
+ return $result;
+ }
}
/**
diff --git a/lib/apiauth.php b/lib/apiauth.php
index 2f2e44a26..0d1613d38 100644
--- a/lib/apiauth.php
+++ b/lib/apiauth.php
@@ -110,7 +110,11 @@ class ApiAuthAction extends ApiAction
} else {
$nickname = $this->auth_user;
$password = $this->auth_pw;
- $this->auth_user = common_check_user($nickname, $password);
+ $user = common_check_user($nickname, $password);
+ if (Event::handle('StartSetApiUser', array(&$user))) {
+ $this->auth_user = $user;
+ Event::handle('EndSetApiUser', array($user));
+ }
if (empty($this->auth_user)) {
diff --git a/lib/common.php b/lib/common.php
index 203b37c87..732c22bfd 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -59,10 +59,6 @@ require_once('PEAR.php');
require_once('DB/DataObject.php');
require_once('DB/DataObject/Cast.php'); # for dates
-if (!function_exists('gettext')) {
- require_once("php-gettext/gettext.inc");
-}
-
require_once(INSTALLDIR.'/lib/language.php');
// This gets included before the config file, so that admin code and plugins
diff --git a/lib/form.php b/lib/form.php
index 868c986b9..f6501dc6d 100644
--- a/lib/form.php
+++ b/lib/form.php
@@ -181,4 +181,14 @@ class Form extends Widget
{
return 'form';
}
+
+ function li()
+ {
+ $this->out->elementStart('li');
+ }
+
+ function unli()
+ {
+ $this->out->elementEnd('li');
+ }
}
diff --git a/lib/language.php b/lib/language.php
index 2570907b7..a99bf89e3 100644
--- a/lib/language.php
+++ b/lib/language.php
@@ -32,6 +32,63 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
+if (!function_exists('gettext')) {
+ require_once("php-gettext/gettext.inc");
+}
+
+if (!function_exists('pgettext')) {
+ /**
+ * Context-aware gettext 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 $context context identifier, should be some key like "menu|file"
+ * @param string $msgid English source text
+ * @return string original or translated message
+ */
+ function pgettext($context, $msg)
+ {
+ $msgid = $context . "\004" . $msg;
+ $out = dcgettext(textdomain(NULL), $msgid, LC_MESSAGES);
+ if ($out == $msgid) {
+ return $msg;
+ } else {
+ return $out;
+ }
+ }
+}
+
+if (!function_exists('npgettext')) {
+ /**
+ * Context-aware ngettext 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 $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 npgettext($context, $msg, $plural, $n)
+ {
+ $msgid = $context . "\004" . $msg;
+ $out = dcngettext(textdomain(NULL), $msgid, $plural, $n, LC_MESSAGES);
+ if ($out == $msgid) {
+ return $msg;
+ } else {
+ return $out;
+ }
+ }
+}
+
+
/**
* Content negotiation for language codes
*
diff --git a/lib/unblockform.php b/lib/unblockform.php
index 4fe28b21a..2a444f7cd 100644
--- a/lib/unblockform.php
+++ b/lib/unblockform.php
@@ -77,6 +77,6 @@ class UnblockForm extends ProfileActionForm
function description()
{
- return _('Unlock this user');
+ return _('Unblock this user');
}
}
diff --git a/lib/util.php b/lib/util.php
index 68f3520db..5bf4f6091 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -196,10 +196,15 @@ function common_set_user($user)
}
if ($user) {
- common_ensure_session();
- $_SESSION['userid'] = $user->id;
- $_cur = $user;
- return $_cur;
+ if (Event::handle('StartSetUser', array(&$user))) {
+ if($user){
+ common_ensure_session();
+ $_SESSION['userid'] = $user->id;
+ $_cur = $user;
+ Event::handle('EndSetUser', array($user));
+ return $_cur;
+ }
+ }
}
return false;
}