Cleaned up BasicStor::bsPutFile()/StoredFile::Insert() by making a better set of more extensible parameters. This allowed me to pass in the MD5 and MIME type values, which means those values do not have to be re-calculated when this function is called. This means adding files will be faster now (each calculation of an MD5 value is .25 of a second on my machine). Added a cache to the Metadata class (this class needs serious cleaning up), so that you only have to do one database call and the rest of the time you just use the cache. The number of calls to getMetadataValue() should speedups due to this. Merged the LsPlaylist class into the Playlist class. Importing through the import script and web interface now reads the COMMENT tag and the COMPOSER tag (bug #2108). Moved from using (ls:genre) to (dc:type) for the metadata label for genre and added to the upgrade script to take this into account. Fixed bug in StoredFile::Recall() so that Playlists work again, added an MD5 parameter for this function so that all the Recall functions work in the same way, changed the return value to NULL if the Recall function does not find the record. Made a lot of code more readable and easier to debug. Added StoredFile::getGunid().
This commit is contained in:
parent
a94f77a09c
commit
488dad1fd9
|
@ -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":
|
||||
|
|
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Campsite
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var array $g_inputErrors Used to store error messages.
|
||||
*/
|
||||
global $g_inputErrors;
|
||||
$g_inputErrors = array();
|
||||
|
||||
|
||||
/**
|
||||
* @package Campsite
|
||||
*/
|
||||
class Input {
|
||||
/**
|
||||
* Please see: {@link http://ca.php.net/manual/en/function.get-magic-quotes-gpc.php
|
||||
* this PHP.net page specifically the user note by php at kaiundina dot de},
|
||||
* for why this is so complicated.
|
||||
*
|
||||
* @param array $p_array
|
||||
* @return array
|
||||
*/
|
||||
function CleanMagicQuotes($p_array)
|
||||
{
|
||||
$gpcList = array();
|
||||
|
||||
foreach ($p_array as $key => $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
|
||||
|
||||
?>
|
|
@ -82,7 +82,7 @@ $mask = array(
|
|||
'element' => 'dc:type',
|
||||
'type' => 'text',
|
||||
'label' => 'Genre',
|
||||
'required' => TRUE,
|
||||
'required' => FALSE,
|
||||
'id3' => array('Genre')
|
||||
),
|
||||
array(
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
require(dirname(__FILE__).'/../ui_handler_init.php');
|
||||
require_once(dirname(__FILE__).'/../ui_handler_init.php');
|
||||
require_once("../Input.php");
|
||||
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$_REQUEST = Input::CleanMagicQuotes($_REQUEST);
|
||||
}
|
||||
|
||||
switch ($_REQUEST['act']) {
|
||||
case "login":
|
||||
|
@ -260,7 +265,7 @@ switch ($_REQUEST['act']) {
|
|||
break;
|
||||
|
||||
case "PL.addItem":
|
||||
if (isset($_REQUEST['id']) && isset($_REQUEST['playlength'])) {
|
||||
if (isset($_REQUEST['id'])) {
|
||||
if ($uiHandler->PLAYLIST->addItem($_REQUEST['id'], $_REQUEST['playlength']) !== FALSE) {
|
||||
$uiHandler->SCRATCHPAD->addItem($_REQUEST['id']);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<div class="container_elements" style="width: 607px;">
|
||||
<h1>
|
||||
{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}
|
||||
</div>
|
||||
|
||||
|
||||
<div id="div_MData">
|
||||
{include file="file/metadataform.tpl"}
|
||||
</div>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)';
|
||||
|
|
|
@ -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']."<BR>";
|
||||
// echo "$ntmp <br>";
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
?>
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,599 +0,0 @@
|
|||
<?
|
||||
require_once("Playlist.php");
|
||||
|
||||
define('INDCH', ' ');
|
||||
define('AC_URL_RELPATH', '../audioClip/');
|
||||
define('PL_URL_RELPATH', '../playlist/');
|
||||
|
||||
/**
|
||||
* Internal playlist format helper.
|
||||
*
|
||||
* @author Tomas Hlava <th@red2head.com>
|
||||
* @author Paul Baranowski <paul@paulbaranowski.org>
|
||||
* @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 <th@red2head.com>
|
||||
* @author Paul Baranowski <paul@paulbaranowski.org>
|
||||
* @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<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
|
||||
"$ind<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n".
|
||||
"$ind2<body>\n".
|
||||
"$ind3<par>\n".
|
||||
"$res".
|
||||
"$ind3</par>\n".
|
||||
"$ind2</body>\n".
|
||||
"$ind</smil>\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<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
|
||||
"$ind<rss version=\"2.0\">\n".
|
||||
"$ind2<channel>\n".
|
||||
"$res".
|
||||
"$ind2</channel>\n".
|
||||
"$ind</rss>\n";
|
||||
return $res;
|
||||
}
|
||||
} // class LsPlaylistTag
|
||||
|
||||
|
||||
/**
|
||||
* @author Tomas Hlava <th@red2head.com>
|
||||
* @author Paul Baranowski <paul@paulbaranowski.org>
|
||||
* @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}<animate attributeName = \"soundLevel\"\n".
|
||||
"{$ind3}from = \"".($ff == 'fi' ? 0 : 100)."%\"\n".
|
||||
"{$ind3}to = \"".($ff == 'fi' ? 100 : 0)."%\"\n".
|
||||
"{$ind3}calcMode = \"linear\"\n".
|
||||
"{$ind3}begin = \"{${$ff."BeginS"}}s\"\n".
|
||||
"{$ind3}end = \"{${$ff."EndS"}}s\"\n".
|
||||
"{$ind3}fill = \"freeze\"\n".
|
||||
"{$ind2}/>\n"
|
||||
;
|
||||
}
|
||||
}
|
||||
$src = $acOrPl['src'];
|
||||
$str = "$ind<audio src=\"$src\" begin=\"{$beginS}s\"".
|
||||
($anim ? ">\n$anim$ind</audio>" : " />").
|
||||
" <!-- {$acOrPl['type']}, {$acOrPl['gunid']}, {$acOrPl['playlength']} -->".
|
||||
"\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<item>\n".
|
||||
"$ind2<title>$title</title>\n".
|
||||
"$ind2<description>$desc</description>\n".
|
||||
"$ind2<link>$link</link>\n".
|
||||
"$ind</item>\n";
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author Tomas Hlava <th@red2head.com>
|
||||
* @author Paul Baranowski <paul@paulbaranowski.org>
|
||||
* @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 <th@red2head.com>
|
||||
* @author Paul Baranowski <paul@paulbaranowski.org>
|
||||
* @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 <th@red2head.com>
|
||||
* @author Paul Baranowski <paul@paulbaranowski.org>
|
||||
* @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
|
||||
?>
|
|
@ -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:
|
||||
* <ul>
|
||||
* <li>mid int, local metadata record id</li>
|
||||
* <li>value string, element value</li>
|
||||
* <li>attrs hasharray of element's attributes indexed by
|
||||
* <li>"mid" - int, local metadata record id</li>
|
||||
* <li>"value" - string, element value</li>
|
||||
* <li>"attrs" - hasharray of element's attributes indexed by
|
||||
* qualified name (e.g. xml:lang)</li>
|
||||
* </ul>
|
||||
* @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');
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
define('RENDER_EXT', 'ogg');
|
||||
|
||||
require_once "LsPlaylist.php";
|
||||
require_once("Playlist.php");
|
||||
|
||||
/**
|
||||
* Renderer caller class
|
||||
|
@ -37,7 +37,7 @@ class Renderer
|
|||
{
|
||||
global $CC_CONFIG;
|
||||
// recall playlist:
|
||||
$pl = LsPlaylist::RecallByGunid($plid);
|
||||
$pl = StoredFile::RecallByGunid($plid);
|
||||
if (PEAR::isError($pl)) {
|
||||
return $pl;
|
||||
}
|
||||
|
@ -232,16 +232,17 @@ class Renderer
|
|||
}
|
||||
$mdata = "<audioClip>\n <metadata>\n$mdata </metadata>\n</audioClip>\n";
|
||||
//$mdata = "<audioClip>\n <metadata>\n$mdata<dcterms:extent>0</dcterms:extent>\n</metadata>\n</audioClip>\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());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 ".
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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":
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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'";
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue