コード例 #1
0
 /**
  * Main action.
  *
  * @return void
  */
 public function index()
 {
     $this->loadModel('System.Options');
     $languages = LocaleToolbox::languagesList();
     $arrayContext = ['schema' => ['site_title' => 'string', 'site_slogan' => 'string', 'site_description' => 'string', 'site_email' => 'string', 'site_contents_home' => 'integer', 'site_maintenance' => 'boolean', 'site_maintenance_ip' => 'string', 'site_maintenance_message' => 'string', 'default_language' => 'string', 'url_locale_prefix' => 'string'], 'defaults' => [], 'errors' => []];
     $variables = $this->Options->find()->where(['name IN' => array_keys($arrayContext['schema'])])->all();
     foreach ($variables as $var) {
         $arrayContext['defaults'][$var->name] = $var->value;
     }
     if ($this->request->data()) {
         $validator = $this->_mockValidator();
         $errors = $validator->errors($this->request->data());
         if (empty($errors)) {
             foreach ($this->request->data() as $k => $v) {
                 $this->Options->update($k, $v, null, false);
             }
             snapshot();
             $this->Flash->success(__d('system', 'Configuration successfully saved!'));
             $this->redirect($this->referer());
         } else {
             $arrayContext['errors'] = $errors;
             $this->Flash->danger(__d('system', 'Configuration could not be saved, please check your information.'));
         }
     }
     $pluginSettings = plugin()->filter(function ($plugin) {
         return !$plugin->isTheme && $plugin->hasSettings;
     });
     $this->title(__d('system', 'Site’ Configuration'));
     $this->set(compact('arrayContext', 'languages', 'variables', 'pluginSettings'));
     $this->Breadcrumb->push('/admin/system/configuration');
 }
コード例 #2
0
 /**
  * Edits language.
  *
  * @param int $id Language's ID
  * @return void
  */
 public function edit($id)
 {
     $this->loadModel('Locale.Languages');
     $language = $this->Languages->get($id);
     $languages = LocaleToolbox::languagesList(true);
     $icons = LocaleToolbox::flagsList();
     if ($this->request->data()) {
         $language = $this->Languages->patchEntity($language, $this->request->data, ['fieldList' => ['name', 'direction', 'icon']]);
         if ($this->Languages->save($language)) {
             $this->Flash->success(__d('locale', 'Language was successfully saved!'));
             $this->redirect($this->referer());
         } else {
             $this->Flash->success(__d('locale', 'Language could not be saved, please check your information.'));
         }
     }
     $this->title(__d('locale', 'Editing Language'));
     $this->set(compact('language', 'languages', 'icons'));
     $this->Breadcrumb->push('/admin/locale')->push(__d('locale', 'Editing language'), '');
 }
コード例 #3
0
 /**
  * Edit content type settings.
  *
  * @param string $slug Content type's slug
  * @return void
  * @throws \Cake\Network\Exception\NotFoundException When content type was not
  *  found.
  */
 public function edit($slug)
 {
     $this->loadModel('Content.ContentTypes');
     $this->loadModel('User.Roles');
     $type = $this->ContentTypes->find()->where(['slug' => $slug])->first();
     if (!$type) {
         throw new NotFoundException(__d('content', 'Content type was not found!'));
     }
     if ($this->request->data()) {
         $type->accessible(['id', 'slug'], false);
         $data = $this->request->data();
         $type = $this->ContentTypes->patchEntity($type, $data);
         if ($this->ContentTypes->save($type, ['associated' => ['Roles']])) {
             $this->Flash->success(__d('content', 'Content type updated!'));
             $this->redirect(['plugin' => 'Content', 'controller' => 'types', 'action' => 'edit', $type->slug]);
         } else {
             $this->Flash->danger(__d('content', 'Content type could not be updated, check your information.'));
         }
     } else {
         // fix for auto-fill "defaults.*" by FormHelper
         $this->request->data = $type->toArray();
     }
     $roles = $this->Roles->find('list');
     $this->title(__d('content', 'Configure Content Type'));
     $this->set(compact('type', 'roles'));
     $this->set('languages', LocaleToolbox::languagesList());
     $this->Breadcrumb->push('/admin/content/manage')->push(__d('content', 'Content Types'), '/admin/content/types')->push(__d('content', 'Editing "{0}" Content Type', $type->name), '');
 }
