Example #1
0
 public function random()
 {
     $model = new \App\Model\Post();
     $begin = rand($model->min('id'), $model->max('id') - 25);
     $posts = $model->where('id', '>', $begin)->paginate(25);
     return view('post/list')->with('posts', $posts)->with('type', ['name' => 'random', 'title' => "随机"]);
 }
Example #2
0
 public function store(StoreBlogPostRequest $request)
 {
     $id = $request->input('id');
     $title = $request->input('title');
     $content = $request->input('content');
     $summary = str_summary($content, 100);
     $thumb_img = $request->input('thumb_img');
     $category = $request->input('category');
     $tags = $request->input('tags');
     if ($id) {
         $post = Post::find($id);
     } else {
         $post = new Post();
         $post->author = Auth::user()->id;
     }
     $post->title = $title;
     $post->summary = $summary;
     $post->content = $content;
     $post->thumb_img = $thumb_img;
     $post->save();
     $relations = [];
     $relations[] = ['term_id' => $category];
     if ($tags) {
         foreach ($tags as $tag) {
             $relations[] = ['term_id' => $tag];
         }
     }
     if ($relations) {
         $post->save_relations($relations);
     }
     return redirect()->action('Admin\\PostController@index');
 }
 public function createPost(Request $request, Response $response)
 {
     $title = $request->getParam('title');
     $content = $request->getParam('content');
     $slug = trim($title);
     $slug = str_replace(' ', '-', $slug);
     $post = new Post();
     $post->setTitle($title);
     $post->setContent($content);
     $post->setSlug($slug);
     $this->em->persist($post);
     $this->em->flush();
     echo "Da them bai viet moi thanh cong";
 }
Example #4
0
 public function record(Application $app, Request $reqeust)
 {
     $post = new Model\Post();
     $post->description = 'descr55';
     $result = $post->save();
     //        $post = new \Model\Post();
     //        $db_post = $post->findOne();
     //        $result = $post->save();
     //        $db_post->name  = 'testname';
     //        $db_post->save();
     //        $db_post = $post->findAll();
     //print_r(get_included_files());exit;
     return '';
     return $app->json(['result' => $db_post]);
 }
Example #5
0
 public function getDetail(Request $request)
 {
     $id = $request->route('id');
     $post = PostModel::where('pos_id', $id)->first();
     $menus = $this->getMenu();
     return view('front.detail', compact('post', 'menus'));
 }
 public function indexAction()
 {
     $data['title'] = 'Blog Tin Tức';
     $data['menu'] = Menu::where('status', 1)->get();
     $data['post'] = Post::where('status', 1)->get();
     return $this->render('default/home/index.html.twig', $data);
 }
 public function indexAction()
 {
     $data = $this->setData();
     $data['IMG_DIR'] = $this->IMG_POST_DIR;
     $data['title'] = 'Trang chủ';
     $data['title1'] = 'Tin tức SAO';
     $data['title2'] = 'Tin tức Giải Trí';
     $data['title3'] = 'Tin tức Thời Sự';
     $data['title4'] = 'Tin tức Thời Trang';
     $data['posts_1'] = Post::get_post_take('sao', 3);
     $data['posts_2'] = Post::get_post_take('giaitri', 3);
     $data['posts_3'] = Post::get_post_take('thoisu', 3);
     $data['posts_4'] = Post::get_post_take('thoitrang', 3);
     for ($i = 0; $i < 3; $i++) {
         $data['posts_1'][$i]['link'] = strtolower($this->convertUnicode($data['posts_1'][$i]['title']));
         $data['posts_2'][$i]['link'] = strtolower($this->convertUnicode($data['posts_2'][$i]['title']));
         $data['posts_3'][$i]['link'] = strtolower($this->convertUnicode($data['posts_3'][$i]['title']));
         $data['posts_4'][$i]['link'] = strtolower($this->convertUnicode($data['posts_4'][$i]['title']));
     }
     $data['others'] = Post::getOtherPost1('sao');
     foreach ($data['others'] as $p) {
         $p['link'] = strtolower($this->convertUnicode($p['title']));
     }
     return $this->render('index.html.twig', $data);
 }
 public function run()
 {
     DB::table('Posts')->delete();
     Post::create(['name' => 'First Name', 'email' => '*****@*****.**', 'city' => 'City 1', 'content' => 'First Feedbuck 24', 'slag' => 'first-feed', 'published' => true, 'created_at' => time()]);
     Post::create(['name' => 'Second Name', 'email' => '*****@*****.**', 'city' => 'City 2', 'content' => 'Second Feedbuck 24', 'slag' => 'second-feed', 'published' => true, 'created_at' => time()]);
     Post::create(['name' => 'Third Name', 'email' => '*****@*****.**', 'city' => 'City 3', 'content' => 'Third Feedbuck 24sdsds', 'slag' => 'third-feed', 'published' => true, 'created_at' => time()]);
 }
