Beispiel #1
0
 /**
  * converts the video
  *
  * @return <type>
  */
 public function convertVideo()
 {
     // experimental
     if (!izapSupportedVideos_izap_videos($this->input_object)) {
         return elgg_echo('izap_videos:error:code:106');
     }
     $convert_video = new izapConvert($this->input_object);
     if ($convert_video->photo()) {
         if ($convert_video->izap_video_convert()) {
             return $convert_video->getValuesForAPI();
         }
     }
     // if nothing is processes so far
     return FALSE;
 }
Beispiel #2
0
 /**
  * Used to process the video file
  * @param string $file upload file name
  * @return object
  */
 protected function processFile($file)
 {
     $returnValue = new stdClass();
     $returnValue->type = 'uploaded';
     $fileName = $_FILES[$file['mainArray']]['name'][$file['fileName']];
     $error = $_FILES[$file['mainArray']]['error'][$file['fileName']];
     $tmpName = $_FILES[$file['mainArray']]['tmp_name'][$file['fileName']];
     $type = $_FILES[$file['mainArray']]['type'][$file['fileName']];
     $size = $_FILES[$file['mainArray']]['size'][$file['fileName']];
     // if error
     if ($error > 0) {
         return 104;
     }
     // if file is of zero size
     if ($size == 0) {
         return 105;
     }
     // check supported video type
     if (!izapSupportedVideos_izap_videos($fileName)) {
         return 106;
     }
     // check supported video size
     if (!izapCheckFileSize_izap_videos($size)) {
         return 107;
     }
     // upload the tmp file
     $newFileName = izapGetFriendlyFileName_izap_videos($fileName);
     $this->setFilename('tmp/' . $newFileName);
     $this->open("write");
     $this->write(file_get_contents($tmpName));
     $returnValue->tmpFile = $this->getFilenameOnFilestore();
     // take snapshot of the video
     $image = new izapConvert($returnValue->tmpFile);
     if ($image->photo()) {
         $retValues = $image->getValues(true);
         if ($retValues['imagename'] != '' && $retValues['imagecontent'] != '') {
             $this->setFilename('izap_videos/uploaded/' . $retValues['imagename']);
             $this->open("write");
             if ($this->write($retValues['imagecontent'])) {
                 $orignal_file_path = $this->getFilenameOnFilestore();
                 $thumb = get_resized_image_from_existing_file($orignal_file_path, 120, 90);
                 $this->setFilename('izap_videos/uploaded/' . $retValues['imagename']);
                 $this->open("write");
                 $this->write($thumb);
                 $this->close();
                 $returnValue->thumb = 'izap_videos/uploaded/' . $retValues['imagename'];
                 // Defining new preview attribute of standard object
                 $returnValue->preview_400 = 'izap_videos/uploaded/preview_400';
                 $returnValue->preview_200 = 'izap_videos/uploaded/preview_200';
             }
         }
     }
     // check if it is flv, then dont send it to queue
     if (izap_get_file_extension($returnValue->tmpFile) == 'flv') {
         $file_name = 'izap_videos/uploaded/' . $newFileName;
         $this->setFilename($file_name);
         $this->open("write");
         $this->write(file_get_contents($returnValue->tmpFile));
         $this->converted = 'yes';
         $this->videofile = $file_name;
         $this->orignalfile = $file_name;
         $returnValue->is_flv = 'yes';
         // remove the tmp file
         @unlink($returnValue->tmpFile);
     }
     return $returnValue;
 }
