private function loadAttributes()
 {
     //Obtiene la tabla de referencia de información de la produccion
     if (!preg_match_all('/<table[^>]*id=["\']name-overview-widget-layout*["\']\\>(.*?)<\\/table>/', $this->htmlContent, $match)) {
         return;
     }
     $match_content = $match[0][0];
     //IMAGEN
     if (!preg_match_all('/<img\\s+.*?src=[\\"\']?([^\\"\' >]*)[\\"\']?[^>]*>(.*?)[\\"\']>/i', $match_content, $match_image, PREG_SET_ORDER)) {
         return;
     }
     $path_image = public_path("assets/db/images/") . md5($this->getName()) . ".jpg";
     try {
         copy(strip_tags($match_image[0][1]), $path_image);
     } catch (\Exception $e) {
     }
     $this->setImage(Util::convertPathToUrl($path_image));
     $this->loadContent(Util::filtrateUrl($this->url_provider) . "bio");
     //BIOGRAFIA
     if (!preg_match_all('/<div[^>]*class=["\']soda odd*["\']\\>(.*?)<\\/p>/i', $this->htmlContent, $match_bio, PREG_SET_ORDER)) {
         return;
     }
     $bio = strip_tags(strip_tags($match_bio[0][0]));
     $this->setBiography(Util::traslateText($bio));
 }
 function setImageProduction($production_id)
 {
     if (!isset($_GET["poster"])) {
         return "Sin poster";
     }
     /**
      *  MODIFICAR LA IMAGEN DE UNA PRODUCCION
      */
     $production = Production::find($production_id);
     $data[Production::ATTR_IMAGE] = "";
     $data[Production::ATTR_POSTER] = "http://" . $_GET["poster"];
     $path_image = public_path("assets/db/images/") . md5($production->title_original . $production->year);
     copy($data[Production::ATTR_POSTER], $path_image . "-poster.jpg");
     $production->poster = Util::convertPathToUrl($path_image . "-poster.jpg");
     if (strlen($data[Production::ATTR_IMAGE]) > 9) {
         copy($data[Production::ATTR_IMAGE], $path_image . ".jpg");
         $production->image = Util::convertPathToUrl($path_image . ".jpg");
     } else {
         $title_md5 = md5($production->title_original . $production->year);
         $image = new Image($production->poster);
         $production->image = $image->createCopy(214, 334, $title_md5, public_path("assets/db/images/"), false);
     }
     $production->save();
     return "REALIZADO EXITOSAMENTE";
 }
 function postCreate(Request $request)
 {
     $data = $request->all();
     //SLUG
     $data[Production::ATTR_SLUG] = Util::createSlug($data[Production::ATTR_TITLE] . " " . $data[Production::ATTR_YEAR]);
     $data[Production::ATTR_STATE] = Production::STATE_IN_WAIT;
     $production = new Production();
     $production->fill($data);
     $production->save();
     //Asigna las Categorias
     foreach ($data as $index => $value) {
         if (strpos($index, "cat-") !== false) {
             $production->terms()->attach($value);
         }
     }
     /*
      * OBTIENES LAS IMAGENES DE LA PRODUCCION
      */
     $path_image = public_path("assets/db/images/") . md5($production->title_original . $production->year);
     copy($data[Production::ATTR_POSTER], $path_image . "-poster.jpg");
     $production->poster = Util::convertPathToUrl($path_image . "-poster.jpg");
     if (strlen($data[Production::ATTR_IMAGE]) > 9) {
         copy($data[Production::ATTR_IMAGE], $path_image . ".jpg");
         $production->image = Util::convertPathToUrl($path_image . ".jpg");
     } else {
         $title_md5 = md5($production->title_original . $production->year);
         $image = new Image($production->poster);
         $production->image = $image->createCopy(214, 334, $title_md5, public_path("assets/db/images/"), false);
     }
     $production->save();
     //Cola de procesamiento
     $queue = new QueueProductions();
     //Si existe
     if (QueueProductions::existsByLink($data["imdb"])) {
         $queue = QueueProductions::where(QueueProductions::ATTR_LINK, $data["imdb"])->get()[0];
     } else {
         $queue->name = $data[Production::ATTR_TITLE_ORIGINAL];
         $queue->link = $data["imdb"];
         $queue->date_creation = DateUtil::getCurrentTime();
     }
     $queue->production_id = $production->id;
     $queue->date_processed = DateUtil::getCurrentTime();
     $queue->save();
     return redirect("manager/productions/edit/" . $production->id);
 }
