Example #1
0
 public function createAction()
 {
     $request = $this->app->request;
     $resp = new Response();
     $errors = array();
     $title = $request->getPostParam('title');
     $content = $request->getPostParam('content');
     if (!$title) {
         $errors['title'] = 'Введите заголовок';
     }
     if (!$content) {
         $errors['content'] = 'Введите текст';
     }
     if (!$errors) {
         $post = new Post(array('user_id' => $this->app->user->getId(), 'title' => $title, 'content' => $content));
         if ($id = $post->save()) {
             $resp->redirect($this->app->router->path('post.show', array($id)));
             return $resp;
         } else {
             $errors[] = 'Не удалось добавить пост';
         }
     }
     $resp->setTplVars(array('values' => array('title' => $title, 'content' => $content)));
     $resp->setTplVars(array('errors' => $errors));
     $resp->setTemplate('new_post.html');
     return $resp;
 }
Example #2
0
 public function __construct()
 {
     parent::__construct();
     if (Session::isSession('user')) {
         $user = new User();
         $user->findByName(Session::getData('user'));
         $authlevel = $user->getAuthlevel();
         $this->view->addAuthlevel($authlevel);
         $this->view->addLogged(1);
     } else {
         $this->view->addLogged(0);
     }
     $posts = new Post();
     $this->view->addPosts($posts->getAll());
 }
Example #3
0
 function deletePost($alias)
 {
     if (Session::isSession('user')) {
         $user = new User();
         $user->findByName(Session::getData('user'));
         $authlevel = $user->getAuthlevel();
         if ($authlevel > 3) {
             $toDelete = new PostModel();
             $toDelete->deleteByAlias($alias);
             $posts = new PostModel();
             $this->view->addAuthlevel($authlevel);
             $this->view->addPosts($posts->getAll());
             $this->view->forAjax('index');
         }
     }
 }
Example #4
0
 public function fromFollowers()
 {
     $user = Auth::get();
     $posts = [];
     $count_posts = 0;
     if ($user) {
         $followers = $user->following();
         $ids = [];
         foreach ($followers as $follower) {
             $ids[] = $follower->id;
         }
         if (count($ids) > 0) {
             $ids = implode(',', $ids);
             $post = new Post();
             $posts = $post->in($ids);
             $count_posts = count($posts);
         }
     }
     return $this->view('followers-posts', compact('posts', 'count_posts'));
 }
Example #5
0
 /**
  * post.php
  */
 public function getPost()
 {
     if (have_posts()) {
         the_post();
         $post = Post::find(get_the_ID());
     }
     if (!isset($post)) {
         return $this->getError();
     }
     return $this->renderPage('post', ['post' => $post]);
 }
Example #6
0
 public function testCreatePost()
 {
     $obj = json_decode($this->user_sample);
     // Casts a stdObject to the type passed in the second argument
     $user = AopTestUtils::cast($obj, 'Models\\User');
     // when post->save() is invoked return true
     AopMocker::mock('Models\\Post', 'save', true);
     // when User::getUser() is called the sample user will be returned
     AopMocker::mock('Models\\User', 'getUser', $user);
     $result = Post::createPost($user->_id, "Test", "This is a test post !", array("test", "unit"));
     $this->assertTrue($result >= 0);
 }
Example #7
0
 /**
  * define page title and load template files
  */
 public function index($category_title, $category_slug)
 {
     $this->data['title'] = 'Manage Posts';
     $total = count(PostModel::category($category_title, $category_slug));
     $pages = new Paginator('4', 'p');
     $this->data['post_content'] = PostModel::category($category_title, $category_slug, $pages->getLimit());
     $pages->setTotal($total);
     $path = DIR . 'post/' . $category_title . '/' . $category_slug . '?';
     $this->data['page_links'] = $pages->pageLinks($path, null);
     View::rendertemplate('header', $this->data);
     View::rendertemplate('sidebar', $this->data);
     View::render('post/post.index', $this->data);
     View::rendertemplate('footer', $this->data);
 }
 /** @test */
 public function it_deletes_all_specified_relations()
 {
     $user = User::create([]);
     $author = Author::create(['user_id' => $user->id]);
     $post = Post::create(['author_id' => $author->id]);
     $comment = Comment::create(['post_id' => $post->id]);
     $user = $user->fresh();
     $this->assertEquals($user->author()->count(), 1, 'author');
     $this->assertEquals($user->author()->first()->posts()->count(), 1, 'posts');
     $this->assertEquals($user->author()->first()->posts()->first()->comments()->count(), 1, 'comments');
     $user->delete();
     $this->assertEquals(Post::where('author_id', 1)->count(), 0, 'post 0');
     $this->assertEquals(Comment::where('post_id', 1)->count(), 0, 'comment 0');
     $this->assertEquals(Author::where('user_id', 1)->count(), 0, 'user 0');
 }