コード例 #4
0
 /**
  * Edits the given user's information.
  *
  * @param int $id User's ID
  * @return void
  */
 public function edit($id)
 {
     $this->loadModel('User.Users');
     $user = $this->Users->get($id, ['contain' => ['Roles']]);
     $languages = LocaleToolbox::languagesList();
     $roles = $this->Users->Roles->find('list', ['conditions' => ['id NOT IN' => [ROLE_ID_AUTHENTICATED, ROLE_ID_ANONYMOUS]]]);
     if ($this->request->data()) {
         $user->accessible(['id', 'username'], false);
         $user = $this->Users->patchEntity($user, $this->request->data);
         if ($this->Users->save($user)) {
             $this->Flash->success(__d('user', 'User information successfully updated!'));
             $this->redirect($this->referer());
         } else {
             $this->Flash->danger(__d('user', 'User information could not be saved, please check your information.'));
         }
     }
     $this->title(__d('user', 'Editing User'));
     $this->set(compact('user', 'roles', 'languages'));
     $this->Breadcrumb->push('/admin/user/manage');
 }
コード例 #5
0
 /**
  * Sets "languages" variable for later use in FormHelper.
  *
  * @return void
  */
 protected function _setLanguages()
 {
     $this->set('languages', LocaleToolbox::languagesList());
 }
コード例 #6
0
 /**
  * Renders user's "my profile" form.
  *
  * Here is where user can change their information.
  *
  * @return void
  */
 public function me()
 {
     $this->loadModel('User.Users');
     $user = $this->Users->get(user()->id, ['conditions' => ['status' => 1]]);
     $languages = LocaleToolbox::languagesList();
     if ($this->request->data()) {
         $user->accessible(['id', 'username', 'roles', 'status'], false);
         $user = $this->Users->patchEntity($user, $this->request->data);
         if ($this->Users->save($user)) {
             $this->Flash->success(__d('user', 'User information successfully updated!'), ['key' => 'user_profile']);
             $this->redirect($this->referer());
         } else {
             $this->Flash->danger(__d('user', 'User information could not be saved, please check your information.'), ['key' => 'user_profile']);
         }
     }
     $this->title(__d('user', 'Account'));
     $this->set(compact('user', 'languages'));
     $this->viewMode('full');
 }
コード例 #7
0
 /**
  * Translate the given content to a different language.
  *
  * @param int $contentId Content's ID
  * @return void
  * @throws \Content\Error\ContentNotFoundException When content type, or when
  *  content content was not found
  * @throws \Content\Error\ContentTranslateException When user is not allowed to
  *  translate contents of this type
  */
 public function translate($contentId)
 {
     $this->loadModel('Content.Contents');
     $content = $this->Contents->get($contentId, ['contain' => 'ContentTypes']);
     if (!$content || empty($content->content_type)) {
         throw new ContentNotFoundException(__d('content', 'The requested page was not found.'));
     }
     if (!$content->content_type->userAllowed('translate')) {
         throw new ContentTranslateException(__d('content', 'You are not allowed to translate contents of this type ({0}).', $content->content_type->name));
     }
     if (!$content->language || $content->translation_for) {
         $this->Flash->danger(__d('content', 'You cannot translate this content.'));
         $this->redirect(['plugin' => 'Content', 'controller' => 'manage', 'action' => 'index']);
     }
     $translations = $this->Contents->find()->where(['translation_for' => $content->id])->all();
     $languages = LocaleToolbox::languagesList();
     $illegal = array_merge([$content->language], $translations->extract('language')->toArray());
     foreach ($languages as $code => $name) {
         if (in_array($code, $illegal)) {
             unset($languages[$code]);
         }
     }
     if (!empty($languages) && !empty($this->request->data['language']) && !empty($this->request->data['title']) && $this->request->data['language'] !== $content->language) {
         $this->Contents->fieldable(false);
         // fix, wont trigger fields validation
         $newContent = $this->Contents->newEntity(['content_type_id' => $content->get('content_type_id'), 'content_type_slug' => $content->get('content_type_slug'), 'title' => $content->get('title'), 'status' => false, 'title' => $this->request->data['title'], 'translation_for' => $content->id, 'language' => $this->request->data['language']]);
         if ($this->Contents->save($newContent)) {
             $this->Flash->success(__d('content', 'Translation successfully created and was marked as unpublished. Complete the translation before publishing.'));
             $this->redirect(['plugin' => 'Content', 'controller' => 'manage', 'action' => 'edit', $newContent->id]);
         } else {
             $this->Flash->set(__d('content', 'Translation could not be created'), ['element' => 'System.installer_errors', 'params' => ['errors' => $newContent->errors()]]);
         }
     }
     $this->title(__d('content', 'Translate Content'));
     $this->set(compact('content', 'translations', 'languages'));
     $this->Breadcrumb->push('/admin/content/manage')->push(__d('content', 'Translating content'), '');
 }
コード例 #8
0
 /**
  * {@inheritDoc}
  */
 public function settings(Block $block, View $view)
 {
     $languagesList = LocaleToolbox::languagesList(false, false);
     return $view->element('Locale.language_switcher_widget_settings', compact('block', 'languagesList'));
 }