Ejemplo n.º 1
0
 function action_post_delete()
 {
     include "application/models/model_post.php";
     $id = $_POST['id'];
     $post = new Model_Post();
     $data = $post->delete_post($id);
     header('Location: /admin', true, 303);
 }
Ejemplo n.º 2
0
 protected function author($url)
 {
     $post = new Model_Post($this->data['id']);
     $post->load();
     $authors = array_keys($post['meta']['author']);
     $authors = Database::get_vector('author', array('alias', 'name'), Database::array_in('alias', $authors), $authors);
     $this->data['author'] = $authors;
 }
Ejemplo n.º 3
0
 public function save(Model_Post $post)
 {
     if ($post->id) {
         $where[] = 'id = ' . $post->id;
         $this->_db->update('posts', $post->toArray(), $where);
     } else {
         $this->_db->insert('posts', $post->toArray());
     }
 }
Ejemplo n.º 4
0
 protected function get_links()
 {
     $id = $this->get_id();
     $post = new Model_Post($id);
     $links = Database::join('post_link_url', 'plu.link_id = pl.id')->join('post_url', 'plu.url_id = pu.id')->get_full_table('post_link', 'pl.post_id = ?', $id);
     foreach ($links as $link) {
         $link = new Model_Post_Link($link);
         $post->add_link($link);
     }
     return $post->get('link');
 }
Ejemplo n.º 5
0
 public function testCanCreatePost()
 {
     $numOfPostsBefore = $this->_postPdo->count();
     $p = new Model_Post();
     $p->title = 'Hoolala';
     $p->content = 'what can I say?';
     $p->save();
     $this->assertTrue(intval($p->id) > 0);
     $numOfPostsAfter = $this->_postPdo->count();
     $this->assertTrue($numOfPostsAfter - $numOfPostsBefore === 1);
 }
Ejemplo n.º 6
0
 /**
  *
  * Loads a basic list info
  * @param string $view template to render 
  */
 public function action_index($view = NULL)
 {
     $this->template->title = __($this->_orm_model);
     $this->template->scripts['footer'][] = 'js/oc-panel/crud/index.js';
     $elements = new Model_Post();
     $elements->where('id_forum', 'IS', NULL);
     $pagination = Pagination::factory(array('view' => 'oc-panel/crud/pagination', 'total_items' => $elements->count_all()))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
     $pagination->title($this->template->title);
     $elements = $elements->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
     $pagination = $pagination->render();
     if ($view === NULL) {
         $view = 'oc-panel/pages/blog/index';
     }
     $this->render($view, array('elements' => $elements, 'pagination' => $pagination));
 }
Ejemplo n.º 7
0
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new Model_Post();
     }
     return self::$_instance;
 }
Ejemplo n.º 8
0
 public function atomAction()
 {
     $feed = $this->getFeed();
     $feed->addAuthor("Jon Lebensold", "*****@*****.**", "http://www.zendcasts.com");
     $feed->setFeedLink(Model_Post::getUrl() . 'feed/atom', 'atom');
     echo $feed->export('atom');
 }
Ejemplo n.º 9
0
 public function __construct($reader = null, $writer = null)
 {
     parent::__construct($reader, $writer);
     $data = $this->reader->get_data();
     if (empty($data['id']) || !Check::id($data['id'])) {
         throw new Error_Update('Incorrect Id');
     }
     $model = new Model_Post($data['id']);
     $model->load();
     if ($model->is_phantom()) {
         throw new Error_Update('Incorrect Id');
     }
     if ($model['area'] != 'workshop' && !sets::user('rights')) {
         throw new Error_Update('Not enough rights');
     }
     $this->model = $model;
 }
Ejemplo n.º 10
0
 public static function summary_userdata(&$data, $user_id)
 {
     $data['total_dive_time'] = Model_Post::summary_dive_time($user_id);
     $data['first_date'] = Model_Post::get_first_date($user_id);
     $data['creature'] = Model_Post::summary_report_count($user_id);
     $data['yearly'] = Model_Post::get_yearly($user_id);
     $data['location'] = Model_Post::summary_location($user_id);
 }
Ejemplo n.º 11
0
 public static function getPosts()
 {
     // this would normally hit a database
     $posts = array();
     $posts[] = Model_Post::create('Title 1', 'this is a really long piece of text about a whole bunch of stuff that doesn\'t matter. I could keep writing and writing and writing!');
     $posts[] = Model_Post::create('Title 2', 'A shorter piece of content lives here');
     return $posts;
 }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
 /**
  * Deletes a single record while ignoring relationships.
  *
  * @chainable
  * @throws Kohana_Exception
  * @return ORM
  */
 public function delete()
 {
     if (!$this->_loaded) {
         throw new Kohana_Exception('Cannot delete :model model because it is not loaded.', array(':model' => $this->_object_name));
     }
     //delete replies for that topic
     DB::delete('posts')->where('id_post_parent', '=', $this->id_post)->execute();
     parent::delete();
 }
