|
@@ -0,0 +1,268 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace AppBundle\Entity;
|
|
|
+
|
|
|
+use Doctrine\ORM\Mapping as ORM;
|
|
|
+use Symfony\Component\Validator\Constraints as Assert;
|
|
|
+
|
|
|
+
|
|
|
+ * MediaVideo
|
|
|
+ *
|
|
|
+ * @ORM\Table(name="media_video")
|
|
|
+ * @ORM\Entity(repositoryClass="AppBundle\Repository\MediaVideoRepository")
|
|
|
+ * @ORM\HasLifecycleCallbacks
|
|
|
+ */
|
|
|
+class MediaVideo
|
|
|
+{
|
|
|
+
|
|
|
+ * @var int
|
|
|
+ *
|
|
|
+ * @ORM\Column(name="id", type="integer")
|
|
|
+ * @ORM\Id
|
|
|
+ * @ORM\GeneratedValue(strategy="AUTO")
|
|
|
+ */
|
|
|
+ private $id;
|
|
|
+
|
|
|
+
|
|
|
+ * @var string
|
|
|
+ *
|
|
|
+ * @ORM\Column(name="type", type="string", length=255)
|
|
|
+ */
|
|
|
+ private $type;
|
|
|
+
|
|
|
+
|
|
|
+ * @var string
|
|
|
+ *
|
|
|
+ * @ORM\Column(name="identif", type="string", length=255)
|
|
|
+ */
|
|
|
+ private $identif;
|
|
|
+
|
|
|
+
|
|
|
+ * @var \DateTime
|
|
|
+ *
|
|
|
+ * @ORM\Column(name="date", type="datetime")
|
|
|
+ */
|
|
|
+ private $date;
|
|
|
+
|
|
|
+
|
|
|
+ * @Assert\Regex(
|
|
|
+ * pattern="#^(http|https)://(www.youtube.com|www.dailymotion.com|vimeo.com)/#",
|
|
|
+ * match=true,
|
|
|
+ * message="L'url doit correspondre à l'url d'une vidéo Youtube, DailyMotion ou Vimeo"
|
|
|
+ * )
|
|
|
+ */
|
|
|
+ private $url;
|
|
|
+
|
|
|
+
|
|
|
+ * Constructor
|
|
|
+ */
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->setDate(new \DateTime());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @return \DateTime
|
|
|
+ */
|
|
|
+ public function getDate()
|
|
|
+ {
|
|
|
+ return $this->date;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param \DateTime $date
|
|
|
+ */
|
|
|
+ public function setDate($date)
|
|
|
+ {
|
|
|
+ $this->date = $date;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Get id
|
|
|
+ *
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function getId()
|
|
|
+ {
|
|
|
+ return $this->id;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @return string
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function getUrl()
|
|
|
+ {
|
|
|
+ return $this->url;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setUrl($url)
|
|
|
+ {
|
|
|
+ return $this->url = $url;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Set type
|
|
|
+ *
|
|
|
+ * @param string $type
|
|
|
+ *
|
|
|
+ * @return MediaVideo
|
|
|
+ */
|
|
|
+ public function setType($type)
|
|
|
+ {
|
|
|
+ $this->type = $type;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Get type
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getType()
|
|
|
+ {
|
|
|
+ return $this->type;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Set identif
|
|
|
+ *
|
|
|
+ * @param string $identif
|
|
|
+ *
|
|
|
+ * @return MediaVideo
|
|
|
+ */
|
|
|
+ public function setIdentif($identif)
|
|
|
+ {
|
|
|
+ $this->identif = $identif;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Get identif
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getIdentif()
|
|
|
+ {
|
|
|
+ return $this->identif;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private function youtubeId($url)
|
|
|
+ {
|
|
|
+ $tableaux = explode("=", $url);
|
|
|
+
|
|
|
+ $this->setIdentif($tableaux[1]);
|
|
|
+ $this->setType('youtube');
|
|
|
+ }
|
|
|
+
|
|
|
+ private function dailymotionId($url)
|
|
|
+ {
|
|
|
+ $cas = explode("/", $url);
|
|
|
+ $idb = $cas[4];
|
|
|
+ $bp = explode("_", $idb);
|
|
|
+ $id = $bp[0];
|
|
|
+
|
|
|
+ $this->setIdentif($id);
|
|
|
+ $this->setType('dailymotion');
|
|
|
+ }
|
|
|
+
|
|
|
+ private function vimeoId($url)
|
|
|
+ {
|
|
|
+ $tableaux = explode("/", $url);
|
|
|
+ $id = $tableaux[count($tableaux)-1];
|
|
|
+ $this->setIdentif($id);
|
|
|
+ $this->setType('vimeo');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @ORM\PrePersist()
|
|
|
+ * @ORM\PreUpdate()
|
|
|
+ * @ORM\PreFlush()
|
|
|
+ */
|
|
|
+ public function extractIdentif()
|
|
|
+ {
|
|
|
+ $url = $this->getUrl();
|
|
|
+
|
|
|
+ if (preg_match("#^(http|https)://www.youtube.com/#", $url))
|
|
|
+ {
|
|
|
+ $this->youtubeId($url);
|
|
|
+ }
|
|
|
+ else if((preg_match("#^(http|https)://www.dailymotion.com/#", $url)))
|
|
|
+ {
|
|
|
+ $this->dailymotionId($url);
|
|
|
+ }
|
|
|
+ else if((preg_match("#^(http|https)://vimeo.com/#", $url)))
|
|
|
+ {
|
|
|
+ $this->vimeoId($url);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private function embedUrl()
|
|
|
+ {
|
|
|
+ $control = $this->getType();
|
|
|
+ $id = strip_tags($this->getIdentif());
|
|
|
+
|
|
|
+ if ($control == 'youtube') {
|
|
|
+ $embed = "https://www.youtube-nocookie.com/embed/" . $id;
|
|
|
+ return $embed;
|
|
|
+ } else if ($control == 'dailymotion') {
|
|
|
+ $embed = "https://www.dailymotion.com/embed/video/" . $id;
|
|
|
+ return $embed;
|
|
|
+ } else if ($control == 'vimeo') {
|
|
|
+ $embed = "https://player.vimeo.com/video/" . $id;
|
|
|
+ return $embed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function url()
|
|
|
+ {
|
|
|
+ $control = $this->getType();
|
|
|
+ $id = strip_tags($this->getIdentif());
|
|
|
+
|
|
|
+ if ($control == 'youtube') {
|
|
|
+ $embed = "https://www.youtube.com/watch?v=" . $id;
|
|
|
+ return $embed;
|
|
|
+ } else if ($control == 'dailymotion') {
|
|
|
+ $embed = "https://www.dailymotion.com/video/" . $id;
|
|
|
+ return $embed;
|
|
|
+ } else if ($control == 'vimeo') {
|
|
|
+ $embed = "https://vimeo.com/" . $id;
|
|
|
+ return $embed;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function image()
|
|
|
+ {
|
|
|
+ $control = $this->getType();
|
|
|
+ $id = strip_tags($this->getIdentif());
|
|
|
+
|
|
|
+ if ($control == 'youtube') {
|
|
|
+ $image = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jpg';
|
|
|
+ return $image;
|
|
|
+ } else if ($control == 'dailymotion') {
|
|
|
+ $image = 'https://www.dailymotion.com/thumbnail/150x120/video/' . $id . '';
|
|
|
+ return $image;
|
|
|
+ } else if ($control == 'vimeo') {
|
|
|
+ $hash = unserialize(file_get_contents("https://vimeo.com/api/v2/video/" . $id . ".php"));
|
|
|
+ $image = $hash[0]['thumbnail_small'];
|
|
|
+ return $image;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function video()
|
|
|
+ {
|
|
|
+ $video = "<iframe width='100%' height='100%' src='".$this->embedUrl()."' frameborder='0' allowfullscreen></iframe>";
|
|
|
+ return $video;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|