/** Obtiene un html en un formato standar para mostrar la produccion * * @param type $production (Production) El objeto de production * @return type */ static function getVisualHtml(Production $production, $classname = "production", $classimage = "img-rounded") { $isVideoMain = $production->haveVideoMain(); $html = "<div class='" . $classname . "'>"; $html .= "<a "; if (Auth::check()) { $html .= "onClick='modalProduction(\"" . $production->id . "\");'"; } else { $html .= "href='" . url("production/" . $production->slug) . "'"; } $html .= ">"; //Si la produccion es una serie incrustar la información de los capitulos if (!$isVideoMain) { $chapters = Chapter::where(Chapter::ATTR_PRODUCTION_ID, $production->id)->get(); $json = array(); foreach ($chapters as $chapter) { $json[] = array($chapter->name, url("production/" . $production->slug . "/play/" . urlencode(\App\System\Library\Security\Hash::encrypt($chapter->id)))); } $html .= "<span class='hidden' id='chapters-" . $production->id . "'>" . json_encode($json) . "</span>"; } $html .= "<span class='hidden' id='url-" . $production->id . "'>" . url("production/" . $production->slug) . "</span><img id='img-production-" . $production->id . "' title='" . $production->title . "' class='" . $classimage; $html .= $production->state != Production::STATE_ACTIVE ? " production-not-available" : ""; $html .= "' src='" . Util::convertToSecureUrl($production->image) . "'><div class='over'><span class='glyphicon glyphicon-play-circle'></span>" . $production->title . "</div>" . "</a>" . "</div>"; return $html; }
/** Recibe una peticion ajax, para generar una url de video con una token especial * * @param Request $request * @return type */ function ajax_getVideoUrl(Request $request) { if (!$request->ajax()) { return; } //Evita que se un usuario pueda reproducir dos videos al mismo tiempo //NOTA: Esta funcion no se puede implementar, porque el evento onbeforeunload de javascript no funciona del todo en Google Chrome (Buscar una alternativa) /* if (Auth::user()->playbacks()->where(User::ATTR_PLAYBACKS_PIVOT_RUNNING, true)->count() > 0) return json_encode(array("error" => "<span style='font-size: 60pt;color: red;' class='glyphicon glyphicon-ban-circle'></span><br/>Lo sentimos, pero no puedes reproducir este contenido, por que esta cuenta ya se esta usando.")); */ //Tiempo de paja //sleep(3); $data = $request->all(); //Verifica que el token no se repite do { $token = Hash::generateToken(100); } while (Auth::user()->playbacks()->where(User::ATTR_PLAYBACKS_PIVOT_TOKEN, $token)->count() > 0); if (strlen($data["token_video"]) > 2) { $parent_play = Auth::user()->playbacks()->where(User::ATTR_PLAYBACKS_PIVOT_TOKEN, $data["token_video"])->get(); if (count($parent_play) > 0) { $parent_play = $parent_play[0]; $parent = $parent_play->pivot->id; } else { return json_encode(array("error" => "Bad Request")); } } else { $parent = 0; } //Obtiene la información del video $chapter = Chapter::firstOrNew([Chapter::ATTR_VIDEO => $data["id_video"]]); //Genera un registro de reproduccion y token de validacion Auth::user()->playbacks()->attach($data["production_id"], array(User::ATTR_PLAYBACKS_PIVOT_CHAPTER_ID => $chapter->id, User::ATTR_PLAYBACKS_PIVOT_IP => Util::getIP(), User::ATTR_PLAYBACKS_PIVOT_DATE => DateUtil::getCurrentTime(), User::ATTR_PLAYBACKS_PIVOT_TOKEN => $token, User::ATTR_PLAYBACKS_PIVOT_PARENT => $parent, User::ATTR_PLAYBACKS_PIVOT_USER_AGENT => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null)); return json_encode(array("url" => url("get/source/video/" . $token . "/" . $data["id_video"]), "token" => $token)); }