Ejemplo n.º 14
0
 /**
  *
  * Display single page
  * @throws HTTP_Exception_404
  */
 public function action_view($seotitle)
 {
     $post = new Model_Post();
     $post->where('status', '=', 1)->where('seotitle', '=', $seotitle)->cached()->limit(1)->find();
     if ($post->loaded()) {
         Breadcrumbs::add(Breadcrumb::factory()->set_title($post->title));
         $this->template->title = $post->title;
         $this->template->meta_description = $post->description;
         $previous = new Model_Post();
         $previous = $previous->where('status', '=', 1)->order_by('created', 'desc')->where('id_post', '<', $post->id_post)->limit(1)->find();
         $next = new Model_Post();
         $next = $next->where('status', '=', 1)->where('id_post', '>', $post->id_post)->limit(1)->find();
         $this->template->bind('content', $content);
         $this->template->content = View::factory('pages/blog/post', array('post' => $post, 'next' => $next, 'previous' => $previous));
     } else {
         //throw 404
         throw new HTTP_Exception_404();
     }
 }
Ejemplo n.º 15
0
 public function action_delete($id = null)
 {
     if ($post = Model_Post::find($id)) {
         $post->delete();
         Session::set_flash('success', e('Deleted post #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete post #' . $id));
     }
     Response::redirect('admin/post');
 }
Ejemplo n.º 16
0
 public function action_view($id = null)
 {
     is_null($id) and Response::redirect('post');
     if (!($data['post'] = Model_Post::find($id))) {
         Session::set_flash('error', 'お求めの記事はありません [# ' . $id . ' ]');
         Response::redirect('post');
     }
     $this->template->title = "ブログ";
     $this->template->content = View::forge('post/view', $data);
 }
Ejemplo n.º 17
0
 /**
  * Portada de los borradores.
  * @param int $pagina Número de página a mostrar.
  */
 public function action_index($pagina)
 {
     // Cargamos la portada.
     $vista = View::factory('borradores/index');
     // Cantidad de elementos por pagina.
     $model_configuracion = new Model_Configuracion();
     $cantidad_por_pagina = $model_configuracion->get('elementos_pagina', 20);
     // Cargamos datos de posts.
     $model_post = new Model_Post();
     // Formato de la página.
     $pagina = (int) $pagina > 0 ? (int) $pagina : 1;
     // Cargamos el listado de borradores.
     list($borradores, $total) = $model_post->borradores(Usuario::$usuario_id, $pagina, $cantidad_por_pagina);
     // Que sea un número de página válido.
     if (count($borradores) == 0 && $pagina != 1) {
         Request::redirect('/borradores');
     }
     // Paginación.
     $paginador = new Paginator($total, $cantidad_por_pagina);
     $vista->assign('paginacion', $paginador->get_view($pagina, '/borradores/index/%d'));
     unset($paginador);
     // Obtengo información de los borradores.
     foreach ($borradores as $k => $v) {
         if (is_array($v)) {
             $a = $v['post']->as_array();
             $a['categoria'] = $v['post']->categoria()->as_array();
             // $a['moderado'] = $v['moderado']->as_array();
             // $a['motivo'] = $v['moderado']->moderacion()->as_array();
         } else {
             $a = $v->as_array();
             $a['categoria'] = $v->categoria()->as_array();
         }
         $borradores[$k] = $a;
     }
     // Seteo parámetros a la vista.
     $vista->assign('borradores', $borradores);
     unset($borradores);
     // Seteo el menu.
     $this->template->assign('master_bar', parent::base_menu('posts'));
     // Asignamos la vista a la plantilla base.
     $this->template->assign('contenido', $vista->parse());
 }
Ejemplo n.º 18
0
 public function action_delete($id = null)
 {
     $post = \Model_Post::find($id);
     if ($post->delete()) {
         // Delete cache
         \Cache::delete('sidebar');
         \Messages::success(__('backend.post.deleted'));
     } else {
         \Messages::error(__('error'));
     }
     \Response::redirect_back(\Router::get('admin_post'));
 }
