예제 #1
0
 public function action_post($Pid)
 {
     $Pid and $this->data['posts'] = Model_Post::query()->where('Pid', '=', $Pid)->get();
     if (!$this->data) {
         Response::redirect('welcome/404');
     }
     return $this->data;
 }
예제 #2
0
 public function action_index()
 {
     $this->dataGlobal['pageTitle'] = __('backend.post.manage');
     // 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', 'backend/post/index')->set($this->data, null, false);
 }
예제 #3
0
 public function action_related_by_article_slug($slug = false)
 {
     $article = Model_Post::query()->where('slug', $slug)->get_one();
     $category = Model_Category::query()->where('id', $article->category_id)->get_one();
     if (!$category) {
         \Messages::error(__('frontend.category.not-found'));
         \Response::redirect_back(\Router::get('homepage'));
     } else {
         //            // Categorys where category parent is parent category id
         $categories = Model_Category::query()->where('parent_id', $category->parent_id)->or_where('id', $category->parent_id)->get();
         $this->data['related_categories'] = $categories;
         return \Response::forge(\View::forge('frontend/category/related/article/slug')->set($this->data, null, false));
     }
 }
예제 #4
0
파일: blog.php 프로젝트: blueshift9/pscms
 public function action_view($slug = null)
 {
     if (Auth::check()) {
         $data['user_link'] = 'logout';
         $email = Auth::get_screen_name();
         $data['email'] = $email;
     } else {
         $data['user_link'] = 'login';
     }
     $data["subnav"] = array('view' => 'active');
     $data['post'] = Model_Post::query()->where('slug', $slug)->get_one();
     //Debug::dump($data['post']);
     $this->template->title = 'Post';
     //$this->template->content = View::forge('blog/view', $data,false);
     return Response::forge(View::forge('blog/view.smarty', $data, false));
 }
예제 #5
0
 public function get_navSubCategories()
 {
     /*
      * Initially get sub categories by post slug and default to world category
      * On subsequent requests get sub categories by category slug
      */
     $slug = \Input::get('slug');
     $slugType = \Input::get('slugType');
     /* [ post | category ] */
     $category = false;
     if ($slugType === 'post') {
         $post = Model_Post::query()->where('slug', $slug)->get_one();
         if ($post) {
             $category = Model_Category::query()->where('id', $post->category_id)->get_one();
             $category = Model_Category::query()->where('id', $category->parent_id)->get_one();
             if (!$category) {
                 $category = Model_Category::query()->where('id', $post->category_id)->get_one();
             }
         } else {
             $cat_id = 1;
             $cat_name = 'world';
         }
     } elseif ($slugType == 'category') {
         $category = Model_Category::query()->where('slug', $slug)->get_one();
     }
     if (!$category) {
         $cat_id = 1;
         $cat_name = 'world';
     } else {
         $cat_id = $category->id;
         $cat_name = $category->name;
     }
     $subCategories = Model_Category::query()->where('parent_id', $cat_id)->get();
     $posts = array();
     $subSections = array();
     $gallery = array();
     $data = array();
     foreach ($subCategories as $key => $cat) {
         $subCategories[$key]['posts'] = Model_Post::query()->where('category_id', $cat->id)->related('galleries')->limit(3)->get();
         foreach ($subCategories[$key]['posts'] as $k => $post) {
             $gallery[$key][$k] = \Model_Gallery::query()->where('post_id', $post->id)->related('asset')->get_one();
         }
     }
     $subCategories['section'] = $cat_name;
     return $this->response = $subCategories;
 }
예제 #6
0
 public function action_index()
 {
     $data = array();
     $message = '';
     $username = Auth::get_screen_name();
     $class = Auth::get('classID');
     $data['posts'] = Model_Post::query()->where('username', '=', $username)->order_by('Ptime', 'desc')->get();
     $data['users'] = Model_Users::query()->where('username', '=', $username)->get();
     //同じクラスのユーザを取得
     $data['classname'] = Model_Class::query()->where('classID', '=', $class)->get();
     $data['classuser'] = Model_Users::query()->where('classID', '=', $class)->get();
     $data['categorize'] = Model_Category::query()->where('df', '=', '0')->get();
     $view = View::forge('mypage/mypage', $data);
     $view->username = $username;
     $view->set_global('message', $message, false);
     return $view;
 }
