/** * View a board * * List all the threads in the board */ public function get_view($board_id) { // get all the threads for this board $threadlist = DB::table('threads')->join('users', 'threads.user_id', '=', 'users.id')->where('threads.board_id', '=', $board_id)->order_by('threads.updated_at', 'desc')->paginate(10, array('threads.id', 'threads.user_id', 'threads.subject', 'threads.postcount', 'threads.created_at', 'users.username')); // get this board $board = Board::find($board_id); return View::make('thread-list')->with('threadlist', $threadlist)->with('board', $board); }
public function getPost($postId) { // board $b = \Board::find($postId); if ($b === NULL) { return \Redirect::route('frontend.board.list'); } $b->count_num = $b->count_num + 1; $b->save(); $b->d = str_replace('-', '/', substr($b->created_at, 0, 10)); $isShowPost = false; if ($b->isPrivate == '0') { $isShowPost = true; } else { $user_id = \Auth::check() ? \Auth::user()->id : null; $isShowPost = $user_id === $b->user_id && $user_id !== null; } // fetch reply $br = \BoardReply::where('board_id', '=', $postId)->orderBy('created_at', 'desc')->first(array('tags', 'content', \DB::raw("date_format(created_at,'%Y/%m/%d') as d"))); $tags = array(); if ($br !== null) { $tagsId = unserialize($br->tags); $tags = \ServiceFaq::find($tagsId, array('id', 'title')); } // get next and previous $sql = 'select * from ' . '(select id, topic, created_at from board where created_at < ? and status = "1" order by created_at desc limit 0, 1) as T ' . 'union select * from ' . '(select id, topic, created_at from board where created_at > ? and status = "1" order by created_at asc limit 0, 1) as T order by id asc'; $rows = \DB::select($sql, array($b->created_at, $b->created_at)); $list = array('next' => null, 'prev' => null); foreach ($rows as &$r) { if ($r->created_at > $b->created_at) { $list['next'] = $r; } if ($r->created_at < $b->created_at) { $list['prev'] = $r; } } return \View::make('aesthetics.board.view_post', array('board' => &$b, 'list' => &$list, 'reply' => &$br, 'tags' => &$tags, 'isShowPost' => $isShowPost)); }
public function showBoard($id) { $posts = array(); $client = new \GuzzleHttp\Client(); $count = 0; $board = Board::find($id); $hashtag = $board->hashtag; $config = $board->config()->first(); $instagramKey = Config::get('laravel-social::providers.instagram.client_id'); $googleKey = 'AIzaSyDiywW3UvpbQ5aR7f_8tLVgNCzui7Gq6ek'; $postCount = 20; $googleToken = ''; $instagramNextMaxId = ''; $instagramMinTagId = ''; $twitterMaxId = ''; $twitterSinceId = ''; $facebookSinceId = ''; $facebookUntilId = ''; $vineSinceId = ''; $googleSinceId = ''; if ($config->has_insta != -1) { if (Auth::check()) { $user = Auth::user(); $provider = SocialProvider::where('user_id', '=', $user->id)->where('provider', '=', 'instagram')->first(); if (is_null($provider)) { $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&client_id=' . $instagramKey); } else { $token = $provider->access_token; $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&access_token=' . $token); } } else { $provider = SocialProvider::where('user_id', '=', $config->user_id)->where('provider', '=', 'instagram')->first(); if (is_null($provider)) { $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&client_id=' . $instagramKey); } else { $token = $provider->access_token; $instagram = $client->get('https://api.instagram.com/v1/tags/' . $hashtag . '/media/recent?count=' . $postCount . '&access_token=' . $token); } } if ($instagram->getStatusCode() == 200) { $instagramData = $instagram->json(); foreach ($instagramData['data'] as $data) { if (strpos($data['caption']['text'], $hashtag) !== false) { $post['user_id'] = $data['caption']['from']['id']; $post['username'] = $data['caption']['from']['username']; $post['url'] = $data['link']; $str = $data['caption']['text']; $str = preg_replace('/@([\\w-]+)/i', '', $str); // #@ $post['caption'] = $str; $post['post_id'] = $data['id']; $post['vendor'] = 'instagram'; $post['user_img_url'] = $data['caption']['from']['profile_picture']; $post['date_created'] = date("m-d-y H:i:s", $data['created_time']); if (isset($data['images']) && !isset($data['videos'])) { $post['img_url'] = $data['images']['standard_resolution']['url']; $post['post_type'] = 'image'; } else { if (isset($data['videos'])) { // dd($data['videos']); $post['img_url'] = $data['images']['standard_resolution']['url']; $post['embed'] = $data['videos']['standard_resolution']['url']; $post['post_type'] = 'video'; } } array_push($posts, $post); $count++; } } if (isset($instagramData['pagination']['next_max_id'])) { $instagramNextMaxId = $instagramData['pagination']['next_max_id']; } if (isset($instagramData['pagination']['min_tag_id'])) { $instagramMinTagId = $instagramData['pagination']['min_tag_id']; } } } if ($config->has_fb == 9999) { $facebook = Facebook::api('/search?type=post&limit=' . $postCount . '&q=%23' . $hashtag); if ($facebook) { foreach ($facebook['data'] as $post) { $post['vendor'] = 'facebook'; $post['post_id'] = $post['id']; //$post['url'] = $post['link']; $post['user_id'] = $post['from']['id']; $post['username'] = $post['from']['name']; $post['user_img_url'] = 'https://graph.facebook.com/' . $post['from']['id'] . '/picture?type=small'; if ($post['type'] == 'photo') { $post['img_url'] = $post['picture']; $post['post_type'] = 'image'; } else { if ($post['type'] == 'video' && isset($post['picture'])) { $post['post_type'] = 'video'; $post['img_url'] = $post['picture']; $post['embed'] = $post['link']; } else { $post['post_type'] = 'text'; } } if (isset($post['message'])) { $post['caption'] = $post['message']; } $post['date_created'] = $post['created_time']; array_push($posts, $post); $count++; } if (isset($facebook['paging'])) { if (isset($facebook['paging']['previous'])) { $prev = $facebook['paging']['previous']; parse_str($prev, $arr); $facebookSinceId = $arr['since']; } if (isset($facebook['paging']['next'])) { $next = $facebook['paging']['next']; parse_str($next, $arr); $facebookUntilId = $arr['until']; } } } } if ($config->has_tw != -1) { $first = true; $twitter = Twitter::getSearch(array('q' => '#' . $hashtag, 'include_entities' => 1, 'result_type' => 'recent', 'count' => $postCount)); if ($twitter) { foreach ($twitter->statuses as $tweet) { if (substr($tweet->text, 0, 2) !== "RT") { if ($first) { $twitterSinceId = $tweet->id . ''; $first = false; } $post['vendor'] = 'twitter'; $post['post_id'] = $tweet->id; $post['user_id'] = $tweet->user->id; $post['username'] = $tweet->user->screen_name; $post['user_img_url'] = $tweet->user->profile_image_url; if (isset($tweet->entities->media)) { $post['img_url'] = $tweet->entities->media[0]->media_url; $post['post_type'] = 'image'; } else { $post['post_type'] = 'text'; } $str = $tweet->text; $str = preg_replace('/@([\\w-]+)/i', '', $str); $post['caption'] = $str; $post['date_created'] = date("m-d-y H:i:s", strtotime($tweet->created_at)); array_push($posts, $post); $count++; } } if (isset($twitter->search_metadata->next_results)) { $next = $twitter->search_metadata->next_results; parse_str($next, $arr); $twitterMaxId = $arr['?max_id']; } else { $twitterMaxId = ''; } } } if ($config->has_google != -1) { $first = true; $google = $client->get('https://www.googleapis.com/plus/v1/activities?maxResults=2&query=' . $hashtag . '&key=' . $googleKey); if ($google->getStatusCode() == 200) { $data = $google->json(); foreach ($data['items'] as $item) { if ($first) { $googleSinceId = $item['id'] . ''; $first = false; } $post['vendor'] = 'google-plus'; $post['post_id'] = $item['id']; $post['user_id'] = $item['actor']['id']; $post['username'] = $item['actor']['displayName']; $post['date_created'] = $item['published']; $post['user_img_url'] = $item['actor']['image']['url']; $post['post_type'] = 'text'; if (isset($item['object']['attachments'][0]['objectType'])) { if ($item['object']['attachments'][0]['objectType'] == 'photo') { $post['img_url'] = $item['object']['attachments'][0]['fullImage']['url']; $post['post_type'] = 'image'; } if ($item['object']['attachments'][0]['objectType'] == 'video') { $post['img_url'] = $item['object']['attachments'][0]['image']['url']; $post['post_type'] = 'video'; $post['embed'] = $item['object']['attachments'][0]['url']; } if ($item['object']['attachments'][0]['objectType'] == 'article') { if (isset($item['object']['attachments'][0]['fullImage']['url'])) { $post['img_url'] = $item['object']['attachments'][0]['fullImage']['url']; } $post['post_type'] = 'article'; $post['article_url'] = $item['object']['attachments'][0]['url']; } } else { $post['post_type'] = 'text'; } $post['caption'] = $item['title']; $post['url'] = $item['url']; array_push($posts, $post); $count++; } if (isset($data['nextPageToken'])) { $googleToken = $data['nextPageToken']; } } } if ($config->has_vine != -1) { $vine = $client->get('https://api.vineapp.com/timelines/tags/' . $hashtag . '?limit=5'); $vineCount = 0; $first = true; if ($vine->getStatusCode() == 200) { $data = $vine->json(); if ($data['data']['count'] !== 0) { foreach ($data['data']['records'] as $item) { if ($first) { $vineSinceId = $item['postId'] . ''; $first = false; } $post['vendor'] = 'vine'; $post['post_id'] = $item['postId']; $post['user_id'] = $item['userId']; $post['username'] = $item['username']; $post['date_created'] = Carbon::parse($item['created'])->addHours(2); $post['user_img_url'] = $item['avatarUrl']; $post['img_url'] = $item['thumbnailUrl']; $post['post_type'] = 'video'; $post['url'] = $item['permalinkUrl']; $post['embed'] = $item['videoLowURL']; $post['caption'] = $item['description']; array_push($posts, $post); $count++; $vineCount++; if ($vineCount == 5) { break; } } } } } if ($count > 0) { $html = $this->postsToHtml($posts, $board->id, true); return Response::json(array('posts' => $html, 'endpoints' => array('google_token' => $googleToken, 'google_since_id' => $googleSinceId, 'twitter_max_id' => $twitterMaxId, 'twitter_since_id' => $twitterSinceId, 'instagram_max_id' => $instagramNextMaxId, 'instagram_min_tag' => $instagramMinTagId, 'facebook_until_id' => $facebookUntilId, 'facebook_since_id' => $facebookSinceId, 'vine_since_id' => $vineSinceId), 'count' => $count)); } else { return Response::json(array('message' => 'No posts')); } }
public function showBoardSettings($hashtag, $id) { if (Auth::check() && isset($hashtag) && isset($id)) { $user = Auth::user(); $board = Board::find($id); if ($board) { if ($board->config()->first()->user_id == $user->id) { $data['config'] = $board->config()->first(); $data['board'] = $board; $data['user'] = $user; $data['title'] = $this->layout->title = 'Ustawienia #' . $board->hashtag; $this->layout->content = View::make('user.board-settings', $data); } else { return Redirect::to('/konto')->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak.')); } } else { return Redirect::to('/konto')->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak.')); } } else { return Redirect::to('/')->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak.')); } }
public function postStatus() { try { $board_id = Arr::get($_POST, 'board_id', null); //update status of board $b = Board::find($board_id); if ($b === null) { throw new Exception('Request ID of board error!'); } $b->status = $b->status == '0' ? '1' : '0'; $b->save(); $topic = mb_substr($b->topic, 0, 10); $topic .= mb_strlen($b->topic, 'UTF-8') > 10 ? '...' : ''; $message = sprintf('更新留言「%s」的狀態,成功!', $topic); return Response::json(array('status' => 'ok', 'value' => $b->status, 'message' => $message, '_token' => csrf_token())); } catch (Exception $e) { return Response::json(array('status' => 'error', 'value' => 1, 'message' => $e->getMessage(), '_token' => csrf_token())); } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $records = ApplyRecord::orderBy('created_at', 'desc')->orderBy('id', 'desc'); if (Input::has('fields')) { $fields = explode(',', Input::get('fields')); $records = $records->select($fields); } if (Input::has('list')) { $list = explode(',', Input::get('list')); $records = $records->whereIn('id', $list); } if (Input::has('user_list')) { $list = explode(',', Input::get('user_list')); $records = $records->whereIn('user_id', $list); } if (Input::has('board_list')) { $list = explode(',', Input::get('board_list')); foreach ($list as $key => $value) { if (!is_numeric($value)) { $board = Board::where('code', $value)->first(); if ($board != null) { $list[$key] = $board->id; } else { unset($list[$key]); } } } $records = $records->whereIn('board_id', $list); } if (Input::has('type_list')) { $list = explode(',', Input::get('type_list')); var_dump($list); $records = $records->whereIn('event_type', $list); } if (Input::has('from') or Input::has('end')) { $from = Input::get('from', date('Y-m-d')); $end = Input::get('end', date('Y-m-d')); $records = $records->where(function ($records) use($from, $end) { $records->orWhereRaw("('{$from}' between `post_from` AND `post_end`)")->orWhereRaw("('{$end}' between `post_from` AND `post_end`)")->orWhereRaw("'{$from}' <= `post_from` AND `post_end` <= '{$end}'"); }); } if (Input::has('date_list')) { $list = explode(',', Input::get('date_list')); $records = $records->where(function ($records) use($list) { foreach ($list as $date) { if (strtotime($date)) { $date = date('Y-m-d', strtotime($date)); $records = $records->orWhereRaw("('{$date}' between `post_from` AND `post_end`)"); } } }); } if (Input::has('limit')) { $limit = Input::get('limit'); $offset = Input::get('offset', 0); $records = $records->skip($offset)->take($limit)->get(); } else { $records = $records->get(); } foreach ($records as $key => $record) { $board = Board::find($record['board_id']); $user = User::find($record['user_id']); $type_mapping = Config::get('poster.name_mapping.event_types'); $record->event_type_name = $type_mapping[$record->event_type]; $record->board_code = $board->code; $record->username = $user->username; $record->user_title = $user->title; } return Response::json($records); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $rules = array('description' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Response::json(['success' => false, 'messages' => $validator->errors()]); } $board = Board::find($id)->update(['description' => Input::get('description')]); return Response::json(['success' => true]); }
public function showBoard($query, $id = NULL, $presentation = NULL) { Asset::add('//cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.0.0/isotope.pkgd.min.js', 'footer'); Asset::add('//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.min.js', 'footer'); Asset::add('/js/libs/jquery.dropdown.js', 'footer'); //Asset::add('/js/posts.js', 'footer'); Asset::add('/js/posts-new.js', 'footer'); //check if board exists if (strlen($query) > 2) { $query = explode(' ', trim($query)); $result = preg_replace('/#([\\w-]+)/i', '$1', $query[0]); $query = Sanitize::string($result); } else { App::abort(404); } if (isset($id)) { $board = Board::find($id); if (!is_null($board)) { if ($board->hashtag != $query || $board->config()->first()->user_id == 0) { App::abort(404); } } else { App::abort(404); } } else { $board = Board::where('hashtag', '=', $query)->whereHas('config', function ($q) { $q->where('user_id', '=', 0); })->first(); if (is_null($board)) { $board = Board::create(array('hashtag' => $query)); $visit = Visit::create(array('ip' => Request::ip())); $config = BoardConfig::create(array('board_id' => $board->id)); } } if ($board->config()->first()->is_active == 1) { if (!is_null($board->cover_file_name)) { $data['layout'] = $this->layout->cover = 'with-cover'; } else { $data['layout'] = $this->layout->cover = 'no-cover'; } if (Auth::check()) { $user = Auth::user(); $data['username'] = preg_replace('/@.*?$/', '', $user->email); $data['userBoards'] = Board::byUserId($user)->orderBy('created_at', 'asc')->get(); $data['user'] = $user; if ($user->id == $board->config()->first()->user_id) { $userOwned = true; } if (!is_null($user->provider()->first()) && $user->provider()->first()->provider == 'facebook') { $data['avatar'] = '<img src="http://graph.facebook.com/' . $user->provider()->first()->provider_id . '/picture?type=small" alt="avatar" />'; } } if (Session::get('session-stat') != $board->id) { $stats = Stat::firstOrCreate(array('board_id' => $board->id))->increment('hits'); Session::put('session-stat', $board->id); } $data['board'] = $board; $data['boardData'] = $this->layout->boardData = $board; $data['title'] = $this->layout->title = $board->hashtag; $data['bodyClass'] = $this->layout->bodyClass = $board->hashtag . (isset($userOwned) ? ' user-owned' : ''); if (isset($presentation) && $presentation != 'live') { App::abort(404); } if (isset($id) && $presentation == 'live' && $board->config()->first()->presentation == 1) { $data['bodyClass'] = $this->layout->bodyClass = $board->hashtag . (isset($userOwned) ? ' user-owned' : '') . ' board-presentation'; $this->layout->content = View::make('boards.board-presentation', $data); } else { $this->layout->content = View::make('boards.index', $data); } } else { App::abort(404); } }