diff --git a/campcaster/src/modules/archiveServer/var/Archive.php b/campcaster/src/modules/archiveServer/var/Archive.php index ea586a4ee..f18b16ef1 100644 --- a/campcaster/src/modules/archiveServer/var/Archive.php +++ b/campcaster/src/modules/archiveServer/var/Archive.php @@ -89,12 +89,18 @@ class Archive extends XR_LocStor { if (PEAR::isError($parid)) { return $parid; } - $res = $this->bsPutFile($parid, $pars['name'], - $fname, $mdfname, - $pars['gunid'], 'audioclip', 'file'); - if (PEAR::isError($res)) { - return $res; + $values = array( + "filename" => $pars['name'], + "filepath" => $fname, + "metadata" => $mdfname, + "gunid" => $pars['gunid'], + "filetype" => "audioclip" + ); + $storedFile = $this->bsPutFile($parid, $values); + if (PEAR::isError($storedFile)) { + return $storedFile; } + $res = $storedFile->getId(); @unlink($fname); @unlink($mdfname); break; @@ -106,12 +112,17 @@ class Archive extends XR_LocStor { if (PEAR::isError($parid)) { return $parid; } - $res = $this->bsPutFile($parid, $pars['name'], - '', $fname, - $pars['gunid'], 'playlist', 'file'); - if (PEAR::isError($res)) { - return $res; + $values = array( + "filename" => $pars['name'], + "metadata" => $fname, + "gunid" => $pars['gunid'], + "filetype" => "playlist" + ); + $storedFile = $this->bsPutFile($parid, $values); + if (PEAR::isError($storedFile)) { + return $storedFile; } + $res = $storedFile->getId(); @unlink($fname); break; case "playlistPkg": diff --git a/campcaster/src/modules/htmlUI/var/Input.php b/campcaster/src/modules/htmlUI/var/Input.php new file mode 100644 index 000000000..a1b3ceab7 --- /dev/null +++ b/campcaster/src/modules/htmlUI/var/Input.php @@ -0,0 +1,187 @@ + $value) { + $decodedKey = stripslashes($key); + if (is_array($value)) { + $decodedValue = Input::CleanMagicQuotes($value); + } else { + $decodedValue = stripslashes($value); + } + $gpcList[$decodedKey] = $decodedValue; + } + return $gpcList; + } // fn CleanMagicQuotes + + + /** + * Get an input value from the $_REQUEST array and check its type. + * The default value is returned if the value is not defined in the + * $_REQUEST array, or if the value does not match the required type. + * + * The type 'checkbox' is special - you cannot specify a default + * value for this. The return value will be TRUE or FALSE, but + * you can change this by specifying 'numeric' as the 3rd parameter + * in which case it will return '1' or '0'. + * + * Use Input::IsValid() to check if any errors were generated. + * + * @param string $p_varName + * The index into the $_REQUEST array. + * + * @param string $p_type + * The type of data expected; can be: + * "int" + * "string" + * "array" + * "checkbox" + * "boolean" + * + * Default is 'string'. + * + * @param mixed $p_defaultValue + * The default value to return if the value is not defined in + * the $_REQUEST array, or if the value does not match + * the required type. + * + * @param boolean $p_errorsOk + * Set to true to ignore any errors for this variable (i.e. + * Input::IsValid() will still return true even if there + * are errors for this varaible). + * + * @return mixed + */ + function Get($p_varName, $p_type = 'string', $p_defaultValue = null, $p_errorsOk = false) + { + global $g_inputErrors; + $p_type = strtolower($p_type); + + if ($p_type == 'checkbox') { + if (strtolower($p_defaultValue) != 'numeric') { + return isset($_REQUEST[$p_varName]); + } else { + return isset($_REQUEST[$p_varName]) ? '1' : '0'; + } + } + if (!isset($_REQUEST[$p_varName])) { + if (!$p_errorsOk) { + $g_inputErrors[$p_varName] = 'not set'; + } + return $p_defaultValue; + } + // Clean the slashes + if (get_magic_quotes_gpc()) { + if (is_array($_REQUEST[$p_varName])) { + $_REQUEST[$p_varName] = Input::CleanMagicQuotes($_REQUEST[$p_varName]); + } else { + $_REQUEST[$p_varName] = stripslashes($_REQUEST[$p_varName]); + } + } + switch ($p_type) { + case 'boolean': + $value = strtolower($_REQUEST[$p_varName]); + if ( ($value == "true") || (is_numeric($value) && ($value > 0)) ) { + return true; + } else { + return false; + } + break; + case 'int': + if (!is_numeric($_REQUEST[$p_varName])) { + if (!$p_errorsOk) { + $g_inputErrors[$p_varName] = 'Incorrect type. Expected type '.$p_type + .', but received type '.gettype($_REQUEST[$p_varName]).'.' + .' Value is "'.$_REQUEST[$p_varName].'".'; + } + return $p_defaultValue; + } + break; + case 'string': + if (!is_string($_REQUEST[$p_varName])) { + if (!$p_errorsOk) { + $g_inputErrors[$p_varName] = 'Incorrect type. Expected type '.$p_type + .', but received type '.gettype($_REQUEST[$p_varName]).'.' + .' Value is "'.$_REQUEST[$p_varName].'".'; + } + return $p_defaultValue; + } + break; + case 'array': + if (!is_array($_REQUEST[$p_varName])) { + // Create an array if it isnt one already. + // Arrays are used with checkboxes and radio buttons. + // The problem with them is that if there is only one + // checkbox, the given value will not be an array. So + // we make it easy for the programmer by always returning + // an array. + $newArray = array(); + $newArray[] = $_REQUEST[$p_varName]; + return $newArray; +// if (!$p_errorsOk) { +// $g_inputErrors[$p_varName] = 'Incorrect type. Expected type '.$p_type +// .', but received type '.gettype($_REQUEST[$p_varName]).'.' +// .' Value is "'.$_REQUEST[$p_varName].'".'; +// } +// return $p_defaultValue; + } + } + return $_REQUEST[$p_varName]; + } // fn get + + + /** + * Return FALSE if any calls to Input::Get() resulted in an error. + * @return boolean + */ + function IsValid() + { + global $g_inputErrors; + if (count($g_inputErrors) > 0) { + return false; + } else { + return true; + } + } // fn isValid + + + /** + * Return a default error string. + * @return string + */ + function GetErrorString() + { + global $g_inputErrors; + ob_start(); + print_r($g_inputErrors); + $str = ob_get_clean(); + return $str; + } // fn GetErrorString + +} // class Input + +?> \ No newline at end of file diff --git a/campcaster/src/modules/htmlUI/var/formmask/metadata.inc.php b/campcaster/src/modules/htmlUI/var/formmask/metadata.inc.php index 3753aae02..46e77e001 100644 --- a/campcaster/src/modules/htmlUI/var/formmask/metadata.inc.php +++ b/campcaster/src/modules/htmlUI/var/formmask/metadata.inc.php @@ -82,7 +82,7 @@ $mask = array( 'element' => 'dc:type', 'type' => 'text', 'label' => 'Genre', - 'required' => TRUE, + 'required' => FALSE, 'id3' => array('Genre') ), array( diff --git a/campcaster/src/modules/htmlUI/var/html/ui_handler.php b/campcaster/src/modules/htmlUI/var/html/ui_handler.php index b37b14c60..5c8e0af62 100644 --- a/campcaster/src/modules/htmlUI/var/html/ui_handler.php +++ b/campcaster/src/modules/htmlUI/var/html/ui_handler.php @@ -1,5 +1,10 @@ PLAYLIST->addItem($_REQUEST['id'], $_REQUEST['playlength']) !== FALSE) { $uiHandler->SCRATCHPAD->addItem($_REQUEST['id']); } diff --git a/campcaster/src/modules/htmlUI/var/templates/file/edit.tpl b/campcaster/src/modules/htmlUI/var/templates/file/edit.tpl index eec944051..8e18e55db 100644 --- a/campcaster/src/modules/htmlUI/var/templates/file/edit.tpl +++ b/campcaster/src/modules/htmlUI/var/templates/file/edit.tpl @@ -5,7 +5,7 @@

- {if $_REQUEST.act == addFileData || $_REQUEST.act == addFileMData || $_REQUEST.act == addWebstreamData || $_REQUEST.act == addWebstreamMData} + {if $_REQUEST.act == addFileData || $_REQUEST.act == addWebstreamData || $_REQUEST.act == addWebstreamMData} ##New## {else} ##Edit## @@ -21,7 +21,7 @@ {assign var="_uploadform" value=null} {/if}

- +
{include file="file/metadataform.tpl"}
diff --git a/campcaster/src/modules/htmlUI/var/ui_base.inc.php b/campcaster/src/modules/htmlUI/var/ui_base.inc.php index 14e523cc8..faae0caad 100644 --- a/campcaster/src/modules/htmlUI/var/ui_base.inc.php +++ b/campcaster/src/modules/htmlUI/var/ui_base.inc.php @@ -514,6 +514,9 @@ class uiBase public function getMetadataValue($id, $key, $langid=NULL, $deflangid=UI_DEFAULT_LANGID) { + if (!is_numeric($id)) { + return null; + } if (!$langid) { $langid = $_SESSION['langid']; } @@ -527,9 +530,9 @@ class uiBase if (!$langid) { $langid = UI_DEFAULT_LANGID; } - if (ini_get('magic_quotes_gpc')) { - $value = str_replace("\'", "'", $value); - } +// if (ini_get('magic_quotes_gpc')) { +// $value = str_replace("\'", "'", $value); +// } if ($this->gb->setMetadataValue($id, $key, $this->sessid, $value, $langid)) { return TRUE; diff --git a/campcaster/src/modules/htmlUI/var/ui_browser.class.php b/campcaster/src/modules/htmlUI/var/ui_browser.class.php index 33bfe0cdb..702f3a426 100644 --- a/campcaster/src/modules/htmlUI/var/ui_browser.class.php +++ b/campcaster/src/modules/htmlUI/var/ui_browser.class.php @@ -122,7 +122,6 @@ class uiBrowser extends uiBase { $data['listdata'][$key]['title'] = $val['name']; } } - #print_r($data); return $data; } // fn getStructure @@ -250,7 +249,7 @@ class uiBrowser extends uiBase { */ function getMdata($id) { - return ($this->gb->getMdata($id, $this->sessid)); + return ($this->gb->getMetadata($id, $this->sessid)); } // getMdata @@ -268,7 +267,7 @@ class uiBrowser extends uiBase { include dirname(__FILE__).'/formmask/mdata_relations.inc.php'; } - $mdata = $this->gb->getMDataArray($id, $this->sessid); + $mdata = $this->gb->getMetadataArray($id, $this->sessid); if (!is_array($mdata)) { return FALSE; } @@ -304,7 +303,7 @@ class uiBrowser extends uiBase { */ function metaDataForm($parms) { - include dirname(__FILE__).'/formmask/metadata.inc.php'; + include(dirname(__FILE__).'/formmask/metadata.inc.php'); extract($parms); $langid = $langid ? $langid : UI_DEFAULT_LANGID; @@ -321,8 +320,7 @@ class uiBrowser extends uiBase { $form->setConstants(array('act' => 'editMetaData', 'id' => $id, 'curr_langid' => $langid, - ) - ); + )); // Convert element names to be unique over different forms-parts, // add javascript to spread values over parts, add existing @@ -332,9 +330,9 @@ class uiBrowser extends uiBase { if (!is_array($mask['pages'][$key][$k]['attributes'])) { $mask['pages'][$key][$k]['attributes'] = array(); } - $mask['pages'][$key][$k]['element'] = $key.'___'.uiBase::formElementEncode($v['element']); + $mask['pages'][$key][$k]['element'] = $key.'___'.uiBase::formElementEncode($v['element']); $mask['pages'][$key][$k]['attributes'] = array_merge($mask['pages'][$key][$k]['attributes'], array('onChange' => "spread(this, '".uiBase::formElementEncode($v['element'])."')")); - ## load data from GreenBox + // load data from GreenBox if ($getval = $this->getMetadataValue($id, $v['element'], $langid, NULL)) { $mask['pages'][$key][$k]['default'] = $getval; $mask['pages'][$key][$k]['attributes']['onFocus'] = 'MData_confirmChange(this)'; diff --git a/campcaster/src/modules/htmlUI/var/ui_handler.class.php b/campcaster/src/modules/htmlUI/var/ui_handler.class.php index a2fa14b8a..6db6a93a7 100644 --- a/campcaster/src/modules/htmlUI/var/ui_handler.class.php +++ b/campcaster/src/modules/htmlUI/var/ui_handler.class.php @@ -35,6 +35,9 @@ class uiHandler extends uiBase { /** * Login to the storageServer. * It set sessid to the cookie with name defined in ../conf.php + * + * @param array $formdata + * The REQUEST array. */ function login($formdata, $mask) { @@ -114,7 +117,7 @@ class uiHandler extends uiBase { function uploadFile($formdata, $mask, $replace=NULL) { global $CC_CONFIG; - if ($this->test4audioType($formdata['mediafile']['name']) === FALSE) { + if ($this->testForAudioType($formdata['mediafile']['name']) === FALSE) { if (UI_ERROR) { $this->_retMsg('"$1" uses an unsupported file type.', $formdata['mediafile']['name']); } @@ -139,9 +142,16 @@ class uiHandler extends uiBase { $md5 = md5_file($formdata['mediafile']['tmp_name']); $duplicate = StoredFile::RecallByMd5($md5); if ($duplicate) { - $this->_retMsg('The file "'.basename($formdata['mediafile']['name']).'" already exists in the database.'); - $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; - return FALSE; + if (PEAR::isError($duplicate)) { + $this->_retMsg($duplicate->getMessage()); + $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; + return FALSE; + } else { + $duplicate->delete(); +// $this->_retMsg('The file "'.basename($formdata['mediafile']['name']).'" already exists in the database.'); +// $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; +// return FALSE; + } } $metadata = camp_get_audio_metadata($formdata['mediafile']['tmp_name']); @@ -150,43 +160,42 @@ class uiHandler extends uiBase { $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; return FALSE; } + // bsSetMetadataBatch doesnt like these values + unset($metadata['audio']); + unset($metadata['playtime_seconds']); $tmpgunid = md5(microtime().$_SERVER['SERVER_ADDR'].rand()."org.mdlf.campcaster"); $ntmp = $CC_CONFIG['bufferDir'].'/'.$tmpgunid; move_uploaded_file($formdata['mediafile']['tmp_name'], $ntmp); chmod($ntmp, 0664); -// echo "buffer dir: ".$CC_CONFIG['bufferDir']."
"; -// echo "$ntmp
"; -// print_r($formdata); -// exit; - $r = $this->gb->putFile($folderId, $formdata['mediafile']['name'], $ntmp, NULL, $this->sessid, $replace); + $values = array( + "filename" => $formdata['mediafile']['name'], + "filepath" => $ntmp, + "filetype" => "audioclip", + "mime" => $metadata["dc:format"], + "md5" => $md5 + ); + $storedFile = $this->gb->putFile($folderId, $values, $this->sessid); @unlink($ntmp); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); + if (PEAR::isError($storedFile)) { + $this->_retMsg($storedFile->getMessage()); $this->redirUrl = UI_BROWSER."?act=editFile&id=".$id; return FALSE; } - $this->setMetadataValue($r, UI_MDATA_KEY_TITLE, $formdata['mediafile']['name']); - $this->translateMetadata($r); + $result = $this->gb->bsSetMetadataBatch($storedFile->getId(), $metadata); - // set records in default language too - if (UI_UPLOAD_LANGID !== UI_DEFAULT_LANGID) { - $this->setMetadataValue($r, UI_MDATA_KEY_TITLE, $formdata['mediafile']['name'], UI_UPLOAD_LANGID); - $this->translateMetadata($r, UI_UPLOAD_LANGID); - } - - $this->redirUrl = UI_BROWSER."?act=addFileMData&id=$r"; + $this->redirUrl = UI_BROWSER."?act=addFileMData&id=".$storedFile->getId(); if (UI_VERBOSE) { - $this->_retMsg('Data of audiclip saved.'); + $this->_retMsg('Data of audioclip saved.'); } - return $r; + return $storedFile->getId(); } // fn uploadFile - function test4audioType($filename) + function testForAudioType($filename) { global $CC_CONFIG; foreach ($CC_CONFIG['file_types'] as $t) { @@ -195,7 +204,7 @@ class uiHandler extends uiBase { } } return FALSE; - } // fn test4AudioType + } /** @@ -212,22 +221,24 @@ class uiHandler extends uiBase { $this->_retMsg($ia->getMessage()); return; } + // This is really confusing: the import script does not do it + // this way. Which way is the right way? $this->setMetadataValue($id, UI_MDATA_KEY_DURATION, Playlist::secondsToPlaylistTime($ia['playtime_seconds'])); - $this->setMetadataValue($id, UI_MDATA_KEY_FORMAT, UI_MDATA_VALUE_FORMAT_FILE); +// $this->setMetadataValue($id, UI_MDATA_KEY_FORMAT, UI_MDATA_VALUE_FORMAT_FILE); // some data from raw audio - if (isset($ia['audio']['channels'])) { - $this->setMetadataValue($id, UI_MDATA_KEY_CHANNELS, $ia['audio']['channels']); - } - if (isset($ia['audio']['sample_rate'])) { - $this->setMetadataValue($id, UI_MDATA_KEY_SAMPLERATE, $ia['audio']['sample_rate']); - } - if (isset($ia['audio']['bitrate'])) { - $this->setMetadataValue($id, UI_MDATA_KEY_BITRATE, $ia['audio']['bitrate']); - } - if (isset($ia['audio']['codec'])) { - $this->setMetadataValue($id, UI_MDATA_KEY_ENCODER, $ia['audio']['codec']); - } +// if (isset($ia['audio']['channels'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_CHANNELS, $ia['audio']['channels']); +// } +// if (isset($ia['audio']['sample_rate'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_SAMPLERATE, $ia['audio']['sample_rate']); +// } +// if (isset($ia['audio']['bitrate'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_BITRATE, $ia['audio']['bitrate']); +// } +// if (isset($ia['audio']['codec'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_ENCODER, $ia['audio']['codec']); +// } // from id3 Tags // loop main, music, talk @@ -489,7 +500,7 @@ class uiHandler extends uiBase { function getMdata($id) { header("Content-type: text/xml"); - $r = $this->gb->getMdata($id, $this->sessid); + $r = $this->gb->getMetadata($id, $this->sessid); print_r($r); } diff --git a/campcaster/src/modules/storageAdmin/var/campcaster-import.php b/campcaster/src/modules/storageAdmin/var/campcaster-import.php index 6e7248836..229bd5d71 100644 --- a/campcaster/src/modules/storageAdmin/var/campcaster-import.php +++ b/campcaster/src/modules/storageAdmin/var/campcaster-import.php @@ -119,16 +119,19 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = // Check for non-supported file type if (!preg_match('/\.(ogg|mp3)$/i', $p_filepath, $var)) { + echo "IGNORED: $p_filepath\n"; //echo " * WARNING: File extension not supported - skipping file: $p_filepath\n"; return array($fileCount, $duplicates); } +// $timeBegin = microtime(true); $md5sum = md5_file($p_filepath); +// $timeEnd = microtime(true); +// echo " * MD5 time: ".($timeEnd-$timeBegin)."\n"; // Look up md5sum in database $duplicate = StoredFile::RecallByMd5($md5sum); if ($duplicate) { - //echo " * File already exists in the database.\n"; echo "DUPLICATE: $p_filepath\n"; return array($fileCount, $duplicates+1); } @@ -138,6 +141,7 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = import_err($metadata); return array($fileCount, $duplicates); } + // bsSetMetadataBatch doesnt like these values unset($metadata['audio']); unset($metadata['playtime_seconds']); @@ -147,30 +151,43 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = } elseif ($p_importMode == "link") { $doCopyFiles = false; } - $r = $greenbox->bsPutFile($parentId, $metadata['ls:filename'], - $p_filepath, "$STORAGE_SERVER_PATH/var/emptyMdata.xml", NULL, - 'audioclip', 'file', $doCopyFiles); - if (PEAR::isError($r)) { - import_err($r, "Error in bsPutFile()"); + $values = array( + "filename" => $metadata['ls:filename'], + "filepath" => $p_filepath, + "metadata" => "$STORAGE_SERVER_PATH/var/emptyMdata.xml", + "gunid" => NULL, + "filetype" => "audioclip", + "md5" => $md5sum, + "mime" => $metadata['dc:format'] + ); +// $timeBegin = microtime(true); + $storedFile = $greenbox->bsPutFile($parentId, $values, $doCopyFiles); + if (PEAR::isError($storedFile)) { + import_err($storedFile, "Error in bsPutFile()"); echo var_export($metadata)."\n"; return 0; } - $id = $r; + $id = $storedFile->getId(); +// $timeEnd = microtime(true); +// echo " * Store file time: ".($timeEnd-$timeBegin)."\n"; + // Note: the bsSetMetadataBatch() takes up .25 of a second + // on my 3Ghz computer. We should try to speed this up. +// $timeBegin = microtime(true); $r = $greenbox->bsSetMetadataBatch($id, $metadata); if (PEAR::isError($r)) { import_err($r, "Error in bsSetMetadataBatch()"); echo var_export($metadata)."\n"; return 0; } +// $timeEnd = microtime(true); +// echo " * Metadata store time: ".($timeEnd-$timeBegin)."\n"; } else { - var_dump($infoFromFile); - echo "======================= "; + echo "==========================================================================\n"; + echo "METADATA\n"; var_dump($metadata); - echo "======================= "; } - //echo " * OK\n"; $fileCount++; return array($fileCount, $duplicates); } @@ -201,7 +218,6 @@ if (count($parsedCommandLine[1]) == 0) { exit; } -//print_r($parsedCommandLine); $files = $parsedCommandLine[1]; $testonly = FALSE; @@ -216,12 +232,10 @@ foreach ($cmdLineOptions as $tmpValue) { exit; case "c": case "--copy": - //echo " *** Working in copy mode\n"; $importMode = "copy"; break 2; case 'l': case '--link': - //echo " *** Working in link mode\n"; $importMode = "link"; break 2; case "t": @@ -236,7 +250,6 @@ if (is_null($importMode)) { exit(0); } -//echo "==========================================================================\n"; $filecount = 0; $duplicates = 0; if (is_array($files)) { @@ -262,6 +275,4 @@ echo " *** Errors: $g_errors\n"; echo " *** Total: ".($filecount+$duplicates)." files in $time seconds = $speed files/second.\n"; echo "==========================================================================\n"; -//echo " * Import completed.\n"; - ?> \ No newline at end of file diff --git a/campcaster/src/modules/storageAdmin/var/restore.php b/campcaster/src/modules/storageAdmin/var/restore.php index 036502b02..4e502e2aa 100644 --- a/campcaster/src/modules/storageAdmin/var/restore.php +++ b/campcaster/src/modules/storageAdmin/var/restore.php @@ -84,9 +84,14 @@ function ls_restore_restoreObject($obj, $parid, $reallyInsert=TRUE){ if (VERBOSE) { echo " creating file {$obj['name']} ...\n"; } - $r = $bs->bsPutFile($parid, $obj['name'], - $mediaFile, $mdataFile, $obj['gunid'], - strtolower($obj['type'])); + $values = array( + "filename" => $obj['name'], + "filepath" => $mediaFile, + "metadata" => $mdataFile, + "gunid" => $obj['gunid'], + "filetype" => strtolower($obj['type']) + ); + $r = $bs->bsPutFile($parid, $values); ls_restore_checkErr($r, __LINE__); } break; diff --git a/campcaster/src/modules/storageServer/var/BasicStor.php b/campcaster/src/modules/storageServer/var/BasicStor.php index 10e47e502..1f3cdb480 100644 --- a/campcaster/src/modules/storageServer/var/BasicStor.php +++ b/campcaster/src/modules/storageServer/var/BasicStor.php @@ -82,20 +82,21 @@ class BasicStor { * 'file'|'string' * @param boolean $copyMedia * copy the media file if true, make symlink if false - * @return int - * @exception PEAR_Error + * @return int|PEAR_Error + * ID of the StoredFile that was created. */ - public function bsPutFile($parid, $fileName, $localFilePath, $metadataFilePath, - $gunid=NULL, $ftype='unknown', $mdataLoc='file', $copyMedia=TRUE) + public function bsPutFile($p_parentId, $p_values, $p_copyMedia=TRUE) { - $ftype = strtolower($ftype); - $id = BasicStor::AddObj($fileName, $ftype, $parid); + if (!isset($p_values['filetype']) || !isset($p_values['filename'])) { + return NULL; + } + $ftype = strtolower($p_values['filetype']); + $id = BasicStor::AddObj($p_values['filename'], $ftype, $p_parentId); if (PEAR::isError($id)) { return $id; } - $storedFile = StoredFile::Insert($id, $fileName, - $localFilePath, $metadataFilePath, $mdataLoc, $gunid, $ftype, - $copyMedia); + $p_values['id'] = $id; + $storedFile = StoredFile::Insert($p_values, $p_copyMedia); if (PEAR::isError($storedFile)) { $res = BasicStor::RemoveObj($id); // catch constraint violations @@ -108,10 +109,7 @@ class BasicStor { return $storedFile; } } - if ($ftype == 'playlist') { - $storedFile->setMime('application/smil'); - } - return $id; + return $storedFile; } // fn bsPutFile @@ -900,8 +898,11 @@ class BasicStor { */ public function bsGetMetadataValue($id, $category = null) { + if (!is_numeric($id)) { + return null; + } $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { + if (PEAR::isError($storedFile) || is_null($storedFile)) { return $storedFile; } if (is_null($category)) { @@ -921,7 +922,7 @@ class BasicStor { /** * Set metadata element value * - * @param int $id + * @param int|StoredFile $id * Virtual file's local id * @param string $category * Metadata element identification (e.g. dc:title) @@ -940,9 +941,16 @@ class BasicStor { public function bsSetMetadataValue($id, $category, $value, $lang=NULL, $mid=NULL, $container='metadata', $regen=TRUE) { - $storedFile = StoredFile::Recall($id); - if (PEAR::isError($storedFile)) { - return $storedFile; + if (!is_string($category) || is_array($value)) { + return FALSE; + } + if (is_a($id, "StoredFile")) { + $storedFile =& $id; + } else { + $storedFile = StoredFile::Recall($id); + if (PEAR::isError($storedFile)) { + return $storedFile; + } } if ($category == 'dcterms:extent') { $value = BasicStor::NormalizeExtent($value); @@ -1002,9 +1010,13 @@ class BasicStor { if (!is_array($values)) { $values = array($values); } + $storedFile = StoredFile::Recall($id); + if (PEAR::isError($storedFile)) { + return $storedFile; + } foreach ($values as $category => $oneValue) { - $res = $this->bsSetMetadataValue($id, $category, $oneValue, - $lang, NULL, $container, FALSE); + $res = $this->bsSetMetadataValue($storedFile, $category, + $oneValue, $lang, NULL, $container, FALSE); if (PEAR::isError($res)) { return $res; } @@ -1136,7 +1148,7 @@ class BasicStor { } $gunids = array(); foreach ($plids as $plid) { - $pl = Playlist::RecallByGunid($plid); + $pl = StoredFile::RecallByGunid($plid); if (PEAR::isError($pl)) { return $pl; } @@ -1150,7 +1162,6 @@ class BasicStor { } $gunids = array_merge($gunids, $gunidsX); } -# header("Content-type: text/plain"); var_dump($gunids); var_dump($withContent); exit; $plExts = array('lspl'=>"lspl", 'smil'=>"smil", 'm3u'=>"m3u"); $plExt = (isset($plExts[$type]) ? $plExts[$type] : "xml" ); $res = array(); @@ -1176,8 +1187,8 @@ class BasicStor { if (file_exists($MDfname)) { switch ($it['type']) { case "playlist": - require_once("LsPlaylist.php"); - $storedFile = $r = LsPlaylist::RecallByGunid($it['gunid']); + require_once("Playlist.php"); + $storedFile = $r = StoredFile::RecallByGunid($it['gunid']); switch ($type) { case "smil": $string = $r = $storedFile->outputToSmil(); @@ -1286,11 +1297,18 @@ class BasicStor { "BasicStor::bsImportPlaylistRaw: file doesn't exist ($aPath/$rPath)" ); } - switch($ext){ + switch ($ext) { case "xml": case "lspl": $fname = $plid; - $res = $this->bsPutFile($parid, $fname, NULL, $path, $plid, 'playlist'); + $values = array( + "filename" => $fname, + "metadata" => $path, + "gunid" => $plid, + "filetype" => "playlist" + ); + $storedFile = $this->bsPutFile($parid, $values); + $res = $storedFile->getId(); break; case "smil": require_once("SmilPlaylist.php"); @@ -1384,8 +1402,15 @@ class BasicStor { } } if (!PEAR::isError($res) ) { - $res = $this->bsPutFile($parid, $gunid, $rawMedia, $metadata, - $gunid, 'audioclip'); + $values = array( + "filename" => $gunid, + "filepath" => $rawMedia, + "metadata" => $metadata, + "gunid" => $gunid, + "filetype" => "audioclip" + ); + $storedFile = $this->bsPutFile($parid, $values); + $res = $storedFile->getId(); } @unlink("$tmpdc/{$it['rawMedia']}"); @unlink("$tmpdc/{$it['metadata']}"); @@ -2202,7 +2227,14 @@ class BasicStor { $fname = basename($xml); break; } - $r = $this->bsPutFile($rootHD, $fname, $media, $xml, $gunid, $type); + $values = array( + "filename" => $fname, + "filepath" => $media, + "metadata" => $xml, + "gunid" => $gunid, + "filetype" => $type + ); + $r = $this->bsPutFile($rootHD, $values); if (PEAR::isError($r)) { return $r; } @@ -2286,140 +2318,6 @@ class BasicStor { } - /** - * Create BasicStor object with temporarily changed configuration - * to prevent data changes in tests - * - */ -// function createTestSpace(&$dbc, $config){ -// $configBckp = $config; -// $config['tblNamePrefix'] .= '_test_'; -// mkdir($config['storageDir'].'/tmp'); -// $config['storageDir'] .= '/tmp/stor'; -// $config['bufferDir'] = $config['storageDir'].'/buffer'; -// $config['transDir'] .= '/tmp/trans'; -// $config['accessDir'] .= '/tmp/access'; -// mkdir($config['storageDir']); -// mkdir($config['bufferDir']); -// $bs = new BasicStor($dbc, $config); -// $bs->configBckp = $configBckp; -// $r = $bs->install(); -// if (PEAR::isError($r)) { -// return $r; -// } -// return $bs; -// } - - - /** - * Clean up test space - * - */ -// function releaseTestSpace() { -// $r = $this->uninstall(); -// if (PEAR::isError($r)) { -// return $r; -// } -// // rmdir($this->config['bufferDir']); -// rmdir($this->config['storageDir']); -// $this->config = $this->configBckp; -// rmdir($this->config['storageDir'].'/tmp'); -// } - - - /** - * testData - * - */ - public function testData($d='') - { - $exdir = dirname(__FILE__).'/tests'; - $o[] = $this->addSubj('test1', 'a'); - $o[] = $this->addSubj('test2', 'a'); - $o[] = $this->addSubj('test3', 'a'); - $o[] = $this->addSubj('test4', 'a'); - - $o[] = $t1hd = M2tree::GetObjId('test1', $this->storId); - $o[] = $t1d1 = BasicStor::bsCreateFolder($t1hd, 'test1_folder1'); - $o[] = BasicStor::bsCreateFolder($t1hd, 'test1_folder2'); - $o[] = BasicStor::bsCreateFolder($t1d1, 'test1_folder1_1'); - $o[] = $t1d12 = BasicStor::bsCreateFolder($t1d1, 'test1_folder1_2'); - - $o[] = $t2hd = M2tree::GetObjId('test2', $this->storId); - $o[] = BasicStor::bsCreateFolder($t2hd, 'test2_folder1'); - - $o[] = $this->bsPutFile($t1hd, 'file1.mp3', "$exdir/ex1.mp3", '', NULL, 'audioclip'); - $o[] = $this->bsPutFile($t1d12, 'file2.wav', "$exdir/ex2.wav", '', NULL, 'audioclip'); - $this->tdata['storage'] = $o; - } - - /** - * test - * - */ - public function test() - { - global $CC_CONFIG; - $this->test_log = ''; - // if(PEAR::isError($p = parent::test())) return $p; - $this->deleteData(); - $this->testData(); - if ($CC_CONFIG['useTrash']) { - $trash = "\n ".$CC_CONFIG['TrashName']; - } else { - $trash = ""; - } - if (!$CC_CONFIG['isArchive']) { - $this->test_correct = " StorageRoot - root - test1 - file1.mp3 - public - test1_folder1 - test1_folder1_1 - test1_folder1_2 - file2.wav - test1_folder2 - test2 - public - test2_folder1 - test3 - public - test4 - public{$trash} -"; - } else { - $this->test_correct = " StorageRoot - root - test1 - file1.mp3 - test1_folder1 - test1_folder1_1 - test1_folder1_2 - file2.wav - test1_folder2 - test2 - test2_folder1 - test3 - test4{$trash} -"; - } - $r = M2tree::DumpTree($this->storId, ' ', ' ', '{name}'); - if (PEAR::isError($r)) { - return $r; - } - $this->test_dump = $r; - if ($this->test_dump == $this->test_correct) { - $this->test_log .= "# BasicStor::test: OK\n"; - return true; - } else { - return PEAR::raiseError( - "BasicStor::test:\ncorrect:\n.{$this->test_correct}.\n". - "dump:\n.{$this->test_dump}.\n", 1, PEAR_ERROR_RETURN); - } - } - - /** * initData - initialize * diff --git a/campcaster/src/modules/storageServer/var/DataEngine.php b/campcaster/src/modules/storageServer/var/DataEngine.php index 1bf61a0a7..741d563d1 100644 --- a/campcaster/src/modules/storageServer/var/DataEngine.php +++ b/campcaster/src/modules/storageServer/var/DataEngine.php @@ -443,11 +443,11 @@ class DataEngine { 'id' => $it['id'], 'gunid' => $gunid, 'type' => $it['ftype'], - 'title' => $values['dc:title'], - 'creator' => (isset($values['dc:creator']) ? $values['dc:creator'] : NULL ), - 'duration' => $values['dcterms:extent'], - 'length' => $values['dcterms:extent'], - 'source' => (isset($values['dc:source']) ? $values['dc:source'] : NULL ), + 'title' => $values['dc:title']["object"], + 'creator' => (isset($values['dc:creator']) ? $values['dc:creator']["object"] : NULL ), + 'duration' => $values['dcterms:extent']["object"], + 'length' => $values['dcterms:extent']["object"], + 'source' => (isset($values['dc:source']) ? $values['dc:source']["object"] : NULL ), ); } else { $eres[] = $it['txt']; diff --git a/campcaster/src/modules/storageServer/var/GreenBox.php b/campcaster/src/modules/storageServer/var/GreenBox.php index 2174598e4..50234e92b 100644 --- a/campcaster/src/modules/storageServer/var/GreenBox.php +++ b/campcaster/src/modules/storageServer/var/GreenBox.php @@ -60,15 +60,15 @@ class GreenBox extends BasicStor { * @param string $ftype * Internal file type * @return int + * ID of the StoredFile that was created. */ - public function putFile($parid, $fileName, $mediaFileLP, $mdataFileLP, - $sessid='', $gunid=NULL, $ftype='audioclip') + public function putFile($p_parentId, $p_values, $p_sessionId='') { - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('write', $p_parentId, $p_sessionId)) !== TRUE) { return $res; } - return $this->bsPutFile($parid, $fileName, $mediaFileLP, - $mdataFileLP, $gunid, $ftype); + $storedFile = $this->bsPutFile($p_parentId, $p_values); + return $storedFile; } // fn putFile @@ -99,12 +99,17 @@ class GreenBox extends BasicStor { if (!file_exists($mdataFileLP)) { $mdataFileLP = dirname(__FILE__).'/emptyWebstream.xml'; } - $oid = $this->bsPutFile( - $parid, $fileName, '', $mdataFileLP, $gunid, 'webstream' + $values = array( + "filename" => $fileName, + "metadata" => $mdataFileLP, + "gunid" => $gunid, + "filetype" => "webstream" ); - if (PEAR::isError($oid)) { - return $oid; + $storedFile = $this->bsPutFile($parid, $values); + if (PEAR::isError($storedFile)) { + return $storedFile; } + $oid = $storedFile->getId(); $r = $this->bsSetMetadataValue( $oid, 'ls:url', $url, NULL, NULL, 'metadata'); if (PEAR::isError($r)) { @@ -313,13 +318,13 @@ class GreenBox extends BasicStor { * @return string|PEAR_Error * @todo rename this function to "getMetadata" */ - public function getMdata($id, $sessid='') + public function getMetadata($id, $sessid='') { if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) { return $res; } return $this->bsGetMetadata($id); - } // fn getMdata + } /** @@ -334,9 +339,8 @@ class GreenBox extends BasicStor { * @param string $sessid * session ID * @return array - * @todo rename this function to "getMdataArray" */ - public function getMdataArray($id, $sessid) + public function getMetadataArray($id, $sessid) { if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) { return $res; @@ -355,7 +359,7 @@ class GreenBox extends BasicStor { } if ($md === FALSE) { return PEAR::raiseError( - "GreenBox::getMdataArray: no metadata container found" + "GreenBox::getMetadataArray: no metadata container found" ); } $res = array(); @@ -369,7 +373,7 @@ class GreenBox extends BasicStor { } } return $res; - } // fn getMdataArray + } /** @@ -396,6 +400,9 @@ class GreenBox extends BasicStor { public function getMetadataValue($id, $category, $sessid='', $lang=NULL, $deflang=NULL) { + if (!is_numeric($id)) { + return null; + } if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) { return $res; } @@ -572,7 +579,7 @@ class GreenBox extends BasicStor { */ // function getPlaylistXml($id, $sessid) // { -// return $this->getMdata($id, $sessid); +// return $this->getMetadata($id, $sessid); // } // fn getPlaylistXml @@ -672,7 +679,7 @@ class GreenBox extends BasicStor { $fadeIn=NULL, $fadeOut=NULL, $length=NULL, $pause=NULL) { require_once"Playlist.php"; - $pl = Playlist::RecallByToken($token); + $pl = StoredFile::RecallByToken($token); if (PEAR::isError($pl)) { return $pl; } @@ -713,7 +720,7 @@ class GreenBox extends BasicStor { public function delAudioClipFromPlaylist($token, $plElGunid, $sessid) { require_once("Playlist.php"); - $pl = Playlist::RecallByToken($token); + $pl = StoredFile::RecallByToken($token); if (PEAR::isError($pl)) { return $pl; } @@ -748,7 +755,7 @@ class GreenBox extends BasicStor { public function changeFadeInfo($token, $plElGunid, $fadeIn, $fadeOut, $sessid) { require_once("Playlist.php"); - $pl = Playlist::RecallByToken($token); + $pl = StoredFile::RecallByToken($token); if (PEAR::isError($pl)) { return $pl; } @@ -784,7 +791,7 @@ class GreenBox extends BasicStor { public function moveAudioClipInPlaylist($token, $plElGunid, $newPos, $sessid) { require_once("Playlist.php"); - $pl = Playlist::RecallByToken($token); + $pl = StoredFile::RecallByToken($token); if (PEAR::isError($pl)) { return $pl; } @@ -864,7 +871,7 @@ class GreenBox extends BasicStor { $lang=NULL, $deflang=NULL) { require_once("Playlist.php"); - $pl = Playlist::RecallByGunid($plid); + $pl = StoredFile::RecallByGunid($plid); if (PEAR::isError($pl)) { return $pl; } diff --git a/campcaster/src/modules/storageServer/var/LocStor.php b/campcaster/src/modules/storageServer/var/LocStor.php index 39ff07d71..b00cab38b 100644 --- a/campcaster/src/modules/storageServer/var/LocStor.php +++ b/campcaster/src/modules/storageServer/var/LocStor.php @@ -93,8 +93,12 @@ class LocStor extends BasicStor { if (PEAR::isError($oid)) { return $oid; } - $storedFile =& StoredFile::Insert($oid, '', '', $metadata, - 'string', $gunid, $ftype); + $values = array( + "id" => $oid, + "metadata" => $metadata, + "gunid" => $gunid, + "filetype" => $ftype); + $storedFile =& StoredFile::Insert($values); if (PEAR::isError($storedFile)) { $res = BasicStor::RemoveObj($oid); return $storedFile; @@ -606,9 +610,12 @@ class LocStor extends BasicStor { if (PEAR::isError($oid)) { return $oid; } - $storedFile =& StoredFile::Insert($oid, '', '', - dirname(__FILE__).'/emptyPlaylist.xml', - 'file', $playlistId, 'playlist'); + $values = array( + "id" => $oid, + "metadata" => dirname(__FILE__).'/emptyPlaylist.xml', + "gunid" => $playlistId, + "filetype" => "playlist"); + $storedFile = StoredFile::Insert($values); if (PEAR::isError($storedFile)) { $res = BasicStor::RemoveObj($oid); return $storedFile; diff --git a/campcaster/src/modules/storageServer/var/LsPlaylist.php b/campcaster/src/modules/storageServer/var/LsPlaylist.php deleted file mode 100644 index ba8c57008..000000000 --- a/campcaster/src/modules/storageServer/var/LsPlaylist.php +++ /dev/null @@ -1,599 +0,0 @@ - - * @author Paul Baranowski - * @version $Revision: 1848 $ - * @package Campcaster - * @subpackage StorageServer - * @copyright 2006 MDLF, Inc. - * @license http://www.gnu.org/licenses/gpl.txt - * @link http://www.campware.org - * @todo Rename this class - */ -class LsPlaylist extends Playlist -{ - /** - * Create instance of LsPlaylist object and recall existing file - * by gunid. - * - * @param string $gunid - * global unique id - * @param string $className - * optional classname to recall - * @return LsPlaylist - */ - public static function RecallByGunid($gunid, $className='LsPlaylist') - { - return parent::RecallByGunid($gunid, $className); - } - - - /** - * Create instance of LsPlaylist object and recall existing file - * by access token. - * - * @param string $token - * access token - * @param string $className - * optional classname to recall - * @return LsPlaylist - */ - public static function RecallByToken($token, $className='LsPlaylist') - { - return parent::RecallByToken($token, $className); - } - - - /** - * Export playlist as simplified SMIL XML file. - * - * @param boolean $toString - * if false don't real export, - * return misc info about playlist only - * @return string - * XML string or hasharray with misc info - */ - public function outputToSmil($toString=TRUE) - { - $plGunid = $this->gunid; - $arr = $this->md->genPhpArray(); - if (PEAR::isError($arr)) { - return $arr; - } - if ($toString) { - $r = LsPlaylistTag::outputToSmil($this, $arr); - if (PEAR::isError($r)) { - return $r; - } - return $r; - } else { - return array( - 'type' => 'playlist', - 'gunid' => $plGunid, - 'src' => PL_URL_RELPATH."$plGunid.smil", - 'playlength' => $arr['attrs']['playlength'], - ); - } - } - - - /** - * Export playlist as M3U file. - * - * @param boolean $toString - * if false don't real export, - * return misc info about playlist only - * @return string|array - * M3U string or hasharray with misc info - */ - public function outputToM3u($toString=TRUE) - { - $plGunid = $this->gunid; - $arr = $this->md->genPhpArray(); - if (PEAR::isError($arr)) { - return $arr; - } - if ($toString) { - $r = LsPlaylistTag::outputToM3u($this, $arr); - if (PEAR::isError($r)) { - return $r; - } - return $r; - } else { - return array( - 'type' => 'playlist', - 'gunid' => $plGunid, - 'uri' => PL_URL_RELPATH."$plGunid.m3u", - 'playlength' => $arr['attrs']['playlength'], - 'title' => $arr['attrs']['title'], - ); - } - } - - - /** - * Export playlist as RSS XML file - * - * @param boolean $toString - * if false don't really export, - * return misc info about playlist only - * @return mixed - * XML string or hasharray with misc info - */ - public function outputToRss($toString=TRUE) - { - $plGunid = $this->gunid; - $arr = $this->md->genPhpArray(); - if (PEAR::isError($arr)) { - return $arr; - } - if ($toString) { - $r = LsPlaylistTag::outputToRss($this, $arr); - if (PEAR::isError($r)) { - return $r; - } - return $r; - } else { - return array( - 'type' => 'playlist', - 'gunid' => $plGunid, - 'src' => PL_URL_RELPATH."$plGunid.smil", - 'playlength' => $arr['attrs']['playlength'], - ); - } - } - -} // class LsPlaylist - - -/** - * Several auxiliary classes follows - * @author Tomas Hlava - * @author Paul Baranowski - * @package Campcaster - * @subpackage StorageServer - * @copyright 2006 MDLF, Inc. - * @license http://www.gnu.org/licenses/gpl.txt - * @link http://www.campware.org - * @todo Rename this class PlaylistTag - */ -class LsPlaylistTag -{ - public function outputToSmil(&$pl, $plt, $ind='') - { - $ind2 = $ind.INDCH; - $ind3 = $ind2.INDCH; - $ind4 = $ind3.INDCH; - $res = ""; - foreach ($plt['children'] as $ple) { - switch ($ple['elementname']) { - case"playlistElement": - $r = LsPlaylistElement::outputToSmil($pl, $ple, $ind4); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $res .= $r; - } - break; - case"metadata": - $r = LsPlaylistMetadata::outputToSmil($pl, $ple, $ind4); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $res .= $r; - } - break; - default: - } - } - $res = "$ind\n". - "$ind\n". - "$ind2\n". - "$ind3\n". - "$res". - "$ind3\n". - "$ind2\n". - "$ind\n"; - return $res; - } - - - public function outputToM3u(&$pl, $plt, $ind='') - { - $res = ""; - foreach ($plt['children'] as $ple) { - switch ($ple['elementname']) { - case"playlistElement": - $r = LsPlaylistElement::outputToM3u($pl, $ple); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $res .= $r; - } - break; - } - } - $res = "#EXTM3U\n$res"; - return $res; - } - - - public function outputToRss(&$pl, $plt, $ind='') - { - $ind2 = $ind.INDCH; - $ind3 = $ind2.INDCH; - $res = ""; - foreach ($plt['children'] as $ple) { - switch ($ple['elementname']) { - case"playlistElement": - $r = LsPlaylistElement::outputToRss($pl, $ple, $ind3); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $res .= $r; - } - break; - case"metadata": - $r = LsPlaylistMetadata::outputToRss($pl, $ple, $ind3); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $res .= $r; - } - break; - default: - } - } - $res = "$ind\n". - "$ind\n". - "$ind2\n". - "$res". - "$ind2\n". - "$ind\n"; - return $res; - } -} // class LsPlaylistTag - - -/** - * @author Tomas Hlava - * @author Paul Baranowski - * @package Campcaster - * @subpackage StorageServer - * @copyright 2006 MDLF, Inc. - * @license http://www.gnu.org/licenses/gpl.txt - * @link http://www.campware.org - * @todo Rename this class "PlaylistElement" - */ -class LsPlaylistElement { - - - public function outputToSmil(&$pl, $ple, $ind='') - { - $acOrPl = NULL; - $finfo = array('fi'=>0, 'fo'=>0); - $ind2 = $ind.INDCH; - $ind3 = $ind2.INDCH; - $anim = ''; - foreach ($ple['children'] as $ac) { - switch ($ac['elementname']) { - case "audioClip": - $r = LsPlaylistAudioClip::outputToSmil($pl, $ac, $ind2); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $acOrPl = $r; - } - break; - case "playlist": - $gunid = $ac['attrs']['id']; - $pl2 = LsPlaylist::RecallByGunid($gunid); - if (PEAR::isError($pl2)) { - return $pl2; - } - $r = $pl2->outputToSmil(FALSE); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $acOrPl = $r; - } - break; - case "fadeInfo": - $r = LsPlaylistFadeInfo::outputToSmil($pl, $ac, $ind2); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $finfo = $r; - } - break; - default: - return PEAR::raiseError( - "LsPlaylistElement::outputToSmil:". - " unknown tag {$ac['elementname']}" - ); - } - } - $beginS = Playlist::playlistTimeToSeconds($ple['attrs']['relativeOffset']); - $playlengthS = Playlist::playlistTimeToSeconds($acOrPl['playlength']); - $fadeOutS = Playlist::playlistTimeToSeconds($finfo['fo']); - $fiBeginS = 0; - $fiEndS = Playlist::playlistTimeToSeconds($finfo['fi']); - $foBeginS = ($playlengthS - $fadeOutS); - $foEndS = Playlist::playlistTimeToSeconds($acOrPl['playlength']); - foreach (array('fi','fo') as $ff) { - if (${$ff."EndS"} - ${$ff."BeginS"} > 0) { - $anim .= "{$ind2}\n" - ; - } - } - $src = $acOrPl['src']; - $str = "$ind" : " />"). - " ". - "\n"; - return $str; - } - - - public function outputToM3u(&$pl, $ple, $ind='') - { - $acOrPl = NULL; - foreach ($ple['children'] as $ac) { - switch ($ac['elementname']) { - case "audioClip": - $r = LsPlaylistAudioClip::outputToM3u($pl, $ac); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $acOrPl = $r; - } - break; - case "playlist": - $gunid = $ac['attrs']['id']; - $pl2 = LsPlaylist::RecallByGunid($gunid); - if (PEAR::isError($pl2)) { - return $pl2; - } - $r = $pl2->outputToM3u(FALSE); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $acOrPl = $r; - } - break; - } - } - if (is_null($acOrPl)) { - return ''; - } - $playlength = ceil(Playlist::playlistTimeToSeconds($acOrPl['playlength'])); - $title = $acOrPl['title']; - $uri = (isset($acOrPl['uri']) ? $acOrPl['uri'] : '???' ); - $res = "#EXTINF: $playlength, $title\n"; - $res .= "$uri\n"; - return $res; - } - - - function outputToRss(&$pl, $ple, $ind='') - { - $acOrPl = NULL; - $ind2 = $ind.INDCH; - $anim = ''; - foreach ($ple['children'] as $ac) { - switch ($ac['elementname']) { - case "audioClip": - $r = LsPlaylistAudioClip::outputToRss($pl, $ac, $ind2); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $acOrPl = $r; - } - break; - case "playlist": - $gunid = $ac['attrs']['id']; - $pl2 = LsPlaylist::RecallByGunid($gunid); - if (PEAR::isError($pl2)) { - return $pl2; - } - $r = $pl2->outputToRss(FALSE); - if (PEAR::isError($r)) { - return $r; - } - if (!is_null($r)) { - $acOrPl = $r; - } - break; - case"fadeInfo": - break; - default: - return PEAR::raiseError( - "LsPlaylistElement::outputToRss:". - " unknown tag {$ac['elementname']}" - ); - } - } - $title = (isset($acOrPl['title']) ? htmlspecialchars($acOrPl['title']) : '' ); - $desc = (isset($acOrPl['desc']) ? htmlspecialchars($acOrPl['desc']) : '' ); - $link = htmlspecialchars($acOrPl['src']); - $desc = ''; - $str = "$ind\n". - "$ind2$title\n". - "$ind2$desc\n". - "$ind2$link\n". - "$ind\n"; - return $str; - } -} - - -/** - * @author Tomas Hlava - * @author Paul Baranowski - * @package Campcaster - * @subpackage StorageServer - * @copyright 2006 MDLF, Inc. - * @license http://www.gnu.org/licenses/gpl.txt - * @link http://www.campware.org - * @todo Rename this class to PlaylistAudioClip (notice the caps) - */ -class LsPlaylistAudioClip -{ - - public function outputToSmil(&$pl, $plac, $ind='') - { - $gunid = $plac['attrs']['id']; - $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { - return $ac; - } - $RADext = $ac->getFileExtension(); - if (PEAR::isError($RADext)) { - return $RADext; - } - return array( - 'type' => 'audioclip', - 'gunid' => $gunid, - 'src' => AC_URL_RELPATH."$gunid.$RADext", - 'playlength' => $plac['attrs']['playlength'], - ); - } - - - public function outputToM3u(&$pl, $plac, $ind='') - { - $gunid = $plac['attrs']['id']; - $ac = StoredFile::RecallByGunid($gunid); - if (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 function outputToRss(&$pl, $plac, $ind='') - { - $gunid = $plac['attrs']['id']; - $ac = StoredFile::RecallByGunid($gunid); - if (PEAR::isError($ac)) { - return $ac; - } - $RADext = $ac->getFileExtension(); - if (PEAR::isError($RADext)) { - return $RADext; - } - $title = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:title'); - $desc = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:description'); - return array( - 'type' => 'audioclip', - 'gunid' => $gunid, - 'src' => "http://XXX/YY/$gunid.$RADext", - 'playlength' => $plac['attrs']['playlength'], - 'title' => $title, - 'desc' => $desc, - ); - } -} // class LsPlaylistAudioClip - - -/** - * @author Tomas Hlava - * @author Paul Baranowski - * @package Campcaster - * @subpackage StorageServer - * @copyright 2006 MDLF, Inc. - * @license http://www.gnu.org/licenses/gpl.txt - * @link http://www.campware.org - * @todo Rename this class "PlaylistFadeInfo" (notive the caps) - */ -class LsPLaylistFadeInfo -{ - - public function outputToSmil(&$pl, $plfi, $ind='') - { - $r = array( - 'fi'=>$plfi['attrs']['fadeIn'], - 'fo'=>$plfi['attrs']['fadeOut'], - ); - return $r; - } - - - public function outputToM3u(&$pl, $plfa, $ind='') - { - return ''; - } - - - public function outputToRss(&$pl, $plfa, $ind='') - { - return ''; - } - -} // class LsPlaylistFadeInfo - - -/** - * @author Tomas Hlava - * @author Paul Baranowski - * @package Campcaster - * @subpackage StorageServer - * @copyright 2006 MDLF, Inc. - * @license http://www.gnu.org/licenses/gpl.txt - * @link http://www.campware.org - * @todo Rename this class to PlaylistMetadata (notice the caps) - */ -class LsPlaylistMetadata -{ - public function outputToSmil(&$pl, $md, $ind='') - { - return NULL; - } - - - public function outputToM3u(&$pl, $md, $ind='') - { - return NULL; - } - - - public function outputToRss(&$pl, $md, $ind='') - { - return NULL; - } -} // class PlaylistMetadata -?> \ No newline at end of file diff --git a/campcaster/src/modules/storageServer/var/MetaData.php b/campcaster/src/modules/storageServer/var/MetaData.php index 7d175a39f..af3488f16 100644 --- a/campcaster/src/modules/storageServer/var/MetaData.php +++ b/campcaster/src/modules/storageServer/var/MetaData.php @@ -3,7 +3,7 @@ define('DEBUG', FALSE); //define('DEBUG', TRUE); define('MODIFY_LAST_MATCH', TRUE); -require_once "XML/Util.php"; +require_once("XML/Util.php"); /** * File storage support class. @@ -23,11 +23,39 @@ require_once "XML/Util.php"; */ class MetaData { + /** + * @var string + */ public $gunid; + + /** + * For debugging purposes. + * + * @var string + */ + public $gunidBigint; + + /** + * @var string + */ public $resDir; + + /** + * @var string + */ public $fname; + + /** + * @var boolean + */ public $exists; + /** + * @var array + */ + private $metadata; + + /** * @param string $gunid * global unique id @@ -40,6 +68,7 @@ class MetaData { $this->resDir = $resDir; $this->fname = $this->makeFileName(); $this->exists = null; + $this->getAllMetadata(); } @@ -116,7 +145,7 @@ class MetaData { public function exists() { if (is_null($this->exists)) { - $this->exists = $this->dbCheck($this->gunid) + $this->exists = ($this->numElements($this->gunid) > 0) && is_file($this->fname) && is_readable($this->fname); } @@ -135,10 +164,9 @@ class MetaData { if (file_exists($this->fname)) { @unlink($this->fname); } - $res = $CC_DBC->query(" - DELETE FROM ".$CC_CONFIG['mdataTable']." - WHERE gunid=x'{$this->gunid}'::bigint - "); + $sql = "DELETE FROM ".$CC_CONFIG['mdataTable'] + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } @@ -164,41 +192,54 @@ class MetaData { /** - * Return all metadata for this GUNID. + * Return all metadata as an array. * * @return array */ public function getAllMetadata() { global $CC_CONFIG, $CC_DBC; - $sql = "SELECT predns, predicate, object + if (!is_string($this->gunid)) { + return array(); + } + $sql = "SELECT id, to_hex(gunid), subjns, subject, predns, predicate, predxml, objns, object FROM ".$CC_CONFIG['mdataTable']." WHERE gunid=x'{$this->gunid}'::bigint"; $rows = $CC_DBC->getAll($sql); - $values = array(); + $this->metadata = array(); foreach ($rows as $row) { - $values[$row["predns"].":".$row["predicate"]] = $row["object"]; + $this->metadata[$row["predns"].":".$row["predicate"]] = $row; } - return $values; + return $this->metadata; } /** * Get metadata element value and record id * - * @param string $category + * @param string $p_category * metadata element name * @param int $parid * metadata record id of parent element * @return array * int 'mid': record id - * string 'value': metadata value} + * string 'value': metadata value */ - public function getMetadataEl($category, $parid=NULL) + public function getMetadataElement($p_category, $parid=NULL) { global $CC_CONFIG, $CC_DBC; + + // Get cached value if it exists. + if (is_null($parid) && isset($this->metadata[$p_category])) { + // to be compatible with return values below - yuk + $retval = array(); + $retval[0]['mid'] = $this->metadata[$p_category]["id"]; + $retval[0]['value'] = $this->metadata[$p_category]["object"]; + return $retval; + } + // handle predicate namespace shortcut - $a = XML_Util::splitQualifiedName($category); + $a = XML_Util::splitQualifiedName($p_category); if (PEAR::isError($a)) { return $a; } @@ -231,13 +272,13 @@ class MetaData { /** * Set metadata value / delete metadata record * - * @param int $mid + * @param int $p_id * metadata record id - * @param string $value + * @param string $p_value * new metadata value (NULL for delete) * @return boolean */ - public function setMetadataEl($mid, $value=NULL) + public function setMetadataElement($p_id, $p_value=NULL) { global $CC_CONFIG, $CC_DBC; $info = $CC_DBC->getRow(" @@ -246,33 +287,29 @@ class MetaData { FROM ".$CC_CONFIG['mdataTable']." parmd INNER JOIN ".$CC_CONFIG['mdataTable']." md ON parmd.id=md.subject AND md.subjns='_I' - WHERE md.id=$mid - "); + WHERE md.id=$p_id"); if (PEAR::isError($info)) { return $info; } if (is_null($info)) { return PEAR::raiseError( - "MetaData::setMetadataEl: parent container not found" - ); + "MetaData::setMetadataElement: parent container not found"); } extract($info); $parname = ($parns ? "$parns:" : '').$parname; $category = ($chns ? "$chns:" : '').$chname; - $r = $this->validateOneValue($parname, $category, $predxml, $value); + $r = $this->validateOneValue($parname, $category, $predxml, $p_value); if (PEAR::isError($r)) { return $r; } - if (!is_null($value)) { - $escapedValue = pg_escape_string($value); - $sql = " - UPDATE ".$CC_CONFIG['mdataTable']." + if (!is_null($p_value)) { + $escapedValue = pg_escape_string($p_value); + $sql = "UPDATE ".$CC_CONFIG['mdataTable']." SET object='$escapedValue', objns='_L' - WHERE id={$mid} - "; + WHERE id={$p_id}"; $res = $CC_DBC->query($sql); } else { - $res = $this->deleteRecord($mid); + $res = $this->deleteRecord($p_id); } if (PEAR::isError($res)) { return $res; @@ -286,46 +323,46 @@ class MetaData { * * @param int $parid * metadata record id of parent element - * @param string $category + * @param string $p_category * metadata element name - * @param string value + * @param string $p_value * new metadata value (NULL for delete) * @param string $predxml * 'T' | 'A' | 'N' (tag, attr., namespace) * @return int * new metadata record id */ - public function insertMetadataEl($parid, $category, $value=NULL, $predxml='T') + public function insertMetadataElement($parid, $p_category, $p_value=NULL, $predxml='T') { global $CC_CONFIG, $CC_DBC; - //$category = strtolower($category); - $parent = $CC_DBC->getRow(" - SELECT predns, predicate, predxml FROM ".$CC_CONFIG['mdataTable']." - WHERE gunid=x'{$this->gunid}'::bigint AND id=$parid - "); + //$p_category = strtolower($p_category); + $sql = "SELECT predns, predicate, predxml " + ." FROM ".$CC_CONFIG['mdataTable'] + ." WHERE gunid=x'{$this->gunid}'::bigint AND id=$parid"; + $parent = $CC_DBC->getRow($sql); if (PEAR::isError($parent)) { return $parent; } if (is_null($parent)) { return PEAR::raiseError( - "MetaData::insertMetadataEl: container not found" + "MetaData::insertMetadataElement: container not found" ); } $parNs = ($parent['predns'] ? "{$parent['predns']}:" : ''); $parName = $parNs.$parent['predicate']; - $r = $this->validateOneValue($parName, $category, $predxml, $value); + $r = $this->validateOneValue($parName, $p_category, $predxml, $p_value); if (PEAR::isError($r)) { return $r; } - $a = XML_Util::splitQualifiedName($category); + $a = XML_Util::splitQualifiedName($p_category); if (PEAR::isError($a)) { return $a; } $catNs = $a['namespace']; $cat = $a['localPart']; - $objns = (is_null($value) ? '_blank' : '_L' ); + $objns = (is_null($p_value) ? '_blank' : '_L' ); $nid= $this->storeRecord('_I', $parid, $catNs, $cat, $predxml, - $objns, $value); + $objns, $p_value); if (PEAR::isError($nid)) { return $nid; } @@ -336,53 +373,53 @@ class MetaData { /** * Get metadata element value * - * @param string $category + * @param string $p_category * metadata element name - * @param string $lang + * @param string $p_lang * optional xml:lang value for select language version * @param string $deflang * optional xml:lang for default language * @param string $objns * object namespace prefix - for internal use only * @return array - * array of matching records as hash with fields: + * array of matching records as an array with fields: *
    - *
  • mid int, local metadata record id
  • - *
  • value string, element value
  • - *
  • attrs hasharray of element's attributes indexed by + *
  • "mid" - int, local metadata record id
  • + *
  • "value" - string, element value
  • + *
  • "attrs" - hasharray of element's attributes indexed by * qualified name (e.g. xml:lang)
  • *
* @see BasicStor::bsGetMetadataValue */ - private function getMetadataValueWithAttrs($category, $lang=NULL, $deflang=NULL, $objns='_L') + private function getMetadataValueWithAttrs($p_category, $p_lang=NULL, $deflang=NULL, $objns='_L') { - $all = $this->getMetadataEl($category); + $all = $this->getMetadataElement($p_category); $res = array(); $exact = NULL; $def = NULL; $plain = NULL; // add attributes to result - foreach ($all as $i => $rec) { - $pom = $this->getSubrows($rec['mid']); - if (PEAR::isError($pom)) { - return $pom; + foreach ($all as $key => $rec) { + $subrows = $this->getSubrows($rec['mid']); + if (PEAR::isError($subrows)) { + return $subrows; } - $all[$i]['attrs'] = $pom['attrs']; - $atlang = (isset($pom['attrs']['xml:lang']) ? - $pom['attrs']['xml:lang'] : NULL); + $all[$key]['attrs'] = $subrows['attrs']; + $atlang = (isset($subrows['attrs']['xml:lang']) ? + $subrows['attrs']['xml:lang'] : NULL); // select only matching lang (en is default) - if (is_null($lang)) { - $res[] = $all[$i]; + if (is_null($p_lang)) { + $res[] = $all[$key]; } else { switch (strtolower($atlang)) { case '': - $plain = array($all[$i]); + $plain = array($all[$key]); break; - case strtolower($lang): - $exact = array($all[$i]); + case strtolower($p_lang): + $exact = array($all[$key]); break; case strtolower($deflang): - $def = array($all[$i]); + $def = array($all[$key]); break; } } @@ -403,14 +440,14 @@ class MetaData { /** * Get metadata element value. * - * @param string $category + * @param string $p_category * metadata element name * @return string * If the value doesnt exist, return the empty string. */ - public function getMetadataValue($category) + public function getMetadataValue($p_category) { - $element = $this->getMetadataEl($category); + $element = $this->getMetadataElement($p_category); $value = (isset($element[0]['value']) ? $element[0]['value'] : ''); return $value; } @@ -419,64 +456,63 @@ class MetaData { /** * Set metadata element value * - * @param string $category + * @param string $p_category * metadata element name (e.g. dc:title) - * @param string $value + * @param string $p_value * value to store, if NULL then delete record - * @param string $lang + * @param string $p_lang * optional xml:lang value for select language version - * @param int $mid + * @param int $p_id * metadata record id (OPTIONAL on unique elements) - * @param string $container + * @param string $p_container * container element name for insert * @return boolean */ - public function setMetadataValue($category, $value, $lang=NULL, $mid=NULL, - $container='metadata') + public function setMetadataValue($p_category, $p_value, $p_lang=NULL, + $p_id=NULL, $p_container='metadata') { // resolve actual element: - $rows = $this->getMetadataValueWithAttrs($category, $lang); - $aktual = NULL; + $rows = $this->getMetadataValueWithAttrs($p_category, $p_lang); + $currentRow = NULL; if (count($rows) > 1) { - if (is_null($mid)) { + if (is_null($p_id)) { if (MODIFY_LAST_MATCH) { - $aktual = array_pop($rows); + $currentRow = array_pop($rows); } else { return PEAR::raiseError( - "MetaData::setMetadataValue:". - " nonunique category, mid required" - ); + "Metadata::setMetadataValue:". + " nonunique category, mid required"); } } else { foreach ($rows as $i => $row) { - if ($mid == intval($row['mid'])) { - $aktual = $row; + if ($p_id == intval($row['mid'])) { + $currentRow = $row; } } } } else { - $aktual = (isset($rows[0])? $rows[0] : NULL); + $currentRow = (isset($rows[0])? $rows[0] : NULL); } - if (!is_null($aktual)) { - $res = $this->setMetadataEl($aktual['mid'], $value); + if (!is_null($currentRow)) { + $res = $this->setMetadataElement($currentRow['mid'], $p_value); if (PEAR::isError($res)) { return $res; } - if (!is_null($lang) - && isset($aktual['attrs']['xml:lang']) - && $aktual['attrs']['xml:lang'] != $lang) { - $lg = $this->getMetadataEl('xml:lang', $aktual['mid']); + if (!is_null($p_lang) + && isset($currentRow['attrs']['xml:lang']) + && $currentRow['attrs']['xml:lang'] != $p_lang) { + $lg = $this->getMetadataElement('xml:lang', $currentRow['mid']); if (PEAR::isError($lg)) { return $lg; } if (isset($lg['mid'])) { - $res = $this->setMetadataEl($lg['mid'], $lang); + $res = $this->setMetadataElement($lg['mid'], $p_lang); if (PEAR::isError($res)) { return $res; } } else { - $res = $this->insertMetadataEl( - $aktual['mid'], 'xml:lang', $lang, 'A'); + $res = $this->insertMetadataElement( + $currentRow['mid'], 'xml:lang', $p_lang, 'A'); if (PEAR::isError($res)) { return $res; } @@ -484,22 +520,22 @@ class MetaData { } } else { // resolve container: - $contArr = $this->getMetadataValueWithAttrs($container, NULL, NULL, '_blank'); + $contArr = $this->getMetadataValueWithAttrs($p_container, NULL, NULL, '_blank'); if (PEAR::isError($contArr)) { return $contArr; } $parid = $contArr[0]['mid']; if (is_null($parid)) { return PEAR::raiseError( - "MetaData::setMetadataValue: container ($container) not found" + "MetaData::setMetadataValue: container ($p_container) not found" ); } - $nid = $this->insertMetadataEl($parid, $category, $value); + $nid = $this->insertMetadataElement($parid, $p_category, $p_value); if (PEAR::isError($nid)) { return $nid; } - if (!is_null($lang)) { - $res = $this->insertMetadataEl($nid, 'xml:lang', $lang, 'A'); + if (!is_null($p_lang)) { + $res = $this->insertMetadataElement($nid, 'xml:lang', $p_lang, 'A'); if (PEAR::isError($res) && $res->getCode()!=VAL_UNKNOWNA) { return $res; } @@ -586,18 +622,17 @@ class MetaData { * global unique id * @return boolean */ - private function dbCheck($gunid) + private function numElements($gunid) { global $CC_CONFIG, $CC_DBC; $cnt = $CC_DBC->getOne(" SELECT count(*)as cnt FROM ".$CC_CONFIG['mdataTable']." - WHERE gunid=x'$gunid'::bigint - "); + WHERE gunid=x'$gunid'::bigint"); if (PEAR::isError($cnt)) { return $cnt; } - return (intval($cnt) > 0); + return intval($cnt); } @@ -649,15 +684,15 @@ class MetaData { * * @param string $parName * parent element name - * @param string $category + * @param string $p_category * qualif. category name * @param string $predxml * 'A' | 'T' (attr or tag) - * @param string $value + * @param string $p_value * validated element value * @return true|PEAR_Error */ - private function validateOneValue($parName, $category, $predxml, $value) + private function validateOneValue($parName, $p_category, $predxml, $p_value) { global $CC_CONFIG; if ($CC_CONFIG['validate'] && !is_null($this->format)) { @@ -666,7 +701,7 @@ class MetaData { if (PEAR::isError($val)) { return $val; } - $r = $val->validateOneValue($parName, $category, $predxml, $value); + $r = $val->validateOneValue($parName, $p_category, $predxml, $p_value); if (PEAR::isError($r)) { return $r; } @@ -817,14 +852,12 @@ class MetaData { INSERT INTO ".$CC_CONFIG['mdataTable']." (id , gunid, subjns, subject, predns, predicate, predxml, - objns, object - ) + objns, object) VALUES ($id, x'{$this->gunid}'::bigint, $subjns_sql, $subject_sql, $predns_sql, $predicate_sql, '$predxml', $objns_sql, $object_sql - ) - "); + )"); if (PEAR::isError($res)) { return $res; } @@ -835,15 +868,15 @@ class MetaData { /** * Delete metadata record recursively * - * @param int $mid + * @param int $p_id * local metadata record id * @return boolean */ - private function deleteRecord($mid) + private function deleteRecord($p_id) { global $CC_CONFIG, $CC_DBC; $sql = "SELECT id FROM ".$CC_CONFIG['mdataTable']." - WHERE subjns='_I' AND subject='{$mid}' AND + WHERE subjns='_I' AND subject='{$p_id}' AND gunid=x'{$this->gunid}'::bigint"; $rh = $CC_DBC->query($sql); if (PEAR::isError($rh)) { @@ -857,7 +890,7 @@ class MetaData { } $rh->free(); $sql = "DELETE FROM ".$CC_CONFIG['mdataTable']." - WHERE id={$mid} AND + WHERE id={$p_id} AND gunid=x'{$this->gunid}'::bigint"; $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { @@ -989,7 +1022,7 @@ class MetaData { * local id of parent metadata record * @param boolean $genXML * if TRUE generate XML else PHP array for children - * @return array + * @return array|PEAR_Error * hash with three fields: * - attr hash, attributes * - children array, child nodes @@ -998,53 +1031,41 @@ class MetaData { private function getSubrows($parid, $genXML=TRUE) { global $CC_CONFIG, $CC_DBC; - if (DEBUG) { - echo" getSubrows:\n"; - } - $qh = $CC_DBC->query($q = " - SELECT - id, predxml, predns, predicate, objns, object - FROM ".$CC_CONFIG['mdataTable']." - WHERE - subjns='_I' AND subject='$parid' AND - gunid=x'{$this->gunid}'::bigint - ORDER BY id - "); - if (PEAR::isError($qh)) { - return $qh; + $sql = "SELECT id, predxml, predns, predicate, objns, object" + ." FROM ".$CC_CONFIG['mdataTable'] + ." WHERE subjns='_I' AND subject='$parid' " + ." AND gunid=x'{$this->gunid}'::bigint" + ." ORDER BY id"; + $dbResult = $CC_DBC->query($sql); + if (PEAR::isError($dbResult)) { + return $dbResult; } $attrs = array(); $children = array(); $nSpaces = array(); - if (DEBUG) { - echo " #=".$qh->numRows()."\n$q\n"; - } - while ($row = $qh->fetchRow()) { - if (DEBUG) { - var_dump($row); - } - extract($row); - switch ($predxml) { + while ($row = $dbResult->fetchRow()) { + switch ($row["predxml"]) { case "N": - $nSpaces["$predicate"] = $object; - // $nSpaces["$predicate"] = htmlentities($object, ENT_COMPAT, 'UTF-8'); + $nSpaces[$row["predicate"]] = $row["object"]; case "A": - $sep=':'; - if($predns=='' || $predicate=='') $sep=''; - $attrs["{$predns}{$sep}{$predicate}"] = $object; - // $attrs["{$predns}{$sep}{$predicate}"] = htmlentities($object, ENT_COMPAT, 'UTF-8'); + $sep = ':'; + if ($row["predns"] == '' || $row["predicate"] == '') { + $sep = ''; + } + $key = $row["predns"].$sep.$row["predicate"]; + $attrs[$key] = $row["object"]; break; case "T": $children[] = $this->genXMLNode($row, $genXML); break; default: return PEAR::raiseError( - "MetaData::getSubrows: unknown predxml ($predxml)"); + "MetaData::getSubrows: unknown predxml (".$row["predxml"].")"); } // switch } - $qh->free(); + $dbResult->free(); if ($genXML) { - $children = join(" ", $children); + $children = join(" ", $children); } return compact('attrs', 'children', 'nSpaces'); } diff --git a/campcaster/src/modules/storageServer/var/Playlist.php b/campcaster/src/modules/storageServer/var/Playlist.php index d356007c1..73c64cc54 100644 --- a/campcaster/src/modules/storageServer/var/Playlist.php +++ b/campcaster/src/modules/storageServer/var/Playlist.php @@ -17,68 +17,9 @@ require_once("StoredFile.php"); */ class Playlist extends StoredFile { - /** - * Create instance of Playlist object and recall existing file - * by gunid.
- * - * @param string $gunid - * global unique id - * @param string $className - * optional classname to recall - * @return Playlist - * instance of Playlist object - */ - public static function RecallByGunid($gunid, $className='Playlist') + public function __construct($p_gunid=NULL) { - return parent::RecallByGunid($gunid, $className); - } - - - /** - * Create instance of Playlist object and recall existing file - * by access token.
- * - * @param string $token - * access token - * @param string $className - * optional classname to recall - * @return Playlist - * instance of Playlist object - */ - public static function RecallByToken($token, $className='Playlist') - { - return parent::RecallByToken($token, $className); - } - - - /** - * Create instance of Playlist object and insert new file - * - * @param GreenBox $gb - * reference to GreenBox object - * @param int $oid - * local object id in the tree - * @param string $fname - * name of new file - * @param string $mediaFileLP - * ignored - * @param string $metadata - * local path to playlist XML file or XML string - * @param string $mdataLoc - * 'file'|'string' (optional) - * @param global $plid - * unique id (optional) - for insert file with gunid - * @param string $ftype - * ignored - * @return Playlist - * instance of Playlist object - */ - public static function &insert(&$gb, $oid, $fname, - $mediaFileLP='', $metadata='', $mdataLoc='file', - $plid=NULL, $ftype=NULL) - { - return parent::insert($gb, $oid, $fname, - '', $metadata, $mdataLoc, $plid, 'playlist', 'Playlist'); + parent::__construct($p_gunid); } @@ -95,17 +36,19 @@ class Playlist extends StoredFile { * local object id of parent folder * @return instance of Playlist object */ - public function &create(&$gb, $plid, $fname=NULL, $parid=NULL) + public function create(&$gb, $plid, $fname=NULL, $parid=NULL) { $tmpFname = uniqid(''); $oid = BasicStor::AddObj($tmpFname , 'playlist', $parid); if (PEAR::isError($oid)) { return $oid; } - $pl =& Playlist::insert($gb, $oid, '', '', - dirname(__FILE__).'/emptyPlaylist.xml', - 'file', $plid - ); + $values = array( + "id" => $oid, + "metadata" => dirname(__FILE__).'/emptyPlaylist.xml', + "gunid" => $plid, + "filetype" => "playlist"); + $pl =& StoredFile::Insert($values); if (PEAR::isError($pl)) { $res = BasicStor::RemoveObj($oid); return $pl; @@ -178,363 +121,6 @@ class Playlist extends StoredFile { } - /** - * Set values of auxiliary metadata - * - * @return mixed - * true or error object - */ - private function setAuxMetadata() - { - // get info about playlist - $plInfo = $this->getPlaylistInfo(); - if (PEAR::isError($plInfo)) { - return $plInfo; - } - extract($plInfo); // 'plLen', 'parid', 'metaParid' - // set gunid as id attr in playlist tag: - $mid = $this->_getMidOrInsert('id', $parid, $this->gunid, 'A'); - if (PEAR::isError($mid)) { - return $mid; - } - $r = $this->_setValueOrInsert( - $mid, $this->gunid, $parid, 'id', 'A'); - if (PEAR::isError($r)) { - return $r; - } - return TRUE; - } - - - /** - * Get audioClip length and title - * - * @param int $acId - * local id of audioClip inserted to playlist - * @return array with fields: - *
    - *
  • acGunid, string - audioClip gunid
  • - *
  • acLen string - length of clip in dcterms:extent format
  • - *
  • acTit string - clip title
  • - *
  • elType string - audioClip | playlist
  • - *
- */ - private function getAudioClipInfo($acId) - { - $ac = StoredFile::Recall($acId); - if (PEAR::isError($ac)) { - return $ac; - } - $acGunid = $ac->gunid; - $r = $ac->md->getMetadataEl('dcterms:extent'); - if (PEAR::isError($r)) { - return $r; - } - if (isset($r[0]['value'])) { - $acLen = $r[0]['value']; - } else { - $acLen = '00:00:00.000000'; - } - $r = $ac->md->getMetadataEl('dc:title'); - if (PEAR::isError($r)) { - return $r; - } - if (isset($r[0]['value'])) { - $acTit = $r[0]['value']; - } else { - $acTit = $acGunid; - } - $elType = BasicStor::GetObjType($acId); - $trTbl = array('audioclip'=>'audioClip', 'webstream'=>'audioClip', - 'playlist'=>'playlist'); - $elType = $trTbl[$elType]; - if ($elType == 'webstream') { - $elType = 'audioClip'; - } - return compact('acGunid', 'acLen', 'acTit', 'elType'); - } - - - /** - * Get info about playlist - * - * @return array with fields: - *
    - *
  • plLen string - length of playlist in dcterms:extent format
  • - *
  • parid int - metadata record id of playlist container
  • - *
  • metaParid int - metadata record id of metadata container
  • - *
- */ - private function getPlaylistInfo() - { - $parid = $this->getContainer('playlist'); - if (PEAR::isError($parid)) { - return $parid; - } - // get playlist length and record id: - $r = $this->md->getMetadataEl('playlength', $parid); - if (PEAR::isError($r)) { - return $r; - } - if (isset($r[0])) { - $plLen = $r[0]['value']; - } else { - $r = $this->md->getMetadataEl('dcterms:extent'); - if (PEAR::isError($r)) { - return $r; - } - if (isset($r[0])) { - $plLen = $r[0]['value']; - } else { - $plLen = '00:00:00.000000'; - } - } - // get main playlist container - $parid = $this->getContainer('playlist'); - if (PEAR::isError($parid)) { - return $parid; - } - // get metadata container (optionally insert it) - $metaParid = $this->getContainer('metadata', $parid, TRUE); - if (PEAR::isError($metaParid)) { - return $metaParid; - } - return compact('plLen', 'parid', 'metaParid'); - } - - - /** - * Get container record id, optionally insert new container - * - * @param string $containerName - * @param int $parid - * parent record id - * @param boolean $insertIfNone - flag if insert may be done - * if container wouldn't be found - * @return int - * metadata record id of container - */ - private function getContainer($containerName, $parid=NULL, $insertIfNone=FALSE) - { - $r = $this->md->getMetadataEl($containerName, $parid); - if (PEAR::isError($r)) { - return $r; - } - $id = $r[0]['mid']; - if (!is_null($id)) { - return $id; - } - if (!$insertIfNone || is_null($parid)) { - return PEAR::raiseError( - "Playlist::getContainer: can't find container ($containerName)" - ); - } - $id = $this->md->insertMetadataEl($parid, $containerName); - if (PEAR::isError($id)) { - return $id; - } - return $id; - } - - - /** - * Inserting of new playlistEelement - * - * @param int $parid - * parent record id - * @param string $offset - * relative offset in extent format - * @param string $acGunid - * audioClip gunid - * @param string $acLen - * audioClip length in extent format - * @param string $acTit - * audioClip title - * @param string $fadeIn - * fadeIn value in ss.ssssss or extent format - * @param string $fadeOut - * fadeOut value in ss.ssssss or extent format - * @param string $plElGunid - * optional playlist element gunid - * @param string $elType - * optional 'audioClip' | 'playlist' - * @return array with fields: - *
    - *
  • plElId int - record id of playlistElement
  • - *
  • plElGunid string - gl.unique id of playlistElement
  • - *
  • fadeInId int - record id
  • - *
  • fadeOutId int - record id
  • - *
- */ - private function insertPlaylistElement($parid, $offset, $acGunid, $acLen, $acTit, - $fadeIn=NULL, $fadeOut=NULL, $plElGunid=NULL, $elType='audioClip') - { - // insert playlistElement - $r = $this->md->insertMetadataEl($parid, 'playlistElement'); - if (PEAR::isError($r)) { - return $r; - } - $plElId = $r; - // create and insert gunid (id attribute) - if (is_null($plElGunid)) { - $plElGunid = StoredFile::CreateGunid(); - } - $r = $this->md->insertMetadataEl($plElId, 'id', $plElGunid, 'A'); - if (PEAR::isError($r)) { - return $r; - } - // insert relativeOffset - $r = $this->md->insertMetadataEl( - $plElId, 'relativeOffset', $offset, 'A'); - if (PEAR::isError($r)) { - return $r; - } - // insert audioClip (or playlist) element into playlistElement - $r = $this->md->insertMetadataEl($plElId, $elType); - if (PEAR::isError($r)) { - return $r; - } - $acId = $r; - $r = $this->md->insertMetadataEl($acId, 'id', $acGunid, 'A'); - if (PEAR::isError($r)) { - return $r; - } - $r = $this->md->insertMetadataEl($acId, 'playlength', $acLen, 'A'); - if (PEAR::isError($r)) { - return $r; - } - $r = $this->md->insertMetadataEl($acId, 'title', $acTit, 'A'); - if (PEAR::isError($r)) { - return $r; - } - $fadeInId=NULL; - $fadeOutId=NULL; - if (!is_null($fadeIn) || !is_null($fadeOut)) { - // insert fadeInfo element into playlistElement - $r = $this->md->insertMetadataEl($plElId, 'fadeInfo'); - if (PEAR::isError($r)) { - return $r; - } - $fiId = $r; - $fiGunid = StoredFile::CreateGunid(); - $r = $this->md->insertMetadataEl($fiId, 'id', $fiGunid, 'A'); - if (PEAR::isError($r)) { - return $r; - } - $r = $this->md->insertMetadataEl($fiId, 'fadeIn', $fadeIn, 'A'); - if (PEAR::isError($r)) { - return $r; - } - $fadeInId = $r; - $r = $this->md->insertMetadataEl($fiId, 'fadeOut', $fadeOut, 'A'); - if (PEAR::isError($r)) { - return $r; - } - $fadeOutId = $r; - } - return compact('plElId', 'plElGunid', 'fadeInId', 'fadeOutId'); - } - - - /** - * Return record id, optionally insert new record - * - * @param string $category - * qualified name of metadata category - * @param int $parid - * parent record id - * @param string $value - * value for inserted record - * @param string $predxml - * 'A' | 'T' (attribute or tag) - * @return int - * metadata record id - */ - private function _getMidOrInsert($category, $parid, $value=NULL, $predxml='T') - { - $arr = $this->md->getMetadataEl($category, $parid); - if (PEAR::isError($arr)) { - return $arr; - } - $mid = NULL; - if (isset($arr[0]['mid'])) { - $mid = $arr[0]['mid']; - } - if (!is_null($mid)) { - return $mid; - } - $mid = $this->md->insertMetadataEl($parid, $category, $value, $predxml); - if (PEAR::isError($mid)) { - return $mid; - } - return $mid; - } - - - /** - * Set value of metadata record, optionally insert new record - * - * @param int $mid - * record id - * @param string $value - * value for inserted record - * @param int $parid - * parent record id - * @param string $category - * qualified name of metadata category - * @param string $predxml - * 'A' | 'T' (attribute or tag) - * @return boolean - */ - private function _setValueOrInsert($mid, $value, $parid, $category, $predxml='T') - { - if (is_null($mid)) { - $r = $this->md->insertMetadataEl( - $parid, $category, $value, $predxml); - } else { - $r = $this->md->setMetadataEl($mid, $value); - } - if (PEAR::isError($r)) { - return $r; - } - return TRUE; - } - - - /** - * Set playlist length - dcterm:extent - * - * @param string $newPlLen - * new length in extent format - * @param int $parid - * playlist container record id - * @param int $metaParid - * metadata container record id - * @return boolean - */ - private function setPlaylistLength($newPlLen, $parid, $metaParid) - { - $mid = $this->_getMidOrInsert('playlength', $parid, $newPlLen, 'A'); - if (PEAR::isError($mid)) { - return $mid; - } - $r = $this->_setValueOrInsert( - $mid, $newPlLen, $parid, 'playlength', 'A'); - if (PEAR::isError($r)) { - return $r; - } - $mid = $this->_getMidOrInsert('dcterms:extent', $metaParid, $newPlLen); - if (PEAR::isError($mid)) { - return $mid; - } - $r = $this->_setValueOrInsert( - $mid, $newPlLen, $metaParid, 'dcterms:extent'); - if (PEAR::isError($r)) { - return $r; - } - return TRUE; - } - /** * Add audioClip specified by local id to the playlist * @@ -602,30 +188,30 @@ class Playlist extends StoredFile { extract($plInfo); // 'plLen', 'parid', 'metaParid' // get array of playlist elements: - $plElArr = $this->md->getMetadataEl('playlistElement', $parid); + $plElArr = $this->md->getMetadataElement('playlistElement', $parid); if (PEAR::isError($plElArr)) { return $plElArr; } $found = FALSE; foreach ($plElArr as $el) { - $plElGunidArr = $this->md->getMetadataEl('id', $el['mid']); + $plElGunidArr = $this->md->getMetadataElement('id', $el['mid']); if (PEAR::isError($plElGunidArr)) { return $plElGunidArr; } // select playlist element to remove if ($plElGunidArr[0]['value'] == $plElGunid) { - $acArr = $this->md->getMetadataEl('audioClip', $el['mid']); + $acArr = $this->md->getMetadataElement('audioClip', $el['mid']); if (PEAR::isError($acArr)) { return $acArr; } $storedAcMid = $acArr[0]['mid']; - $acLenArr = $this->md->getMetadataEl('playlength', $storedAcMid); + $acLenArr = $this->md->getMetadataElement('playlength', $storedAcMid); if (PEAR::isError($acLenArr)) { return $acLenArr; } $acLen = $acLenArr[0]['value']; // remove playlist element: - $r = $this->md->setMetadataEl($el['mid'], NULL); + $r = $this->md->setMetadataElement($el['mid'], NULL); if (PEAR::isError($r)) { return $r; } @@ -664,13 +250,13 @@ class Playlist extends StoredFile { extract($plInfo); // 'plLen', 'parid', 'metaParid' // get array of playlist elements: - $plElArr = $this->md->getMetadataEl('playlistElement', $parid); + $plElArr = $this->md->getMetadataElement('playlistElement', $parid); if (PEAR::isError($plElArr)) { return $plElArr; } $found = FALSE; foreach ($plElArr as $el) { - $plElGunidArr = $this->md->getMetadataEl('id', $el['mid']); + $plElGunidArr = $this->md->getMetadataElement('id', $el['mid']); if (PEAR::isError($plElGunidArr)) { return $plElGunidArr; } @@ -754,11 +340,11 @@ class Playlist extends StoredFile { $fadeOut = NULL; foreach ($el['children'] as $j => $af) { switch ($af['elementname']) { - case"audioClip": - case"playlist": + case "audioClip": + case "playlist": $acGunid = $af['attrs']['id']; break; - case"fadeInfo": + case "fadeInfo": $fadeIn = $af['attrs']['fadeIn']; $fadeOut = $af['attrs']['fadeOut']; break; @@ -788,7 +374,7 @@ class Playlist extends StoredFile { /** - * Recalculate total length of playlist and relativeOffset values + * Recalculate total length of playlist and relativeOffset values * of all playlistElements according to legth and fadeIn values. * FadeOut values adjusted to next fadeIn. * @@ -804,7 +390,7 @@ class Playlist extends StoredFile { } extract($plInfo); // 'plLen', 'parid', 'metaParid' // get array of playlist elements: - $plElArr = $this->md->getMetadataEl('playlistElement', $parid); + $plElArr = $this->md->getMetadataElement('playlistElement', $parid); if (PEAR::isError($plElArr)) { return $plElArr; } @@ -816,46 +402,46 @@ class Playlist extends StoredFile { foreach ($plElArr as $el) { $elId = $el['mid']; // get playlistElement gunid: - $plElGunidArr = $this->md->getMetadataEl('id', $elId); + $plElGunidArr = $this->md->getMetadataElement('id', $elId); if (PEAR::isError($plElGunidArr)) { return $plElGunidArr; } $plElGunid = $plElGunidArr[0]['value']; // get relativeOffset: - $offArr = $this->md->getMetadataEl('relativeOffset', $elId); + $offArr = $this->md->getMetadataElement('relativeOffset', $elId); if (PEAR::isError($offArr)) { return $offArr; } $offsetId = $offArr[0]['mid']; $offset = $offArr[0]['value']; // get audioClip: - $acArr = $this->md->getMetadataEl('audioClip', $elId); + $acArr = $this->md->getMetadataElement('audioClip', $elId); if (is_array($acArr) && (!isset($acArr[0]) || is_null($acArr[0]))) { - $acArr = $this->md->getMetadataEl('playlist', $elId); + $acArr = $this->md->getMetadataElement('playlist', $elId); } if (PEAR::isError($acArr)) { return $acArr; } $storedAcMid = $acArr[0]['mid']; // get playlength: - $acLenArr = $this->md->getMetadataEl('playlength', $storedAcMid); + $acLenArr = $this->md->getMetadataElement('playlength', $storedAcMid); if (PEAR::isError($acLenArr)) { return $acLenArr; } $acLen = $acLenArr[0]['value']; // get fadeInfo: - $fiArr = $this->md->getMetadataEl('fadeInfo', $elId); + $fiArr = $this->md->getMetadataElement('fadeInfo', $elId); if (PEAR::isError($fiArr)) { return $fiArr; } if (isset($fiArr[0]['mid'])) { $fiMid = $fiArr[0]['mid']; - $fadeInArr = $this->md->getMetadataEl('fadeIn', $fiMid); + $fadeInArr = $this->md->getMetadataElement('fadeIn', $fiMid); if (PEAR::isError($fadeInArr)) { return $fadeInArr; } $fadeIn = $fadeInArr[0]['value']; - $fadeOutArr = $this->md->getMetadataEl('fadeOut', $fiMid); + $fadeOutArr = $this->md->getMetadataElement('fadeOut', $fiMid); if (PEAR::isError($fadeOutArr)) { return $fadeOutArr; } @@ -956,7 +542,7 @@ class Playlist extends StoredFile { if ($found) { // we've found offset switch ($el['type']) { case "playlist": - $pl = Playlist::RecallByGunid($acGunid); + $pl = StoredFile::RecallByGunid($acGunid); if (PEAR::isError($pl)) { return $pl; } @@ -1033,7 +619,7 @@ class Playlist extends StoredFile { extract($el); // acLen, elOffset, acGunid, fadeIn, fadeOut, playlist switch ($el['type']) { case "playlist": - $pl = Playlist::RecallByGunid($acGunid); + $pl = StoredFile::RecallByGunid($acGunid); if (PEAR::isError($pl)) { return $pl; } @@ -1105,7 +691,7 @@ class Playlist extends StoredFile { if ($this->gunid == $insGunid) { return TRUE; } - $pl = Playlist::RecallByGunid($insGunid); + $pl = StoredFile::RecallByGunid($insGunid); if (PEAR::isError($pl)) { return $pl; } @@ -1135,11 +721,470 @@ class Playlist extends StoredFile { return FALSE; } + + /** + * Export playlist as simplified SMIL XML file. + * + * @param boolean $toString + * if false don't real export, + * return misc info about playlist only + * @return string + * XML string or hasharray with misc info + */ + public function outputToSmil($toString=TRUE) + { + $plGunid = $this->gunid; + $arr = $this->md->genPhpArray(); + if (PEAR::isError($arr)) { + return $arr; + } + if ($toString) { + $r = PlaylistTagExport::OutputToSmil($this, $arr); + if (PEAR::isError($r)) { + return $r; + } + return $r; + } else { + return array( + 'type' => 'playlist', + 'gunid' => $plGunid, + 'src' => PL_URL_RELPATH."$plGunid.smil", + 'playlength' => $arr['attrs']['playlength'], + ); + } + } + + + /** + * Export playlist as M3U file. + * + * @param boolean $toString + * if false don't real export, + * return misc info about playlist only + * @return string|array + * M3U string or hasharray with misc info + */ + public function outputToM3u($toString=TRUE) + { + $plGunid = $this->gunid; + $arr = $this->md->genPhpArray(); + if (PEAR::isError($arr)) { + return $arr; + } + if ($toString) { + $r = PlaylistTagExport::OutputToM3u($this, $arr); + if (PEAR::isError($r)) { + return $r; + } + return $r; + } else { + return array( + 'type' => 'playlist', + 'gunid' => $plGunid, + 'uri' => PL_URL_RELPATH."$plGunid.m3u", + 'playlength' => $arr['attrs']['playlength'], + 'title' => $arr['attrs']['title'], + ); + } + } + + + /** + * Export playlist as RSS XML file + * + * @param boolean $toString + * if false don't really export, + * return misc info about playlist only + * @return mixed + * XML string or hasharray with misc info + */ + public function outputToRss($toString=TRUE) + { + $plGunid = $this->gunid; + $arr = $this->md->genPhpArray(); + if (PEAR::isError($arr)) { + return $arr; + } + if ($toString) { + $r = PlaylistTagExport::OutputToRss($this, $arr); + if (PEAR::isError($r)) { + return $r; + } + return $r; + } else { + return array( + 'type' => 'playlist', + 'gunid' => $plGunid, + 'src' => PL_URL_RELPATH."$plGunid.smil", + 'playlength' => $arr['attrs']['playlength'], + ); + } + } + + + /** + * Set values of auxiliary metadata + * + * @return mixed + * true or error object + */ + private function setAuxMetadata() + { + // get info about playlist + $plInfo = $this->getPlaylistInfo(); + if (PEAR::isError($plInfo)) { + return $plInfo; + } + extract($plInfo); // 'plLen', 'parid', 'metaParid' + // set gunid as id attr in playlist tag: + $mid = $this->_getMidOrInsert('id', $parid, $this->gunid, 'A'); + if (PEAR::isError($mid)) { + return $mid; + } + $r = $this->_setValueOrInsert( + $mid, $this->gunid, $parid, 'id', 'A'); + if (PEAR::isError($r)) { + return $r; + } + return TRUE; + } + + + /** + * Get audioClip length and title + * + * @param int $acId + * local id of audioClip inserted to playlist + * @return array with fields: + *
    + *
  • acGunid, string - audioClip gunid
  • + *
  • acLen string - length of clip in dcterms:extent format
  • + *
  • acTit string - clip title
  • + *
  • elType string - audioClip | playlist
  • + *
+ */ + private function getAudioClipInfo($acId) + { + $ac = StoredFile::Recall($acId); + if (PEAR::isError($ac)) { + return $ac; + } + $acGunid = $ac->gunid; + $r = $ac->md->getMetadataElement('dcterms:extent'); + if (PEAR::isError($r)) { + return $r; + } + if (isset($r[0]['value'])) { + $acLen = $r[0]['value']; + } else { + $acLen = '00:00:00.000000'; + } + $r = $ac->md->getMetadataElement('dc:title'); + if (PEAR::isError($r)) { + return $r; + } + if (isset($r[0]['value'])) { + $acTit = $r[0]['value']; + } else { + $acTit = $acGunid; + } + $elType = BasicStor::GetObjType($acId); + $trTbl = array('audioclip'=>'audioClip', 'webstream'=>'audioClip', + 'playlist'=>'playlist'); + $elType = $trTbl[$elType]; + if ($elType == 'webstream') { + $elType = 'audioClip'; + } + return compact('acGunid', 'acLen', 'acTit', 'elType'); + } + + + /** + * Get info about playlist + * + * @return array with fields: + *
    + *
  • plLen string - length of playlist in dcterms:extent format
  • + *
  • parid int - metadata record id of playlist container
  • + *
  • metaParid int - metadata record id of metadata container
  • + *
+ */ + private function getPlaylistInfo() + { + $parid = $this->getContainer('playlist'); + if (PEAR::isError($parid)) { + return $parid; + } + // get playlist length and record id: + $r = $this->md->getMetadataElement('playlength', $parid); + if (PEAR::isError($r)) { + return $r; + } + if (isset($r[0])) { + $plLen = $r[0]['value']; + } else { + $r = $this->md->getMetadataElement('dcterms:extent'); + if (PEAR::isError($r)) { + return $r; + } + if (isset($r[0])) { + $plLen = $r[0]['value']; + } else { + $plLen = '00:00:00.000000'; + } + } + // get main playlist container + $parid = $this->getContainer('playlist'); + if (PEAR::isError($parid)) { + return $parid; + } + // get metadata container (optionally insert it) + $metaParid = $this->getContainer('metadata', $parid, TRUE); + if (PEAR::isError($metaParid)) { + return $metaParid; + } + return compact('plLen', 'parid', 'metaParid'); + } + + + /** + * Get container record id, optionally insert new container + * + * @param string $containerName + * @param int $parid + * parent record id + * @param boolean $insertIfNone - flag if insert may be done + * if container wouldn't be found + * @return int + * metadata record id of container + */ + private function getContainer($containerName, $parid=NULL, $insertIfNone=FALSE) + { + $r = $this->md->getMetadataElement($containerName, $parid); + if (PEAR::isError($r)) { + return $r; + } + $id = $r[0]['mid']; + if (!is_null($id)) { + return $id; + } + if (!$insertIfNone || is_null($parid)) { + return PEAR::raiseError( + "Playlist::getContainer: can't find container ($containerName)" + ); + } + $id = $this->md->insertMetadataElement($parid, $containerName); + if (PEAR::isError($id)) { + return $id; + } + return $id; + } + + + /** + * Insert a new playlist element. + * + * @param int $parid + * parent record id + * @param string $offset + * relative offset in extent format + * @param string $acGunid + * audioClip gunid + * @param string $acLen + * audioClip length in extent format + * @param string $acTit + * audioClip title + * @param string $fadeIn + * fadeIn value in ss.ssssss or extent format + * @param string $fadeOut + * fadeOut value in ss.ssssss or extent format + * @param string $plElGunid + * optional playlist element gunid + * @param string $elType + * optional 'audioClip' | 'playlist' + * @return array with fields: + *
    + *
  • plElId int - record id of playlistElement
  • + *
  • plElGunid string - gl.unique id of playlistElement
  • + *
  • fadeInId int - record id
  • + *
  • fadeOutId int - record id
  • + *
+ */ + private function insertPlaylistElement($parid, $offset, $acGunid, $acLen, $acTit, + $fadeIn=NULL, $fadeOut=NULL, $plElGunid=NULL, $elType='audioClip') + { + // insert playlistElement + $r = $this->md->insertMetadataElement($parid, 'playlistElement'); + if (PEAR::isError($r)) { + return $r; + } + $plElId = $r; + // create and insert gunid (id attribute) + if (is_null($plElGunid)) { + $plElGunid = StoredFile::CreateGunid(); + } + $r = $this->md->insertMetadataElement($plElId, 'id', $plElGunid, 'A'); + if (PEAR::isError($r)) { + return $r; + } + // insert relativeOffset + $r = $this->md->insertMetadataElement( + $plElId, 'relativeOffset', $offset, 'A'); + if (PEAR::isError($r)) { + return $r; + } + // insert audioClip (or playlist) element into playlistElement + $r = $this->md->insertMetadataElement($plElId, $elType); + if (PEAR::isError($r)) { + return $r; + } + $acId = $r; + $r = $this->md->insertMetadataElement($acId, 'id', $acGunid, 'A'); + if (PEAR::isError($r)) { + return $r; + } + $r = $this->md->insertMetadataElement($acId, 'playlength', $acLen, 'A'); + if (PEAR::isError($r)) { + return $r; + } + $r = $this->md->insertMetadataElement($acId, 'title', $acTit, 'A'); + if (PEAR::isError($r)) { + return $r; + } + $fadeInId=NULL; + $fadeOutId=NULL; + if (!is_null($fadeIn) || !is_null($fadeOut)) { + // insert fadeInfo element into playlistElement + $r = $this->md->insertMetadataElement($plElId, 'fadeInfo'); + if (PEAR::isError($r)) { + return $r; + } + $fiId = $r; + $fiGunid = StoredFile::CreateGunid(); + $r = $this->md->insertMetadataElement($fiId, 'id', $fiGunid, 'A'); + if (PEAR::isError($r)) { + return $r; + } + $r = $this->md->insertMetadataElement($fiId, 'fadeIn', $fadeIn, 'A'); + if (PEAR::isError($r)) { + return $r; + } + $fadeInId = $r; + $r = $this->md->insertMetadataElement($fiId, 'fadeOut', $fadeOut, 'A'); + if (PEAR::isError($r)) { + return $r; + } + $fadeOutId = $r; + } + return compact('plElId', 'plElGunid', 'fadeInId', 'fadeOutId'); + } + + + /** + * Return record id, optionally insert new record + * + * @param string $category + * qualified name of metadata category + * @param int $parid + * parent record id + * @param string $value + * value for inserted record + * @param string $predxml + * 'A' | 'T' (attribute or tag) + * @return int + * metadata record id + */ + private function _getMidOrInsert($category, $parid, $value=NULL, $predxml='T') + { + $arr = $this->md->getMetadataElement($category, $parid); + if (PEAR::isError($arr)) { + return $arr; + } + $mid = NULL; + if (isset($arr[0]['mid'])) { + $mid = $arr[0]['mid']; + } + if (!is_null($mid)) { + return $mid; + } + $mid = $this->md->insertMetadataElement($parid, $category, $value, $predxml); + if (PEAR::isError($mid)) { + return $mid; + } + return $mid; + } + + + /** + * Set value of metadata record, optionally insert new record + * + * @param int $mid + * record id + * @param string $value + * value for inserted record + * @param int $parid + * parent record id + * @param string $category + * qualified name of metadata category + * @param string $predxml + * 'A' | 'T' (attribute or tag) + * @return boolean + */ + private function _setValueOrInsert($mid, $value, $parid, $category, $predxml='T') + { + if (is_null($mid)) { + $r = $this->md->insertMetadataElement( + $parid, $category, $value, $predxml); + } else { + $r = $this->md->setMetadataElement($mid, $value); + } + if (PEAR::isError($r)) { + return $r; + } + return TRUE; + } + + + /** + * Set playlist length - dcterm:extent + * + * @param string $newPlLen + * new length in extent format + * @param int $parid + * playlist container record id + * @param int $metaParid + * metadata container record id + * @return boolean + */ + private function setPlaylistLength($newPlLen, $parid, $metaParid) + { + $mid = $this->_getMidOrInsert('playlength', $parid, $newPlLen, 'A'); + if (PEAR::isError($mid)) { + return $mid; + } + $r = $this->_setValueOrInsert( + $mid, $newPlLen, $parid, 'playlength', 'A'); + if (PEAR::isError($r)) { + return $r; + } + $mid = $this->_getMidOrInsert('dcterms:extent', $metaParid, $newPlLen); + if (PEAR::isError($mid)) { + return $mid; + } + $r = $this->_setValueOrInsert( + $mid, $newPlLen, $metaParid, 'dcterms:extent'); + if (PEAR::isError($r)) { + return $r; + } + return TRUE; + } + } // class Playlist /** * Auxiliary class for GB playlist editing methods + * * @author Tomas Hlava * @author Paul Baranowski * @copyright 2006 MDLF, Inc. @@ -1152,7 +1197,7 @@ class PlaylistElement { public function PlaylistElement(&$pl, $plEl) { - $this->pl = $pl; + $this->pl = $pl; $this->plEl = $plEl; } @@ -1198,4 +1243,446 @@ class PlaylistElement { } } // class PlaylistElement + +/** + * @author Tomas Hlava + * @author Paul Baranowski + * @package Campcaster + * @subpackage StorageServer + * @copyright 2006 MDLF, Inc. + * @license http://www.gnu.org/licenses/gpl.txt + * @link http://www.campware.org + * @todo Rename this class PlaylistTag + */ +class PlaylistTagExport +{ + public static function OutputToSmil(&$pl, $plt, $ind='') + { + $ind2 = $ind.INDCH; + $ind3 = $ind2.INDCH; + $ind4 = $ind3.INDCH; + $res = ""; + foreach ($plt['children'] as $ple) { + switch ($ple['elementname']) { + case "playlistElement": + $r = PlaylistElementExport::OutputToSmil($pl, $ple, $ind4); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } + break; + case "metadata": + $r = PlaylistMetadataExport::OutputToSmil($pl, $ple, $ind4); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } + break; + default: + } + } + $res = "$ind\n". + "$ind\n". + "$ind2\n". + "$ind3\n". + "$res". + "$ind3\n". + "$ind2\n". + "$ind\n"; + return $res; + } + + + public static function OutputToM3u(&$pl, $plt, $ind='') + { + $res = ""; + foreach ($plt['children'] as $ple) { + switch ($ple['elementname']) { + case"playlistElement": + $r = PlaylistElementExport::OutputToM3u($pl, $ple); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } + break; + } + } + $res = "#EXTM3U\n$res"; + return $res; + } + + + public static function OutputToRss(&$pl, $plt, $ind='') + { + $ind2 = $ind.INDCH; + $ind3 = $ind2.INDCH; + $res = ""; + foreach ($plt['children'] as $ple) { + switch ($ple['elementname']) { + case "playlistElement": + $r = PlaylistElementExport::OutputToRss($pl, $ple, $ind3); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } + break; + case "metadata": + $r = PlaylistMetadataExport::OutputToRss($pl, $ple, $ind3); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } + break; + default: + } + } + $res = "$ind\n". + "$ind\n". + "$ind2\n". + "$res". + "$ind2\n". + "$ind\n"; + return $res; + } +} + + +/** + * @author Tomas Hlava + * @author Paul Baranowski + * @package Campcaster + * @subpackage StorageServer + * @copyright 2006 MDLF, Inc. + * @license http://www.gnu.org/licenses/gpl.txt + * @link http://www.campware.org + * @todo Rename this class "PlaylistElement" + */ +class PlaylistElementExport { + + public static function OutputToSmil(&$pl, $ple, $ind='') + { + $acOrPl = NULL; + $finfo = array('fi'=>0, 'fo'=>0); + $ind2 = $ind.INDCH; + $ind3 = $ind2.INDCH; + $anim = ''; + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { + case "audioClip": + $r = PlaylistAudioClipExport::OutputToSmil($pl, $ac, $ind2); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } + break; + case "playlist": + $gunid = $ac['attrs']['id']; + $pl2 = StoredFile::RecallByGunid($gunid); + if (PEAR::isError($pl2)) { + return $pl2; + } + $r = $pl2->outputToSmil(FALSE); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } + break; + case "fadeInfo": + $r = PlaylistFadeInfoExport::OutputToSmil($pl, $ac, $ind2); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $finfo = $r; + } + break; + default: + return PEAR::raiseError( + "PlaylistElementExport::OutputToSmil:". + " unknown tag {$ac['elementname']}" + ); + } + } + $beginS = Playlist::playlistTimeToSeconds($ple['attrs']['relativeOffset']); + $playlengthS = Playlist::playlistTimeToSeconds($acOrPl['playlength']); + $fadeOutS = Playlist::playlistTimeToSeconds($finfo['fo']); + $fiBeginS = 0; + $fiEndS = Playlist::playlistTimeToSeconds($finfo['fi']); + $foBeginS = ($playlengthS - $fadeOutS); + $foEndS = Playlist::playlistTimeToSeconds($acOrPl['playlength']); + foreach (array('fi','fo') as $ff) { + if (${$ff."EndS"} - ${$ff."BeginS"} > 0) { + $anim .= "{$ind2}\n" + ; + } + } + $src = $acOrPl['src']; + $str = "$ind" : " />"). + " ". + "\n"; + return $str; + } + + + public static function OutputToM3u(&$pl, $ple, $ind='') + { + $acOrPl = NULL; + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { + case "audioClip": + $r = PlaylistAudioClipExport::OutputToM3u($pl, $ac); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } + break; + case "playlist": + $gunid = $ac['attrs']['id']; + $pl2 = StoredFile::RecallByGunid($gunid); + if (PEAR::isError($pl2)) { + return $pl2; + } + $r = $pl2->outputToM3u(FALSE); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } + break; + } + } + if (is_null($acOrPl)) { + return ''; + } + $playlength = ceil(Playlist::playlistTimeToSeconds($acOrPl['playlength'])); + $title = $acOrPl['title']; + $uri = (isset($acOrPl['uri']) ? $acOrPl['uri'] : '???' ); + $res = "#EXTINF: $playlength, $title\n"; + $res .= "$uri\n"; + return $res; + } + + + public static function OutputToRss(&$pl, $ple, $ind='') + { + $acOrPl = NULL; + $ind2 = $ind.INDCH; + $anim = ''; + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { + case "audioClip": + $r = PlaylistAudioClipExport::OutputToRss($pl, $ac, $ind2); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } + break; + case "playlist": + $gunid = $ac['attrs']['id']; + $pl2 = StoredFile::RecallByGunid($gunid); + if (PEAR::isError($pl2)) { + return $pl2; + } + $r = $pl2->outputToRss(FALSE); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } + break; + case "fadeInfo": + break; + default: + return PEAR::raiseError( + "PlaylistElementExport::OutputToRss:". + " unknown tag {$ac['elementname']}" + ); + } + } + $title = (isset($acOrPl['title']) ? htmlspecialchars($acOrPl['title']) : '' ); + $desc = (isset($acOrPl['desc']) ? htmlspecialchars($acOrPl['desc']) : '' ); + $link = htmlspecialchars($acOrPl['src']); + $desc = ''; + $str = "$ind\n". + "$ind2$title\n". + "$ind2$desc\n". + "$ind2$link\n". + "$ind\n"; + return $str; + } +} + + +/** + * @author Tomas Hlava + * @author Paul Baranowski + * @package Campcaster + * @subpackage StorageServer + * @copyright 2006 MDLF, Inc. + * @license http://www.gnu.org/licenses/gpl.txt + * @link http://www.campware.org + * @todo Rename this class to PlaylistAudioClip (notice the caps) + */ +class PlaylistAudioClipExport +{ + + public static function OutputToSmil(&$pl, $plac, $ind='') + { + $gunid = $plac['attrs']['id']; + $ac = StoredFile::RecallByGunid($gunid); + if (PEAR::isError($ac)) { + return $ac; + } + $RADext = $ac->getFileExtension(); + if (PEAR::isError($RADext)) { + return $RADext; + } + return array( + 'type' => 'audioclip', + 'gunid' => $gunid, + 'src' => AC_URL_RELPATH."$gunid.$RADext", + 'playlength' => $plac['attrs']['playlength'], + ); + } + + + public static function OutputToM3u(&$pl, $plac, $ind='') + { + $gunid = $plac['attrs']['id']; + $ac = StoredFile::RecallByGunid($gunid); + if (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 OutputToRss(&$pl, $plac, $ind='') + { + $gunid = $plac['attrs']['id']; + $ac = StoredFile::RecallByGunid($gunid); + if (PEAR::isError($ac)) { + return $ac; + } + $RADext = $ac->getFileExtension(); + if (PEAR::isError($RADext)) { + return $RADext; + } + $title = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:title'); + $desc = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:description'); + return array( + 'type' => 'audioclip', + 'gunid' => $gunid, + 'src' => "http://XXX/YY/$gunid.$RADext", + 'playlength' => $plac['attrs']['playlength'], + 'title' => $title, + 'desc' => $desc, + ); + } +} + + +/** + * @author Tomas Hlava + * @author Paul Baranowski + * @package Campcaster + * @subpackage StorageServer + * @copyright 2006 MDLF, Inc. + * @license http://www.gnu.org/licenses/gpl.txt + * @link http://www.campware.org + * @todo Rename this class "PlaylistFadeInfo" (notive the caps) + */ +class PlaylistFadeInfoExport +{ + + public static function OutputToSmil(&$pl, $plfi, $ind='') + { + $r = array( + 'fi'=>$plfi['attrs']['fadeIn'], + 'fo'=>$plfi['attrs']['fadeOut'], + ); + return $r; + } + + + public static function OutputToM3u(&$pl, $plfa, $ind='') + { + return ''; + } + + + public static function OutputToRss(&$pl, $plfa, $ind='') + { + return ''; + } + +} + + +/** + * @author Tomas Hlava + * @author Paul Baranowski + * @package Campcaster + * @subpackage StorageServer + * @copyright 2006 MDLF, Inc. + * @license http://www.gnu.org/licenses/gpl.txt + * @link http://www.campware.org + * @todo Rename this class to PlaylistMetadata (notice the caps) + */ +class PlaylistMetadataExport +{ + public static function OutputToSmil(&$pl, $md, $ind='') + { + return NULL; + } + + + public static function OutputToM3u(&$pl, $md, $ind='') + { + return NULL; + } + + + public static function OutputToRss(&$pl, $md, $ind='') + { + return NULL; + } +} + ?> \ No newline at end of file diff --git a/campcaster/src/modules/storageServer/var/Renderer.php b/campcaster/src/modules/storageServer/var/Renderer.php index e8ed75900..c68424930 100644 --- a/campcaster/src/modules/storageServer/var/Renderer.php +++ b/campcaster/src/modules/storageServer/var/Renderer.php @@ -1,7 +1,7 @@ \n \n$mdata \n\n"; //$mdata = "\n \n$mdata0\n\n\n"; - $id = $gb->bsPutFile($parid, $fileName, $realOgg, $mdata, - NULL, 'audioclip', 'string'); - if (PEAR::isError($id)) { - return $id; + $values = array( + "filename" => $fileName, + "filepath" => $realOgg, + "metadata" => $mdata, + "filetype" => "audioclip" + ); + $storedFile = $gb->bsPutFile($parid, $values); + if (PEAR::isError($storedFile)) { + return $storedFile; } - $ac = StoredFile::Recall($id); - if (PEAR::isError($ac)) { - return $ac; - } - return array('gunid' => $ac->gunid); + return array('gunid' => $storedFile->getGunid()); } diff --git a/campcaster/src/modules/storageServer/var/Restore.php b/campcaster/src/modules/storageServer/var/Restore.php index 8c0b9143f..94412f32f 100644 --- a/campcaster/src/modules/storageServer/var/Restore.php +++ b/campcaster/src/modules/storageServer/var/Restore.php @@ -312,16 +312,15 @@ class Restore { "$parid, $name, $mediaFileLP, $file, {$this->sessid}, $gunid, $type \n" ); } - $put = $this->gb->putFile( - $parid, # parent id - $name, # name of original file - $mediaFileLP, # media file if have - $file, # meta file - $this->sessid, # sessid - $gunid, # gunid - $type # type + $values = array( + "filename" => $name, + "filepath" => $mediaFileLP, + "metadata" => $file, + "gunid" => $gunid, + "filetype" => $type ); - # $this->addLogItem("add as new \n"); + $put = $this->gb->putFile($parid, $values, $this->sessid); + //$this->addLogItem("add as new \n"); if (PEAR::isError($put)) { $this->addLogItem("-E- ".date("Ymd-H:i:s"). " addFileToStorage - putFile Error ". diff --git a/campcaster/src/modules/storageServer/var/SmilPlaylist.php b/campcaster/src/modules/storageServer/var/SmilPlaylist.php index 61cdbbca4..bf4404ec2 100644 --- a/campcaster/src/modules/storageServer/var/SmilPlaylist.php +++ b/campcaster/src/modules/storageServer/var/SmilPlaylist.php @@ -266,7 +266,7 @@ class SmilPlaylistAudioElement { if (PEAR::isError($ac)) { return $ac; } - $r = $ac->md->getMetadataEl('dcterms:extent'); + $r = $ac->md->getMetadataElement('dcterms:extent'); if (PEAR::isError($r)) { return $r; } diff --git a/campcaster/src/modules/storageServer/var/StoredFile.php b/campcaster/src/modules/storageServer/var/StoredFile.php index 3ecdee4d9..23587f796 100644 --- a/campcaster/src/modules/storageServer/var/StoredFile.php +++ b/campcaster/src/modules/storageServer/var/StoredFile.php @@ -57,13 +57,12 @@ function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859 * For diagnostic and debugging purposes - setting this to TRUE * will print out the values found in the file and the ones assigned * to the return array. - * @return array/PEAR_Error + * @return array|PEAR_Error */ function camp_get_audio_metadata($p_filename, $p_testonly = false) { $getID3 = new getID3(); $infoFromFile = $getID3->analyze($p_filename); - //echo "\n".var_export($infoFromFile)."\n"; exit; if (PEAR::isError($infoFromFile)) { return $infoFromFile; } @@ -79,16 +78,45 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) } $titleKey = 'dc:title'; $flds = array( - 'dc:format' => array( + 'dc:format' => array( array('path'=>"['mime_type']", 'ignoreEnc'=>TRUE), ), - 'ls:bitrate' => array( + 'ls:bitrate' => array( array('path'=>"['bitrate']", 'ignoreEnc'=>TRUE), + array('path'=>"['audio']['bitrate']", 'ignoreEnc'=>TRUE), + ), + 'ls:samplerate' => array( + array('path'=>"['audio']['sample_rate']", 'ignoreEnc'=>TRUE), + ), + 'ls:encoder' => array( + array('path'=>"['audio']['codec']", 'ignoreEnc'=>TRUE), ), 'dcterms:extent'=> array( array('path'=>"['playtime_seconds']", 'ignoreEnc'=>TRUE), ), - 'dc:title' => array( + 'ls:composer'=> array( + array('path'=>"['id3v2']['comments']['composer']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['id3v2']['TCOM'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['id3v2']['composer']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['ogg']['comments']['composer']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['composer']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:description'=> array( + array('path'=>"['id3v1']['comments']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['comments']['comments']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['id3v2']['COMM'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['id3v2']['comments']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['ogg']['comments']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:type'=> array( + array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:title' => array( array('path'=>"['id3v2']['comments']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TIT2'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TT2'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), @@ -96,7 +124,7 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) array('path'=>"['ogg']['comments']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['tags']['vorbiscomment']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), ), - 'dc:creator' => array( + 'dc:creator' => array( array('path'=>"['id3v2']['comments']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TPE1'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TP1'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), @@ -104,7 +132,7 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) array('path'=>"['ogg']['comments']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['tags']['vorbiscomment']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), ), - 'dc:source' => array( + 'dc:source' => array( array('path'=>"['id3v2']['comments']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TALB'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TAL'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), @@ -117,36 +145,30 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) array('path'=>"['ogg']['comments']['encoded-by']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['tags']['vorbiscomment']['encoded-by']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), ), - 'ls:track_num' => array( + 'ls:track_num' => array( array('path'=>"['id3v2']['TRCK'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), array('path'=>"['id3v2']['TRK'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), array('path'=>"['ogg']['comments']['tracknumber']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['tags']['vorbiscomment']['tracknumber']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), ), - 'ls:genre' => array( - array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'ls:channels' => array( +// 'ls:genre' => array( +// array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), +// array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), +// array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), +// array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), +// array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), +// ), + 'ls:channels' => array( array('path'=>"['audio']['channels']", 'ignoreEnc'=>TRUE), ), - 'ls:year' => array( + 'ls:year' => array( array('path'=>"['comments']['date']"), array('path'=>"['ogg']['comments']['date']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), array('path'=>"['tags']['vorbiscomment']['date']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), ), - 'ls:filename' => array( + 'ls:filename' => array( array('path'=>"['filename']"), ), - /* - 'xx:fileformat' => array(array('path'=>"['fileformat']")), - 'xx:filesize' => array(array('path'=>"['filesize']")), - 'xx:dataformat' => array(array('path'=>"['audio']['dataformat']")), - 'xx:sample_rate'=> array(array('path'=>"['audio']['sample_rate']")), - */ ); $mdata = array(); if (isset($infoFromFile['audio'])) { @@ -158,9 +180,6 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) $titleHaveSet = FALSE; foreach ($flds as $key => $getid3keys) { - if ($p_testonly) { - echo "$key\n"; - } foreach ($getid3keys as $getid3key) { $path = $getid3key["path"]; $ignoreEnc = isset($getid3key["ignoreEnc"])?$getid3key["ignoreEnc"]:FALSE; @@ -168,35 +187,22 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) $encPath = isset($getid3key["encPath"])?$getid3key["encPath"]:""; $enc = "UTF-8"; - $vn = "\$infoFromFile$path$dataPath"; - if ($p_testonly) { - echo " $vn -> "; - } - eval("\$vnFl = isset($vn);"); - if ($vnFl) { - eval("\$data = $vn;"); - if ($p_testonly) { - echo "$data\n"; - } + $tagElement = "\$infoFromFile$path$dataPath"; + eval("\$tagExists = isset($tagElement);"); + if ($tagExists) { + eval("\$data = $tagElement;"); if (!$ignoreEnc && $encPath != "") { - $encVn = "\$infoFromFile$path$encPath"; - eval("\$encVnFl = isset($encVn);"); - if ($encVnFl) { - eval("\$enc = $encVn;"); + $encodedElement = "\$infoFromFile$path$encPath"; + eval("\$encodedElementExists = isset($encodedElement);"); + if ($encodedElementExists) { + eval("\$enc = $encodedElement;"); } } - if ($p_testonly) { - echo " ENC=$enc\n"; - } camp_add_metadata($mdata, $key, $data, $enc); if ($key == $titleKey) { $titleHaveSet = TRUE; } break; - } else { - if ($p_testonly) { - echo "\n"; - } } } } @@ -248,6 +254,15 @@ class StoredFile { */ public $gunid; + /** + * The unique ID of the file as it is stored in the database. + * This is for debugging purposes and may not always exist in this + * class. + * + * @var string + */ + private $gunidBigint; + /** * @var string */ @@ -321,14 +336,14 @@ class StoredFile { /** * Constructor, but shouldn't be externally called * - * @param string $gunid + * @param string $p_gunid * globally unique id of file */ - public function __construct($gunid=NULL) + public function __construct($p_gunid=NULL) { global $CC_CONFIG; global $CC_DBC; - $this->gunid = $gunid; + $this->gunid = $p_gunid; if (is_null($this->gunid)) { $this->gunid = StoredFile::CreateGunid(); } @@ -343,54 +358,65 @@ class StoredFile { /** * Create instance of StoredFile object and insert new file * - * @param int $oid - * local object id in the tree - * @param string $filename - * name of new file - * @param string $localFilePath - * local path to media file - * @param string $metadata - * local path to metadata XML file or XML string - * @param string $mdataLoc - * 'file'|'string' - * @param global $gunid - * unique id - for insert file with gunid - * @param string $ftype - * internal file type - * @param boolean $copyMedia + * @param array $p_values + * "id" - required, local object id in the tree + * "gunid" - optional, unique id, for insert file with gunid + * "filename" - optional + * "filepath" - local path to media file, not needed for Playlist + * "metadata" - local path to metadata XML file or XML string + * "filetype" - internal file type + * "mime" - MIME type, highly recommended to pass in + * "md5" - MD5 sum, highly recommended to pass in + * @param boolean $p_copyMedia * copy the media file if true, make symlink if false - * @return StoredFile + * @return StoredFile|NULL|PEAR_Error */ - public static function Insert($oid, $filename, $localFilePath='', - $metadata='', $mdataLoc='file', $gunid=NULL, $ftype=NULL, - $copyMedia=TRUE) + public static function Insert($p_values, $p_copyMedia=TRUE) { global $CC_CONFIG, $CC_DBC; - $storedFile = new StoredFile(($gunid ? $gunid : NULL)); - $storedFile->name = $filename; - $storedFile->id = $oid; - $storedFile->mime = "unknown"; - $emptyState = TRUE; - if ($storedFile->name == '') { - $storedFile->name = $storedFile->gunid; + + $gunid = isset($p_values['gunid'])?$p_values['gunid']:NULL; + + // Create the StoredFile object + $storedFile = new StoredFile($gunid); + $storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $storedFile->gunid; + $storedFile->id = $p_values['id']; + $storedFile->ftype = $p_values['filetype']; + if ($storedFile->ftype == 'playlist') { + $storedFile->mime = 'application/smil'; + } else { + $storedFile->mime = $p_values["mime"]; } + $storedFile->filepath = $p_values['filepath']; + if (isset($p_values['md5'])) { + $storedFile->md5 = $p_values['md5']; + } elseif (file_exists($storedFile->filepath)) { + echo "StoredFile::Insert: WARNING: Having to recalculate MD5 value\n"; + $storedFile->md5 = md5_file($storedFile->filepath); + } + $storedFile->exists = FALSE; - if (file_exists($localFilePath)) { - $md5 = md5_file($localFilePath); - } - $escapedName = pg_escape_string($filename); - $escapedFtype = pg_escape_string($ftype); + $emptyState = TRUE; + + // Insert record into the database + $escapedName = pg_escape_string($storedFile->name); + $escapedFtype = pg_escape_string($storedFile->ftype); $CC_DBC->query("BEGIN"); $sql = "INSERT INTO ".$CC_CONFIG['filesTable'] ."(id, name, gunid, mime, state, ftype, mtime, md5)" - ."VALUES ('$oid', '{$escapedName}', x'{$storedFile->gunid}'::bigint, - '{$storedFile->mime}', 'incomplete', '$escapedFtype', now(), '$md5')"; + ."VALUES ('{$storedFile->id}', '{$escapedName}', " + ." x'{$storedFile->gunid}'::bigint," + ." '{$storedFile->mime}', 'incomplete', '$escapedFtype'," + ." now(), '{$storedFile->md5}')"; $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; } - // --- metadata insert: + + // Insert metadata + $metadata = $p_values['metadata']; + $mdataLoc = ($metadata[0]=="/")?"file":"string"; if (is_null($metadata) || ($metadata == '') ) { $metadata = dirname(__FILE__).'/emptyMdata.xml'; $mdataLoc = 'file'; @@ -401,73 +427,95 @@ class StoredFile { return PEAR::raiseError("StoredFile::Insert: ". "metadata file not found ($metadata)"); } - $res = $storedFile->md->insert($metadata, $mdataLoc, $ftype); + $res = $storedFile->md->insert($metadata, $mdataLoc, $storedFile->ftype); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; } - // --- media file insert: - if ($localFilePath != '') { - if (!file_exists($localFilePath)) { + + // Save media file + if (!empty($storedFile->filepath)) { + if (!file_exists($storedFile->filepath)) { return PEAR::raiseError("StoredFile::Insert: ". - "media file not found ($localFilePath)"); + "media file not found ($storedFile->filepath)"); } - $res = $storedFile->addFile($localFilePath, $copyMedia); + $res = $storedFile->addFile($storedFile->filepath, $p_copyMedia); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; } - $mime = $storedFile->getMime(); - if ($mime !== FALSE) { - $res = $storedFile->setMime($mime); + if (empty($storedFile->mime)) { + echo "StoredFile::Insert: WARNING: Having to recalculate MIME value\n"; + $storedFile->setMime($storedFile->getMime()); } $emptyState = FALSE; } + + // Save state if (!$emptyState) { $res = $storedFile->setState('ready'); } + + // Commit changes $res = $CC_DBC->query("COMMIT"); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; } + + // Recall the object to get all the proper values + $storedFile = StoredFile::RecallByGunid($storedFile->gunid); return $storedFile; } /** - * Create instance of StoreFile object and recall existing file.
- * Should be supplied with oid OR gunid - not both. + * Fetch instance of StoreFile object.
+ * Should be supplied with only ONE parameter, all the rest should + * be NULL. * - * @param int $oid + * @param int $p_oid * local object id in the tree - * @param string $gunid + * @param string $p_gunid * global unique id of file - * @return StoredFile + * @param string $p_md5sum + * MD5 sum of the file + * @return StoredFile|Playlist|NULL + * Return NULL if the object doesnt exist in the DB. */ - public static function Recall($oid='', $gunid='') + public static function Recall($p_oid=null, $p_gunid=null, $p_md5sum=null) { global $CC_DBC; global $CC_CONFIG; - $cond = ($oid != '' - ? "id='".intval($oid)."'" - : "gunid=x'$gunid'::bigint" - ); - $row = $CC_DBC->getRow(" - SELECT id, to_hex(gunid)as gunid, name, mime, ftype, state, currentlyaccessing, editedby, mtime, md5 - FROM ".$CC_CONFIG['filesTable']." WHERE $cond"); + if (!is_null($p_oid)) { + $cond = "id='".intval($p_oid)."'"; + } elseif (!is_null($p_gunid)) { + $cond = "gunid=x'$p_gunid'::bigint"; + } elseif (!is_null($p_md5sum)) { + $cond = "md5='$p_md5sum'"; + } else { + return null; + } + $sql = "SELECT id, to_hex(gunid)as gunid, gunid as gunid_bigint," + ." name, mime, ftype, state, currentlyaccessing, editedby, " + ." mtime, md5" + ." FROM ".$CC_CONFIG['filesTable'] + ." WHERE $cond"; + $row = $CC_DBC->getRow($sql); if (PEAR::isError($row)) { return $row; } if (is_null($row)) { - $r =& PEAR::raiseError( - "StoredFile::recall: fileobj not exist ($oid/$gunid)", - GBERR_FOBJNEX - ); - return $r; + return null; } $gunid = StoredFile::NormalizeGunid($row['gunid']); - $storedFile = new StoredFile($gunid); + if ($row['ftype'] == 'audioclip') { + $storedFile = new StoredFile($gunid); + } elseif ($row['ftype'] == 'playlist') { + $storedFile = new Playlist($gunid); + } + $storedFile->gunidBigint = $row['gunid_bigint']; + $storedFile->md->gunidBigint = $row['gunid_bigint']; $storedFile->id = $row['id']; $storedFile->name = $row['name']; $storedFile->mime = $row['mime']; @@ -487,13 +535,25 @@ class StoredFile { * Create instance of StoreFile object and recall existing file * by gunid. * - * @param string $gunid + * @param string $p_gunid * global unique id of file * @return StoredFile */ - public static function RecallByGunid($gunid='') + public static function RecallByGunid($p_gunid='') { - return StoredFile::Recall('', $gunid); + return StoredFile::Recall(null, $p_gunid); + } + + + /** + * Fetch the StoredFile by looking up the MD5 value. + * + * @param string $p_md5sum + * @return StoredFile|NULL|PEAR_Error + */ + public static function RecallByMd5($p_md5sum) + { + return StoredFile::Recall(null, null, $p_md5sum); } @@ -501,80 +561,55 @@ class StoredFile { * Create instance of StoreFile object and recall existing file * by access token. * - * @param string $token + * @param string $p_token * access token * @return StoredFile */ - public static function RecallByToken($token) + public static function RecallByToken($p_token) { global $CC_CONFIG, $CC_DBC; - $gunid = $CC_DBC->getOne(" - SELECT to_hex(gunid) as gunid - FROM ".$CC_CONFIG['accessTable']." - WHERE token=x'$token'::bigint"); + $sql = "SELECT to_hex(gunid) as gunid" + ." FROM ".$CC_CONFIG['accessTable'] + ." WHERE token=x'$p_token'::bigint"; + $gunid = $CC_DBC->getOne($sql); if (PEAR::isError($gunid)) { return $gunid; } if (is_null($gunid)) { return PEAR::raiseError( - "StoredFile::RecallByToken: invalid token ($token)", GBERR_AOBJNEX); + "StoredFile::RecallByToken: invalid token ($p_token)", GBERR_AOBJNEX); } $gunid = StoredFile::NormalizeGunid($gunid); - return StoredFile::Recall('', $gunid); - } - - - /** - * Check if the MD5 value already exists. - * - * @param string $p_md5sum - * @return StoredFile|FALSE|PEAR_Error - */ - public static function RecallByMd5($p_md5sum) - { - global $CC_CONFIG, $CC_DBC; - $gunid = $CC_DBC->getOne( - "SELECT to_hex(gunid) as gunid - FROM ".$CC_CONFIG['filesTable']." - WHERE md5='$p_md5sum'"); - if (PEAR::isError($gunid)) { - return $gunid; - } - if ($gunid) { - $gunid = StoredFile::NormalizeGunid($gunid); - return StoredFile::Recall('', $gunid); - } else { - return FALSE; - } + return StoredFile::Recall(null, $gunid); } /** * Insert media file to filesystem * - * @param string $localFilePath + * @param string $p_localFilePath * local path - * @param boolean $copyMedia + * @param boolean $p_copyMedia * copy the media file if true, make symlink if false * @return TRUE|PEAR_Error */ - public function addFile($localFilePath, $copyMedia=TRUE) + public function addFile($p_localFilePath, $p_copyMedia=TRUE) { if ($this->exists) { return FALSE; } // for files downloaded from archive: - if ($localFilePath == $this->filepath) { + if ($p_localFilePath == $this->filepath) { $this->exists = TRUE; return TRUE; } umask(0002); - if ($copyMedia) { - $r = @copy($localFilePath, $this->filepath); + if ($p_copyMedia) { + $r = @copy($p_localFilePath, $this->filepath); } else { - $r = @symlink($localFilePath, $this->filepath); + $r = @symlink($p_localFilePath, $this->filepath); } - if ( $r ) { + if ($r) { $this->exists = TRUE; return TRUE; } else { @@ -582,7 +617,7 @@ class StoredFile { $this->exists = FALSE; return PEAR::raiseError( "StoredFile::addFile: file save failed". - " ($localFilePath, {$this->filepath})",GBERR_FILEIO + " ($p_localFilePath, {$this->filepath})",GBERR_FILEIO ); } } @@ -591,15 +626,15 @@ class StoredFile { /** * Delete and insert media file * - * @param string $localFilePath + * @param string $p_localFilePath * local path * @return TRUE|PEAR_Error */ - public function replaceFile($localFilePath) + public function replaceFile($p_localFilePath) { // Dont do anything if the source and destination files are // the same. - if ($this->name == $localFilePath) { + if ($this->name == $p_localFilePath) { return TRUE; } @@ -609,7 +644,7 @@ class StoredFile { return $r; } } - return $this->addFile($localFilePath); + return $this->addFile($p_localFilePath); } @@ -668,20 +703,25 @@ class StoredFile { /** * Create instance of StoredFile object and make copy of existing file * - * @param StoredFile $src + * @param StoredFile $p_src * source object - * @param int $nid + * @param int $p_nid * new local id * @return StoredFile */ - public static function CopyOf(&$src, $nid) + public static function CopyOf(&$p_src, $p_nid) { - $storedFile = StoredFile::Insert($nid, $src->name, $src->getRealFileName(), - '', '', NULL, BasicStor::GetType($src->gunid)); + $values = array( + "id" => $p_nid, + "filename" => $p_src->name, + "filepath" => $p_src->getRealFileName(), + "filetype" => BasicStor::GetType($p_src->gunid) + ); + $storedFile = StoredFile::Insert($values); if (PEAR::isError($storedFile)) { return $storedFile; } - $storedFile->md->replace($src->md->getMetadata(), 'string'); + $storedFile->md->replace($p_src->md->getMetadata(), 'string'); return $storedFile; } @@ -689,30 +729,30 @@ class StoredFile { /** * Replace existing file with new data. * - * @param int $oid - * local id - * @param string $name + * @param int $p_oid + * NOT USED + * @param string $p_name * name of file - * @param string $localFilePath + * @param string $p_localFilePath * local path to media file - * @param string $metadata + * @param string $p_metadata * local path to metadata XML file or XML string - * @param string $mdataLoc + * @param string $p_mdataLoc * 'file'|'string' * @return TRUE|PEAR_Error */ - public function replace($oid, $name, $localFilePath='', $metadata='', - $mdataLoc='file') + public function replace($p_oid, $p_name, $p_localFilePath='', $p_metadata='', + $p_mdataLoc='file') { global $CC_CONFIG, $CC_DBC; $CC_DBC->query("BEGIN"); - $res = $this->setName($name); + $res = $this->setName($p_name); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; } - if ($localFilePath != '') { - $res = $this->setRawMediaData($localFilePath); + if ($p_localFilePath != '') { + $res = $this->setRawMediaData($p_localFilePath); } else { $res = $this->deleteFile(); } @@ -720,8 +760,8 @@ class StoredFile { $CC_DBC->query("ROLLBACK"); return $res; } - if ($metadata != '') { - $res = $this->setMetadata($metadata, $mdataLoc); + if ($p_metadata != '') { + $res = $this->setMetadata($p_metadata, $p_mdataLoc); } else { $res = $this->md->delete(); } @@ -746,11 +786,11 @@ class StoredFile { * @return array * array with: access URL, access token */ - public function accessRawMediaData($parent='0') + public function accessRawMediaData($p_parent='0') { $realFname = $this->getRealFileName(); $ext = $this->getFileExtension(); - $res = BasicStor::bsAccess($realFname, $ext, $this->gunid, 'access', $parent); + $res = BasicStor::bsAccess($realFname, $ext, $this->gunid, 'access', $p_parent); if (PEAR::isError($res)) { return $res; } @@ -763,13 +803,13 @@ class StoredFile { /** * Decrease access couter, delete access record. * - * @param string $token + * @param string $p_token * access token * @return boolean */ - public function releaseRawMediaData($token) + public function releaseRawMediaData($p_token) { - $res = BasicStor::bsRelease($token); + $res = BasicStor::bsRelease($p_token); if (PEAR::isError($res)) { return $res; } @@ -780,13 +820,13 @@ class StoredFile { /** * Replace media file only with new binary file * - * @param string $localFilePath + * @param string $p_localFilePath * local path to media file * @return TRUE|PEAR_Error */ - public function setRawMediaData($localFilePath) + public function setRawMediaData($p_localFilePath) { - $res = $this->replaceFile($localFilePath); + $res = $this->replaceFile($p_localFilePath); if (PEAR::isError($res)) { return $res; } @@ -808,21 +848,21 @@ class StoredFile { /** * Replace metadata with new XML file * - * @param string $metadata + * @param string $p_metadata * local path to metadata XML file or XML string - * @param string $mdataLoc + * @param string $p_mdataLoc * 'file'|'string' - * @param string $format + * @param string $p_format * metadata format for validation * ('audioclip' | 'playlist' | 'webstream' | NULL) * (NULL = no validation) * @return boolean */ - public function setMetadata($metadata, $mdataLoc='file', $format=NULL) + public function setMetadata($p_metadata, $p_mdataLoc='file', $p_format=NULL) { global $CC_CONFIG, $CC_DBC; $CC_DBC->query("BEGIN"); - $res = $this->md->replace($metadata, $mdataLoc, $format); + $res = $this->md->replace($p_metadata, $p_mdataLoc, $p_format); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; @@ -855,16 +895,17 @@ class StoredFile { /** * Rename stored virtual file * - * @param string $newname + * @param string $p_newname * @return TRUE|PEAR_Error */ public function setName($p_newname) { global $CC_CONFIG, $CC_DBC; $escapedName = pg_escape_string($p_newname); - $res = $CC_DBC->query(" - UPDATE ".$CC_CONFIG['filesTable']." SET name='$escapedName', mtime=now() - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "UPDATE ".$CC_CONFIG['filesTable'] + ." SET name='$escapedName', mtime=now()" + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } @@ -876,9 +917,9 @@ class StoredFile { /** * Set state of virtual file * - * @param string $state + * @param string $p_state * 'empty'|'incomplete'|'ready'|'edited' - * @param int $editedby + * @param int $p_editedby * user id | 'NULL' for clear editedBy field * @return TRUE|PEAR_Error */ @@ -887,10 +928,10 @@ class StoredFile { global $CC_CONFIG, $CC_DBC; $escapedState = pg_escape_string($p_state); $eb = (!is_null($p_editedby) ? ", editedBy=$p_editedby" : ''); - $res = $CC_DBC->query(" - UPDATE ".$CC_CONFIG['filesTable']." - SET state='$escapedState'$eb, mtime=now() - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "UPDATE ".$CC_CONFIG['filesTable'] + ." SET state='$escapedState'$eb, mtime=now()" + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } @@ -903,7 +944,7 @@ class StoredFile { /** * Set mime-type of virtual file * - * @param string $mime + * @param string $p_mime * mime-type * @return boolean|PEAR_Error */ @@ -914,9 +955,10 @@ class StoredFile { $p_mime = 'application/octet-stream'; } $escapedMime = pg_escape_string($p_mime); - $res = $CC_DBC->query( - "UPDATE ".$CC_CONFIG['filesTable']." SET mime='$escapedMime', mtime=now() - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "UPDATE ".$CC_CONFIG['filesTable'] + ." SET mime='$escapedMime', mtime=now()" + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } @@ -935,9 +977,10 @@ class StoredFile { { global $CC_CONFIG, $CC_DBC; $escapedMd5 = pg_escape_string($p_md5sum); - $res = $CC_DBC->query( - "UPDATE ".$CC_CONFIG['filesTable']." SET md5='$escapedMd5', mtime=now() - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "UPDATE ".$CC_CONFIG['filesTable'] + ." SET md5='$escapedMd5', mtime=now()" + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } @@ -949,6 +992,7 @@ class StoredFile { /** * Delete stored virtual file * + * @param boolean $p_deleteFile * @see MetaData * @return TRUE|PEAR_Error */ @@ -965,9 +1009,10 @@ class StoredFile { if (PEAR::isError($res)) { return $res; } - $tokens = $CC_DBC->getAll(" - SELECT to_hex(token)as token, ext FROM ".$CC_CONFIG['accessTable']." - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "SELECT to_hex(token)as token, ext " + ." FROM ".$CC_CONFIG['accessTable'] + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $tokens = $CC_DBC->getAll($sql); if (is_array($tokens)) { foreach ($tokens as $i => $item) { $file = $this->_getAccessFileName($item['token'], $item['ext']); @@ -976,15 +1021,15 @@ class StoredFile { } } } - $res = $CC_DBC->query( - "DELETE FROM ".$CC_CONFIG['accessTable']." - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "DELETE FROM ".$CC_CONFIG['accessTable'] + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } - $res = $CC_DBC->query( - "DELETE FROM ".$CC_CONFIG['filesTable']." - WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "DELETE FROM ".$CC_CONFIG['filesTable'] + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { return $res; } @@ -996,22 +1041,22 @@ class StoredFile { * Returns true if virtual file is currently in use.
* Static or dynamic call is possible. * - * @param string $gunid + * @param string $p_gunid * optional (for static call), global unique id * @return boolean|PEAR_Error */ - public function isAccessed($gunid=NULL) + public function isAccessed($p_gunid=NULL) { global $CC_CONFIG, $CC_DBC; - if (is_null($gunid)) { + if (is_null($p_gunid)) { return ($this->currentlyaccessing > 0); } - $ca = $CC_DBC->getOne(" - SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable']." - WHERE gunid=x'$gunid'::bigint"); + $sql = "SELECT currentlyAccessing FROM ".$CC_CONFIG['filesTable'] + ." WHERE gunid=x'$p_gunid'::bigint"; + $ca = $CC_DBC->getOne($sql); if (is_null($ca)) { return PEAR::raiseError( - "StoredFile::isAccessed: invalid gunid ($gunid)", + "StoredFile::isAccessed: invalid gunid ($p_gunid)", GBERR_FOBJNEX ); } @@ -1022,16 +1067,16 @@ class StoredFile { /** * Returns true if virtual file is edited * - * @param string $playlistId + * @param string $p_playlistId * playlist global unique ID * @return boolean */ - public function isEdited($playlistId=NULL) + public function isEdited($p_playlistId=NULL) { - if (is_null($playlistId)) { + if (is_null($p_playlistId)) { return ($this->state == 'edited'); } - $state = $this->getState($playlistId); + $state = $this->getState($p_playlistId); if ($state != 'edited') { return FALSE; } @@ -1042,21 +1087,20 @@ class StoredFile { /** * Returns id of user editing playlist * - * @param string $playlistId + * @param string $p_playlistId * playlist global unique ID * @return int|null|PEAR_Error * id of user editing it */ - public function isEditedBy($playlistId=NULL) + public function isEditedBy($p_playlistId=NULL) { global $CC_CONFIG, $CC_DBC; - if (is_null($playlistId)) { - $playlistId = $this->gunid; + if (is_null($p_playlistId)) { + $p_playlistId = $this->gunid; } - $ca = $CC_DBC->getOne(" - SELECT editedBy FROM ".$CC_CONFIG['filesTable']." - WHERE gunid=x'$playlistId'::bigint - "); + $sql = "SELECT editedBy FROM ".$CC_CONFIG['filesTable'] + ." WHERE gunid=x'$p_playlistId'::bigint"; + $ca = $CC_DBC->getOne($sql); if (PEAR::isError($ca)) { return $ca; } @@ -1068,7 +1112,8 @@ class StoredFile { /** - * Returns local id of virtual file + * Return local ID of virtual file. + * * @return int */ public function getId() @@ -1077,6 +1122,17 @@ class StoredFile { } + /** + * Return global ID of virtual file. + * + * @return string + */ + public function getGunid() + { + return $this->gunid; + } + + /** * Returns true if raw media file exists * @return boolean|PEAR_Error @@ -1084,9 +1140,10 @@ class StoredFile { public function exists() { global $CC_CONFIG, $CC_DBC; - $indb = $CC_DBC->getRow( - "SELECT to_hex(gunid) FROM ".$CC_CONFIG['filesTable'] - ." WHERE gunid=x'{$this->gunid}'::bigint"); + $sql = "SELECT to_hex(gunid) " + ." FROM ".$CC_CONFIG['filesTable'] + ." WHERE gunid=x'{$this->gunid}'::bigint"; + $indb = $CC_DBC->getRow($sql); if (PEAR::isError($indb)) { return $indb; } @@ -1121,9 +1178,9 @@ class StoredFile { * * @return string */ - public static function NormalizeGunid($gunid) + public static function NormalizeGunid($p_gunid) { - return str_pad($gunid, 16, "0", STR_PAD_LEFT); + return str_pad($p_gunid, 16, "0", STR_PAD_LEFT); } @@ -1187,41 +1244,39 @@ class StoredFile { /** * Get storage-internal file state * - * @param string $gunid + * @param string $p_gunid * global unique id of file * @return string * see install() */ - public function getState($gunid=NULL) + public function getState($p_gunid=NULL) { global $CC_CONFIG, $CC_DBC; - if (is_null($gunid)) { + if (is_null($p_gunid)) { return $this->state; } - return $CC_DBC->getOne(" - SELECT state FROM ".$CC_CONFIG['filesTable']." - WHERE gunid=x'$gunid'::bigint - "); + $sql = "SELECT state FROM ".$CC_CONFIG['filesTable'] + ." WHERE gunid=x'$p_gunid'::bigint"; + return $CC_DBC->getOne($sql); } /** * Get mnemonic file name * - * @param string $gunid + * @param string $p_gunid * global unique id of file * @return string */ - public function getName($gunid=NULL) + public function getName($p_gunid=NULL) { global $CC_CONFIG, $CC_DBC; - if (is_null($gunid)) { + if (is_null($p_gunid)) { return $this->name; } - return $CC_DBC->getOne(" - SELECT name FROM ".$CC_CONFIG['filesTable']." - WHERE gunid=x'$gunid'::bigint - "); + $sql = "SELECT name FROM ".$CC_CONFIG['filesTable'] + ." WHERE gunid=x'$p_gunid'::bigint"; + return $CC_DBC->getOne($sql); } @@ -1274,11 +1329,11 @@ class StoredFile { * @todo Should be more unique * @return string */ - private function _getAccessFileName($token, $ext='EXT') + private function _getAccessFileName($p_token, $p_ext='EXT') { global $CC_CONFIG; - $token = StoredFile::NormalizeGunid($token); - return $CC_CONFIG['accessDir']."/$token.$ext"; + $token = StoredFile::NormalizeGunid($p_token); + return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; } } // class StoredFile diff --git a/campcaster/src/modules/storageServer/var/Transport.php b/campcaster/src/modules/storageServer/var/Transport.php index 30223c18d..8fcbed023 100644 --- a/campcaster/src/modules/storageServer/var/Transport.php +++ b/campcaster/src/modules/storageServer/var/Transport.php @@ -325,7 +325,7 @@ class Transport case "playlist": $plid = $gunid; require_once("Playlist.php"); - $pl = Playlist::RecallByGunid($plid); + $pl = StoredFile::RecallByGunid($plid); if (PEAR::isError($pl)) { return $pl; } @@ -1351,13 +1351,19 @@ class Transport $mdtrec->setLock(FALSE); return $parid; } - $res = $this->gb->bsPutFile($parid, $row['fname'], - $trec->row['localfile'], $mdtrec->row['localfile'], - $row['gunid'], 'audioclip', 'file'); - if (PEAR::isError($res)) { + $values = array( + "filename" => $row['fname'], + "filepath" => $trec->row['localfile'], + "metadata" => $mdtrec->row['localfile'], + "gunid" => $row['gunid'], + "filetype" => "audioclip" + ); + $storedFile = $this->gb->bsPutFile($parid, $values); + if (PEAR::isError($storedFile)) { $mdtrec->setLock(FALSE); - return $res; + return $storedFile; } + $res = $storedFile->getId(); $ret = $this->xmlrpcCall('archive.downloadClose', array( 'token' => $mdtrec->row['pdtoken'] , @@ -1406,12 +1412,17 @@ class Transport if (PEAR::isError($parid)) { return $parid; } - $res = $this->gb->bsPutFile($parid, $row['fname'], - '', $trec->row['localfile'], - $row['gunid'], 'playlist', 'file'); - if (PEAR::isError($res)) { - return $res; + $values = array( + "filename" => $row['fname'], + "metadata" => $trec->row['localfile'], + "gunid" => $row['gunid'], + "filetype" => "playlist" + ); + $storedFile = $this->gb->bsPutFile($parid, $values); + if (PEAR::isError($storedFile)) { + return $storedFile; } + $res = $storedFile->getId(); @unlink($row['localfile']); break; case "playlistPkg": diff --git a/campcaster/src/modules/storageServer/var/Validator.php b/campcaster/src/modules/storageServer/var/Validator.php index eefd33161..9e8801fd5 100644 --- a/campcaster/src/modules/storageServer/var/Validator.php +++ b/campcaster/src/modules/storageServer/var/Validator.php @@ -109,8 +109,7 @@ class Validator { * 'A' | 'T' (attr or tag) * @param string $value * validated element value - * @return mixed - * TRUE or PEAR::error + * @return TRUE|PEAR_Error */ function validateOneValue($fname, $category, $predxml, $value) { diff --git a/campcaster/src/modules/storageServer/var/install/upgrade/upgrade-to-1.2.0.php b/campcaster/src/modules/storageServer/var/install/upgrade/upgrade-to-1.2.0.php index cc69093bc..9ffaf4346 100644 --- a/campcaster/src/modules/storageServer/var/install/upgrade/upgrade-to-1.2.0.php +++ b/campcaster/src/modules/storageServer/var/install/upgrade/upgrade-to-1.2.0.php @@ -48,6 +48,10 @@ echo " * Creating index on column 'md5'..."; $sql = "CREATE INDEX ".$CC_CONFIG['filesTable']."_md5_idx ON ".$CC_CONFIG['filesTable']." (md5)"; camp_install_query($sql); +echo " * Converting metadata values 'ls:genre' to 'dc:type'..."; +$sql = "UPDATE ".$CC_CONFIG['mdataTable']." SET predns='dc', predicate='type' WHERE predns='ls' and predicate='genre'"; +camp_install_query($sql); + // Get MD5 values for all files echo " * Computing MD5 sums for all files (this may take a while)...\n"; $sql = "SELECT to_hex(gunid) as gunid, name FROM ".$CC_CONFIG['filesTable'] ." WHERE ftype='audioclip'"; diff --git a/campcaster/src/modules/storageServer/var/tests/transTest.php b/campcaster/src/modules/storageServer/var/tests/transTest.php index f521b7416..f98e7bd68 100644 --- a/campcaster/src/modules/storageServer/var/tests/transTest.php +++ b/campcaster/src/modules/storageServer/var/tests/transTest.php @@ -40,8 +40,21 @@ echo"# Login: ".($sessid = Alib::Login('root', 'q'))."\n"; echo"# Store: "; $parid = $gb->_getHomeDirIdFromSess($sessid); -$oid = $r = $gb->bsPutFile($parid, "xx1.mp3", $mediaFile, $mdataFile, $gunid, 'audioclip'); -if(PEAR::isError($r)){ if($r->getCode()!=GBERR_GUNID){ echo "ERROR: ".$r->getMessage()."\n"; exit(1); }} +$values = array( + "filename" => "xx1.mp3", + "filepath" => $mediaFile, + "metadata" => $mdataFile, + "gunid" => $gunid, + "filetype" => "audioclip" +); +$storedFile = $gb->bsPutFile($parid, $values); +if (PEAR::isError($storedFile)) { + if ($storedFile->getCode()!=GBERR_GUNID) { + echo "ERROR: ".$storedFile->getMessage()."\n"; + exit(1); + } +} +$oid = $storedFile->getId(); $comm = "ls -l ".$CC_CONFIG['storageDir']."/a23"; echo `$comm`; echo "$oid\n"; diff --git a/campcaster/src/modules/storageServer/var/tests/webstreamTest.php b/campcaster/src/modules/storageServer/var/tests/webstreamTest.php index f9f13dc40..415175b85 100644 --- a/campcaster/src/modules/storageServer/var/tests/webstreamTest.php +++ b/campcaster/src/modules/storageServer/var/tests/webstreamTest.php @@ -33,7 +33,7 @@ var_dump($r); $id = $r; echo "# getMdata: "; -$r = $gb->getMdata($id, $sessid); +$r = $gb->getMetadata($id, $sessid); if (PEAR::isError($r)) { echo "ERROR: ".$r->getMessage()." ".$r->getUserInfo()."\n"; exit(1);