/** * * @author Patrick Plichart, patrick@taotesting.com * @param array $propertiesValues * @throws \common_exception_MissingParameter * @throws \common_exception_PreConditionFailure * @return \core_kernel_classes_Resource */ public function createFromArray($propertiesValues = array()) { // mandatory parameters if (!isset($propertiesValues[PROPERTY_USER_LOGIN])) { throw new \common_exception_MissingParameter("login"); } if (!isset($propertiesValues[PROPERTY_USER_PASSWORD])) { throw new \common_exception_MissingParameter("password"); } // default values if (!isset($propertiesValues[PROPERTY_USER_UILG])) { $propertiesValues[PROPERTY_USER_UILG] = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG); } if (!isset($propertiesValues[PROPERTY_USER_DEFLG])) { $propertiesValues[PROPERTY_USER_DEFLG] = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG); } if (!isset($propertiesValues[RDFS_LABEL])) { $propertiesValues[RDFS_LABEL] = ""; } // check if login already exists $userService = \tao_models_classes_UserService::singleton(); if ($userService->loginExists($propertiesValues[PROPERTY_USER_LOGIN])) { throw new \common_exception_PreConditionFailure("login already exists"); } $propertiesValues[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($propertiesValues[PROPERTY_USER_PASSWORD]); $type = isset($propertiesValues[RDF_TYPE]) ? $propertiesValues[RDF_TYPE] : $this->getRootClass(); $label = $propertiesValues[RDFS_LABEL]; // hmmm unset($propertiesValues[RDFS_LABEL]); unset($propertiesValues[RDF_TYPE]); $resource = parent::create($label, $type, $propertiesValues); $this->getClassService()->setTestTakerRole($resource); return $resource; }
/** * Run the controller * * @param common_http_Request $pRequest * @throws \ActionEnforcingException * @throws \Exception * @throws \common_exception_Error * @throws \common_ext_ExtensionException */ public function legacy(common_http_Request $pRequest) { $resolver = new Resolver($pRequest); // load the responsible extension $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); \Context::getInstance()->setExtensionName($resolver->getExtensionId()); // load translations $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); \tao_helpers_I18n::init($ext, $uiLang); //if the controller is a rest controller we try to authenticate the user $controllerClass = $resolver->getControllerClass(); if (is_subclass_of($controllerClass, \tao_actions_RestController::class)) { $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest()); try { $user = $authAdapter->authenticate(); $session = new \common_session_RestSession($user); \common_session_SessionManager::startSession($session); } catch (\common_user_auth_AuthFailedException $e) { $data['success'] = false; $data['errorCode'] = '401'; $data['errorMsg'] = 'You are not authorized to access this functionality.'; $data['version'] = TAO_VERSION; header('HTTP/1.0 401 Unauthorized'); header('WWW-Authenticate: Basic realm="' . GENERIS_INSTANCE_NAME . '"'); echo json_encode($data); exit(0); } } try { $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $pRequest->getParams()); $enforcer->execute(); } catch (InterruptedActionException $iE) { // Nothing to do here. } }
/** * (non-PHPdoc) * @see FrontController::loadModule() */ public function loadModule() { $resolver = new Resolver($this->getRequest()); // load the responsible extension $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); \Context::getInstance()->setExtensionName($resolver->getExtensionId()); // load translations $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); \tao_helpers_I18n::init($ext, $uiLang); //if the controller is a rest controller we try to authenticate the user $controllerClass = $resolver->getControllerClass(); if (is_subclass_of($controllerClass, 'tao_actions_CommonRestModule')) { $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest()); try { $user = $authAdapter->authenticate(); $session = new \common_session_RestSession($user); \common_session_SessionManager::startSession($session); } catch (\common_user_auth_AuthFailedException $e) { $class = new $controllerClass(); $class->requireLogin(); } } try { $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $this->getRequest()->getParams()); $enforcer->execute(); } catch (InterruptedActionException $iE) { // Nothing to do here. } }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { $chainingElt = tao_helpers_form_FormFactory::getElement('chaining', 'Radiobox'); $chainingElt->setDescription(__('Filtering mode')); $chainingElt->setOptions(array('or' => __('Exclusive (OR)'), 'and' => __('Inclusive (AND)'))); $chainingElt->setValue('or'); $this->form->addElement($chainingElt); $recursiveElt = tao_helpers_form_FormFactory::getElement('recursive', 'Radiobox'); $recursiveElt->setDescription(__('Recursive')); $recursiveElt->setOptions(array('0' => __('Current class only'), '10' => __('Current class + Subclasses'))); $recursiveElt->setValue('current'); $this->form->addElement($recursiveElt); $langElt = tao_helpers_form_FormFactory::getElement('lang', 'Combobox'); $langElt->setDescription(__('Language')); $languages = array_merge(array(' '), tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA))); $langElt->setOptions($languages); $langElt->setValue(0); $this->form->addElement($langElt); $this->form->createGroup('params', __('Options'), array('chaining', 'recursive', 'lang')); $filters = array(); $descElt = tao_helpers_form_FormFactory::getElement('desc', 'Label'); $descElt->setValue(__('Use the * character to replace any string')); $this->form->addElement($descElt); $filters[] = 'desc'; $defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties(); $classProperties = tao_helpers_form_GenerisFormFactory::getClassProperties($this->clazz, $this->getTopClazz()); $properties = array_merge($defaultProperties, $classProperties); isset($this->options['recursive']) ? $recursive = $this->options['recursive'] : ($recursive = false); if ($recursive) { foreach ($this->clazz->getSubClasses(true) as $subClass) { $properties = array_merge($subClass->getProperties(false), $properties); } } foreach ($properties as $property) { $element = tao_helpers_form_GenerisFormFactory::elementMap($property); if (!is_null($element) && !$element instanceof tao_helpers_form_elements_Authoring && !$element instanceof tao_helpers_form_elements_Hiddenbox && !$element instanceof tao_helpers_form_elements_Hidden) { if ($element instanceof tao_helpers_form_elements_MultipleElement) { $newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Checkbox'); $newElement->setDescription($element->getDescription()); $newElement->setOptions($element->getOptions()); $element = $newElement; } if ($element instanceof tao_helpers_form_elements_Htmlarea) { $newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Textarea'); $newElement->setDescription($element->getDescription()); $element = $newElement; } $this->form->addElement($element); $filters[] = $element->getName(); } } $this->form->createGroup('filters', __('Filters'), $filters); }
/** * Initialize the form elements * * @access protected * @author Bertrand Chevrier, <*****@*****.**> * @return mixed */ protected function initElements() { parent::initElements(); $elements = $this->form->getElements(); $this->form->setElements(array()); $currentLangElt = tao_helpers_form_FormFactory::getElement('current_lang', 'Textbox'); $currentLangElt->setDescription(__('Current language')); $currentLangElt->setAttributes(array('readonly' => 'true')); $currentLangElt->setValue(\common_session_SessionManager::getSession()->getDataLanguage()); //API lang /data lang $this->form->addElement($currentLangElt); $dataLangElement = tao_helpers_form_FormFactory::getElement('translate_lang', 'Combobox'); $dataLangElement->setDescription(__('Translate to')); $dataLangElement->setOptions(tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA))); $dataLangElement->setEmptyOption(__('Select a language')); $dataLangElement->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $this->form->addElement($dataLangElement); $this->form->createGroup('translation_info', __('Translation parameters'), array('current_lang', 'translate_lang')); $dataGroup = array(); foreach ($elements as $element) { if ($element instanceof tao_helpers_form_elements_Hidden || $element->getName() == 'uri' || $element->getName() == 'classUri') { $this->form->addElement($element); } else { $propertyUri = tao_helpers_Uri::decode($element->getName()); $property = new core_kernel_classes_Property($propertyUri); //translate only language dependent properties or Labels //supported widget are: Textbox, TextArea, HtmlArea //@todo support other widgets if ($property->isLgDependent() && ($element instanceof tao_helpers_form_elements_Textbox || $element instanceof tao_helpers_form_elements_TextArea || $element instanceof tao_helpers_form_elements_HtmlArea) || $propertyUri == RDFS_LABEL) { $translatedElt = clone $element; $viewElt = tao_helpers_form_FormFactory::getElement('view_' . $element->getName(), 'Label'); $viewElt->setDescription($element->getDescription()); $viewElt->setValue($element->getValue()); $viewElt->setAttribute('no-format', true); if ($element instanceof tao_helpers_form_elements_HtmlArea) { $viewElt->setAttribute('htmlentities', false); } $this->form->addElement($viewElt); $dataGroup[] = $viewElt->getName(); $translatedElt->setDescription(' '); $translatedElt->setValue(''); if ($propertyUri == RDFS_LABEL) { $translatedElt->setForcedValid(); } $this->form->addElement($translatedElt); $dataGroup[] = $translatedElt->getName(); } } } $this->form->createGroup('translation_form', __('Translate'), $dataGroup); }
/** * Allows the remote system to change the data language * * @return string The json response * @throws common_Exception */ public function setDataLanguage() { $success = false; if (!$this->hasRequestParameter('lang')) { throw new common_Exception('Missing parameters'); } $user = $this->getCurrentUser(); $dataLangResource = tao_helpers_I18n::getLangResourceByCode($this->getRequestParameter('lang')); if (!is_null($dataLangResource)) { $success = $user->editPropertyValues(new core_kernel_classes_Property(PROPERTY_USER_DEFLG), $dataLangResource); common_Logger::w('Data language changed to "' . $this->getRequestParameter('lang') . '"'); } else { common_Logger::w('language ' . $this->getRequestParameter('lang') . ' not found'); return $this->returnFailure(__('Language not supported')); } $this->returnSuccess(); }
/** * Get the require.js' config file */ public function config() { $this->setContentHeader('application/javascript'); //get extension paths to set up aliases dynamically $extensionsAliases = ClientLibRegistry::getRegistry()->getLibAliasMap(); $this->setData('extensionsAliases', $extensionsAliases); $libConfigs = ClientLibConfigRegistry::getRegistry()->getMap(); $this->setData('libConfigs', $libConfigs); $extendedConfig = $this->getServiceManager()->get(ClientConfigService::SERVICE_ID)->getExtendedConfig(); foreach ($extendedConfig as $key => $value) { $this->setData($key, json_encode($value)); } $extensionManager = common_ext_ExtensionsManager::singleton(); $langCode = tao_helpers_I18n::getLangCode(); //loads the URLs context /** @var AssetService $assetService */ $assetService = ServiceManager::getServiceManager()->get(AssetService::SERVICE_ID); $tao_base_www = $assetService->getJsBaseWww('tao'); $extensionId = $this->hasRequestParameter('extension') ? $this->getRequestParameter('extension') : \Context::getInstance()->getExtensionName(); $extension = $extensionManager->getExtensionById($extensionId); $base_www = $assetService->getJsBaseWww($extensionId); $base_url = $extension->getConstant('BASE_URL'); //set contextual data $this->setData('locale', $langCode); if (strpos($langCode, '-') > 0) { $lang = strtolower(substr($langCode, 0, strpos($langCode, '-'))); } else { $lang = strtolower($langCode); } $this->setData('lang', $lang); $this->setData('version', TAO_VERSION); $this->setData('extension', $this->getRequestParameter('extension')); $this->setData('module', $this->getRequestParameter('module')); $this->setData('action', $this->getRequestParameter('action')); $this->setData('base_www', $base_www); $this->setData('tao_base_www', $tao_base_www); $this->setData('base_url', $base_url); $this->setData('shownExtension', $this->getRequestParameter('shownExtension')); $this->setData('shownStructure', $this->getRequestParameter('shownStructure')); $this->setData('client_timeout', $this->getClientTimeout()); $this->setView('client_config.tpl'); }
/** * Get the require.js' config file */ public function config() { $this->setContentHeader('application/javascript'); //get extension paths to set up aliases dynamically $extensionsAliases = ClientLibRegistry::getRegistry()->getLibAliasMap(); $this->setData('extensionsAliases', $extensionsAliases); $libConfigs = ClientLibConfigRegistry::getRegistry()->getMap(); $this->setData('libConfigs', $libConfigs); $themesAvailable = ThemeRegistry::getRegistry()->getAvailableThemes(); $this->setData('themesAvailable', $themesAvailable); $extensionManager = common_ext_ExtensionsManager::singleton(); $langCode = tao_helpers_I18n::getLangCode(); //loads the URLs context $base_www = BASE_WWW; $base_url = BASE_URL; if ($this->hasRequestParameter('extension')) { $extension = $extensionManager->getExtensionById($this->getRequestParameter('extension')); if (!is_null($extension)) { $base_www = $extension->getConstant('BASE_WWW'); $base_url = $extension->getConstant('BASE_URL'); } } //set contextual data $this->setData('locale', $langCode); if (strpos($langCode, '-') > 0) { $lang = strtolower(substr($langCode, 0, strpos($langCode, '-'))); } else { $lang = strtolower($langCode); } $this->setData('lang', $lang); $this->setData('extension', $this->getRequestParameter('extension')); $this->setData('module', $this->getRequestParameter('module')); $this->setData('action', $this->getRequestParameter('action')); $this->setData('base_www', $base_www); $this->setData('base_url', $base_url); $this->setData('shownExtension', $this->getRequestParameter('shownExtension')); $this->setData('shownStructure', $this->getRequestParameter('shownStructure')); $this->setData('client_timeout', $this->getClientTimeout()); $this->setView('client_config.tpl'); }
/** * Experimental convenience function * @return boolean */ function _isRtl() { return tao_helpers_I18n::isLanguageRightToLeft(common_session_SessionManager::getSession()->getInterfaceLanguage()); }
/** * Render the form to translate a Resource instance * @return void * @requiresRight id WRITE */ public function translateInstance() { $instance = $this->getCurrentInstance(); $formContainer = new tao_actions_form_Translate($this->getCurrentClass(), $instance); $myForm = $formContainer->getForm(); if ($this->hasRequestParameter('target_lang')) { $targetLang = $this->getRequestParameter('target_lang'); if (in_array($targetLang, tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA)))) { $langElt = $myForm->getElement('translate_lang'); $langElt->setValue($targetLang); $langElt->setAttribute('readonly', 'true'); $trData = $this->getClassService()->getTranslatedProperties($instance, $targetLang); foreach ($trData as $key => $value) { $element = $myForm->getElement(tao_helpers_Uri::encode($key)); if (!is_null($element)) { $element->setValue($value); } } } } if ($myForm->isSubmited()) { if ($myForm->isValid()) { $values = $myForm->getValues(); if (isset($values['translate_lang'])) { $datalang = common_session_SessionManager::getSession()->getDataLanguage(); $lang = $values['translate_lang']; $translated = 0; foreach ($values as $key => $value) { if (preg_match("/^http/", $key)) { $value = trim($value); $property = new core_kernel_classes_Property($key); if (empty($value)) { if ($datalang != $lang && $lang != '') { $instance->removePropertyValueByLg($property, $lang); } } else { if ($instance->editPropertyValueByLg($property, $value, $lang)) { $translated++; } } } } if ($translated > 0) { $this->setData('message', __('Translation saved')); } } } } $this->setData('myForm', $myForm->render()); $this->setData('formTitle', __('Translate')); $this->setView('form.tpl', 'tao'); }
/** * Initialize the internationalization * @see tao_helpers_I18n */ protected function i18n() { $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); tao_helpers_I18n::init($this->extension, $uiLang); }
/** * This method returns the languages available in TAO. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param boolean langName If set to true, an associative array where keys are language codes and values are language labels. If set to false (default), a simple array of language codes is returned. * @return array * @throws common_exception_InconsistentData */ private static function getAvailableLangs() { //get it into the api only once if (count(self::$availableLangs) == 0) { try { self::$availableLangs = common_cache_FileCache::singleton()->get(self::AVAILABLE_LANGS_CACHEKEY); } catch (common_cache_NotFoundException $e) { $langClass = new core_kernel_classes_Class(CLASS_LANGUAGES); $valueProperty = new core_kernel_classes_Property(RDF_VALUE); foreach ($langClass->getInstances() as $lang) { $values = $lang->getPropertiesValues(array(RDF_VALUE, PROPERTY_LANGUAGE_USAGES, PROPERTY_LANGUAGE_ORIENTATION)); if (count($values[RDF_VALUE]) != 1) { throw new common_exception_InconsistentData('Error with value of language ' . $lang->getUri()); } $value = current($values[RDF_VALUE])->__toString(); $usages = array(); foreach ($values[PROPERTY_LANGUAGE_USAGES] as $usage) { $usages[] = $usage->getUri(); } if (count($values[PROPERTY_LANGUAGE_ORIENTATION]) != 1) { common_Logger::w('Error with orientation of language ' . $lang->getUri()); $orientation = INSTANCE_ORIENTATION_LTR; } else { $orientation = current($values[PROPERTY_LANGUAGE_ORIENTATION])->getUri(); } self::$availableLangs[$value] = array('uri' => $lang->getUri(), PROPERTY_LANGUAGE_USAGES => $usages, PROPERTY_LANGUAGE_ORIENTATION => $orientation); } common_cache_FileCache::singleton()->put(self::$availableLangs, self::AVAILABLE_LANGS_CACHEKEY); } } return self::$availableLangs; }
/** * (non-PHPdoc) * @see tao_models_classes_import_CsvImporter::getStaticData() */ protected function getStaticData() { $lang = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG)->getUri(); return array(PROPERTY_USER_DEFLG => $lang, PROPERTY_USER_TIMEZONE => TIME_ZONE, PROPERTY_USER_ROLES => INSTANCE_ROLE_DELIVERY); }
/** * Action dedicated to change the settings of the user (language, ...) */ public function properties() { $myFormContainer = new tao_actions_form_UserSettings($this->getUserSettings()); $myForm = $myFormContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $currentUser = $this->userService->getCurrentUser(); $userSettings = array(PROPERTY_USER_UILG => $myForm->getValue('ui_lang'), PROPERTY_USER_DEFLG => $myForm->getValue('data_lang'), PROPERTY_USER_TIMEZONE => $myForm->getValue('timezone')); $uiLang = new core_kernel_classes_Resource($myForm->getValue('ui_lang')); $dataLang = new core_kernel_classes_Resource($myForm->getValue('data_lang')); $userSettings[PROPERTY_USER_UILG] = $uiLang->getUri(); $userSettings[PROPERTY_USER_DEFLG] = $dataLang->getUri(); $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($currentUser); if ($binder->bind($userSettings)) { \common_session_SessionManager::getSession()->refresh(); $uiLangCode = tao_models_classes_LanguageService::singleton()->getCode($uiLang); $extension = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); tao_helpers_I18n::init($extension, $uiLangCode); $this->setData('message', __('Settings updated')); $this->setData('reload', true); } } } $userLabel = $this->userService->getCurrentUser()->getLabel(); $this->setData('formTitle', sprintf(__("My settings (%s)"), __($userLabel))); $this->setData('myForm', $myForm->render()); //$this->setView('form.tpl'); $this->setView('form/settings_user.tpl'); }