/** * @param \yii\rest\Action $action * @return \yii\data\ActiveDataProvider */ public function prepareListDataProvider($action) { /* @var $modelClass PageModel */ $modelClass = $action->modelClass; $Query = $modelClass::find(); $search = str_clean(Request()->get('search')); if (!empty($search)) { $Query->search($search); } $deleted = Request()->get('deleted'); if ($deleted === 'false') { $Query->withoutDeleted(); } return new \yii\data\ActiveDataProvider(['query' => $Query, 'pagination' => ['pageSize' => 15]]); }
function str_clean($str, $removeSpaces = false) { //remove html, spacers, html_entities... if (is_array($str)) { $res = array(); foreach ($str as $k => $v) { $res[$k] = str_clean($v, $removeSpaces); } return $res; } $res = str_replace(">", "> ", str_replace(" ", " ", $str)); $res = html_entity_decode(strip_tags($res)); $res = preg_replace("{[" . chr(1) . "-" . chr(32) . "]+}si", " ", $res); return $removeSpaces ? str_replace(" ", "", trim($res)) : trim($res); }
/** * @param \yii\rest\Action $action * @return \yii\data\ActiveDataProvider */ public function prepareListDataProvider($action) { /* @var $modelClass FeedItemModel */ $modelClass = $action->modelClass; $Query = $modelClass::find(); $section = str_clean(Request()->get('section')); if (!empty($section)) { $Query->bySectionSlug($section); } $search = str_clean(Request()->get('search')); if (!empty($search)) { $Query->search($search); } $deleted = Request()->get('deleted'); if ($deleted === 'false') { $Query->withoutDeleted(); } $Query->orderBy(['sort' => SORT_DESC]); return new \yii\data\ActiveDataProvider(['query' => $Query, 'pagination' => ['pageSize' => 10]]); }
/** * @return array * @throws \Exception * @throws \yii\web\BadRequestHttpException * @throws \yii\web\NotFoundHttpException */ public function actionDelete() { $result = ['result' => false, 'message' => \Yii::t('account', 'Unknown error')]; $account_id = (int) Request()->get('account_id'); $key = str_clean(Request()->get('key')); if (empty($account_id)) { throw new \yii\web\BadRequestHttpException('Empty account id'); } /** @var \cookyii\modules\Account\resources\AccountProperty $AccountPropertyModel */ $AccountPropertyModel = \Yii::createObject(\cookyii\modules\Account\resources\AccountProperty::className()); $Property = $AccountPropertyModel::find()->byAccountId($account_id)->byKey($key)->one(); if (empty($Property)) { throw new \yii\web\NotFoundHttpException('Property not found'); } if ($Property->delete() === false) { $result = ['result' => false, 'message' => \Yii::t('account', 'Unable to remove a property')]; } else { $result = ['result' => true, 'message' => \Yii::t('account', 'Property was successfully removed')]; } return $result; }
/** * @return array */ public function run() { $result = ['result' => false, 'message' => \Yii::t('cookyii', 'Unknown error')]; $section_slug = str_clean(Request()->post('section_slug')); /** @var $modelClass \cookyii\modules\Feed\resources\FeedSection\Model */ $modelClass = $this->modelClass; $Section = null; if (!empty($section_slug)) { $Section = $modelClass::find()->bySlug($section_slug)->one(); } if (empty($Section)) { $Section = new $modelClass(); } $SectionEditForm = \Yii::createObject(['class' => Feed\backend\forms\SectionEditForm::class, 'Section' => $Section]); $SectionEditForm->load(Request()->post()) && $SectionEditForm->validate() && $SectionEditForm->save(); if ($SectionEditForm->hasErrors()) { $result = ['result' => false, 'message' => \Yii::t('cookyii', 'When executing a query the error occurred'), 'errors' => $SectionEditForm->getFirstErrors()]; } else { $result = ['result' => true, 'message' => \Yii::t('cookyii.feed', 'Section successfully saved'), 'section_id' => $Section->id, 'section_slug' => $Section->slug]; } return $result; }
function parse_arg() { $new_args = pt_parse_arg($this->arg); if (isset($new_args['NOFORM'])) { $this->n = ""; $this->nt = ""; } if (isset($new_args['WIDTH'])) { $this->resize_width = $new_args['WIDTH']; } else { $this->resize_width = (int) $this->settings['resize_width']; } $this->nodef = isset($new_args['NODEF']); $this->ajax = isset($new_args['AJAX']); if (isset($new_args['ALTTEXT'])) { $this->alt_text = str_clean($new_args['ALTTEXT']); } else { if ($this->post->post_title == '') { $this->alt_text = $this->default_title; } else { $this->alt_text = $this->post->post_title; } } if (isset($new_args['USECATNAME'])) { $this->use_catname = $new_args['USECATNAME'] == 1; } else { $this->use_catname = $this->settings['use_catname'] == 'true'; } if (isset($new_args['SHOWTITLE']) && $new_args['SHOWTITLE'] != '') { $this->show_title = $this->Return_Title($new_args['SHOWTITLE']); } if (isset($new_args['CAPTION'])) { $this->has_caption = $new_args['CAPTION'] == 1; } else { $this->has_caption = $this->settings['caption'] == 'true'; } if (isset($new_args['TITLE'])) { $this->img_title = $this->Get_Title($new_args['TITLE']); } else { $this->img_title = $this->title; } if (isset($new_args['MYCLASSHREF'])) { $this->myclasshref = $new_args['MYCLASSHREF']; } if (isset($new_args['ALIGN'])) { $this->align = ' align="' . $new_args['ALIGN'] . '"'; } if (isset($new_args['MYCLASSIMG'])) { $this->myclassimg = ' class="' . $new_args['MYCLASSIMG'] . '"'; } if (isset($new_args['LB_EFFECT'])) { $this->LB_effect = $new_args['LB_EFFECT'] == 1; } if (isset($new_args['SHOWPOST'])) { $this->showpost = $new_args['SHOWPOST'] == 1; } if (isset($new_args['LINK'])) { $this->link = $new_args['LINK']; if ($this->link == 'p') { $this->showpost = true; } if ($this->link == 'u' && $this->default_link != '') { $this->showlink = true; } } }