public function indexAction() { $posts = new Posts(); $posts->getAll(); $view = View::init(); echo $view->render('pages/posts/all.twig', ['title' => 'Блог', 'posts' => $posts->getAll()]); }
/** * @var $post Posts; * @return Posts|null */ public function createPost() { $post = new Posts(); $post->user_id = Yii::$app->user->id; $post->full_text = preg_replace('#<(/?(?:em|b|i|u|ul|li|ol|h2|blockquote))>#', '<\\1>', Html::encode($this->post)); $post->meta_keys = Html::encode($this->keys); $post->intro_text = preg_replace('#<(/?(?:em|b|i|u|ul|li|ol|h2|h3|blockquote))>#', '<\\1>', Html::encode(substr($this->post, 0, 32) . ' ...')); $post->meta_desc = Html::encode($this->desc); $post->title = Html::encode($this->title_post); /* todo allow user some interaction * // $str is the result of htmlspecialchars() preg_replace('#<(/?(?:pre|b|em|u|ul|li|ol))>#', '<\1>', $str); */ return $post->save() ? $post : null; }
/** * Execute the job. * * @return void */ public function handle() { $posts = Posts::active()->get(); $fh = fopen(public_path(Conf::get('sitemap.filename', 'sitemap.xml', false)), 'w'); fwrite($fh, view('files.sitemap', compact('posts'))->render()); fclose($fh); }
public function addData() { $data = $this->request()->request->all(); $data['user_id'] = $this->request()->getSession()->get('uid'); $id = Posts::create($data); return new RedirectResponse('/admin/post'); }
public function tag($tag) { $data = ['posts' => Posts::i()->getPostsByTag($tag), 'title' => 'Тэг: ' . $tag]; View::share('seo_title', $data['title']); $this->title->prepend($data['title']); return view('site.posts.index', $data); }
public function compose(View $view) { $categories = \App\Models\Categories::i()->withPostsCount(); $posts_count = \App\Models\Posts::active()->count(); $view->with('categories', $categories); $view->with('posts_count', $posts_count); }
public function home() { $eureka = Eurekas::find('random'); $projects = Projects::find('all'); $posts = Posts::latest(); return compact('posts', 'eureka', 'projects'); }
/** * Display the 5 draft posts of a particular user * * @param Request $request * @return type */ public function user_posts_draft(Request $request) { $user = $request->user(); $posts = Posts::where('author_id', $user->id)->where('active', '0')->orderBy('created_at', 'desc')->paginate(5); $title = $user->name; return view('home')->withPosts($posts)->withTitle($title); }
public function tag($tag) { Title::prepend('Тэг: ' . $tag); $data = ['posts' => Posts::i()->getPostsByTag($tag), 'title' => Title::renderr(' : ', true), 'q' => '']; view()->share('seo_title', $data['title']); return view('site.posts.index', $data); }
public static function index() { $posts = Posts::all()->fetchAll(\PDO::FETCH_CLASS); $categories = Categories::all()->fetchAll(\PDO::FETCH_CLASS); $comments = Comments::all()->fetchAll(\PDO::FETCH_CLASS); View::render('admin/home', ['posts' => $posts, 'categories' => $categories, 'comments' => $comments]); }
public function index() { view()->share('menu_item_active', 'index'); Title::prepend('Dashboard'); $data = ['title' => Title::renderr(' : ', true), 'posts_total' => Posts::count(), 'posts_active' => Posts::where('status', 'active')->count(), 'posts_draft' => Posts::where('status', 'draft')->count(), 'posts_moderation' => Posts::where('status', 'moderation')->count(), 'users_total' => Users::count(), 'users_active' => Users::where('active', '1')->count(), 'users_inactive' => Users::where('active', '0')->count(), 'latest_posts' => Posts::active()->orderBy('published_at', 'desc')->limit(5)->get(), 'popular_posts' => Posts::active()->orderBy('views', 'desc')->limit(5)->get()]; return view('root.dashboard.index', $data); }
/** * Loads our model and throws an exception if we encounter an error * @param int $id The $id of the model we want to delete */ private function loadModel($id) { $model = Posts::find($id); if ($model == NULL) { throw new HttpException(404, 'Model not found.'); } return $model; }
public function validatePostUrl($attribute, $params) { $row = Posts::findOne(['url' => $this->url]); if ($row) { if ($row->id != $this->post_id) { $this->addError($attribute, 'Страница с таким URI уже существует.'); } } }
public function delete() { if (!$this->request->is('post') && !$this->request->is('delete')) { $msg = "Posts::delete can only be called with http:post or http:delete."; throw new DispatchException($msg); } Posts::find($this->request->id)->delete(); $this->redirect('Posts::index'); }
public function actionArticle($id) { $query = Posts::findOne(['id' => $id]); if ($query !== null) { return $this->render('article', ['article' => $query]); } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function slug($slug) { $post = \App\Models\Posts::where("post_slug", $slug)->first(); $autor = \App\Models\User::where("id", $post->post_autor)->first(); $categoria = \App\Models\Categorias::where("cat_id", $post->post_categoria_id)->get(); $posts = $this->pega_posts(); // Coloca no Thema $pagina = view('base.depoimento', compact('post', 'autor', 'categoria', 'posts')); return view('themes.layout', compact("pagina")); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['users']); return $dataProvider; } $query->andFilterWhere(['PostID' => $this->PostID, 'PostTypeID' => $this->PostTypeID, 'AttachmentTypeID' => $this->AttachmentTypeID, 'UserID' => $this->UserID, 'Likes' => $this->Likes, 'Pinned' => $this->Pinned, 'TimeStamp' => $this->TimeStamp]); $query->andFilterWhere(['like', 'PostTitle', $this->PostTitle])->andFilterWhere(['like', 'PostContent', $this->PostContent])->andFilterWhere(['like', 'Tags', $this->Tags])->andFilterWhere(['like', 'Attachment', $this->Attachment]); return $dataProvider; }
/** * Render the profile page * @param $username */ public static function profile($username) { # fetch account data by username $account = Accounts::findByUsername($username); # fecth all categories $categories = Categories::all(); # fetch all of this member's post $posts = Posts::find(['id_account' => $account['id']]); # fetch all accounts $users = Accounts::find(['type' => 2]); View::render('member/profile', ['account' => $account, 'posts' => $posts, 'users' => $users, 'categories' => $categories]); }
public function allow_comments() { $post = Posts::findOne($this->post_id); if ($post) { if (!$post->allow_comments) { return false; } } else { return false; } return true; }
public function add() { if (!Auth::check('default')) { return $this->redirect('Sessions::add'); } $success = false; if ($this->request->data) { $post = Posts::create($this->request->data); $success = $post->save(); } return compact('success'); }
public static function setNumbers($posts) { $all_releases = Posts::find()->where(['is_release' => 1])->orderBy("date")->all(); $number = 1; foreach ($all_releases as $release) { foreach ($posts as $post) { if ($post->id == $release->id) { $post->number = $number; } } $number++; } }
public function remove($category_id) { $category = Categories::find($category_id); $category->delete(); if (Input::get('with_posts', '0') == '1') { Posts::where('category_id', $category_id)->delete(); Notifications::add('Category removed with posts', 'success'); } else { Posts::where('category_id', $category_id)->update(['category_id' => '1']); Notifications::add('Category removed. Posts moved to Uncategorized', 'success'); } return Redirect::route('root-categories'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); $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, 'date' => $this->date, 'auther_id' => $this->auther_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function run() { $posts = Posts::find()->where(['hide' => 0])->limit(5)->where(['not', ['id' => $this->id]])->orderBy("rand()")->all(); $trs = ""; foreach ($posts as $post) { $img = Html::tag('img', null, ['src' => $post->img, 'alt' => $post->title]); $td_1 = Html::tag('td', $img); $a_span = Html::tag('a', '«' . $post->title . '»', ['href' => $post->link]); $a_span .= Html::tag('span', $post->date, ['class' => 'date']); $td_2 = Html::tag('td', $a_span); $trs .= Html::tag('tr', $td_1 . $td_2); } return Html::tag('table', $trs, ['id' => 'post_others']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::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_time' => $this->created_time, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::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, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'updated_at', $this->updated_at])->andFilterWhere(['like', 'full_text', $this->full_text])->andFilterWhere(['like', 'intro_text', $this->intro_text])->andFilterWhere(['like', 'meta_keys', $this->meta_keys])->andFilterWhere(['like', 'meta_desc', $this->meta_desc])->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::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' => $this->created, 'modfied' => $this->modfied]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::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(['post_id' => $this->post_id, 'author_id' => $this->author_id]); $query->andFilterWhere(['like', 'post_title', $this->post_title])->andFilterWhere(['like', 'post_description', $this->post_description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::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, 'date' => $this->date, 'published' => $this->published, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'short', $this->short])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::find()->where(['user_id' => Yii::$app->user->getId()]); $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->joinWith('status'); $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'end_date' => $this->end_date]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'status.name', $this->status_id]); return $dataProvider; }