Beispiel #3
0
 /**
  * Process upload file
  * 
  * @param array  $file
  * 
  * @return mixed int if any error occured else array
  * 
  * @version 5.0
  */
 public function processFile($file)
 {
     $returnvalue = new stdClass();
     $filename = strtolower(str_replace(' ', '_', $file['name']));
     $tmpname = $file['tmp_name'];
     $file_err = $file['error'];
     $file_type = $file['type'];
     $file_size = $file['size'];
     if ($file_err > 0) {
         return 104;
     }
     // if file is of zero size
     if ($file_size == 0) {
         return 105;
     }
     $returnvalue->videotype = $file_type;
     $set_video_name = $this->getTmpPath(time() . $filename);
     $this->setFilename($set_video_name);
     $this->open("write");
     $this->write(file_get_contents($tmpname));
     $returnvalue->videofile = $this->getFilenameOnFilestore();
     // take snapshot from video
     if (IZAP_VIDEO_UNIT_TEST === True) {
         global $CONFIG;
         $returnvalue->videofile = $CONFIG->dataroot . 'test_video.avi';
         $image = new izapConvert($returnvalue->videofile);
     } else {
         $image = new izapConvert($returnvalue->videofile);
     }
     if ($image->get_thumbnail_from_video()) {
         $retValues = $image->getValues(TRUE);
         if ($retValues['imagename'] != '' && $retValues['imagecontent'] != '') {
             $set_original_thumbnail = $this->getTmpPath('original_' . $retValues['imagename']);
             $this->setFilename($set_original_thumbnail);
             $this->open("write");
             if ($this->write($retValues['imagecontent'])) {
                 if (IZAP_VIDEO_UNIT_TEST === True) {
                     $returnvalue->orignal_thumb = $CONFIG->dataroot . $retValues['imagename'];
                 } elseif ($this->write($retValues['imagecontent'])) {
                     $orignal_file_path = $this->getFilenameOnFilestore();
                     $thumb = get_resized_image_from_existing_file($orignal_file_path, 650, 500);
                     $set_thumb = $this->getTmpPath($retValues['imagename']);
                     $this->setFilename($set_thumb);
                     $this->open("write");
                     $this->write($thumb);
                     // $this->close();
                     $returnvalue->orignal_thumb = $set_original_thumbnail;
                     $returnvalue->thumb = $set_thumb;
                 }
             }
         }
     }
     return $returnvalue;
 }
Beispiel #4
0
/**
 * Check file existance and send for conversion
 * 
 * @param string  $file
 * @param integer $videoId
 * @param string  $videoTitle
 * @param string  $videoUrl
 * @param integer $ownerGuid
 * @param integer $accessId
 * 
 * @return mixed  string if video converted successfully, array if video not converted successfully
 * 
 * @version 5.0
 */
function izap_convert_video_izap_videos($file, $videoId, $videoTitle, $videoUrl, $ownerGuid, $accessId = 2)
{
    if (file_exists($file)) {
        $queue_object = new izapQueue();
        $video = new izapConvert($file);
        $videofile = $video->izap_video_convert();
        //if file converted successfully then change flag from pending to processed
        if (!is_array($videofile)) {
            $queue_object->change_conversion_flag($videoId);
            return $videofile;
        } else {
            $err_message = $videofile['message'];
        }
    } else {
        $err_message = elgg_echo('izap_videos:file not found');
    }
    if (isset($err_message)) {
        $return = array('error' => true, 'message' => $err_message);
    }
    return $return;
}
Beispiel #5
0
/**
 * This function actually converts the video
 * @param string $file file loacation
 * @param int $videoId video guid
 * @param int $ownerGuid video owner guid
 * @param int $accessId access id
 * @return boolean
 */
