/**
  * @inheritdoc
  */
 public function run()
 {
     if ($this->hasModel()) {
         $name = Html::getInputName($this->model, $this->attribute);
         $value = null;
         if (is_array($this->model->{$this->attribute})) {
             $value = StringHelper::base64EncodeUrl(serialize((array) $this->model->{$this->attribute}));
         } else {
             if (is_string($this->model->{$this->attribute})) {
                 $value = $this->model->{$this->attribute};
             }
         }
         $this->options['id'] = Html::getInputId($this->model, $this->attribute);
         //$element = Html::activeHiddenInput($this->model, $this->attribute, $this->options);
         $element = Html::hiddenInput($name, $value, $this->options);
     } else {
         $element = Html::hiddenInput($this->name, $this->value, $this->options);
     }
     $this->registerPlugin();
     $this->clientOptions['componentSelectId'] = $this->componentSelectId;
     $this->clientOptions['componentSettingsId'] = Html::getInputId($this->model, $this->attribute);
     $this->clientOptions['id'] = $this->id;
     $this->clientOptions['backend'] = UrlHelper::construct('/cms/admin-universal-component-settings/index')->setSystemParam(Module::SYSTEM_QUERY_EMPTY_LAYOUT, 'true')->enableAdmin()->toString();
     return $this->render('element', ['widget' => $this, 'element' => $element]);
 }
Example #2
0
 /**
  * @param array $data
  * @param string $method
  *
  * @return ApiResponseOk|ApiResponseError
  */
 private function _send(array $data, $method = 'post')
 {
     $client = new Client(['requestConfig' => ['format' => Client::FORMAT_JSON]]);
     $response = $client->createRequest()->setMethod($method)->setUrl($this->url)->addHeaders(['Content-type' => 'application/json'])->addHeaders(['user-agent' => 'JSON-RPC PHP Client'])->setData($data)->setOptions(['timeout' => $this->timeout])->send();
     //Нам сказали это всегда json. А... нет, все мы люди, бывает и не json )
     try {
         $dataResponse = (array) Json::decode($response->content);
     } catch (\Exception $e) {
         \Yii::error("Json api response error: " . $e->getMessage() . ". Response: \n{$response->content}", self::className());
         //Лайф хак, вдруг разработчики апи оставили var dump
         if ($pos = strpos($response->content, "{")) {
             $content = StringHelper::substr($response->content, $pos, StringHelper::strlen($response->content));
             try {
                 $dataResponse = (array) Json::decode($content);
             } catch (\Exception $e) {
                 \Yii::error("Api response error: " . $response->content, self::className());
             }
         }
     }
     if (!$response->isOk) {
         \Yii::error($response->content, self::className());
         $responseObject = new ApiResponseError($dataResponse);
     } else {
         $responseObject = new ApiResponseOk($dataResponse);
     }
     $responseObject->statusCode = $response->statusCode;
     return $responseObject;
 }