Example #9
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $posts = [['user_id' => 1, 'title' => '又一个shcms', 'content' => '欢迎你安装shcms,请开始体验吧!'], ['user_id' => 1, 'title' => 'shcms怎么用啊?', 'content' => '刚安装就报错了。请问怎么办?']];
     foreach ($posts as $post) {
         $model = \App\Model\Post::create($post);
         $this->command->info($model->id);
     }
 }
Example #10
0
 public function show($slug, $id)
 {
     //Tăng view
     $post = Post::find($id);
     $post->views++;
     $post->save();
     $data = ['post' => $this->post->show($id, current_lang())];
     return view('frontend.post', $data);
 }
 public function removePostAction()
 {
     if (!$this->isAdmin()) {
         return $this->redirect('home');
     }
     if ($this->isPostRequest()) {
         Post::delete_post($_POST['id']);
         die;
     }
 }
Example #12
0
 /**
  * Return the field values from the model
  *
  * @param integer $id
  * @param array $fields
  * @return array
  */
 protected function fieldsFromModel($id, array $fields)
 {
     $post = Post::findOrFail($id);
     $fieldNames = array_keys(array_except($fields, ['tags']));
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $post->{$field};
     }
     $fields['tags'] = $post->tags()->lists('tag')->all();
     return $fields;
 }
Example #13
0
 public static function list_paginate($term_id = 0, $term_type = 'category', $per_page = 2)
 {
     if ($term_id) {
         $terms = Term::get_item_by_type($term_type, $term_id);
         $category_ids = array_column($terms, 'id');
         $category_ids[] = $term_id;
         $posts = Post::leftJoin('relations', 'posts.id', '=', 'relations.object_id')->whereIn('relations.term_id', $category_ids)->orderBy('id', 'desc')->paginate($per_page);
     } else {
         $posts = Post::orderBy('id', 'desc')->paginate($per_page);
     }
     return $posts;
 }
 public function showHome()
 {
     //gets latest post
     $news = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 1)->orderBy('updated_at', 'desc')->first();
     $job = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 2)->orderBy('updated_at', 'desc')->first();
     $product = Product::where('is_active', 1)->orderby('updated_at', 'desc')->first();
     $project = Project::where('is_public', 1)->where('is_active', 1)->orderBy('updated_at', 'desc')->first();
     $newsContent = htmlspecialchars_decode($news->content, ENT_NOQUOTES);
     $news->content = $newsContent;
     //dd($news);
     return view('pages.home', ['news' => $news, 'job' => $job, 'product' => $product, 'project' => $project]);
 }
Example #15
0
 public function run()
 {
     DB::table('posts')->delete();
     $faker = Faker::create('ja_JP');
     for ($i = 0; $i < 10; $i++) {
         if ($i >= 5) {
             $categoryId = 2;
         } else {
             $categoryId = 1;
         }
         Post::create(['user_id' => 1, 'category_id' => $categoryId, 'title' => $faker->sentence(), 'content' => $faker->paragraph()]);
     }
 }
