protected function renderContent()
 {
     $model = new Block();
     $block_model = null;
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'block-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     $current_type = isset($_GET['type']) ? trim($_GET['type']) : '0';
     Yii::app()->controller->layout = isset($_GET['embed']) ? 'clean' : 'main';
     if ($current_type != '0') {
         $block_ini = parse_ini_file(Yii::getPathOfAlias('common.blocks.' . $current_type) . DIRECTORY_SEPARATOR . 'info.ini');
         //Include the class
         Yii::import('common.blocks.' . $current_type . '.' . $block_ini['class']);
         $model->type = $current_type;
         $block_model = new $block_ini['class']();
         // collect user input data
         if (isset($_POST['Block'])) {
             $model->attributes = $_POST['Block'];
             $model->type = $_POST['Block']['type'];
             $params = $block_model->params();
             $block_params = array();
             foreach ($params as $key => $param) {
                 $block_params[$key] = $block_model->{$key} = isset($_POST['Block'][$key]) ? $_POST['Block'][$key] : null;
             }
             if ($model->validate()) {
                 if (!$block_model->validate()) {
                     foreach ($block_model->errors as $key => $message) {
                         $model->addError($key, $message);
                     }
                 } else {
                     $block_model->beforeBlockSave();
                     //Re-set params if needed
                     foreach ($params as $key => $param) {
                         $block_params[$key] = $block_model->{$key};
                     }
                     $model->params = b64_serialize($block_params);
                     if ($model->save()) {
                         $block_model->afterBlockSave();
                         user()->setFlash('success', t('cms', 'Create new Block Successfully!'));
                         if (!isset($_GET['embed'])) {
                             $model = new Block();
                             $block_model = new $block_ini['class']();
                             Yii::app()->controller->redirect(array('create'), array('type' => $current_type));
                         }
                     }
                 }
             }
         }
         $this->render('cmswidgets.views.block.block_form_widget', array('model' => $model, 'type' => $current_type, 'block_model' => $block_model));
     } else {
         $this->render('cmswidgets.views.block.block_start_widget', array('model' => $model, 'type' => $current_type));
     }
 }
Example #2
0
 public function actionIndex()
 {
     //First need to check has_install or not ?
     if (file_exists(COMMON_FOLDER . DIRECTORY_SEPARATOR . '.locked')) {
         echo t('cms', 'Website installed! Please remove .locked file in common folder');
     } else {
         $model = new InstallForm();
         $model->app_name = 'New Application';
         $model->site_title = 'New Application - Site Title';
         $model->site_description = 'New Application - Site Description';
         $model->db_host = 'localhost';
         $path = Yii::app()->getbaseUrl(true);
         $new_path = str_replace('/backend', '', $path);
         $backend_path = $new_path . '/backend' . '/';
         $web_path = $new_path . '/web' . '/';
         $model->url_path = $path;
         $model->url_resource_path = $new_path . '/resources';
         $model->admin_email = '*****@*****.**';
         if (isset($_POST['InstallForm'])) {
             $model->attributes = $_POST['InstallForm'];
             $string_connection = 'mysql:host=' . $model->db_host . ';dbname=' . $model->db_name;
             $connection = new CDbConnection($string_connection, $model->db_username, $model->db_password);
             // Get SQL Script
             $sql = file_get_contents(CMS_FOLDER . DIRECTORY_SEPARATOR . '_DATABASE' . DIRECTORY_SEPARATOR . 'data.sql', true);
             if ($sql) {
                 //Replace some default attributes
                 $command = $connection->createCommand($sql);
                 if ($command->execute() !== false) {
                     //Modify Settings Values
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'general', PDO::PARAM_STR);
                     $command->bindValue(':k', 'site_name', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize($model->app_name), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'general', PDO::PARAM_STR);
                     $command->bindValue(':k', 'site_title', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize($model->site_title), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'general', PDO::PARAM_STR);
                     $command->bindValue(':k', 'site_description', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize($model->site_description), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'system', PDO::PARAM_STR);
                     $command->bindValue(':k', 'support_email', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize($model->admin_email), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'system', PDO::PARAM_STR);
                     $command->bindValue(':k', 'page_size', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize('10'), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'general', PDO::PARAM_STR);
                     $command->bindValue(':k', 'homepage', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize('home'), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_settings SET `value` = :v where `category` = :c and `key` = :k ");
                     $command->bindValue(':c', 'system', PDO::PARAM_STR);
                     $command->bindValue(':k', 'keep_file_name_upload', PDO::PARAM_STR);
                     $command->bindValue(':v', b64_serialize('0'), PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_user SET `password` = :p where `username` = :n ");
                     $command->bindValue(':p', PassHash::hash('123456'), PDO::PARAM_STR);
                     $command->bindValue(':n', 'admin', PDO::PARAM_STR);
                     $command->execute();
                     $command = $connection->createCommand("UPDATE gxc_user SET `password` = :p where `username` = :n ");
                     $command->bindValue(':p', PassHash::hash('123456'), PDO::PARAM_STR);
                     $command->bindValue(':n', 'reporter', PDO::PARAM_STR);
                     $command->execute();
                     // Modify Environments
                     $apps = GxcHelpers::getAllApps(true);
                     foreach ($apps as $app) {
                         $env = file_get_contents($app . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'environment.php');
                         if (strpos($app, 'backend') !== false) {
                             //Backend, Apply its environment
                             $env = str_replace('{{site_path}}', $backend_path, $env);
                         }
                         if (strpos($app, 'web') !== false) {
                             //Web, Apply its environment
                             $env = str_replace('{{site_path}}', $web_path, $env);
                         }
                         $env = str_replace('{{site_name}}', $model->app_name, $env);
                         $env = str_replace('{{resource_url}}', $model->url_resource_path, $env);
                         $env = str_replace('{{timezone}}', $model->timezone, $env);
                         $env = str_replace('{{admin_email}}', $model->admin_email, $env);
                         $env = str_replace('{{db_connect_string}}', $string_connection, $env);
                         $env = str_replace('{{db_username}}', $model->db_username, $env);
                         $env = str_replace('{{db_password}}', $model->db_password, $env);
                         file_put_contents($app . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'environment.php', $env);
                     }
                     //Create lock file in COMMON folder
                     if (!file_put_contents(COMMON_FOLDER . DIRECTORY_SEPARATOR . '.locked', 'installed')) {
                         echo "Error while creating locking install file!";
                     } else {
                         $this->redirect($path);
                     }
                 } else {
                     echo "Error while installing! Please check config file and try again";
                 }
             } else {
                 echo "Can't file data.sql file in COMMON FOLDER";
             }
         }
         $this->render('index', array('model' => $model));
     }
     Yii::app()->end();
 }
Example #3
0
 protected function addDbItem($category = 'system', $key, $value)
 {
     $connection = $this->getDbComponent();
     $command = $connection->createCommand('SELECT id FROM ' . $this->getTableName() . ' WHERE `category`=:cat AND `key`=:key LIMIT 1');
     $command->bindParam(':cat', $category);
     $command->bindParam(':key', $key);
     $result = $command->queryRow();
     $value = b64_serialize($value);
     if (!empty($result)) {
         $command = $connection->createCommand('UPDATE ' . $this->getTableName() . ' SET `value`=:value WHERE `category`=:cat AND `key`=:key');
     } else {
         $command = $connection->createCommand('INSERT INTO ' . $this->getTableName() . ' (`category`,`key`,`value`) VALUES(:cat,:key,:value)');
     }
     $command->bindParam(':cat', $category);
     $command->bindParam(':key', $key);
     $command->bindParam(':value', $value);
     $command->execute();
 }