Example #1
0
 public function submit_link()
 {
     // for submitting the link created to the database
     $submit_link = Post::submit_link();
     $posts = Post::all();
     require_once 'views/posts/index.php';
 }
 public function adminDashboard()
 {
     $moderate_count = User::where('role_id', 1)->get()->count();
     $post_count = Post::all()->count();
     $posts = Post::orderBy('id', 'desc')->distinct()->where('is_approved', 1)->take(5)->get();
     return View::make('admin.adminDashboard')->withPage('dashboard')->with('moderate_count', $moderate_count)->with('post_count', $post_count)->withPosts($posts);
 }
 public function testAll()
 {
     $post = Post::all();
     $debug = last(DB::getQueryLog());
     $this->assertCount(3, $post);
     $this->assertEquals('select * from "posts" where "published" = ? and "status" = ?', $debug['query']);
 }
Example #4
0
 /**
  * Show Admin Dashboard
  * GET /admin/dashboard
  *
  * @return Response
  */
 public function dashboard()
 {
     $users = \DB::table('users')->count();
     $posts = \Post::all()->count();
     $feedback = \Feedback::all()->count();
     return \View::make('admin.dashboard', compact('posts', 'users', 'feedback'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $posts = Post::all();
     $data = compact('posts');
     // equal to ->with('posts', $posts);
     return View::make('home.index')->with('posts', $posts);
 }
Example #6
0
 public function testPaginate()
 {
     $posts = Paginator::paginatePosts(Post::all(), 0, 5);
     $res = $this->e->paginate($posts, 'year');
     $keys = array_keys($res);
     $this->assertTrue(2010 < $keys[0] and $keys[0] < 2020);
     $this->assertTrue(isset($res[$keys[0]]['posts']));
 }
 public function run()
 {
     $faker = Faker::create();
     Comment::truncate();
     $posts = Post::all();
     foreach (range(1, 50) as $index) {
         Comment::create(['user_id' => $faker->numberBetween($min = 1, $max = 10), 'post_id' => rand(1, $posts->count()), 'text' => $faker->paragraph($nbSentences = 3), 'attachment_id' => 0]);
     }
 }
 /**
  * Display a listing of the resource.
  * @param live
  * @return Response
  */
 public function index($live = null)
 {
     if (isset($live)) {
         $posts = Post::where('live', $live)->get();
     } else {
         $posts = Post::all();
     }
     return $posts;
 }
Example #9
0
 public function isUniqueSlug($slug)
 {
     $posts = Post::all();
     foreach ($posts as $post) {
         if ($post->slug == $slug) {
             return false;
         }
     }
     return true;
 }
Example #10
0
 public static function addLang($lang_id)
 {
     $pages = Post::all();
     foreach ($pages as $item) {
         $page_lang = new PostLang();
         $page_lang->lang_id = $lang_id;
         $page_lang->post_id = $item->id;
         $page_lang->save();
     }
 }
 public function run()
 {
     $faker = Faker::create();
     //add these posts
     for ($i = 0; $i < 10; $i++) {
         $comment = new Comment();
         $comment->post_id = Post::all()->random(1)->id;
         $comment->user_id = User::all()->random(1)->id;
         $comment->comment = $faker->text($maxNbChars = 200);
         $comment->save();
     }
 }
 public function index()
 {
     // Check if user has sent a search query
     if ($query = Input::get('query', false)) {
         // Use the Elasticquent search method to search ElasticSearch
         //        $posts = Post::search($query);
         $posts = Post::searchByQuery(["bool" => ['must' => ['multi_match' => ['query' => Input::get('query', ''), 'fields' => ["title^2", "content"]]], "should" => ['match' => ['tags' => ["query" => Input::get('query', ''), "type" => "phrase"]]]]]);
     } else {
         // Show all posts if no query is set
         $posts = Post::all();
     }
     return View::make('home', compact('posts'));
 }
 public function blog()
 {
     $this->load->model('post');
     $this->load->library('pagination');
     $posts = Post::all();
     $config['base_url'] = base_url() . 'blog/page/';
     $config['total_rows'] = $posts->count();
     $config['per_page'] = 5;
     $skip = ($this->uri->segment(3) - 1) * $config['per_page'];
     $this->pagination->initialize($config);
     $data = ['menu' => 'blog', 'posts' => Post::orderBy('created_at', 'desc')->skip($skip)->take($config['per_page'])->get(), 'links' => $this->pagination->create_links()];
     $this->load->view('front/blog', $data);
 }
 public function run()
 {
     /*delete all existing images*/
     DB::table('images')->delete();
     $faker = Faker::create();
     for ($i = 0; $i < 10; $i++) {
         $image = new Image();
         $image->post_id = Post::all()->random()->id;
         $image->url = $faker->imageUrl(640, 480, 'city');
         $image->image_title = '';
         $image->save();
     }
 }
Example #15
0
 public function tags($slug)
 {
     if (!$slug) {
         redirect('web');
     }
     // $join = 'LEFT JOIN post_to_tags a ON(posts.id = a.post_id) WHERE tag_id = '.$id.' AND post_status = "active"' ;
     $join = " LEFT JOIN post_to_tags a " . "ON(posts.id = a.post_id) " . "WHERE a.tag_id = " . Tag::first(array('slug' => $slug))->id . " " . "AND post_type = 'post' ORDER BY id DESC";
     $data['posts'] = Post::all(array('joins' => $join));
     $data['navs'] = Post::all(array('post_type' => 'page'));
     if (!$data['posts']) {
         redirect('web/error/404/NotFound');
     }
     $this->theme->view('tags', $data);
 }
Example #16
0
 public function posts()
 {
     $this->load->library('pagination');
     $posts = Post::all();
     $config['base_url'] = base_url() . 'dashboard/posts/page/';
     $config['total_rows'] = $posts->count();
     $config['per_page'] = 5;
     $skip = ($this->uri->segment(4) - 1) * $config['per_page'];
     $this->pagination->initialize($config);
     $data = ['menu' => 'posts', 'posts' => Post::skip($skip)->take($config['per_page'])->get(), 'links' => $this->pagination->create_links(), 'row' => $this->uri->segment(4) ? $config['per_page'] * ($this->uri->segment(4) - 1) : 0];
     // set redirect back url in session
     $this->session->set_userdata('previous_url', current_url());
     $this->load->view('dashboard/posts-list', $data);
 }
Example #17
0
 /**
  * Список сообщений
  */
 public function topic($id)
 {
     if (!($topic = Topic::find_by_id($id))) {
         App::abort('default', 'Данной темы не существует!');
     }
     if (User::check()) {
         $bookmark = Bookmark::find_by_topic_id_and_user_id($id, User::get('id'));
         if ($bookmark && $topic->postCount() > $bookmark->posts) {
             $bookmark->posts = $topic->postCount();
             $bookmark->save();
         }
     }
     $total = Post::count(['conditions' => ['topic_id = ?', $id]]);
     $page = App::paginate(Setting::get('posts_per_page'), $total);
     $posts = Post::all(['conditions' => ['topic_id = ?', $id], 'offset' => $page['offset'], 'limit' => $page['limit'], 'order' => 'created_at', 'include' => ['user']]);
     $crumbs = ['/forum' => 'Форум', '/forum/' . $topic->forum()->id => $topic->forum()->title, $topic->title];
     if ($topic->forum()->parent_id) {
         $crumbs = ['/forum' => 'Форум', '/forum/' . $topic->forum()->parent_id => $topic->forum()->parent()->title, '/forum/' . $topic->forum()->id => $topic->forum()->title, $topic->title];
     }
     App::view('forums.topic', compact('topic', 'posts', 'page', 'crumbs'));
 }
Example #18
0
 public function view()
 {
     $posts = Post::all();
     return View::make('posts.index', ['posts' => $posts]);
 }
Example #19
0
 public function index()
 {
     $post = Post::all();
     return Response::json(array('post' => $post));
 }
Example #20
0
 /**
  *  Search 
  * 
  */
 public function search()
 {
     if (isset($_POST["submitSearch"])) {
         $find = $_POST['searchBlog'];
         $getData = Post::all();
         $temp = array();
         if ($find != "") {
             foreach ($getData as $data) {
                 $pos = strpos($data['title'], $find);
                 if ($pos !== false) {
                     $temp[] = $data;
                 }
             }
             $posts1 = $this->post->orderBy('created_at', 'DESC')->paginate(10);
             return View::make('site/blog/index')->with(['posts' => $temp, 'posts1' => $posts1]);
         } else {
             if ($find == "") {
                 $posts = $this->post->orderBy('created_at', 'DESC')->paginate(10);
                 $posts1 = $this->post->orderBy('created_at', 'DESC')->paginate(10);
                 return View::make('site/blog/index', compact('posts', 'posts1'));
             }
         }
     }
 }
Route::post('/create-post', function () {
    $post = Post::create(Input::all());
    return Redirect::to('/' . $post->id);
});
Route::group(array('before' => 'auth'), function () {
    Route::post('/', function () {
        return View::make('create-post');
    });
    Route::post('/{post}', function () {
        return Redirect::to('create-post');
    });
    Route::get('/create-post', function () {
        return View::make('create-post');
    });
    Route::get('/{post}/edit-post', function (Post $post) {
        return View::make('edit-post')->with('post', $post)->with('method', 'put');
    });
    Route::get('/{post}/delete-post', function (Post $post) {
        return View::make('delete-post')->with('post', $post)->with('method', 'delete');
    });
});
Route::get('/login', function () {
    return View::make('login');
});
Route::get('/', function () {
    $posts = Post::all();
    return View::make('main-page')->with('posts', $posts);
});
Route::get('/{post}', function ($post) {
    return View::make('single-post')->with('post', $post);
});
 public function moderateDashboard()
 {
     $post_count = Post::all()->count();
     return View::make('moderate.moderateDashboard')->withPage('dashboard')->with('post_count', $post_count);
 }
Example #23
0
 public function testDelete()
 {
     $post = Post::forceCreateInLocale('de', ['title' => 'Title DE']);
     $post->forceSaveTranslation('en', ['title' => 'Title EN']);
     Post::forceCreateInLocale('en', ['title' => 'Title 2 EN']);
     $post->delete();
     $this->assertCount(1, Post::all());
     $this->assertCount(1, Post::i18nQuery()->get());
 }
Example #24
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $posts = Post::all();
     return View::make('backend.posts.index')->with('post', $posts);
 }
Example #25
0
 public function testDeleteWithoutTranslations()
 {
     Post::forceCreate(['title' => 'Title']);
     Post::i18nQuery()->truncate();
     $post = Post::first();
     $post->delete();
     $this->assertCount(0, Post::all());
 }
Example #26
0
 /**
  * Posts list
  *
  * @param Request $request
  * @param $opts
  * @return mixed
  */
 public function posts_list(Request $request, $opts)
 {
     $title = $this->lang->translate('post.list');
     // Delete post
     if ($request->get('delete')) {
         $post = \Post::find_by_id(intval($request->get('delete')));
         if ($post && $post->delete()) {
             $this->view->assign('message', $this->lang->translate('form.deleted'));
         }
     }
     // Publish post
     if ($request->get('accept')) {
         $post = \Post::find_by_id(intval($request->get('accept')));
         if ($post) {
             $post->moderate = '0';
             $post->created_at = time();
             if ($post->save()) {
                 $this->view->assign('message', $this->lang->translate('post.published'));
             }
             // Export to social
             $post->export();
             // Pinging sitemap
             NCService::load('SocialMedia.Ping');
         } else {
             $this->view->assign('message', $this->lang->translate('post.error_publish'));
         }
     }
     // Filter
     $filter['order'] = 'id DESC';
     if ($request->order) {
         $filter['order'] = $request->order;
     }
     $conditions = [];
     $values = [];
     // By Category
     if ($request->get('category')) {
         $category = \PostCategory::find($request->get('category'));
         if ($category) {
             $conditions[] = 'category_id = ?';
             $values[] = $category->id;
         }
     }
     // By Author
     if ($request->get('author')) {
         $author = \User::find($request->get('author'));
         if ($author) {
             $conditions[] = 'author_id = ?';
             $values[] = $author->id;
         }
     }
     // Premoderate
     $conditions[] = 'moderate = ?';
     if ($opts->get('mod')) {
         $title = $this->lang->translate('post.onmoderation');
         $values[] = '1';
     } else {
         $values[] = '0';
     }
     if ($conditions) {
         $filter['conditions'] = array_merge([implode(' AND ', $conditions)], $values);
     }
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \Post::count($filter)]);
     $filter = array_merge($filter, $paginator->limit());
     // Filter users
     $posts = \Post::all($filter);
     // Mass managing
     // Accept all visible
     if ($request->get('accept') == 'all') {
         foreach ($posts as $item) {
             $item->moderate = '0';
             $item->save();
             // Export to social
             Module::export($item, $this->view);
         }
         // Pinging sitemap
         NCService::load('SocialMedia.Ping');
         return static::redirect_response($request->getPathInfo());
     }
     // Sent to moderate all visible
     if ($request->get('moderate') == 'all') {
         foreach ($posts as $item) {
             $item->moderate = '1';
             $item->save();
         }
         return static::redirect_response($request->getPathInfo());
     }
     // Delete all visible
     if ($request->get('delete') == 'all') {
         foreach ($posts as $item) {
             $item->delete();
         }
         return static::redirect_response($request->getPathInfo());
     }
     $posts = array_map(function ($i) {
         return $i->to_array();
     }, $posts);
     return $this->view->render('posts/list.twig', ['title' => $title, 'posts_list' => $posts, 'listing' => $paginator->pages(), 'page' => $paginator->cur_page, 'moderate' => $opts->get('mod')]);
 }
 public function index()
 {
     return View::make('post.index', array('posts' => Post::all()));
 }
Example #28
0
 function all()
 {
     $posts = Post::all();
     return View::make('pages.frontpage', ['posts' => $posts]);
 }
Example #29
0
 public function showTattooProjectImages()
 {
     $posts = Post::all()->orderBy('created_at', 'desc')->paginate(10);
     return View::make('tattoo-artist-portfolio')->with(['posts' => $posts]);
 }
Example #30
0
 public function index()
 {
     //we store all the posts in a varaible
     $posts = Post::all();
     require_once 'views/posts/index.php';
 }