Example #16
0
 private function postImageToLocal(\App\Model\Post $post)
 {
     $sum_count = 0;
     $abs_count = 0;
     $err_count = 0;
     $rel_count = 0;
     $suc_count = 0;
     $post->content = preg_replace_callback("/<img.*?src=\"(.+?)\".*?>/ism", function ($data) use($post, &$sum_count, &$abs_count, &$err_count, &$rel_count, &$suc_count) {
         $sum_count++;
         if (preg_match('/^http:|https:|\\/\\//i', $data[1])) {
             $abs_count++;
             $path = tempnam('/tmp', 'sex');
             $file_content = @file_get_contents($data[1]);
             if (!$file_content) {
                 $err_count++;
                 return '#';
             } else {
                 $suc_count++;
             }
             file_put_contents($path, $file_content);
             $file = new \Symfony\Component\HttpFoundation\File\UploadedFile($path, $data[1], null, null, null, true);
             $model = \App\Model\File::create(['type' => 'post_image', 'name' => $post->id, 'file' => $file]);
             $model = \App\Model\File::find($model->id);
             return str_replace($data[1], $model->getFileUrl(), $data[0]);
         } else {
             $rel_count++;
         }
         return $data[0];
     }, $post->content);
     if ($suc_count > 0) {
         $post->save();
     }
     $this->info('总数:' . $sum_count);
     $this->info('绝对:' . $abs_count);
     $this->info('失败:' . $err_count);
     $this->info('相对:' . $rel_count);
     $this->info('成功:' . $suc_count);
 }
Example #17
0
    private function savePost($request): Post
    {
        $post = new Post();
        $user = $this->userSession->getUser();
        $user = $this->em->find("App\Model\User", $user->getId());
        $post->setUser($user);
        $post->setTitle($request->get('title'));
        $post->setDescription($request->get('description'));
        if ($imageName = $request->get('imageName')) {
            rename($this->uploadDir.'/temp/'.$imageName, $this->uploadDir.'/'.$imageName);
            $post->setImage($imageName);
        }
        $post->setPostedAt(new \DateTime('now'));
        $this->em->persist($post);
        $this->em->flush();

        return $post;
    }
Example #18
0
    private function savePost($request): Post
    {
        $post = new Post();
        $user = $this->userSession->getUser();
        $user = $this->em->find("App\Model\User", $user->getId());
        $post->setUser($user);
        $post->setTitle($request->get('title'));
        $post->setDescription($request->get('description'));
        $post->setPostedAt(new \DateTime('now'));
        $this->em->persist($post);
        $this->em->flush();

        return $post;
    }
Example #19
0
 public function all_post()
 {
     $number = get_setting('news_widget_number');
     $order = get_setting('news_widget_order');
     $orderby = get_setting('news_widget_orderby');
     $post_cat = get_setting('news_widget_cat');
     $cat = Tax::find($post_cat ? intval($post_cat) : 0)->all_ids();
     $post_id = array();
     foreach ($cat as $val) {
         $post = Tax::find($val)->posts()->select('id')->get();
         foreach ($post as $value) {
             $post_id[$value->id] = $value->id;
         }
     }
     if ($orderby === 'random') {
         $all_post = Post::whereIn('id', $post_id)->with('langs')->orderByRaw("RAND()")->take($number)->get();
     } else {
         $all_post = Post::whereIn('id', $post_id)->with('langs')->orderBy($orderby, $order)->take($number)->get();
     }
     return $all_post;
 }