예제 #7
0
 public function action_archive($year)
 {
     $error = '';
     //ページネーションの設定
     $count = Model_Post::query()->where('Ptime', 'between', array($year . "-1-1", $year . "-12-31"))->count();
     $config = array('pagination_url' => 'noteshare/list/archive/' . $year . '/', 'uri_segment' => 4, 'num_links' => 5, 'per_page' => $this->per_page, 'total_items' => $count, 'show_first' => false, 'show_last' => false);
     //ビューに送るデータの取得
     $pagination = Pagination::forge('post_pagination', $config);
     $this->action_categorize();
     $this->data['posts'] = Model_Post::query()->where('Ptime', 'between', array($year . "-1-1", $year . "-12-31"))->order_by('Ptime', 'desc')->limit($this->per_page)->offset($pagination->offset)->get();
     //ビューの作成
     $view = View::forge('list/ArchiveList', $this->data);
     if ($count != 0) {
         $view->set_safe('pagination', $pagination);
         $view->year = $year;
     } else {
         $view->year = $year;
         $error = "現在選択されたアーカイブの投稿はありません。";
         $view->set('error', $error);
     }
     return $view;
 }
예제 #8
0
파일: log.php 프로젝트: nobuhiko/mylogbook
 public function action_create($id = null)
 {
     if ($this->current_user == null) {
         Response::redirect('welcome/404', 'location', 404);
     }
     if ($id) {
         $post = Model_Post::query()->select('date', 'location', 'point', 'point_type', 'diving_shop', 'air_temp', 'suit', 'suit_thickness', 'weight', 'tank', 'tank_cap', 'visibility')->where('serial_dive_no', $id - 1)->where('user_id', $this->current_user->id)->get_one();
         $post->serial_dive_no = $id;
         $fieldset = $this->_fieldset()->populate($post, true);
     } else {
         $fieldset = $this->_fieldset()->repopulate();
     }
     if (Input::method() == 'POST') {
         if ($fieldset->validation()->run()) {
             $fields = $fieldset->validated();
             $post = Model_Post::forge();
             foreach ($fields as $key => $value) {
                 $post->{$key} = $value;
             }
             $post->dive_time = Model_Post::calc_diff_of_time($post->exit, $post->entry);
             $post->user_id = $this->current_user->id;
             // todo トランザクション
             $post->creatures = Model_Creature::parseCreatures(Input::post('report'));
             if ($post->save()) {
                 Session::set_flash('success', e('Added log #' . $post->id . '.'));
                 Response::redirect('/log/edit/' . $post->id);
             } else {
                 Session::set_flash('error', e('Could not save post.'));
             }
         }
     }
     $this->template->set_global('fieldset', $fieldset, false);
     $this->template->title = ' | ログを書く';
     $this->template->set_global('title', 'ログを書く', false);
     $this->template->content = View::forge('log/create');
     $this->template->set_global('noindex', true);
 }
예제 #9
0
 /**
  * Show a post
  * @param  string $slug 
  */
 public function action_show($slug = false)
 {
     // Get post by slug
     $post = $this->data['post'] = \Model_Post::query()->where('slug', $slug)->get_one();
     if (!$post) {
         \Messages::error(__('frontend.post.not-found'));
         \Response::redirect_back(\Router::get('homepage'));
     } else {
         // Prepare comment form fieldset
         $form = \Fieldset::forge('post_comment');
         $form->add_model('Model_Comment');
         $form->add('submit', '', array('type' => 'submit', 'value' => __('submit'), 'class' => 'btn btn-primary'));
         // If submit comment
         if (\Input::post('submit')) {
             $form->validation()->run();
             if (!$form->validation()->error()) {
                 // Create and populate the comment object
                 $comment = \Model_Comment::forge();
                 $comment->from_array(array('username' => $form->validated('username'), 'mail' => $form->validated('mail'), 'content' => $form->validated('content'), 'post_id' => $post->id));
                 if ($comment->save()) {
                     \Messages::success(__('frontend.comment.added'));
                     \Response::redirect_back(\Router::get('show_post', array('segment' => $post->slug)));
                 } else {
                     \Messages::error(__('error'));
                 }
             } else {
                 // Output validation errors
                 foreach ($form->validation()->error() as $error) {
                     \Messages::error($error);
                 }
             }
         }
         $form->repopulate();
         $this->data['form'] = $form;
         $this->theme->set_partial('content', 'frontend/post/show')->set($this->data, null, false);
     }
 }