Example #3
0
 /**
  * Runs the action
  *
  * @return string result content
  */
 public function run()
 {
     if (($exception = Yii::$app->getErrorHandler()->exception) === null) {
         return '';
     }
     if ($exception instanceof \HttpException) {
         $code = $exception->statusCode;
     } else {
         $code = $exception->getCode();
     }
     if ($exception instanceof Exception) {
         $name = $exception->getName();
     } else {
         $name = $this->defaultName ?: Yii::t('yii', 'Error');
     }
     if ($code) {
         $name .= " (#{$code})";
     }
     if ($exception instanceof UserException) {
         $message = $exception->getMessage();
     } else {
         $message = $this->defaultMessage ?: Yii::t('yii', 'An internal server error occurred.');
     }
     if (Yii::$app->getRequest()->getIsAjax()) {
         $rr = new RequestResponse();
         $rr->success = false;
         $rr->message = "{$name}: {$message}";
         return (array) $rr;
     } else {
         if (\Yii::$app->admin->requestIsAdmin) {
             if (\Yii::$app->user->can(CmsManager::PERMISSION_ADMIN_ACCESS)) {
                 $this->controller->layout = \Yii::$app->cms->moduleAdmin->layout;
                 return $this->controller->render('@skeeks/cms/modules/admin/views/error/error', ['message' => nl2br(Html::encode($message))]);
             } else {
                 $this->controller->layout = '@skeeks/cms/modules/admin/views/layouts/unauthorized';
                 return $this->controller->render('@skeeks/cms/modules/admin/views/error/unauthorized-403', ['message' => nl2br(Html::encode($message))]);
             }
         } else {
             //All requests are to our backend
             //TODO::Add image processing
             $info = pathinfo(\Yii::$app->request->pathInfo);
             if ($extension = ArrayHelper::getValue($info, 'extension')) {
                 $extension = \skeeks\cms\helpers\StringHelper::strtolower($extension);
                 if (in_array($extension, ['js', 'css'])) {
                     \Yii::$app->response->format = Response::FORMAT_RAW;
                     if ($extension == 'js') {
                         \Yii::$app->response->headers->set('Content-Type', 'application/javascript');
                     }
                     if ($extension == 'css') {
                         \Yii::$app->response->headers->set('Content-Type', 'text/css');
                     }
                     $url = \Yii::$app->request->absoluteUrl;
                     return "/* File: '{$url}' not found */";
                 }
             }
             return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]);
         }
     }
 }
Example #4
0
 /**
  * @return null|string
  */
 public function getVerifyedCaptcha()
 {
     $captcha = $this->_captchaSource;
     $captcha = StringHelper::substr($this->_captchaSource, 4, 5);
     $captcha = $captcha . StringHelper::substr($this->_captchaSource, 1, 4);
     $captcha = $captcha . StringHelper::substr($this->_captchaSource, 1, 2);
     $captcha = $captcha . StringHelper::substr($this->_captchaSource, 5, 6);
     return $captcha;
 }
Example #5
0
 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $sourceOriginalFile = File::object($pathInfo);
     $extension = $sourceOriginalFile->getExtension();
     if (!$extension) {
         return false;
     }
     if (!in_array(StringHelper::strtolower($extension), (array) \Yii::$app->imaging->extensions)) {
         return false;
     }
     return ['cms/imaging/process', $params];
 }
 public function actionSave()
 {
     $rr = new RequestResponse();
     $classComponent = \Yii::$app->request->get('component');
     /**
      * @var $component \skeeks\cms\relatedProperties\PropertyType;
      */
     $component = new $classComponent();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $component->load(\Yii::$app->request->post());
         $forSave = StringHelper::base64EncodeUrl(serialize($component->attributes));
         $rr->success = true;
         $rr->message;
         $rr->data = ['forSave' => $forSave];
         return $rr;
     }
 }
Example #7
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['created_by', 'updated_by', 'created_at', 'updated_at', 'priority', 'multiple_cnt', 'version'], 'integer'], [['name', 'component'], 'required'], [['component_settings'], 'safe'], [['name', 'component', 'hint'], 'string', 'max' => 255], [['code'], 'string', 'max' => 64], [['active', 'property_type', 'list_type', 'multiple', 'with_description', 'searchable', 'filtrable', 'is_required', 'smart_filtrable'], 'string', 'max' => 1], ['code', 'default', 'value' => function ($model, $attribute) {
         return "property" . StringHelper::ucfirst(md5(rand(1, 10) . time()));
     }], ['priority', 'default', 'value' => 500], [['active', 'searchable'], 'default', 'value' => Cms::BOOL_Y], [['is_required', 'smart_filtrable', 'filtrable', 'with_description'], 'default', 'value' => Cms::BOOL_N]]);
 }
Example #8
0
 /**
  * Динамическая отдача robots.txt
  */
 public function actionResult()
 {
     $searchQuery = \Yii::$app->cmsSearch->searchQuery;
     $this->view->title = StringHelper::ucfirst($searchQuery) . " — результаты поиска";
     return $this->render($this->action->id);
 }
Example #9
0
 /**
  * @param $value
  * @return $this
  */
 public function setComponentSettingsString($value)
 {
     $this->component_settings = unserialize(\skeeks\cms\helpers\StringHelper::base64DecodeUrl($value));
     return $this;
 }
