Пример #1
0
 public function indexAction()
 {
     $posts = new Posts();
     $posts->getAll();
     $view = View::init();
     echo $view->render('pages/posts/all.twig', ['title' => 'Блог', 'posts' => $posts->getAll()]);
 }
Пример #2
0
 /**
  * @var $post  Posts;
  * @return Posts|null
  */
 public function createPost()
 {
     $post = new Posts();
     $post->user_id = Yii::$app->user->id;
     $post->full_text = preg_replace('#&lt;(/?(?:em|b|i|u|ul|li|ol|h2|blockquote))&gt;#', '<\\1>', Html::encode($this->post));
     $post->meta_keys = Html::encode($this->keys);
     $post->intro_text = preg_replace('#&lt;(/?(?:em|b|i|u|ul|li|ol|h2|h3|blockquote))&gt;#', '<\\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('#&lt;(/?(?:pre|b|em|u|ul|li|ol))&gt;#', '<\1>', $str); */
     return $post->save() ? $post : null;
 }
Пример #3
0
 /**
  * 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);
 }
Пример #4
0
 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');
 }
Пример #5
0
 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);
 }
Пример #6
0
 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);
 }
Пример #7
0
 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);
 }
Пример #9
0
 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);
 }
Пример #10
0
 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]);
 }
Пример #11
0
 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);
 }
Пример #12
0
 /**
  * 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;
 }
Пример #13
0
 public function validatePostUrl($attribute, $params)
 {
     $row = Posts::findOne(['url' => $this->url]);
     if ($row) {
         if ($row->id != $this->post_id) {
             $this->addError($attribute, 'Страница с таким URI уже существует.');
         }
     }
 }
Пример #14
0
 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');
 }
Пример #15
0
 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.');
     }
 }
Пример #16
0
 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"));
 }
Пример #17
0
 /**
  * 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;
 }
Пример #18
0
 /**
  * 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]);
 }
Пример #19
0
 public function allow_comments()
 {
     $post = Posts::findOne($this->post_id);
     if ($post) {
         if (!$post->allow_comments) {
             return false;
         }
     } else {
         return false;
     }
     return true;
 }
Пример #20
0
 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');
 }
Пример #21
0
 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++;
     }
 }
Пример #22
0
 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');
 }
Пример #23
0
 /**
  * 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;
 }
Пример #24
0
 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', '&laquo;' . $post->title . '&raquo;', ['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']);
 }
Пример #25
0
 /**
  * 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;
 }
Пример #26
0
 /**
  * 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;
 }
Пример #27
0
 /**
  * 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;
 }
Пример #28
0
 /**
  * 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;
 }
Пример #29
0
 /**
  * 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;
 }
Пример #30
0
 /**
  * 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;
 }