Example #20
0
    public function submitPostAction(Request $request): Response
    {
        if ($this->form->isValid($request)) {

            $post = new Post();
            $user = $this->userSession->getUser($this->session);
            $user = $this->em->find("App\Model\User", $user->getId());
            $post->setUser($user);
            $post->setTitle($request->get('title'));
            $post->setDescription($request->get('description'));
            $post->setPostedAt(new \DateTime('now'));
            $this->em->persist($post);
            $this->em->flush();

            return new Response($this->twig->render('post_success.html.twig'));

        }

        $this->setFlashMessages('errors', $this->form->getErrors());

        return new RedirectResponse(
            $this->urlGenerator->generate('post')
        );
    }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     try {
         $this->validate($request, ['title' => 'required|max:255|min:3', 'content' => 'required|min:10']);
         $ispublished = $request->input('is_published') ? true : false;
         $isactive = $request->input('is_active') ? true : false;
         $content = htmlspecialchars($request->input('content'), ENT_NOQUOTES);
         $postobj = new Post();
         $postobj->where('id', $id)->update(['title' => $request->input('title'), 'content' => $request->input('content'), 'post_type' => $request->input('post_type'), 'is_published' => $ispublished, 'is_active' => $isactive]);
         //update attachment images
         if ($request->has('img')) {
             foreach ($request->input('img') as $img) {
                 //unserialize image value
                 $imgVal = unserialize($img);
                 if ($imgVal[1]) {
                     $fileObj = new Files();
                     $fileObj->where('id', $imgVal[0])->update(['attachment_id' => $id]);
                 } else {
                     $fileObj = new Files();
                     $fileObj->where('id', $imgVal[0])->update(['is_active' => false]);
                 }
             }
         }
         return Redirect::to("/back/post/edit/{$id}")->with('message', $request->input('title') . ' was successfully updated');
     } catch (Exception $e) {
         return Redirect::to("/back/post/edit/{$id}")->with('message', 'Oops! Something went wrong. Please try again later');
     }
 }
    function addPostScrollAction()
    {
        $postDB = $this->getPostData();
        $take = $postDB['NoP'];
        $data['posts'] = Post::getPost_skip_take($postDB['cateID'], $postDB['qty_now'], $take + 1);
        //$data['posts'] = Post::getPost_skip_take($cateID, $qty_now, $take + 1);
        $html = "";
        foreach ($data['posts'] as $key => $p) {
            if ($key < $take) {
                $p['link'] = strtolower($this->convertUnicode($p['title']));
                ob_start();
                ?>
                <div class="item_post post_<?php 
                echo $p['id'];
                ?>
">
                    <div class="all-post">
                        <div class="item_image">
                            <div class="image-box">
                                <a href="../bai-viet/<?php 
                echo $p['link'] . '/' . $p['id'];
                ?>
">
                                    <img src="<?php 
                echo $this->IMG_POST_DIR . $p['image'];
                ?>
" alt="<?php 
                echo $p['title'];
                ?>
" />
                                </a>
                            </div>
                        </div>
                        <div class="right-info">
                            <div class="info-box">
                                <div class="item_title">
                                    <a href="../bai-viet/<?php 
                echo $p['link'] . '/' . $p['id'];
                ?>
"><?php 
                echo $p['title'];
                ?>
</a>
                                </div>
                                <div class="item_time">
                                    <span><?php 
                echo date("H:i  d-m-Y", strtotime($p['time']));
                ?>
</span>
                                </div>
                                <div class="item_summary">
                                    <span><?php 
                echo $p['summary'];
                ?>
</span>
                                </div>
                                <div class="item_read_more" title="Chọn để xem nội dung chi tiết">
                                    <a href="../bai-viet/<?php 
                echo $p['link'] . '/' . $p['id'];
                ?>
">Xem thêm...</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php 
                $html = $html . ob_get_clean();
            }
        }
        $tbc = isset($data['posts'][$take]);
        echo json_encode(array("html" => $html, "tbc" => $tbc));
        exit;
    }
Example #23
0
 public function delete(Request $request)
 {
     if ($request->ajax()) {
         $ids = $request->input('ids');
         $status = true;
         $status = PostModel::whereIn("pos_id", $ids)->update(["pos_status_cd" => "DEL"]) ? true : false;
         if ($status) {
             return Redirect::route('postHome');
         } else {
             return "error";
         }
     }
 }
Example #24
0
 public function delTagByPost($post_id, $tag_id)
 {
     $post = \App\Model\Post::find($post_id);
     $post->tags()->detach($tag_id);
     return back();
 }
Example #25
0
 public function index()
 {
     $posts = Post::where("pos_status_cd", "ACT")->get(["pos_id", "pos_name", "pos_image", "pos_sum"]);
     $menus = $this->getMenu();
     return view('home', compact('posts', 'menus'));
 }
Example #26
0
 /**
  * 記事削除
  */
 public function postDelete(Request $request)
 {
     $post = Post::findOrFail($request->id);
     $post->delete();
     \Session::flash('flash_message', '削除しました。');
     return redirect('/');
 }
Example #27
0
 public function delete($moe)
 {
     $moe->send(array('result' => Post::instance()->findByPK($moe->get('GET.id'))->findById_author(Auth::data('id_author'))->get(1)->delete()));
 }
Example #28
0
 public function update(Request $request, $id)
 {
     $input = $request->input();
     $post = Post::find($id)->update($input);
     return redirect()->route('posts.show', $id);
 }
Example #29
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     Post::find($id)->delete();
     return redirect('post');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Post::truncate();
     factory(Post::class, 15)->create();
 }