Example #10
0
 /**
  * @inheritdoc
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     $text = $model->{$this->attribute};
     return "<small>" . StringHelper::substr($text, 0, $this->maxLength) . (StringHelper::strlen($text) > $this->maxLength ? " ..." : "") . "</small>";
 }
Example #11
0
 /**
  * Проверка валидности значения
  *
  * @param  mixed $value
  * @return Ix_Validate_Result
  */
 public function validate($extension)
 {
     return !in_array(StringHelper::strtolower($extension), self::getPossibleExtensions()) ? $this->_bad("Расширение '{$extension}' Не поддерживается данной библиотекой") : $this->_ok();
 }
Example #12
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return ArrayHelper::merge(parent::rules(), [[['created_by', 'updated_by', 'created_at', 'updated_at', 'priority', 'multiple_cnt', 'version'], 'integer'], [['name', 'component'], 'required'], [['component_settings'], 'safe'], [['name', 'component', 'hint'], 'string', 'max' => 255], [['code'], function ($attribute) {
         if (!preg_match('/^[a-zA-Z]{1}[a-zA-Z0-9]{1,255}$/', $this->{$attribute})) {
             $this->addError($attribute, \Yii::t('skeeks/cms', 'Use only letters of the alphabet in lower or upper case and numbers, the first character of the letter (Example {code})', ['code' => 'code1']));
         }
     }], [['active', 'property_type', 'list_type', 'multiple', 'with_description', 'searchable', 'filtrable', 'is_required', 'smart_filtrable'], 'string', 'max' => 1], ['code', 'default', 'value' => function ($model, $attribute) {
         return "property" . StringHelper::ucfirst(md5(rand(1, 10) . time()));
     }], ['priority', 'default', 'value' => 500], [['active', 'searchable'], 'default', 'value' => Cms::BOOL_Y], [['is_required', 'smart_filtrable', 'filtrable', 'with_description'], 'default', 'value' => Cms::BOOL_N]]);
 }
Example #13
0
File: Seo.php Project: Liv1020/cms
 /**
  *
  * Генерация ключевых слов
  *
  * @param string $content
  * @return string
  */
 public function keywords($content = "")
 {
     $result = "";
     $content = $this->_processPriority($content);
     if ($content) {
         //Избавляем от тегов и разбиваем в массив
         $content = preg_replace("!<script(.*?)</script>!si", "", $content);
         $content = preg_replace('/(&\\w+;)|\'/', ' ', strtolower(strip_tags($content)));
         $words = preg_split('/(\\s+)|([\\.\\,\\:\\(\\)\\"\'\\!\\;])/m', $content);
         foreach ($words as $n => $word) {
             if (strlen($word) < $this->minKeywordLenth || (int) $word || strpos($word, '/') !== false || strpos($word, '@') !== false || strpos($word, '_') !== false || strpos($word, '=') !== false || in_array(StringHelper::strtolower($word), $this->keywordsStopWords)) {
                 unset($words[$n]);
             }
         }
         // получаем массив с числом каждого слова
         $words = array_count_values($words);
         arsort($words);
         // сортируем - наиболее частые - вперед
         $words = array_keys($words);
         $count = 0;
         foreach ($words as $word) {
             if (strlen($result) > $this->maxKeywordsLength) {
                 break;
             }
             $count++;
             if ($count > 1) {
                 $result .= ', ' . StringHelper::strtolower($word);
             } else {
                 $result .= StringHelper::strtolower($word);
             }
         }
     }
     return $result;
 }
Example #14
0
 /**
  * Генерация логина пользователя
  * @return $this
  */
 public function generateUsername()
 {
     /*if ($this->email)
       {
           $userName = \skeeks\cms\helpers\StringHelper::substr($this->email, 0, strpos() );
       }*/
     $userLast = static::find()->orderBy("id DESC")->one();
     $this->username = "******" . ($userLast->id + 1);
     if (static::find()->where(['username' => $this->username])->one()) {
         $this->username = $this->username . "_" . \skeeks\cms\helpers\StringHelper::substr(md5(time()), 0, 6);
     }
     return $this;
 }