From: <gem...@li...> - 2011-12-01 15:27:01
|
Revision: 326 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=326&view=rev Author: mennodekker Date: 2011-12-01 15:26:53 +0000 (Thu, 01 Dec 2011) Log Message: ----------- Merged userloader branch up to revision 321 - indexAction: use project email for retrieve password emails - StaffAction: start towards better handling of other userclasses (mainly raising questions) unique gsf_login replaced by unique gsf_login + gsf_id_organization unique constraint on email removed (one email can have two logins for example admin / non admin login (needs check with password retrieval) - SurveyMaintenanceAction: Show description of survey (so we can see what 'version' we use - ProjectSettings: Just a note on init and notice fixes - TabForm: bugfixes - TrackEngineAbstract: Show description of survey (like in SurveyMaintenanceAction - Survey: allow to read description - Organization: moved -> access to get, so we can have default values and get something when key exists but value is null - UserLoader: Related to StaffAction, retrieve definition without having a user - TrackData: Extra method to have surveys with and without description - patches.sql: Remove unique constraint from the index to allow multiple accounts with the same email Revision Links: -------------- http://gemstracker.svn.sourceforge.net/gemstracker/?rev=321&view=rev Modified Paths: -------------- trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Default/StaffAction.php trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php trunk/library/classes/Gems/Project/ProjectSettings.php trunk/library/classes/Gems/TabForm.php trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php trunk/library/classes/Gems/Tracker/Survey.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/Gems/Util/TrackData.php trunk/library/configs/db/patches.sql Added Paths: ----------- trunk/library/classes/Zend/ trunk/library/classes/Zend/Translate/ trunk/library/classes/Zend/Translate/Adapter.php Removed Paths: ------------- trunk/library/classes/Zend/Translate/ trunk/library/classes/Zend/Translate/Adapter.php Property Changed: ---------------- trunk/library/ Property changes on: trunk/library ___________________________________________________________________ Modified: svn:mergeinfo - /branches/1.5.0-pulse/library:306-311 /branches/newUser:113-150 /branches/newUser2:175-207 /tags/1.5.0beta1/library:305 + /branches/1.5.0-pulse/library:306-311 /branches/newUser:113-150 /branches/newUser2:175-207 /branches/userloader:259-324 /tags/1.5.0beta1/library:305 Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-12-01 15:26:53 UTC (rev 326) @@ -1,5 +1,4 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -416,12 +415,14 @@ $this->addMessage($this->_('This key timed out or does not belong to this user.')); } } else { - // P{ass mail by key + // Pass mail by key $mail = new MUtil_Mail(); - $mail->setFrom('mj...@ma...'); $mail->addTo($user->getEmailAddress(), $user->getFullName()); - if (isset($this->escort->project->email) && isset($this->escort->project->email['bcc'])) { + if (isset($this->escort->project->email['site'])) { + $mail->setFrom($this->escort->project->email['site']); + } + if (isset($this->escort->project->email['bcc'])) { $mail->addBcc($this->escort->project->email['bcc']); } Modified: trunk/library/classes/Gems/Default/StaffAction.php =================================================================== --- trunk/library/classes/Gems/Default/StaffAction.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Default/StaffAction.php 2011-12-01 15:26:53 UTC (rev 326) @@ -44,6 +44,8 @@ */ class Gems_Default_StaffAction extends Gems_Controller_BrowseEditAction { + //@@TODO What if we want a different one per organization? + //Maybe check if org has a default and otherwise use this one? public $defaultStaffDefinition = Gems_User_UserLoader::USER_STAFF; public $filterStandard = array('gsf_active' => 1); @@ -102,22 +104,23 @@ } $dbLookup = $this->util->getDbLookup(); - switch ($data['gul_user_class']) { - case Gems_User_UserLoader::USER_STAFF: + $passwordField = false; + + //@@TODO Like this? should work when user is not saved, but storing the password should be done when + //we do have a user... + $definition = $this->loader->getUserLoader()->getUserDefinition($data['gul_user_class'].'Definition'); + + if ($definition->canSetPassword()) { + //@@TODO: Should we handle it like this? The userdef has a setpassword method... + if ($definition instanceof Gems_User_StaffUserDefinition) { Gems_Model::addUserPassword($model); $passwordField = 'gup_password'; $model->setOnSave($passwordField, array($this->project, 'getValueHash')); - break; - - case Gems_User_UserLoader::USER_OLD_STAFF: + } elseif ($definition instanceof Gems_User_OldStaffUserDefinition) { $passwordField = 'gsf_password'; $model->setOnSave($passwordField, array($this, 'getOldPasswordHash')); - break; - - default: - $passwordField = false; - break; } + } $model->set('gsf_id_primary_group', 'multiOptions', MUtil_Lazy::call($dbLookup->getAllowedStaffGroups)); if ($new) { @@ -133,8 +136,10 @@ $bridge->addHidden( 'gul_id_user'); $bridge->addHidden( 'gup_id_user'); $bridge->addHidden( 'gul_user_class'); + //@@TODO: How do we change this? Only per org, or allow per user? + //What classes are available? Maybe use something like event loader and add a little desc. to each type? $bridge->addText( 'gsf_login', 'size', 15, 'minlength', 4, - 'validator', $model->createUniqueValidator('gsf_login', array('gsf_id_user'))); + 'validator', $model->createUniqueValidator(array('gsf_login', 'gsf_id_organization'), array('gsf_id_user'))); // Can the organization be changed? if ($this->escort->hasPrivilege('pr.staff.edit.all')) { @@ -163,7 +168,7 @@ $bridge->addText( 'gsf_surname_prefix', 'label', $this->_('Surname prefix'), 'description', 'de, van der, \'t, etc...'); $bridge->addText( 'gsf_last_name', 'label', $this->_('Last name'), 'required', true); $bridge->addFilter( 'gsf_last_name', $ucfirst); - $bridge->addText( 'gsf_email', array('size' => 30))->addValidator('SimpleEmail')->addValidator($model->createUniqueValidator('gsf_email')); + $bridge->addText( 'gsf_email', array('size' => 30))->addValidator('SimpleEmail'); $bridge->addSelect('gsf_id_primary_group'); $bridge->addCheckbox('gsf_logout_on_survey', 'description', $this->_('If checked the user will logoff when answering a survey.')); Modified: trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php =================================================================== --- trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Default/SurveyMaintenanceAction.php 2011-12-01 15:26:53 UTC (rev 326) @@ -344,11 +344,11 @@ $model->resetOrder(); $model->set('gsu_survey_name', 'label', $this->_('Name')); + $model->set('gsu_survey_description', 'label', $this->_('Description'), 'formatFunction', array(__CLASS__, 'formatDescription')); $model->set('gso_source_name', 'label', $this->_('Source')); $model->set('gsu_status_show', 'label', $this->_('Status in source')); if ($detailed) { - $model->set('gsu_survey_description', 'label', $this->_('Description'), 'formatFunction', array(__CLASS__, 'formatDescription')); $model->set('gsu_surveyor_active', 'label', $this->_('Active in source')); $model->set('gsu_active', 'label', sprintf($this->_('Active in %s'), GEMS_PROJECT_NAME_UC)); } else { Modified: trunk/library/classes/Gems/Project/ProjectSettings.php =================================================================== --- trunk/library/classes/Gems/Project/ProjectSettings.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Project/ProjectSettings.php 2011-12-01 15:26:53 UTC (rev 326) @@ -97,6 +97,8 @@ parent::__construct($array, ArrayObject::ARRAY_AS_PROPS); + //@@TODO: some checks should not be done on each and every request! + // this can be a problem when testing $this->checkRequiredValues(); } @@ -276,7 +278,7 @@ */ public function getSuperAdminName() { - if (isset($this->admin['user'])) { + if (isset($this->admin) && isset($this->admin['user'])) { return $this->admin['user']; } } @@ -288,7 +290,7 @@ */ protected function getSuperAdminPassword() { - if (isset($this->admin['pwd'])) { + if (isset($this->admin) && isset($this->admin['pwd'])) { return $this->admin['pwd']; } } Modified: trunk/library/classes/Gems/TabForm.php =================================================================== --- trunk/library/classes/Gems/TabForm.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/TabForm.php 2011-12-01 15:26:53 UTC (rev 326) @@ -60,18 +60,22 @@ if ($this->currentTab && !($element instanceof Zend_Form_Element_Hidden)) { return $this->currentTab->addElement($element, $name, $options); } else { + parent::addElement($element, $name, $options); + if (is_string($element)) { + $element = $this->getElement($element); + } if ($element instanceof Zend_Form_Element_Hidden) { //Remove decorators $element->removeDecorator('htmlTag'); $element->removeDecorator('Label'); - } else { + } elseif ($element instanceof Zend_Form_Element) { $error = $element->getDecorator('Errors'); if ($error instanceof Zend_Form_Decorator_Errors) { $element->removeDecorator('Errors'); $element->addDecorator($error); } } - return parent::addElement($element, $name, $options); + return $this; } } @@ -337,6 +341,13 @@ * @return Gems_TabForm */ public function setView(Zend_View_Interface $view = null) { + /** + * If the form is populated... and we have a tab set... select it + */ + if ($tab = $this->getValue('tab')) { + $this->selectTab($tab); + } + $form = parent::setView($view); if ($view) { Modified: trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php =================================================================== --- trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Tracker/Engine/TrackEngineAbstract.php 2011-12-01 15:26:53 UTC (rev 326) @@ -702,7 +702,7 @@ $model->set('gro_id_track', 'label', $this->_('Track'), 'elementClass', 'exhibitor', 'multiOptions', MUtil_Lazy::call($this->util->getTrackData()->getAllTracks)); } - $model->set('gro_id_survey', 'label', $this->_('Survey'), 'multiOptions', $this->util->getTrackData()->getAllSurveys()); + $model->set('gro_id_survey', 'label', $this->_('Survey'), 'multiOptions', $this->util->getTrackData()->getAllSurveysAndDescriptions()); $model->set('gro_id_order', 'label', $this->_('Order'), 'default', 10, 'validators[]', $model->createUniqueValidator(array('gro_id_order', 'gro_id_track'))); $model->set('gro_round_description', 'label', $this->_('Description'), 'size', '30'); //, 'minlength', 4, 'required', true); $model->set('gro_changed_event', 'label', $this->_('After change'), 'multiOptions', $this->events->listRoundChangedEvents()); Modified: trunk/library/classes/Gems/Tracker/Survey.php =================================================================== --- trunk/library/classes/Gems/Tracker/Survey.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Tracker/Survey.php 2011-12-01 15:26:53 UTC (rev 326) @@ -1,5 +1,4 @@ <?php - /** * Copyright (c) 2011, Erasmus MC * All rights reserved. @@ -262,7 +261,16 @@ return $source->getDatesList($language, $this->_surveyId, $this->_gemsSurvey['gsu_surveyor_id']); } + /** + * + * @return string Description of the survey + */ + public function getDescription() + { + return $this->_gemsSurvey['gsu_survey_description']; + } + /** * * @return int Gems group id for survey Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/User/Organization.php 2011-12-01 15:26:53 UTC (rev 326) @@ -77,22 +77,6 @@ protected $db; /** - * Returns a callable if a method is called as a variable - * or the value from the organizationData if it exists - * - * @param string $name - * @return Callable - */ - public function __get($name) - { - if (isset($this->_data[$name])) { - return $this->_data[$name]; - } - - return parent::__get($name); - } - - /** * Set menu parameters from the organization * * @param Gems_Menu_ParameterSource $source @@ -122,6 +106,22 @@ { return (boolean) $this->_get('gor_has_respondents') || $this->_get('gor_add_respondents'); } + + /** + * Returns the $key in organizationData when set otherwise the default value + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function get($key, $default = null) + { + if (array_key_exists($key, $this->_data)) { + return $this->_data[$key]; + } else { + return $default; + } + } /** * Get the organizations this organizations can access. Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-12-01 15:26:53 UTC (rev 326) @@ -189,7 +189,7 @@ list($defName, $userOrganization) = $this->getUserClassInfo($login_name, $currentOrganization); // MUtil_Echo::track($defName, $userOrganization); - $definition = $this->_getClass($defName); + $definition = $this->getUserDefinition($defName); $values = $definition->getUserData($login_name, $userOrganization); // MUtil_Echo::track($defName, $login_name, $userOrganization, $values); @@ -208,6 +208,20 @@ } /** + * Retrieve a userdefinition, so we can check it's capabilities without + * instantiating a user + * + * @param type $userClassName + * @return Gems_User_UserDefinitionInterface + */ + public function getUserDefinition($userClassName) + { + $definition = $this->_getClass($userClassName); + + return $definition; + } + + /** * Get a staff user using the $staff_id * * @param int $staff_id Modified: trunk/library/classes/Gems/Util/TrackData.php =================================================================== --- trunk/library/classes/Gems/Util/TrackData.php 2011-12-01 15:14:59 UTC (rev 325) +++ trunk/library/classes/Gems/Util/TrackData.php 2011-12-01 15:26:53 UTC (rev 326) @@ -95,6 +95,13 @@ return $surveys; } // */ + + /** + * Retrieve an array of key/value pairs for gsu_id_survey and gsu_survey_name + * + * @staticvar array $surveys + * @return array + */ public function getAllSurveys() { static $surveys; @@ -107,6 +114,23 @@ } /** + * Retrieve an array of key/value pairs for gsu_id_survey and gsu_survey_name plus gsu_survey_description + * + * @staticvar array $surveys + * @return array + */ + public function getAllSurveysAndDescriptions() + { + static $surveys; + + if (! $surveys) { + $surveys = $this->db->fetchPairs('SELECT gsu_id_survey, LEFT(CONCAT_WS(" - ", gsu_survey_name, gsu_survey_description),50) FROM gems__surveys ORDER BY gsu_survey_name'); + } + + return $surveys; + } + + /** * Returns array (id => name) of all tracks, sorted alphabetically * @return array */ Deleted: trunk/library/classes/Zend/Translate/Adapter.php =================================================================== --- branches/userloader/classes/Zend/Translate/Adapter.php 2011-12-01 14:57:08 UTC (rev 324) +++ trunk/library/classes/Zend/Translate/Adapter.php 2011-12-01 15:26:53 UTC (rev 326) @@ -1,999 +0,0 @@ -<?php -/** - * Zend Framework - * - * LICENSE - * - * This source file is subject to the new BSD license that is bundled - * with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * http://framework.zend.com/license/new-bsd - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to li...@ze... so we can send you a copy immediately. - * - * @category Zend - * @package Zend_Translate - * @subpackage Zend_Translate_Adapter - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Adapter.php 24268 2011-07-25 14:47:42Z guilhermeblanco $ - */ - -/** - * @see Zend_Locale - */ -require_once 'Zend/Locale.php'; - -/** - * @see Zend_Translate_Plural - */ -require_once 'Zend/Translate/Plural.php'; - -/** - * Basic adapter class for each translation source adapter - * - * THIS CLASS IS ALTERED FOR THE GEMSTRACKER PROJECT TO NEVER CACHE THE OPTIONS AS THEY CHANGE - * ON EVERY REQUEST AND THIS COUSES TROUBLE AS DESCRIBED AND IGNORED BY ZEND IN - * http://framework.zend.com/issues/browse/ZF-9850 - * - * @category Zend - * @package Zend_Translate - * @subpackage Zend_Translate_Adapter - * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License - */ -abstract class Zend_Translate_Adapter { - /** - * Shows if locale detection is in automatic level - * @var boolean - */ - private $_automatic = true; - - /** - * Internal value to see already routed languages - * @var array() - */ - private $_routed = array(); - - /** - * Internal cache for all adapters - * @var Zend_Cache_Core - */ - protected static $_cache = null; - - /** - * Internal value to remember if cache supports tags - * - * @var boolean - */ - private static $_cacheTags = false; - - /** - * Scans for the locale within the name of the directory - * @constant integer - */ - const LOCALE_DIRECTORY = 'directory'; - - /** - * Scans for the locale within the name of the file - * @constant integer - */ - const LOCALE_FILENAME = 'filename'; - - /** - * Array with all options, each adapter can have own additional options - * 'clear' => when true, clears already loaded translations when adding new files - * 'content' => content to translate or file or directory with content - * 'disableNotices' => when true, omits notices from being displayed - * 'ignore' => a prefix for files and directories which are not being added - * 'locale' => the actual set locale to use - * 'log' => a instance of Zend_Log where logs are written to - * 'logMessage' => message to be logged - * 'logPriority' => priority which is used to write the log message - * 'logUntranslated' => when true, untranslated messages are not logged - * 'reload' => reloads the cache by reading the content again - * 'scan' => searches for translation files using the LOCALE constants - * 'tag' => tag to use for the cache - * - * @var array - */ - protected $_options = array( - 'clear' => false, - 'content' => null, - 'disableNotices' => false, - 'ignore' => '.', - 'locale' => 'auto', - 'log' => null, - 'logMessage' => "Untranslated message within '%locale%': %message%", - 'logPriority' => 5, - 'logUntranslated' => false, - 'reload' => false, - 'route' => null, - 'scan' => null, - 'tag' => 'Zend_Translate' - ); - - /** - * Translation table - * @var array - */ - protected $_translate = array(); - - /** - * Generates the adapter - * - * @param array|Zend_Config $options Translation options for this adapter - * @throws Zend_Translate_Exception - * @return void - */ - public function __construct($options = array()) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (func_num_args() > 1) { - $args = func_get_args(); - $options = array(); - $options['content'] = array_shift($args); - - if (!empty($args)) { - $options['locale'] = array_shift($args); - } - - if (!empty($args)) { - $opt = array_shift($args); - $options = array_merge($opt, $options); - } - } else if (!is_array($options)) { - $options = array('content' => $options); - } - - if (array_key_exists('cache', $options)) { - self::setCache($options['cache']); - unset($options['cache']); - } - - /*if (isset(self::$_cache)) { - $id = 'Zend_Translate_' . $this->toString() . '_Options'; - $result = self::$_cache->load($id); - if ($result) { - $this->_options = $result; - } - }*/ - - if (empty($options['locale']) || ($options['locale'] === "auto")) { - $this->_automatic = true; - } else { - $this->_automatic = false; - } - - $locale = null; - if (!empty($options['locale'])) { - $locale = $options['locale']; - unset($options['locale']); - } - - $this->setOptions($options); - $options['locale'] = $locale; - - if (!empty($options['content'])) { - $this->addTranslation($options); - } - - if ($this->getLocale() !== (string) $options['locale']) { - $this->setLocale($options['locale']); - } - } - - /** - * Add translations - * - * This may be a new language or additional content for an existing language - * If the key 'clear' is true, then translations for the specified - * language will be replaced and added otherwise - * - * @param array|Zend_Config $options Options and translations to be added - * @throws Zend_Translate_Exception - * @return Zend_Translate_Adapter Provides fluent interface - */ - public function addTranslation($options = array()) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (func_num_args() > 1) { - $args = func_get_args(); - $options = array(); - $options['content'] = array_shift($args); - - if (!empty($args)) { - $options['locale'] = array_shift($args); - } - - if (!empty($args)) { - $opt = array_shift($args); - $options = array_merge($opt, $options); - } - } else if (!is_array($options)) { - $options = array('content' => $options); - } - - if (!isset($options['content']) || empty($options['content'])) { - require_once 'Zend/Translate/Exception.php'; - throw new Zend_Translate_Exception("Required option 'content' is missing"); - } - - $originate = null; - if (!empty($options['locale'])) { - $originate = (string) $options['locale']; - } - - if ((array_key_exists('log', $options)) && !($options['log'] instanceof Zend_Log)) { - require_once 'Zend/Translate/Exception.php'; - throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log'); - } - - try { - if (!($options['content'] instanceof Zend_Translate) && !($options['content'] instanceof Zend_Translate_Adapter)) { - if (empty($options['locale'])) { - $options['locale'] = null; - } - - $options['locale'] = Zend_Locale::findLocale($options['locale']); - } - } catch (Zend_Locale_Exception $e) { - require_once 'Zend/Translate/Exception.php'; - throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e); - } - - $options = $options + $this->_options; - if (is_string($options['content']) and is_dir($options['content'])) { - $options['content'] = realpath($options['content']); - $prev = ''; - $iterator = new RecursiveIteratorIterator( - new RecursiveRegexIterator( - new RecursiveDirectoryIterator($options['content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME), - '/^(?!.*(\.svn|\.cvs)).*$/', RecursiveRegexIterator::MATCH - ), - RecursiveIteratorIterator::SELF_FIRST - ); - - foreach ($iterator as $directory => $info) { - $file = $info->getFilename(); - if (is_array($options['ignore'])) { - foreach ($options['ignore'] as $key => $ignore) { - if (strpos($key, 'regex') !== false) { - if (preg_match($ignore, $directory)) { - // ignore files matching the given regex from option 'ignore' and all files below - continue 2; - } - } else if (strpos($directory, DIRECTORY_SEPARATOR . $ignore) !== false) { - // ignore files matching first characters from option 'ignore' and all files below - continue 2; - } - } - } else { - if (strpos($directory, DIRECTORY_SEPARATOR . $options['ignore']) !== false) { - // ignore files matching first characters from option 'ignore' and all files below - continue; - } - } - - if ($info->isDir()) { - // pathname as locale - if (($options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale($file, true, false))) { - $options['locale'] = $file; - $prev = (string) $options['locale']; - } - } else if ($info->isFile()) { - // filename as locale - if ($options['scan'] === self::LOCALE_FILENAME) { - $filename = explode('.', $file); - array_pop($filename); - $filename = implode('.', $filename); - if (Zend_Locale::isLocale((string) $filename, true, false)) { - $options['locale'] = (string) $filename; - } else { - $parts = explode('.', $file); - $parts2 = array(); - foreach($parts as $token) { - $parts2 += explode('_', $token); - } - $parts = array_merge($parts, $parts2); - $parts2 = array(); - foreach($parts as $token) { - $parts2 += explode('-', $token); - } - $parts = array_merge($parts, $parts2); - $parts = array_unique($parts); - $prev = ''; - foreach($parts as $token) { - if (Zend_Locale::isLocale($token, true, false)) { - if (strlen($prev) <= strlen($token)) { - $options['locale'] = $token; - $prev = $token; - } - } - } - } - } - - try { - $options['content'] = $info->getPathname(); - $this->_addTranslationData($options); - } catch (Zend_Translate_Exception $e) { - // ignore failed sources while scanning - } - } - } - - unset($iterator); - } else { - $this->_addTranslationData($options); - } - - if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) { - $this->setLocale($originate); - } - - return $this; - } - - /** - * Sets new adapter options - * - * @param array $options Adapter options - * @throws Zend_Translate_Exception - * @return Zend_Translate_Adapter Provides fluent interface - */ - public function setOptions(array $options = array()) - { - $change = false; - $locale = null; - foreach ($options as $key => $option) { - if ($key == 'locale') { - $locale = $option; - } else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or - !isset($this->_options[$key])) { - if (($key == 'log') && !($option instanceof Zend_Log)) { - require_once 'Zend/Translate/Exception.php'; - throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log'); - } - - if ($key == 'cache') { - self::setCache($option); - continue; - } - - $this->_options[$key] = $option; - $change = true; - } - } - - if ($locale !== null) { - $this->setLocale($locale); - } - - /*if (isset(self::$_cache) and ($change == true)) { - $id = 'Zend_Translate_' . $this->toString() . '_Options'; - if (self::$_cacheTags) { - self::$_cache->save($this->_options, $id, array($this->_options['tag'])); - } else { - self::$_cache->save($this->_options, $id); - } - }*/ - - return $this; - } - - /** - * Returns the adapters name and it's options - * - * @param string|null $optionKey String returns this option - * null returns all options - * @return integer|string|array|null - */ - public function getOptions($optionKey = null) - { - if ($optionKey === null) { - return $this->_options; - } - - if (isset($this->_options[$optionKey]) === true) { - return $this->_options[$optionKey]; - } - - return null; - } - - /** - * Gets locale - * - * @return Zend_Locale|string|null - */ - public function getLocale() - { - return $this->_options['locale']; - } - - /** - * Sets locale - * - * @param string|Zend_Locale $locale Locale to set - * @throws Zend_Translate_Exception - * @return Zend_Translate_Adapter Provides fluent interface - */ - public function setLocale($locale) - { - if (($locale === "auto") or ($locale === null)) { - $this->_automatic = true; - } else { - $this->_automatic = false; - } - - try { - $locale = Zend_Locale::findLocale($locale); - } catch (Zend_Locale_Exception $e) { - require_once 'Zend/Translate/Exception.php'; - throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist", 0, $e); - } - - if (!isset($this->_translate[$locale])) { - $temp = explode('_', $locale); - if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) { - if (!$this->_options['disableNotices']) { - if ($this->_options['log']) { - $this->_options['log']->log("The language '{$locale}' has to be added before it can be used.", $this->_options['logPriority']); - } else { - trigger_error("The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE); - } - } - } - - $locale = $temp[0]; - } - - if (empty($this->_translate[$locale])) { - if (!$this->_options['disableNotices']) { - if ($this->_options['log']) { - $this->_options['log']->log("No translation for the language '{$locale}' available.", $this->_options['logPriority']); - } else { - trigger_error("No translation for the language '{$locale}' available.", E_USER_NOTICE); - } - } - } - - if ($this->_options['locale'] != $locale) { - $this->_options['locale'] = $locale; - - /*if (isset(self::$_cache)) { - $id = 'Zend_Translate_' . $this->toString() . '_Options'; - if (self::$_cacheTags) { - self::$_cache->save($this->_options, $id, array($this->_options['tag'])); - } else { - self::$_cache->save($this->_options, $id); - } - }*/ - } - - return $this; - } - - /** - * Returns the available languages from this adapter - * - * @return array|null - */ - public function getList() - { - $list = array_keys($this->_translate); - $result = null; - foreach($list as $value) { - if (!empty($this->_translate[$value])) { - $result[$value] = $value; - } - } - return $result; - } - - /** - * Returns the message id for a given translation - * If no locale is given, the actual language will be used - * - * @param string $message Message to get the key for - * @param string|Zend_Locale $locale (optional) Language to return the message ids from - * @return string|array|false - */ - public function getMessageId($message, $locale = null) - { - if (empty($locale) or !$this->isAvailable($locale)) { - $locale = $this->_options['locale']; - } - - return array_search($message, $this->_translate[(string) $locale]); - } - - /** - * Returns all available message ids from this adapter - * If no locale is given, the actual language will be used - * - * @param string|Zend_Locale $locale (optional) Language to return the message ids from - * @return array - */ - public function getMessageIds($locale = null) - { - if (empty($locale) or !$this->isAvailable($locale)) { - $locale = $this->_options['locale']; - } - - return array_keys($this->_translate[(string) $locale]); - } - - /** - * Returns all available translations from this adapter - * If no locale is given, the actual language will be used - * If 'all' is given the complete translation dictionary will be returned - * - * @param string|Zend_Locale $locale (optional) Language to return the messages from - * @return array - */ - public function getMessages($locale = null) - { - if ($locale === 'all') { - return $this->_translate; - } - - if ((empty($locale) === true) or ($this->isAvailable($locale) === false)) { - $locale = $this->_options['locale']; - } - - return $this->_translate[(string) $locale]; - } - - /** - * Is the wished language available ? - * - * @see Zend_Locale - * @param string|Zend_Locale $locale Language to search for, identical with locale identifier, - * @see Zend_Locale for more information - * @return boolean - */ - public function isAvailable($locale) - { - $return = isset($this->_translate[(string) $locale]); - return $return; - } - - /** - * Load translation data - * - * @param mixed $data - * @param string|Zend_Locale $locale - * @param array $options (optional) - * @return array - */ - abstract protected function _loadTranslationData($data, $locale, array $options = array()); - - /** - * Internal function for adding translation data - * - * This may be a new language or additional data for an existing language - * If the options 'clear' is true, then the translation data for the specified - * language is replaced and added otherwise - * - * @see Zend_Locale - * @param array|Zend_Config $content Translation data to add - * @throws Zend_Translate_Exception - * @return Zend_Translate_Adapter Provides fluent interface - */ - private function _addTranslationData($options = array()) - { - if ($options instanceof Zend_Config) { - $options = $options->toArray(); - } else if (func_num_args() > 1) { - $args = func_get_args(); - $options['content'] = array_shift($args); - - if (!empty($args)) { - $options['locale'] = array_shift($args); - } - - if (!empty($args)) { - $options += array_shift($args); - } - } - - if (($options['content'] instanceof Zend_Translate) || ($options['content'] instanceof Zend_Translate_Adapter)) { - $options['usetranslateadapter'] = true; - if (!empty($options['locale']) && ($options['locale'] !== 'auto')) { - $options['content'] = $options['content']->getMessages($options['locale']); - } else { - $content = $options['content']; - $locales = $content->getList(); - foreach ($locales as $locale) { - $options['locale'] = $locale; - $options['content'] = $content->getMessages($locale); - $this->_addTranslationData($options); - } - - return $this; - } - } - - try { - $options['locale'] = Zend_Locale::findLocale($options['locale']); - } catch (Zend_Locale_Exception $e) { - require_once 'Zend/Translate/Exception.php'; - throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e); - } - - if ($options['clear'] || !isset($this->_translate[$options['locale']])) { - $this->_translate[$options['locale']] = array(); - } - - $read = true; - if (isset(self::$_cache)) { - $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString(); - $temp = self::$_cache->load($id); - if ($temp) { - $read = false; - } - } - - if ($options['reload']) { - $read = true; - } - - if ($read) { - if (!empty($options['usetranslateadapter'])) { - $temp = array($options['locale'] => $options['content']); - } else { - $temp = $this->_loadTranslationData($options['content'], $options['locale'], $options); - } - } - - if (empty($temp)) { - $temp = array(); - } - - $keys = array_keys($temp); - foreach($keys as $key) { - if (!isset($this->_translate[$key])) { - $this->_translate[$key] = array(); - } - - if (array_key_exists($key, $temp) && is_array($temp[$key])) { - $this->_translate[$key] = $temp[$key] + $this->_translate[$key]; - } - } - - if ($this->_automatic === true) { - $find = new Zend_Locale($options['locale']); - $browser = $find->getEnvironment() + $find->getBrowser(); - arsort($browser); - foreach($browser as $language => $quality) { - if (isset($this->_translate[$language])) { - $this->_options['locale'] = $language; - break; - } - } - } - - if (($read) and (isset(self::$_cache))) { - $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString(); - if (self::$_cacheTags) { - self::$_cache->save($temp, $id, array($this->_options['tag'])); - } else { - self::$_cache->save($temp, $id); - } - } - - return $this; - } - - /** - * Translates the given string - * returns the translation - * - * @see Zend_Locale - * @param string|array $messageId Translation string, or Array for plural translations - * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with - * locale identifier, @see Zend_Locale for more information - * @return string - */ - public function translate($messageId, $locale = null) - { - if ($locale === null) { - $locale = $this->_options['locale']; - } - - $plural = null; - if (is_array($messageId)) { - if (count($messageId) > 2) { - $number = array_pop($messageId); - if (!is_numeric($number)) { - $plocale = $number; - $number = array_pop($messageId); - } else { - $plocale = 'en'; - } - - $plural = $messageId; - $messageId = $messageId[0]; - } else { - $messageId = $messageId[0]; - } - } - - if (!Zend_Locale::isLocale($locale, true, false)) { - if (!Zend_Locale::isLocale($locale, false, false)) { - // language does not exist, return original string - $this->_log($messageId, $locale); - // use rerouting when enabled - if (!empty($this->_options['route'])) { - if (array_key_exists($locale, $this->_options['route']) && - !array_key_exists($locale, $this->_routed)) { - $this->_routed[$locale] = true; - return $this->translate($messageId, $this->_options['route'][$locale]); - } - } - - $this->_routed = array(); - if ($plural === null) { - return $messageId; - } - - $rule = Zend_Translate_Plural::getPlural($number, $plocale); - if (!isset($plural[$rule])) { - $rule = 0; - } - - return $plural[$rule]; - } - - $locale = new Zend_Locale($locale); - } - - $locale = (string) $locale; - if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) { - // return original translation - if ($plural === null) { - $this->_routed = array(); - return $this->_translate[$locale][$messageId]; - } - - $rule = Zend_Translate_Plural::getPlural($number, $locale); - if (isset($this->_translate[$locale][$plural[0]][$rule])) { - $this->_routed = array(); - return $this->_translate[$locale][$plural[0]][$rule]; - } - } else if (strlen($locale) != 2) { - // faster than creating a new locale and separate the leading part - $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); - - if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) { - // return regionless translation (en_US -> en) - if ($plural === null) { - $this->_routed = array(); - return $this->_translate[$locale][$messageId]; - } - - $rule = Zend_Translate_Plural::getPlural($number, $locale); - if (isset($this->_translate[$locale][$plural[0]][$rule])) { - $this->_routed = array(); - return $this->_translate[$locale][$plural[0]][$rule]; - } - } - } - - $this->_log($messageId, $locale); - // use rerouting when enabled - if (!empty($this->_options['route'])) { - if (array_key_exists($locale, $this->_options['route']) && - !array_key_exists($locale, $this->_routed)) { - $this->_routed[$locale] = true; - return $this->translate($messageId, $this->_options['route'][$locale]); - } - } - - $this->_routed = array(); - if ($plural === null) { - return $messageId; - } - - $rule = Zend_Translate_Plural::getPlural($number, $plocale); - if (!isset($plural[$rule])) { - $rule = 0; - } - - return $plural[$rule]; - } - - /** - * Translates the given string using plural notations - * Returns the translated string - * - * @see Zend_Locale - * @param string $singular Singular translation string - * @param string $plural Plural translation string - * @param integer $number Number for detecting the correct plural - * @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with - * locale identifier, @see Zend_Locale for more information - * @return string - */ - public function plural($singular, $plural, $number, $locale = null) - { - return $this->translate(array($singular, $plural, $number), $locale); - } - - /** - * Logs a message when the log option is set - * - * @param string $message Message to log - * @param String $locale Locale to log - */ - protected function _log($message, $locale) { - if ($this->_options['logUntranslated']) { - $message = str_replace('%message%', $message, $this->_options['logMessage']); - $message = str_replace('%locale%', $locale, $message); - if ($this->_options['log']) { - $this->_options['log']->log($message, $this->_options['logPriority']); - } else { - trigger_error($message, E_USER_NOTICE); - } - } - } - - /** - * Translates the given string - * returns the translation - * - * @param string $messageId Translation string - * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale - * identifier, @see Zend_Locale for more information - * @return string - */ - public function _($messageId, $locale = null) - { - return $this->translate($messageId, $locale); - } - - /** - * Checks if a string is translated within the source or not - * returns boolean - * - * @param string $messageId Translation string - * @param boolean $original (optional) Allow translation only for original language - * when true, a translation for 'en_US' would give false when it can - * be translated with 'en' only - * @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale identifier, - * see Zend_Locale for more information - * @return boolean - */ - public function isTranslated($messageId, $original = false, $locale = null) - { - if (($original !== false) and ($original !== true)) { - $locale = $original; - $original = false; - } - - if ($locale === null) { - $locale = $this->_options['locale']; - } - - if (!Zend_Locale::isLocale($locale, true, false)) { - if (!Zend_Locale::isLocale($locale, false, false)) { - // language does not exist, return original string - return false; - } - - $locale = new Zend_Locale($locale); - } - - $locale = (string) $locale; - if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) { - // return original translation - return true; - } else if ((strlen($locale) != 2) and ($original === false)) { - // faster than creating a new locale and separate the leading part - $locale = substr($locale, 0, -strlen(strrchr($locale, '_'))); - - if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) { - // return regionless translation (en_US -> en) - return true; - } - } - - // No translation found, return original - return false; - } - - /** - * Returns the set cache - * - * @return Zend_Cache_Core The set cache - */ - public static function getCache() - { - return self::$_cache; - } - - /** - * Sets a cache for all Zend_Translate_Adapters - * - * @param Zend_Cache_Core $cache Cache to store to - */ - public static function setCache(Zend_Cache_Core $cache) - { - self::$_cache = $cache; - self::_getTagSupportForCache(); - } - - /** - * Returns true when a cache is set - * - * @return boolean - */ - public static function hasCache() - { - if (self::$_cache !== null) { - return true; - } - - return false; - } - - /** - * Removes any set cache - * - * @return void - */ - public static function removeCache() - { - self::$_cache = null; - } - - /** - * Clears all set cache data - * - * @param string $tag Tag to clear when the default tag name is not used - * @return void - */ - public static function clearCache($tag = null) - { - require_once 'Zend/Cache.php'; - if (self::$_cacheTags) { - if ($tag == null) { - $tag = 'Zend_Translate'; - } - - self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array($tag)); - } else { - self::$_cache->clean(Zend_Cache::CLEANING_MODE_ALL); - } - } - - /** - * Returns the adapter name - * - * @return string - */ - abstract public function toString(); - - /** - * Internal method to check if the given cache supports tags - * - * @param Zend_Cache $cache - */ - private static function _getTagSupportForCache() - { - $backend = self::$_cache->getBackend(); - if ($backend instanceof Zend_Cache_Backend_ExtendedInterface) { - $cacheOptions = $backend->getCapabilities(); - self::$_cacheTags = $cacheOptions['tags']; - } else { - self::$_cacheTags = false; - } - - return self::$_cacheTags; - } -} \ No newline at end of file Copied: trunk/library/classes/Zend/Translate/Adapter.php (from rev 324, branches/userloader/classes/Zend/Translate/Adapter.php) =================================================================== --- trunk/library/classes/Zend/Translate/Adapter.php (rev 0) +++ trunk/library/classes/Zend/Translate/Adapter.php 2011-12-01 15:26:53 UTC (rev 326) @@ -0,0 +1,999 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to li...@ze... so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Translate + * @subpackage Zend_Translate_Adapter + * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id: Adapter.php 24268 2011-07-25 14:47:42Z guilhermeblanco $ + */ + +/** + * @see Zend_Locale + */ +require_once 'Zend/Locale.php'; + +/** + * @see Zend_Translate_Plural + */ +require_once 'Zend/Translate/Plural.php'; + +/** + * Basic adapter class for each translation source adapter + * + * THIS CLASS IS ALTERED FOR THE GEMSTRACKER PROJECT TO NEVER CACHE THE OPTIONS AS THEY CHANGE + * ON EVERY REQUEST AND THIS COUSES TROUBLE AS DESCRIBED AND IGNORED BY ZEND IN + * http://framework.zend.com/issues/browse/ZF-9850 + * + * @category Zend + * @package Zend_Translate + * @subpackage Zend_Translate_Adapter + * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_Translate_Adapter { + /** + * Shows if locale detection is in automatic level + * @var boolean + */ + private $_automatic = true; + + /** + * Internal value to see already routed languages + * @var array() + */ + private $_routed = array(); + + /** + * Internal cache for all adapters + * @var Zend_Cache_Core + */ + protected static $_cache = null; + + /** + * Internal value to remember if cache supports tags + * + * @var boolean + */ + private static $_cacheTags = false; + + /** + * Scans for the locale within the name of the directory + * @constant integer + */ + const LOCALE_DIRECTORY = 'directory'; + + /** + * Scans for the locale within the name of the file + * @constant integer + */ + const LOCALE_FILENAME = 'filename'; + + /** + * Array with all options, each adapter can have own additional options + * 'clear' => when true, clears already loaded translations when adding new files + * 'content' => content to translate or file or directory with content + * 'disableNotices' => when true, omits notices from being displayed + * 'ignore' => a prefix for files and directories which are not being added + * 'locale' => the actual set locale to use + * 'log' => a instance of Zend_Log where logs are written to + * 'logMessage' => message to be logged + * 'logPriority' => priority which is used to write the log message + * 'logUntranslated' => when true, untranslated messages are not logged + * 'reload' => reloads the cache by reading the content again + * 'scan' => searches for translation files using the LOCALE constants + * 'tag' => tag to use for the cache + * + * @var array + */ + protected $_options = array( + 'clear' => false, + 'content' => null, + 'disableNotices' => false, + 'ignore' => '.', + 'locale' => 'auto', + 'log' => null, + 'logMessage' => "Untranslated message within '%locale%': %message%", + 'logPriority' => 5, + 'logUntranslated' => false, + 'reload' => false, + 'route' => null, + 'scan' => null, + 'tag' => 'Zend_Translate' + ); + + /** + * Translation table + * @var array + */ + protected $_translate = array(); + + /** + * Generates the adapter + * + * @param array|Zend_Config $options Translation options for this adapter + * @throws Zend_Translate_Exception + * @return void + */ + public function __construct($options = array()) + { + if ($options instanceof Zend_Config) { + $options = $options->toArray(); + } else if (func_num_args() > 1) { + $args = func_get_args(); + $options = array(); + $options['content'] = array_shift($args); + + if (!empty($args)) { + $options['locale'] = array_shift($args); + } + + if (!empty($args)) { + $opt = array_shift($args); + $options = array_merge($opt, $options); + } + } else if (!is_array($options)) { + $options = array('content' => $options); + } + + if (array_key_exists('cache', $options)) { + self::setCache($options['cache']); + unset($options['cache']); + } + + /*if (isset(self::$_cache)) { + $id = 'Zend_Translate_' . $this->toString() . '_Options'; + $result = self::$_cache->load($id); + if ($result) { + $this->_options = $result; + } + }*/ + + if (empty($options['locale']) || ($options['locale'] === "auto")) { + $this->_automatic = true; + } else { + $this->_automatic = false; + } + + $locale = null; + if (!empty($options['locale'])) { + $locale = $options['locale']; + unset($options['locale']); + } + + $this->setOptions($options); + $options['locale'] = $locale; + + if (!empty($options['content'])) { + $this->addTranslation($options); + } + + if ($this->getLocale() !== (string) $options['locale']) { + $this->setLocale($options['locale']); + } + } + + /** + * Add translations + * + * This may be a new language or additional content for an existing language + * If the key 'clear' is true, then translations for the specified + * language will be replaced and ad... [truncated message content] |