Example #9
0
 public static function createPost($user_id, $title, $body, array $tags)
 {
     $user = User::getUser($user_id);
     if (!$user instanceof User) {
         return -1;
         // User does not exist
     }
     if ($title == "") {
         return -2;
     }
     if (count($tags) < 2) {
         return -3;
     }
     $post = new Post();
     $post->title = $title;
     $post->tags = $tags;
     $post->body = $body;
     $post->creator = $user;
     if ($post->save()) {
         return 0;
     } else {
         return -3;
     }
 }
 public function getTagsNameArray()
 {
     $this->_load();
     return parent::getTagsNameArray();
 }
Example #11
0
 public function index()
 {
     $this->data['posts'] = Post::all();
     $this->data['title'] = 'Selamata datang di starter slim';
     return App::render('index.twig', $this->data);
 }
 /**
  * tag.php
  */
 public function getTag()
 {
     $tag = get_queried_object();
     $args = ['postsWhereKey' => Ajax::TAG, 'postsWhereValue' => $tag->term_id, 'thingType' => I18n::transu('tag'), 'thingToSearch' => $tag->name, 'posts' => Post::getByTag($tag->term_id)];
     return $this->renderPage('base/search', $args);
 }
Example #13
0
 public function indexAction()
 {
     $posts = Post::findAll('ORDER BY created_at DESC');
     return new Response('index.html', array('posts' => $posts));
 }
Example #14
0
 /**
  * Get the post relaction with the commnet
  *
  * @return Post
  */
 public function getPost()
 {
     return Post::find($this->comment_post_ID);
 }
 /**
  * Response the menu
  *
  * @param array $_datas
  * @return array JSON
  */
 private function jsonMenu($_datas)
 {
     $type = $_datas['type'];
     $args = ['archives' => Archive::getMonthly(), 'categories' => Term::getCategories(), 'languages' => I18n::getAllLangAvailableKeyValue(), 'pages' => Post::getPages(), 'tags' => Term::getTags()];
     $type = str_replace('-', '_', $type);
     $content = $this->render('menu/' . $type . '_default', $args);
     $json['content'] = $content;
     $json['code'] = KeysRequest::OK;
     return $json;
 }
Example #16
0
 /**
  *
  * @return Post
  */
 public function getNextPost()
 {
     return Post::find(get_next_post()->ID);
 }
Example #17
0
 public function edit($parameter)
 {
     $item_id = $parameter[0];
     $this->data['title'] = 'Edit Post';
     $category_model = new \Models\Category();
     $post_model = new \Models\Post();
     $album_model = new \models\album();
     $this->data['post'] = $post_model->getItem($item_id);
     $this->data['album_group'] = $album_model->all();
     $this->data['post_category_groups'] = $category_model->groupByCol('category_slug');
     if (isset($_POST) && !empty($_POST)) {
         $post_category_id = $_POST['post_category_id'];
         $post_album_id = $_POST['post_album_id'];
         $post_title = $_POST['post_title'];
         $post_body = $_POST['post_body'];
         $post_link = $_POST['post_link'];
         $post_excerpt = $_POST['post_excerpt'];
         $post_slug = Url::generateSafeSlug($post_title);
         $post_modified = time();
         $update_array = array('post_category_id' => $post_category_id, 'post_album_id' => $post_album_id, 'post_title' => $post_title, 'post_body' => $post_body, 'post_link' => $post_link, 'post_excerpt' => $post_excerpt, 'post_slug' => $post_slug, 'post_modified' => $post_modified);
         $update_array = Gump::xss_clean($update_array);
         $update_array = Gump::sanitize($update_array);
         $update_id = $post_model->updateId($update_array, $item_id);
         //UPLOAD IMAGE
         if ($_FILES["image"]["tmp_name"] != '') {
             Upload::setName(uniqid());
             Upload::upload_file($_FILES["image"], UPLOAD_PATH);
             $image_name = Upload::getFileName('images');
             $update_data = array('post_image' => $image_name);
             $update = $post_model->updateId($update_data, $update_id);
         }
         if ($update_id > 0) {
             Session::set('success', 'post edited');
             Url::redirect('post');
         }
     }
     View::rendertemplate('header', $this->data);
     View::rendertemplate('sidebar', $this->data);
     View::render('post/post.add', $this->data);
     View::rendertemplate('footer', $this->data);
 }