示例#1
0
 public function store(Request $request)
 {
     $user = $request->auth;
     $uniq = md5(uniqid(time(), true));
     if ($request->hasFile('image')) {
         $types = array('115x69', '285x170', '617x324');
         // Width and height for thumb and resiged
         $sizes = array(array('115', '69'), array('285', '170'), array('617', '324'));
         $targetPath = 'img/media/';
         $image = $request->file('image');
         $ext = $image->getClientOriginalExtension();
         foreach ($types as $key => $type) {
             Image::make($image)->fit($sizes[$key][0], $sizes[$key][1])->save($targetPath . $type . "/" . $uniq . '.' . $ext);
         }
     }
     $post = new PostModel();
     $post->pos_name = ucfirst($request->input('pos_name'));
     $post->pos_slug = $request->input('pos_slug');
     $post->pos_image = $uniq . '.' . $ext;
     $post->pos_sum = $request->input('pos_sum');
     $post->pos_desc = $request->input('pos_desc');
     $post->pos_status_cd = "ACT";
     $post->created_by = $user->usr_id;
     $post->updated_by = $user->usr_id;
     $post->cat_id = $request->input('cat_id');
     if (!$post->save()) {
         return "Error";
     }
     return Redirect::route('postHome');
 }
示例#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');
 }
示例#3
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]);
 }
示例#4
0
文件: Test.php 项目: kpaxer/shcms
 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);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $this->validate($request, ['title' => 'required|unique:post|max:255|min:3', 'content' => 'required|min:10']);
         $ispublished = $request->input('is_published') ? true : false;
         $postobj = new Post();
         $postobj->title = $request->input('title');
         $postobj->content = htmlspecialchars($request->input('content'), ENT_NOQUOTES);
         $postobj->post_type = $request->input('post_type');
         $postobj->is_published = $ispublished;
         $postobj->is_active = true;
         $postobj->save();
         return Redirect::to('/back/post/edit/' . $postobj->id);
     } catch (Exception $e) {
         return Redirect::to('/back/post/create')->withwith('message', 'Oops! Something went wrong. Please try again later');
     }
 }