Ejemplo n.º 19
0
 public function editarAcao()
 {
     $view = $this->getView();
     if ($_POST) {
         $idpost = (int) $_POST['idpost'];
         $idcategoria = (int) $_POST['idcategoria'];
         $titulo = $_POST['titulo'];
         $texto = $_POST['texto'];
         $voPost = new Vo_Post();
         $voPost->idpost = $idpost;
         $voPost->idcategoria = $idcategoria;
         //by conz
         $voPost->titulo = $titulo;
         $voPost->texto = $texto;
         $postModel = new Model_Post();
         try {
             $postModel->editar($voPost);
             header("location:post-editar.php?idpost={$idpost}");
             exit;
         } catch (Exception_Post_TextoVazio $exTexto) {
             $view->setValor('erro', "Preencha o campo texto!");
         } catch (Exception_Post_TituloVazio $exTitulo) {
             $view->setValor('erro', "Preencha o campo título!");
         }
     } else {
         $idpost = (int) $_GET['idpost'];
         $dao = new Dao_Post();
         $retorno = $dao->request("idpost = {$idpost}");
         if (!isset($retorno[0])) {
             echo 'Nenhum Post encontrado';
             exit;
         }
         $voPost = $retorno[0];
     }
     $daoCategoria = new Dao_Categoria();
     $listaCategoria = $daoCategoria->request();
     $view->setValor('categorias', $listaCategoria);
     $view->setValor('post', $voPost);
     $view->mostrar('post-editar');
 }
Ejemplo n.º 20
0
 /**
  * Visualização post individual, e não autenticado
  */
 public function postAction()
 {
     $this->view->content = 400;
     $this->view->nu_post = $this->getRequest()->getParam('id');
     $this->view->post = Model_Post::getInstance()->get(array('tipo' => 'id', 'nu_post' => $this->getRequest()->getParam('id')));
     $this->view->title = "Post";
     $this->view->description = current($this->view->post);
     $this->view->description = $this->view->description['tx_post'];
     if (!$this->view->post) {
         $this->_helper->viewRenderer->setNoRender();
         echo $this->view->partial('helpers/404.phtml');
     }
 }
Ejemplo n.º 21
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));
     }
 }
    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.º 23
0
 /**
  *
  * Display single page
  * @throws HTTP_Exception_404
  */
 public function action_view($seotitle)
 {
     $post = new Model_Post();
     // if visitor or user with ROLE_USER display post with STATUS_ACTIVE
     if (!Auth::instance()->logged_in() or Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role == Model_Role::ROLE_USER) {
         $post->where('status', '=', Model_Post::STATUS_ACTIVE);
     }
     $post->where('seotitle', '=', $seotitle)->where('id_forum', 'IS', NULL)->cached()->limit(1)->find();
     if ($post->loaded()) {
         Breadcrumbs::add(Breadcrumb::factory()->set_title($post->title));
         $this->template->title = $post->title;
         $this->template->meta_description = $post->description;
         $previous = new Model_Post();
         $previous = $previous->where('status', '=', Model_Post::STATUS_ACTIVE)->where('id_forum', 'IS', NULL)->order_by('created', 'desc')->where('id_post', '<', $post->id_post)->limit(1)->find();
         $next = new Model_Post();
         $next = $next->where('status', '=', Model_Post::STATUS_ACTIVE)->where('id_forum', 'IS', NULL)->where('id_post', '>', $post->id_post)->limit(1)->find();
         $this->template->bind('content', $content);
         $this->template->content = View::factory('pages/blog/post', array('post' => $post, 'next' => $next, 'previous' => $previous));
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Ejemplo n.º 24
0
 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));
 }
Ejemplo n.º 25
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;
 }
Ejemplo n.º 26
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;
 }
Ejemplo n.º 27
0
 public function action_comment($slug)
 {
     $post = Model_Post::find_by_slug($slug);
     // Lazy validation
     if (Input::post('name') and Input::post('email') and Input::post('message')) {
         // Create a new comment
         $post->comments[] = new Model_Comment(array('name' => Input::post('name'), 'website' => Input::post('website'), 'email' => Input::post('email'), 'message' => Input::post('message'), 'user_id' => $this->current_user->id));
         // Save the post and the comment will save too
         if ($post->save()) {
             $comment = end($post->comments);
             Session::set_flash('success', 'Added comment #' . $comment->id . '.');
         } else {
             Session::set_flash('error', 'Could not save comment.');
         }
         Response::redirect('blog/view/' . $slug);
     } else {
         // Just show the view again until they get it right
         $this->action_view($slug);
     }
 }
Ejemplo n.º 28
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('post');
     if (!($post = Model_Post::find($id))) {
         Session::set_flash('error', '投稿が見つかりませんでした。');
         Response::redirect('post');
     }
     if (Input::method() == 'POST') {
         if ($post->check(Input::post('delete_password'))) {
             $post->delete();
             Session::set_flash('削除が完了しました。');
             Response::redirect('post');
         } else {
             Session::set_flash('error', 'パスワードが違います。');
         }
     }
     $data['post'] = $post;
     $data['title'] = 'SAMPLE BBS';
     $this->template->title = 'SAMPLE BBS';
     $this->template->content = View::forge('post/delete', $data);
 }
Ejemplo n.º 29
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;
 }
Ejemplo n.º 30
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);
     }
 }