public static function customCreate(CreateConversationRequest $request) { $conv = new Conversation(); $conv->Title = $request->Title; // if nothing specified in the request if (!$request->has('user_id')) { // if we are not even logged ( happen while seeding base) if (!\Auth::check()) { $conv->user_id = User::first()->id; } else { $conv->user_id = \Auth::id(); } } // if Pending status is specified we take it, if not default value will be applied (false) if (!$request->has('Pending')) { $conv->Pending = $request->Pending; } $conv->created_at = Carbon::now(); $conv->save(); // When conversation is settled the Thread can be created $thread = new Thread(); $thread->user_id = $conv->user_id; $thread->Content = $request->Content; $thread->conversation_id = $conv->id; $thread->created_at = Carbon::now(); $thread->Pending = $conv->Pending; $thread->save(); return true; }
/** * スレッド名取得メソッド * @param unknown $threadName: スレッドID */ public static function getThreadName($threadName) { //スレッド名を検索 $thread_name = Thread::where('id', '=', $threadName)->get(); //有れば名前を、なければfalse return $thread_name[0]['thread']; }
public function view($board, $thread_id) { // Does the thread exist? $thread = Thread::where("board", "=", $board)->where("thread_id", "=", $thread_id)->first(); // Has this thread been takendown? But does this user know the secret key? if ($thread->deleted_at != null && Request::input('sv') != $thread->secret) { return view('thread.takendown', ['reason' => $thread->takedown_reason ? $thread->takedown_reason : "No reason given."]); } // Fetch cache first. if (Cache::has('thread_' . $board . '_' . $thread_id)) { return Cache::get('thread_' . $board . '_' . $thread_id); } // No cache? Okay, let's fetch all the posts. $posts = $thread->posts()->get(); // Has this user already viewed this thread in the past 12 hours? $viewCache = ViewCache::where('user_ip', '=', Request::ip())->first(); if (!$viewCache) { // They haven't viewed this thread in the past 12 hours. Add to cache $viewCache = new ViewCache(); $viewCache->thread_id = $thread->id; $viewCache->user_ip = Request::ip(); $viewCache->save(); } $op = $posts[0]; unset($posts[0]); // remove OP. only leave replies. $response = view('thread.view', ['thread' => $thread, 'replies' => $posts, 'op' => $op])->render(); Cache::put('thread_' . $board . '_' . $thread_id, $response, 60); return $response; }
/** * New thread (not the create thread page) * @param Request $request * @return string */ public function newThread(Request $request) { // Validate input $this->validate($request, ['title' => 'required|max:255', 'forum' => 'required|numeric', 'body' => 'required|max:30000']); // Verify forum is a valid forum that can be posted in $forum = null; try { $forum = Forum::findOrFail($request->input('forum')); } catch (ModelNotFoundException $e) { abort(400); // 400 Bad Request - invalid forum id } if ($forum->type != 0) { abort(400); // 400 Bad Request - not correct forum type } // Create thread $thread = Thread::newThread($request->input('title'), $request->input('forum')); // Create opening post $post = post::newPost($request->input('body'), $thread->id); // Generate response $resp = new Response(json_encode(['status' => true, 'link' => $thread->getUserFriendlyURL()]), 200); $resp->header('Content-Type', 'application/json'); return $resp; }
public function run() { DB::table('update_records')->delete(); DB::table('view_cache')->delete(); DB::table('posts')->delete(); DB::table('threads')->delete(); ################## Thread::create(['id' => 1, 'thread_id' => 111111111, 'board' => 'a', 'updated_num' => 0, 'views' => '500', 'notice' => null, 'secret' => 'a719c9a1', 'takedown_reason' => null, 'tweeted_at' => null]); Post::create(['chan_id' => 111111111, 'thread_id' => 1, 'original_image_name' => 'Imgur.jpg', 'image_size' => 128000, 'image_width' => '535', 'image_height' => '535', 'thumb_width' => '250', 'thumb_height' => '250', 'image_url' => 'http://i.imgur.com/UmmyTUG.png', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 111111112, 'thread_id' => 1, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 111111113, 'thread_id' => 1, 'original_image_name' => 'Imgur 2.jpg', 'image_size' => 34000, 'image_width' => '500', 'image_height' => '466', 'thumb_width' => '116', 'thumb_height' => '125', 'image_url' => 'http://i.imgur.com/w6pQEvY.jpg', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 111111114, 'thread_id' => 1, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); ################## Thread::create(['id' => 2, 'thread_id' => 222222222, 'board' => 'b', 'updated_num' => 0, 'views' => '555', 'notice' => null, 'secret' => 'a719c9a1', 'takedown_reason' => null, 'tweeted_at' => null]); Post::create(['chan_id' => 222222222, 'thread_id' => 2, 'original_image_name' => 'Imgur.jpg', 'image_size' => 128000, 'image_width' => '535', 'image_height' => '535', 'thumb_width' => '250', 'thumb_height' => '250', 'image_url' => 'http://i.imgur.com/UmmyTUG.png', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 222222223, 'thread_id' => 2, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 222222224, 'thread_id' => 2, 'original_image_name' => 'Imgur 2.jpg', 'image_size' => 34000, 'image_width' => '500', 'image_height' => '466', 'thumb_width' => '116', 'thumb_height' => '125', 'image_url' => 'http://i.imgur.com/w6pQEvY.jpg', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 222222225, 'thread_id' => 2, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); ################## Thread::create(['id' => 3, 'thread_id' => 333333333, 'board' => 'g', 'updated_num' => 3, 'views' => '123', 'notice' => 'Admin note: This thread is garbage.', 'secret' => 'a719c9a1', 'takedown_reason' => null, 'tweeted_at' => null]); Post::create(['chan_id' => 333333333, 'thread_id' => 3, 'original_image_name' => 'Imgur.jpg', 'image_size' => 128000, 'image_width' => '535', 'image_height' => '535', 'thumb_width' => '250', 'thumb_height' => '250', 'image_url' => 'http://i.imgur.com/UmmyTUG.png', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 333333334, 'thread_id' => 3, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 333333335, 'thread_id' => 3, 'original_image_name' => 'Imgur 2.jpg', 'image_size' => 34000, 'image_width' => '500', 'image_height' => '466', 'thumb_width' => '116', 'thumb_height' => '125', 'image_url' => 'http://i.imgur.com/w6pQEvY.jpg', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 333333336, 'thread_id' => 3, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); ################## Thread::create(['id' => 4, 'thread_id' => 444444444, 'board' => 'q', 'updated_num' => 10, 'views' => '1250', 'notice' => null, 'secret' => 'a719c9a1', 'takedown_reason' => null, 'tweeted_at' => null, 'deleted_at' => DB::raw('NOW()')]); Post::create(['chan_id' => 444444444, 'thread_id' => 4, 'original_image_name' => 'Imgur.jpg', 'image_size' => 128000, 'image_width' => '535', 'image_height' => '535', 'thumb_width' => '250', 'thumb_height' => '250', 'image_url' => 'http://i.imgur.com/UmmyTUG.png', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 444444445, 'thread_id' => 4, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 444444446, 'thread_id' => 4, 'original_image_name' => 'Imgur 2.jpg', 'image_size' => 34000, 'image_width' => '500', 'image_height' => '466', 'thumb_width' => '116', 'thumb_height' => '125', 'image_url' => 'http://i.imgur.com/w6pQEvY.jpg', 'imgur_hash' => 'something', 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); Post::create(['chan_id' => 444444447, 'thread_id' => 4, 'subject' => null, 'name' => 'Anonymous', 'tripcode' => null, 'capcode' => null, 'post_timestamp' => DB::raw('FROM_UNIXTIME(1429902005)'), 'body' => 'What is your movie editing software of choice? Pic related for me, but the things you can do it with are pretty limited. Is there a good (free) alternative for simple video editing?']); }
/** * Create a new post * @param string $body Content of post, will be run through filters * @param integer $threadid Thread ID * @param integer| $posterid Poster's ID. Defaults to currently authenticated user * @param bool|false $hidden Is the post hidden from normal view? * @param bool|true $save Should the post be automatically saved into the database? * @return Post The resulting post object */ public static function newPost($body, $threadid, $posterid = null, $hidden = false, $save = true) { // Check users rights if (!Auth::check() && $posterid === null) { abort(403); // 403 Forbidden } // Check thread $thread = Thread::findOrFail($threadid); if ($thread->locked) { abort(403); // 403 Forbidden } // Run post through filters $body = PostProcessor::preProcess($body); // Create new post $post = new Post(); $post->thread_id = $threadid; $post->poster_id = Auth::user()->id; $post->body = $body; $post->hidden = $hidden; // defaults to false // Put post into database if ($save) { $post->save(); } return $post; }
public function run() { Model::unguard(); // MUST fail is have nothing $aConvID = Conversation::firstOrFail()->id; $userID = User::firstOrFail()->id; Thread::create(['Content' => 'A Thread comment seeded', 'user_id' => $userID, 'conversation_id' => $aConvID]); }
public function storeMessage($user, $input) { $thread = Thread::create(['subject' => $input['subject']]); Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); Participant::create(['thread_id' => $thread->id, 'user_id' => $user->id, 'last_read' => new Carbon()]); $this->sentMessageNotification($user); }
/** * Run the database seeds. * * @return void */ public function run() { $threads = Thread::all(); $users = User::all(); foreach ($threads as $thread) { factory(App\Post::class, mt_rand(1, 15))->create(['thread_id' => $thread->id, 'user_id' => $users->random()->id]); } }
/** * Displays threads belonging to the given forum. * * @param $id The forum to find threads for * @return Response */ public function listThreadsForForum($id) { // We only care about the ID before the first hyphen $id = strtok($id, '-'); $forum = Forum::where('id', $id)->first(); $threads = Thread::where('forum', $id)->join('users', 'users.id', '=', 'threads.author')->join('categories', 'categories.id', '=', 'threads.forum')->select('threads.*', 'users.username')->paginate(20); return view('forum', compact('threads', 'forum')); }
/** * Create a new thread * @param string $title Title of thread * @param integer $forumid Forum ID to host the thread * @param bool|false $locked Is the thread locked to further replies? * @param bool|false $hidden Is the thread hidden from normal view? * @param bool|true $save Should the thread be saved to the database? * @return Thread */ public static function newThread($title, $forumid, $locked = false, $hidden = false, $save = true) { // Create thread definition $thread = new Thread(); $thread->forum_id = $forumid; $thread->name = $title; $thread->locked = false; $thread->locked = $locked; // defaults to unlocked $thread->hidden = $hidden; // defaults to not hidden // Save thread to database if ($save) { $thread->save(); } return $thread; }
/** * Displays a given thread. * * @param $id int The thread to display * @return Response */ public function displayThread($id) { // We only care about the ID before the first hyphen $id = strtok($id, '-'); // Retrieve the first post of the thread $thread = Thread::where('threads.id', $id)->join('users', 'users.id', '=', 'threads.author')->select('threads.*', 'users.username')->first(); $replies = Reply::where('replies.thread', $id)->join('users', 'users.id', '=', 'replies.author')->select('replies.*', 'users.username')->paginate(20); return view('thread', compact('thread', 'replies')); }
public function delete() { $usr_id = Auth::user()->id; if (User::destroy($usr_id)) { Thread::where('user_id', '=', $usr_id)->delete(); Relation::where('user_id', '=', $usr_id)->delete(); Comment::where('user_id', '=', $usr_id)->delete(); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $this->data['post'] = App\Post::findOrFail($id); $this->data['thread'] = App\Thread::findOrFail($this->data['post']->thread_id); if (!\Auth::hasPerm($this->data['post']->user_id)) { \Session::flash('flash_message', 'You do not have permission to edit this post.'); return redirect('thread/' . $this->data['post']->thread_id); } return view('forum.posts.edit', $this->data); }
public function submit() { $url = trim(Request::input('uri')); $reason = trim(Request::input('reason')); $info = trim(Request::input('info')); $captcha = trim(Request::input('g-recaptcha-response')); $verify = new ReCaptcha(env('RECAPTCHA_PRIVATE')); $resp = $verify->verify($captcha, Request::ip()); if (!$resp->isSuccess()) { return redirect()->back()->withInput()->with('error', 'You entered the captcha incorrectly.'); } if (!$url || !$reason || !$info) { return redirect()->back()->withInput()->with('error', 'Please fill in all of the required fields.'); } $urlRegex = "/\\/?([a-z]+)\\/?(thread|res)\\/?([0-9]+)/"; $matches = array(); // Does this url match our pattern? if (!preg_match($urlRegex, $url, $matches)) { return redirect()->back()->withInput()->with('error', 'The URL you entered is not valid.'); } // Assign values $board = $matches[1]; $thread_id = $matches[3]; // Does this thread exist? $thread = Thread::withTrashed()->where('board', '=', $board)->where('thread_id', '=', $thread_id)->firstOrFail(); if ($thread->deleted_at != null) { return redirect()->back()->withInput()->with('error', 'This thread has already been taken down.'); } // Was this thread denied less than 3 days ago? $lastTakedown = TakedownRequest::where('thread_id', '=', $thread->id)->orderBy('id', 'desc')->first(); if ($lastTakedown) { // Was this request denied? if ($lastTakedown->processed == 1 && $lastTakedown->approved == 0 && strtotime($lastTakedown->deleted_at) > time() - 259200) { // 3 days return redirect()->back()->withInput()->with('error', 'This thread was recently reversed due to a previous takedown request. Please wait before resubmitting.'); } else { if ($lastTakedown->processed == 0) { return redirect()->back()->withInput()->with('error', 'Someone has already requested this thread be taken down.'); } } } $request = new TakedownRequest(); $request->thread_id = $thread->id; $request->reason = $reason; $request->info_provided = $info; $request->user_ip = Request::ip(); $request->save(); // Soft delete $thread->takedown_reason = "This thread has been automatically taken down - '" . $reason . "'"; $thread->save(); $thread->delete(); return redirect()->back()->with('success', 'Your takedown request has been sent. The thread has been automatically taken down. Please keep in mind that the takedown could be revsered in the future by an Admin.'); }
/** * Store a newly created resource in storage. * * @param $categoryId * @param $threadId * @param PostRequest $request * @return Response */ public function store($categoryId, $threadId, PostRequest $request) { if (!Sentinel::getUser()->hasAccess(['posts.create'])) { abort(401); } $thread = Thread::with(['category' => function ($query) use($categoryId) { $query->where('id', $categoryId); }])->findOrFail($threadId); $post = new Post($request->all()); $post->user_id = Sentinel::getUser()->id; $post->thread_id = $thread->id; $post->save(); return redirect()->route('categories.threads.posts.index', [$thread->category->id, $thread->id]); }
public function update($id) { try { $thread = Thread::findOrFail($id); } catch (ModelNotFoundException $e) { Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.'); return redirect('messages'); } $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => Input::get('message')]); $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]); $participant->last_read = new Carbon(); $participant->save(); return redirect('/message/' . $id); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { try { App\Thread::findOrFail($id); } catch (ModelNotFoundException $e) { return redirect('/'); } $this->data['posts'] = App\Thread::findOrFail($id)->posts()->select('posts.*', 'threads.forum_id')->join('threads', 'threads.id', '=', 'posts.thread_id')->paginate(10); foreach ($this->data['posts'] as $post) { $post->user = App\Post::findOrFail($post->id)->author; $post->user->post_count = App\User::findOrFail($post->user->id)->posts()->count(); } $this->data['forum'] = App\Forum::where('id', $this->data['posts'][0]->forum_id)->first(); $this->data['thread'] = App\Thread::where('id', $id)->first(); return view('forum.threads.show', $this->data); }
/** * スレッド詳細表示アクション * @return Ambigous <\Illuminate\Http\RedirectResponse, \Illuminate\Http\RedirectResponse>|Ambigous <\Illuminate\View\View, mixed, \Illuminate\Container\static> */ public function thread() { //スレッドIDを取得 if (Input::has('id')) { $thread_id = Input::get('id'); } else { return redirect('/')->with('err_msg', 'スレッドが選択されていません'); } //スレッドID→スレッド名 $thread = Thread::getThreadName($thread_id); //スレッドID→投稿一覧 $comments = Comment::select('id', 'user', 'content', 'date', 'number', 'response', 'file')->where('thread_id', '=', $thread_id)->orderBy('response', 'ASC')->get(); //飲み屋取得 $shops = Tavern::getTarern($thread_id); return view('board.thread', compact('thread_id', 'thread', 'comments', 'shops')); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { try { App\Forum::findOrFail($id); } catch (ModelNotFoundException $e) { return redirect('/'); } $this->data['threads'] = App\Thread::where('threads.forum_id', '=', $id)->join('users', 'users.id', '=', 'threads.user_id')->select('users.username', 'threads.*')->orderBy('threads.updated_at', 'desc')->paginate(15); foreach ($this->data['threads'] as $thread) { $thread->latest = App\Post::where('posts.thread_id', '=', $thread->id)->orderBy('posts.id', 'desc')->join('users', 'users.id', '=', 'posts.user_id')->first(); foreach ($this->data['threads'] as $thread) { $thread->post_count = App\Post::where('posts.thread_id', '=', $thread->id)->count(); } } $this->data['forum'] = App\Forum::findOrFail($id); return view('forum.show', $this->data); }
public function delete() { if (Input::has('id')) { $thread_id = Input::get('id'); //アップロードされている画像のパスを取得 $paths = Comment::select('file')->where('thread_id', '=', $thread_id)->get(); //画像ファイルの削除 foreach ($paths as $path) { if (!$path == null) { continue; } unlink($path['file']); } //スレッドの削除 Thread::where('id', '=', $thread_id)->delete(); } return redirect('/dashboard'); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $users = \App\User::lists('id')->all(); $threads = \App\Thread::lists('id')->all(); $faker = \Faker\Factory::create(); foreach (range(1, 500) as $index) { $text = $faker->paragraphs(mt_rand(1, 5)); $paragraphs = ''; foreach ($text as $index => $t) { $paragraphs .= $t; if ($index != count($text) - 1) { $paragraphs .= "\n\n"; } } \App\Post::create(['user_id' => $faker->randomElement($users), 'thread_id' => $faker->randomElement($threads), 'post' => $paragraphs]); } Model::reguard(); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $users = \App\User::lists('id')->all(); $forums = \App\Forum::lists('id')->all(); $faker = \Faker\Factory::create(); foreach (range(1, 200) as $index) { $user_id = $faker->randomElement($users); $thread = \App\Thread::create(['user_id' => $user_id, 'forum_id' => $faker->randomElement($forums), 'title' => $faker->sentence(6), 'slug' => $faker->slug]); $text = $faker->paragraphs(mt_rand(1, 5)); $paragraphs = ''; foreach ($text as $index => $t) { $paragraphs .= $t; if ($index != count($text) - 1) { $paragraphs .= "\n\n"; } } \App\Post::create(['user_id' => $user_id, 'thread_id' => $thread->id, 'thread_first' => $thread->id, 'post' => $paragraphs]); } Model::reguard(); }
public function postComment(Request $request) { $thread = Thread::findOrFail($request->input('thread_id')); $user = User::where('id', '=', Auth::user()->id)->first(); $relation = Relation::where([['user_id', '=', $user->id], ['thread_id', '=', $thread->id]])->first(); if (empty($relation)) { $relation = User::find(Auth::user()->id)->threads->find($thread->id); if (empty($relation)) { return Response::json(['response' => 'error']); } $comment = new Comment(['comments' => $request->input('comments')]); $comment->user_id = $user->id; $comment->relation_id = $relation->id; $comment->save(); return Response::json(['response' => 'Ok', 'comment' => $comment]); } else { $comment = new Comment(['comments' => $request->input('comments')]); $comment->user_id = $user->id; $comment->thread_id = $relation->thread_id; $comment->save(); return Response::json(['response' => 'Ok', 'comment' => $comment]); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $thread = Thread::findOrFail($id); return view('bbs.show', compact('thread')); }
public function run() { DB::table('threads')->delete(); Thread::create(array('thread' => '仙台出身の俺氏におすすめの酒場を教えるスレ', 'user' => 'morimori')); }
public function archive() { $board = Request::input('board'); $thread_id = Request::input('id'); // Validation if (!$board || !is_numeric($thread_id)) { return response()->json(['error' => 'no board or thread_id']); } // Is this board blacklisted? if (in_array($board, ['gif'])) { return response()->json(['error' => 'This board is currently not allowed to be archived.']); } // Retrieve thread JSON and validate $threadJson = @file_get_contents('http://a.4cdn.org/' . $board . '/thread/' . $thread_id . '.json'); if (!$threadJson) { return response()->json(['error' => 'Thread not found. Did it 404?']); } $threadInformation = json_decode($threadJson); if (!$threadInformation) { return response()->json(['error' => 'Something went wrong here... Unable to parse response from 4chan']); } $livePosts = $threadInformation->posts; $livePostCount = count($livePosts); // Does this thread have more than 10 replies? if ($livePostCount <= 10) { return response()->json(['error' => 'To archive a thread, it must have at least 10 replies.']); } $postPosition = 0; // Default value (start from beginning of thread // Has this thread been archived in the past? $threadCheck = Thread::where('board', '=', $board)->where('thread_id', '=', $thread_id)->get(); $countOfThreads = $threadCheck->count(); if ($countOfThreads > 0) { // return response()->json(['error' => 'Thread already archived. Re-archving is currently disabled.']); $existingThread = $threadCheck->first(); // Has this thread been taken down? if ($existingThread->deleted_at != null) { return response()->json(['error' => 'This thread is not allowed to be archived.']); } // Is this thread currently busy? if ($existingThread->busy) { return response()->json(['error' => 'This thread is currently in the process of being archived by someone else.']); } // Retrieve posts for this thread. // Determine at what point we should continue archiving this thread. $existingPosts = $existingThread->posts()->get(); $existingPostCount = $existingPosts->count(); // No existing posts? Huh... if ($existingPostCount == 0) { return response()->json(['error' => 'Something weird happened... Please try again later.']); } $lastExistingPost = $existingPosts->last(); // Get last live post (from 4chan API) and compare with the last post // we recorded since last archive attempt. $lastLivePost = end($livePosts); if ($lastExistingPost->chan_id == $lastLivePost->no) { return response()->json(['success' => true]); } // Wait... what? This shouldn't happen. if ($existingPostCount > $livePostCount) { return response()->json(['error' => 'Something weird happened... Please try again later.']); } // Update existing thread to become busy. $existingThread->busy = 1; // $existingThread->updated_num++; $existingThread->save(); // Set post position to existingPostCount. $postPosition = $postPosition; } else { // Create a new thread $existingThread = new Thread(); $existingThread->thread_id = $thread_id; $existingThread->board = $board; $existingThread->archive_date = DB::raw('NOW()'); $existingThread->user_ips = Request::ip(); $existingThread->busy = 1; $existingThread->secret = str_random(8); $existingThread->save(); } // Add user IP to list of user IPs $update_record = new UpdateRecord(); $update_record->thread_id = $existingThread->id; $update_record->user_ip = Request::ip(); $update_record->save(); $postsToInsert = []; // Start recording posts, starting at last reply position for ($i = $postPosition; $i < $livePostCount; $i++) { $livePost = $livePosts[$i]; $postID = isset($livePost->no) ? $livePost->no : null; $subject = isset($livePost->sub) ? $livePost->sub : null; $name = isset($livePost->name) ? $livePost->name : ""; $posterId = isset($livePost->id) ? $livePost->id : null; $tripcode = isset($livePost->trip) ? $livePost->trip : null; $capcode = isset($livePost->capcode) ? $livePost->capcode : null; $postTimestamp = isset($livePost->time) && is_numeric($livePost->time) ? $livePost->time : null; $postBody = isset($livePost->com) ? $livePost->com : ""; $md5 = isset($livePost->md5) ? $livePost->md5 : ""; // Set image default values $imageName = null; $imageSize = 271304; $thumbWidth = 0; $thumbHeight = 0; $imageWidth = 0; $imageHeight = 0; $imageUrl = null; $originalImageName = null; $imageDeleteHash = null; $chanImageName = null; $uploadedImage = null; $deleteHash = null; $imageDimensions = null; $thumbDimensions = null; if (isset($livePost->tim) && $livePost->ext == ".webm") { //use http://gfycat.com/api instead of imgur $uploadedImage = "/image/image-404.png"; $imageDimensions = "486x500"; $thumbDimensions = "195x200"; } // Do we have an image with this post? "tim" is only set when there is an image (or a file?). if (isset($livePost->tim) && $livePost->tim > 0 && $livePost->ext != ".webm") { $chanImageName = $livePost->tim . $livePost->ext; $imageLink = "http://i.4cdn.org/" . $board . "/src/" . $chanImageName; $thumbWidth = $livePost->tn_w; $thumbHeight = $livePost->tn_h; $imageWidth = $livePost->w; $imageHeight = $livePost->h; $originalImageName = $livePost->filename . $livePost->ext; $imageSize = $livePost->fsize; $deleteHash = ""; $uploadedImage = "/image/image-404.png"; // Upload to Imgur or Imageshack /* $imgur = new Imgur( env('IMGUR_KEY') ); $response = json_decode($imgur->upload($imageLink)); if($response && isset($response->status) && $response->status == 200) { $uploadedImage = $response->data->link; $deleteHash = $response->data->deletehash; } else { // Imgur failed, upload to Imageshack $imageshack = new Imageshack(env('IMAGESHACK_KEY')); $response = $imageshack->upload($imageLink); if ($response && isset($response->status) && $response->status == 1) { $uploadedImage = $response->links->image_link; } }*/ set_time_limit(10800); //3 hours max execution time $client_id = env('IMGUR_KEY'); $image = $imageLink; // do { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json'); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id)); curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => $image)); $reply = curl_exec($ch); curl_close($ch); $reply = json_decode($reply); $status = $reply->status; // } while( $status != 200 ); //repeat until we get no errors if ($status == 200) { $newimgurl = $reply->data->link; $deleteHashData = $reply->data->deletehash; $uploadedImage = $newimgurl; $deleteHash = $deleteHashData; $imageDimensions = $imageWidth . "x" . $imageHeight; $thumbDimensions = $thumbWidth . "x" . $thumbHeight; } else { $uploadedImage = "/image/image-404.png"; } /* //If you wish to download the image instead, file_put_contents( "L:\\data\\".$originalImageName, fopen($imageLink, 'r')); $filename = "L:\\data\\".$originalImageName; $client_id=env('IMGUR_KEY'); $handle = fopen($filename, "r"); $data = fread($handle, filesize($filename)); $pvars = array('image' => base64_encode($data)); $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json'); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id)); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars); $out = curl_exec($curl); curl_close ($curl); $pms = json_decode($out,true); $url=$pms['data']['link']; if($url!=""){ $uploadedImage = $url; }else{ echo "<h2>There's a Problem</h2>"; echo $pms['data']['error']; } */ } $postsToInsert[] = ["chan_id" => $postID, "threads_id" => $existingThread->id, "image_size" => $imageSize, "image_dimensions" => $imageDimensions, "thumb_dimensions" => $thumbDimensions, "image_url" => $uploadedImage, "imgur_hash" => $deleteHash, "original_image_name" => $originalImageName, "subject" => $subject, "name" => $name, "tripcode" => $tripcode, "capcode" => $capcode, "chan_post_date" => DB::raw('FROM_UNIXTIME(' . $postTimestamp . ')'), "body" => $postBody, "md5" => $md5]; } Post::insert($postsToInsert); // Mass insert posts $existingThread->busy = 0; $existingThread->save(); if (Cache::has('thread_' . $board . '_' . $thread_id)) { Cache::forget('thread_' . $board . '_' . $thread_id); } return response()->json(['success' => true]); }
/** * Add or remove star to thread. * * @param Thread $thread * @return \Illuminate\Http\RedirectResponse */ public function star(Thread $thread) { if ($thread->starred) { $thread->starred = false; $thread->save(); } else { $thread->starred = true; $thread->save(); } return back(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($thread_id, $comment_id) { $thread = Thread::findOrFail($thread_id); $comment = $thread->comments()->findOrFail($comment_id); return $comment; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { //we recover the Thread to update $aThread = Thread::findOrFail($id); // if we want to update the content if ($request->has('Content')) { $aThread->update($request->all()); session()->flash('flash_message', 'Thread updated'); } else { // we want to publish/unpublish it if ($aThread->Pending == 0) { $aThread->Pending = 1; session()->flash('flash_message', 'Thread unpublished'); } else { $aThread->Pending = 0; session()->flash('flash_message', 'Thread published'); } $aThread->save(); } // We go back to the list of Threads for the current Conversation return redirect('Thread/' . $aThread->conversation_id); }