/** * Returns a new LanguageQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return LanguageQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof LanguageQuery) { return $criteria; } $query = new LanguageQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
private function checkStrings($sCheckLanguageId = null) { $aAllStrings = array(); foreach (TranslationQuery::create()->orderByStringKey()->find() as $oString) { if (!in_array($oString->getStringKey(), $aAllStrings)) { $aAllStrings[] = $oString->getStringKey(); } } $aAllLanguages = array(); foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) { $aAllLanguages[$oLanguage->getId()] = $oLanguage->getLanguageName(); } foreach ($aAllStrings as $sStringKey) { foreach ($aAllLanguages as $sLanguageId => $sLanguageName) { if ($sCheckLanguageId && $sCheckLanguageId === $sLanguageId) { continue; } $oString = TranslationPeer::getString($sStringKey, $sLanguageId, self::$EMPTY_STRING_KEY); if ($oString === self::$EMPTY_STRING_KEY) { $sText = TranslationPeer::getString('wns.check.check_string_message', null, null, array('string_key' => $sStringKey, 'language_id' => $sLanguageId)); $this->log($sText, $sLanguageId, self::LOG_LEVEL_WARNING); } } } return $this->aLogMessages; }
public function deleteRow($aRowData, $oCriteria) { $oLanguage = LanguagePeer::doSelectOne($oCriteria); if ($oLanguage->getIsDefault()) { throw new LocalizedException('wns.language.delete_default.denied'); } if ($oLanguage->getIsDefaultEdit()) { throw new LocalizedException('wns.language.delete_default.denied'); } if (LanguagePeer::doCount(new Criteria()) < 2) { throw new LocalizedException('wns.language.delete_last.denied'); } $sLanguageId = $oLanguage->getId(); foreach (LanguageObjectQuery::create()->filterByLanguageId($sLanguageId)->find() as $oLanguageObject) { $oHistory = $oLanguageObject->newHistory(); $oHistory->save(); $oLanguageObject->delete(); } $iResult = $oLanguage->delete(); $oReplacementLanguage = LanguageQuery::create()->findOne(); if (AdminManager::getContentLanguage() === $sLanguageId) { AdminManager::setContentLanguage(Settings::getSetting("session_default", AdminManager::CONTENT_LANGUAGE_SESSION_KEY, $oReplacementLanguage->getId())); } if (Session::language() === $sLanguageId) { Session::getSession()->setLanguage(Settings::getSetting("session_default", Session::SESSION_LANGUAGE_KEY, $oReplacementLanguage->getId())); } }
public function listLanguages() { $aResult = array(); foreach (LanguageQuery::create()->orderBySort()->find() as $oLanguage) { $aResult[$oLanguage->getId()] = $oLanguage->getLanguageName(); } asort($aResult); return $aResult; }
/** {@inheritdoc} */ public function showMain() { $this->addMainMenu(); $configFile = Curry_Core::$config->curry->configPath; if (!$configFile) { $this->addMessage("Configuration file not set.", self::MSG_ERROR); } else { if (!is_writable($configFile)) { $this->addMessage("Configuration file doesn't seem to be writable.", self::MSG_ERROR); } } $config = new Zend_Config($configFile ? require $configFile : array(), true); $defaultConfig = Curry_Core::getDefaultConfiguration(); $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post')); $themes = array(); $backendPath = Curry_Util::path(true, Curry_Core::$config->curry->wwwPath, 'shared', 'backend'); if ($backendPath) { foreach (new DirectoryIterator($backendPath) as $entry) { $name = $entry->getFilename(); if (!$entry->isDot() && $entry->isDir() && $name !== 'common') { $themes[$name] = $name; } } } $activeTheme = isset($config->curry->backend->theme) ? $config->curry->backend->theme : false; if ($activeTheme && !array_key_exists($activeTheme, $themes)) { $themes[$activeTheme] = $activeTheme; } $pages = PagePeer::getSelect(); // General $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'General', 'elements' => array('name' => array('text', array('label' => 'Name', 'required' => true, 'value' => isset($config->curry->name) ? $config->curry->name : '', 'description' => 'Name of site, shown in backend header and page title by default.', 'placeholder' => $defaultConfig->curry->name)), 'baseUrl' => array('text', array('label' => 'Base URL', 'value' => isset($config->curry->baseUrl) ? $config->curry->baseUrl : '', 'description' => 'The URL to use when creating absolute URLs. This should end with a slash, and may include a path.', 'placeholder' => $defaultConfig->curry->baseUrl)), 'adminEmail' => array('text', array('label' => 'Admin email', 'value' => isset($config->curry->adminEmail) ? $config->curry->adminEmail : '')), 'divertOutMailToAdmin' => array('checkbox', array('label' => 'Divert outgoing email to adminEmail', 'value' => isset($config->curry->divertOutMailToAdmin) ? $config->curry->divertOutMailToAdmin : '', 'description' => 'All outgoing Curry_Mail will be diverted to adminEmail.')), 'developmentMode' => array('checkbox', array('label' => 'Development mode', 'value' => isset($config->curry->developmentMode) ? $config->curry->developmentMode : '')), 'forceDomain' => array('checkbox', array('label' => 'Force domain', 'value' => isset($config->curry->forceDomain) ? $config->curry->forceDomain : '', 'description' => 'If the domain of the requested URL doesn\'t match the domain set by Base URL, the user will be redirected to the correct domain.')), 'fallbackLanguage' => array('select', array('label' => 'Fallback Language', 'multiOptions' => array('' => '[ None ]') + LanguageQuery::create()->find()->toKeyValue('PrimaryKey', 'Name'), 'value' => isset($config->curry->fallbackLanguage) ? $config->curry->fallbackLanguage : '', 'description' => 'The language used when no language has been specified for the rendered page. Also the language used in backend context.'))))), 'general'); // Backend $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Backend', 'class' => 'advanced', 'elements' => array('theme' => array('select', array('label' => 'Theme', 'multiOptions' => array('' => '[ Default ]') + $themes, 'value' => isset($config->curry->backend->theme) ? $config->curry->backend->theme : '', 'description' => 'Theme for the administrative back-end.')), 'logotype' => array('filebrowser', array('label' => 'Backend Logotype', 'value' => isset($config->curry->backend->logotype) ? $config->curry->backend->logotype : '', 'description' => 'Path to the backend logotype. The height of this image should be 100px.')), 'templatePage' => array('select', array('label' => 'Template page', 'multiOptions' => array('' => '[ None ]') + $pages, 'value' => isset($config->curry->backend->templatePage) ? $config->curry->backend->templatePage : '', 'description' => 'The page containing page templates (i.e. pages to be used as base pages). When creating new pages or editing a page using the Content tab, only this page and pages below will be shown as base pages.')), 'defaultEditor' => array('text', array('label' => 'Default HTML editor', 'value' => isset($config->curry->defaultEditor) ? $config->curry->defaultEditor : '', 'description' => 'The default WYSIWYG editor to use with the article module.', 'placeholder' => $defaultConfig->curry->defaultEditor)), 'autoBackup' => array('text', array('label' => 'Automatic database backup', 'value' => isset($config->curry->autoBackup) ? $config->curry->autoBackup : '', 'placeholder' => $defaultConfig->curry->autoBackup, 'description' => 'Specifies the number of seconds since last backup to create automatic database backups when logged in to the backend.')), 'revisioning' => array('checkbox', array('label' => 'Revisioning', 'value' => isset($config->curry->revisioning) ? $config->curry->revisioning : '', 'description' => 'When enabled, a new working revision will automatically be created when you create a page. You will also be warned when editing a published page revision')), 'autoPublish' => array('checkbox', array('label' => 'Auto Publish', 'value' => isset($config->curry->autoPublish) ? $config->curry->autoPublish : '', 'description' => 'When enabled, a check will be made on every request to check if there are any pages that should be published (using publish date).')), 'noauth' => array('checkbox', array('label' => 'Disable Backend Authorization', 'value' => isset($config->curry->backend->noauth) ? $config->curry->backend->noauth : '', 'description' => 'This will completely disable authorization for the backend.')), 'autoUpdateIndex' => array('checkbox', array('label' => 'Auto Update Search Index', 'value' => isset($config->curry->autoUpdateIndex) ? $config->curry->autoUpdateIndex : '', 'description' => 'Automatically update (rebuild) search index when changing page content.'))))), 'backend'); // Live edit $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Live edit', 'class' => 'advanced', 'elements' => array('liveEdit' => array('checkbox', array('label' => 'Enable Live Edit', 'value' => isset($config->curry->liveEdit) ? $config->curry->liveEdit : $defaultConfig->curry->liveEdit, 'description' => 'Enables editing of content directly in the front-end.')), 'placeholderExclude' => array('textarea', array('label' => 'Excluded placeholders', 'value' => isset($config->curry->backend->placeholderExclude) ? join(PHP_EOL, $config->curry->backend->placeholderExclude->toArray()) : '', 'description' => 'Prevent placeholders from showing up in live edit mode. Use newlines to separate placeholders.', 'rows' => 5))))), 'liveEdit'); // Error pages $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Error pages', 'class' => 'advanced', 'elements' => array('notFound' => array('select', array('label' => 'Page not found (404)', 'multiOptions' => array('' => '[ None ]') + $pages, 'value' => isset($config->curry->errorPage->notFound) ? $config->curry->errorPage->notFound : '')), 'unauthorized' => array('select', array('label' => 'Unauthorized (401)', 'multiOptions' => array('' => '[ None ]') + $pages, 'value' => isset($config->curry->errorPage->unauthorized) ? $config->curry->errorPage->unauthorized : '')), 'error' => array('select', array('label' => 'Internal server error (500)', 'multiOptions' => array('' => '[ None ]') + $pages, 'value' => isset($config->curry->errorPage->error) ? $config->curry->errorPage->error : ''))))), 'errorPage'); // Maintenance $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Maintenance', 'class' => 'advanced', 'elements' => array('enabled' => array('checkbox', array('label' => 'Enabled', 'required' => true, 'value' => isset($config->curry->maintenance->enabled) ? $config->curry->maintenance->enabled : '', 'description' => 'When maintenance is enabled, users will not be able to access the pages. Only a page (specified below) will be shown. If no page is specified, the message will be shown.')), 'page' => array('select', array('label' => 'Page to show', 'multiOptions' => array('' => '[ None ]') + $pages, 'value' => isset($config->curry->maintenance->page) ? $config->curry->maintenance->page : '')), 'message' => array('textarea', array('label' => 'Message', 'value' => isset($config->curry->maintenance->message) ? $config->curry->maintenance->message : '', 'rows' => 6, 'cols' => 40))))), 'maintenance'); // Mail $testEmailUrl = url('', array('module', 'view' => 'TestEmail')); $dlgOpts = array('width' => 600, 'minHeight' => 150); $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Mail', 'class' => 'advanced', 'elements' => array('method' => array('select', array('label' => 'Transport', 'multiOptions' => array('' => '[ Default ]', 'smtp' => 'SMTP', 'sendmail' => 'PHP mail() function, ie sendmail.'), 'value' => isset($config->curry->mail->method) ? $config->curry->mail->method : '')), 'host' => array('text', array('label' => 'Host', 'value' => isset($config->curry->mail->host) ? $config->curry->mail->host : '')), 'port' => array('text', array('label' => 'Port', 'value' => isset($config->curry->mail->options->port) ? $config->curry->mail->options->port : '')), 'auth' => array('select', array('label' => 'Auth', 'multiOptions' => array('' => '[ Default ]', 'plain' => 'plain', 'login' => 'login', 'cram-md5' => 'cram-md5'), 'value' => isset($config->curry->mail->options->auth) ? $config->curry->mail->options->auth : '')), 'username' => array('text', array('label' => 'Username', 'value' => isset($config->curry->mail->options->username) ? $config->curry->mail->options->username : '')), 'password' => array('password', array('label' => 'Password')), 'ssl' => array('select', array('label' => 'SSL', 'multiOptions' => array('' => 'Disabled', 'ssl' => 'SSL', 'tls' => 'TLS'), 'value' => isset($config->curry->mail->options->ssl) ? $config->curry->mail->options->ssl : '')), 'mailTest' => array('rawHtml', array('value' => '<a href="' . $testEmailUrl . '" class="btn dialog" data-dialog="' . htmlspecialchars(json_encode($dlgOpts)) . '">Test email</a>'))))), 'mail'); // Paths $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Paths', 'class' => 'advanced', 'elements' => array('basePath' => array('text', array('label' => 'Base path', 'value' => isset($config->curry->basePath) ? $config->curry->basePath : '', 'placeholder' => $defaultConfig->curry->basePath)), 'projectPath' => array('text', array('label' => 'Project Path', 'value' => isset($config->curry->projectPath) ? $config->curry->projectPath : '', 'placeholder' => $defaultConfig->curry->projectPath)), 'wwwPath' => array('text', array('label' => 'WWW path', 'value' => isset($config->curry->wwwPath) ? $config->curry->wwwPath : '', 'placeholder' => $defaultConfig->curry->wwwPath)), 'vendorPath' => array('text', array('label' => 'Vendor path', 'value' => isset($config->curry->vendorPath) ? $config->curry->vendorPath : '', 'placeholder' => $defaultConfig->curry->vendorPath))))), 'paths'); // Encoding $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Encoding', 'class' => 'advanced', 'elements' => array('internal' => array('text', array('label' => 'Internal Encoding', 'value' => isset($config->curry->internalEncoding) ? $config->curry->internalEncoding : '', 'description' => 'The internal encoding for PHP.', 'placeholder' => $defaultConfig->curry->internalEncoding)), 'output' => array('text', array('label' => 'Output Encoding', 'value' => isset($config->curry->outputEncoding) ? $config->curry->outputEncoding : '', 'description' => 'The default output encoding for pages.', 'placeholder' => $defaultConfig->curry->outputEncoding))))), 'encoding'); // Misc $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Misc', 'class' => 'advanced', 'elements' => array('error_notification' => array('checkbox', array('label' => 'Error notification', 'value' => isset($config->curry->errorNotification) ? $config->curry->errorNotification : '', 'description' => 'If enabled, an attempt to send error-logs to the admin email will be performed when an error occur.')), 'log_propel' => array('checkbox', array('label' => 'Propel Logging', 'value' => isset($config->curry->propel->logging) ? $config->curry->propel->logging : '', 'description' => 'Database queries and other debug information will be logged to the selected logging facility.')), 'debug_propel' => array('checkbox', array('label' => 'Debug Propel', 'value' => isset($config->curry->propel->debug) ? $config->curry->propel->debug : '', 'description' => 'Enables query counting but doesn\'t log queries.')), 'log' => array('select', array('label' => 'Logging', 'multiOptions' => array('' => '[ Other ]', 'none' => 'Disable logging', 'firebug' => 'Firebug'), 'value' => isset($config->curry->log->method) ? $config->curry->log->method : '')), 'update_translations' => array('checkbox', array('label' => 'Update Language strings', 'value' => isset($config->curry->updateTranslationStrings) ? $config->curry->updateTranslationStrings : '', 'description' => 'Add strings as they are used and record last used timestamp'))))), 'misc'); $form->addElement('submit', 'save', array('label' => 'Save', 'disabled' => $configFile ? null : 'disabled')); if (isPost() && $form->isValid($_POST)) { $this->saveSettings($config, $form->getValues()); } $this->addMainContent($form); }
public function verifySessionContentEditLanguage() { $sSessionDefaultLanguage = Settings::getSetting("session_default", AdminManager::CONTENT_LANGUAGE_SESSION_KEY, null); if (LanguageQuery::create()->filterById($sSessionDefaultLanguage)->count() < 1) { $oLanguage = new Language(); $oLanguage->setId($sSessionDefaultLanguage); $oLanguage->setPathPrefix($sSessionDefaultLanguage); $oLanguage->setIsActive(true); $oLanguage->save(); } }
/** * Get flexigrid for specified model. * * @param string $modelClass * @param array $options * @return \Curry_Flexigrid */ public function getGrid($modelClass, $options = array()) { $options = array_merge(array('title' => $modelClass . 's', 'rp' => 100, 'rpOptions' => array(25, 50, 100, 200, 500)), $options); $flexigrid = new \Curry_Flexigrid_Propel($modelClass, url('', $_GET)->add(array('view' => $modelClass . 'Json')), $options); $editUrl = url('', $_GET)->add(array('module', 'view' => $modelClass)); $flexigrid->addEditButton($editUrl); $flexigrid->addAddButton($editUrl); $flexigrid->addDeleteButton(); if (in_array('translatable', array_keys(\PropelQuery::from($modelClass)->getTableMap()->getBehaviors()))) { $langcode = \LanguageQuery::create()->findOne()->getLangcode(); $flexigrid->addLinkButton('View Translations', 'icon-flag', url('', $_GET)->add(array('translate' => true, 'langcode' => $langcode))); } return $flexigrid; }
protected function initLanguage() { $this->sOldSessionLanguage = Session::language(); if (isset($_REQUEST[AdminManager::CONTENT_LANGUAGE_SESSION_KEY]) && LanguageQuery::languageExists($_REQUEST[AdminManager::CONTENT_LANGUAGE_SESSION_KEY])) { AdminManager::setContentLanguage($_REQUEST[AdminManager::CONTENT_LANGUAGE_SESSION_KEY]); unset($_REQUEST[AdminManager::CONTENT_LANGUAGE_SESSION_KEY]); LinkUtil::redirect(LinkUtil::link(Manager::getRequestedPath(), get_class())); } else { if (!LanguageQuery::languageExists(AdminManager::getContentLanguage())) { AdminManager::setContentLanguage($this->sOldSessionLanguage); } if (!LanguageQuery::languageExists(AdminManager::getContentLanguage())) { LinkUtil::redirectToManager('', "AdminManager"); } } Session::getSession()->setLanguage(AdminManager::getContentLanguage()); }
/** * @param string $sLanguageId * use cases: * 1. at first users' creation * 2. fallback method, creates language if it does not exist, but not at first users' login time, i.e. when languages have been truncated * @return void */ public static function createLanguageIfNoneExist($sLanguage, $oUser = null) { if (LanguageQuery::create()->count() > 0) { return; } $oLanguage = new Language(); $oLanguage->setId($sLanguage); $oLanguage->setPathPrefix($sLanguage); $oLanguage->setIsActive(true); $oLanguage->setCreatedAt(date('c')); $oLanguage->setUpdatedAt(date('c')); if ($oUser) { $oLanguage->setCreatedBy($oUser->getId()); $oLanguage->setUpdatedBy($oUser->getId()); } LanguagePeer::ignoreRights(true); $oLanguage->save(); }
private function validate($aDocumentationData, $oDocumentation) { $oFlash = Flash::getFlash(); $oFlash->setArrayToCheck($aDocumentationData); $oFlash->checkForValue('name', 'name_required'); $oFlash->checkForValue('key', 'key_required'); if (!LanguageInputWidgetModule::isMonolingual()) { $oDocumentation->setLanguageId($aDocumentationData['language_id']); $oFlash->checkForValue('language_id', 'language_required'); } else { $oLanguage = LanguageQuery::create()->findOne(); $oDocumentation->setLanguageId($oLanguage->getId()); } $oCheckDocumentation = DocumentationQuery::create()->filterByLanguageId($oDocumentation->getLanguageId())->filterByKey($aDocumentationData['key'])->findOne(); if ($oCheckDocumentation && !Util::equals($oDocumentation, $oCheckDocumentation)) { $oFlash->addMessage('documentation_unique_required'); } $oFlash->finishReporting(); }
public function saveData($aLanguageData) { // string key is changed if a existing Language string_key is changed if ($aLanguageData['language_id'] !== $this->sLanguageId) { $this->sLanguageId = $aLanguageData['language_id']; } $oLanguage = LanguageQuery::create()->findPk($this->sLanguageId); if ($oLanguage === null) { $oLanguage = new Language(); $oLanguage->setId($aLanguageData['language_id']); } $this->validate($aLanguageData, $oLanguage); if (!Flash::noErrors()) { throw new ValidationException(); } $oLanguage->setIsActive($aLanguageData['is_active']); $oLanguage->setPathPrefix($aLanguageData['path_prefix']); return $oLanguage->save(); }
/** * @deprecated use query methods directly in context */ public static function getLanguagesAssoc($bActiveOnly = false, $oSortBySort = false) { $aResult = array(); $oQuery = LanguageQuery::create(); if ($bActiveOnly) { $oQuery->filterByIsActive(true); } if ($oSortBySort) { $oQuery->orderBySort(); } else { $oQuery->orderById(); } foreach ($oQuery->find() as $oLanguage) { $aResult[$oLanguage->getId()] = $oLanguage->getLanguageName(); } if (!$oSortBySort) { asort($aResult); } return $aResult; }
#!/usr/bin/env php <?php require_once __DIR__ . '/../../../base/lib/inc.php'; try { set_error_handler(array('ErrorHandler', "handleError")); foreach (LanguageQuery::create()->filterByIsActive(true)->find() as $oLanguage) { $sLanguageId = $oLanguage->getId(); $oModule = new UpdateSearchIndexFileModule(array(), $sLanguageId, true); $oModule->renderFile(); } } catch (Exception $oException) { ErrorHandler::handleException($oException); }
/** * Returns the number of related Language objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related Language objects. * @throws PropelException */ public function countLanguagesRelatedByUpdatedBy(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collLanguagesRelatedByUpdatedByPartial && !$this->isNew(); if (null === $this->collLanguagesRelatedByUpdatedBy || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collLanguagesRelatedByUpdatedBy) { return 0; } if ($partial && !$criteria) { return count($this->getLanguagesRelatedByUpdatedBy()); } $query = LanguageQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByUserRelatedByUpdatedBy($this)->count($con); } return count($this->collLanguagesRelatedByUpdatedBy); }
/** * Get the associated Language object * * @param PropelPDO $con Optional Connection object. * @param $doQuery Executes a query to get the object if required * @return Language The associated Language object. * @throws PropelException */ public function getLanguage(PropelPDO $con = null, $doQuery = true) { if ($this->aLanguage === null && ($this->language_id !== "" && $this->language_id !== null) && $doQuery) { $this->aLanguage = LanguageQuery::create()->findPk($this->language_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aLanguage->addLanguageObjectHistorys($this); */ } return $this->aLanguage; }
/** * Get user form. * * @param User $user * @return Curry_Form_ModelForm */ protected function getUserForm(User $user) { $createHomeFolder = $user->isNew() || self::getUserHome($user) !== null; $validRoles = $this->getValidRoles(); $invalidRoles = UserRoleQuery::create()->filterByUserRoleId(array_keys($validRoles), Criteria::NOT_IN)->select('UserRoleId')->find()->getArrayCopy(); $validLanguages = UserLanguageQuery::create()->_if(!$user->hasAccess('*'))->filterByUser(User::getUser())->_endif()->select('langcode')->find()->getArrayCopy(); $invalidLanguages = LanguageQuery::create()->filterByLangcode($validLanguages, Criteria::NOT_IN)->select('langcode')->find()->getArrayCopy(); $form = new Curry_Form_ModelForm('User', array('method' => 'post', 'action' => url('', $_GET), 'columnElements' => array('password' => array('password', array('required' => $user->isNew())), 'relation__userrole' => array('select', array('label' => 'Role', 'disable' => $invalidRoles, 'validators' => array(array('InArray', true, array(array_keys($validRoles)))))), 'relation__language' => array('multiselect', array('class' => 'chosen', 'disable' => $invalidLanguages, 'validators' => array(array('InArray', true, array($validLanguages)))))))); $form->addElements(array('verify_password' => array('password', array('label' => 'Verify password', 'required' => $user->isNew(), 'validators' => array(array('identical', false, array('token' => 'password'))))), 'create_home_folder' => array('checkbox', array('label' => 'Create home folder', 'description' => 'Creates a folder in /user-content/ for the user and adds file permission for it.', 'value' => $createHomeFolder, 'order' => 5)))); $form->withRelation('UserRole'); $form->withRelation('Language'); $form->addElement('submit', 'save', array('label' => 'Save')); return $form; }
/** * Get page properties form. * * @param Page $page * @return Curry_Form */ public static function getPagePropertiesForm(Page $page) { $form = new Curry_Form(array('action' => url('', array("module", "view", "page_id")), 'method' => 'post', 'elements' => array('pid_properties' => array('hidden'), 'name' => array('text', array('label' => 'Name', 'required' => true, 'value' => $page->getName(), 'description' => 'The name of the page is shown in menus. It\'s also used to generate the default title and URL for the page.')), 'url' => array('text', array('label' => 'URL', 'value' => $page->getUrl(), 'description' => 'The URL of the page. Subpages will be based on this URL.')), 'enabled' => array('checkbox', array('label' => 'Active', 'value' => $page->getEnabled(), 'description' => 'Only active pages can be accessed.')), 'visible' => array('checkbox', array('label' => 'Show in menu', 'value' => $page->getVisible(), 'description' => 'Enable this if you want the page to show up in menus.')), 'index' => array('checkbox', array('label' => 'Include in search index', 'value' => $page->getIncludeInIndex(), 'description' => 'Disable this if you dont want the page to be included in search results.'))))); $redirectValue = null; if ($page->getRedirectUrl()) { $redirectValue = "external"; } else { if ($page->getRedirectPageId()) { $redirectValue = $page->getRedirectPageId(); } else { $redirectValue = ""; } } // first-subpage $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Redirect', 'class' => $page->getRedirectMethod() ? '' : 'advanced', 'elements' => array('method' => array('select', array('label' => 'Method', 'multiOptions' => array('' => '[ None ]', PagePeer::REDIRECT_METHOD_CLONE => 'Clone', PagePeer::REDIRECT_METHOD_PERMANENT => 'Permanent redirect (301)', PagePeer::REDIRECT_METHOD_TEMPORARY => 'Temporary redirect (302)'), 'value' => $page->getRedirectMethod(), 'onchange' => '$("#redirect-page_id").attr("disabled", this.value == "").change();')), 'page_id' => array('select', array('label' => 'Page', 'multiOptions' => array("" => '[ First subpage ]', 'external' => '[ External ]') + PagePeer::getSelect(), 'value' => $redirectValue, 'onchange' => '$("#redirect-url").attr("disabled", $(this).attr("disabled") || this.value != "external");', 'disabled' => !$page->getRedirectMethod() ? 'disabled' : null)), 'url' => array('text', array('label' => 'External URL', 'value' => $page->getRedirectUrl() ? $page->getRedirectUrl() : 'http://', 'disabled' => !$page->getRedirectMethod() || $redirectValue != 'external' ? 'disabled' : null))))), 'redirect'); // Base page $advanced = Curry_Backend_Page::getPagePermission($page, PageAccessPeer::PERM_MODULES); $pageRevision = $page->getPageRevision(); list($basePageElement, $basePreviewElement) = self::getBasePageSelect($page, $pageRevision->getBasePageId(), $advanced); // Template $templates = Curry_Backend_Template::getTemplateSelect(); if ($pageRevision->getInheritRevision()) { $template = $pageRevision->getInheritRevision()->getInheritedProperty('Template', 'Undefined', false); $templates = array('' => '[ Inherited: ' . $template . ' ]') + $templates; } else { $templates = array('' => '[ None ]') + $templates; } $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Base page', 'class' => 'advanced', 'elements' => array('base_page_id' => $basePageElement, 'base_page_preview' => $basePreviewElement))), 'base_page'); $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Advanced', 'class' => 'advanced', 'elements' => array('image' => array('previewImage', array('label' => 'Image', 'value' => $page->getImage(), 'description' => 'Select an image to represent the page. This will show up when selecting base page.')), 'template' => array('select', array('label' => 'Page template', 'multiOptions' => $templates, 'value' => (string) $pageRevision->getTemplate(), 'description' => 'Override page template inherited from base page.')), 'langcode' => array('select', array('label' => 'Language', 'value' => $page->getLangcode(), 'multiOptions' => array('' => 'None (Inherit from parent)') + LanguageQuery::create()->find()->toKeyValue('Langcode', 'Name'), 'description' => 'Language of page. Inherited from closest parent if not set.')), 'model_route' => array('text', array('label' => 'Model route', 'value' => $page->getModelRoute(), 'description' => 'The model class used for routing.')), 'cache_lifetime' => array('text', array('label' => 'Cache lifetime', 'value' => $page->getCacheLifetime(), 'description' => 'Full page caching, specified in seconds (0 to disable, -1 for infinity).')), 'generator' => array('text', array('label' => 'Generator', 'value' => $page->getGenerator(), 'placeholder' => \Curry\App::getInstance()['defaultGeneratorClass']))))), 'advanced'); $form->addElement('submit', 'Save'); return $form; }
protected function initLanguage() { $bIsMultilingual = Settings::getSetting('general', 'multilingual', true); if ($bIsMultilingual && self::hasNextPathItem() && LanguageQuery::languageIsActive(self::peekNextPathItem(), true)) { $oLanguage = LanguageQuery::create()->filterByPathPrefix(self::usePath())->findOne(); Session::getSession()->setLanguage($oLanguage); } else { // If site is monolingual, try setting the session default as a shortcut if ($bIsMultilingual) { // If we’ve got a valid session language set (and it’s not just from the default), use that if (Session::getSession()->hasAttribute(Session::SESSION_LANGUAGE_KEY) && LanguageQuery::languageIsActive(Session::language())) { LinkUtil::redirectToLanguage(); } // Otherwise, use the first of the user’s accept languages that is valid foreach (LocaleUtil::acceptLocales() as $oAcceptLocale) { if (LanguageQuery::languageIsActive($oAcceptLocale->language_id)) { Session::getSession()->setLanguage($oAcceptLocale->language_id); LinkUtil::redirectToLanguage(); } } // As a last resort, try, the default session language Session::getSession()->resetAttribute(Session::SESSION_LANGUAGE_KEY); if (LanguageQuery::languageIsActive(Session::language())) { LinkUtil::redirectToLanguage(); } } else { if (LanguageQuery::languageIsActive(Session::language())) { return; } else { Session::getSession()->resetAttribute(Session::SESSION_LANGUAGE_KEY); if (LanguageQuery::languageIsActive(Session::language())) { return; } } } // If all fails, redirect to the admin manager, where new languages can be created/activated LinkUtil::redirectToManager(array('languages'), "AdminManager"); } }
public function saveData($aStringData) { $this->validate($aStringData); if (!Flash::noErrors()) { throw new ValidationException(); } $oConnection = Propel::getConnection(); foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) { $oUpdateCriteria = new Criteria(); $oUpdateCriteria->add(TranslationPeer::LANGUAGE_ID, $oLanguage->getId()); $oUpdateCriteria->add(TranslationPeer::STRING_KEY, $this->sStringId); if (isset($aStringData['text_' . $oLanguage->getId()])) { $sText = trim($aStringData['text_' . $oLanguage->getId()]); $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId)); if ($sText === '') { if ($oString !== null) { $oString->delete(); } continue; } if ($oString === null) { $oString = new Translation(); $oString->setLanguageId($oLanguage->getId()); $oString->setStringKey($aStringData['string_key']); } else { if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) { $oString->setStringKey($aStringData['string_key']); BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection); } } $oString->setText($sText); $oString->save(); } else { $oString = TranslationQuery::create()->findPk(array($oLanguage->getId(), $this->sStringId)); if ($oString === null) { continue; } if ($this->sStringId !== null && $this->sStringId !== $aStringData['string_key']) { $oString->setStringKey($aStringData['string_key']); BasePeer::doUpdate($oUpdateCriteria, $oString->buildCriteria(), $oConnection); } } } // check sidebar reload criteria $sNameSpaceOld = TranslationPeer::getNameSpaceFromStringKey($this->sStringId); $sNameSpaceNew = TranslationPeer::getNameSpaceFromStringKey($aStringData['string_key']); // if both are the same the sidebar is not effected $bSidebarHasChanged = false; if ($sNameSpaceOld !== $sNameSpaceNew) { // if there was an old name space then we have to check whether it was the last string with this namespace if ($sNameSpaceOld !== null && !TranslationPeer::nameSpaceExists($sNameSpaceOld)) { $bSidebarHasChanged = true; } // if the new exits only once it has been created and the sidebar needs to be relaoded if ($sNameSpaceNew !== null && TranslationPeer::countNameSpaceByName($sNameSpaceNew) === 1) { $bSidebarHasChanged = true; } } $this->sStringId = $aStringData['string_key']; return array('id' => $this->sStringId, self::SIDEBAR_CHANGED => $bSidebarHasChanged); }
public static function link($mPath = false, $mManager = null, $aParameters = array(), $mLanguage = null, $bIncludeLanguage = null) { if ($mPath === null) { // Respect null-links return null; } if (!$mPath) { $mPath = array(); } if (!is_array($mPath)) { $mPath = explode("/", $mPath); } $mManager = Manager::getManagerClassNormalized($mManager); $sPrefix = Manager::getPrefixForManager($mManager); if ($mLanguage === true || $mLanguage === false) { $bIncludeLanguage = $mLanguage; $mLanguage = null; } if ($bIncludeLanguage === null) { $bIncludeLanguage = $mManager::shouldIncludeLanguageInLink(); } if ($bIncludeLanguage) { if ($mLanguage === null) { $mLanguage = Session::language(true); } if ($mLanguage instanceof Language) { array_unshift($mPath, $mLanguage->getPathPrefix()); } else { if (is_string($mLanguage)) { $mLanguage = LanguageQuery::create()->findPk($mLanguage)->getPathPrefix(); array_unshift($mPath, $mLanguage); } } } foreach ($mPath as $iKey => $sValue) { if ($sValue === null || $sValue === "") { unset($mPath[$iKey]); } else { $mPath[$iKey] = rawurlencode($sValue); } } if ($sPrefix !== null && $sPrefix !== "") { $sPrefix .= "/"; } else { $sPrefix = ''; } return MAIN_DIR_FE_PHP . $sPrefix . implode('/', $mPath) . self::prepareLinkParameters($aParameters); }
/** * Get language selection form. * * @param string $langcode * @return Curry_Form */ private function getLanguageForm($langcode) { $form = new Curry_Form(array('method' => 'get', 'action' => url(''), 'id' => 'language-selector', 'elements' => array('langcode' => array('select', array('label' => 'Language', 'multiOptions' => array('' => 'None') + LanguageQuery::create()->find()->toKeyValue('Langcode', 'Name'), 'onchange' => 'this.form.submit();', 'value' => $langcode, 'description' => 'Change this if you want to set language specific content.'))))); $preserve = array('module', 'view', 'page_module_id', 'page_id'); foreach ($preserve as $var) { if (isset($_GET[$var])) { $form->addElement('hidden', $var, array('value' => $_GET[$var])); } } return $form; }
public static function languageExists($sLanguageId, $bByPath = false) { return LanguageQuery::language($sLanguageId, $bByPath)->count() > 0; }
public function getLanguage($bObject = false) { $sResult = $this->getAttribute(self::SESSION_LANGUAGE_KEY); if ($bObject) { $sResult = LanguageQuery::create()->findPk($sResult); if (!$sResult) { //If an object was explicitly requested, most likely, it’s supposed to be a content language $sResult = LanguageQuery::create()->findPk(AdminManager::getContentLanguage()); } } return $sResult; }
/** * Show edit language. */ public function showLanguages() { $this->addMainMenu(); $langcodes = array(); foreach (Zend_Locale::getLocaleList() as $langcode => $ignore) { list($l, $t) = explode('_', $langcode); $language = Zend_Locale::getTranslation($l, 'language', 'en_US'); if (!$language) { $language = $langcode; } $territory = $t ? Zend_Locale::getTranslation($t, 'territory', 'en_US') : ''; $langcodes[$langcode] = $language . ($territory ? " ({$territory})" : ' (Generic)'); } $existing = LanguageQuery::create()->find()->toKeyValue('Langcode', 'Name'); foreach ($existing as $langcode => $name) { if (!array_key_exists($langcode, $langcodes)) { $langcodes[$langcode] = $name . ' (Custom)'; } } asort($langcodes); $form = new Curry_ModelView_Form('Language', array('ignorePks' => false, 'columnElements' => array('langcode' => array('select', array('multiOptions' => $langcodes, 'disable' => array_keys($existing), 'onchange' => "\$('[name=\"name\"]', this.form).val(this.options[this.selectedIndex].text);"))), 'onFillForm' => function ($item, $form) { if ($item->isNew()) { $form->addElement('select', 'copy', array('label' => 'Copy translations from', 'multiOptions' => array('' => '[ None ]') + LanguageQuery::create()->find()->toKeyValue('PrimaryKey', 'Name'), 'order' => 2)); } else { // Prevent changing langcode (propel cant change primary keys anyway) $form->removeElement('langcode'); } }, 'onFillModel' => function (Language $item, $form, $values) { $user = User::getUser(); if ($item->isNew()) { $item->addUser($user); if (isset($values['copy']) && $values['copy']) { $translations = LanguageStringTranslationQuery::create()->findByLangcode($values['copy']); foreach ($translations as $translation) { $item->addLanguageStringTranslation($translation->copy()); } } } })); $list = new Curry_ModelView_List('Language', array('modelForm' => $form, 'maxPerPage' => 0)); $this->addMainContent($list); }
/** * @param main template * description: * - @see config.yml section language_chooser * - use parameter replaced in method * @return Template The rendered language chooser */ public static function getLanguageChooser($oMainTemplate) { $oTemplate = new Template(TemplateIdentifier::constructIdentifier('languages'), null, true); $oLanguageTemplate = new Template(Settings::getSetting("language_chooser", 'template', 'language'), array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION)); $sLinkSeparator = Settings::getSetting("language_chooser", 'link_separator', ' | '); $oLanguageActiveTemplate = null; $bShowActiveLanguage = Settings::getSetting("language_chooser", 'show_active_language', false); $bIsPreview = Manager::getCurrentManager() instanceof PreviewManager; if ($bShowActiveLanguage) { if (Settings::getSetting("language_chooser", 'template_active', false) !== false) { $oLanguageActiveTemplate = new Template(Settings::getSetting("language_chooser", 'template_active', 'language_active'), array(DIRNAME_TEMPLATES, DIRNAME_NAVIGATION)); } else { $oLanguageActiveTemplate = clone $oLanguageTemplate; } } // Find request variables $aParameters = array_diff_assoc($_REQUEST, $_COOKIE); unset($aParameters['path']); unset($aParameters['content_language']); // Check whether manager needs language to be included $bCurrentPathIncludesLanguage = call_user_func(array(Manager::getManagerClassNormalized(null), 'shouldIncludeLanguageInLink')); $aRequestPath = explode("/", Manager::getRequestedPath()); $aLanguages = LanguageQuery::create()->filterByIsActive(true)->exclude($bShowActiveLanguage ? false : ($bIsPreview ? 'edit' : 'current'))->orderBySort()->find(); foreach ($aLanguages as $i => $oLanguage) { $oLangTemplate = null; $oPageString = null; if ($oLanguage->getId() === Session::language()) { $oLangTemplate = $oLanguageActiveTemplate; $oLangTemplate->replaceIdentifier('class', 'active'); } else { $oPageString = PageStringQuery::create()->filterByPage(FrontendManager::$CURRENT_PAGE)->filterByLanguageId($oLanguage->getId())->filterByIsInactive(false)->findOne(); if ($oPageString === null) { continue; } $oLangTemplate = clone $oLanguageTemplate; } // If language is included, replace it by language id and set include_language param to false if ($bCurrentPathIncludesLanguage) { $aRequestPath[0] = $oLanguage->getPathPrefix(); $sLink = LinkUtil::link($aRequestPath, null, $aParameters, false); } else { $sLink = LinkUtil::link($aRequestPath, null, array_merge($aParameters, array('content_language' => $oLanguage->getId()))); } $oLangTemplate->replaceIdentifier('link', $sLink); // Add alternate language links if ($oPageString) { ResourceIncluder::metaIncluder()->addCustomResource(array('template' => 'link', 'rel' => 'alternate', 'lang' => $oLanguage->getId(), 'location' => $sLink, 'title' => $oPageString->getPageTitle())); } $oLangTemplate->replaceIdentifier('id', $oLanguage->getId()); $oLangTemplate->replaceIdentifier('name', $oLanguage->getLanguageName($oLanguage->getId())); $oLangTemplate->replaceIdentifier('name_in_current_lang', $oLanguage->getLanguageName()); $oTemplate->replaceIdentifierMultiple('languages', $oLangTemplate, null, Template::NO_NEWLINE); if ($i + 1 < count($aLanguages)) { $oTemplate->replaceIdentifierMultiple('languages', $sLinkSeparator, null, Template::NO_HTML_ESCAPE | Template::NO_NEWLINE); } } return $oTemplate; }
/** * Get a list of all languages. * * @return string[] An associative array, with langcode as key and name as value. */ public static function getLanguages() { return LanguageQuery::create()->find()->toKeyValue('Langcode', 'Name'); }
public static function isMonolingual() { return LanguageQuery::create()->count() <= 1; }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(LanguagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = LanguageQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // denyable behavior if (!(LanguagePeer::isIgnoringRights() || $this->mayOperate("delete"))) { throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "languages"))); } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(LanguagePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { LanguageQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
private function paramsForObject($oObject) { $aObject = array('id' => $oObject->getId()); $aObject['language_objects'] = array(); foreach (LanguageQuery::create()->orderById()->find() as $oLanguage) { $aLanguageInfo = array(); $oLanguageObject = $oObject->getLanguageObject($oLanguage->getId()); $aLanguageInfo['exists_in_language'] = $oLanguageObject !== null; if ($oLanguageObject === null) { $oLanguageObject = LanguageObjectHistoryQuery::create()->filterByLanguageId($oLanguage->getId())->filterByObjectId($oObject->getId())->sort()->findOne(); $aLanguageInfo['is_draft'] = $oLanguageObject !== null; } else { $aLanguageInfo['is_draft'] = $oLanguageObject->getHasDraft(); } if ($oLanguageObject !== null) { $sFrontendModuleClass = FrontendModule::getClassNameByName($oObject->getObjectType()); if (class_exists($sFrontendModuleClass, true)) { $mContentInfo = $sFrontendModuleClass::getContentInfo($oLanguageObject); } else { $mContentInfo = null; } $aLanguageInfo['content_info'] = $mContentInfo; } else { $aLanguageInfo['content_info'] = null; } $aObject['language_objects'][$oLanguage->getId()] = $aLanguageInfo; } $aObject['object_type'] = $oObject->getObjectType(); $aObject['has_condition'] = $oObject->getConditionSerialized() !== null; $aObject['object_type_display_name'] = FrontendModule::getDisplayNameByName($oObject->getObjectType()); return $aObject; }