예제 #10
0
 /**
  * Get the sidebar view (HMVC Only)
  */
 public function get_sidebar()
 {
     if (\Request::is_hmvc()) {
         // Get sidebar in cache
         try {
             $sidebar = \Cache::get('sidebar');
         } catch (\CacheNotFoundException $e) {
             // If Cache doesn't exist, get data and cache the view
             $this->data['categories'] = Model_Category::find('all');
             $this->data['lastPosts'] = Model_Post::query()->order_by('created_at', 'DESC')->limit(5)->get();
             $sidebar = \View::forge('backend/post/sidebar', $this->data);
             \Cache::set('sidebar', $sidebar);
         }
         return $sidebar;
     }
 }
예제 #11
0
 public function action_Delete()
 {
     $check = Input::post('check');
     foreach ($check as $ck) {
         $query = Model_Post::query()->where('Pid', '=', $ck)->delete();
     }
     //セッションの取得
     $username = Session::get('user');
     $title = Session::get('Title');
     $Pcontent = Session::get('Pcontent');
     $category = Session::get('category');
     $Syear = Session::get('Syear');
     $Smonth = Session::get('Smonth');
     $Sday = Session::get('Sday');
     $Eyear = Session::get('Eyear');
     $Emonth = Session::get('Emonth');
     $Eday = Session::get('Eday');
     //値のセット
     $view = View::forge('search/SearchResults', $this->action_kensaku($username, $title, $Pcontent, $category, $Syear, $Smonth, $Sday, $Eyear, $Emonth, $Eday));
     return $view;
 }
예제 #12
0
 public function action_Adetail($Pid = 0)
 {
     //トークンの生成
     $this->data['token_key'] = Config::get('security.csrf_token_key');
     $this->data['token'] = Security::fetch_token();
     //投稿内容取得
     $this->data['posts'] = Model_Post::query()->where('Pid', '=', $Pid)->get();
     $is_record = count($this->data['posts']);
     //投稿IDが存在し、そのレコードが取得されているか
     if ($is_record) {
         $this->data['comments'] = Model_Comment::query()->where('Pid', '=', $Pid)->get();
         $this->action_categorize();
         $view = View::forge('post/PostsDetail_2', $this->data);
         $view->set_global('error', $this->error, false);
         return $view;
     } else {
         Response::redirect('_404_');
     }
 }
예제 #13
0
 public function action_category($Kid = 0)
 {
     //CSRF対策
     $this->data['token_key'] = Config::get('security.csrf_token_key');
     $this->data['token'] = Security::fetch_token();
     //カテゴリごとの投稿件数を取得
     $count = Model_Post::query()->where('Kid', '=', $Kid)->count();
     //ページネーションの設定(カテゴリごとの投稿表示仕様)
     $config = array('pagination_url' => 'noteshare/home/category/' . $Kid, 'uri_segment' => 4, '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()->where('Kid', '=', $Kid)->order_by('Ptime', 'desc')->limit($this->per_page)->offset($pagination->offset)->get();
     $this->action_categorize();
     //homeのビューオブジェクトを生成
     if (!$count) {
         $view = View::forge('home/home', $this->data);
         $view->set_safe('pagination', $pagination);
         //メッセージの定義
         $this->msg = '現在このカテゴリの投稿はありません。';
         $view->set_global('error', $this->error, FALSE);
         $view->set_global('csrmsg', $this->csrmsg, false);
         $view->set_global('msg', $this->msg, false);
     } else {
         $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);
     }
     return $view;
 }