From f4c68079d4acb8731341b50f46591bdcd4ce8514 Mon Sep 17 00:00:00 2001 From: paul Date: Sat, 14 Oct 2006 15:34:00 +0000 Subject: [PATCH] Renamed LiveSupport to Campcaster. Got rid of copyright notice in files, we will just have one that covers all files at the root of the package. Converted comments to Phpdocumentor format. Added @author, @version, @package, and @subpackage doc tags. Reformatted code to Campware PHP coding conventions. --- .../modules/storageServer/var/AccessRecur.php | 147 ++- .../src/modules/storageServer/var/Backup.php | 167 +-- .../modules/storageServer/var/BasicStor.php | 50 +- .../modules/storageServer/var/DataEngine.php | 64 +- .../modules/storageServer/var/GreenBox.php | 42 +- .../src/modules/storageServer/var/LocStor.php | 40 +- .../modules/storageServer/var/LsPlaylist.php | 402 ++++-- .../modules/storageServer/var/M3uPlaylist.php | 43 +- .../modules/storageServer/var/MetaData.php | 794 +++++++----- .../modules/storageServer/var/Playlist.php | 956 +++++++++------ .../src/modules/storageServer/var/Prefs.php | 368 +++--- .../storageServer/var/RawMediaData.php | 207 ++-- .../modules/storageServer/var/Renderer.php | 213 ++-- .../src/modules/storageServer/var/Restore.php | 232 ++-- .../storageServer/var/SmilPlaylist.php | 241 ++-- .../modules/storageServer/var/StoredFile.php | 327 ++--- .../modules/storageServer/var/Transport.php | 1085 +++++++++++------ .../storageServer/var/TransportRecord.php | 261 ++-- .../modules/storageServer/var/Validator.php | 279 +++-- .../modules/storageServer/var/XmlParser.php | 262 ++-- .../storageServer/var/audioClipFormat.php | 37 +- .../src/modules/storageServer/var/conf.php | 48 +- .../modules/storageServer/var/cron/Cron.php | 46 +- .../storageServer/var/cron/CronJob.php | 15 +- .../storageServer/var/cron/Crontab.php | 51 +- .../var/cron/transportCronJob.php | 14 +- .../src/modules/storageServer/var/index.php | 32 +- .../storageServer/var/install/getGname.php | 29 - .../storageServer/var/install/getPwd.php | 29 - .../storageServer/var/install/getWwwRoot.php | 29 - .../storageServer/var/install/getXrUrl.php | 29 - .../storageServer/var/install/index.php | 31 +- .../storageServer/var/install/install.php | 31 +- .../storageServer/var/install/uninstall.php | 31 +- .../storageServer/var/playlistFormat.php | 35 +- .../modules/storageServer/var/tests/index.php | 31 +- .../storageServer/var/tests/transTest.php | 28 - .../storageServer/var/tests/webstreamTest.php | 28 - .../storageServer/var/webstreamFormat.php | 34 +- .../storageServer/var/xmlrpc/XR_LocStor.php | 73 +- .../storageServer/var/xmlrpc/index.php | 31 +- .../modules/storageServer/var/xmlrpc/put.php | 31 +- .../var/xmlrpc/schedulerPhpClient.php | 34 +- .../storageServer/var/xmlrpc/simpleGet.php | 33 +- .../storageServer/var/xmlrpc/xrLocStor.php | 34 +- .../storageServer/var/xmlrpc/xr_cli_test.php | 33 +- 46 files changed, 3805 insertions(+), 3252 deletions(-) diff --git a/livesupport/src/modules/storageServer/var/AccessRecur.php b/livesupport/src/modules/storageServer/var/AccessRecur.php index f2911fbdd..526c6ee75 100644 --- a/livesupport/src/modules/storageServer/var/AccessRecur.php +++ b/livesupport/src/modules/storageServer/var/AccessRecur.php @@ -1,103 +1,108 @@ ls =& $ls; $this->dbc =& $ls->dbc; $this->sessid = $sessid; } - function accessPlaylist(&$ls, $sessid, $plid, $parent='0'){ + + + function accessPlaylist(&$ls, $sessid, $plid, $parent='0') + { $ppa =& new AccessRecur($ls, $sessid); $r = $ls->accessPlaylist($sessid, $plid, FALSE, $parent); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $plRes = $r; $r = StoredFile::recallByGunid($ppa->ls, $plid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $ac = $r; $r = $ac->md->genPhpArray(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $pla = $r; $r = $ppa->processPlaylist($pla, $plRes['token']); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $plRes['content'] = $r; return $plRes; } - function releasePlaylist(&$ls, $sessid, $token){ + + + function releasePlaylist(&$ls, $sessid, $token) + { $ppa =& new AccessRecur($ls, $sessid); $r = $ppa->dbc->getAll(" SELECT to_hex(token)as token2, to_hex(gunid)as gunid FROM {$ppa->ls->accessTable} WHERE parent=x'{$token}'::bigint "); - if($ppa->dbc->isError($r)){ return $r; } + if ($ppa->dbc->isError($r)) { + return $r; + } $arr = $r; - foreach($arr as $i=>$item){ + foreach ($arr as $i => $item) { extract($item); // token2, gunid $r = $ppa->ls->_getType($gunid); - if($ppa->dbc->isError($r)){ return $r; } + if ($ppa->dbc->isError($r)) { + return $r; + } $ftype = $r; # echo "$ftype/$token2\n"; - switch(strtolower($ftype)){ + switch (strtolower($ftype)) { case"audioclip": $r = $ppa->ls->releaseRawAudioData($ppa->sessid, $token2); - if($ppa->dbc->isError($r)){ return $r; } + if ($ppa->dbc->isError($r)) { + return $r; + } # var_dump($r); break; case"playlist": $r = $ppa->releasePlaylist($ppa->ls, $ppa->sessid, $token2); - if($ppa->dbc->isError($r)){ return $r; } + if ($ppa->dbc->isError($r)) { + return $r; + } # var_dump($r); break; default: } } $r = $ppa->ls->releasePlaylist($ppa->sessid, $token, FALSE); - if($ppa->dbc->isError($r)){ return $r; } + if ($ppa->dbc->isError($r)) { + return $r; + } return $r; } - function processPlaylist($pla, $parent){ + + + function processPlaylist($pla, $parent) + { $res = array(); - foreach($pla['children'] as $ple){ - switch($ple['elementname']){ + foreach ($pla['children'] as $ple) { + switch ($ple['elementname']) { case"playlistElement": $r = $this->processPlEl($ple, $parent); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } // $res = array_merge($res, $r); $res[] = $r; break; @@ -106,28 +111,41 @@ class AccessRecur{ } return $res; } - function processAc($gunid, $parent){ + + + function processAc($gunid, $parent) + { $r = $this->ls->accessRawAudioData($this->sessid, $gunid, $parent); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $r; } - function processPlEl($ple, $parent='0'){ - foreach($ple['children'] as $ac){ - switch($ac['elementname']){ + + + function processPlEl($ple, $parent='0') + { + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { case"audioClip": $r = $this->processAc($ac['attrs']['id'], $parent); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $r; break; case"playlist": // if(empty($ac['children'])){ $r = $this->accessPlaylist($this->ls, $this->sessid, $ac['attrs']['id'], $parent); - if(PEAR::isError($r)){ - if($r->getCode() != GBERR_NOTF) return $r; - else{ + if (PEAR::isError($r)) { + if ($r->getCode() != GBERR_NOTF) { + return $r; + } else { $r = $this->processPlaylist($ac, $parent); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = array( 'content' => $r, 'url' => NULL, @@ -160,5 +178,6 @@ class AccessRecur{ } return array(); } -} -?> + +} // class AccessRecur +?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/Backup.php b/livesupport/src/modules/storageServer/var/Backup.php index 248ca41ca..e40ff66b3 100755 --- a/livesupport/src/modules/storageServer/var/Backup.php +++ b/livesupport/src/modules/storageServer/var/Backup.php @@ -2,7 +2,13 @@ define('BACKUP_EXT', 'tar'); define('ACCESS_TYPE', 'backup'); -class Backup +/** + * @author $Author: $ + * @version $Revision: $ + * @package Campcaster + * @subpackage StorageServer + */ +class Backup { /** * string - name of logfile @@ -34,7 +40,7 @@ class Backup * array - array of affected filenames */ var $filenames = array(); - + /** * string - base tmp name */ @@ -46,25 +52,25 @@ class Backup /** * string - name of temporary directory */ - var $tmpDir; + var $tmpDir; /** * string - name of temporary playlist directory */ - var $tmpDirPlaylist; + var $tmpDirPlaylist; /** * string - name of temporary audioclip directory */ - var $tmpDirClip; + var $tmpDirClip; /** * string - name of temporary metafile directory */ - var $tmpDirMeta; - + var $tmpDirMeta; + /** * string - loglevel */ var $loglevel = 'warn'; # 'debug'; - + /** * greenbox object reference */ @@ -82,14 +88,15 @@ class Backup $this->logFile = $this->gb->bufferDir.'/'.ACCESS_TYPE.'.log'; $this->addLogItem("-I- ".date("Ymd-H:i:s")." construct\n"); } - + + /** * Open a backup * Create a backup file (tarball) * * @param sessid : string - session id * @param criteria : struct - see search criteria - * @return hasharray with field: + * @return hasharray with field: * token string: backup token */ function openBackup($sessid,$criteria='') @@ -99,23 +106,25 @@ class Backup } $this->sessid = $sessid; $this->criteria = $criteria; - + # get ids (and real filenames) which files match with criteria $srch = $r = $this->gb->localSearch($this->criteria,$this->sessid); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } $this->setIDs($srch); #echo 'this->ids:'; print_r($this->ids); echo ''; - + # get real filenames if (is_array($this->ids)) { $this->setFilenames(); #echo 'this->filenames:'; print_r($this->filenames); echo ''; - + $this->setEnviroment(true); - + # write a status file file_put_contents($this->statusFile, 'working'); - + # save the metafile to tmpdir $hostname = trim(`hostname`); $ctime = time(); @@ -129,22 +138,25 @@ class Backup " hostname=\"$hostname\"\n". "/>\n" ); - + # copy all file to tmpdir $this->copyAllFiles(); - + # do everything $this->doIt(); - + return array('token'=>$this->token); - } else return false; + } else { + return false; + } } - + + /** - * check the status of backup + * Check the status of backup. * - * @param token : token - * @return hasharray with field: + * @param unknown $token + * @return array * status : string - susccess | working | fault * faultString: string - description of fault * token : stirng - backup token @@ -160,7 +172,7 @@ class Backup $this->setEnviroment(); $status = file_get_contents($this->statusFile); if (strpos($status,'fault')!==false) { - list($status,$faultString) = explode('|',$status); + list($status,$faultString) = explode('|',$status); } switch ($status) { case 'success': @@ -175,12 +187,13 @@ class Backup } return $r; } - + + /** - * Close a backup + * Close a backup * - * @param token : token - * @return status : boolean + * @param unknown $token + * @return boolean */ function closeBackup($token) { @@ -194,16 +207,19 @@ class Backup Backup::rRmDir($this->tmpDir); unlink($this->statusFile); unlink($this->tmpFile); - if (is_file($this->tmpName)) unlink($this->tmpName); + if (is_file($this->tmpName)) { + unlink($this->tmpName); + } return !is_file($this->tmpFile); } - + + /** * list of unclosed backups * - * @param stat : status (optional) + * @param string $stat (optional) * if this parameter is not set, then return with all unclosed backups - * @return array of hasharray with field: + * @return array of hasharray with field: * status : string - susccess | working | fault * token : stirng - backup token * url : string - access url @@ -224,11 +240,12 @@ class Backup } return $r; } - + + /** - * set the ids from searchResult + * Aet the ids from searchResult * - * @param searchResult : array of gunids + * @param array $searchResult : array of gunids */ function setIDs($searchResult) { @@ -242,12 +259,13 @@ class Backup return PEAR::raiseError('The IDs variable isn\'t array.'); } } - + + /** - * set the filenames from ids + * Set the filenames from ids. * */ - function setFilenames () + function setFilenames() { if ($this->loglevel=='debug') { $this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames\n"); @@ -257,9 +275,11 @@ class Backup $gunid = $item['gunid']; # get a stored file object of this gunid $sf = $r = StoredFile::recallByGunid($this->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $lid = $this->gb->_idFromGunid($gunid); - if(($res = $this->gb->_authorize('read', $lid, $this->sessid)) !== TRUE){ + if (($res = $this->gb->_authorize('read', $lid, $this->sessid)) !== TRUE) { $this->addLogItem("-E- ".date("Ymd-H:i:s")." setFilenames - authorize gunid:$gunid\n"); return PEAR::raiseError('Backup::setFilenames : Authorize ... error.'); } @@ -284,9 +304,10 @@ class Backup return PEAR::raiseError('Backup::setFilenames : The IDs variable isn\'t array.'); } } - + + /** - * Create the tarball - call the shell script + * Create the tarball - call the shell script * */ function doIt() @@ -305,7 +326,8 @@ class Backup $this->addLogItem("-I- ".date("Ymd-H:i:s")." doIt - command:$command\n"); } } - + + /** * Copy the real files into the tmp dirs to tar they. * @@ -315,7 +337,7 @@ class Backup if ($this->loglevel=='debug') { $this->addLogItem("-I- ".date("Ymd-H:i:s")." copyAllFiles\n"); } - //echo 'this->filenames:'; print_r($this->filenames); echo ''; + //echo 'this->filenames:'; print_r($this->filenames); echo ''; if (is_array($this->filenames)) { foreach ($this->filenames as $v) { # get the filename from full path @@ -333,7 +355,8 @@ class Backup } } } - + + /** * Figure out the enviroment to the backup * @@ -347,9 +370,9 @@ class Backup if (is_null($this->token) && $createDir) { $this->tmpName = tempnam($this->gb->bufferDir, ACCESS_TYPE.'_'); $this->tmpFile = $this->tmpName.'.'.BACKUP_EXT; - $this->tmpDir = $this->tmpName.'.dir'; - $this->tmpDirPlaylist = $this->tmpDir. '/playlist'; - $this->tmpDirClip = $this->tmpDir. '/audioClip'; + $this->tmpDir = $this->tmpName.'.dir'; + $this->tmpDirPlaylist = $this->tmpDir. '/playlist'; + $this->tmpDirClip = $this->tmpDir. '/audioClip'; $this->tmpDirMeta = $this->tmpDir. '/meta-inf'; touch($this->tmpFile); mkdir($this->tmpDir); @@ -362,13 +385,13 @@ class Backup if (is_link($symlink) && is_file(readlink($symlink))) { $this->tmpName = str_replace('.tar','',readlink($symlink)); $this->tmpFile = $this->tmpName.'.'.BACKUP_EXT; - $this->tmpDir = $this->tmpName.'.dir'; - $this->tmpDirPlaylist = $this->tmpDir. '/playlist'; - $this->tmpDirClip = $this->tmpDir. '/audioClip'; + $this->tmpDir = $this->tmpName.'.dir'; + $this->tmpDirPlaylist = $this->tmpDir. '/playlist'; + $this->tmpDirClip = $this->tmpDir. '/audioClip'; $this->tmpDirMeta = $this->tmpDir. '/meta-inf'; } else { $this->addLogItem("-E- ".date("Ymd-H:i:s")." setEnviroment - Corrupt symbolic link.\n"); - return false; + return false; } } $this->statusFile = $this->gb->accessDir.'/'.$this->token.'.'.BACKUP_EXT.'.status'; @@ -383,22 +406,26 @@ class Backup $this->addLogItem("this->statusFile: $this->statusFile\n"); } } - + + /** - * generate a new token. - * + * Generate a new token. + * @return void */ function genToken() { $acc = $this->gb->bsAccess($this->tmpFile, BACKUP_EXT, null, ACCESS_TYPE); - if($this->gb->dbc->isError($acc)){ return $acc; } + if ($this->gb->dbc->isError($acc)) { + return $acc; + } $this->token = $acc['token']; } - + + /** - * Add a line to the logfile. + * Add a line to the logfile. * - * @param item : string - the new row of log file + * @param string $item - the new row of log file */ function addLogItem($item) { @@ -407,27 +434,31 @@ class Backup fclose($f); //echo file_get_contents($this->logFile)."

\n\n"; } - + + /** * Delete a directory recursive * - * @param dirname : string - path of dir. + * @param string $dirname - path of dir. */ function rRmDir($dirname) { - if(is_dir($dirname)) + if (is_dir($dirname)) { $dir_handle = opendir($dirname); - while($file = readdir($dir_handle)) { - if($file!="." && $file!="..") { - if(!is_dir($dirname."/".$file)) + } + while ($file = readdir($dir_handle)) { + if ( ($file != ".") && ($file != "..") ) { + if (!is_dir($dirname."/".$file)) { unlink ($dirname."/".$file); - else + } else { Backup::rRmDir($dirname."/".$file); + } } } closedir($dir_handle); rmdir($dirname); return true; } -} + +} // classs Backup ?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/BasicStor.php b/livesupport/src/modules/storageServer/var/BasicStor.php index 5475dfd6c..d6a36e9e0 100644 --- a/livesupport/src/modules/storageServer/var/BasicStor.php +++ b/livesupport/src/modules/storageServer/var/BasicStor.php @@ -1,32 +1,4 @@ bufferDir = realpath($config['bufferDir']); $this->transDir = realpath($config['transDir']); $this->accessDir = realpath($config['accessDir']); - if(!$install){ + if (!$install) { $this->rootId = $r = $this->getRootNode(); - if ($this->dbc->isError($r)){ + if ($this->dbc->isError($r)) { trigger_error("BasicStor: ". $r->getMessage()." ".$r->getUserInfo(),E_USER_ERROR); } $this->storId = $this->wd = $r = $this->getObjId('StorageRoot', $this->getRootNode()); - if ($this->dbc->isError($r)){ + if ($this->dbc->isError($r)) { trigger_error("BasicStor: ". $r->getMessage()." ".$r->getUserInfo(),E_USER_ERROR); } @@ -147,7 +121,7 @@ class BasicStor extends Alib { if ($this->dbc->isError($ac)){ $res = $this->removeObj($id); // catch constraint violations - switch($ac->getCode()){ + switch ($ac->getCode()){ case -3: return PEAR::raiseError( "BasicStor::bsPutFile: gunid duplication", @@ -1173,7 +1147,7 @@ class BasicStor extends Alib { * @param int $parid, destination folder local id * @param string $plid, playlist gunid * @param string $aPath, absolute path part of imported file - * (e.g. /home/user/livesupport) + * (e.g. /home/user/campcaster) * @param string $rPath, relative path/filename part of imported file * (e.g. playlists/playlist_1.smil) * @param string $ext, playlist extension (determines type of import) diff --git a/livesupport/src/modules/storageServer/var/DataEngine.php b/livesupport/src/modules/storageServer/var/DataEngine.php index 1021379ac..0124264b1 100644 --- a/livesupport/src/modules/storageServer/var/DataEngine.php +++ b/livesupport/src/modules/storageServer/var/DataEngine.php @@ -1,32 +1,4 @@ filetype - string, type of searched files, * meaningful values: 'audioclip', 'webstream', 'playlist', 'all' *
  • operator - string, type of conditions join - * (any condition matches / all conditions match), + * (any condition matches / all conditions match), * meaningful values: 'and', 'or', '' * (may be empty or ommited only with less then 2 items in * "conditions" field) @@ -63,8 +35,12 @@ require_once "XML/Util.php"; *
  • cnt : integer - number of matching items
  • * * - * @see MetaData - * @see StoredFile + * @Author $Author$ + * @version $Revision$ + * @package Campcaster + * @subpackage StorageServer + * @see MetaData + * @see StoredFile */ class DataEngine{ @@ -136,7 +112,7 @@ class DataEngine{ } return $whereArr; } - + /** * Method returning SQL query for search/browse with AND operator * (without using INTERSECT command) @@ -156,7 +132,7 @@ class DataEngine{ foreach($whereArr as $i=>$v){ $whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i"); $lastTbl = ($i==0 ? "f" : "md".($i-1)); - $innerBlocks[] = + $innerBlocks[] = "INNER JOIN {$this->mdataTable} md$i ON md$i.gunid = $lastTbl.gunid\n"; } // query construcion: @@ -173,7 +149,7 @@ class DataEngine{ if($browse) $sql .= "\nORDER BY br.object"; return $sql; } - + /** * Method returning SQL query for search/browse with AND operator * (using INTERSECT command) @@ -194,13 +170,13 @@ class DataEngine{ $isectBlocks = array(); foreach($whereArr as $i=>$v){ $whereArr[$i] = sprintf($v, "md$i", "md$i", "md$i", "md$i", "md$i"); - $isectBlocks[] = + $isectBlocks[] = " SELECT gunid FROM {$this->mdataTable} md$i\n". " WHERE\n {$whereArr[$i]}"; } // query construcion: if(count($isectBlocks)>0){ - $isectBlock = + $isectBlock = "FROM\n(\n".join("INTERSECT\n", $isectBlocks).") sq\n". "INNER JOIN {$this->filesTable} f ON f.gunid = sq.gunid"; }else{ @@ -218,7 +194,7 @@ class DataEngine{ if($browse) $sql .= "\nORDER BY br.object"; return $sql; } - + /** * Method returning SQL query for search/browse with OR operator * @@ -255,7 +231,7 @@ class DataEngine{ if($browse) $sql .= "\nORDER BY br.object"; return $sql; } - + /** * Search in local metadata database. * @@ -264,7 +240,7 @@ class DataEngine{ * @param offset int, starting point (0 means without offset) * @return hash, fields: * results : array with gunid strings - * cnt : integer - number of matching gunids + * cnt : integer - number of matching gunids * of files have been found */ function localSearch($cri, $limit=0, $offset=0) @@ -273,7 +249,7 @@ class DataEngine{ // if(PEAR::isError($res)) return $res; return $res; } - + /** * Search in local metadata database, more general version. * @@ -283,7 +259,7 @@ class DataEngine{ * @param brFldNs string - namespace prefix of category for browse * @param brFld string, metadata category identifier for browse * @return arrays of hashes, fields: - * cnt : integer - number of matching gunids + * cnt : integer - number of matching gunids * of files have been found * results : array of hashes: * gunid: string @@ -393,7 +369,7 @@ class DataEngine{ * @param criteria hash * @return hash, fields: * results : array with found values - * cnt : integer - number of matching values + * cnt : integer - number of matching values */ function browseCategory($category, $limit=0, $offset=0, $criteria=NULL) { @@ -421,7 +397,7 @@ class DataEngine{ if(!is_array($res)) $res = array(); return array('results'=>$res, 'cnt'=>$cnt); } - + /** * Get number of rows in query result * @@ -437,7 +413,7 @@ class DataEngine{ $rh->free(); return $cnt; } - + } ?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/GreenBox.php b/livesupport/src/modules/storageServer/var/GreenBox.php index 6e248c4b2..5cf9ebea2 100644 --- a/livesupport/src/modules/storageServer/var/GreenBox.php +++ b/livesupport/src/modules/storageServer/var/GreenBox.php @@ -1,42 +1,16 @@ _authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) { return $res; } return $this->bsPutFile( diff --git a/livesupport/src/modules/storageServer/var/LocStor.php b/livesupport/src/modules/storageServer/var/LocStor.php index b56a7018a..9ef614f41 100644 --- a/livesupport/src/modules/storageServer/var/LocStor.php +++ b/livesupport/src/modules/storageServer/var/LocStor.php @@ -1,39 +1,15 @@ * - * @param gb reference to GreenBox object - * @param gunid string, global unique id - * @param className string, optional classname to recall + * @param Greenbox $gb, reference to GreenBox object + * @param string $gunid, global unique id + * @param string $className, optional classname to recall * @return instance of LsPlaylist object */ function &recallByGunid(&$gb, $gunid, $className='LsPlaylist') @@ -55,13 +32,14 @@ class LsPlaylist extends Playlist return parent::recallByGunid($gb, $gunid, $className); } + /** * Create instance of LsPlaylist object and recall existing file * by access token.
    * - * @param gb reference to GreenBox object - * @param token string, access token - * @param className string, optional classname to recall + * @param GreenBox $gb, reference to GreenBox object + * @param string $token, access token + * @param string $className, optional classname to recall * @return instance of LsPlaylist object */ function &recallByToken(&$gb, $token, $className='LsPlaylist') @@ -69,23 +47,30 @@ class LsPlaylist extends Playlist return parent::recallByToken($gb, $token, $className); } + /** * Export playlist as simplified SMIL XML file * - * @param toString boolean, if false don't real export, - * return misc info about playlist only - * @return XML string or hasharray with misc info + * @param boolean $toString + * if false don't real export, + * return misc info about playlist only + * @return string + * XML string or hasharray with misc info */ function output2Smil($toString=TRUE) { $plGunid = $this->gunid; $arr = $r = $this->md->genPhpArray(); - if(PEAR::isError($r)){ return $r; } - if($toString){ + if (PEAR::isError($r)) { + return $r; + } + if ($toString) { $r = LsPlaylistTag::output2Smil($this, $arr); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $r; - }else{ + } else { return array( 'type' => 'playlist', 'gunid' => $plGunid, @@ -95,6 +80,7 @@ class LsPlaylist extends Playlist } } + /** * Export playlist as M3U file * @@ -106,12 +92,16 @@ class LsPlaylist extends Playlist { $plGunid = $this->gunid; $arr = $r = $this->md->genPhpArray(); - if(PEAR::isError($r)){ return $r; } - if($toString){ + if (PEAR::isError($r)) { + return $r; + } + if ($toString) { $r = LsPlaylistTag::output2m3u($this, $arr); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $r; - }else{ + } else { return array( 'type' => 'playlist', 'gunid' => $plGunid, @@ -122,23 +112,30 @@ class LsPlaylist extends Playlist } } + /** - * Export playlist as RSS XML file + * Export playlist as RSS XML file * - * @param toString boolean, if false don't real export, - * return misc info about playlist only - * @return XML string or hasharray with misc info + * @param boolean $toString + * if false don't really export, + * return misc info about playlist only + * @return mixed + * XML string or hasharray with misc info */ function output2RSS($toString=TRUE) { $plGunid = $this->gunid; $arr = $r = $this->md->genPhpArray(); - if(PEAR::isError($r)){ return $r; } - if($toString){ + if (PEAR::isError($r)) { + return $r; + } + if ($toString) { $r = LsPlaylistTag::output2RSS($this, $arr); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $r; - }else{ + } else { return array( 'type' => 'playlist', 'gunid' => $plGunid, @@ -147,28 +144,43 @@ class LsPlaylist extends Playlist ); } } -} + +} // class LsPlaylist + /** - * Several auxiliary classes follows + * Several auxiliary classes follows + * @package Campcaster + * @subpackage StorageServer + * @todo Rename this class PlaylistTag */ class LsPlaylistTag { function output2Smil(&$pl, $plt, $ind='') { - $ind2 = $ind.INDCH; $ind3 = $ind2.INDCH; $ind4 = $ind3.INDCH; + $ind2 = $ind.INDCH; + $ind3 = $ind2.INDCH; + $ind4 = $ind3.INDCH; $res = ""; - foreach($plt['children'] as $ple){ - switch($ple['elementname']){ + foreach ($plt['children'] as $ple) { + switch ($ple['elementname']) { case"playlistElement": $r = LsPlaylistElement::output2Smil($pl, $ple, $ind4); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $res .= $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } break; case"metadata": $r = LsPlaylistMetadata::output2Smil($pl, $ple, $ind4); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $res .= $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } break; default: } @@ -183,36 +195,53 @@ class LsPlaylistTag "$ind\n"; return $res; } + + function output2m3u(&$pl, $plt, $ind='') { $res = ""; - foreach($plt['children'] as $ple){ - switch($ple['elementname']){ + foreach ($plt['children'] as $ple) { + switch ($ple['elementname']) { case"playlistElement": $r = LsPlaylistElement::output2m3u($pl, $ple); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $res .= $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } break; } } $res = "#EXTM3U\n$res"; return $res; } + + function output2RSS(&$pl, $plt, $ind='') { - $ind2 = $ind.INDCH; $ind3 = $ind2.INDCH; + $ind2 = $ind.INDCH; + $ind3 = $ind2.INDCH; $res = ""; - foreach($plt['children'] as $ple){ - switch($ple['elementname']){ + foreach ($plt['children'] as $ple) { + switch ($ple['elementname']) { case"playlistElement": $r = LsPlaylistElement::output2RSS($pl, $ple, $ind3); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $res .= $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } break; case"metadata": $r = LsPlaylistMetadata::output2RSS($pl, $ple, $ind3); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $res .= $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $res .= $r; + } break; default: } @@ -225,32 +254,57 @@ class LsPlaylistTag "$ind\n"; return $res; } -} -class LsPlaylistElement{ +} // class LsPlaylistTag + + +/** + * @package Campcaster + * @subpackage StorageServer + * @todo Rename this class "PlaylistElement" + */ +class LsPlaylistElement { + + function output2Smil(&$pl, $ple, $ind='') { - $acOrPl = NULL; $finfo = array('fi'=>0, 'fo'=>0); - $ind2 = $ind.INDCH; $ind3 = $ind2.INDCH; + $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": + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { + case "audioClip": $r = LsPlaylistAudioClip::output2Smil($pl, $ac, $ind2); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $acOrPl = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } break; - case"playlist": + case "playlist": $gunid = $ac['attrs']['id']; $pl2 = $r = LsPlaylist::recallByGunid($pl->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $pl2->output2Smil(FALSE); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $acOrPl = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } break; case"fadeInfo": $r = LsPlaylistFadeInfo::output2Smil($pl, $ac, $ind2); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $finfo = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $finfo = $r; + } break; default: return PEAR::raiseError( @@ -266,8 +320,8 @@ class LsPlaylistElement{ $fiEndS = $pl->_plTimeToSecs($finfo['fi']); $foBeginS = ($playlengthS - $fadeOutS); $foEndS = $pl->_plTimeToSecs($acOrPl['playlength']); - foreach(array('fi','fo') as $ff){ - if(${$ff."EndS"} - ${$ff."BeginS"} > 0){ + foreach (array('fi','fo') as $ff) { + if (${$ff."EndS"} - ${$ff."BeginS"} > 0) { $anim .= "{$ind2}\n" ; - }else{ } } $src = $acOrPl['src']; @@ -287,27 +340,41 @@ class LsPlaylistElement{ "\n"; return $str; } + + function output2m3u(&$pl, $ple, $ind='') { $acOrPl = NULL; - foreach($ple['children'] as $ac){ - switch($ac['elementname']){ - case"audioClip": + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { + case "audioClip": $r = LsPlaylistAudioClip::output2m3u($pl, $ac); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $acOrPl = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } break; - case"playlist": + case "playlist": $gunid = $ac['attrs']['id']; $pl2 = $r = LsPlaylist::recallByGunid($pl->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $pl2->output2m3u(FALSE); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $acOrPl = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } break; } } - if(is_null($acOrPl)) return ''; + if (is_null($acOrPl)) { + return ''; + } $playlength = ceil($pl->_plTimeToSecs($acOrPl['playlength'])); $title = $acOrPl['title']; $uri = (isset($acOrPl['uri']) ? $acOrPl['uri'] : '???' ); @@ -315,25 +382,37 @@ class LsPlaylistElement{ $res .= "$uri\n"; return $res; } + + function output2RSS(&$pl, $ple, $ind='') { $acOrPl = NULL; $ind2 = $ind.INDCH; $anim = ''; - foreach($ple['children'] as $ac){ - switch($ac['elementname']){ - case"audioClip": + foreach ($ple['children'] as $ac) { + switch ($ac['elementname']) { + case "audioClip": $r = LsPlaylistAudioClip::output2RSS($pl, $ac, $ind2); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $acOrPl = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } break; case"playlist": $gunid = $ac['attrs']['id']; $pl2 = $r = LsPlaylist::recallByGunid($pl->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $pl2->output2RSS(FALSE); - if(PEAR::isError($r)) return $r; - if(!is_null($r)) $acOrPl = $r; + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($r)) { + $acOrPl = $r; + } break; case"fadeInfo": break; @@ -356,15 +435,27 @@ class LsPlaylistElement{ return $str; } } + + +/** + * @package Campcaster + * @subpackage StorageServer + * @todo Rename this class to PlaylistAudioClip (notice the caps) + */ class LsPLaylistAudioClip { + function output2Smil(&$pl, $plac, $ind='') { $gunid = $plac['attrs']['id']; $ac = $r = StoredFile::recallByGunid($pl->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $RADext = $r =$ac->_getExt(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return array( 'type' => 'audioclip', 'gunid' => $gunid, @@ -372,31 +463,47 @@ class LsPLaylistAudioClip 'playlength' => $plac['attrs']['playlength'], ); } + + function output2m3u(&$pl, $plac, $ind='') { $gunid = $plac['attrs']['id']; $ac = $r = StoredFile::recallByGunid($pl->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $RADext = $r =$ac->_getExt(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return array( 'playlength' => $plac['attrs']['playlength'], 'title' => $plac['attrs']['title'], 'uri' => AC_URL_RELPATH."$gunid.$RADext", ); } + + function output2RSS(&$pl, $plac, $ind='') { $gunid = $plac['attrs']['id']; $ac = $r = StoredFile::recallByGunid($pl->gb, $gunid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $RADext = $r =$ac->_getExt(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:title'); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $title = ( isset($r[0]) ? $r[0]['value'] : '' ); $r = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:description'); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $desc = ( isset($r[0]) ? $r[0]['value'] : '' ); return array( 'type' => 'audioclip', @@ -407,10 +514,17 @@ class LsPLaylistAudioClip 'desc' => $desc, ); } -} +} // class LsPlaylistAudioClip + +/** + * @package Campcaster + * @subpackage StorageServer + * @todo Rename this class "PlaylistFadeInfo" (notive the caps) + */ class LsPLaylistFadeInfo { + function output2Smil(&$pl, $plfi, $ind='') { $r = array( @@ -419,14 +533,44 @@ class LsPLaylistFadeInfo ); return $r; } - function output2m3u(&$pl, $plfa, $ind=''){ return ''; } - function output2RSS(&$pl, $plfa, $ind=''){ return ''; } -} + + function output2m3u(&$pl, $plfa, $ind='') + { + return ''; + } + + + function output2RSS(&$pl, $plfa, $ind='') + { + return ''; + } + +} // class LsPlaylistFadeInfo + + +/** + * @package Campcaster + * @subpackage StorageServer + * @todo Rename this class to PlaylistMetadata (notive the caps) + */ class LsPLaylistMetadata { - function output2Smil(&$pl, $md, $ind=''){ return NULL; } - function output2m3u(&$pl, $md, $ind=''){ return NULL; } - function output2RSS(&$pl, $md, $ind=''){ return NULL; } -} -?> + function output2Smil(&$pl, $md, $ind='') + { + return NULL; + } + + + function output2m3u(&$pl, $md, $ind='') + { + return NULL; + } + + + function output2RSS(&$pl, $md, $ind='') + { + return NULL; + } +} // class PlaylistMetadata +?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/M3uPlaylist.php b/livesupport/src/modules/storageServer/var/M3uPlaylist.php index 702b0937a..f5cb33de6 100644 --- a/livesupport/src/modules/storageServer/var/M3uPlaylist.php +++ b/livesupport/src/modules/storageServer/var/M3uPlaylist.php @@ -1,38 +1,13 @@ +?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/MetaData.php b/livesupport/src/modules/storageServer/var/MetaData.php index a8abe5391..2f07493db 100644 --- a/livesupport/src/modules/storageServer/var/MetaData.php +++ b/livesupport/src/modules/storageServer/var/MetaData.php @@ -1,32 +1,4 @@ - * Store metadata tree in relational database.
    + * Campcaster file storage support class.
    + * Store metadata tree in relational database.
    * - * @see StoredFile - * @see XmlParser - * @see DataEngine + * @author $Author$ + * @version $Revision$ + * @package Campcaster + * @subpackage StorageServer + * @see StoredFile + * @see XmlParser + * @see DataEngine */ -class MetaData{ +class MetaData { + /** * Constructor * - * @param gb reference to GreenBox object - * @param gunid string, global unique id - * @param resDir string, resource directory + * @param Greenbox $gb + * A reference to GreenBox object + * @param string $gunid + * global unique id + * @param string $resDir + * resource directory * @return this */ function MetaData(&$gb, $gunid, $resDir) @@ -67,26 +47,38 @@ class MetaData{ ; } + /** * Parse and store metadata from XML file or XML string * - * @param mdata string, local path to metadata XML file or XML string - * @param loc string - location: 'file'|'string' - * @param format string, metadata format for validation + * @param string $mdata + * Local path to metadata XML file or XML string + * @param string $loc + * location: 'file'|'string' + * @param string $format + * Metadata format for validation * ('audioclip' | 'playlist' | 'webstream' | NULL) * (NULL = no validation) * @return true or PEAR::error */ function insert($mdata, $loc='file', $format=NULL) { - if($this->exists) return FALSE; + if ($this->exists) { + return FALSE; + } $tree =& $this->parse($mdata, $loc); - if(PEAR::isError($tree)) return $tree; + if (PEAR::isError($tree)) { + return $tree; + } $this->format = $format; $res = $this->validate($tree); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $this->storeDoc($tree); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } /* obsolete by regenerateXmlFile() switch($loc){ case"file": @@ -117,29 +109,38 @@ class MetaData{ */ $this->exists = TRUE; $r = $this->regenerateXmlFile(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return TRUE; } + /** * Call delete and insert * - * @param mdata string, local path to metadata XML file or XML string - * @param loc string 'file'|'string' - * @param format string, metadata format for validation + * @param string $mdata + * local path to metadata XML file or XML string + * @param string $loc + * 'file'|'string' + * @param string $format + * metadata format for validation * ('audioclip' | 'playlist' | 'webstream' | NULL) * (NULL = no validation) * @return true or PEAR::error */ function replace($mdata, $loc='file', $format=NULL) { - if($this->exists){ + if ($this->exists) { $res = $this->delete(); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } } return $this->insert($mdata, $loc, $format); } + /** * Return true if metadata exists * @@ -150,6 +151,7 @@ class MetaData{ return $this->exists; } + /** * Delete all file's metadata * @@ -157,50 +159,67 @@ class MetaData{ */ function delete() { - if(file_exists($this->fname)) @unlink($this->fname); + if (file_exists($this->fname)) { + @unlink($this->fname); + } $res = $this->dbc->query(" DELETE FROM {$this->mdataTable} WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $this->exists = FALSE; return TRUE; } + /** - * Return metadata XML string + * Return metadata XML string * - * @return string + * @return string */ function getMetaData() { // return $this->genXMLDoc(); // obsolete - if(file_exists($this->fname)){ + if (file_exists($this->fname)) { $res = file_get_contents($this->fname); //require_once "XML/Beautifier.php"; //$fmt = new XML_Beautifier(); //$res = $fmt->formatString($res); return $res; - }else{ return file_get_contents(dirname(__FILE__).'/emptyMdata.xml'); } + } else { + return file_get_contents(dirname(__FILE__).'/emptyMdata.xml'); + } } + /** - * Get metadata element value and record id + * Get metadata element value and record id * - * @param category string, metadata element name - * @param parid int, metadata record id of parent element - * @return hash {mid: int - record id, value: metadata alue} + * @param string $category + * metadata element name + * @param int $parid + * metadata record id of parent element + * @return hash + * {mid: int - record id, value: metadata alue} */ function getMetadataEl($category, $parid=NULL) { // handle predicate namespace shortcut - $a = XML_Util::splitQualifiedName($category); - if(PEAR::isError($a)) return $a; + $a = XML_Util::splitQualifiedName($category); + if (PEAR::isError($a)) { + return $a; + } $catNs = $a['namespace']; - $cat = $a['localPart']; + $cat = $a['localPart']; $cond = "gunid=x'{$this->gunid}'::bigint AND predicate='$cat'"; - if(!is_null($catNs)) $cond .= " AND predns='$catNs'"; - if(!is_null($parid)) $cond .= " AND subjns='_I' AND subject='$parid'"; + if (!is_null($catNs)) { + $cond .= " AND predns='$catNs'"; + } + if (!is_null($parid)) { + $cond .= " AND subjns='_I' AND subject='$parid'"; + } $sql = " SELECT id as mid, object as value FROM {$this->mdataTable} @@ -210,27 +229,32 @@ class MetaData{ $all = $this->dbc->getAll($sql); $transTbl = get_html_translation_table(); $transTbl = array_flip($transTbl); - foreach($all as $i=>$v){ - if(!is_null($all[$i]['value'])){ + foreach ($all as $i => $v) { + if (!is_null($all[$i]['value'])) { $all[$i]['value'] = strtr($all[$i]['value'], $transTbl); - }else{ + } else { $all[$i]['value'] = ''; } } - if(PEAR::isError($all)) return $all; + if (PEAR::isError($all)) { + return $all; + } return $all; } - + + /** * Set metadata value / delete metadata record * - * @param mid int, metadata record id - * @param value string, new metadata value (NULL for delete) + * @param int $mid + * metadata record id + * @param string $value + * new metadata value (NULL for delete) * @return boolean */ function setMetadataEl($mid, $value=NULL) { - if(!is_null($value)){ + if (!is_null($value)) { $transTbl = get_html_translation_table(); $value = strtr($value, $transTbl); } @@ -242,8 +266,10 @@ class MetaData{ ON parmd.id=md.subject AND md.subjns='_I' WHERE md.id=$mid "); - if(PEAR::isError($info)) return $info; - if(is_null($info)){ + if (PEAR::isError($info)) { + return $info; + } + if (is_null($info)) { return PEAR::raiseError( "MetaData::setMetadataEl: parent container not found" ); @@ -252,30 +278,40 @@ class MetaData{ $parname = ($parns ? "$parns:" : '').$parname; $category = ($chns ? "$chns:" : '').$chname; $r = $this->validateOneValue($parname, $category, $predxml, $value); - if(PEAR::isError($r)) return $r; - if(!is_null($value)){ - foreach(array('value') as $v) $$v = pg_escape_string($$v); + if (PEAR::isError($r)) { + return $r; + } + if (!is_null($value)) { + $value = pg_escape_string($value); $sql = " UPDATE {$this->mdataTable} SET object='$value', objns='_L' WHERE id={$mid} "; $res = $this->dbc->query($sql); - }else{ + } else { $res = $this->deleteRecord($mid); } - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** - * Insert new metadata element + * Insert new metadata element * - * @param parid int, metadata record id of parent element - * @param category string, metadata element name - * @param value string, new metadata value (NULL for delete) - * @param predxml string, 'T' | 'A' | 'N' (tag, attr., namespace) - * @return int, new metadata record id + * @param int $parid + * metadata record id of parent element + * @param string $category + * metadata element name + * @param string value + * new metadata value (NULL for delete) + * @param string $predxml + * 'T' | 'A' | 'N' (tag, attr., namespace) + * @return int, + * new metadata record id */ function insertMetadataEl($parid, $category, $value=NULL, $predxml='T') { @@ -284,8 +320,10 @@ class MetaData{ SELECT predns, predicate, predxml FROM {$this->mdataTable} WHERE gunid=x'{$this->gunid}'::bigint AND id=$parid "); - if(PEAR::isError($parent)) return $parent; - if(is_null($parent)){ + if (PEAR::isError($parent)) { + return $parent; + } + if (is_null($parent)) { return PEAR::raiseError( "MetaData::insertMetadataEl: container not found" ); @@ -293,37 +331,49 @@ class MetaData{ $parNs = ($parent['predns'] ? "{$parent['predns']}:" : ''); $parName = $parNs.$parent['predicate']; $r = $this->validateOneValue($parName, $category, $predxml, $value); - if(PEAR::isError($r)) return $r; - $a = XML_Util::splitQualifiedName($category); - if(PEAR::isError($a)) return $a; + if (PEAR::isError($r)) { + return $r; + } + $a = XML_Util::splitQualifiedName($category); + if (PEAR::isError($a)) { + return $a; + } $catNs = $a['namespace']; - $cat = $a['localPart']; + $cat = $a['localPart']; $objns = (is_null($value) ? '_blank' : '_L' ); - if(!is_null($value)){ + if (!is_null($value)) { $transTbl = get_html_translation_table(); $value = strtr($value, $transTbl); } $nid= $this->storeRecord('_I', $parid, $catNs, $cat, $predxml, $objns, $value); - if(PEAR::isError($nid)) return $nid; + if (PEAR::isError($nid)) { + return $nid; + } return $nid; } - + + /** - * Get metadata element value + * Get metadata element value * - * @param category string, metadata element name - * @param lang string, optional xml:lang value for select language version - * @param deflang string, optional xml:lang for default language - * @param objns string, object namespace prefix - for internal use only - * @return array of matching records as hash with fields: + * @param string $category + * metadata element name + * @param string $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: * - * @see BasicStor::bsGetMetadataValue + * @see BasicStor::bsGetMetadataValue */ function getMetadataValue($category, $lang=NULL, $deflang=NULL, $objns='_L') { @@ -333,17 +383,19 @@ class MetaData{ $def = NULL; $plain = NULL; // add attributes to result - foreach($all as $i=>$rec){ + foreach ($all as $i => $rec) { $pom = $this->getSubrows($rec['mid']); - if(PEAR::isError($pom)) return $pom; + if (PEAR::isError($pom)) { + return $pom; + } $all[$i]['attrs'] = $pom['attrs']; $atlang = (isset($pom['attrs']['xml:lang']) ? $pom['attrs']['xml:lang'] : NULL); // select only matching lang (en is default) - if(is_null($lang)){ + if (is_null($lang)) { $res[] = $all[$i]; - }else{ - switch(strtolower($atlang)){ + } else { + switch (strtolower($atlang)) { case '': $plain = array($all[$i]); break; @@ -356,21 +408,33 @@ class MetaData{ } } } - if($exact) return $exact; - if($def) return $def; - if($plain) return $plain; + if ($exact) { + return $exact; + } + if ($def) { + return $def; + } + if ($plain) { + return $plain; + } return $res; } + /** - * Set metadata element value + * Set metadata element value * - * @param category string, metadata element name (e.g. dc:title) - * @param value string/NULL value to store, if NULL then delete record - * @param lang string, optional xml:lang value for select language version - * @param mid int, metadata record id (OPTIONAL on unique elements) - * @param container string, container element name for insert - * @return boolean + * @param string $category + * metadata element name (e.g. dc:title) + * @param string $value + * value to store, if NULL then delete record + * @param string $lang + * optional xml:lang value for select language version + * @param int mid + * metadata record id (OPTIONAL on unique elements) + * @param string $container + * container element name for insert + * @return boolean */ function setMetadataValue($category, $value, $lang=NULL, $mid=NULL, $container='metadata') @@ -378,83 +442,105 @@ class MetaData{ // resolve aktual element: $rows = $this->getMetadataValue($category, $lang); $aktual = NULL; - if(count($rows)>1){ - if(is_null($mid)){ - if(MODIFY_LAST_MATCH){ $aktual = array_pop($rows); } - else{ + if (count($rows) > 1) { + if (is_null($mid)) { + if (MODIFY_LAST_MATCH) { + $aktual = array_pop($rows); + } else { return PEAR::raiseError( "MetaData::setMdataValue:". " nonunique category, mid required" ); } - }else{ - foreach($rows as $i=>$row){ - if($mid == intval($row['mid'])) $aktual = $row; + } else { + foreach ($rows as $i => $row) { + if ($mid == intval($row['mid'])) { + $aktual = $row; + } } } - }else $aktual = (isset($rows[0])? $rows[0] : NULL); - if(!is_null($aktual)){ + } else { + $aktual = (isset($rows[0])? $rows[0] : NULL); + } + if (!is_null($aktual)) { $res = $this->setMetadataEl($aktual['mid'], $value); - if(PEAR::isError($res)) return $res; - if(!is_null($lang) && + 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(PEAR::isError($lg)) return $lg; - if(isset($lg['mid'])){ + if (PEAR::isError($lg)) { + return $lg; + } + if (isset($lg['mid'])) { $res = $this->setMetadataEl($lg['mid'], $lang); - if(PEAR::isError($res)) return $res; - }else{ + if (PEAR::isError($res)) { + return $res; + } + } else { $res = $this->insertMetadataEl( $aktual['mid'], 'xml:lang', $lang, 'A'); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } } } - }else{ + } else { // resolve container: $contArr = $this->getMetadataValue($container, NULL, NULL, '_blank'); - if(PEAR::isError($contArr)) return $contArr; + if (PEAR::isError($contArr)) { + return $contArr; + } $parid = $contArr[0]['mid']; - if(is_null($parid)){ + if (is_null($parid)) { return PEAR::raiseError( "MetaData::setMdataValue: container ($container) not found" ); } $nid = $this->insertMetadataEl($parid, $category, $value); - if(PEAR::isError($nid)) return $nid; - if(!is_null($lang)){ + if (PEAR::isError($nid)) { + return $nid; + } + if (!is_null($lang)) { $res = $this->insertMetadataEl($nid, 'xml:lang', $lang, 'A'); - if(PEAR::isError($res) && $res->getCode()!=VAL_UNKNOWNA) return $res; + if (PEAR::isError($res) && $res->getCode()!=VAL_UNKNOWNA) { + return $res; + } } } return TRUE; } + /** - * Regenerate XML metadata file after metadata value change + * Regenerate XML metadata file after metadata value change * - * @return boolean + * @return boolean */ function regenerateXmlFile() { $atime = date('c'); // php4 fix: - if($atime=='c'){ - $tz=preg_replace("|00$|",":00",trim(`date +%z`)); - $atime=trim(`date +%Y-%m-%dT%H:%M:%S`).$tz; + if ($atime=='c') { + $tz = preg_replace("|00$|",":00",trim(`date +%z`)); + $atime = trim(`date +%Y-%m-%dT%H:%M:%S`).$tz; } $r = $this->setMetadataValue('ls:mtime', $atime); if(PEAR::isError($r)) return $r; $fn = $this->fname; $xml = $this->genXMLDoc(); - if(PEAR::isError($xml)) return $xml; + if (PEAR::isError($xml)) { + return $xml; + } if (!$fh = fopen($fn, 'w')) { return PEAR::raiseError( "MetaData::regenerateXmlFile: cannot open for write ($fn)" ); } - if(fwrite($fh, $xml) === FALSE) { + if (fwrite($fh, $xml) === FALSE) { return PEAR::raiseError( "MetaData::regenerateXmlFile: write error ($fn)" ); @@ -463,40 +549,45 @@ class MetaData{ @chmod($fn, 0664); return TRUE; } - + + /** - * Contruct filepath of metadata file + * Contruct filepath of metadata file * - * @return string + * @return string */ function makeFname() { return "{$this->resDir}/{$this->gunid}.xml"; } - + + /** - * Return filename + * Return filename * - * @return string + * @return string */ function getFname() { return $this->fname; } - + + /** - * Set the metadata format to the object instance + * Set the metadata format to the object instance */ function setFormat($format=NULL) { $this->format = $format; } - + + /** - * Check if there are any file's metadata in database + * Check if there are any file's metadata in database * - * @param gunid string, global unique id - * @return boolean + * @param string $gunid + * global unique id + * @return boolean */ function dbCheck($gunid) { @@ -505,91 +596,122 @@ class MetaData{ FROM {$this->mdataTable} WHERE gunid=x'$gunid'::bigint "); - if(PEAR::isError($cnt)) return $cnt; + if (PEAR::isError($cnt)) { + return $cnt; + } return (intval($cnt) > 0); } + /* ============================================= parse and store metadata */ /** * Parse XML metadata * - * @param mdata string, local path to metadata XML file or XML string - * @param loc string, location: 'file'|'string' - * @return array reference, parse result tree (or PEAR::error) + * @param string $mdata + * local path to metadata XML file or XML string + * @param string $loc + * location: 'file'|'string' + * @return array + * reference, parse result tree (or PEAR::error) */ function &parse($mdata='', $loc='file') { - require_once"XmlParser.php"; + require_once("XmlParser.php"); return XmlParser::parse($mdata, $loc); } - + + /** - * Validate parsed metadata + * Validate parsed metadata * - * @param tree array, parsed tree - * @return true or PEAR::error + * @param array $tree + * parsed tree + * @return true or PEAR::error */ function validate(&$tree) { - if($this->config['validate'] && !is_null($this->format)){ - require_once"Validator.php"; + if ($this->config['validate'] && !is_null($this->format)) { + require_once("Validator.php"); $val =& new Validator($this->format, $this->gunid); - if(PEAR::isError($val)) return $val; + if (PEAR::isError($val)) { + return $val; + } $res = $val->validate($tree); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } } return TRUE; } - + + /** - * Validate one metadata value (on insert/update) + * Validate one metadata value (on insert/update) * - * @param parName string - parent element name - * @param category string - qualif.category name - * @param predxml string - 'A' | 'T' (attr or tag) - * @param value string - validated element value - * @return true or PEAR::error + * @param string $parName + * parent element name + * @param string $category + * qualif. category name + * @param string $predxml + * 'A' | 'T' (attr or tag) + * @param string $value + * validated element value + * @return true or PEAR::error */ function validateOneValue($parName, $category, $predxml, $value) { - if($this->config['validate'] && !is_null($this->format)){ - require_once"Validator.php"; + if ($this->config['validate'] && !is_null($this->format)) { + require_once("Validator.php"); $val =& new Validator($this->format, $this->gunid); - if(PEAR::isError($val)) return $val; + if (PEAR::isError($val)) { + return $val; + } $r = $val->validateOneValue($parName, $category, $predxml, $value); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } } return TRUE; } - + + /** - * Insert parsed metadata into database + * Insert parsed metadata into database * - * @param tree array, parsed tree - * @return true or PEAR::error + * @todo Check the return value for this function... + * @param array $tree + * parsed tree + * @return true or PEAR::error */ function storeDoc(&$tree) { $this->dbc->query("BEGIN"); $res = $this->storeNode($tree); - if(PEAR::isError($res)){ - $this->dbc->query("ROLLBACK"); return $res; + if (PEAR::isError($res)) { + $this->dbc->query("ROLLBACK"); + return $res; } $res = $this->dbc->query("COMMIT"); - if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } + if (PEAR::isError($res)) { + $this->dbc->query("ROLLBACK"); + return $res; + } return TRUE; - - return $root; } + /** - * Process one node of metadata XML for insert or update.
    + * Process one node of metadata XML for insert or update. * - * @param node object, node in tree returned by XmlParser - * @param parid int, parent id - * @param nSpaces array of name spaces definitions - * @return int, local metadata record id + * @param object $node + * node in tree returned by XmlParser + * @param int $parid + * parent id + * @param array $nSpaces + * array of name spaces definitions + * @return int + * local metadata record id */ function storeNode(&$node, $parid=NULL, $nSpaces=array()) { @@ -599,66 +721,81 @@ class MetaData{ $subjns = (is_null($parid)? '_G' : '_I'); $subject = (is_null($parid)? $this->gunid : $parid); $object = $node->content; - if(is_null($object) || $object == ''){ + if (is_null($object) || $object == '') { $objns = '_blank'; $object = NULL; - }else $objns = '_L'; + } else { + $objns = '_L'; + } $id = $this->storeRecord($subjns, $subject, $node->ns, $node->name, 'T', $objns, $object); // process attributes - foreach($node->attrs as $atn=>$ato){ + foreach ($node->attrs as $atn => $ato) { $this->storeRecord('_I', $id, $ato->ns, $ato->name, 'A', '_L', $ato->val); } // process child nodes - foreach($node->children as $ch){ + foreach ($node->children as $ch) { $this->storeNode($ch, $id, $nSpaces); } // process namespace definitions - foreach($node->nSpaces as $ns=>$uri){ + foreach ($node->nSpaces as $ns => $uri) { $this->storeRecord('_I', $id, 'xmlns', $ns, 'N', '_L', $uri); } return $id; } + /** - * Update object namespace and value of one metadata record - * identified by metadata record id + * Update object namespace and value of one metadata record + * identified by metadata record id * - * @param mdid int, metadata record id - * @param object string, object value, e.g. title string - * @param objns string, object namespace prefix, have to be defined - * in file's metadata - * @return true or PEAR::error + * @param int $mdid + * metadata record id + * @param string $object + * object value, e.g. title string + * @param string $objns + * object namespace prefix, have to be defined in file's metadata + * @return true or PEAR::error */ function updateRecord($mdid, $object, $objns='_L') { - foreach(array('objns', 'object') as $v){ - ${$v."_sql"} = (is_null($$v) ? "NULL" : "'".pg_escape_string($$v)."'" ); - } + $object_sql = is_null($object) ? "NULL" : "'".pg_escape_string($object)."'"; + $objns_sql = is_null($objns) ? "NULL" : "'".pg_escape_string($objns)."'"; $res = $this->dbc->query("UPDATE {$this->mdataTable} SET objns = $objns_sql, object = $object_sql WHERE gunid = x'{$this->gunid}'::bigint AND id='$mdid' "); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** - * Insert or update of one metadata record completely + * Insert or update of one metadata record completely * - * @param subjns string, subject namespace prefix, have to be defined - * in file's metadata (or reserved prefix) - * @param subject string, subject value, e.g. gunid - * @param predns string, predicate namespace prefix, have to be defined - * in file's metadata (or reserved prefix) - * @param predicate string, predicate value, e.g. name of DC element - * @param predxml string 'T'|'A'|'N' - XML tag, attribute or NS def. - * @param objns string, object namespace prefix, have to be defined - * in file's metadata (or reserved prefix) - * @param object string, object value, e.g. title of song - * @return int, new metadata record id + * @param string $subjns + * subject namespace prefix, have to be defined + * in file's metadata (or reserved prefix) + * @param string $subject + * subject value, e.g. gunid + * @param string $predns + * predicate namespace prefix, have to be defined + * in file's metadata (or reserved prefix) + * @param string $predicate + * predicate value, e.g. name of DC element + * @param string $predxml + * 'T'|'A'|'N' - XML tag, attribute or NS def. + * @param string $objns + * object namespace prefix, have to be defined + * in file's metadata (or reserved prefix) + * @param string $object + * object value, e.g. title of song + * @return int + * new metadata record id */ function storeRecord($subjns, $subject, $predns, $predicate, $predxml='T', $objns=NULL, $object=NULL) @@ -666,13 +803,16 @@ class MetaData{ //echo "$subjns, $subject, $predns, $predicate, $predxml, $objns, $object\n"; //$predns = strtolower($predns); //$predicate = strtolower($predicate); - foreach(array( - 'subjns', 'subject', 'predns', 'predicate', 'objns', 'object', - ) as $v){ - ${$v."_sql"} = (is_null($$v) ? "NULL" : "'".pg_escape_string($$v)."'" ); - } + $subjns_sql = is_null($subjns) ? "NULL" : "'".pg_escape_string($subjns)."'"; + $subject_sql = is_null($subject) ? "NULL" : "'".pg_escape_string($subject)."'"; + $predns_sql = is_null($predns) ? "NULL" : "'".pg_escape_string($predns)."'"; + $predicate_sql = is_null($predicate) ? "NULL" : "'".pg_escape_string($predicate)."'"; + $objns_sql = is_null($objns) ? "NULL" : "'".pg_escape_string($objns)."'"; + $object_sql = is_null($object) ? "NULL" : "'".pg_escape_string($object)."'"; $id = $this->dbc->nextId("{$this->mdataTable}_id_seq"); - if(PEAR::isError($id)) return $id; + if (PEAR::isError($id)) { + return $id; + } $res = $this->dbc->query(" INSERT INTO {$this->mdataTable} (id , gunid , subjns , subject , @@ -685,15 +825,19 @@ class MetaData{ $objns_sql, $object_sql ) "); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return $id; } + /** - * Delete metadata record recursively + * Delete metadata record recursively * - * @param mid int local metadata record id - * @return boolean + * @param int $mid + * local metadata record id + * @return boolean */ function deleteRecord($mid) { @@ -703,10 +847,14 @@ class MetaData{ gunid=x'{$this->gunid}'::bigint "; $rh = $this->dbc->query($sql); - if(PEAR::isError($rh)) return $rh; - while($row = $rh->fetchRow()){ + if (PEAR::isError($rh)) { + return $rh; + } + while ($row = $rh->fetchRow()) { $r = $this->deleteRecord($row['id']); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } } $rh->free(); $sql = " @@ -715,15 +863,19 @@ class MetaData{ gunid=x'{$this->gunid}'::bigint "; $res = $this->dbc->query($sql); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } - + + /* =========================================== XML reconstruction from db */ /** - * Generate PHP array from metadata database + * Generate PHP array from metadata database * - * @return array with metadata tree + * @return array + * array with metadata tree */ function genPhpArray() { @@ -733,63 +885,84 @@ class MetaData{ WHERE gunid=x'{$this->gunid}'::bigint AND subjns='_G' AND subject='{$this->gunid}' "); - if(PEAR::isError($row)) return $row; - if(is_null($row)){ - }else{ + if (PEAR::isError($row)) { + return $row; + } + if (!is_null($row)) { $node = $this->genXMLNode($row, FALSE); - if(PEAR::isError($node)) return $node; + if (PEAR::isError($node)) { + return $node; + } $res = $node; } return $res; } + /** - * Generate XML document from metadata database + * Generate XML document from metadata database * - * @return string with XML document + * @return string + * string with XML document */ function genXMLDoc() { - require_once "XML/Util.php"; + require_once("XML/Util.php"); $res = XML_Util::getXMLDeclaration("1.0", "UTF-8")."\n"; $row = $this->dbc->getRow(" SELECT * FROM {$this->mdataTable} WHERE gunid=x'{$this->gunid}'::bigint AND subjns='_G' AND subject='{$this->gunid}' "); - if(PEAR::isError($row)) return $row; - if(is_null($row)){ + if (PEAR::isError($row)) { + return $row; + } + if (is_null($row)) { $node = XML_Util::createTagFromArray(array( 'localpart'=>'none' )); - }else{ + } else { $node = $this->genXMLNode($row); - if(PEAR::isError($node)) return $node; + if (PEAR::isError($node)) { + return $node; + } } $res .= $node; - require_once "XML/Beautifier.php"; + require_once("XML/Beautifier.php"); $fmt = new XML_Beautifier(); # $res = $fmt->formatString($res); return $res; } + /** - * Generate XML element from database + * Generate XML element from database * - * @param row array, hash with metadata record fields - * @param genXML boolean, if TRUE generate XML else PHP array - * @return string, XML serialization of node + * @param array $row + * hash with metadata record fields + * @param boolean $genXML + * if TRUE generate XML else PHP array + * @return string + * XML serialization of node */ function genXMLNode($row, $genXML=TRUE) { - if(DEBUG) echo"genXMLNode:\n"; - if(DEBUG) var_dump($row); + if (DEBUG) { + echo"genXMLNode:\n"; + } + if (DEBUG) { + var_dump($row); + } extract($row); $arr = $this->getSubrows($id, $genXML); - if(PEAR::isError($arr)) return $arr; - if(DEBUG) var_dump($arr); + if (PEAR::isError($arr)) { + return $arr; + } + if (DEBUG) { + var_dump($arr); + } extract($arr); // attr, children, nSpaces - if($genXML){ + if ($genXML) { $node = XML_Util::createTagFromArray(array( 'namespace' => $predns, 'localPart' => $predicate, @@ -797,7 +970,7 @@ class MetaData{ 'content' => (is_null($object) ? $children : htmlspecialchars($object)), ), FALSE); // 'content' => (is_null($object) ? $children : htmlentities($object, ENT_COMPAT, 'UTF-8')), - }else{ + } else { $node = array_merge( array( 'elementname' => ($predns ? "$predns:" : '').$predicate, @@ -809,21 +982,26 @@ class MetaData{ return $node; } + /** - * Return values of attributes, child nodes and namespaces for - * one metadata record + * Return values of attributes, child nodes and namespaces for + * one metadata record * - * @param parid int, local id of parent metadata record - * @param genXML boolean, if TRUE generate XML else PHP array for - * children - * @return hash with three fields: + * @param int $parid + * local id of parent metadata record + * @param boolean $genXML + * if TRUE generate XML else PHP array for children + * @return array + * hash with three fields: * - attr hash, attributes * - children array, child nodes * - nSpaces hash, namespace definitions */ function getSubrows($parid, $genXML=TRUE) { - if(DEBUG) echo" getSubrows:\n"; + if (DEBUG) { + echo" getSubrows:\n"; + } $qh = $this->dbc->query($q = " SELECT id, predxml, predns, predicate, objns, object @@ -833,37 +1011,46 @@ class MetaData{ gunid=x'{$this->gunid}'::bigint ORDER BY id "); - if(PEAR::isError($qh)) return $qh; - $attrs = array(); - $children = array(); - $nSpaces = array(); - if(DEBUG) echo " #=".$qh->numRows()."\n$q\n"; - while($row = $qh->fetchRow()){ - if(DEBUG) var_dump($row); + if (PEAR::isError($qh)) { + return $qh; + } + $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){ - case"N": - $nSpaces["$predicate"] = $object; -// $nSpaces["$predicate"] = htmlentities($object, ENT_COMPAT, 'UTF-8'); - case"A": - $sep=':'; - if($predns=='' || $predicate=='') $sep=''; - $attrs["{$predns}{$sep}{$predicate}"] = $object; -// $attrs["{$predns}{$sep}{$predicate}"] = htmlentities($object, ENT_COMPAT, 'UTF-8'); - break; - case"T": - $children[] = $this->genXMLNode($row, $genXML); - break; - default: - return PEAR::raiseError( - "MetaData::getSubrows: unknown predxml ($predxml)"); + switch ($predxml) { + case "N": + $nSpaces["$predicate"] = $object; + // $nSpaces["$predicate"] = htmlentities($object, ENT_COMPAT, 'UTF-8'); + case "A": + $sep=':'; + if($predns=='' || $predicate=='') $sep=''; + $attrs["{$predns}{$sep}{$predicate}"] = $object; + // $attrs["{$predns}{$sep}{$predicate}"] = htmlentities($object, ENT_COMPAT, 'UTF-8'); + break; + case "T": + $children[] = $this->genXMLNode($row, $genXML); + break; + default: + return PEAR::raiseError( + "MetaData::getSubrows: unknown predxml ($predxml)"); } // switch } $qh->free(); - if($genXML) $children = join(" ", $children); + if ($genXML) { + $children = join(" ", $children); + } return compact('attrs', 'children', 'nSpaces'); } - + + /* ========================================================= test methods */ /** * Test method @@ -873,10 +1060,15 @@ class MetaData{ function test() { $res = $this->replace(getcwd().'/mdata2.xml'); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $this->getMetaData(); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } -} -?> + +} // class MetaData +?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/Playlist.php b/livesupport/src/modules/storageServer/var/Playlist.php index 2457f5b78..7ec478bd2 100644 --- a/livesupport/src/modules/storageServer/var/Playlist.php +++ b/livesupport/src/modules/storageServer/var/Playlist.php @@ -1,80 +1,75 @@ + * Create instance of Playlist object and recall existing file + * by gunid.
    * - * @param gb reference to GreenBox object - * @param gunid string, global unique id - * @param className string, optional classname to recall - * @return instance of Playlist object + * @param GreenBox $gb + * reference to GreenBox object + * @param string $gunid + * global unique id + * @param string $className + * optional classname to recall + * @return Playlist + * instance of Playlist object */ function &recallByGunid(&$gb, $gunid, $className='Playlist') { return parent::recallByGunid($gb, $gunid, $className); } + /** - * Create instance of Playlist object and recall existing file - * by access token.
    + * Create instance of Playlist object and recall existing file + * by access token.
    * - * @param gb reference to GreenBox object - * @param token string, access token - * @param className string, optional classname to recall - * @return instance of Playlist object + * @param GreenBox $gb + * reference to GreenBox object + * @param string $token + * access token + * @param string $className + * optional classname to recall + * @return Playlist + * instance of Playlist object */ function &recallByToken(&$gb, $token, $className='Playlist') { return parent::recallByToken($gb, $token, $className); } + /** - * Create instance of Playlist object and insert new file + * Create instance of Playlist object and insert new file * - * @param gb reference to GreenBox object - * @param oid int, local object id in the tree - * @param fname string, name of new file - * @param mediaFileLP string, ignored - * @param metadata string, local path to playlist XML file or XML string - * @param mdataLoc string 'file'|'string' (optional) - * @param plid global unique id (optional) - for insert file with gunid - * @param ftype string, ignored - * @return instance of Playlist object + * @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 */ function &insert(&$gb, $oid, $fname, $mediaFileLP='', $metadata='', $mdataLoc='file', @@ -83,52 +78,72 @@ class Playlist extends StoredFile{ return parent::insert($gb, $oid, $fname, '', $metadata, $mdataLoc, $plid, 'playlist', 'Playlist'); } - + + /** * Create instance of Playlist object and insert empty file - * - * @param gb reference to GreenBox object - * @param plid global unique id - * @param fname string, name of new file - * @param parid int, local object id of parent folder - * @return instance of Playlist object + * + * @param GreenBox $gb + * reference to GreenBox object + * @param global $plid + * unique id + * @param string $fname + * name of new file + * @param int $parid + * local object id of parent folder + * @return instance of Playlist object */ function &create(&$gb, $plid, $fname=NULL, $parid=NULL) { $tmpFname = uniqid(''); $oid = $this->addObj($tmpFname , 'playlist', $parid); - if(PEAR::isError($oid)) return $oid; + if (PEAR::isError($oid)) { + return $oid; + } $pl =& Playlist::insert($this, $oid, '', '', dirname(__FILE__).'/emptyPlaylist.xml', 'file', $plid ); - if(PEAR::isError($pl)){ + if (PEAR::isError($pl)) { $res = $this->removeObj($oid); return $pl; } $fname = ($fname == '' || is_null($fname) ? "newFile.xml" : $fname ); $res = $this->bsRenameFile($oid, $fname); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $pl->setState('ready'); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $pl->setMime('application/smil'); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $pl->setAuxMetadata(); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return $pl; } + /** * Lock playlist for edit * - * @param gb reference to GreenBox object - * @param subjid int, local subject (user) id - * @param val boolean, if false do unlock - * @return boolean, previous state or error object + * @param GreenBox $gb + * reference to GreenBox object + * @param int $subjid + * local subject (user) id + * @param boolean $val + * if false do unlock + * @return boolean + * previous state or error object */ function lock(&$gb, $subjid=NULL, $val=TRUE) { - if($val && $gb->_isEdited($this->gunid) !== FALSE){ + if ($val && $gb->_isEdited($this->gunid) !== FALSE) { return PEAR::raiseError( 'Playlist::lock: playlist already locked' ); @@ -136,48 +151,65 @@ class Playlist extends StoredFile{ $r = $gb->_setEditFlag($this->gunid, $val, NULL, $subjid); return $r; } - + + /** - * Unlock playlist (+recalculate and pregenerate XML) + * Unlock playlist (+recalculate and pregenerate XML) * - * @param gb reference to GreenBox object - * @return boolean, previous state or error object + * @param GreenBox $gb + * reference to GreenBox object + * @return boolean + * previous state or error object */ function unLock(&$gb) { $r = $this->recalculateTimes(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $this->md->regenerateXmlFile(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $this->lock($gb, $this->gunid, NULL, FALSE); return $r; } - + + /** - * Set values of auxiliary metadata + * Set values of auxiliary metadata * - * @return boolean true or error object + * @return mixed + * true or error object */ function setAuxMetadata() { // get info about playlist $plInfo = $r = $this->getPlInfo(); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } extract($plInfo); // 'plLen', 'parid', 'metaParid' // set gunid as id attr in playlist tag: $mid = $r = $this->_getMidOrInsert('id', $parid, $this->gunid, 'A'); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } $r = $this->_setValueOrInsert( $mid, $this->gunid, $parid, 'id', 'A'); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return TRUE; } - + + /** - * Get audioClip legth and title + * Get audioClip legth and title * - * @param acId int, local id of audioClip inserted to playlist - * @return array with fields: + * @param int $acId + * local id of audioClip inserted to playlist + * @return array with fields: *