if (!isset($params['secret'])) {
throw new Horde_Token_Exception('Missing secret parameter.');
}
+
if (!isset($params['token_lifetime'])) {
$params['token_lifetime'] = -1;
}
{
list($nonce, $hash) = $this->_decode($token);
if ($hash != $this->_hash($nonce . $seed)) {
- throw new Horde_Token_Exception_Invalid('We cannot verify that this request was really sent by you. It could be a malicious request. If you intended to perform this action, you can retry it now.');
+ throw new Horde_Token_Exception_Invalid(Horde_Token_Translation::t('We cannot verify that this request was really sent by you. It could be a malicious request. If you intended to perform this action, you can retry it now.'));
}
if ($this->_isExpired($nonce, $this->_params['token_lifetime'])) {
- throw new Horde_Token_Exception_Expired(sprintf("This request cannot be completed because the link you followed or the form you submitted was only valid for %s minutes. Please try again now.", floor($this->_params['token_lifetime'] / 60)));
+ throw new Horde_Token_Exception_Expired(Horde_Token_Translation::t(sprintf("This request cannot be completed because the link you followed or the form you submitted was only valid for %s minutes. Please try again now.", floor($this->_params['token_lifetime'] / 60))));
}
return array($nonce, $hash);
}
{
list($nonce, $hash) = $this->isValid($token, $seed);
if (!$this->verify($nonce)) {
- throw new Horde_Token_Exception_Used('This token has been used before!');
+ throw new Horde_Token_Exception_Used(Horde_Token_Translation::t('This token has been used before!'));
}
}
--- /dev/null
+<?php
+/**
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Horde
+ * @package Translation
+ */
+
+/**
+ * Horde_Token_Translation is the translation wrapper class for horde/Token.
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @package Token
+ */
+class Horde_Token_Translation extends Horde_Translation
+{
+ /**
+ * Returns the translation of a message.
+ *
+ * @var string $message The string to translate.
+ *
+ * @return string The string translation, or the original string if no
+ * translation exists.
+ */
+ static public function t($message)
+ {
+ self::$_domain = 'Horde_Token';
+ self::$_directory = '@data_dir@' == '@'.'data_dir'.'@' ? dirname(__FILE__) . '/../../../locale' : '@data_dir@/Token/locale';
+ return parent::t($message);
+ }
+
+ /**
+ * Returns the plural translation of a message.
+ *
+ * @param string $singular The singular version to translate.
+ * @param string $plural The plural version to translate.
+ * @param integer $number The number that determines singular vs. plural.
+ *
+ * @return string The string translation, or the original string if no
+ * translation exists.
+ */
+ static public function ngettext($singular, $plural, $number)
+ {
+ self::$_domain = 'Horde_Token';
+ self::$_directory = '@data_dir@' == '@'.'data_dir'.'@' ? dirname(__FILE__) . '/../../../locale' : '@data_dir@/Token/locale';
+ return parent::ngettext($singular, $plural, $number);
+ }
+
+}
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>
+ <notes>* Add translation support.
* Add support for timestamped tokens.
* Add Horde_Token_Exception::.
* Move driver code into sub-classes.
<file name="File.php" role="php" />
<file name="Null.php" role="php" />
<file name="Sql.php" role="php" />
+ <file name="Translation.php" role="php">
+ <tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />
+ </file>
</dir> <!-- /lib/Horde/Token -->
<file name="Token.php" role="php" />
</dir> <!-- /lib/Horde -->
<channel>pear.horde.org</channel>
</package>
<package>
+ <name>Translation</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Url</name>
<channel>pear.horde.org</channel>
</package>
<install as="Horde/Token/File.php" name="lib/Horde/Token/File.php" />
<install as="Horde/Token/Null.php" name="lib/Horde/Token/Null.php" />
<install as="Horde/Token/Sql.php" name="lib/Horde/Token/Sql.php" />
+ <install as="Horde/Token/Translation.php" name="lib/Horde/Token/Translation.php" />
<install as="Horde/Token/Exception/Expired.php" name="lib/Horde/Token/Exception/Expired.php" />
<install as="Horde/Token/Exception/Invalid.php" name="lib/Horde/Token/Exception/Invalid.php" />
<install as="Horde/Token/Exception/Used.php" name="lib/Horde/Token/Exception/Used.php" />