예제 #1
0
 /**
  * Prepare data to create/update banner
  *
  * @return multitype:string |multitype:\Fennec\Model\string \Fennec\Model\integer
  */
 private function prepare()
 {
     $errors = $this->validate();
     if (!$errors['valid']) {
         return $errors;
     }
     $this->title = filter_var($this->title, \FILTER_SANITIZE_STRING);
     $this->startdate = filter_var($this->startdate, \FILTER_SANITIZE_STRING);
     $this->enddate = $this->enddate ? filter_var($this->enddate, \FILTER_SANITIZE_STRING) : null;
     $this->url = filter_var($this->url, \FILTER_SANITIZE_STRING);
     if (isset($_FILES['image']) && !empty($_FILES['image']['name'])) {
         $this->image = uniqid('banner') . '.png';
         $image = ImageWorkshop::initFromPath($_FILES['image']['tmp_name']);
         $image->save(self::UPLOAD_DIR, $this->image, true);
     } elseif ($this->id) {
         $banner = $this->getByColumn('id', $this->id)[0];
         $this->image = $banner->image;
     }
     $result = array('title' => $this->title, 'startdate' => $this->startdate, 'url' => $this->url, 'image' => $this->image);
     if ($this->enddate) {
         $result['enddate'] = $this->enddate;
     } elseif ($this->id && !$this->enddate) {
         $result['enddate'] = null;
     }
     return $result;
 }
예제 #2
0
 /**
  * Prepare data to create/update video
  *
  * @return multitype:string |multitype:\Fennec\Model\string \Fennec\Model\integer
  */
 private function prepare()
 {
     $errors = $this->validate();
     if (!$errors['valid']) {
         return $errors;
     }
     $this->title = filter_var($this->title, \FILTER_SANITIZE_STRING);
     $this->description = filter_var($this->description, \FILTER_SANITIZE_STRING);
     $videoInfo = self::parseVideoUrl($this->url);
     $this->videosource = $videoInfo['source'];
     $this->videoid = $videoInfo['id'];
     switch ($this->videosource) {
         case 'youtube':
             $this->image = "video-{$this->videoid}.png";
             $ch = curl_init("http://img.youtube.com/vi/{$this->videoid}/0.jpg");
             curl_setopt($ch, \CURLOPT_SSL_VERIFYPEER, 0);
             curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1);
             $image = curl_exec($ch);
             $image = ImageWorkshop::initFromString($image);
             $image->save(self::UPLOAD_DIR, $this->image, true);
             break;
     }
     $result = array('title' => $this->title, 'videoid' => $this->videoid, 'videosource' => $this->videosource, 'description' => $this->description, 'image' => $this->image);
     return $result;
 }