Example #1
0
 /**
  * Index action.
  *
  * @return void
  */
 public function indexAction()
 {
     $this->view->site_title = Settings::getSetting('system_title', '');
     $this->view->logo = $this->getParam('logo');
     $this->view->show_title = $this->getParam('show_title');
     $this->view->show_auth = $this->getParam('show_auth');
 }
 /**
  * Index action.
  *
  * @return void
  *
  * @Route("/", methods={"GET", "POST"}, name="admin-performance")
  */
 public function indexAction()
 {
     $form = new PerformanceForm();
     $this->view->form = $form;
     $cacheData = $this->config->application->cache->toArray();
     switch ($this->config->application->cache->adapter) {
         case "File":
             $cacheData['adapter'] = 0;
             break;
         case "Memcache":
             $cacheData['adapter'] = 1;
             break;
         case "Apc":
             $cacheData['adapter'] = 2;
             break;
         case "Mongo":
             $cacheData['adapter'] = 3;
             break;
     }
     $form->setValues($cacheData);
     if (!$this->request->isPost() || !$form->isValid()) {
         return;
     }
     $data = $form->getValues();
     if (!empty($data['clear_cache']) && ($data['clear_cache'] = 1)) {
         $this->app->clearCache(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
         $this->flash->success('Cache cleared!');
         $form->setValue('clear_cache', null);
     }
     $cacheData = ['lifetime' => $data['lifetime'], 'prefix' => $data['prefix']];
     switch ($data['adapter']) {
         case 0:
             $cacheData['adapter'] = 'File';
             $cacheData['cacheDir'] = $data['cacheDir'];
             break;
         case 1:
             $cacheData['adapter'] = 'Memcache';
             $cacheData['host'] = $data['host'];
             $cacheData['port'] = $data['port'];
             $cacheData['persistent'] = $data['persistent'];
             break;
         case 2:
             $cacheData['adapter'] = 'Apc';
             break;
         case 3:
             $cacheData['adapter'] = 'Mongo';
             $cacheData['server'] = $data['server'];
             $cacheData['db'] = $data['db'];
             $cacheData['collection'] = $data['collection'];
             break;
     }
     $this->config->application->cache = new Config($cacheData);
     $this->config->save();
     $this->flash->success('Settings saved!');
 }
 /**
  * Index action.
  *
  * @return void
  *
  * @Route("/", methods={"GET", "POST"}, name="admin-settings-general")
  */
 public function indexAction()
 {
     $form = new SystemSettingsForm();
     $this->view->form = $form;
     if (!$this->request->isPost() || !$form->isValid()) {
         return;
     }
     $values = $form->getValues();
     Settings::setSettings($values);
     $this->flash->success('Settings saved!');
 }
Example #4
0
 /**
  * Get setting by name.
  *
  * @param string     $name    Setting name.
  * @param null|mixed $default Default value.
  *
  * @return null|string
  */
 public function get($name, $default = null)
 {
     return Settings::getSetting($name, $default);
 }
Example #5
0
 /**
  * Initialize form.
  *
  * @return void
  */
 public function initialize()
 {
     $this->setTitle('System settings')->setDescription('All system settings here.');
     $this->addContentFieldSet()->addText('system_title', 'Site name', null, Settings::getSetting('system_title', ''))->addSelect('system_theme', 'Theme', null, $this->_getThemeOptions(), Settings::getSetting('system_theme'))->addSelect('system_default_language', 'Default language', null, $this->_getLanguageOptions(), Settings::getSetting('system_default_language'));
     $this->addFooterFieldSet()->addButton('save');
 }
Example #6
0
 /**
  * Install assets from modules.
  *
  * @return void
  */
 public function installAction()
 {
     $assetsManager = new Manager($this->getDI(), false);
     $assetsManager->installAssets(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
     print ConsoleUtil::success('Assets successfully installed.') . PHP_EOL;
 }
Example #7
0
 /**
  * Init locale.
  *
  * @param DI     $di     Dependency injection.
  * @param Config $config Dependency injection.
  *
  * @return void
  */
 protected function _initI18n(DI $di, Config $config)
 {
     if ($di->get('app')->isConsole()) {
         return;
     }
     $languageObject = null;
     if (!$di->get('session')->has('language')) {
         /** @var Language $languageObject */
         if ($config->installed) {
             $language = Settings::getSetting('system_default_language');
             if ($language == 'auto') {
                 $locale = \Locale::acceptFromHttp($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
                 $languageObject = Language::findFirst("language = '" . $locale . "' OR locale = '" . $locale . "'");
             } else {
                 $languageObject = Language::findFirst("language = '" . $language . "'");
             }
         }
         if ($languageObject) {
             $di->get('session')->set('language', $languageObject->language);
             $di->get('session')->set('locale', $languageObject->locale);
         } else {
             $di->get('session')->set('language', Config::CONFIG_DEFAULT_LANGUAGE);
             $di->get('session')->set('locale', Config::CONFIG_DEFAULT_LOCALE);
         }
     }
     $language = $di->get('session')->get('language');
     $translate = null;
     if (!$config->application->debug || !$config->installed) {
         $messages = [];
         $directory = $config->application->languages->cacheDir;
         $extension = ".php";
         if (file_exists($directory . $language . $extension)) {
             require $directory . $language . $extension;
         } else {
             if (file_exists($directory . Config::CONFIG_DEFAULT_LANGUAGE . $extension)) {
                 // fallback to default
                 require $directory . Config::CONFIG_DEFAULT_LANGUAGE . $extension;
             }
         }
         $translate = new TranslateArray(["content" => $messages]);
     } else {
         if (!$languageObject) {
             $languageObject = Language::findFirst(['conditions' => 'language = :language:', 'bind' => ["language" => $language]]);
             if (!$languageObject) {
                 $languageObject = Language::findFirst("language = '" . Config::CONFIG_DEFAULT_LANGUAGE . "'");
             }
         }
         $translate = new TranslationDb($di, $languageObject->getId(), new LanguageTranslation());
     }
     $di->set('i18n', $translate);
 }
 /**
  * Clear cache
  *
  * @return void
  */
 protected function _clearCache()
 {
     $this->app->clearCache(PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
 }
Example #9
0
 /**
  * Set setting by name.
  *
  * @param string $name  Setting name.
  * @param mixed  $value Setting value.
  */
 public static function setSetting($name, $value)
 {
     $setting = self::getSettingObject($name);
     if (!$setting) {
         $setting = new Settings();
         $setting->name = $name;
     }
     $setting->setValue($value);
 }
Example #10
0
 /**
  * Save finish form action.
  *
  * @return ResponseInterface
  *
  * @Route("/save", methods={"GET"}, name="install-save")
  */
 public function saveAction()
 {
     if (!$this->_isPassed('finishAction')) {
         return $this->_selectAction();
     }
     foreach ($this->_actions as $action) {
         $this->_setPassed($action, false);
     }
     $this->_setupDatabase();
     $this->config->offsetSet('installed', true);
     $packageManager = new PackageManager(Package::find());
     $packageManager->generateMetadata();
     $assetsManager = new AssetManager($this->getDI(), false);
     $assetsManager->clear(true, PUBLIC_PATH . '/themes/' . Settings::getSetting('system_theme'));
     return $this->response->redirect();
 }
Example #11
0
    /**
     * Admin action for editing widget options through admin panel.
     *
     * @return CoreForm
     */
    public function adminAction()
    {
        $form = new CoreForm();
        $form->addText('title');
        // Adding additional html for language selector support.
        $languageSelectorHtml = '
                <style type="text/css">
                    form .form_elements > div{
                        min-height: auto !important;
                        padding-top: 0px !important;
                    }

                    form .form_elements > div:nth-last-child(2){
                        padding-top: 10px !important;
                    }
                </style>
                <script type="text/javascript">
                     var defaultLanguage = "%s";
                     $(document).ready(function(){
                        $("#html_block_language").change(function(){
                            $("#cke_html_"+$(this).val()).closest(".form_element_container").show();
                            $(".cke").not("#cke_html_"+$(this).val()).closest(".form_element_container").hide();
                        });

                        // Hide inactive.
                        $("textarea").not("#html_"+defaultLanguage).closest(".form_element_container").hide();
                        setTimeout(
                            function(){
                                $(".cke").not("#cke_html_"+defaultLanguage).closest(".form_element_container").hide();
                            }, 200);
                    });
                </script>
                <div class="form_element_container" style="float: left;">
                    <div class="form_label">
                        <label for="title">%s</label>
                    </div>
                    <div class="form_element">
                        <select id="html_block_language" style="width: 120px;">
                            %s
                        </select>
                    </div>
                </div>
                ';
        // Creating languages boxes.
        $languages = Language::find();
        $languageHtmlItems = '';
        $defaultLanguage = Settings::getSetting('system_default_language', 'en');
        if ($defaultLanguage == 'auto') {
            $defaultLanguage = 'en';
        }
        $elements = [];
        foreach ($languages as $language) {
            $selectedLanguage = '';
            if ($language->language == $defaultLanguage) {
                $selectedLanguage = 'selected="selected"';
            }
            $elementName = 'html_' . $language->language;
            $elements[$elementName] = 'HTML (' . strtoupper($language->language) . ')';
            $languageHtmlItems .= '<option ' . $selectedLanguage . ' value=' . $language->language . '>' . $language->name . '</option>';
        }
        $languageSelectorHtml = sprintf($languageSelectorHtml, $defaultLanguage, $this->di->get('i18n')->_('HTML block, for:'), $languageHtmlItems);
        // Adding created html to form.
        $form->addHtml('html_language', $languageSelectorHtml);
        foreach ($elements as $elementName => $elementTitle) {
            $form->addCkEditor($elementName, $elementTitle);
        }
        $form->addHtml('separator');
        return $form;
    }