public function upload(UploadEvent $event)
 {
     set_time_limit(max(100, ini_get('max_execution_time')));
     if (!$event->getUrl()) {
         #some other uploader has already taken care of it?
         if ($data = $event->getEventData()) {
             if ($file = @$data['file']) {
                 if (file_exists($file)) {
                     $app = App::getInstance();
                     $user_id = $event->getUserId();
                     if ($youtubeConfig = $app->config->getKey('private/api_keys/youtube')) {
                         if (!empty($youtubeConfig['token'])) {
                             if ($user_id > 0 || !empty($youtubeConfig['anonymous_uploads'])) {
                                 try {
                                     if ($userToken = UserManager::getInstance()->getUserData($user_id, 'youtube')) {
                                         try {
                                             $uploader = 'local';
                                             $url = $this->uploadVideo($file, $userToken, $refreshToken);
                                         } catch (Exception $e) {
                                         }
                                     }
                                     if (empty($url)) {
                                         $uploader = 'global';
                                         $url = $this->uploadVideo($file, $youtubeConfig['token'], $refreshToken);
                                     }
                                     if (!empty($refreshToken) && !empty($uploader)) {
                                         if ($uploader === 'global') {
                                             $app->config->setKey('private/api_keys/youtube/token', $refreshToken);
                                         } elseif ($uploader === 'local') {
                                             UserManager::getInstance()->setUserData($user_id, ['youtube' => $refreshToken]);
                                         }
                                     }
                                     if (!empty($url)) {
                                         $event->setUrl($url);
                                     } else {
                                         throw new UploadError("Error uploading video: No url returned");
                                     }
                                 } catch (Exception $e) {
                                     throw new UploadError("Error uploading video: " . $e->getMessage(), $e);
                                 }
                             } else {
                                 throw new LoginError("You must be logged in to upload.", $user_id);
                             }
                         } else {
                             throw new UploadError("Youtube configuration is incomplete.", $youtubeConfig);
                         }
                     } else {
                         throw new UploadError("Youtube configuration is empty");
                     }
                 } else {
                     throw new UploadError("Upload file is missing");
                 }
             } else {
                 throw new UploadError("Upload data is empty");
             }
         }
     }
 }
Beispiel #2
0
 function __construct()
 {
     ArList::$has_many = [['sqls', 'foreign_key' => 'ar_list_id', 'class_name' => 'ArListSql']];
     $this->userClass = UserManager::getInstance()->getUserModelClass();
 }
Beispiel #3
0
 /**
  * @param null $user
  *
  * @return int
  * @throws \Minute\Errors\ConfigError
  */
 private function getVideoCredits($user = null)
 {
     $level = $this->getUserVideoLevel();
     return UserManager::getInstance()->getCredits($user, $level);
 }