Example #1
0
File: Video.php Project: zfury/cmf
 /**
  * Prepares all necessary data for converting video file and calls "executeConversion" method
  *
  * @param File $videoEntity
  * @param string $newExtension
  * @param int $bitrate
  * @return File
  */
 public function convertVideo(File $videoEntity, $newExtension = self::MP4_EXT, $bitrate = 300)
 {
     //With libav avconv installed
     $oldLocation = $videoEntity->getLocation();
     $videoEntity->setExtension($newExtension);
     $this->sm->get('doctrine.entitymanager.orm_default')->persist($videoEntity);
     $this->sm->get('doctrine.entitymanager.orm_default')->flush();
     $newLocation = $videoEntity->getLocation();
     $this->executeConversion($oldLocation, $newLocation, $bitrate);
     return $videoEntity;
 }
Example #2
0
File: Audio.php Project: zfury/cmf
 /**
  * Prepares all necessary data for converting audio file and calls "executeConversion" method
  *
  * @param File $audioEntity
  * @param string $newExtension
  * @return File
  */
 public function convertAudio(File $audioEntity, $newExtension = self::MP3_EXT)
 {
     //With libav avconv installed
     $oldLocation = $audioEntity->getLocation();
     $audioEntity->setExtension($newExtension);
     $this->sm->get('doctrine.entitymanager.orm_default')->persist($audioEntity);
     $this->sm->get('doctrine.entitymanager.orm_default')->flush();
     $newLocation = $audioEntity->getLocation();
     $this->executeConversion($oldLocation, $newLocation);
     return $audioEntity;
 }
Example #3
0
 public function setFile(File $toSave)
 {
     $permissionEngine = PermissionEngine::getInstance();
     if (!$permissionEngine->currentUserCanDo('uploadFile')) {
         return false;
     }
     $database = Database::getInstance();
     if (!$database->isConnected()) {
         return false;
     }
     $validator = new checkIfKnownMimeType();
     if (!$validator->validate($toSave->getMimeType())) {
         return false;
     }
     if (!is_readable($toSave->getLocation())) {
         return false;
     }
     $id = $database->escapeString($toSave->getID());
     $dateUploaded = $database->escapeString($toSave->getUploadedDate()->format('Y-m-d H:i:s'));
     $title = $database->escapeString(strip_tags($toSave->getTitle()));
     $mimeType = $database->escapeString($toSave->getMimeType());
     $size = $database->escapeString($toSave->getSize());
     $location = $database->escapeString($toSave->getLocation());
     $nodeID = $database->escapeString($toSave->getNodeID());
     $uploader = $database->escapeString($toSave->getUploaderID());
     $folder = $database->escapeString($toSave->getFolderID());
     $result = $database->updateTable('file', "uploaded='{$dateUploaded}', title='{$title}', mimeType='{$mimeType}', size={$size}, location='{$location}', nodeID={$nodeID}, uploader={$uploader}, folderID={$folder}", "fileID='{$id}'");
     if ($result === false) {
         return false;
     }
     return true;
 }
   public function test_file() {
	$file = new File("/my/location/for/the/file.html");
	$this->assertEqual("/my/location/for/the/file.html", $file->getLocation(), "the default location is \"/my/location/for/the/file.html\"");
	$file->setLocation("/location/two.css");
	$this->assertEqual("/location/two.css", $file->getLocation(), "the new location is \"/location/two.css\"");
   }