예제 #1
0
 public function actionIndex()
 {
     $model = Config::find()->one();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }
예제 #2
0
 /**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = Config::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['config_id' => $this->config_id]);
     $query->andFilterWhere(['like', 'config_name', $this->config_name])->andFilterWhere(['like', 'config_value', $this->config_value]);
     return $dataProvider;
 }
예제 #3
0
 public function actionSubscribe()
 {
     if (Yii::$app->request->isAjax) {
         $email = Yii::$app->request->post('email');
         $validator = new EmailValidator();
         if ($validator->validate($email)) {
             $mc = new Mailchimp(Config::find()->where('name = :name', [':name' => 'mailChimpKey'])->one()->value);
             $Mailchimp_Lists = new Mailchimp_Lists($mc);
             $subscriber = $Mailchimp_Lists->subscribe(Config::find()->where('name = :name', [':name' => 'mailChimpListId'])->one()->value, array('email' => htmlentities($email)));
             if (!empty($subscriber['leid'])) {
                 echo "'Ваш электронный адрес добавлен в подписчики'";
             } else {
                 echo "error";
             }
         } else {
             echo "Неправильный электронный адрес";
         }
     }
 }
예제 #4
0
 public function getUIConfig()
 {
     $cache = Yii::$app->get($this->cacheComponent);
     $cache->delete('UI_CONFIG');
     $config = $cache->get('UI_CONFIG');
     if ($config === false) {
         $config = [];
         $configModels = Config::find()->where(['option' => 'cdnServer'])->all();
         foreach ($configModels as $model) {
             $config[$model->option] = $model->value;
         }
         $cache->set('UI_CONFIG', $config);
     }
     if (YII_ENV_DEV || Yii::$app->session->get("debugMode", false)) {
         $sessionConfig = Yii::$app->session->get("uiConfig", false);
         if ($sessionConfig !== false) {
             foreach ($sessionConfig as $key => $value) {
                 $config[$key] = $value;
             }
         }
     }
     return $config;
 }
예제 #5
0
 public function run()
 {
     $config = Config::find()->select('watermark')->one();
     return $this->render('watermark', ['watermark' => $config->watermark]);
 }
예제 #6
0
파일: Video.php 프로젝트: Romario25/porka
 public static function getVideoUrl($w, $h, $url)
 {
     $config = ArrayHelper::map(Config::find()->all(), 'name', 'value');
     $s3 = new S3Client(['version' => 'latest', 'region' => 'us-west-2', 'credentials' => ['key' => $config['amazon_key'], 'secret' => $config['amazon_secret']]]);
     $result = "https://s3-us-west-2.amazonaws.com/" . $config['amazon_bucket'] . "/video/" . $w . "_" . $h . "_" . $url;
     //        if($s3->doesObjectExist($config['amazon_bucket'], "video/".$w."_".$h."_".$url)){
     //            return $result;
     //        } else {
     //            return "";
     //        }
     return $result;
 }
예제 #7
0
 public function beforeDelete()
 {
     $photos = Photos::find()->where(['catalog_id' => $this->id])->all();
     //print_r($photos); die();
     foreach ($photos as $photo) {
         if (file_exists("../web" . $photo->url_thumbnail)) {
             unlink("../web" . $photo->url_thumbnail);
         }
         $config = ArrayHelper::map(Config::find()->all(), 'name', 'value');
         $s3 = new S3Client(['version' => 'latest', 'region' => 'us-west-2', 'credentials' => ['key' => $config['amazon_key'], 'secret' => $config['amazon_secret']]]);
         if ($this->storage == 2) {
             try {
                 $res = $s3->deleteObject(['Bucket' => $config['amazon_bucket'], 'Key' => 'photo/' . urldecode(mb_substr($photo->url, mb_strrpos($photo->url, '/') + 1))]);
             } catch (S3Exception $e) {
                 echo $e->getMessage();
                 Yii::$app->session->setFlash('error', $e->getMessage());
             }
         } else {
             if ($this->storage == 1) {
                 if (file_exists("../web" . $photo->url)) {
                     unlink("../web" . $photo->url);
                 }
             } else {
                 $arr = explode('/', $photo->url);
                 $f = array_pop($arr);
                 //  print_r($f); //die();
                 $this->ftp_delete($f);
             }
         }
     }
     return parent::beforeDelete();
     // TODO: Change the autogenerated stub
 }
예제 #8
0
 /**
  * Get models from specified section.
  * @param string $section
  * @return Config[]
  */
 public static function getConfigsBySection($section)
 {
     return Config::find()->where(['section' => $section])->indexBy('id')->all();
 }
예제 #9
0
 public function run()
 {
     $config = Config::find()->select('logo')->one();
     return $config->logo;
 }
예제 #10
0
 /**
  * Lists all Config models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Config::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }