Example #1
0
 /**
  * Set default template
  */
 protected final function _setTemplateDefault()
 {
     $config = PDI::getDefault()->get('config');
     $cache = ZCache::getInstance('ZCMS_APPLICATION');
     $templateDefault = $cache->get('DEFAULT_TEMPLATE');
     if ($templateDefault === null) {
         /**
          * @var CoreTemplates $templateDefault
          */
         $templateDefault = CoreTemplates::findFirst('published = 1 AND location = \'frontend\'');
         $templateDefault = $templateDefault->base_name;
         $cache->save('DEFAULT_TEMPLATE', $templateDefault);
     }
     if ($templateDefault) {
         $config->frontendTemplate->defaultTemplate = $templateDefault;
         PDI::getDefault()->set('config', $config);
     }
 }
Example #2
0
 /**
  * Save widget
  *
  * @param $sidebar
  * @param integer $ordering
  * @param integer $id
  * @param mixed $newInstance
  * @param string $themeName
  * @return bool
  */
 public final function save($sidebar, $ordering = null, $id = null, $newInstance = null, $themeName = null)
 {
     $ordering = intval($ordering);
     if ($this->validation) {
         if (!$themeName) {
             /**
              * @var CoreTemplates $CoreTemplates
              */
             $CoreTemplates = CoreTemplates::findFirst("location = 'frontend' AND published = 1");
             $themeName = $CoreTemplates->base_name;
         }
         /**
          * @var CoreWidgetValues $CoreWidgetValues
          */
         if ((int) $id) {
             $CoreWidgetValues = CoreWidgetValues::findFirst($id);
         } else {
             $CoreWidgetValues = new CoreWidgetValues();
         }
         $CoreWidgetValues->reOder('sidebar_base_name = ?0', [0 => $sidebar]);
         $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering >= {$ordering} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
         $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering < {$ordering} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
         $this->db->execute($queryDown);
         $this->db->execute($queryUp);
         $CoreWidgetValues->sidebar_base_name = $sidebar;
         $CoreWidgetValues->theme_name = $themeName;
         $CoreWidgetValues->class_name = $this->_widget_name . '_Widget';
         $CoreWidgetValues->options = $this->_processOptions($id, $newInstance);
         $CoreWidgetValues->published = 1;
         $CoreWidgetValues->ordering = $ordering;
         $CoreWidgetValues->title = $this->_title;
         if ($CoreWidgetValues->save()) {
             //Do something
         } else {
             //Do something
         }
         $this->_id = $CoreWidgetValues->widget_value_id;
         $CoreWidgetValues->reOder('sidebar_base_name = ?0', [0 => $sidebar]);
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Set default template
  *
  * @param $base_name
  * @param $location
  * @return bool
  */
 public function setDefaultTemplate($base_name, $location)
 {
     if (!($location == 'frontend' || $location == 'backend')) {
         $this->getDI()->get('flashSession')->error('gb_location_template_must_be_backend_or_frontend');
         return false;
     }
     /**
      * @var CoreTemplates $defaultTemplate
      */
     $defaultTemplate = CoreTemplates::findFirst(['conditions' => "location = ?0 AND base_name = ?1", 'bind' => [$location, $base_name]]);
     if ($defaultTemplate) {
         $phql = "UPDATE ZCMS\\Core\\Models\\CoreTemplates SET published = 0 WHERE location = '{$location}'";
         if ($this->getDI()->get('modelsManager')->createQuery($phql)->execute()) {
             $defaultTemplate->published = 1;
             if ($defaultTemplate->save()) {
                 file_put_contents(APP_DIR . "/" . $location . "/index.volt", '{% extends "../../../templates/' . $location . "/" . $base_name . '/index.volt" %}');
                 return true;
             }
         }
     }
     return false;
 }
Example #4
0
 /**
  * @return bool|\Phalcon\Http\ResponseInterface
  */
 public function indexAction()
 {
     //Add tool bar
     $this->_toolbar->addBreadcrumb(['title' => 'm_system_system_manager']);
     $this->_toolbar->addBreadcrumb(['title' => 'm_system_manage_manager']);
     $this->_toolbar->addHeaderPrimary('m_system_manage_manager');
     $this->_toolbar->addHeaderSecond('m_system_system_manager');
     $error_is_writable = false;
     if (!is_writable(APP_DIR . '/backup')) {
         $this->flashSession->error('gb_backup_folder_cannot_be_writable ');
         $error_is_writable = true;
     }
     if (!is_writable(APP_DIR . '/config')) {
         $error_is_writable = true;
         $this->flashSession->error('gb_config_folder_cannot_be_writable ');
     }
     if (!$error_is_writable) {
         $this->_toolbar->addSaveButton('system|config|manage');
     }
     $core_config = CoreConfigs::find();
     $config = [];
     foreach ($core_config as $item) {
         $config[$item->key] = $item->value;
     }
     $config = (object) $config;
     $configForm = new ConfigForm($config);
     $this->view->setVar('configForm', $configForm);
     if ($this->request->isPost()) {
         if ($configForm->isValid($_POST, $config)) {
             $error = 0;
             foreach ($configForm->getElements() as $element) {
                 $name = $element->getName();
                 /**
                  * @var $coreConfig CoreConfigs
                  */
                 $coreConfig = CoreConfigs::findFirst(['conditions' => 'key = ?0', 'bind' => [$name]]);
                 if ($coreConfig && $config->{$name} != '') {
                     if ($coreConfig->scope == 'database') {
                         continue;
                     }
                     //Crypt value
                     if ($coreConfig->is_crypt_value) {
                         $coreConfig->value = ZCrypt::getInstance()->encrypt($config->{$name});
                     } else {
                         $coreConfig->value = $config->{$name};
                     }
                     if ($coreConfig->save()) {
                         if ($name == 'defaultTemplate') {
                             $coreTemplate = new CoreTemplates();
                             $coreTemplate->setDefaultTemplate($config->{$name}, 'backend');
                         }
                         if ($name == 'defaultTemplate') {
                             $coreTemplate = new CoreTemplates();
                             $coreTemplate->setDefaultTemplate($config->{$name}, 'frontend');
                         }
                         if ($name == 'language') {
                             $coreLanguage = new CoreLanguages();
                             $coreLanguage->setDefaultLanguage($config->{$name});
                         }
                     } else {
                         $error++;
                         $this->setFlashSession($coreConfig->getMessages(), 'warning');
                     }
                 }
             }
             if ($error != 0) {
                 $this->flashSession->warning('m_system_config_message_some_config_cannot_save');
             } else {
                 //$defaultLanguage = CoreLanguage::findFirst('is_default = 1');
                 $this->flashSession->success('m_system_config_message_config_save_successfully');
                 $configFileContent = file_get_contents(APP_DIR . '/config/config.php');
                 if (file_put_contents(APP_DIR . '/backup/config.backup_' . date('Y-m-d') . '_at_' . date('H-i-s') . '.php', $configFileContent)) {
                     $newConfig = [];
                     $sections = $this->getSectionConfig();
                     foreach ($sections as $section) {
                         $itemsInSection = $this->getItemInSectionConfig($section);
                         if ($section == 'system') {
                             foreach ($itemsInSection as $item) {
                                 if (is_numeric($item->value)) {
                                     $item->value = (int) $item->value;
                                 }
                                 $newConfig[$item->key] = $item->value;
                             }
                         } else {
                             foreach ($itemsInSection as $item) {
                                 if (is_numeric($item->value)) {
                                     $item->value = (int) $item->value;
                                 }
                                 $newConfig[$section][$item->key] = $item->value;
                                 if ($section == 'website') {
                                     /**
                                      * @var CoreLanguages $defaultLanguage
                                      */
                                     $defaultLanguage = CoreLanguages::findFirst('is_default = 1');
                                     /**
                                      * @var CoreConfigs $directionConfig
                                      */
                                     $directionConfig = CoreConfigs::findFirst("scope = 'website' AND key = 'direction'");
                                     $newConfig['website']['language'] = $defaultLanguage->language_code;
                                     $newConfig['website']['metakey'] = htmlspecialchars_decode($defaultLanguage->metaKey);
                                     $newConfig['website']['metadesc'] = htmlspecialchars_decode($defaultLanguage->metaDesc);
                                     $newConfig['website']['sitename'] = htmlspecialchars_decode($defaultLanguage->siteName);
                                     $newConfig['website']['direction'] = $directionConfig->key;
                                     $newConfig['website']['country_image'] = $defaultLanguage->image;
                                 }
                             }
                         }
                     }
                     /**
                      * Todo
                      * Add new on feature ZCMS
                      */
                     $newConfig['apc_cache'] = ['apc_prefix' => 'cache', 'apc_lifetime' => 1800, 'apc_status' => 1];
                     $var_str = var_export($newConfig, true);
                     $newConfigFileContent = "<?php\n\n return {$var_str};\n";
                     if (!file_put_contents(APP_DIR . '/config/config.php', $newConfigFileContent)) {
                         $this->flashSession->warning('gb_config_folder_cannot_be_writable');
                         return false;
                     }
                 } else {
                 }
             }
         } else {
             $this->flashSession->warning('m_system_config_message_please_check_error_field');
             $this->setFlashSession($configForm->getMessages(), 'warning');
             return false;
         }
         $this->view->disable();
         return $this->response->redirect('/admin/system/config');
     }
     return true;
 }
Example #5
0
 /**
  * @param CoreConfigs $data
  */
 public function initialize($data = null)
 {
     $allConfig = CoreConfigs::find()->toArray();
     $isCryptOfAllKey = [];
     foreach ($allConfig as $conf) {
         $isCryptOfAllKey[$conf['key']] = $conf['is_crypt_value'];
     }
     if ($data != null) {
         $allKeyData = get_object_vars($data);
         foreach ($allKeyData as $key => $value) {
             if ($isCryptOfAllKey[$key] == 1) {
                 $data->{$key} = '';
             }
         }
     }
     //Section Website
     $debug = new Select('debug', [0 => __('gb_off'), 1 => __('gb_on')]);
     $debug->addValidator(new InclusionIn(['domain' => ['0', '1']]));
     $this->add($debug);
     $baseUri = new Text('baseUri');
     $this->add($baseUri);
     $metaDesc = new TextArea("metadesc", ['rows' => 4]);
     $this->add($metaDesc);
     $metaKey = new TextArea("metakey");
     $this->add($metaKey);
     $siteName = new Text("sitename");
     $this->add($siteName);
     $direction = new Select('direction', ['ltr' => 'Left to right', 'rtl' => 'Right to Left']);
     $this->add($direction);
     $timezone = new Select('timezone', array_combine(timezone_identifiers_list(), timezone_identifiers_list()));
     $this->add($timezone);
     //$CoreLanguages = CoreLanguages::find(['columns' => 'language_code, title', 'order' => 'language_code']);
     $CoreLanguages = CoreLanguages::find(['order' => 'language_code']);
     $language = new Select('language', $CoreLanguages, ['using' => ['language_code', 'title']]);
     $this->add($language);
     $limit = new Text('limit');
     $limit->addValidator(new Between(['minimum' => 0, 'maximum' => 100, 'message' => 'm_system_module_message_the_limit_must_be_between_1_100']));
     $this->add($limit);
     $media_limit = new Text('media_limit');
     $media_limit->addValidator(new Regex(['pattern' => '/[0-9]+(\\.[0-9]+)?/', 'message' => 'm_system_config_message_this_field_must_be_a_number']));
     $media_limit->addValidator(new Between(['minimum' => 0, 'maximum' => 100, 'message' => 'm_system_module_message_the_media_limit_must_be_between_1_100']));
     $this->add($media_limit);
     $feed_limit = new Text('feed_limit');
     $feed_limit->addValidator(new Regex(['pattern' => '/[0-9]+(\\.[0-9]+)?/', 'message' => 'm_system_config_message_this_field_must_be_a_number']));
     $feed_limit->addValidator(new Between(['minimum' => 0, 'maximum' => 100, 'message' => 'm_system_module_message_the_media_limit_must_be_between_1_100']));
     $this->add($feed_limit);
     //Section memcache
     $mem_cache_status = new Select('mem_cache_status', [0 => __('gb_off'), 1 => __('gb_on')]);
     $mem_cache_status->addValidator(new InclusionIn(['domain' => ['0', '1']]));
     $this->add($mem_cache_status);
     $mem_cache_host = new Text('mem_cache_host');
     $this->add($mem_cache_host);
     $mem_cache_lifetime = new Text('mem_cache_lifetime');
     $this->add($mem_cache_lifetime);
     $mem_cache_prefix = new Text('mem_cache_prefix');
     $this->add($mem_cache_prefix);
     $mem_cache_port = new Text('mem_cache_port');
     $mem_cache_port->addValidator(new Regex(['pattern' => '/[0-9]+(\\.[0-9]+)?/', 'message' => 'm_system_module_message_the_memcache_port_must_be_a_number']));
     $this->add($mem_cache_port);
     //Section apc cache
     $apc_prefix = new Text('apc_prefix');
     $this->add($apc_prefix);
     $apc_lifetime = new Text('apc_lifetime');
     $this->add($apc_lifetime);
     $apc_status = new Select('apc_status', [0 => __('gb_off'), 1 => __('gb_on')]);
     $apc_status->addValidator(new InclusionIn(['domain' => ['0', '1']]));
     $this->add($apc_status);
     //Section Mail
     /**
      * <code>
      * <select id="mail_type" name="mail_type" class="form-control">
      *    <option value="mail">Mail</option>
      *    <option selected="selected" value="smtp">SMTP</option>
      *    <option value="sendmail">SendMail</option>
      * </select>
      * </code>
      */
     $mail_type = new Select('mail_type', ['mail' => __('m_system_config_label_mail_type_value_mail'), 'smtp' => __('m_system_config_label_mail_type_value_smtp'), 'sendmail' => __('m_system_config_label_mail_type_value_sendmail')]);
     $mail_type->addValidator(new InclusionIn(['domain' => ['mail', 'smtp', 'sendmail']]));
     $this->add($mail_type);
     $mail_from = new Text('mail_from');
     $this->add($mail_from);
     $from_name = new Text('from_name');
     $this->add($from_name);
     $send_mail = new Text('send_mail');
     $this->add($send_mail);
     $smtp_user = new Text('smtp_user');
     $this->add($smtp_user);
     $smtp_pass = new Password('smtp_pass');
     $this->add($smtp_pass);
     $smtp_host = new Text('smtp_host');
     $this->add($smtp_host);
     $smtp_secure = new Select('smtp_secure', ['ssl' => 'SSL', 'tsl' => 'TSL']);
     $smtp_secure->addValidator(new InclusionIn(['domain' => ['ssl', 'tsl']]));
     $this->add($smtp_secure);
     $smtp_port = new Text('smtp_port');
     $smtp_port->addValidator(new Regex(['pattern' => '/[0-9]+(\\.[0-9]+)?/', 'message' => 'm_system_module_message_the_smtp_port_must_be_a_number']));
     $this->add($smtp_port);
     $smtp_auth = new Text('smtp_auth');
     $smtp_auth->addValidator(new Regex(['pattern' => '/[0-9]+(\\.[0-9]+)?/', 'message' => 'm_system_module_message_the_smtp_auth_must_be_a_number']));
     $this->add($smtp_auth);
     //Section log
     $log = new Select('log', ['0' => __('gb_off'), '1' => __('gb_on')]);
     $log->addValidator(new InclusionIn(['domain' => ['0', '1']]));
     $this->add($log);
     $log_type = new Select('log_type', ['file' => __('m_system_config_label_database_file'), 'database' => __('m_system_config_label_database')]);
     $log_type->addValidator(new InclusionIn(['domain' => ['file', 'database']]));
     $this->add($log_type);
     $auth_lifetime = new Text('auth_lifetime');
     $auth_lifetime->addValidator(new Regex(['pattern' => '/[0-9]+(\\.[0-9]+)?/', 'message' => 'm_system_module_message_the_auth_lifetime_must_be_a_number']));
     $this->add($auth_lifetime);
     //Section Template
     //Add translation template
     ZTranslate::getInstance()->addTemplateLang(get_child_folder(APP_DIR . '/templates/backend'));
     ZTranslate::getInstance()->addTemplateLang(get_child_folder(APP_DIR . '/templates/frontend'), 'frontend');
     //Backend default template
     $backendTemplateArray = CoreTemplates::find("location = 'backend'")->toArray();
     $backendTemplateBaseName = array_column($backendTemplateArray, 'base_name');
     $backendTemplate = array_combine($backendTemplateBaseName, array_map('__', array_column($backendTemplateArray, 'name')));
     $defaultTemplate = new Select('defaultTemplate', $backendTemplate);
     $defaultTemplate->addValidator(new InclusionIn(['domain' => $backendTemplateBaseName]));
     $this->add($defaultTemplate);
     //Backend compile template
     $compileTemplate = new Select('compileTemplate', ['0' => __('gb_off'), '1' => __('gb_on')]);
     $compileTemplate->addValidator(new InclusionIn(['domain' => ['0', '1']]));
     $this->add($compileTemplate);
     //Frontend default template
     $frontendTemplateArray = CoreTemplates::find("location = 'frontend'")->toArray();
     $frontendTemplateBaseName = array_column($frontendTemplateArray, 'base_name');
     $frontendTemplate = array_combine($frontendTemplateBaseName, array_map('__', array_column($frontendTemplateArray, 'name')));
     $defaultTemplate = new Select('defaultTemplate', $frontendTemplate);
     $defaultTemplate->addValidator(new InclusionIn(['domain' => $frontendTemplateBaseName]));
     $this->add($defaultTemplate);
     //Frontend compile template
     $compileTemplate = new Select('compileTemplate', ['0' => __('gb_off'), '1' => __('gb_on')]);
     $compileTemplate->addValidator(new InclusionIn(['domain' => ['0', '1']]));
     $this->add($compileTemplate);
     //Shipping
     $shipping = new Text('sender_id');
     $this->add($shipping);
     $shipping = new Text('sender_name');
     $this->add($shipping);
     $shipping = new Text('sender_contact_name');
     $this->add($shipping);
     $shipping = new Text('sender_contact_phone');
     $this->add($shipping);
     $shipping = new Text('sender_address_1');
     $this->add($shipping);
     $shipping = new Text('sender_address_2');
     $this->add($shipping);
     $shipping = new Text('sender_town');
     $this->add($shipping);
     $shipping = new Text('sender_state');
     $this->add($shipping);
     $shipping = new Text('sender_post_code');
     $this->add($shipping);
     $shipping = new Text('sender_country');
     $this->add($shipping);
     $shipping = new Text('toll_slid');
     $this->add($shipping);
     $shipping = new Text('toll_service_name');
     $this->add($shipping);
     $shipping = new Text('toll_service_code');
     $this->add($shipping);
     $shipping = new Text('toll_email_transmission');
     $this->add($shipping);
     $shipping = new Text('toll_system_transmission_id');
     $this->add($shipping);
     $shipping = new Text('line_weight');
     $this->add($shipping);
     $shipping = new Text('charge_account');
     $this->add($shipping);
     //Payment get way
     $merchant_number = new Text('merchant_number');
     $this->add($merchant_number);
     $merchant_number = new Text('merchant_username');
     $this->add($merchant_number);
     $merchant_number = new Password('merchant_password');
     $this->add($merchant_number);
     $merchant_number = new Text('merchant_referrence');
     $this->add($merchant_number);
     $merchant_number = new Text('link_authorize');
     $this->add($merchant_number);
     $merchant_number = new Text('link_pay_request');
     $this->add($merchant_number);
     $merchant_number = new Text('link_verify');
     $this->add($merchant_number);
     $merchant_number = new Text('link_pay_shop');
     $this->add($merchant_number);
     $payment_return_url = new Text('return_url');
     $this->add($payment_return_url);
 }
Example #6
0
 /**
  * Update widget order
  *
  * @return PResponse
  * @throws Exception
  */
 public function updateWidgetOrderAction()
 {
     $response = new PResponse();
     $content = '';
     $response->setHeader("Content-Type", "application/json");
     if ($this->request->isAjax()) {
         $widget_id = $this->request->getPost('widget_id', 'int');
         $newIndex = $this->request->getPost('index', 'int');
         $sidebar = str_replace(' ', '', $this->request->getPost('sidebar_name', ['string', 'striptags']));
         if ($widget_id && $newIndex && $sidebar) {
             /**
              * @var CoreWidgetValues $widget
              */
             $widget = CoreWidgetValues::findFirst($widget_id);
             /**
              * @var CoreSidebars $CoreSidebars
              */
             $CoreSidebars = CoreSidebars::findFirst(['conditions' => 'sidebar_base_name = ?1', 'bind' => [1 => $sidebar]]);
             if ($widget && $CoreSidebars) {
                 /**
                  * @var CoreTemplates $defaultFrontendTemplate
                  */
                 $defaultFrontendTemplate = CoreTemplates::findFirst("location = 'frontend' AND published = 1");
                 $themeName = $defaultFrontendTemplate->base_name;
                 $widget->reOder('sidebar_base_name = ?1', [1 => $CoreSidebars->sidebar_base_name]);
                 $widget->reOder('sidebar_base_name = ?1', [1 => $widget->sidebar_base_name]);
                 if ($widget->ordering > $newIndex) {
                     $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering >= {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                     $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering < {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                 } elseif ($widget->ordering < $newIndex) {
                     $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering > {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                     $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering <= {$newIndex} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
                 }
                 if (isset($queryUp) && isset($queryDown)) {
                     $this->db->execute($queryUp);
                     $this->db->execute($queryDown);
                 }
                 $widget->ordering = $newIndex;
                 $widget->sidebar_base_name = $CoreSidebars->sidebar_base_name;
                 if ($widget->save()) {
                     $content = '1';
                     $widget->reOder('sidebar_base_name = ?1', [1 => $sidebar]);
                     $widget->reOder('sidebar_base_name = ?1', [1 => $CoreSidebars->sidebar_base_name]);
                 } else {
                     //Do something
                 }
             }
         }
     }
     $response->setJsonContent($content);
     return $response;
 }
Example #7
0
 /**
  * Published template
  *
  * @param int $id
  * @param string $redirect
  * @param bool $log
  * @return \Phalcon\Http\ResponseInterface|void
  */
 public function publishAction($id = null, $redirect = null, $log = true)
 {
     //Add template language
     $this->_addTemplateLang();
     $id = (int) $id;
     /**
      * @var CoreTemplates $templateMustPublish
      */
     $templateMustPublish = CoreTemplates::findFirst($id);
     if ($templateMustPublish) {
         $query = "UPDATE core_templates SET published = 0 WHERE location = '{$templateMustPublish->location}'";
         $this->db->execute($query);
         $templateMustPublish->published = 1;
         $templateMustPublish->save();
         file_put_contents(APP_DIR . '/' . $templateMustPublish->location . '/index.volt', '{% extends "../../../templates/' . $templateMustPublish->location . '/' . $templateMustPublish->base_name . '/index.volt" %}');
         if ($templateMustPublish->location == 'frontend') {
             //Do something
         } elseif ($templateMustPublish->location == 'backend') {
             //Do something
         }
         $this->flashSession->success(__('m_template_notice_template_is_active', ['1' => __($templateMustPublish->name), '2' => $templateMustPublish->location]));
     } else {
         $this->flashSession->error(__('m_template_notice_template_not_exists'));
     }
     return $this->response->redirect('/admin/template/');
 }