예제 #1
0
 /**
  * Gets the Youtube url (virtual field)
  * @return string|null
  * @uses MeYoutube\Utility\Youtube::getUrl()
  */
 protected function _getYoutubeUrl()
 {
     if (empty($this->_properties['youtube_id'])) {
         return null;
     }
     return Youtube::getUrl($this->_properties['youtube_id']);
 }
예제 #2
0
 /**
  * Updates to 2.0.4-RC4 version
  * @return void
  * @uses MeYoutube\Utility\Youtube::getInfo()
  */
 public function to2v0v4vRC4()
 {
     $this->loadModel('MeYoutube.Videos');
     $videos = $this->Videos->find('all')->select(['id', 'youtube_id', 'duration', 'seconds'])->where(['OR' => ['duration' => '00:00', 'duration' => '', 'seconds' => 0]]);
     foreach ($videos as $video) {
         $data = \MeYoutube\Utility\Youtube::getInfo($video->youtube_id);
         $video->duration = $data['duration'];
         $video->seconds = $data['seconds'];
         $this->Videos->query()->update()->set(['duration' => $data['duration'], 'seconds' => $data['seconds']])->where(['id' => $video->id])->execute();
     }
 }
예제 #3
0
 /**
  * Adds video
  * @return \Cake\Network\Response|null|void
  * @uses MeYoutube\Utility\Youtube::getId()
  * @uses MeYoutube\Utility\Youtube::getInfo()
  * @uses MeYoutube\Utility\Youtube::getUrl()
  */
 public function add()
 {
     //If the address of a YouTube video has been specified
     if ($this->request->query('url') && $this->request->is('get')) {
         //Gets video ID and information
         $youtubeId = Youtube::getId($this->request->query('url'));
         $youtubeInfo = Youtube::getInfo($youtubeId);
         $youtubeUrl = Youtube::getUrl($youtubeId);
         if (!$youtubeId) {
             $this->Flash->error(__d('me_youtube', 'This is not a {0} video', 'YouTube'));
         } elseif (!$youtubeInfo || !$youtubeUrl) {
             $this->Flash->error(__d('me_youtube', 'Unable to retrieve video informations. Probably the video is private'));
         } else {
             $this->request->data = am(compact('youtubeId', 'youtubeUrl'), $youtubeInfo);
         }
     }
     $video = $this->Videos->newEntity();
     if ($this->request->is('post')) {
         //Only admins and managers can add videos on behalf of other users
         if (!$this->Auth->isGroup(['admin', 'manager'])) {
             $this->request->data('user_id', $this->Auth->user('id'));
         }
         $this->request->data['created'] = new Time($this->request->data('created'));
         $video = $this->Videos->patchEntity($video, $this->request->data);
         if ($this->Videos->save($video)) {
             $this->Flash->success(__d('me_cms', 'The operation has been performed correctly'));
             return $this->redirect(['action' => 'index']);
         } else {
             $this->Flash->error(__d('me_cms', 'The operation has not been performed correctly'));
         }
     }
     $this->set(compact('video'));
 }