Ejemplo n.º 1
0
 public function action_create()
 {
     //$data['categories'] = Model_Category::find('all');
     //$view = View::forge('admin/posts/create');
     $cats = DB::query('SELECT id,name FROM categories')->execute()->as_array();
     $data['post'] = array();
     $data['post']['categories'] = $cats;
     if (Input::method() == 'POST') {
         $val = Model_Post::validate('create');
         if ($val->run()) {
             $post = Model_Post::forge(array('slug' => Input::post('slug'), 'title' => Input::post('title'), 'body' => Input::post('body'), 'user_id' => Input::post('user_id'), 'active' => Input::post('active')));
             $categories = array();
             $categories = Input::post('category_id');
             //exit(var_dump($categories));
             foreach ($categories as $category_id) {
                 $post->categories[] = Model_Category::find($category_id);
             }
             if ($post and $post->save()) {
                 Session::set_flash('success', e('Added post #' . $post->id . '.'));
                 Response::redirect('admin/posts');
             } else {
                 Session::set_flash('error', e('Could not save post.'));
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Posts";
     $this->template->content = View::forge('admin/posts/create', $data);
 }
Ejemplo n.º 2
0
 public function action_create()
 {
     $fieldset = Fieldset::forge()->add_model('Model_Post');
     $form = $fieldset->form();
     $form->add('submit', '', array('type' => 'submit', 'value' => 'Add New Post', 'class' => 'btn btn-large'));
     if (Input::method() == 'POST') {
         if ($fieldset->validation()->run() == true) {
             $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->creatures = Model_Creature::parseCreatures(Input::post('report'));
             if ($post->save()) {
                 Session::set_flash('success', e('Added post #' . $post->id . '.'));
                 Response::redirect('admin/posts');
             } else {
                 Session::set_flash('error', e('Could not save post.'));
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->set_global('form', $form->build(), false);
     $this->template->title = "Posts";
     $this->template->content = View::forge('admin/posts/create');
 }
Ejemplo n.º 3
0
 public function action_add($id = null)
 {
     $this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
     // Prepare form fieldset
     $form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal btn btn-primary')));
     $form->add_model('Blog\\Model_Post');
     $form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
     // Get or create the post
     if ($isUpdate) {
         $this->data['post'] = $post = Model_Post::find($id);
         $this->dataGlobal['pageTitle'] = __('backend.post.edit');
     } else {
         $this->data['post'] = $post = Model_Post::forge();
         $this->dataGlobal['pageTitle'] = __('backend.post.add');
     }
     $form->populate($post);
     // If POST submit
     if (\Input::post('add')) {
         $form->validation()->run();
         if (!$form->validation()->error()) {
             // Populate the post
             $post->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug'), '-', true) : \Inflector::friendly_title($form->validated('name'), '-', true), 'category_id' => $form->validated('category_id'), 'user_id' => $form->validated('user_id'), 'content' => $form->validated('content'), 'original_url' => $form->validated('original_url')));
             if ($post->save()) {
                 // Delete cache
                 \Cache::delete('sidebar');
                 // Category Post count update
                 foreach (Model_Category::find('all') as $category) {
                     $category->post_count = count($category->posts);
                     $category->save();
                 }
                 if ($isUpdate) {
                     //						\Messages::success(__('backend.post.edited'));
                     \Session::set_flash('success', __('backend.post.edited'));
                 } else {
                     //						\Messages::success(__('backend.post.added'));
                     \Session::set_flash('success', __('backend.post.added'));
                 }
                 \Response::redirect(\Router::get('admin'));
             } else {
                 \Messages::error(__('error'));
                 \Session::set_flash('error', __('error'));
             }
         } else {
             // Output validation errors
             foreach ($form->validation()->error() as $error) {
                 \Messages::error($error);
                 \Session::set_flash('error', __('error'));
             }
         }
     }
     $form->repopulate();
     $this->data['form'] = $form;
     return \Response::forge(\View::forge('backend/post/add')->set($this->data, null, false));
 }
    public function up()
    {
        \DBUtil::create_table('blog_post', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true), 'name' => array('constraint' => 255, 'type' => 'varchar'), 'slug' => array('constraint' => 255, 'type' => 'varchar'), 'content' => array('type' => 'text'), 'category_id' => array('constraint' => 11, 'type' => 'int'), 'user_id' => array('constraint' => 11, 'type' => 'int'), 'created_at' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'));
        \Model_Post::forge(array('name' => 'The route of All Evil', 'slug' => 'the-route-of-all-evil', 'content' => "Five hours? Aw, man! Couldn't you just get me the death penalty? Daylight and everything. What's with you kids? Every other day it's food, food, food. Alright, I'll get you some stupid food.\n\n## Bendin' in the Wind\n\n![1][4]\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit. Suscipit, modi, libero, earum, fugiat beatae ipsa quae accusamus eligendi minima eos sint consequuntur voluptate nihil inventore voluptatum? Possimus neque similique quam.\n\nNemo, aliquam non nulla corporis veritatis molestiae omnis nobis dolores dicta dolorum accusamus porro ipsum rem tempora maxime quisquam accusantium facilis saepe consequatur qui doloribus iusto distinctio perspiciatis modi voluptatum?\n\nIllum temporibus natus cumque recusandae non fugiat quisquam fuga repellendus. Quas, esse, a rem possimus vero sequi fugit non dolor corrupti in similique repudiandae excepturi quidem perspiciatis soluta amet qui?\n\n  * Fetal stemcells, aren't those controversial?\n  * Yes! In your face, Gandhi!\n  * The key to victory is discipline, and that means a well made bed. You will practice until you can make your bed in your sleep.\n\n### Why Must I Be a Crustacean in Love?\n\n![2][5]\n\nWe're rescuing ya. I'm Santa Claus! Have you ever tried just turning off the TV, sitting down with your children, and hitting them? Calculon is gonna kill us and it's all everybody else's fault! I just want to talk. It has nothing to do with mating. Fry, that doesn't make sense. Ummm…to eBay?\n\n#### Attack of the Killer App\n\nWhy would I want to know that? It's toe-tappingly tragic! You won't have time for sleeping, soldier, not with all the bed making you'll be doing. I've got to find a way to escape the horrible ravages of youth. Suddenly, I'm going to the bathroom like clockwork, every three hours. And those jerks at Social Security stopped sending me checks. Now 'I'' have to pay ''them'! I was all of history's great robot actors - Acting Unit 0.8; Thespomat; David Duchovny! Five hours? Aw, man! Couldn't you just get me the death penalty?\n\n  1. But, like most politicians, he promised more than he could deliver.\n  2. Calculon is gonna kill us and it's all everybody else's fault!\n  3. Bender?! You stole the atom.\n\n##### A Tale of Two Santas\n\nKif might! I wish! It's a nickel. OK, this has gotta stop. I'm going to remind Fry of his humanity the way only a woman can. Kif, I have mated with a woman. Inform the men. Look, everyone wants to be like Germany, but do we really have the pure strength of 'will'?\n\n\n   [4]: http://lorempicsum.com/futurama/200/150/1\n   [5]: http://lorempicsum.com/futurama/200/150/2\n   [6]: http://lorempicsum.com/futurama/100/100/4\n   [7]: http://lorempicsum.com/futurama/100/100/5\n\n  ", 'category_id' => 1, 'user_id' => 1))->save();
        \Model_Post::forge(array('name' => 'Post 1', 'slug' => 'post-1', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ligula augue, congue eu diam ut, interdum bibendum mi. Etiam fringilla, diam id vestibulum lobortis, libero ipsum laoreet massa, varius egestas lorem nunc hendrerit nulla. Donec tincidunt nisi odio, vel facilisis justo adipiscing sed. Nulla imperdiet ligula ac ligula fringilla tempor. Pellentesque posuere nulla hendrerit arcu tempor feugiat. Pellentesque magna massa, rutrum eu quam sed, imperdiet ultrices sapien. Nulla at neque ut erat porta feugiat. Nunc rhoncus pretium nisi, bibendum accumsan diam auctor vel. Mauris egestas porta felis, non tempus nibh feugiat fermentum. Aenean luctus sit amet nisi vel volutpat. In rhoncus vulputate fringilla. Nullam id lectus lacus.

Donec posuere, nisl in consectetur convallis, tellus massa sagittis metus, vel tincidunt diam arcu rhoncus metus. Nam at turpis ac urna volutpat vulputate nec nec velit. Maecenas nec venenatis velit, ac eleifend risus. Quisque eu mi nec ante mollis vehicula. Aliquam a eros vel turpis rhoncus elementum ac eu mi. Nunc congue tempus velit sit amet ultrices. Praesent at lacinia purus. Nullam eu dui commodo, facilisis nisi vel, hendrerit lacus. In nec sapien in dolor ullamcorper pharetra. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In magna libero, mattis at accumsan id, fermentum vel dolor. Mauris fermentum egestas bibendum. Integer feugiat at quam quis congue. Duis iaculis purus sit amet felis pulvinar, id ultricies ante scelerisque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'category_id' => 1, 'user_id' => 1))->save();
        \Model_Post::forge(array('name' => 'Post 2', 'slug' => 'post-2', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ligula augue, congue eu diam ut, interdum bibendum mi. Etiam fringilla, diam id vestibulum lobortis, libero ipsum laoreet massa, varius egestas lorem nunc hendrerit nulla. Donec tincidunt nisi odio, vel facilisis justo adipiscing sed. Nulla imperdiet ligula ac ligula fringilla tempor. Pellentesque posuere nulla hendrerit arcu tempor feugiat. Pellentesque magna massa, rutrum eu quam sed, imperdiet ultrices sapien. Nulla at neque ut erat porta feugiat. Nunc rhoncus pretium nisi, bibendum accumsan diam auctor vel. Mauris egestas porta felis, non tempus nibh feugiat fermentum. Aenean luctus sit amet nisi vel volutpat. In rhoncus vulputate fringilla. Nullam id lectus lacus.

Donec posuere, nisl in consectetur convallis, tellus massa sagittis metus, vel tincidunt diam arcu rhoncus metus. Nam at turpis ac urna volutpat vulputate nec nec velit. Maecenas nec venenatis velit, ac eleifend risus. Quisque eu mi nec ante mollis vehicula. Aliquam a eros vel turpis rhoncus elementum ac eu mi. Nunc congue tempus velit sit amet ultrices. Praesent at lacinia purus. Nullam eu dui commodo, facilisis nisi vel, hendrerit lacus. In nec sapien in dolor ullamcorper pharetra. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In magna libero, mattis at accumsan id, fermentum vel dolor. Mauris fermentum egestas bibendum. Integer feugiat at quam quis congue. Duis iaculis purus sit amet felis pulvinar, id ultricies ante scelerisque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'category_id' => 1, 'user_id' => 1))->save();
        \Model_Post::forge(array('name' => 'Post 3', 'slug' => 'post-3', 'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse ligula augue, congue eu diam ut, interdum bibendum mi. Etiam fringilla, diam id vestibulum lobortis, libero ipsum laoreet massa, varius egestas lorem nunc hendrerit nulla. Donec tincidunt nisi odio, vel facilisis justo adipiscing sed. Nulla imperdiet ligula ac ligula fringilla tempor. Pellentesque posuere nulla hendrerit arcu tempor feugiat. Pellentesque magna massa, rutrum eu quam sed, imperdiet ultrices sapien. Nulla at neque ut erat porta feugiat. Nunc rhoncus pretium nisi, bibendum accumsan diam auctor vel. Mauris egestas porta felis, non tempus nibh feugiat fermentum. Aenean luctus sit amet nisi vel volutpat. In rhoncus vulputate fringilla. Nullam id lectus lacus.

Donec posuere, nisl in consectetur convallis, tellus massa sagittis metus, vel tincidunt diam arcu rhoncus metus. Nam at turpis ac urna volutpat vulputate nec nec velit. Maecenas nec venenatis velit, ac eleifend risus. Quisque eu mi nec ante mollis vehicula. Aliquam a eros vel turpis rhoncus elementum ac eu mi. Nunc congue tempus velit sit amet ultrices. Praesent at lacinia purus. Nullam eu dui commodo, facilisis nisi vel, hendrerit lacus. In nec sapien in dolor ullamcorper pharetra. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In magna libero, mattis at accumsan id, fermentum vel dolor. Mauris fermentum egestas bibendum. Integer feugiat at quam quis congue. Duis iaculis purus sit amet felis pulvinar, id ultricies ante scelerisque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'category_id' => 2, 'user_id' => 1))->save();
    }
Ejemplo n.º 5
0
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Post::validate('create');
         if ($val->run()) {
             $post = Model_Post::forge(array('title' => Input::post('title'), 'body' => Input::post('body')));
             if ($post and $post->save()) {
                 Session::set_flash('success', e('Added post #' . $post->id . '.'));
                 Response::redirect('admin/post');
             } else {
                 Session::set_flash('error', e('Could not save post.'));
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $this->template->title = "Posts";
     $this->template->content = View::forge('admin/post/create');
 }
Ejemplo n.º 6
0
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Post::validate('create');
         if ($val->run()) {
             $post = Model_Post::forge(array('name' => Input::post('name'), 'title' => Input::post('title'), 'body' => Input::post('body'), 'delete_password' => Input::post('delete_password')));
             if ($post and $post->save()) {
                 Session::set_flash('success', '投稿が完了しました。');
                 Response::redirect('post');
             } else {
                 Session::set_flash('error', '投稿の保存に失敗しました。');
             }
         } else {
             Session::set_flash('error', $val->error());
         }
     }
     $data['posts'] = Model_Post::find('all', array('order_by' => array('id' => 'desc')));
     $data['title'] = 'SAMPLE BBS';
     $this->template->set_global($data);
     $this->template->content = View::forge('post/create');
 }
Ejemplo n.º 7
0
 public function action_create($id = null)
 {
     if (Input::method() == 'POST') {
         $val = Model_Post::validate('create');
         if ($val->run()) {
             $post = Model_Post::forge(array('title' => Input::post('title'), 'slug' => Inflector::friendly_title(Input::post('title'), '-', true), 'summary' => Input::post('summary'), 'body' => Input::post('body'), 'user_id' => Input::post('user_id')));
             if ($post and $post->save()) {
                 Session::set_flash('success', 'Added post #' . $post->id . '.');
                 Response::redirect('admin/posts');
             } else {
                 Session::set_flash('error', 'Could not save post.');
             }
         } else {
             Session::set_flash('error', $val->show_errors());
         }
     }
     $this->template->title = "Create Post";
     $view = View::forge('admin/posts/create');
     // Set some data
     $view->set_global('users', Arr::assoc_to_keyval(Model_User::find('all'), 'id', 'username'));
     $this->template->content = $view;
 }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
 public function action_index()
 {
     //Model_Postオブジェクトを新規作成
     $post = Model_Post::forge();
     $post->user_id = 1;
     //県のセレクト用のオプション配列の作成
     $prefectures = Model_Prefecture::find('all');
     $pref_op = array();
     foreach ($prefectures as $pref) {
         $pref_op[$pref->id] = $pref->name;
     }
     //カテゴリのチェックボックス用のオプション配列の作成
     $categories = array('何かを学ぶ旅' => '何かを学ぶ旅', '温泉でゆったりする旅' => '温泉でゆったりする旅', 'テーマパーク・アミューズメントの旅' => 'テーマパーク・アミューズメントの旅', '大自然にふれる旅' => '大自然にふれる旅', '街並みを楽しむ旅' => '街並みを楽しむ旅', 'グルメな旅' => 'グルメな旅', '平和について考える旅' => '平和について考える旅');
     //タグのチェックボックス用のオプション配列の作成
     $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'));
     //Fieldsetオブジェクトにモデルを登録
     $fieldset = Fieldset::forge('fset', $config)->add_model('Model_Post');
     //県名選択を登録
     $fieldset->add_before('prefid', '県名', array('type' => 'select', 'options' => $pref_op), array('required', 'in_array' => $pref_op), 'place');
     //カテゴリ選択を登録
     $fieldset->add_before('category2', 'カテゴリ', array('type' => 'select', 'options' => $categories), array('required', 'in_array' => $categories), 'tag1');
     //ファイルアップロードを登録
     $fieldset->add_after('imagefile', '写真', array('type' => 'file'), array('required'), 'rating');
     //$fieldset->field('imagefile')->set_attribute('form_attributes',array('enctype'=>'multipart/form-data'));
     //投稿ボタンを登録
     $fieldset->add_after('submit', '', array('type' => 'submit', 'value' => '投稿'), array(), 'rating');
     //モデルの値をFieldsetに登録
     $fieldset->populate($post, true);
     //$form = $fieldset->form();
     //$form['imagefile']->set_config('form_attributes', array('enctype'=>'multipart/form-data'));
     //POSTの場合は登録処理を行う
     if (Input::method() == 'POST') {
         //Validationの実行
         if ($fieldset->validation()->run()) {
             if (Input::post('imagefile')) {
                 Upload::process($config);
                 if (Upload::is_valid()) {
                     Upload::save();
                     $getfile = Upload::get_files();
                     $file = $getfile[0]['name'];
                 } else {
                     //ファイルがアップロードできなかったとき、メッセージをフラッシュセッションにセット
                     Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。');
                     //投稿を中断して入力画面へリダイレクト
                     Response::redirect('members/postfieldset');
                 }
             }
             var_dump($file);
             exit;
             //Validationに成功したフィールドの読み込み
             $fields = $fieldset->validated();
             //Model_Postオブジェクトの生成
             $post = Model_Post::forge();
             //Model_Postオブジェクトのプロパティの設定
             $post->user_id = $fields['user_id'];
             $post->pref_id = $fields['prefid'];
             $post->place = $fields['place'];
             $post->title = $fields['title'];
             $post->content = $fields['content'];
             $post->category = $fields['category2'];
             $post->tag1 = $fields['tag1'];
             $post->tag2 = $fields['tag2'];
             $post->rating = $fields['rating'];
             $post->image = $file;
             if ($post->save()) {
                 Response::redirect('members/top');
             } else {
                 //入力エラーがある場合は元の入力画面にもどるため
                 //入力した内容をそのまま引き継ぐ
                 $fieldset->repopulate();
             }
         }
     }
     //ビューの生成とbuild()したHTMLの埋め込み
     /* 本当は、members/postlist に飛びたい */
     $view = View::forge('members/postfieldset');
     $view->set('form', $fieldset->build(), false);
     return Response::forge($view);
 }
Ejemplo n.º 10
0
 public function action_index()
 {
     //ビューに渡すデータの配列を初期化
     $data = array();
     //県のセレクト用のオプション配列の作成
     $prefectures = Model_Prefecture::find('all');
     $pref_op = array();
     foreach ($prefectures as $pref) {
         $pref_op[$pref->id] = $pref->name;
     }
     $data['prefs'] = $pref_op;
     //カテゴリのチェックボックス用のオプション配列の作成
     $catego_op = array('何かを学ぶ旅' => '何かを学ぶ旅', '温泉でゆったりする旅' => '温泉でゆったりする旅', 'テーマパーク・アミューズメントの旅' => 'テーマパーク・アミューズメントの旅', '大自然にふれる旅' => '大自然にふれる旅', '街並みを楽しむ旅' => '街並みを楽しむ旅', 'グルメな旅' => 'グルメな旅', '平和について考える旅' => '平和について考える旅');
     $data['categories'] = $catego_op;
     //入力チェックのためのvalidationオブジェクトを呼び出す
     $val = Validation::forge();
     //
     $val->add('pref', '県名')->add_rule('required');
     $val->add('place', '場所')->add_rule('required');
     $val->add('title', 'タイトル')->add_rule('required');
     $val->add('content', '記事内容')->add_rule('required');
     $val->add('category', 'カテゴリ')->add_rule('required');
     $val->add('tag1', 'タグ1')->add_rule('required');
     $val->add('tag2', 'タグ2')->add_rule('required');
     $val->add('rating', '評価')->add_rule('required');
     //validationチェック
     if ($val->run()) {
         /*-----------
           画像ファイルの入力があったらアップロード
           ---------------*/
         //データ保存用変数 初期化
         $upload_file = '';
         if (Input::file('upload.name')) {
             //アップロード用初期設定
             $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'));
             //アップロード基本プロセス
             Upload::process($config);
             //検証
             if (Upload::is_valid()) {
                 //設定を元に保存
                 Upload::save();
                 //保存されたファイル名を変数に入れる
                 $getfile = Upload::get_files();
                 $upload_file = $getfile[0]['name'];
             } else {
                 //ファイルがアップロードできなかったとき、メッセージをフラッシュセッションにセット
                 Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。');
                 //投稿を中断して入力画面へリダイレクト
                 Response::redirect('members/post2');
             }
         }
         /*------
           postされた各データをDBに保存
           ----------*/
         if ($upload_file == '') {
             Session::set_flash('uerr', 'ファイルを選択してください。');
             //投稿を中断して入力画面へリダイレクト
             Response::redirect('members/post2');
         }
         //各送信データを配列
         $props = array('user_id' => 1, 'pref_id' => Input::post('pref'), 'place' => Input::post('place'), 'title' => Input::post('title'), 'content' => Input::post('content'), 'category' => Input::post('category'), 'tag1' => Input::post('tag1'), 'tag2' => Input::post('tag2'), 'rating' => Input::post('rating'), 'image' => $upload_file);
         //モデルオブジェクト作成
         $new = Model_Post::forge($props);
         //データを保存する
         if (!$new->save()) {
             //保存失敗
             $data['save'] = '正しく投稿できませんでした。';
         } else {
             //保存成功
             $data['save'] = '投稿されました。';
         }
     }
     //$val->run()ここまで
     //validationオブジェクトをviewに渡す
     $data['val'] = $val;
     /*---------------
        投稿済みのデータをDBから取得
       -------------*/
     /*$data['posts'] = 
       Model_Post::find('all', array(
           'order_by' => array(
               'created_at' => 'desc'
               )));*/
     return View::forge('members/post2', $data);
 }
Ejemplo n.º 11
0
 public function action_index()
 {
     //ビューに渡すデータの配列を初期化
     $data = array();
     //県のセレクト用のオプション配列の作成
     $prefectures = Model_Prefecture::find('all');
     $pref_op = array();
     foreach ($prefectures as $pref) {
         $pref_op[$pref->pref_num] = $pref->pref_name;
     }
     $data['prefs'] = $pref_op;
     //カテゴリのチェックボックス用のオプション配列の作成
     $categories = Model_Category::find('all');
     $catego_op = array();
     foreach ($categories as $catego) {
         $catego_op[$catego->cate_num] = $catego->cate_name;
     }
     $data['categories'] = $catego_op;
     //タグのセレクト用のオプション配列の作成
     $tags = Model_Tag::find('all');
     $tag_op = array();
     foreach ($tags as $tag) {
         $tag_op[$tag->tag_num] = $tag->tag_name;
     }
     $data['tags'] = $tag_op;
     if (Input::method() == 'POST') {
         /*-------
           ユーザが入力した値とその時の時刻を保持
           --------*/
         $data['input_pref'] = Input::post('pref');
         $data['input_place'] = Input::post('place');
         $data['input_title'] = Input::post('title');
         $data['input_content'] = Input::post('content');
         $data['input_category'] = Input::post('category');
         $data['input_tag1'] = Input::post('tag1');
         $data['input_tag2'] = Input::post('tag2');
         $data['input_rating'] = Input::post('rating');
         $time = Date::forge()->get_timestamp();
     }
     /*--------
        Validationの準備
       ---------*/
     //Validationオブジェクトを呼び出す
     $val = Validation::forge();
     //フォームのルール設定
     $val->add('pref', '県名')->add_rule('required');
     $val->add('place', '場所')->add_rule('required');
     $val->add('title', 'タイトル')->add_rule('required');
     //->add_rule('max_length', 30)
     $val->add('content', '記事内容')->add_rule('required');
     //->add_rule('max_length', 200)
     $val->add('category', 'カテゴリ')->add_rule('required');
     $val->add('tag1', 'タグ1')->add_rule('required');
     $val->add('tag2', 'タグ2')->add_rule('required');
     $val->add('rating', '評価')->add_rule('required');
     /*-----------
       画像ファイルの入力があったらアップロード
       ---------------*/
     //データ保存用変数 初期化
     $upload_file = '';
     if (Input::file('upload.name')) {
         //アップロード用初期設定
         $config = array('path' => DOCROOT . DS . '/assets/img/uimg', 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'));
         //アップロード基本プロセス
         Upload::process($config);
         //検証
         if (Upload::is_valid()) {
             //設定を元に保存
             Upload::save();
             //保存されたファイル名を変数に入れる
             $getfile = Upload::get_files();
             $upload_file = $getfile[0]['name'];
         } else {
             //ファイルがアップロードできなかったとき、
             //メッセージをフラッシュセッションにセット
             Session::set_flash('uerr', 'ファイルが正しくアップできませんでした。');
             //投稿を中断して入力画面にもどる。
             return View::forge('members/post2', $data, false);
             //Response::redirect(View::forge('members/post2', $data, false));
         }
     }
     //Validationチェック
     if ($val->run()) {
         //ファイルがアップロードされてなかったらダメ
         if ($upload_file == '') {
             $data['error'] = 'ファイルを選択してください。';
             return View::forge('members/post2', $data);
         }
         /*------
           postされた各データをDBに保存
           ----------*/
         //各送信データを配列
         $props = array('uid' => 1, 'pref_num' => $data['input_pref'], 'place' => $data['input_place'], 'title' => $data['input_title'], 'contents' => $data['input_content'], 'category' => $data['input_category'], 'tag1' => $data['input_tag1'], 'tag2' => $data['input_tag2'], 'rating' => $data['input_rating'], 'image' => $upload_file, 'datetime' => $time);
         //モデルオブジェクト作成
         $new = Model_Post::forge();
         $new->set($props);
         //データを保存する
         if (!$new->save()) {
             //保存失敗
             $data['save'] = '正しく投稿できませんでした。';
         } else {
             //保存成功
             /* 本当はユーザの投稿りすとページに飛びたい */
             Response::redirect('members/top');
         }
     }
     //$val->run()ここまで
     //validationオブジェクトをviewに渡す
     $data['val'] = $val;
     return View::forge('members/post2', $data, false);
 }
Ejemplo n.º 12
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;
 }