Exemple #4
0
 /** Crea una copy redimensionada y recortada adecuadamente sin defases de la image original y la almacena en el servidor con nuevo name
  * 
  * @param type $width Width de la copy
  * @param type $height Height de la copy
  * @param type $name Name de la copy
  * @param type $route La route donde se almacenara la copy
  * @param boolean $includeName Indica si debe adjuntar el antiguo nombre con el nuevo nombre 
  */
 public function createCopy($width, $height, $name, $route, $includeName = true)
 {
     $this->objectImage = $this->createImageFromOriginal();
     //Calcula los valores optimos a redimensioar sin desfasarse en los tamaños requeridos
     list($width_redim, $height_redim) = $this->calculateResizeMinProporcionate($width, $height);
     $copy_redim = imagecreatetruecolor($width_redim, $height_redim);
     $background = imagecolorallocate($copy_redim, 50, 255, 0);
     imagefilledrectangle($copy_redim, 0, 0, $width_redim, $height_redim, $background);
     imagecolortransparent($copy_redim, $background);
     //Redimensiona la image al proporcion adecuada
     imagecopyresized($copy_redim, $this->objectImage, 0, 0, 0, 0, $width_redim, $height_redim, $this->width, $this->height);
     //Almacenara la copy de la image redimensiona y recortada adecuadamente
     $copy_rec = imagecreatetruecolor($width, $height);
     $background = imagecolorallocate($copy_rec, 50, 255, 0);
     imagefilledrectangle($copy_rec, 0, 0, $width, $height, $background);
     imagecolortransparent($copy_rec, $background);
     list($x_recorte, $y_recorte) = $this->calculateCutPosition($width_redim, $height_redim, $width, $height);
     //Genera el recorte adecuado de la image
     imagecopy($copy_rec, $copy_redim, 0, 0, $x_recorte, $y_recorte, $width_redim, $height_redim);
     $destination = $includeName ? $route . $this->name . $name . "." . $this->extension : $route . $name . "." . $this->extension;
     $this->saveImage($copy_rec, $destination);
     return Util::convertPathToUrl($destination);
 }
 /**
  * Carga los atributos de la produccion dado por el contenido proveido en la URL
  */
 private function loadAttributes()
 {
     //Obtiene la tabla de referencia de información de la produccion
     if (!preg_match_all('/<table[^>]*id=["\']title-overview-widget-layout*["\']\\>(.*?)<\\/table>/', $this->htmlContent, $match)) {
         return;
     }
     $match_content = $match[0][0];
     //(TITULO)**********************************/
     //
     //Obtiene el encabezado para extraer la información mas importante
     if (!preg_match_all('/<h1 [^>]*class=["\']header*["\']\\>(.*?)<\\/h1>/i', $match_content, $match, PREG_SET_ORDER)) {
         return;
     }
     //Obtiene la referencia al titulo de la produccion
     if (!preg_match_all('/<span[^>]*class=["\']itemprop*["\'] itemprop=["\']name*["\']\\>(.*?)<\\/span>/i', $match[0][0], $match_title, PREG_SET_ORDER)) {
         return;
     }
     //Asigna el titulo de la produccion
     $this->title = strip_tags(isset($match_title[0][1]) ? $this->getLatinTitle($match_title[0][1]) : null);
     $title_ori = $match_title[0][1];
     //(AÑO)*************************************/
     //Obtiene el año de lanzamiento de la produccion
     if (!preg_match_all('/<span[^>]*class=["\']nobr*["\']\\>(.*?)<\\/span>/i', $match[0][0], $match_year, PREG_SET_ORDER)) {
         return;
     }
     $this->year = str_replace(array("(", ")"), "", strip_tags(isset($match_year[0][1]) ? $match_year[0][1] : null));
     //(TITULO ORIGINAL)*************************/
     //Busca el titulo original de la produccion, si no lo encuentra asigna el titulo encontrado
     if (preg_match_all('/<span[^>]*itemprop=["\']name*["\']\\>(.*?)<\\/span>/i', $match[0][0], $match_title_original, PREG_SET_ORDER)) {
         $this->title_original = str_replace(array("\"", "(original title)", "  "), "", strip_tags(isset($match_title_original[0][0]) ? $match_title_original[0][0] : null));
     } else {
         $this->title_original = $title_ori;
     }
     //(SLUG)*************************/
     $this->slug = Util::createSlug(trim($this->title) . " " . $this->year);
     //(DESCRIPCION)*************************/
     if (!preg_match_all('/<p[^>]*itemprop=["\']description*["\']\\>(.*?)<\\/p>/i', $match_content, $match_description, PREG_SET_ORDER)) {
         return;
     }
     $this->description = Util::traslateText(strip_tags(isset($match_description[0][1]) ? $match_description[0][1] : null));
     //SECCION INFOBAR PARA EXTRAER - DURACION - CATEGORIAS
     if (!preg_match_all('/<div[^>]*class=["\']infobar*["\']\\>(.*?)<\\/div>/i', $match_content, $match_infobar, PREG_SET_ORDER)) {
         return;
     }
     //(DURACION)*************************/
     if (preg_match_all('/<time[^>]*itemprop=["\']duration*["\'](.*?)\\>(.*?)<\\/time>/i', $match_infobar[0][1], $match_duration, PREG_SET_ORDER)) {
         $this->duration = intval(preg_replace("/[^0-9-.]/", "", strip_tags($match_duration[0][2])));
     }
     //(CATEGORIAS)*************************/
     if (!preg_match_all('/<a\\s+.*?href=[\\"\']\\/genre\\/(.+?)[\\"\']?[^>]*>(.*?)<\\/a>/i', $match_infobar[0][1], $match_categories, PREG_SET_ORDER)) {
         return;
     }
     foreach ($match_categories as $category) {
         $cat = strip_tags($category[2]);
         $this->categories[] = Util::textDecodetoSimply($cat);
     }
     //RATING
     if (preg_match_all('/<div[^>]*class=["\']titlePageSprite star-box-giga-star*["\']\\>(.*?)<\\/div>/i', $match_content, $match_rating, PREG_SET_ORDER)) {
         $this->rating_rel = trim(strip_tags($match_rating[0][1]));
     }
     //IMAGEN
     if (!preg_match_all('/<img\\s+.*?src=[\\"\']?([^\\"\' >]*)[\\"\']?[^>]*>/i', $match_content, $match_image, PREG_SET_ORDER)) {
         return;
     }
     $path_image = public_path("assets/db/images/") . md5($this->title_original . $this->year);
     try {
         if (Util::UrlExist(strip_tags($match_image[0][1]))) {
             copy(strip_tags($match_image[0][1]), $path_image . ".jpg");
             $this->image = Util::convertPathToUrl($path_image . ".jpg");
         } else {
             $this->image = null;
         }
     } catch (Exception $e) {
         $this->image = null;
     }
     //POSTER
     $search = new BingSearchImage($this->title_original . " poster " . $this->year, 1700, 1200);
     $images = $search->getResult();
     //Verifica que la url este bien
     $i = -1;
     do {
         $i++;
         $url_poster = $images[$i];
     } while (!Util::UrlExist($url_poster));
     try {
         if (is_array(@getimagesize($url_poster))) {
             copy($url_poster, $path_image . "-poster.jpg");
             $this->poster = Util::convertPathToUrl($path_image . "-poster.jpg");
         } else {
             $this->poster = null;
         }
     } catch (Exception $e) {
         $this->poster = null;
     }
     if (is_null($this->image) && !is_null($this->poster)) {
         $md5 = md5($this->title_original . $this->year);
         $image = new Image($this->poster);
         $this->image = $image->createCopy(214, 334, $md5, public_path("assets/db/images/"), false);
     }
     //(PERSONAL DE LA PRODUCCION)*************************************
     if (!preg_match_all('/<div\\s+.*?itemprop=[\\"\']director[\\"\']?[^>]*>(.*?)<\\/div>/i', $match_content, $match_director_bar, PREG_SET_ORDER)) {
         return;
     }
     //DIRECTOR
     if (!preg_match_all('/<a[^>]*href=["\']\\/name\\/.*["\']*itemprop=["\']url*["\']\\>(.*?)<\\/a>/i', $match_director_bar[0][1], $match_director, PREG_SET_ORDER)) {
         return;
     }
     $this->director = array(trim(strip_tags($match_director[0][1])), $this->extractLinkPerson($match_director[0][0]));
     //Actores
     if (!preg_match_all('/<table[^>]*class=["\']cast_list*["\']\\>(.*?)<\\/table>/', $this->htmlContent, $match_cast)) {
         return;
     }
     if (!preg_match_all('/(<a)?[^>]*href=["\']\\/name\\/(.*?)itemprop=["\']url*(.*?)<span[^>]*class=["\']itemprop*["\'] itemprop=["\']name*["\']\\>(.*?)<\\/span><\\/a>/i', $match_cast[0][0], $match_actors, PREG_SET_ORDER)) {
         return;
     }
     foreach ($match_actors as $actor) {
         $this->actors[] = array(trim(strip_tags($actor[0])), $this->extractLinkPerson($actor[0]));
     }
 }