예제 #1
0
 public function action_show_more_news()
 {
     // Pagination
     $config = array('pagination_url' => \Uri::current(), 'total_items' => Model_Post::count(), 'per_page' => 3, 'uri_segment' => 'page');
     $pagination = \Pagination::forge('more_news_pagination', $config);
     // Get posts
     $this->data['posts'] = Model_Post::query()->offset($pagination->offset)->limit($pagination->per_page)->order_by('created_at', 'DESC')->get();
     return \Response::forge(\View::forge('frontend/post/show/more')->set($this->data, null, false));
 }
예제 #2
0
 /**
  * Get all posts
  */
 public function action_index()
 {
     // Pagination
     $config = array('pagination_url' => \Uri::current(), 'total_items' => \Model_Post::count(), 'per_page' => \Config::get('application.pagination.per_page'), 'uri_segment' => 'page');
     $this->data['pagination'] = $pagination = \Pagination::forge('post_pagination', $config);
     // Get posts
     $this->data['posts'] = \Model_Post::query()->offset($pagination->offset)->limit($pagination->per_page)->order_by('created_at', 'DESC')->get();
     $this->theme->set_partial('content', 'frontend/post/index')->set($this->data, null, false);
 }
예제 #3
0
파일: user.php 프로젝트: nobuhiko/mylogbook
 public function before()
 {
     parent::before();
     $data = array();
     $this->username = $this->param('username');
     $this->template = View::forge('template');
     // todo related
     $this->user = $data['user'] = Model_User::find_by_username($this->username);
     if (empty($data['user'])) {
         Response::redirect('welcome/404', 'location', 404);
     }
     $data['log'] = Model_Post::count(array('where' => array_merge(array(array('user_id', $this->user->id)), $this->status_where)));
     $this->log_count = $data['log'];
     Model_Post::summary_userdata($data, $this->user->id);
     $this->template->set_global('description', $this->user->profiles->description);
     $this->template->content = View::forge('user/profile', $data);
     // 共通tpl
     $this->template->title = ' | ' . $this->user->profiles->full_name . 'のログ';
 }
예제 #4
0
파일: blog.php 프로젝트: blueshift9/pscms
 public function action_index()
 {
     /*$data["subnav"] = array('index'=> 'active' );
     		$this->template->title = 'Blog » Index';*/
     $config = array('pagination_url' => '', 'total_items' => Model_Post::count(), 'per_page' => 5, 'uri_segment' => 'page');
     $pagination = Pagination::forge('mypagination', $config);
     $data['posts'] = Model_Post::query()->rows_offset($pagination->offset)->rows_limit($pagination->per_page)->order_by(array('created_at' => 'desc'))->get();
     // we pass the object, it will be rendered when echo'd in the view
     $data['pagination'] = $pagination;
     //$data['posts'] = Model_Post::find('all');
     if (Auth::check()) {
         $data['user_link'] = 'logout';
         $email = Auth::get_screen_name();
         $data['email'] = $email;
     } else {
         $data['user_link'] = 'login';
     }
     $this->template->title = "Posts";
     $data['title'] = 'Posts';
     return Response::forge(View::forge('blog/index.smarty', $data, false));
 }
예제 #5
0
 public function get_articles()
 {
     // Pagination
     $config = array('pagination_url' => \Uri::current(), 'total_items' => Model_Post::count(), 'per_page' => 3, 'uri_segment' => 'page');
     $this->data['pagination'] = $pagination = \Pagination::forge('post_pagination', $config);
     // Get posts
     return $this->response = Model_Post::query()->offset($pagination->offset)->limit($pagination->per_page)->order_by('created_at', 'DESC')->get();
 }
예제 #6
0
 public function action_save()
 {
     //ページネーションの設定
     $count = Model_Post::count();
     $config = array('pagination_url' => 'noteshare/home', 'uri_segment' => 2, 'num_links' => 3, 'per_page' => $this->per_page, 'total_items' => $count, 'show_first' => true, 'show_last' => true);
     //ページネーションオブジェクトの作成
     $pagination = Pagination::forge('post_pagination', $config);
     $this->data['rows'] = Model_Post::query()->order_by('Ptime', 'desc')->limit($this->per_page)->offset($pagination->offset)->get();
     //postでデータが送信されたか?
     if (Input::post()) {
         //CSRF対策用のトークンを生成
         $this->data['token_key'] = Config::get('security.csrf_token_key');
         $this->data['token'] = Security::fetch_token();
         //CSRF対策
         if (Security::check_token()) {
             //バリデーション定義の読み込み
             $val = Model_Post::validate();
             if ($val->run()) {
                 $form = array();
                 $form['username'] = Auth::get_screen_name();
                 $form['Kid'] = input::post('category');
                 $form['class'] = "【" . Input::post('cla') . "】";
                 $form['Title'] = Input::post('title');
                 $form['Pcontent'] = Input::post('Pcontent');
                 //アップロードファイルがバリデーション通りなら投稿内容保存
                 if (Upload::is_valid()) {
                     //設定を元に保存をする
                     Upload::save();
                     foreach (Upload::get_files() as $file) {
                         $form['image'] = $file['saved_as'];
                     }
                 }
                 //モデルの呼び出し
                 $post = Model_Post::forge();
                 $post->set($form);
                 $post->save();
                 //home/homeに遷移
                 Response::redirect('home');
                 //バリデーションエラー
             } else {
                 $this->error = $val->error();
                 $this->action_categorize();
                 $view = View::forge('home/home', $this->data);
                 $view->set_safe('pagination', $pagination);
                 $view->set_global('error', $this->error, false);
                 $view->set_global('csrmsg', $this->csrmsg, false);
                 $view->set_global('msg', $this->msg, false);
             }
             //CSRFエラー
         } else {
             $this->csrmsg = '不正なリクエストです。<br>もう一度home画面にアクセスし、投稿をやり直してください。';
             $this->action_categorize();
             $view = View::forge('home/home', $this->data);
             $view->set_safe('pagination', $pagination);
             $view->set_global('error', $this->error, false);
             $view->set_global('csrmsg', $this->csrmsg, false);
             $view->set_global('msg', $this->msg, false);
             Profiler::mark('CSRFです');
         }
         //postエラー
     } else {
     }
     return $view;
 }