public static function getNewsFromCronAuto() { $result = 0; $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'cron-import.json'; if (file_exists($file)) { $data = file_get_contents($file); $data = unserialize($data); if ($data) { foreach ($data as $row) { $duble = Blog::getDublicateByTitle(mb_convert_encoding($row['title'], 'UTF-8', 'Windows-1251')); if (!$duble) { $model = new Blog(); $model->title = mb_convert_encoding($row['title'], 'UTF-8', 'Windows-1251'); $model->image = $row['image'] ? $row['image'] : ''; $model->content = mb_convert_encoding($row['content'], 'UTF-8', 'Windows-1251'); $model->updated_at = time(); $model->author = (int) 1; $model->save(); $result = 1; } $result = 2; } } } return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $query->joinWith(['author']); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $dataProvider->sort->attributes['fullname'] = ['asc' => ['{{%core_account}}.fullname' => SORT_ASC], 'desc' => ['{{%core_account}}.fullname' => SORT_DESC]]; /* user's blog */ if (Core::checkMCA(null, 'blog', 'manage')) { $query->andFilterWhere(['{{%core_blog}}.created_by' => Yii::$app->user->id]); } /* list all public blog */ if (Core::checkMCA(null, 'blog', 'index')) { $query->andFilterWhere(['{{%core_blog}}.status' => Blog::STATUS_PUBLISHED]); } $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['{{%core_blog}}.id' => $this->id, '{{%core_blog}}.created_by' => $this->created_by, '{{%core_blog}}.views' => $this->views, '{{%core_blog}}.status' => $this->status]); $query->andFilterWhere(['like', '{{%core_blog}}.title', $this->title])->andFilterWhere(['like', '{{%core_account}}.fullname', $this->fullname])->andFilterWhere(['like', '{{%core_blog}}.desc', $this->desc])->andFilterWhere(['like', '{{%core_blog}}.content', $this->content])->andFilterWhere(['like', '{{%core_blog}}.tags', $this->tags]); $query->andFilterWhere(['DATE(FROM_UNIXTIME(`{{%core_blog}}.updated_at`))' => $this->updated_at]); return $dataProvider; }
/** * Deletes an existing Blog model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = Blog::findOne($id); if ($model) { $model->delete(); } return $this->redirect(['index']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]); $timestamp = null; if (isset($params['datetime'])) { $timestamp = strtotime($params['datetime']); } if (isset($params['category'])) { $query->joinWith("category")->andFilterWhere(['category.id' => $params['category'], "category.status" => Category::STATUS_ON]); } $query->andFilterWhere(['user_id' => $this->user_id, 'created_at' => $timestamp]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'topic', $this->topic])->andFilterWhere(['like', 'detail', $this->detail])->andFilterWhere(['like', 'tag', $this->tag]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'views' => $this->views, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'short_text', $this->short_text])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
public function actionEditBlog($id) { $categoriesId = Yii::$app->request->post("categorys"); $model = Blog::find()->where(['id' => $id, 'user_id' => Yii::$app->user->id])->one(); if (!empty($model)) { $model->load(Yii::$app->request->post(), ''); if ($model->save()) { if (!empty($model->categorys)) { CategoryVia::deleteAll(['blog_id' => $model->id]); $model->setCategories(); } return $model; } return $model->getErrors(); } return "Blog not found"; }
public function init() { parent::init(); // TODO: Change the autogenerated stub if ($this->type == 'mostViewed') { $this->title = Yii::t('app', 'Most Viewed'); $this->models = Blog::mostViewed(); } if ($this->type == 'latest') { $this->title = Yii::t('app', 'Latest Updates'); $this->models = Blog::latest(); } if ($this->type == 'random') { $this->title = Yii::t('app', 'Random Blog'); $this->models = Blog::random(); } }
public static function getFreshNews() { $quantity = 0; $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json'; if (file_exists($file)) { $ImportModel = file_get_contents(Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json'); $obj = json_decode($ImportModel); $quantity = 0; if ($ImportModel) { foreach ($obj as $row) { $duble = Blog::getDublicateByTitle($row->title); if (!$duble) { $quantity++; } } } } return $quantity; }
</div> <?php echo $form->field($model, 'tags')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'thumbnail')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'thumbnail_square')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'status')->dropDownList(Blog::getStatusOption()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Submit') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * get image object info for SEO * @return array */ public function getImageObject() { $key = 'cache_blog_image_object_' . $this->id; $img = Yii::$app->cache->get($key); if ($img === false) { $flag = false; $doc = new DOMDocument(); $doc->loadHTML($this->content); $tags = $doc->getElementsByTagName('img'); $img = ['url' => '', 'width' => '', 'height' => '']; foreach ($tags as $i => $tag) { $img['url'] = $tag->getAttribute('src'); $img['width'] = $tag->getAttribute('width'); $img['height'] = $tag->getAttribute('height'); $flag = true; break; } if ($flag) { /* cache */ $sql = (new Query())->select('updated_at')->from(Blog::tableName())->where(['id' => $this->id])->createCommand()->rawSql; $dependency = new DbDependency(); $dependency->sql = $sql; Yii::$app->cache->set($key, $img, 0, $dependency); } else { Yii::$app->session->setFlash('warning', Yii::t('app', 'Missing image in blog post.')); } } return $img; }
public function actionAddNewsFromParser() { Yii::$app->response->format = Response::FORMAT_JSON; $result = Blog::getNewsFromCronAuto(); //vd($result); return $result; }
/** * Finds the Blog model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Blog the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Blog::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
$form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'short_text')->widget(Imperavi::className(), ['settings' => ['minHeight' => 300, 'imageGetJson' => Url::to(['/blogs/default/imperavi-get']), 'imageUpload' => Url::to(['/blogs/default/imperavi-image-upload']), 'fileUpload' => Url::to(['/blogs/default/imperavi-file-upload'])]]); ?> <?php echo $form->field($model, 'text')->widget(Imperavi::className(), ['settings' => ['minHeight' => 300, 'imageGetJson' => Url::to(['/blogs/default/imperavi-get']), 'imageUpload' => Url::to(['/blogs/default/imperavi-image-upload']), 'fileUpload' => Url::to(['/blogs/default/imperavi-file-upload'])]]); ?> <?php echo $form->field($model, 'status')->dropDownList(Blog::statusNames()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
<div class="box-body"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php Pjax::begin(); ?> <div class="table-responsive sort-ordinal"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'title', 'desc', 'views', ['attribute' => 'updated_at', 'value' => 'updated_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'updated_at', 'dateFormat' => 'yyyy-MM-dd', 'options' => ['class' => 'form-control']])], ['attribute' => 'status', 'value' => function ($model) { return $model->statusText; }, 'filter' => Blog::getStatusOption()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'buttons' => ['view' => function ($url, $model) { $view = Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $model->viewUrl, ['title' => Yii::t('yii', 'View'), 'data-pjax' => 0]); unset($url); return $model->status == Blog::STATUS_PUBLISHED ? $view : ''; }]]]]); ?> </div> <?php Pjax::end(); ?> </div> <!-- Loading (remove the following to stop the loading)--> <div class="overlay grid-view-overlay hidden"> <?php
public function actionBlogDetail($id) { $data = $this->getCommonDate(); $modelGoodsCategories = GoodsCategory::find()->all(); $modelBanner = Banner::find()->where(['status' => 0])->all(); $modelBrends = Brend::find()->all(); $modelBlog = Blog::findOne($id); $modelBlogComents = BlogComments::getComentsByBlogId($id); return $this->render('blog-detail', ['modelBlog' => $modelBlog, 'data' => $data, 'modelGoodsCategories' => $modelGoodsCategories, 'modelBrends' => $modelBrends, 'modelBanner' => $modelBanner, 'modelBlogComents' => $modelBlogComents]); }
public function actionAddNewsFromParser() { $result = 0; $file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json'; if (file_exists($file)) { $ImportModel = file_get_contents($file); $obj = json_decode($ImportModel); //vd($obj); if ($ImportModel) { foreach ($obj as $row) { $duble = Blog::getDublicateByTitle($row->title); if (!$duble) { $model = new Article(); $model->title = $row->title; $model->image = $row->image ? $row->image : ''; $model->content = $row->content; $model->created_at = $row->created_at; $model->updated_at = $row->updated_at; $model->author = $row->author; $model->save(); $result = 1; } else { //echo "It is Dublicate", PHP_EOL; } } } } return $result; }
public function getauthor() { // Customer has_many Order via Order.customer_id -> id return $this->hasMany(Blog::className(), ['author' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getBlog() { return $this->hasOne(Blog::className(), ['id' => 'blog_id']); }
/** * sitemap * @return mixed */ public function actionSitemap() { /* header response */ Yii::$app->response->format = Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'application/xml'); /* begin */ $sitemaps = []; /* blog sitemap */ $query = Blog::find()->where(['status' => Blog::STATUS_PUBLISHED]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(Yii::$app->params['sitemapPageSize']); $pages = $pagination->getPageCount(); if ($pages > 0) { for ($i = 0; $i < $pages; $i++) { $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/blog/sitemap', 'page' => $i + 1]); } } /* page sitemap */ $query = PageData::find()->where(['status' => PageData::STATUS_ACTIVE]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(Yii::$app->params['sitemapPageSize']); $pages = $pagination->getPageCount(); if ($pages > 0) { for ($i = 0; $i < $pages; $i++) { $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/page/sitemap', 'page' => $i + 1]); } } /* load modules sitemap */ $modules = scandir(\Yii::$app->vendorPath . '/modernkernel'); foreach ($modules as $module) { if (!preg_match('/[\\.]+/', $module)) { $moduleName = str_ireplace('yii2-', '', $module); if (method_exists(Yii::$app->getModule($moduleName), 'sitemap')) { $sitemaps = array_merge($sitemaps, Yii::$app->getModule($moduleName)->sitemap()); } } } return $this->renderPartial('sitemap', ['sitemaps' => $sitemaps]); }
/** * find blog by $slug * @param string $slug * @return array|Blog|null * @throws NotFoundHttpException */ protected function findBySlug($slug) { if (($model = Blog::find()->where(['slug' => $slug, 'status' => Blog::STATUS_PUBLISHED])->one()) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } }
public function actionViews($id) { $this->layout = '/blog'; $id = Yii::$app->request->get('id'); $blog = Blog::find()->where(['id' => $id])->one(); $viwsQuantity = (int) $blog->view; $blog->view = $viwsQuantity + 1; $blog->updateAttributes(['view']); $coment_model = Comment::find()->where(['blog_id' => $id])->all(); return $this->render('views', ['model' => $blog, 'coment_model' => $coment_model]); }