function izapConvertVideo_izap_videos($file, $videoId, $videoTitle, $videoUrl, $ownerGuid, $accessId = 2)
{
    $return = false;
    // Works only if we have the input file
    if (file_exists($file)) {
        // Need to set flag for the file going in the conversion
        $queue_object = new izapQueue();
        $queue_object->change_conversion_flag($videoId);
        $video = new izapConvert($file);
        $videofile = $video->izap_video_convert();
        // Check if everything is ok
        if (!is_array($videofile)) {
            // If everything is ok then get back values to save
            $file_values = $video->getValues();
            $izap_videofile = 'izap_videos/uploaded/' . $file_values['filename'];
            $izap_origfile = 'izap_videos/uploaded/' . $file_values['origname'];
            $izap_videos = get_entity($videoId);
            $izap_videos->setFilename($izap_videofile);
            $izap_videos->open("write");
            $izap_videos->write($file_values['filecontent']);
            // Check if we have to keep original file
            if (izapAdminSettings_izap_videos('izapKeepOriginal') == 'YES') {
                $izap_videos->setFilename($izap_origfile);
                $izap_videos->open("write");
                $izap_videos->write($file_values['origcontent']);
            }
            $izap_videos->converted = 'yes';
            $izap_videos->videofile = $izap_videofile;
            $izap_videos->orignalfile = $izap_origfile;
            notify_user($ownerGuid, elgg_get_site_entity()->getGUID(), elgg_echo('izap_videos:notifySub:videoConverted'), elgg_echo('izap_videos:notifyMsg:videoConverted', array($videoUrl)));
            return true;
        } else {
            $errorReason = $videofile['message'];
        }
    } else {
        $errorReason = elgg_echo('izap_videos:fileNotFound');
    }
    $adminGuid = izapGetSiteAdmin_izap_videos(true);
    // notify admin
    notify_user($adminGuid, elgg_get_site_entity()->getGUID(), elgg_echo('izap_videos:notifySub:videoNotConverted'), elgg_echo('izap_videos:notifyAdminMsg:videoNotConverted', array($errorReason)));
    if (!empty($errorReason)) {
        $return = array('error' => true, 'reason' => $errorReason);
    }
    return $return;
}
Beispiel #6
0
/**
 * this fucntion actually converts the video
 * @param string $file file loacation
 * @param int $videoId video guid
 * @param int $ownerGuid video owner guid
 * @param int $accessId access id
 * @return boolean
 */
function izapConvertVideo_izap_videos($file, $videoId, $videoTitle, $videoUrl, $ownerGuid, $accessId = 2)
{
    global $CONFIG;
    $return = FALSE;
    // works only if we have the input file
    if (file_exists($file)) {
        // now convert video
        //
        // Need to set flag for the file going in the conversion.
        $queue_object = new izapQueue();
        $queue_object->change_conversion_flag($videoId);
        $video = new izapConvert($file);
        $videofile = $video->izap_video_convert();
        // check if every this is ok
        if (!is_array($videofile)) {
            // if every thing is ok then get back values to save
            $file_values = $video->getValues();
            $izap_videofile = 'izap_videos/uploaded/' . $file_values['filename'];
            $izap_origfile = 'izap_videos/uploaded/' . $file_values['origname'];
            $izap_videos = new IzapVideos($videoId);
            $izap_videos->setFilename($izap_videofile);
            $izap_videos->open("write");
            $izap_videos->write($file_values['filecontent']);
            //check if you do not want to keep original file
            if (get_plugin_setting('izapKeepOriginal', GLOBAL_IZAP_VIDEOS_PLUGIN) == 'YES') {
                $izap_videos->setFilename($izap_origfile);
                $izap_videos->open("write");
                $izap_videos->write($file_values['origcontent']);
            }
            $izap_videos->converted = 'yes';
            $izap_videos->videofile = $izap_videofile;
            $izap_videos->orignalfile = $izap_origfile;
            notify_user($ownerGuid, $CONFIG->site_guid, elgg_echo('izap_videos:notifySub:videoConverted'), sprintf(elgg_echo('izap_videos:notifyMsg:videoConverted'), $izap_videos->getUrl()));
            return true;
        } else {
            $errorReason = $videofile['message'];
        }
    } else {
        $errorReason = elgg_echo('izap_videos:fileNotFound');
    }
    $adminGuid = izapGetSiteAdmin_izap_videos(TRUE);
    // notify admin
    notify_user($adminGuid, $CONFIG->site_guid, elgg_echo('izap_videos:notifySub:videoNotConverted'), sprintf(elgg_echo('izap_videos:notifyAdminMsg:videoNotConverted'), $errorReason));
    if (!empty($errorReason)) {
        $return = array('error' => TRUE, 'reason' => $errorReason);
    }
    return $return;
}