function testDeleteAndPutFile() { $STORAGE_SERVER_PATH = dirname(__FILE__) . "/../../"; $filePath = dirname(__FILE__) . "/ex1.mp3"; // Delete any old data from previous tests $md5 = md5_file($filePath); $duplicate = StoredFile::RecallByMd5($md5); if ($duplicate) { $duplicate->delete(); } // Test inserting a file by linking $values = array("filepath" => $filePath, "dc:description" => "Unit test " . time()); $storedFile = StoredFile::Insert($values, false); if (PEAR::isError($storedFile)) { $this->fail("Failed to create StoredFile: " . $storedFile->getMessage()); return; } //var_dump($storedFile); $id = $storedFile->getId(); if (!is_numeric($id)) { $this->fail("StoredFile not created correctly. id = " . $id); return; } // Test loading metadata $f = new StoredFile(); $f->__setGunid($storedFile->getGunid()); $f->loadMetadata(); if (!is_array($md = $f->getMetadata())) { $this->fail("Unable to load metadata."); return; } //var_dump($md); // Check if the length field has been set. $f2 = StoredFile::RecallByGunid($storedFile->getGunid()); $m2 = $f2->getMetadata(); if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") { $this->fail("Length not reporting correctly in metadata."); return; } }
public static function OutputToM3u(&$pl, $plac, $ind = '') { $gunid = $plac['attrs']['id']; $ac = StoredFile::RecallByGunid($gunid); if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $RADext = $ac->getFileExtension(); if (PEAR::isError($RADext)) { return $RADext; } return array('playlength' => $plac['attrs']['playlength'], 'title' => $plac['attrs']['title'], 'uri' => AC_URL_RELPATH . "{$gunid}.{$RADext}"); }
public static function convert2lspl(&$gb, &$tree, &$gunids, $parr, $ind = '') { extract($parr); $uri = $tree->attrs['src']->val; $gunid = isset($gunids[basename($uri)]) ? $gunids[basename($uri)] : NULL; $ind2 = $ind . INDCH; if ($tree->name != 'audio') { return PEAR::raiseError("SmilPlaylist::parse: audio tag expected"); } if (isset($tree->children[2])) { return PEAR::raiseError(sprintf("SmilPlaylist::parse: unexpected tag %s in tag audio", $tree->children[2]->name)); } $res = ''; $fadeIn = 0; $fadeOut = 0; foreach ($tree->children as $i => $ch) { $ch =& $tree->children[$i]; $r = SmilPlaylistAnimateElement::convert2lspl($gb, $ch, &$gunids, $parr, $ind2); if (PEAR::isError($r)) { return $r; } switch ($r['type']) { case "fadeIn": $fadeIn = $r['val']; break; case "fadeOut": $fadeOut = $r['val']; break; } } if ($fadeIn > 0 || $fadeOut > 0) { $fiGunid = StoredFile::CreateGunid(); $fadeIn = Playlist::secondsToPlaylistTime($fadeIn); $fadeOut = Playlist::secondsToPlaylistTime($fadeOut); $fInfo = "{$ind2}<fadeInfo id=\"{$fiGunid}\" fadeIn=\"{$fadeIn}\" fadeOut=\"{$fadeOut}\"/>\n"; } else { $fInfo = ''; } $plElGunid = StoredFile::CreateGunid(); $acGunid = $gunid; $type = 'audioClip'; if (preg_match("|\\.([a-zA-Z0-9]+)\$|", $uri, $va)) { switch (strtolower($ext = $va[1])) { case "lspl": case "xml": case "smil": case "m3u": $type = 'playlist'; $acId = $gb->bsImportPlaylistRaw($gunid, $aPath, $uri, $ext, $gunids, $subjid); if (PEAR::isError($acId)) { return $r; } //break; //break; default: $ac = StoredFile::RecallByGunid($gunid); if (is_null($ac) || PEAR::isError($ac)) { return $ac; } $r = $ac->md->getMetadataElement('dcterms:extent'); if (PEAR::isError($r)) { return $r; } $playlength = $r[0]['value']; } } $title = basename($tree->attrs['src']->val); $offset = Playlist::secondsToPlaylistTime($tree->attrs['begin']->val); $clipStart = Playlist::secondsToPlaylistTime($tree->attrs['clipStart']->val); $clipEnd = Playlist::secondsToPlaylistTime($tree->attrs['clipEnd']->val); $clipLength = Playlist::secondsToPlaylistTime($tree->attrs['clipLength']->val); $res = "{$ind}<playlistElement id=\"{$plElGunid}\" relativeOffset=\"{$offset}\" clipStart=\"{$clipStart}\" clipEnd=\"{$clipEnd}\" clipLength=\"{$clipLength}\">\n" . "{$ind2}<{$type} id=\"{$acGunid}\" playlength=\"{$playlength}\" title=\"{$title}\"/>\n" . $fInfo . "{$ind}</playlistElement>\n"; return $res; }
/** * Allows remote client to download requested media file. * * @return void * */ public function getMediaAction() { global $CC_CONFIG; // disable the view and the layout $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $api_key = $this->_getParam('api_key'); $download = "true" == $this->_getParam('download'); $logger = Logging::getLogger(); if (!in_array($api_key, $CC_CONFIG["apiKey"]) && is_null(Zend_Auth::getInstance()->getStorage()->read())) { header('HTTP/1.0 401 Unauthorized'); print 'You are not allowed to access this resource.'; $logger->info("401 Unauthorized"); return; } $filename = $this->_getParam("file"); $file_id = substr($filename, 0, strpos($filename, ".")); if (ctype_alnum($file_id) && strlen($file_id) == 32) { $media = StoredFile::RecallByGunid($file_id); if ($media != null && !PEAR::isError($media)) { $filepath = $media->getFilePath(); if (is_file($filepath)) { // possibly use fileinfo module here in the future. // http://www.php.net/manual/en/book.fileinfo.php $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext == "ogg") { header("Content-Type: audio/ogg"); } else { if ($ext == "mp3") { header("Content-Type: audio/mpeg"); } } if ($download) { //path_info breaks up a file path into seperate pieces of informaiton. //We just want the basename which is the file name with the path //information stripped away. We are using Content-Disposition to specify //to the browser what name the file should be saved as. // // By james.moon: // I'm removing pathinfo() since it strips away UTF-8 characters. // Using manualy parsing $full_path = $media->getPropelOrm()->getDbFilepath(); $file_base_name = strrchr($full_path, '/'); $file_base_name = substr($file_base_name, 1); header('Content-Disposition: attachment; filename="' . $file_base_name . '"'); } header("Content-Length: " . filesize($filepath)); // !! binary mode !! $fp = fopen($filepath, 'rb'); //We can have multiple levels of output buffering. Need to //keep looping until all have been disabled!!! //http://www.php.net/manual/en/function.ob-end-flush.php while (@ob_end_flush()) { } fpassthru($fp); fclose($fp); //make sure to exit here so that no other output is sent. exit; } else { $logger->err('Resource in database, but not in storage: "' . $filepath . '"'); } } else { $logger->err('$media != null && !PEAR::isError($media)'); } } else { $logger->err('ctype_alnum($file_id) && strlen($file_id) == 32'); } header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); $logger->info("404 Not Found"); return; }