예제 #1
0
 public function showItem($screen_name, $id)
 {
     if (User::where('screen_name', '=', $screen_name)->first() == NULL) {
         return Response::view('404', array('title' => '404 page'), 404);
     }
     if (Item::where('id', '=', $id)->first() == NULL) {
         return Response::view('404', array('title' => '404 page'), 404);
     }
     $user = DB::table('users')->where('screen_name', '=', $screen_name)->get()[0];
     $item = DB::table('items')->where('id', '=', $id)->where('user_id', '=', $user->id)->get()[0];
     $tagmaps = DB::table('tagmaps')->where('item_id', $item->id)->get();
     $tags = array();
     foreach ($tagmaps as $tagmap) {
         $tags[] = DB::table('tags')->select('content')->where('id', $tagmap->tag_id)->get()[0]->content;
     }
     $comments = array();
     $cs = Comment::where('item_id', '=', $id)->get();
     foreach ($cs as $comment) {
         $comment_user = User::where('id', '=', $comment->user_id)->first();
         $comment['user'] = $comment_user;
         $comments[] = $comment;
     }
     $star_status = false;
     if (Auth::check()) {
         $auth_id = Auth::user()->id;
         $star_status = $this->getStarStatus($auth_id, $id);
     }
     $Niconico = new Niconico();
     $query = implode(' | ', $tags);
     $ret = $Niconico->sugoiSearch($item->type, $query);
     $related_works = array();
     if (isset($ret->values)) {
         foreach ($ret->values as $value) {
             $related_works[] = array('cmsid' => $value->cmsid, 'title' => $value->title, 'thumbnail_url' => $value->thumbnail_url, 'start_time' => $value->start_time, 'view_counter' => $value->view_counter, 'comment_counter' => $value->comment_counter, 'mylist_counter' => $value->mylist_counter);
         }
     }
     if ($item->type == 'video') {
         $pattern = '/^http:\\/\\/www\\.nicovideo\\.jp\\/watch\\/(sm[0-9]+)/';
     } else {
         $pattern = '/^http:\\/\\/seiga\\.nicovideo\\.jp\\/seiga\\/(im[0-9]+)/';
     }
     $works = Work::where('item_id', '=', $item->id)->get();
     foreach ($works as &$work) {
         $item = Item::where('id', '=', $work->item_id)->get()[0];
         $work['item'] = $item;
         $work['user'] = User::where('id', '=', $work->user_id)->get()[0];
         $work['item_poster_screen_name'] = User::where('id', '=', $item->user_id)->get()[0]->screen_name;
         if ($item->category_id != 0) {
             $work['item_category'] = Category::where('id', '=', $item->category_id)->get()[0]->content;
         }
     }
     $data = array('item' => $item, 'user' => $user, 'works' => $works, 'pattern' => $pattern, 'title' => $item->title, 'comments' => $comments, 'tags' => $tags, 'star_status' => $star_status, 'star_count' => Starmap::where('user_id', '=', $user->id)->count(), 'work_count' => Work::where('user_id', '=', $user->id)->count(), 'star_gazers_num' => Starmap::where('item_id', '=', $item->id)->count()[0], 'related_works' => $related_works);
     return View::make('item', $data);
 }
예제 #2
0
 public function create($item_id)
 {
     $data = Input::all();
     $item = Item::where('id', '=', $item_id)->get()[0];
     $screen_name = User::where('id', '=', $item->user_id)->first()['attributes']['screen_name'];
     $now = date("Y-m-d H:i:s");
     if ($item['type'] == 'video') {
         $reg = '/^http:\\/\\/www\\.nicovideo\\.jp\\/watch\\/(sm[0-9]+)/';
     } else {
         $reg = '/^http:\\/\\/seiga\\.nicovideo\\.jp\\/seiga\\/im([0-9]+)/';
     }
     preg_match($reg, $data['url'], $match);
     $nico_content = $match ? $match[1] : 0;
     if ($item['type'] == 'video') {
         $Niconico = new Niconico();
         $ret = $Niconico->getThumbInfo($nico_content);
         $title = $ret->title;
         $thumbnail_url = $ret->thumbnail_url;
     } else {
         $title = '';
         $thumbnail_url = "http://lohas.nicoseiga.jp/thumb/{$nico_content}q";
     }
     if ($nico_content) {
         $work = new Work();
         $work->item_id = $item_id;
         $work->user_id = Auth::user()->id;
         $work->url = $data['url'];
         $work->title = $title;
         $work->thumbnail_url = $thumbnail_url;
         $work->comment = nl2br(htmlspecialchars($data['comment']));
         $work->created_at = date("Y-m-d H:i:s");
         $work->updated_at = date("Y-m-d H:i:s");
         $work->save();
         Starmap::where('item_id', '=', $item_id)->update(array('notice_flag' => 1));
         return Redirect::to("/{$screen_name}/items/{$item_id}");
     } else {
         echo "その作品はあかん";
     }
 }