From df89686c169d6798f914d4ffa44db580f5608f61 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 15 Sep 2006 13:13:38 +0000 Subject: [PATCH] Attempt to fix bug #1709 - where names are not escaped before being used in database queries. Also converted some files to be partially compatible with Campware coding conventions. --- livesupport/src/modules/alib/var/class.php | 19 +- livesupport/src/modules/alib/var/m2tree.php | 2 + .../modules/storageServer/var/BasicStor.php | 1333 +++++++++++------ .../src/modules/storageServer/var/LocStor.php | 696 ++++++--- .../modules/storageServer/var/StoredFile.php | 431 ++++-- 5 files changed, 1622 insertions(+), 859 deletions(-) diff --git a/livesupport/src/modules/alib/var/class.php b/livesupport/src/modules/alib/var/class.php index c2a198db8..3bee81cc2 100644 --- a/livesupport/src/modules/alib/var/class.php +++ b/livesupport/src/modules/alib/var/class.php @@ -2,26 +2,26 @@ /*------------------------------------------------------------------------------ Copyright (c) 2004 Media Development Loan Fund - + This file is part of the LiveSupport project. http://livesupport.campware.org/ To report bugs, send an e-mail to bugs@campware.org - + LiveSupport is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + LiveSupport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with LiveSupport; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - + + Author : $Author$ Version : $Revision$ Location : $URL$ @@ -161,6 +161,7 @@ class ObjClasses extends M2tree{ */ function getClassId($cname) { + $cname = pg_escape_string($cname); return $this->dbc->getOne($query = "SELECT id FROM {$this->classTable} WHERE cname='$cname'"); } @@ -235,7 +236,7 @@ class ObjClasses extends M2tree{ ))."\n"; return $r; } - + /** * Delete all classes and membeship records * @@ -261,7 +262,7 @@ class ObjClasses extends M2tree{ $this->addObj2Class($o['cl2'], $this->tdata['tree']['pb']); $this->tdata['classes'] = $o; } - + /** * Make basic test * @@ -280,7 +281,7 @@ class ObjClasses extends M2tree{ $this->test_dump .= $this->dumpClasses(); $this->deleteData(); if($this->test_dump==$this->test_correct){ - $this->test_log.="class: OK\n"; return TRUE; + $this->test_log.="class: OK\n"; return TRUE; }else return PEAR::raiseError( 'ObjClasses::test:', 1, PEAR_ERROR_DIE, '%s'. "
\ncorrect:\n{$this->test_correct}\n".
diff --git a/livesupport/src/modules/alib/var/m2tree.php b/livesupport/src/modules/alib/var/m2tree.php
index b483edd82..7a9264d31 100644
--- a/livesupport/src/modules/alib/var/m2tree.php
+++ b/livesupport/src/modules/alib/var/m2tree.php
@@ -323,6 +323,7 @@ class M2tree{
         if ($this->dbc->isError($xid)) {
             return $xid;
         }
+        $newName = pg_escape_string($newName);
         $r = $this->dbc->query("
             UPDATE {$this->treeTable}
             SET name='$newName'
@@ -348,6 +349,7 @@ class M2tree{
         if ( ($name == '') && is_null($parId)) {
             $name = $this->rootNodeName;
         }
+        $name = pg_escape_string($name);
         $parcond = (is_null($parId) ? "parid is null" :
             "parid='$parId' AND level=1");
         $r = $this->dbc->getOne("
diff --git a/livesupport/src/modules/storageServer/var/BasicStor.php b/livesupport/src/modules/storageServer/var/BasicStor.php
index 344e27a35..7a4dbf307 100644
--- a/livesupport/src/modules/storageServer/var/BasicStor.php
+++ b/livesupport/src/modules/storageServer/var/BasicStor.php
@@ -2,26 +2,26 @@
 /*------------------------------------------------------------------------------
 
     Copyright (c) 2004 Media Development Loan Fund
- 
+
     This file is part of the LiveSupport project.
     http://livesupport.campware.org/
     To report bugs, send an e-mail to bugs@campware.org
- 
+
     LiveSupport is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
-  
+
     LiveSupport is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
- 
+
     You should have received a copy of the GNU General Public License
     along with LiveSupport; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- 
- 
+
+
     Author   : $Author$
     Version  : $Revision$
     Location : $URL$
@@ -58,7 +58,7 @@ require_once "Transport.php";
  *  @version $Revision$
  *  @see Alib
  */
-class BasicStor extends Alib{
+class BasicStor extends Alib {
     var $filesTable;
     var $mdataTable;
     var $accessTable;
@@ -72,8 +72,8 @@ class BasicStor extends Alib{
     /**
      *  Constructor
      *
-     *  @param dbc PEAR::db abstract class reference
-     *  @param config config array from conf.php
+     *  @param PEAR::db $dbc abstract class reference
+     *  @param config $config array from conf.php
      *  @return class instance
      */
     function BasicStor(&$dbc, $config)
@@ -94,11 +94,12 @@ class BasicStor extends Alib{
         $this->dbc->setErrorHandling();
     }
 
+
     /**
      *  Create new folder
      *
-     *  @param parid int, parent id
-     *  @param folderName string, name for new folder
+     *  @param int $parid, parent id
+     *  @param string $folderName, name for new folder
      *  @return id of new folder
      *  @exception PEAR::error
      */
@@ -107,31 +108,34 @@ class BasicStor extends Alib{
         return $this->addObj($folderName , 'Folder', $parid);
     }
 
+
     /**
      *  Store new file in the storage
      *
-     *  @param parid int, parent id
-     *  @param fileName string, name for new file
-     *  @param mediaFileLP string, local path of media file
-     *  @param mdataFileLP string, local path of metadata file
-     *  @param gunid string, global unique id OPTIONAL
-     *  @param ftype string, internal file type
-     *  @param mdataLoc string 'file'|'string' (optional)
+     *  @param int $parid, parent id
+     *  @param string $fileName, name for new file
+     *  @param string $mediaFileLP, local path of media file
+     *  @param string $mdataFileLP, local path of metadata file
+     *  @param string $gunid, global unique id OPTIONAL
+     *  @param string $ftype, internal file type
+     *  @param string $mdataLoc 'file'|'string' (optional)
      *  @return int
      *  @exception PEAR::error
      */
     function bsPutFile($parid, $fileName, $mediaFileLP, $mdataFileLP,
         $gunid=NULL, $ftype='unKnown', $mdataLoc='file')
     {
-        $name = $fileName;
+        $name   = pg_escape_string($fileName);
         $ftype  = strtolower($ftype);
         $id = $this->addObj($name , $ftype, $parid);
-        if($this->dbc->isError($id)) return $id;
+        if ($this->dbc->isError($id)) {
+            return $id;
+        }
         $ac =  StoredFile::insert(
             $this, $id, $name, $mediaFileLP, $mdataFileLP, $mdataLoc,
             $gunid, $ftype
         );
-        if($this->dbc->isError($ac)){
+        if ($this->dbc->isError($ac)){
             $res = $this->removeObj($id);
             // catch constraint violations
             switch($ac->getCode()){
@@ -143,60 +147,67 @@ class BasicStor extends Alib{
                     return $ac;
             }
         }
-        if($ftype == 'playlist') $ac->setMime('application/smil');
+        if ($ftype == 'playlist') {
+            $ac->setMime('application/smil');
+        }
         return $id;
-    }
+    } // fn bsPutFile
+
 
     /**
      *  Rename file
      *
-     *  @param id int, virt.file's local id
-     *  @param newName string
+     *  @param int $id, virt.file's local id
+     *  @param string $newName
      *  @return boolean or PEAR::error
      */
     function bsRenameFile($id, $newName)
     {
         $parid = $this->getParent($id);
-        switch($this->getObjType($id)){
-            case"audioclip":
-            case"playlist":
-            case"webstream":
+        switch ($this->getObjType($id)) {
+            case "audioclip":
+            case "playlist":
+            case "webstream":
                 $ac = StoredFile::recall($this, $id);
-                if($this->dbc->isError($ac)){
+                if ($this->dbc->isError($ac)) {
                     // catch nonerror exception:
                     //if($ac->getCode() != GBERR_FOBJNEX)
                     return $ac;
                 }
                 $res = $ac->rename($newName);
-                if($this->dbc->isError($res)) return $res;
+                if ($this->dbc->isError($res)) {
+                    return $res;
+                }
                 break;
-            case"File":
+            case "File":
             default:
         }
         return $this->renameObj($id, $newName);
     }
 
+
     /**
      *  Move file
      *
-     *  @param id int, virt.file's local id
-     *  @param did int, destination folder local id
+     *  @param int $id, virt.file's local id
+     *  @param int $did, destination folder local id
      *  @return boolean or PEAR::error
      */
     function bsMoveFile($id, $did)
     {
         $parid = $this->getParent($id);
-        if($this->getObjType($did) !== 'Folder')
+        if ($this->getObjType($did) !== 'Folder') {
             return PEAR::raiseError(
                 "BasicStor::moveFile: destination is not folder ($did)",
                 GBERR_WRTYPE
             );
-        switch($this->getObjType($id)){
-            case"audioclip":
-            case"playlist":
-            case"webstream":
-            case"File":
-            case"Folder":
+        }
+        switch ($this->getObjType($id)) {
+            case "audioclip":
+            case "playlist":
+            case "webstream":
+            case "File":
+            case "Folder":
                 return $this->moveObj($id, $did);
                 break;
             default:
@@ -207,28 +218,29 @@ class BasicStor extends Alib{
         }
     }
 
+
     /**
      *  Copy file
      *
-     *  @param id int, virt.file's local id
-     *  @param did int, destination folder local id
+     *  @param int $id, virt.file's local id
+     *  @param int $did, destination folder local id
      *  @return boolean or PEAR::error
      */
     function bsCopyFile($id, $did)
     {
         $parid = $this->getParent($id);
-        if($this->getObjType($did) !== 'Folder'){
+        if ($this->getObjType($did) !== 'Folder') {
             return PEAR::raiseError(
                 'BasicStor::bsCopyFile: destination is not folder',
                 GBERR_WRTYPE
             );
         }
-        switch($this->getObjType($id)){
-            case"audioclip":
-            case"playlist":
-            case"webstream":
-            case"File":
-            case"Folder":
+        switch ($this->getObjType($id)) {
+            case "audioclip":
+            case "playlist":
+            case "webstream":
+            case "File":
+            case "Folder":
                 return $this->copyObj($id, $did);
                 break;
             default:
@@ -239,61 +251,75 @@ class BasicStor extends Alib{
         }
     }
 
+
     /**
      *  Replace file. Doesn't change filetype!
      *
-     *  @param id int, virt.file's local id
-     *  @param mediaFileLP string, local path of media file
-     *  @param mdataFileLP string, local path of metadata file
-     *  @param mdataLoc string 'file'|'string' (optional)
+     *  @param int $id, virt.file's local id
+     *  @param string $mediaFileLP, local path of media file
+     *  @param string $mdataFileLP, local path of metadata file
+     *  @param string $mdataLoc 'file'|'string' (optional)
      *  @return true or PEAR::error
      *  @exception PEAR::error
      */
     function bsReplaceFile($id, $mediaFileLP, $mdataFileLP, $mdataLoc='file')
     {
         $ac = StoredFile::recall($this, $id);
-        if($this->dbc->isError($ac)) return $ac;
-        if(!empty($mdataFileLP) &&
-                ($mdataLoc!='file' || file_exists($mdataFileLP))){
-            $r = $ac->replaceMetaData($mdataFileLP, $mdataLoc);
-            if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->isError($ac)) {
+            return $ac;
         }
-        if(!empty($mediaFileLP) && file_exists($mediaFileLP)){
+        if (!empty($mdataFileLP) &&
+                ($mdataLoc!='file' || file_exists($mdataFileLP))) {
+            $r = $ac->replaceMetaData($mdataFileLP, $mdataLoc);
+            if ($this->dbc->isError($r)) {
+                return $r;
+            }
+        }
+        if (!empty($mediaFileLP) && file_exists($mediaFileLP)) {
             $r = $ac->replaceRawMediaData($mediaFileLP);
-            if($this->dbc->isError($r)) return $r;
+            if ($this->dbc->isError($r)) {
+                return $r;
+            }
         }
         return TRUE;
     }
 
+
     /**
      *  Delete file
      *
-     *  @param id int, virt.file's local id
-     *  @param forced boolean, if true don't use trash
+     *  @param int $id, virt.file's local id
+     *  @param boolean $forced, if true don't use trash
      *  @return true or PEAR::error
      */
     function bsDeleteFile($id, $forced=FALSE)
     {
         // full delete:
-        if(!$this->config['useTrash'] || $forced){
+        if (!$this->config['useTrash'] || $forced) {
             $res = $this->removeObj($id, $forced);
             return $res;
         }
         // move to trash:
         $did = $this->getObjId($this->config['TrashName'], $this->storId);
-        if($this->dbc->isError($did)) return $did;
-        switch($this->getObjType($id)){
+        if ($this->dbc->isError($did)) {
+            return $did;
+        }
+        switch ($this->getObjType($id)) {
             case"audioclip":
             case"playlist":
             case"webstream":
                 $ac = StoredFile::recall($this, $id);
-                if($this->dbc->isError($ac)) return $ac;
-                if(is_null($did)){
+                if ($this->dbc->isError($ac)) {
+                    return $ac;
+                }
+                if (is_null($did)) {
                     return PEAR::raiseError("BasicStor::bsDeleteFile: ".
                         "trash not found", GBERR_NOTF);
                 }
                 $res = $ac->setState('deleted');
-                if($this->dbc->isError($res)) return $res;
+                if ($this->dbc->isError($res)) {
+                    return $res;
+                }
                 break;
             default:
         }
@@ -301,12 +327,13 @@ class BasicStor extends Alib{
         return $res;
     }
 
+
     /* ----------------------------------------------------- put, access etc. */
     /**
      *  Check validity of asscess/put token
      *
-     *  @param token string, access/put token
-     *  @param type string 'put'|'access'|'download'
+     *  @param string $token, access/put token
+     *  @param string $type 'put'|'access'|'download'
      *  @return boolean
      */
     function bsCheckToken($token, $type='put')
@@ -315,15 +342,18 @@ class BasicStor extends Alib{
             SELECT count(token) FROM {$this->accessTable}
             WHERE token=x'{$token}'::bigint AND type='$type'
         ");
-        if($this->dbc->isError($cnt)){ return FALSE; }
+        if ($this->dbc->isError($cnt)) {
+            return FALSE;
+        }
         return ($cnt == 1);
     }
-    
+
+
     /**
      *  Get gunid from token
      *
-     *  @param token string, access/put token
-     *  @param type string 'put'|'access'|'download'
+     *  @param string $token, access/put token
+     *  @param string $type 'put'|'access'|'download'
      *  @return string
      */
     function _gunidFromToken($token, $type='put')
@@ -332,46 +362,54 @@ class BasicStor extends Alib{
             SELECT to_hex(gunid)as gunid, ext FROM {$this->accessTable}
             WHERE token=x'{$token}'::bigint AND type='$type'
         ");
-        if($this->dbc->isError($acc)){ return $acc; }
+        if ($this->dbc->isError($acc)) {
+            return $acc;
+        }
         $gunid = StoredFile::_normalizeGunid($acc['gunid']);
-        if($this->dbc->isError($gunid)){ return $gunid; }
+        if ($this->dbc->isError($gunid)) {
+            return $gunid;
+        }
         return $gunid;
     }
-    
+
+
     /**
      *  Create and return access link to real file
      *
-     *  @param realFname string, local filepath to accessed file
+     *  @param string $realFname, local filepath to accessed file
      *      (NULL for only increase access counter, no symlink)
-     *  @param ext string, useful filename extension for accessed file
-     *  @param gunid int, global unique id
+     *  @param string $ext, useful filename extension for accessed file
+     *  @param int $gunid, global unique id
      *      (NULL for special files such exported playlists)
-     *  @param type string 'access'|'download'
-     *  @param parent int parent token (recursive access/release)
-     *  @param owner int, local user id - owner of token
+     *  @param string $type 'access'|'download'
+     *  @param int $parent parent token (recursive access/release)
+     *  @param int $owner, local user id - owner of token
      *  @return array with: seekable filehandle, access token
      */
     function bsAccess($realFname, $ext, $gunid, $type='access',
         $parent='0', $owner=NULL)
     {
-        if(!is_null($gunid)){
+        if (!is_null($gunid)) {
             $gunid = StoredFile::_normalizeGunid($gunid);
         }
-        foreach(array('ext', 'type') as $v) $$v = pg_escape_string($$v);
+        $ext = pg_escape_string($ext);
+        $type = pg_escape_string($type);
         $token  = StoredFile::_createGunid();
-        if(!is_null($realFname)){
+        if (!is_null($realFname)) {
             $linkFname = "{$this->accessDir}/$token.$ext";
-            if(!file_exists($realFname)){
+            if (!file_exists($realFname)) {
                 return PEAR::raiseError(
                     "BasicStor::bsAccess: real file not found ($realFname)",
                     GBERR_FILEIO);
             }
-            if(! @symlink($realFname, $linkFname)){
+            if (! @symlink($realFname, $linkFname)) {
                 return PEAR::raiseError(
                     "BasicStor::bsAccess: symlink create failed ($linkFname)",
                     GBERR_FILEIO);
             }
-        }else $linkFname=NULL;
+        } else {
+            $linkFname=NULL;
+        }
         $this->dbc->query("BEGIN");
         $gunidSql = (is_null($gunid) ? "NULL" : "x'{$gunid}'::bigint" );
         $ownerSql = (is_null($owner) ? "NULL" : "$owner" );
@@ -382,27 +420,34 @@ class BasicStor extends Alib{
                 ($gunidSql, x'$token'::bigint,
                 '$ext', '$type', x'{$parent}'::bigint, $ownerSql, now())
         ");
-        if($this->dbc->isError($res)){
-            $this->dbc->query("ROLLBACK"); return $res; }
-        if(!is_null($gunid)){
+        if ($this->dbc->isError($res)) {
+            $this->dbc->query("ROLLBACK");
+            return $res;
+        }
+        if (!is_null($gunid)) {
             $res = $this->dbc->query("
                 UPDATE {$this->filesTable}
                 SET currentlyAccessing=currentlyAccessing+1, mtime=now()
                 WHERE gunid=x'{$gunid}'::bigint
             ");
         }
-        if($this->dbc->isError($res)){
-            $this->dbc->query("ROLLBACK"); return $res; }
+        if ($this->dbc->isError($res)) {
+            $this->dbc->query("ROLLBACK");
+            return $res;
+        }
         $res = $this->dbc->query("COMMIT");
-        if($this->dbc->isError($res)){ return $res; }
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         return array('fname'=>$linkFname, 'token'=>$token);
     }
 
+
     /**
      *  Release access link to real file
      *
-     *  @param token string, access token
-     *  @param type string 'access'|'download'
+     *  @param string $token, access token
+     *  @param string $type 'access'|'download'
      *  @return hasharray
      *      gunid: string, global unique ID or real pathname of special file
      *      owner: int, local subject id of token owner
@@ -410,7 +455,7 @@ class BasicStor extends Alib{
      */
     function bsRelease($token, $type='access')
     {
-        if(!$this->bsCheckToken($token, $type)){
+        if (!$this->bsCheckToken($token, $type)) {
             return PEAR::raiseError(
              "BasicStor::bsRelease: invalid token ($token)"
             );
@@ -419,34 +464,44 @@ class BasicStor extends Alib{
             SELECT to_hex(gunid)as gunid, ext, owner FROM {$this->accessTable}
             WHERE token=x'{$token}'::bigint AND type='$type'
         ");
-        if($this->dbc->isError($acc)){ return $acc; }
+        if ($this->dbc->isError($acc)) {
+            return $acc;
+        }
         $ext = $acc['ext'];
         $owner = $acc['owner'];
         $linkFname = "{$this->accessDir}/$token.$ext";
         $realFname = readlink($linkFname);
-        if(file_exists($linkFname)) if(! @unlink($linkFname)){
-            return PEAR::raiseError(
-                "BasicStor::bsRelease: unlink failed ($linkFname)",
-                GBERR_FILEIO);
+        if (file_exists($linkFname)) {
+            if(! @unlink($linkFname)){
+                return PEAR::raiseError(
+                    "BasicStor::bsRelease: unlink failed ($linkFname)",
+                    GBERR_FILEIO);
+            }
         }
         $this->dbc->query("BEGIN");
-        if(!is_null($acc['gunid'])){
+        if (!is_null($acc['gunid'])) {
             $gunid = StoredFile::_normalizeGunid($acc['gunid']);
             $res = $this->dbc->query("
                 UPDATE {$this->filesTable}
                 SET currentlyAccessing=currentlyAccessing-1, mtime=now()
                 WHERE gunid=x'{$gunid}'::bigint AND currentlyAccessing>0
             ");
-            if($this->dbc->isError($res)){
-                $this->dbc->query("ROLLBACK"); return $res; }
+            if ($this->dbc->isError($res)) {
+                $this->dbc->query("ROLLBACK");
+                return $res;
+            }
         }
         $res = $this->dbc->query("
             DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
         ");
-        if($this->dbc->isError($res)){
-            $this->dbc->query("ROLLBACK"); return $res; }
+        if ($this->dbc->isError($res)) {
+            $this->dbc->query("ROLLBACK");
+            return $res;
+        }
         $res = $this->dbc->query("COMMIT");
-        if($this->dbc->isError($res)){ return $res; }
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         $res = array(
             'gunid' => (isset($gunid) ? $gunid : NULL ),
             'realFname' => $realFname,
@@ -455,21 +510,24 @@ class BasicStor extends Alib{
         return $res;
     }
 
+
     /**
      *  Create and return downloadable URL for file
      *
-     *  @param id int, virt.file's local id
-     *  @param part string, 'media'|'metadata'
-     *  @param parent int parent token (recursive access/release)
+     *  @param int $id, virt.file's local id
+     *  @param string $part, 'media'|'metadata'
+     *  @param int $parent parent token (recursive access/release)
      *  @return array with strings:
      *      downloadable URL, download token, chsum, size, filename
      */
     function bsOpenDownload($id, $part='media', $parent='0')
     {
         $ac = StoredFile::recall($this, $id);
-        if($this->dbc->isError($ac)) return $ac;
-        $gunid      = $ac->gunid;
-        switch($part){
+        if ($this->dbc->isError($ac)) {
+            return $ac;
+        }
+        $gunid = $ac->gunid;
+        switch ($part) {
             case"media":
                 $realfile  = $ac->_getRealRADFname();
                 $ext       = $ac->_getExt();
@@ -486,7 +544,9 @@ class BasicStor extends Alib{
                 );
         }
         $acc = $this->bsAccess($realfile, $ext, $gunid, 'download', $parent);
-        if($this->dbc->isError($acc)){ return $acc; }
+        if ($this->dbc->isError($acc)) {
+            return $acc;
+        }
         $url = $this->getUrlPart()."access/".basename($acc['fname']);
         $chsum = md5_file($realfile);
         $size = filesize($realfile);
@@ -497,32 +557,36 @@ class BasicStor extends Alib{
         );
     }
 
+
     /**
      *  Discard downloadable URL
      *
-     *  @param token string, download token
-     *  @param part string, 'media'|'metadata'
+     *  @param string $token, download token
+     *  @param string $part, 'media'|'metadata'
      *  @return string, gunid
      */
     function bsCloseDownload($token, $part='media')
     {
-        if(!$this->bsCheckToken($token, 'download')){
+        if (!$this->bsCheckToken($token, 'download')) {
             return PEAR::raiseError(
              "BasicStor::bsCloseDownload: invalid token ($token)"
             );
         }
         $r = $this->bsRelease($token, 'download');
-        if($this->dbc->isError($r)){ return $r; }
+        if ($this->dbc->isError($r)){
+            return $r;
+        }
         return (is_null($r['gunid']) ? $r['realFname'] : $r['gunid']);
     }
 
+
     /**
      *  Create writable URL for HTTP PUT method file insert
      *
-     *  @param chsum string, md5sum of the file having been put
-     *  @param gunid string, global unique id
+     *  @param string $chsum, md5sum of the file having been put
+     *  @param string $gunid, global unique id
      *      (NULL for special files such imported playlists)
-     *  @param owner int, local user id - owner of token
+     *  @param int $owner, local user id - owner of token
      *  @return hasharray with:
      *      url string: writable URL
      *      fname string: writable local filename
@@ -530,16 +594,18 @@ class BasicStor extends Alib{
      */
     function bsOpenPut($chsum, $gunid, $owner=NULL)
     {
-        if(!is_null($gunid)){
+        if (!is_null($gunid)) {
             $gunid = StoredFile::_normalizeGunid($gunid);
         }
-        foreach(array('chsum') as $v) $$v = pg_escape_string($$v);
+        $chsum = pg_escape_string($chsum);
         $ext    = '';
         $token  = StoredFile::_createGunid();
         $res    = $this->dbc->query("
             DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
         ");
-        if($this->dbc->isError($res)){ return $res; }
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         $gunidSql = (is_null($gunid) ? "NULL" : "x'{$gunid}'::bigint" );
         $ownerSql = (is_null($owner) ? "NULL" : "$owner" );
         $res    = $this->dbc->query("
@@ -549,18 +615,21 @@ class BasicStor extends Alib{
                 ($gunidSql, x'$token'::bigint,
                     '$ext', '$chsum', 'put', $ownerSql, now())
         ");
-        if($this->dbc->isError($res)){ return $res; }
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         $fname = "{$this->accessDir}/$token";
         touch($fname);      // is it needed?
         $url = $this->getUrlPart()."xmlrpc/put.php?token=$token";
         return array('url'=>$url, 'fname'=>$fname, 'token'=>$token);
     }
 
+
     /**
      *  Get file from writable URL and return local filename.
      *  Caller should move or unlink this file.
      *
-     *  @param token string, PUT token
+     *  @param string $token, PUT token
      *  @return hash with fields:
      *      fname string, local path of the file having been put
      *      owner int, local subject id - owner of token
@@ -568,7 +637,7 @@ class BasicStor extends Alib{
     function bsClosePut($token)
     {
         $token = StoredFile::_normalizeGunid($token);
-        if(!$this->bsCheckToken($token, 'put')){
+        if (!$this->bsCheckToken($token, 'put')) {
             return PEAR::raiseError(
              "BasicStor::bsClosePut: invalid token ($token)",
              GBERR_TOKEN
@@ -578,17 +647,23 @@ class BasicStor extends Alib{
             SELECT chsum, owner FROM {$this->accessTable}
             WHERE token=x'{$token}'::bigint
         ");
-        if($this->dbc->isError($row)){ return $row; }
+        if ($this->dbc->isError($row)) {
+            return $row;
+        }
         $chsum = $row['chsum'];
         $owner = $row['owner'];
         $res = $this->dbc->query("
             DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
         ");
-        if($this->dbc->isError($res)){ return $res; }
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         $fname = "{$this->accessDir}/$token";
         $md5sum = md5_file($fname);
         if(trim($chsum) !='' && $chsum != $md5sum){
-            if(file_exists($fname)) @unlink($fname);
+            if (file_exists($fname)) {
+                @unlink($fname);
+            }
             return PEAR::raiseError(
              "BasicStor::bsClosePut: md5sum does not match (token=$token)".
              " [$chsum/$md5sum]",
@@ -598,10 +673,11 @@ class BasicStor extends Alib{
         return array('fname'=>$fname, 'owner'=>$owner);
     }
 
+
     /**
      *  Check uploaded file
      *
-     *  @param token string, put token
+     *  @param string $token, put token
      *  @return hash, (
      *      status: boolean,
      *      size: int - filesize
@@ -611,7 +687,7 @@ class BasicStor extends Alib{
      */
     function bsCheckPut($token)
     {
-        if(!$this->bsCheckToken($token, 'put')){
+        if (!$this->bsCheckToken($token, 'put')) {
             return PEAR::raiseError(
              "BasicStor::bsCheckPut: invalid token ($token)"
             );
@@ -620,7 +696,9 @@ class BasicStor extends Alib{
             SELECT chsum FROM {$this->accessTable}
             WHERE token=x'{$token}'::bigint
         ");
-        if($this->dbc->isError($chsum)){ return $chsum; }
+        if ($this->dbc->isError($chsum)) {
+            return $chsum;
+        }
         $fname = "{$this->accessDir}/$token";
         $md5sum = md5_file($fname);
         $size = filesize($fname);
@@ -632,6 +710,7 @@ class BasicStor extends Alib{
         );
     }
 
+
     /**
      *  Return starting part of storageServer URL
      *
@@ -644,7 +723,8 @@ class BasicStor extends Alib{
         $path  = $this->config['storageUrlPath'];
         return "http://$host:$port$path/";
     }
-    
+
+
     /**
      *  Return local subject id of token owner
      *
@@ -657,11 +737,14 @@ class BasicStor extends Alib{
             SELECT owner FROM {$this->accessTable}
             WHERE token=x'{$token}'::bigint
         ");
-        if($this->dbc->isError($row)){ return $row; }
+        if ($this->dbc->isError($row)) {
+            return $row;
+        }
         $owner = $row;
     }
-    
-    /** 
+
+
+    /**
      *  Get tokens by type
      *
      *  @param type: string - access|put|render etc.
@@ -677,92 +760,112 @@ class BasicStor extends Alib{
         }
         return $r;
     }
-    
+
+
     /* ----------------------------------------------------- metadata methods */
 
     /**
      *  Replace metadata with new XML file or string
      *
-     *  @param id int, virt.file's local id
-     *  @param mdata string, local path of metadata XML file
-     *  @param mdataLoc string 'file'|'string'
+     *  @param int $id, virt.file's local id
+     *  @param string $mdata, local path of metadata XML file
+     *  @param string $mdataLoc 'file'|'string'
      *  @return boolean or PEAR::error
      */
     function bsReplaceMetadata($id, $mdata, $mdataLoc='file')
     {
         $ac = StoredFile::recall($this, $id);
-        if($this->dbc->isError($ac)) return $ac;
+        if ($this->dbc->isError($ac)) {
+            return $ac;
+        }
         return $ac->replaceMetaData($mdata, $mdataLoc);
     }
-    
+
+
     /**
      *  Get metadata as XML string
      *
-     *  @param id int, virt.file's local id
+     *  @param int $id, virt.file's local id
      *  @return string or PEAR::error
      */
     function bsGetMetadata($id)
     {
         $ac = StoredFile::recall($this, $id);
-        if($this->dbc->isError($ac)) return $ac;
+        if ($this->dbc->isError($ac)) {
+            return $ac;
+        }
         return $ac->getMetaData();
     }
 
+
     /**
      *  Get dc:title (if exists)
      *
-     *  @param id int, virt.file's local id
-     *  @param gunid string, virt.file's gunid, optional, used only if not
+     *  @param int $id, virt.file's local id
+     *  @param string $gunid, virt.file's gunid, optional, used only if not
      *          null, id is then ignored
-     *  @param lang string, optional xml:lang value for select language version
-     *  @param deflang string, optional xml:lang for default language
+     *  @param string $lang, optional xml:lang value for select language version
+     *  @param string $deflang, optional xml:lang for default language
      *  @return string or PEAR::error
      */
     function bsGetTitle($id, $gunid=NULL, $lang=NULL, $deflang=NULL)
     {
-        if(is_null($gunid)) $ac = StoredFile::recall($this, $id);
-        else $ac = $r = StoredFile::recallByGunid($this, $gunid);
-        if($this->dbc->isError($r)) return $r;
+        if (is_null($gunid)) {
+            $ac = StoredFile::recall($this, $id);
+        } else {
+            $ac = $r = StoredFile::recallByGunid($this, $gunid);
+        }
+        if ($this->dbc->isError($r)) {
+            return $r;
+        }
         $r = $ac->md->getMetadataValue('dc:title', $lang, $deflang);
-        if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->isError($r)) {
+            return $r;
+        }
         $title = (isset($r[0]['value']) ? $r[0]['value'] : 'unknown');
         return $title;
     }
 
+
     /**
      *  Get metadata element value
      *
-     *  @param id int, virt.file's local id
-     *  @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 int $id, virt.file's local id
+     *  @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
      *  @return array of matching records (as hash {id, value, attrs})
      *  @see Metadata::getMetadataValue
      */
     function bsGetMetadataValue($id, $category, $lang=NULL, $deflang=NULL)
-    {   
+    {
         $ac = StoredFile::recall($this, $id);
-        if($this->dbc->isError($ac)) return $ac;
+        if ($this->dbc->isError($ac)) {
+            return $ac;
+        }
         return $ac->md->getMetadataValue($category, $lang, $deflang);
     }
-    
+
+
     /**
      *  Set metadata element value
      *
-     *  @param id int, virt.file's local id
-     *  @param category string, metadata element identification (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
-     *  @param regen boolean, optional flag, if true, regenerate XML file
+     *  @param int $id, virt.file's local id
+     *  @param string $category, metadata element identification (e.g. dc:title)
+     *  @param string $value/NULL 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
+     *  @param boolean $regen, optional flag, if true, regenerate XML file
      *  @return boolean
      */
     function bsSetMetadataValue($id, $category, $value,
         $lang=NULL, $mid=NULL, $container='metadata', $regen=TRUE)
     {
         $ac = StoredFile::recall($this, $id);
-        if($this->dbc->isError($ac)) return $ac;
+        if ($this->dbc->isError($ac)) {
+            return $ac;
+        }
         /* disabled - html ui change only nonimportant categories
         if($ac->isEdited()){
             return PEAR::raiseError(
@@ -770,28 +873,33 @@ class BasicStor extends Alib{
             );
         }
         */
-        if($category == 'dcterms:extent'){
+        if ($category == 'dcterms:extent') {
             $value = $this->normalizeExtent($value);
         }
         $res = $ac->md->setMetadataValue(
             $category, $value, $lang, $mid, $container);
-        if($this->dbc->isError($res)) return $res;
-        if($regen){
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
+        if ($regen) {
             $r = $ac->md->regenerateXmlFile();
-            if($this->dbc->isError($r)) return $r;
+            if ($this->dbc->isError($r)) {
+                return $r;
+            }
         }
         return $res;
     }
 
+
     /**
      *  Normalize time value to hh:mm:ss:dddddd format
      *
-     *  @param v mixed, value to normalize
+     *  @param mixed $v, value to normalize
      *  @return string
      */
     function normalizeExtent($v)
     {
-        if(!preg_match("|^\d{2}:\d{2}:\d{2}.\d{6}$|", $v)){
+        if (!preg_match("|^\d{2}:\d{2}:\d{2}.\d{6}$|", $v)) {
             require_once"Playlist.php";
             $s = Playlist::_plTimeToSecs($v);
             $t = Playlist::_secsToPlTime($s);
@@ -799,45 +907,55 @@ class BasicStor extends Alib{
         }
         return $v;
     }
-    
+
+
     /**
      *  Set metadata values in 'batch' mode
      *
-     *  @param id int, virt.file's local id
-     *  @param values hasharray, array of key/value pairs
+     *  @param int $id, virt.file's local id
+     *  @param hasharray $values, array of key/value pairs
      *      (e.g. 'dc:title'=>'New title')
-     *  @param lang string, optional xml:lang value for select language version
-     *  @param container string, container element name for insert
-     *  @param regen boolean, optional flag, if true, regenerate XML file
+     *  @param string $lang, optional xml:lang value for select language version
+     *  @param string $container, container element name for insert
+     *  @param boolean $regen, optional flag, if true, regenerate XML file
      *  @return boolean
      */
     function bsSetMetadataBatch(
         $id, $values, $lang=NULL, $container='metadata', $regen=TRUE)
     {
-        if(!is_array($values)) $values = array($values);
-        foreach($values as $category=>$oneValue){
+        if (!is_array($values)) {
+            $values = array($values);
+        }
+        foreach ($values as $category=>$oneValue) {
             $res = $this->bsSetMetadataValue($id, $category, $oneValue,
                 $lang, NULL, $container, FALSE);
-            if($this->dbc->isError($res)) return $res;
+            if ($this->dbc->isError($res)) {
+                return $res;
+            }
         }
-        if($regen){
+        if ($regen) {
             $ac = StoredFile::recall($this, $id);
-            if($this->dbc->isError($ac)) return $ac;
+            if ($this->dbc->isError($ac)) {
+                return $ac;
+            }
             $r = $ac->md->regenerateXmlFile();
-            if($this->dbc->isError($r)) return $r;
+            if ($this->dbc->isError($r)) {
+                return $r;
+            }
         }
         return TRUE;
     }
 
+
     /**
      *  Search in local metadata database.
      *
-     *  @param criteria hash, with following structure:
+ * @param hash $criteria, with following structure:
* * * - * @param limit int, limit for result arrays (0 means unlimited) - * @param offset int, starting point (0 means without offset) + * @param int $limit, limit for result arrays (0 means unlimited) + * @param int $offset, starting point (0 means without offset) * @return array 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 @@ -875,18 +993,21 @@ class BasicStor extends Alib{ require_once "DataEngine.php"; $de =& new DataEngine($this); $res = $r = $de->localSearch($criteria, $limit, $offset); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $res; } + /** * Return values of specified metadata category * - * @param category string, metadata category name + * @param string $category, metadata category name * with or without namespace prefix (dc:title, author) - * @param limit int, limit for result arrays (0 means unlimited) - * @param offset int, starting point (0 means without offset) - * @param criteria hash, see bsLocalSearch method + * @param int $limit, limit for result arrays (0 means unlimited) + * @param int $offset, starting point (0 means without offset) + * @param hash $criteria, see bsLocalSearch method * @return hash, fields: * results : array with found values * cnt : integer - number of matching values @@ -899,17 +1020,18 @@ class BasicStor extends Alib{ return $de->browseCategory($category, $limit, $offset, $criteria); } + /* ---------------------------------------------------- methods4playlists */ /** * Create a tarfile with playlist export - playlist and all matching * sub-playlists and media files (if desired) * - * @param plids - array of strings, playlist global unique IDs + * @param array $plids - array of strings, playlist global unique IDs * (one gunid is accepted too) - * @param type - string, playlist format, + * @param string $type - playlist format, * possible values: lspl | smil | m3u - * @param withContent - boolean, if true export related files too + * @param boolean $withContent - if true, export related files too * @return hasharray with fields: * fname string: readable fname, * token string: access token @@ -917,15 +1039,21 @@ class BasicStor extends Alib{ function bsExportPlaylistOpen($plids, $type='lspl', $withContent=TRUE) { require_once"Playlist.php"; - if(!is_array($plids)) $plids=array($plids); + if (!is_array($plids)) { + $plids = array($plids); + } $gunids = array(); - foreach($plids as $plid){ + foreach ($plids as $plid) { $pl = $r = Playlist::recallByGunid($this, $plid); - if(PEAR::isError($r)) return $r; - if($withContent){ + if (PEAR::isError($r)) { + return $r; + } + if ($withContent) { $gunidsX = $r = $pl->export(); - if(PEAR::isError($r)) return $r; - }else{ + if (PEAR::isError($r)) { + return $r; + } + } else { $gunidsX = array(array('gunid'=>$plid, 'type'=>'playlist')); } $gunids = array_merge($gunids, $gunidsX); @@ -937,111 +1065,147 @@ class BasicStor extends Alib{ $tmpf = "$tmpn.tar"; $tmpd = "$tmpn.dir"; mkdir($tmpd); $tmpdp = "$tmpn.dir/playlist"; mkdir($tmpdp); - if($withContent){ + if ($withContent) { $tmpdc = "$tmpn.dir/audioClip"; mkdir($tmpdc); } - foreach($gunids as $i=>$it){ + foreach ($gunids as $i => $it) { $ac = $r = StoredFile::recallByGunid($this, $it['gunid']); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $MDfname = $r = $ac->md->getFname(); - if(PEAR::isError($r)) return $r; - if(file_exists($MDfname)){ switch($it['type']){ + if (PEAR::isError($r)) { + return $r; + } + if (file_exists($MDfname)) { + switch($it['type']) { case"playlist": require_once"LsPlaylist.php"; $ac = $r = LsPlaylist::recallByGunid($this, $it['gunid']); - switch($type){ - case"smil": $string = $r = $ac->output2Smil(); break; - case"m3u": $string = $r = $ac->output2M3U(); break; - default: $string = $r = $ac->md->genXmlDoc(); + switch ($type) { + case"smil": + $string = $r = $ac->output2Smil(); + break; + case"m3u": + $string = $r = $ac->output2M3U(); + break; + default: + $string = $r = $ac->md->genXmlDoc(); + } + if (PEAR::isError($r)) { + return $r; } - if(PEAR::isError($r)) return $r; $r = $this->bsStr2File($string, "$tmpdp/{$it['gunid']}.$plExt"); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } break; - default: copy($MDfname, "$tmpdc/{$it['gunid']}.xml"); break; - }} + default: + copy($MDfname, "$tmpdc/{$it['gunid']}.xml"); break; + } // switch + } // if file_exists() $RADfname = $r =$ac->_getRealRADFname(); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $RADext = $r = $ac->_getExt(); - if(PEAR::isError($r)) return $r; - if(file_exists($RADfname)){ + if (PEAR::isError($r)) { + return $r; + } + if (file_exists($RADfname)) { copy($RADfname, "$tmpdc/{$it['gunid']}.$RADext"); } } - if(count($plids)==1){ + if (count($plids)==1) { copy("$tmpdp/$plid.$plExt", "$tmpd/exportedPlaylist.$plExt"); } $res = `cd $tmpd; tar cf $tmpf * --remove-files`; - @rmdir($tmpdc); @rmdir($tmpdp); @rmdir($tmpd); + @rmdir($tmpdc); + @rmdir($tmpdp); + @rmdir($tmpd); unlink($tmpn); $acc = $this->bsAccess($tmpf, 'tar', NULL/*gunid*/, 'access'); - if($this->dbc->isError($acc)){ return $acc; } + if ($this->dbc->isError($acc)) { + return $acc; + } return $acc; } + /** * Close playlist export previously opened by the bsExportPlaylistOpen * method * - * @param token - string, access token obtained from bsExportPlaylistOpen - * method call + * @param string $token - access token obtained from + * bsExportPlaylistOpen method call * @return boolean true or error object */ function bsExportPlaylistClose($token) { $r = $this->bsRelease($token, 'access'); - if($this->dbc->isError($r)){ return $r; } + if ($this->dbc->isError($r)) { + return $r; + } $file = $r['realFname']; - if(file_exists($file)) if(! @unlink($file)){ - return PEAR::raiseError( - "BasicStor::bsExportPlaylistClose: unlink failed ($file)", - GBERR_FILEIO); + if (file_exists($file)) { + if(! @unlink($file)){ + return PEAR::raiseError( + "BasicStor::bsExportPlaylistClose: unlink failed ($file)", + GBERR_FILEIO); + } } return TRUE; } + /** * Import playlist in LS Archive format * - * @param parid int, destination folder local id - * @param plid string, playlist gunid - * @param aPath string, absolute path part of imported file + * @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) - * @param rPath string, relative path/filename part of imported file + * @param string $rPath, relative path/filename part of imported file * (e.g. playlists/playlist_1.smil) - * @param ext string, playlist extension (determines type of import) - * @param gunids hasharray, hash relation from filenames to gunids - * @param subjid int, local subject (user) id (id of user doing the import) + * @param string $ext, playlist extension (determines type of import) + * @param hasharray $gunids, hash relation from filenames to gunids + * @param int $subjid, local subject (user) id (id of user doing the import) * @return int, result file local id (or error object) */ function bsImportPlaylistRaw($parid, $plid, $aPath, $rPath, $ext, &$gunids, $subjid) { $id = $r = $this->_idFromGunid($plid); - if(!is_null($r)) return $r; + if (!is_null($r)) { + return $r; + } $path = realpath("$aPath/$rPath"); - if(FALSE === $path){ + if (FALSE === $path) { return PEAR::raiseError( "BasicStor::bsImportPlaylistRaw: file doesn't exist ($aPath/$rPath)" ); } switch($ext){ - case"xml": - case"lspl": + case "xml": + case "lspl": $fname = $plid; $res = $this->bsPutFile($parid, $fname, NULL, $path, $plid, 'playlist' ); break; - case"smil": + case "smil": require_once "SmilPlaylist.php"; $res = SmilPlaylist::import($this, $aPath, $rPath, $gunids, $plid, $parid, $subjid); - if(PEAR::isError($res)) break; + if (PEAR::isError($res)) { + break; + } $res = $res->getId(); break; - case"m3u": + case "m3u": require_once "M3uPlaylist.php"; $res = M3uPlaylist::import($this, $aPath, $rPath, $gunids, $plid, $parid, $subjid); - if(PEAR::isError($res)) break; + if (PEAR::isError($res)) { + break; + } $res = $res->getId(); break; default: @@ -1051,16 +1215,19 @@ class BasicStor extends Alib{ ); break; } - if(!PEAR::isError($res)){ $gunids[basename($rPath)] = $plid; } + if (!PEAR::isError($res)) { + $gunids[basename($rPath)] = $plid; + } return $res; } + /** * Import playlist in LS Archive format * - * @param parid int, destination folder local id - * @param fpath string, imported file pathname - * @param subjid int, local subject (user) id (id of user doing the import) + * @param int $parid, destination folder local id + * @param string $fpath, imported file pathname + * @param int $subjid, local subject (user) id (id of user doing the import) * @return int, result file local id (or error object) */ function bsImportPlaylist($parid, $fpath, $subjid) @@ -1073,12 +1240,14 @@ class BasicStor extends Alib{ mkdir($tmpd); $res = `cd $tmpd; tar xf $fpath`; // clips: - $d = @dir($tmpdc); $entries=array(); $gunids=array(); - if($d !== false){ + $d = @dir($tmpdc); + $entries = array(); + $gunids = array(); + if ($d !== false) { while (false !== ($entry = $d->read())) { - if(preg_match("|^([0-9a-fA-F]{16})\.(.*)$|", $entry, $va)){ + if (preg_match("|^([0-9a-fA-F]{16})\.(.*)$|", $entry, $va)) { list(,$gunid, $ext) = $va; - switch($ext){ + switch ($ext) { case"xml": $entries[$gunid]['metadata'] = $entry; break; @@ -1093,33 +1262,41 @@ class BasicStor extends Alib{ $d->close(); } $res = TRUE; - foreach($entries as $gunid=>$it){ + foreach ($entries as $gunid => $it) { $rawMedia = "$tmpdc/{$it['rawMedia']}"; - if(!file_exists($rawMedia)) $rawMedia = NULL; + if (!file_exists($rawMedia)) { + $rawMedia = NULL; + } $metadata = "$tmpdc/{$it['metadata']}"; - if(!file_exists($metadata)) $metadata = NULL; + if (!file_exists($metadata)) { + $metadata = NULL; + } $r = $this->bsExistsFile($gunid, NULL, TRUE); - if(!PEAR::isError($res) && !$r){ + if (!PEAR::isError($res) && !$r) { $res = $this->bsPutFile($parid, $gunid, $rawMedia, $metadata, $gunid, 'audioclip' ); } @unlink("$tmpdc/{$it['rawMedia']}"); @unlink("$tmpdc/{$it['metadata']}"); - if(PEAR::isError($res)) break; + if (PEAR::isError($res)) { + break; + } } // playlists: require_once"Playlist.php"; $d = @dir($tmpdp); - if($d !== false){ + if ($d !== false) { while ((!PEAR::isError($res)) && false !== ($entry = $d->read())) { - if(preg_match("|^([0-9a-fA-F]{16})\.(.*)$|", $entry, $va)){ + if (preg_match("|^([0-9a-fA-F]{16})\.(.*)$|", $entry, $va)) { list(,$gunid, $ext) = $va; $res = $this->bsImportPlaylistRaw($parid, $gunid, $tmpdp, $entry, $ext, $gunids, $subjid); unlink("$tmpdp/$entry"); - if(PEAR::isError($res)) break; - } + if (PEAR::isError($res)) { + break; + } + } } $d->close(); } @@ -1129,55 +1306,73 @@ class BasicStor extends Alib{ return $res; } + /* --------------------------------------------------------- info methods */ /** * List files in folder * - * @param id int, local id of folder + * @param int $id, local id of folder * @return array */ function bsListFolder($id) { - if($this->getObjType($id) !== 'Folder') + if ($this->getObjType($id) !== 'Folder') { return PEAR::raiseError( 'BasicStor::bsListFolder: not a folder', GBERR_NOTF ); + } $listArr = $this->getDir($id, 'id, name, type, param as target', 'name'); - if($this->dbc->isError($listArr)) return $listArr; - foreach($listArr as $i=>$v){ - if($v['type'] == 'Folder') break; + if ($this->dbc->isError($listArr)) { + return $listArr; + } + foreach ($listArr as $i=>$v) { + if ($v['type'] == 'Folder') { + break; + } $gunid = $this->_gunidFromId($v['id']); - if($this->dbc->isError($gunid)) return $gunid; - if(is_null($gunid)){ unset($listArr[$i]); break; } - $listArr[$i]['type'] = $r = $this->_getType($gunid); - if($this->dbc->isError($r)) return $r; - $listArr[$i]['gunid'] = $gunid; - if(StoredFIle::_getState($gunid) == 'incomplete') + if ($this->dbc->isError($gunid)) { + return $gunid; + } + if (is_null($gunid)) { unset($listArr[$i]); + break; + } + $listArr[$i]['type'] = $r = $this->_getType($gunid); + if ($this->dbc->isError($r)) { + return $r; + } + $listArr[$i]['gunid'] = $gunid; + if (StoredFIle::_getState($gunid) == 'incomplete') { + unset($listArr[$i]); + } } return $listArr; } - + + /** * Analyze media file for internal metadata information * - * @param id int, virt.file's local id + * @param int $id, virt.file's local id * @return array */ function bsAnalyzeFile($id) { $ac = StoredFile::recall($this, $id); - if($this->dbc->isError($ac)) return $ac; + if ($this->dbc->isError($ac)) { + return $ac; + } $ia = $ac->analyzeMediaFile(); return $ia; } + /** * List files in folder * - * @param id int, local id of object - * @param relPath string, relative path + * @param int $id, local id of object + * @param string $relPath, relative path * @return array */ function getObjIdFromRelPath($id, $relPath='.') @@ -1185,21 +1380,28 @@ class BasicStor extends Alib{ $relPath = trim(urldecode($relPath)); //if($this->getObjType($id) !== 'Folder') $nid = $this->getParent($id); - if($this->dbc->isError($nid)) return $nid; - if(is_null($nid)){ - return PEAR::raiseError("null parent for id=$id"); } + if ($this->dbc->isError($nid)) { + return $nid; + } + if (is_null($nid)) { + return PEAR::raiseError("null parent for id=$id"); + } //else $nid = $id; - if(substr($relPath, 0, 1)=='/'){ $nid=$this->storId; } + if (substr($relPath, 0, 1)=='/') { + $nid = $this->storId; + } $a = split('/', $relPath); - foreach($a as $i=>$pathItem){ + foreach ($a as $i => $pathItem) { switch($pathItem){ case".": break; case"..": - if($nid != $this->storId){ + if ($nid != $this->storId) { $nid = $this->getParent($nid); - if($this->dbc->isError($nid)) return $nid; - if(is_null($nid)){ + if ($this->dbc->isError($nid)) { + return $nid; + } + if (is_null($nid)) { return PEAR::raiseError( "null parent for $nid"); } @@ -1209,8 +1411,10 @@ class BasicStor extends Alib{ break; default: $nid = $this->getObjId($pathItem, $nid); - if($this->dbc->isError($nid)) return $nid; - if(is_null($nid)){ + if ($this->dbc->isError($nid)) { + return $nid; + } + if (is_null($nid)) { return PEAR::raiseError( "Object $pathItem not found (from id=$id)"); } @@ -1218,7 +1422,8 @@ class BasicStor extends Alib{ } return $nid; } - + + /** * Check if file exists in the storage * @@ -1229,9 +1434,12 @@ class BasicStor extends Alib{ */ function bsExistsFile($id, $ftype=NULL, $byGunid=FALSE) { - if($byGunid) $ac = StoredFile::recallByGunid($this, $id); - else $ac = StoredFile::recall($this, $id); - if($this->dbc->isError($ac)){ + if ($byGunid) { + $ac = StoredFile::recallByGunid($this, $id); + } else { + $ac = StoredFile::recall($this, $id); + } + if ($this->dbc->isError($ac)) { // catch some exceptions switch($ac->getCode()){ case GBERR_FILENEX: @@ -1242,182 +1450,247 @@ class BasicStor extends Alib{ } } $realFtype = $this->_getType($ac->gunid); - if(!is_null($ftype) && ( + if (!is_null($ftype) && ( ($realFtype != $ftype) // webstreams are subset of audioclips && !($realFtype == 'webstream' && $ftype == 'audioclip') - )) return FALSE; + )) { + return FALSE; + } return TRUE; } + /* ---------------------------------------------------- redefined methods */ /** * Get object type by id. * (RootNode, Folder, File, ) * - * @param oid int, local object id + * @param int $oid, local object id * @return string/err */ function getObjType($oid) { $type = parent::getObjType($oid); - if($type == 'File'){ + if ($type == 'File') { $gunid = $this->_gunidFromId($oid); - if($this->dbc->isError($gunid)) return $gunid; + if ($this->dbc->isError($gunid)) { + return $gunid; + } $ftype = $this->_getType($gunid); - if($this->dbc->isError($ftype)) return $ftype; - if(!is_null($ftype)) $type=$ftype; + if ($this->dbc->isError($ftype)) { + return $ftype; + } + if (!is_null($ftype)) { + $type = $ftype; + } } return $type; } - + + /** * Add new user with home folder * - * @param login string - * @param pass string OPT - * @param realname string OPT + * @param string $login + * @param string $pass OPT + * @param string $realname OPT * @return int/err */ function addSubj($login, $pass=NULL, $realname='') { $uid = parent::addSubj($login, $pass, $realname); - if($this->dbc->isError($uid)) return $uid; - if($this->isGroup($uid) === FALSE){ + if ($this->dbc->isError($uid)) { + return $uid; + } + if ($this->isGroup($uid) === FALSE) { $fid = $this->bsCreateFolder($this->storId, $login); - if($this->dbc->isError($fid)) return $fid; + if ($this->dbc->isError($fid)) { + return $fid; + } $res = parent::addPerm($uid, '_all', $fid, 'A'); - if($this->dbc->isError($res)) return $res; - if(!$this->config['isArchive']){ + if ($this->dbc->isError($res)) { + return $res; + } + if (!$this->config['isArchive']) { $res =$this->addSubj2Gr($login, $this->config['StationPrefsGr']); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } $res =$this->addSubj2Gr($login, $this->config['AllGr']); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } $pfid = $this->bsCreateFolder($fid, 'public'); - if($this->dbc->isError($pfid)) return $pfid; + if ($this->dbc->isError($pfid)) { + return $pfid; + } $res = parent::addPerm($uid, '_all', $pfid, 'A'); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } $allGrId = $this->getSubjId($this->config['AllGr']); - if($this->dbc->isError($allGrId)) return $allGrId; + if ($this->dbc->isError($allGrId)) { + return $allGrId; + } $res = parent::addPerm($allGrId, 'read', $pfid, 'A'); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } } } return $uid; } + + /** * Remove user by login and remove also his home folder * - * @param login string + * @param string $login * @return boolean/err */ function removeSubj($login) { - if(FALSE !== array_search($login, $this->config['sysSubjs'])){ + if (FALSE !== array_search($login, $this->config['sysSubjs'])) { return $this->dbc->raiseError( "BasicStor::removeSubj: cannot remove system user/group"); } $uid = $this->getSubjId($login); - if($this->dbc->isError($uid)) return $uid; + if ($this->dbc->isError($uid)) { + return $uid; + } $res = $this->dbc->query(" DELETE FROM {$this->accessTable} WHERE owner=$uid "); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } $res = parent::removeSubj($login); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } $id = $this->getObjId($login, $this->storId); - if($this->dbc->isError($id)) return $id; - if(!is_null($id)){ + if ($this->dbc->isError($id)) { + return $id; + } + if (!is_null($id)) { // remove home folder: $res = $this->bsDeleteFile($id); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } } return TRUE; - } - + } + + /** * Authenticate and create session * - * @param login string - * @param pass string + * @param string $login + * @param string $pass * @return boolean/sessionId/err */ function login($login, $pass) { $r = $this->upgradeDbStructure(); - if($this->dbc->isError($r)) return $r; + if ($this->dbc->isError($r)) { + return $r; + } $r = parent::login($login, $pass); - if($this->dbc->isError($r)) return $r; + if ($this->dbc->isError($r)) { + return $r; + } return $r; } - + + /* ================================================== "protected" methods */ /** * Check authorization - auxiliary method * - * @param acts array of actions - * @param pars array of parameters - e.g. ids - * @param sessid string, session id + * @param array $acts of actions + * @param array $pars of parameters - e.g. ids + * @param string $sessid, session id * @return true or PEAR::error */ function _authorize($acts, $pars, $sessid='') { $userid = $this->getSessUserId($sessid); - if($this->dbc->isError($userid)) return $userid; - if(is_null($userid)){ + if ($this->dbc->isError($userid)) { + return $userid; + } + if (is_null($userid)) { return PEAR::raiseError( "BasicStor::_authorize: invalid session", GBERR_DENY); } - if(!is_array($pars)) $pars = array($pars); - if(!is_array($acts)) $acts = array($acts); + if (!is_array($pars)) { + $pars = array($pars); + } + if (!is_array($acts)) { + $acts = array($acts); + } $perm = true; - foreach($acts as $i=>$action){ + foreach ($acts as $i => $action) { $res = $this->checkPerm($userid, $action, $pars[$i]); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } $perm = $perm && $res; } - if($perm) return TRUE; + if ($perm) { + return TRUE; + } $adesc = "[".join(',',$acts)."]"; return PEAR::raiseError( "BasicStor::$adesc: access denied", GBERR_DENY); } + /** * Return users's home folder local ID * - * @param subjid string, local subject id + * @param string $subjid, local subject id * @return local folder id */ function _getHomeDirId($subjid) { $login = $this->getSubjName($subjid); - if($this->dbc->isError($login)) return $login; + if ($this->dbc->isError($login)) { + return $login; + } $parid = $this->getObjId($login, $this->storId); - if($this->dbc->isError($parid)) return $parid; - if(is_null($parid)){ + if ($this->dbc->isError($parid)) { + return $parid; + } + if (is_null($parid)) { return PEAR::raiseError("BasicStor::_getHomeDirId: ". "homedir not found ($subjid)", GBERR_NOTF); } return $parid; } - + + /** * Return users's home folder local ID * - * @param sessid string, session ID + * @param string $sessid, session ID * @return local folder id */ function _getHomeDirIdFromSess($sessid) { $uid = $this->getSessUserId($sessid); - if($this->dbc->isError($uid)) return $uid; + if ($this->dbc->isError($uid)) { + return $uid; + } return $this->_getHomeDirId($uid); } - + + /** * Get local id from global id * - * @param gunid string global id + * @param string $gunid global id * @return int local id */ function _idFromGunid($gunid) @@ -1427,28 +1700,36 @@ class BasicStor extends Alib{ ); } + /** * Get global id from local id * - * @param id int local id + * @param int $id local id * @return string global id */ function _gunidFromId($id) { - if(!is_numeric($id)) return NULL; + if (!is_numeric($id)) { + return NULL; + } $gunid = $this->dbc->getOne(" SELECT to_hex(gunid)as gunid FROM {$this->filesTable} WHERE id='$id' "); - if($this->dbc->isError($gunid)) return $gunid; - if(is_null($gunid)) return NULL; + if ($this->dbc->isError($gunid)) { + return $gunid; + } + if (is_null($gunid)) { + return NULL; + } return StoredFile::_normalizeGunid($gunid); } + /** * Get storage-internal file type * - * @param gunid string, global unique id of file + * @param string $gunid, global unique id of file * @return string, see install() */ function _getType($gunid) @@ -1460,10 +1741,11 @@ class BasicStor extends Alib{ return $ftype; } + /** * Check gunid format * - * @param gunid string, global unique ID + * @param string $gunid, global unique ID * @return boolean */ function _checkGunid($gunid) @@ -1472,6 +1754,7 @@ class BasicStor extends Alib{ return $res; } + /** * Returns if gunid is free * @@ -1482,49 +1765,69 @@ class BasicStor extends Alib{ SELECT count(*) FROM {$this->filesTable} WHERE gunid=x'{$this->gunid}'::bigint "); - if($this->dbc->isError($cnt)) return $cnt; - if($cnt > 0) return FALSE; + if ($this->dbc->isError($cnt)) { + return $cnt; + } + if ($cnt > 0) { + return FALSE; + } return TRUE; - } + } + /** * Set playlist edit flag * - * @param playlistId string, playlist global unique ID - * @param val boolean, set/clear of edit flag - * @param sessid string, session id - * @param subjid int, subject id (if sessid is not specified) + * @param string $playlistId, playlist global unique ID + * @param boolean $val, set/clear of edit flag + * @param string $sessid, session id + * @param int $subjid, subject id (if sessid is not specified) * @return boolean, previous state */ function _setEditFlag($playlistId, $val=TRUE, $sessid=NULL, $subjid=NULL) { - if(!is_null($sessid)){ + if (!is_null($sessid)) { $subjid = $this->getSessUserId($sessid); - if($this->dbc->isError($subjid)) return $subjid; + if ($this->dbc->isError($subjid)) { + return $subjid; + } } $ac = StoredFile::recallByGunid($this, $playlistId); - if($this->dbc->isError($ac)) return $ac; + if ($this->dbc->isError($ac)) { + return $ac; + } $state = $ac->_getState(); - if($val){ $r = $ac->setState('edited', $subjid); } - else{ $r = $ac->setState('ready', 'NULL'); } - if($this->dbc->isError($r)) return $r; + if ($val) { + $r = $ac->setState('edited', $subjid); + } else { + $r = $ac->setState('ready', 'NULL'); + } + if ($this->dbc->isError($r)) { + return $r; + } return ($state == 'edited'); } + /** * Check if playlist is marked as edited * - * @param playlistId string, playlist global unique ID + * @param string $playlistId, playlist global unique ID * @return FALSE | int - id of user editing it */ function _isEdited($playlistId) { $ac = StoredFile::recallByGunid($this, $playlistId); - if($this->dbc->isError($ac)) return $ac; - if(!$ac->isEdited($playlistId)) return FALSE; + if ($this->dbc->isError($ac)) { + return $ac; + } + if (!$ac->isEdited($playlistId)) { + return FALSE; + } return $ac->isEditedBy($playlistId); } + /* ---------------------------------------- redefined "protected" methods */ /** * Copy virtual file.
@@ -1536,22 +1839,27 @@ class BasicStor extends Alib{ { $parid = $this->getParent($id); $nid = parent::copyObj($id, $newParid, $after); - if($this->dbc->isError($nid)) return $nid; - switch($this->getObjType($id)){ - case"audioclip": - case"playlist": - case"webstream": + if ($this->dbc->isError($nid)) { + return $nid; + } + switch ($this->getObjType($id)) { + case "audioclip": + case "playlist": + case "webstream": $ac = StoredFile::recall($this, $id); - if($this->dbc->isError($ac)){ return $ac; } + if ($this->dbc->isError($ac)) { + return $ac; + } $ac2 = StoredFile::copyOf($ac, $nid); $ac2->rename($this->getObjName($nid)); break; - case"File": + case "File": default: } return $nid; } + /** * Move virtual file.
* Redefined from parent class. @@ -1561,25 +1869,33 @@ class BasicStor extends Alib{ function moveObj($id, $newParid, $after=NULL) { $parid = $this->getParent($id); - switch($this->getObjType($id)){ - case"audioclip": - case"playlist": - case"webstream": + switch ($this->getObjType($id)) { + case "audioclip": + case "playlist": + case "webstream": $ac = StoredFile::recall($this, $id); - if($this->dbc->isError($ac)){ return $ac; } - if($ac->isEdited()) + if ($this->dbc->isError($ac)) { + return $ac; + } + if ($ac->isEdited()) { return PEAR::raiseError( 'BasicStor::moveObj: is edited'); - if($ac->isAccessed()) + } + if ($ac->isAccessed()) { return PEAR::raiseError( 'BasicStor::moveObj: is accessed'); + } break; default: } $nid = parent::moveObj($id, $newParid, $after); - if($this->dbc->isError($nid)) return $nid; + if ($this->dbc->isError($nid)) { + return $nid; + } return TRUE; } + + /** * Optionaly remove virtual file with the same name and add new one.
* Redefined from parent class. @@ -1590,49 +1906,56 @@ class BasicStor extends Alib{ { $name = pg_escape_string($name); $exid = $this->getObjId($name, $parid); - if($this->dbc->isError($exid)) return $exid; + if ($this->dbc->isError($exid)) { + return $exid; + } //if(!is_null($exid)){ $this->removeObj($exid); } $name2 = $name; - for( ; + for ( ; $xid = $this->getObjId($name2, $parid), !is_null($xid) && !$this->dbc->isError($xid); $name2 .= "_" ); - if(!is_null($exid)){ $r = $this->renameObj($exid, $name2); } + if (!is_null($exid)) { + $r = $this->renameObj($exid, $name2); + } return parent::addObj($name, $type, $parid, $aftid, $param); } + /** * Remove virtual file.
* Redefined from parent class. * - * @param id int, local id of removed object - * @param forced boolean, unconditional delete + * @param int $id, local id of removed object + * @param boolean $forced, unconditional delete * @return true or PEAR::error */ function removeObj($id, $forced=FALSE) { - switch($ot = $this->getObjType($id)){ - case"audioclip": - case"playlist": - case"webstream": + switch ($ot = $this->getObjType($id)) { + case "audioclip": + case "playlist": + case "webstream": $ac = StoredFile::recall($this, $id); - if($this->dbc->isError($ac)) return $ac; - if($ac->isEdited() && !$forced){ + if ($this->dbc->isError($ac)) { + return $ac; + } + if ($ac->isEdited() && !$forced) { return PEAR::raiseError( 'BasicStor.php: removeObj: is edited' ); } - if($ac->isAccessed() && !$forced){ + if ($ac->isAccessed() && !$forced) { return PEAR::raiseError( 'BasicStor.php: removeObj: is accessed' ); } $ac->delete(); break; - case"File": - case"Folder": - case"Replica": + case "File": + case "Folder": + case "Replica": break; default: return PEAR::raiseError( @@ -1640,10 +1963,13 @@ class BasicStor extends Alib{ ); } $res = parent::removeObj($id); - if($this->dbc->isError($res)) return $res; + if ($this->dbc->isError($res)) { + return $res; + } return TRUE; } + /* ========================================================= misc methods */ /** * Write string to file @@ -1655,7 +1981,7 @@ class BasicStor extends Alib{ function bsStr2File($str, $fname) { $fp = @fopen($fname, "w"); - if($fp === FALSE){ + if ($fp === FALSE) { return PEAR::raiseError( "BasicStor::bsStr2File: cannot open file ($fname)" ); @@ -1664,7 +1990,8 @@ class BasicStor extends Alib{ fclose($fp); return TRUE; } - + + /** * Check and optionally upgrade LS db structure. * (add column suported only now) @@ -1692,12 +2019,14 @@ class BasicStor extends Alib{ ), ), ); - foreach($chDb as $version=>$chArr){ - foreach($chArr as $change){ + foreach ($chDb as $version => $chArr) { + foreach ($chArr as $change) { extract($change); // tbl, op, fld, type $r = $this->dbc->tableInfo($tbl, DB_TABLEINFO_ORDERTABLE); - if($this->dbc->isError($r)) return $r; - if(!isset($r['ordertable'][$tbl][$fld])){ + if ($this->dbc->isError($r)) { + return $r; + } + if (!isset($r['ordertable'][$tbl][$fld])) { $q = "ALTER table $tbl ADD $fld $type"; $r = $this->dbc->query($q); if($this->dbc->isError($r)) return $r; @@ -1706,13 +2035,14 @@ class BasicStor extends Alib{ } return TRUE; } - + + /* =============================================== test and debug methods */ /** * Reset storageServer for debugging. * - * @param loadSampleData boolean - flag for allow sample data loading - * @param filesOnly boolean - flag for operate only on files in storage + * @param boolean $loadSampleData - flag for allow sample data loading + * @param boolean $filesOnly - flag for operate only on files in storage * @return result of localSearch with filetype 'all' and no conditions, * i.e. array of hashes, fields: * cnt : integer - number of inserted files @@ -1725,26 +2055,36 @@ class BasicStor extends Alib{ */ function resetStorage($loadSampleData=TRUE, $filesOnly=FALSE) { - if($filesOnly) $this->deleteFiles(); - else $this->deleteData(); - if(!$this->config['isArchive']){ + if ($filesOnly) { + $this->deleteFiles(); + } else { + $this->deleteData(); + } + if (!$this->config['isArchive']) { $tr =& new Transport($this); $tr->resetData(); } $res = array( 'cnt'=>0, 'results'=>array(), ); - if(!$loadSampleData) return $res; + if (!$loadSampleData) { + return $res; + } $rootHD = $this->getObjId('root', $this->storId); $samples = dirname(__FILE__)."/tests/sampleData.php"; - if(file_exists($samples)){ + if (file_exists($samples)) { include $samples; - }else $sampleData = array(); - foreach($sampleData as $k=>$it){ + } else { + $sampleData = array(); + } + foreach ($sampleData as $k => $it) { $type = $it['type']; $xml = $it['xml']; - if(isset($it['gunid'])) $gunid = $it['gunid']; - else $gunid = ''; + if (isset($it['gunid'])) { + $gunid = $it['gunid']; + } else { + $gunid = ''; + } switch($type){ case"audioclip": $media = $it['media']; @@ -1760,7 +2100,9 @@ class BasicStor extends Alib{ $rootHD, $fname, $media, $xml, $gunid, $type ); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } #$gunid = $this->_gunidFromId($r); #$res['results'][] = array('gunid' => $gunid, 'type' => $type); #$res['cnt']++; @@ -1771,28 +2113,35 @@ class BasicStor extends Alib{ #return $res; } + /** * dump * */ function dump($id='', $indch=' ', $ind='', $format='{name}') { - if($id=='') $id = $this->storId; + if ($id=='') { + $id = $this->storId; + } return parent::dump($id, $indch, $ind, $format); } + /** * * */ function dumpDir($id='', $format='$o["name"]') { - if($id=='') $id = $this->storId; + if ($id == '') { + $id = $this->storId; + } $arr = $this->getDir($id, 'id,name'); $arr = array_map(create_function('$o', 'return "'.$format .'";'), $arr); return join('', $arr); } + /** * * @@ -1802,6 +2151,7 @@ class BasicStor extends Alib{ echo"
\n"; print_r($va);
     }
 
+
     /**
      *  deleteFiles
      *
@@ -1810,10 +2160,14 @@ class BasicStor extends Alib{
     function deleteFiles()
     {
         $ids = $this->dbc->getAll("SELECT id FROM {$this->filesTable}");
-        if(is_array($ids)) foreach($ids as $i=>$item){
-            $this->bsDeleteFile($item['id'], TRUE);
+        if (is_array($ids)) {
+            foreach($ids as $i=>$item){
+                $this->bsDeleteFile($item['id'], TRUE);
+            }
         }
     }
+
+
     /**
      *  deleteData
      *
@@ -1825,6 +2179,8 @@ class BasicStor extends Alib{
         parent::deleteData();
         $this->initData();
     }
+
+
     /**
      *  Create BasicStor object with temporarily changed configuration
      *  to prevent data changes in tests
@@ -1843,21 +2199,29 @@ class BasicStor extends Alib{
         $bs =& new BasicStor($dbc, $config);
         $bs->configBckp = $configBckp;
         $r = $bs->install();
-        if(PEAR::isError($r)){ return $r; }
+        if (PEAR::isError($r)) {
+            return $r;
+        }
         return $bs;
     }
+
+
     /**
      *  Clean up test space
      *
      */
     function releaseTestSpace(){
         $r = $this->uninstall();
-        if(PEAR::isError($r)){ return $r; }
+        if (PEAR::isError($r)) {
+            return $r;
+        }
         // rmdir($this->config['bufferDir']);
         rmdir($this->config['storageDir']);
         $this->config = $this->configBckp;
         rmdir($this->config['storageDir'].'/tmp');
     }
+
+
     /**
      *  testData
      *
@@ -1896,12 +2260,12 @@ class BasicStor extends Alib{
         // if($this->dbc->isError($p = parent::test())) return $p;
         $this->deleteData();
         $this->testData();
-        if($this->config['useTrash']){
+        if ($this->config['useTrash']) {
             $trash = "\n        {$this->config['TrashName']}";
-        }else{
+        } else {
             $trash = "";
         }
-        if(!$this->config['isArchive']){
+        if (!$this->config['isArchive']) {
             $this->test_correct = "    StorageRoot
         root
         test1
@@ -1920,7 +2284,7 @@ class BasicStor extends Alib{
         test4
             public{$trash}
 ";
-        }else{
+        } else {
             $this->test_correct = "    StorageRoot
         root
         test1
@@ -1937,15 +2301,21 @@ class BasicStor extends Alib{
 ";
         }
         $r = $this->dumpTree($this->storId, '    ', '    ', '{name}');
-        if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->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(
+        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
      *
@@ -1957,33 +2327,52 @@ class BasicStor extends Alib{
             $this->addObj('StorageRoot', 'Folder', $this->rootId);
         $rootUid = parent::addSubj('root', $this->config['tmpRootPass']);
         $res = parent::addPerm($rootUid, '_all', $this->rootId, 'A');
-        if($this->dbc->isError($res)) return $res;
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         $res = parent::addPerm($rootUid, 'subjects', $this->rootId, 'A');
-        if($this->dbc->isError($res)) return $res;
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
         $fid = $this->bsCreateFolder($this->storId, 'root');
-        if($this->dbc->isError($fid)) return $fid;
-        if($this->config['useTrash']){
+        if ($this->dbc->isError($fid)) {
+            return $fid;
+        }
+        if ($this->config['useTrash']) {
             $tfid = $this->bsCreateFolder(
                 $this->storId, $this->config["TrashName"]);
-            if($this->dbc->isError($tfid)) return $tfid;
+            if ($this->dbc->isError($tfid)) {
+                return $tfid;
+            }
         }
         $allid = parent::addSubj($this->config['AllGr']);
-        if($this->dbc->isError($allid)) return $allid;
+        if ($this->dbc->isError($allid)) {
+            return $allid;
+        }
         $r = $this->addSubj2Gr('root', $this->config['AllGr']);
         $r = $res = parent::addPerm($allid, 'read', $this->rootId, 'A');
         $admid = parent::addSubj($this->config['AdminsGr']);
-        if($this->dbc->isError($admid)) return $admid;
+        if ($this->dbc->isError($admid)) {
+            return $admid;
+        }
         $r = $this->addSubj2Gr('root', $this->config['AdminsGr']);
-        if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->isError($r)) {
+            return $r;
+        }
         $res = parent::addPerm($admid, '_all', $this->rootId, 'A');
-        if($this->dbc->isError($res)) return $res;
-        if(!$this->config['isArchive']){
+        if ($this->dbc->isError($res)) {
+            return $res;
+        }
+        if (!$this->config['isArchive']) {
             $stPrefGr = parent::addSubj($this->config['StationPrefsGr']);
-            if($this->dbc->isError($stPrefGr)) return $stPrefGr;
+            if ($this->dbc->isError($stPrefGr)) {
+                return $stPrefGr;
+            }
             $this->addSubj2Gr('root', $this->config['StationPrefsGr']);
         }
     }
 
+
     /**
      *  install - create tables
      *
@@ -2021,7 +2410,9 @@ class BasicStor extends Alib{
             editedby int REFERENCES {$this->subjTable}, -- who edits it
             mtime timestamp(6) with time zone           -- lst modif.time
         )");
-        if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->isError($r)) {
+            return $r;
+        }
         $this->dbc->query("CREATE UNIQUE INDEX {$this->filesTable}_id_idx
             ON {$this->filesTable} (id)");
         $this->dbc->query("CREATE UNIQUE INDEX {$this->filesTable}_gunid_idx
@@ -2041,7 +2432,9 @@ class BasicStor extends Alib{
             objns varchar(255),              -- object namespace shortcut/uri
             object text
         )");
-        if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->isError($r)) {
+            return $r;
+        }
         $this->dbc->query("CREATE UNIQUE INDEX {$this->mdataTable}_id_idx
             ON {$this->mdataTable} (id)");
         $this->dbc->query("CREATE INDEX {$this->mdataTable}_gunid_idx
@@ -2061,21 +2454,25 @@ class BasicStor extends Alib{
             owner int REFERENCES {$this->subjTable},  -- subject have started it
             ts timestamp
         )");
-        if($this->dbc->isError($r)) return $r;
+        if ($this->dbc->isError($r)) {
+            return $r;
+        }
         $this->dbc->query("CREATE INDEX {$this->accessTable}_token_idx
             ON {$this->accessTable} (token)");
         $this->dbc->query("CREATE INDEX {$this->accessTable}_gunid_idx
             ON {$this->accessTable} (gunid)");
         $this->dbc->query("CREATE INDEX {$this->accessTable}_parent_idx
             ON {$this->accessTable} (parent)");
-        if(!file_exists($this->storageDir)){
+        if (!file_exists($this->storageDir)) {
             mkdir($this->storageDir, 02775);
         }
-        if(!file_exists($this->bufferDir)){
+        if (!file_exists($this->bufferDir)) {
             mkdir($this->bufferDir, 02775);
         }
         $this->initData();
     }
+
+
     /**
      *  id  subjns  subject predns  predicate   objns   object
      *  y1  literal xmbf    NULL    namespace   literal http://www.sotf.org/xbmf
@@ -2103,34 +2500,40 @@ class BasicStor extends Alib{
         $this->dbc->query("DROP TABLE {$this->accessTable}");
         $d = @dir($this->storageDir);
         while (is_object($d) && (false !== ($entry = $d->read()))){
-            if(filetype("{$this->storageDir}/$entry")=='dir'){
-                if($entry!='CVS' && $entry!='tmp' && strlen($entry)==3)
-                {
+            if (filetype("{$this->storageDir}/$entry")=='dir') {
+                if ($entry!='CVS' && $entry!='tmp' && strlen($entry)==3) {
                     $dd = dir("{$this->storageDir}/$entry");
-                    while (false !== ($ee = $dd->read())){
-                        if(substr($ee, 0, 1)!=='.')
+                    while (false !== ($ee = $dd->read())) {
+                        if (substr($ee, 0, 1)!=='.') {
                             unlink("{$this->storageDir}/$entry/$ee");
+                        }
                     }
                     $dd->close();
                     rmdir("{$this->storageDir}/$entry");
                 }
             }
         }
-        if(is_object($d)) $d->close();
-        if(file_exists($this->bufferDir)){
+        if (is_object($d)) {
+            $d->close();
+        }
+        if (file_exists($this->bufferDir)) {
             $d = dir($this->bufferDir);
-            while (false !== ($entry = $d->read())) if(substr($entry,0,1)!='.')
-                { unlink("{$this->bufferDir}/$entry"); }
+            while (false !== ($entry = $d->read())) {
+                if(substr($entry,0,1)!='.') {
+                    unlink("{$this->bufferDir}/$entry");
+                }
+            }
             $d->close();
             @rmdir($this->bufferDir);
         }
         parent::uninstall();
     }
 
+
     /**
      *  Aux logging for debug
      *
-     *  @param msg string - log message
+     *  @param string $msg - log message
      */
     function debugLog($msg)
     {
@@ -2139,5 +2542,5 @@ class BasicStor extends Alib{
         fclose($fp);
     }
 
-}
+} // class BasicStor
 ?>
\ No newline at end of file
diff --git a/livesupport/src/modules/storageServer/var/LocStor.php b/livesupport/src/modules/storageServer/var/LocStor.php
index 298f9c22b..b56a7018a 100644
--- a/livesupport/src/modules/storageServer/var/LocStor.php
+++ b/livesupport/src/modules/storageServer/var/LocStor.php
@@ -2,26 +2,26 @@
 /*------------------------------------------------------------------------------
 
     Copyright (c) 2004 Media Development Loan Fund
- 
+
     This file is part of the LiveSupport project.
     http://livesupport.campware.org/
     To report bugs, send an e-mail to bugs@campware.org
- 
+
     LiveSupport is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
-  
+
     LiveSupport is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
- 
+
     You should have received a copy of the GNU General Public License
     along with LiveSupport; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- 
- 
+
+
     Author   : $Author$
     Version  : $Revision$
     Location : $URL$
@@ -35,18 +35,20 @@ require_once "BasicStor.php";
  *
  *  Livesupport local storage interface
  */
-class LocStor extends BasicStor{
+class LocStor extends BasicStor {
+
     /* ---------------------------------------------------------------- store */
+
     /**
      *  Store or replace existing audio clip
      *
-     *  @param sessid string, session id
-     *  @param gunid string, global unique id
-     *  @param metadata string, metadata XML string
-     *  @param fname string, human readable menmonic file name
+     *  @param string $sessid, session id
+     *  @param string $gunid, global unique id
+     *  @param string $metadata, metadata XML string
+     *  @param string $fname, human readable menmonic file name
      *                      with extension corresponding to filetype
-     *  @param chsum string, md5 checksum of media file
-     *  @param ftype string audioclip | playlist | webstream
+     *  @param string $chsum, md5 checksum of media file
+     *  @param string $ftype audioclip | playlist | webstream
      *  @return struct {url:writable URL for HTTP PUT, token:access token
      */
     function storeAudioClipOpen(
@@ -54,19 +56,20 @@ class LocStor extends BasicStor{
     )
     {
         // test of gunid format:
-        if(!$this->_checkGunid($gunid)){
+        if (!$this->_checkGunid($gunid)) {
             return PEAR::raiseError(
                 "LocStor::storeAudioClipOpen: Wrong gunid ($gunid)"
             );
         }
         // test if specified gunid exists:
         $ac =& StoredFile::recallByGunid($this, $gunid);
-        if(!PEAR::isError($ac)){
+        if (!PEAR::isError($ac)) {
             // gunid exists - do replace
             $oid = $ac->getId();
-            if(($res = $this->_authorize('write', $oid, $sessid)) !== TRUE)
-                { return $res; }
-            if($ac->isAccessed()){
+            if (($res = $this->_authorize('write', $oid, $sessid)) !== TRUE) {
+                return $res;
+            }
+            if ($ac->isAccessed()) {
                 return PEAR::raiseError(
                     'LocStor::storeAudioClipOpen: is accessed'
                 );
@@ -74,63 +77,89 @@ class LocStor extends BasicStor{
             $res = $ac->replace(
                 $oid, $ac->name, '', $metadata, 'string'
             );
-            if(PEAR::isError($res)) return $res;
-        }else{
+            if (PEAR::isError($res)) {
+                return $res;
+            }
+        } else {
             // gunid doesn't exists - do insert:
             $tmpFname = uniqid('');
             $parid = $this->_getHomeDirIdFromSess($sessid);
-            if(PEAR::isError($parid)) return $parid;
-            if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
-                { return $res; }
-            $oid = $this->addObj($tmpFname , $ftype, $parid);
-            if(PEAR::isError($oid)) return $oid;
-            $ac =&  StoredFile::insert(
+            if (PEAR::isError($parid)) {
+                return $parid;
+            }
+            if (($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) {
+                return $res;
+            }
+            $oid = $this->addObj($tmpFname, $ftype, $parid);
+            if (PEAR::isError($oid)) {
+                return $oid;
+            }
+            $ac =& StoredFile::insert(
                 $this, $oid, '', '', $metadata, 'string',
                 $gunid, $ftype
             );
-            if(PEAR::isError($ac)){
+            if (PEAR::isError($ac)) {
                 $res = $this->removeObj($oid);
                 return $ac;
             }
-            if(PEAR::isError($res)) return $res;
+            if (PEAR::isError($res)) {
+                return $res;
+            }
         }
         $res = $ac->setState('incomplete');
-        if(PEAR::isError($res)) return $res;
-        if($fname == ''){
+        if (PEAR::isError($res)) {
+            return $res;
+        }
+        if ($fname == '') {
             $fname = "newFile";
         }
         $res = $this->bsRenameFile($oid, $fname);
-        if(PEAR::isError($res)) return $res;
+        if (PEAR::isError($res)) {
+            return $res;
+        }
         return $this->bsOpenPut($chsum, $ac->gunid);
     }
 
+
     /**
      *  Store or replace existing audio clip
      *
-     *  @param sessid string
-     *  @param token string
+     *  @param string $sessid
+     *  @param string $token
      *  @return string gunid or PEAR::error
      */
     function storeAudioClipClose($sessid, $token)
     {
         $ac =& StoredFile::recallByToken($this, $token);
-        if(PEAR::isError($ac)){ return $ac; }
+        if (PEAR::isError($ac)) {
+            return $ac;
+        }
         $arr = $r = $this->bsClosePut($token);
-        if(PEAR::isError($r)){ $ac->delete(); return $r; }
+        if (PEAR::isError($r)) {
+            $ac->delete();
+            return $r;
+        }
         $fname = $arr['fname'];
         //$owner = $arr['owner'];
         $res = $ac->replaceRawMediaData($fname);
-        if(PEAR::isError($res)){ return $res; }
-        if(file_exists($fname)) @unlink($fname);
+        if (PEAR::isError($res)) {
+            return $res;
+        }
+        if (file_exists($fname)) {
+            @unlink($fname);
+        }
         $res = $ac->setState('ready');
-        if(PEAR::isError($res)) return $res;
+        if (PEAR::isError($res)) {
+            return $res;
+        }
         return $ac->gunid;
     }
 
+
     /**
      *  Check uploaded file
      *
-     *  @param token string, put token
+     *  @param string $token, put token
      *  @return hash, (status: boolean, size: int - filesize)
      */
     function uploadCheck($token)
@@ -138,94 +167,115 @@ class LocStor extends BasicStor{
         return $this->bsCheckPut($token);
     }
 
+
     /**
      *  Store webstream
      *
-     *  @param sessid string, session id
-     *  @param gunid string, global unique id
-     *  @param metadata string, metadata XML string
-     *  @param fname string, human readable menmonic file name
+     *  @param string $sessid, session id
+     *  @param string $gunid, global unique id
+     *  @param string $metadata, metadata XML string
+     *  @param string $fname, human readable menmonic file name
      *                      with extension corresponding to filetype
-     *  @param url string, wewbstream url
+     *  @param string $url, wewbstream url
      *  @return string, gunid
      */
     function storeWebstream($sessid, $gunid, $metadata, $fname, $url)
     {
         $a = $this->storeAudioClipOpen(
             $sessid, $gunid, $metadata, $fname, md5(''), 'webstream');
-        if(PEAR::isError($a)) return $a;
+        if (PEAR::isError($a)) {
+            return $a;
+        }
         $gunid = $this->storeAudioClipClose($sessid, $a['token']);
-        if(PEAR::isError($gunid)) return $gunid;
+        if (PEAR::isError($gunid)) {
+            return $gunid;
+        }
         $ac =& StoredFile::recallByGunid($this, $gunid);
-        if(PEAR::isError($ac)) return $ac;
+        if (PEAR::isError($ac)) {
+            return $ac;
+        }
         $oid = $ac->getId();
         $r = $this-> bsSetMetadataValue(
             $oid, 'ls:url', $url, NULL, NULL, 'metadata');
-        if(PEAR::isError($r)) return $r;
+        if (PEAR::isError($r)) {
+            return $r;
+        }
         return $gunid;
     }
 
+
     /* --------------------------------------------------------------- access */
     /**
      *  Make access to audio clip
      *
-     *  @param sessid string
-     *  @param gunid string
-     *  @param parent int parent token
+     *  @param string $sessid
+     *  @param string $gunid
+     *  @param int $parent parent token
      *  @return array with: seekable filehandle, access token
      */
     function accessRawAudioData($sessid, $gunid, $parent='0')
     {
         $ac =& StoredFile::recallByGunid($this, $gunid);
-        if(PEAR::isError($ac)) return $ac;
-        if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
+        if (PEAR::isError($ac)) {
+            return $ac;
+        }
+        if (($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE) {
             return $res;
+        }
         return $ac->accessRawMediaData($parent);
     }
 
+
     /**
      *  Release access to audio clip
      *
-     *  @param sessid string
-     *  @param token string, access token
+     *  @param string $sessid
+     *  @param string $token, access token
      *  @return boolean or PEAR::error
      */
     function releaseRawAudioData($sessid, $token)
     {
         $ac =& StoredFile::recallByToken($this, $token);
-        if(PEAR::isError($ac)) return $ac;
+        if (PEAR::isError($ac)) {
+            return $ac;
+        }
         return $ac->releaseRawMediaData($token);
     }
 
+
     /* ------------------------------------------------------------- download */
     /**
      *  Create and return downloadable URL for audio file
      *
-     *  @param sessid string, session id
-     *  @param gunid string, global unique id
+     *  @param string $sessid, session id
+     *  @param string $gunid, global unique id
      *  @return array with strings:
      *      downloadable URL, download token, chsum, size, filename
      */
     function downloadRawAudioDataOpen($sessid, $gunid)
     {
         $ex = $this->existsAudioClip($sessid, $gunid);
-        if(PEAR::isError($ex)) return $ex;
+        if (PEAR::isError($ex)) {
+            return $ex;
+        }
         $id = $this->_idFromGunid($gunid);
-        if(is_null($id) || !$ex){
+        if (is_null($id) || !$ex) {
             return PEAR::raiseError(
                 "LocStor::downloadRawAudioDataOpen: gunid not found ($gunid)",
                 GBERR_NOTF
             );
         }
-        if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
+        if (($res = $this->_authorize('read', $id, $sessid)) !== TRUE) {
             return $res;
+        }
         return $this->bsOpenDownload($id);
     }
 
+
     /**
      *  Discard downloadable URL for audio file
      *
-     *  @param token string, download token
+     *  @param string $token, download token
      *  @return string, gunid
      */
     function downloadRawAudioDataClose($token)
@@ -233,11 +283,12 @@ class LocStor extends BasicStor{
         return $this->bsCloseDownload($token);
     }
 
+
     /**
      *  Create and return downloadable URL for metadata
      *
-     *  @param sessid string, session id
-     *  @param gunid string, global unique id
+     *  @param string $sessid, session id
+     *  @param string $gunid, global unique id
      *  @return array with strings:
      *      downloadable URL, download token, chsum, filename
      */
@@ -246,22 +297,24 @@ class LocStor extends BasicStor{
 //        $res = $this->existsAudioClip($sessid, $gunid);
 //        if(PEAR::isError($res)) return $res;
         $id = $this->_idFromGunid($gunid);
-        if(is_null($id)){
+        if (is_null($id)) {
             return PEAR::raiseError(
              "LocStor::downloadMetadataOpen: gunid not found ($gunid)"
             );
         }
-        if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
+        if (($res = $this->_authorize('read', $id, $sessid)) !== TRUE) {
             return $res;
+        }
         $res = $this->bsOpenDownload($id, 'metadata');
         #unset($res['filename']);
         return $res;
     }
 
+
     /**
      *  Discard downloadable URL for metadata
      *
-     *  @param token string, download token
+     *  @param string $token, download token
      *  @return string, gunid
      */
     function downloadMetadataClose($token)
@@ -269,35 +322,43 @@ class LocStor extends BasicStor{
         return $this->bsCloseDownload($token, 'metadata');
     }
 
+
     /**
      *  Return metadata as XML
      *
-     *  @param sessid string
-     *  @param gunid string
+     *  @param string $sessid
+     *  @param string $gunid
      *  @return string or PEAR::error
      */
     function getAudioClip($sessid, $gunid)
     {
         $ac =& StoredFile::recallByGunid($this, $gunid);
-        if(PEAR::isError($ac)) return $ac;
-        if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
+        if (PEAR::isError($ac)) {
+            return $ac;
+        }
+        if (($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE) {
             return $res;
+        }
         $md = $this->bsGetMetadata($ac->getId());
-        if(PEAR::isError($md)) return $md;
+        if (PEAR::isError($md)) {
+            return $md;
+        }
         return $md;
     }
 
+
     /* ------------------------------------------------------- search, browse */
+
     /**
      *  Search in metadata database
      *
-     *  @param sessid string
-     *  @param criteria hash, with following structure:
+ * @param string $sessid + * @param hash $criteria, with following structure:
*
    *
  • 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) @@ -321,7 +382,7 @@ class LocStor extends BasicStor{ *
* @return array of hashes, fields: *
    - *
  • cnt : integer - number of matching gunids + *
  • cnt : integer - number of matching gunids * of files have been found
  • *
  • results : array of hashes: *
      @@ -337,18 +398,30 @@ class LocStor extends BasicStor{ */ function searchMetadata($sessid, $criteria) { - if(($res = $this->_authorize('read', $this->storId, $sessid)) !== TRUE) + if (($res = $this->_authorize('read', $this->storId, $sessid)) !== TRUE) { return $res; + } $criteria['resultMode'] = 'xmlrpc'; $res = $this->localSearch($criteria, $sessid); return $res; } + + + /** + * Enter description here... + * + * @param array $criteria + * @param mixed $sessid - this variable isnt used + * @return unknown + */ function localSearch($criteria, $sessid='') { $limit = intval(isset($criteria['limit']) ? $criteria['limit'] : 0); $offset = intval(isset($criteria['offset']) ? $criteria['offset'] : 0); $res = $r = $this->bsLocalSearch($criteria, $limit, $offset); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $res; } @@ -356,13 +429,13 @@ class LocStor extends BasicStor{ /** * Return values of specified metadata category * - * @param category string, metadata category name + * @param string $category, metadata category name * with or without namespace prefix (dc:title, author) - * @param criteria hash, see searchMetadata method - * @param sessid string + * @param hash $criteria, see searchMetadata method + * @param string $sessid * @return hash, fields: * results : array with found values - * cnt : integer - number of matching values + * cnt : integer - number of matching values * @see BasicStor::bsBrowseCategory */ function browseCategory($category, $criteria=NULL, $sessid='') @@ -372,13 +445,14 @@ class LocStor extends BasicStor{ $res = $this->bsBrowseCategory($category, $limit, $offset, $criteria); return $res; } - + + /* ----------------------------------------------------------------- etc. */ /** * Check if audio clip exists * - * @param sessid string - * @param gunid string + * @param string $sessid + * @param string $gunid * @return boolean */ function existsAudioClip($sessid, $gunid) @@ -388,230 +462,303 @@ class LocStor extends BasicStor{ // if($ex === FALSE ){ // $ex = $this->existsFile($sessid, $gunid, 'webstream'); // } - if($ex === FALSE ) return FALSE; - if(PEAR::isError($ex)){ return $ex; } + if ($ex === FALSE ) { + return FALSE; + } + if (PEAR::isError($ex)) { + return $ex; + } $ac =& StoredFile::recallByGunid($this, $gunid); - if(PEAR::isError($ac)){ return $ac; } + if (PEAR::isError($ac)) { + return $ac; + } return $ac->exists(); } + /** * Check if file exists in the storage * - * @param sessid string - * @param gunid string - * @param ftype string, internal file type + * @param string $sessid + * @param string $gunid + * @param string $ftype, internal file type * @return boolean */ function existsFile($sessid, $gunid, $ftype=NULL) { $id = $this->_idFromGunid($gunid); - if(is_null($id)) return FALSE; - if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) + if (is_null($id)) { + return FALSE; + } + if (($res = $this->_authorize('read', $id, $sessid)) !== TRUE) { return $res; + } $ex = $this->bsExistsFile($id, $ftype); return $ex; } + /** * Delete existing audio clip * - * @param sessid string - * @param gunid string - * @param forced boolean, if true don't use trash + * @param string $sessid + * @param string $gunid + * @param boolean $forced, if true don't use trash * @return boolean or PEAR::error */ function deleteAudioClip($sessid, $gunid, $forced=FALSE) { $ac =& StoredFile::recallByGunid($this, $gunid); - if(PEAR::isError($ac)){ - if($ac->getCode()==GBERR_FOBJNEX && $forced) return TRUE; + if (PEAR::isError($ac)) { + if ($ac->getCode()==GBERR_FOBJNEX && $forced) { + return TRUE; + } return $ac; } - if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) + if (($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) { return $res; + } $res = $this->bsDeleteFile($ac->getId(), $forced); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Update existing audio clip metadata * - * @param sessid string - * @param gunid string - * @param metadata string, metadata XML string + * @param string $sessid + * @param string $gunid + * @param string $metadata, metadata XML string * @return boolean or PEAR::error */ function updateAudioClipMetadata($sessid, $gunid, $metadata) { $ac =& StoredFile::recallByGunid($this, $gunid); - if(PEAR::isError($ac)) return $ac; - if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) + if (PEAR::isError($ac)) { + return $ac; + } + if (($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) { return $res; + } return $ac->replaceMetaData($metadata, 'string'); } + /*====================================================== playlist methods */ /** * Create a new empty playlist. * - * @param sessid string, session ID - * @param playlistId string, playlist global unique ID - * @param fname string, human readable mnemonic file name + * @param string $sessid, session ID + * @param string $playlistId, playlist global unique ID + * @param string $fname, human readable mnemonic file name * @return string, playlist global unique ID */ function createPlaylist($sessid, $playlistId, $fname) { $ex = $this->existsPlaylist($sessid, $playlistId); - if(PEAR::isError($ex)){ return $ex; } - if($ex){ + if (PEAR::isError($ex)) { + return $ex; + } + if ($ex) { return PEAR::raiseError( 'LocStor::createPlaylist: already exists' ); } $tmpFname = uniqid(''); $parid = $this->_getHomeDirIdFromSess($sessid); - if(PEAR::isError($parid)) return $parid; - if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) + if (PEAR::isError($parid)) { + return $parid; + } + if (($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) { return $res; + } $oid = $this->addObj($tmpFname , 'playlist', $parid); - if(PEAR::isError($oid)) return $oid; + if (PEAR::isError($oid)) { + return $oid; + } $ac =& StoredFile::insert($this, $oid, '', '', dirname(__FILE__).'/emptyPlaylist.xml', 'file', $playlistId, 'playlist' ); - if(PEAR::isError($ac)){ + if (PEAR::isError($ac)) { $res = $this->removeObj($oid); return $ac; } - if($fname == ''){ + if ($fname == '') { $fname = "newFile.xml"; } $res = $this->bsRenameFile($oid, $fname); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $ac->setState('ready'); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $ac->setMime('application/smil'); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return $ac->gunid; } + /** * Open a Playlist metafile for editing. * Open readable URL and mark file as beeing edited. * - * @param sessid string, session ID - * @param playlistId string, playlist global unique ID + * @param string $sessid, session ID + * @param string $playlistId, playlist global unique ID * @return struct * {url:readable URL for HTTP GET, token:access token, chsum:checksum} */ function editPlaylist($sessid, $playlistId) { $ex = $this->existsPlaylist($sessid, $playlistId); - if(PEAR::isError($ex)){ return $ex; } - if(!$ex){ + if (PEAR::isError($ex)) { + return $ex; + } + if (!$ex) { return PEAR::raiseError( 'LocStor::editPlaylist: playlist not exists' ); } - if($this->_isEdited($playlistId) !== FALSE){ + if ($this->_isEdited($playlistId) !== FALSE) { return PEAR::raiseError( 'LocStor::editPlaylist: playlist already edited' ); } $ac =& StoredFile::recallByGunid($this, $playlistId); - if(PEAR::isError($ac)){ return $ac; } + if (PEAR::isError($ac)) { + return $ac; + } $id = $ac->getId(); - if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) + if (($res = $this->_authorize('write', $id, $sessid)) !== TRUE) { return $res; + } $res = $this->bsOpenDownload($id, 'metadata'); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } $r = $this->_setEditFlag($playlistId, TRUE, $sessid); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } unset($res['filename']); return $res; } + /** * Store a new Playlist metafile in place of the old one. * - * @param sessid string, session ID - * @param playlistToken string, playlist access token - * @param newPlaylist string, new playlist as XML string + * @param string $sessid, session ID + * @param string $playlistToken, playlist access token + * @param string $newPlaylist, new playlist as XML string * @return string, playlistId */ function savePlaylist($sessid, $playlistToken, $newPlaylist) { $playlistId = $this->bsCloseDownload($playlistToken, 'metadata'); - if(PEAR::isError($playlistId)){ return $playlistId; } + if (PEAR::isError($playlistId)) { + return $playlistId; + } $ac =& StoredFile::recallByGunid($this, $playlistId); - if(PEAR::isError($ac)){ return $ac; } + if (PEAR::isError($ac)) { + return $ac; + } $res = $ac->replaceMetaData($newPlaylist, 'string', 'playlist'); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } $r = $this->_setEditFlag($playlistId, FALSE, $sessid); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $playlistId; } + /** * RollBack playlist changes to the locked state * - * @param playlistToken string, playlist access token - * @param sessid string, session ID + * @param string $playlistToken, playlist access token + * @param string $sessid, session ID * @return string gunid of playlist */ function revertEditedPlaylist($playlistToken, $sessid='') { $gunid = $this->bsCloseDownload($playlistToken, 'metadata'); - if(PEAR::isError($gunid)) return $gunid; + if (PEAR::isError($gunid)) { + return $gunid; + } $ac =& StoredFile::recallByGunid($this, $gunid); - if(PEAR::isError($ac)){ return $ac; } + if (PEAR::isError($ac)) { + return $ac; + } $id = $ac->getId(); $mdata = $ac->getMetaData(); - if(PEAR::isError($mdata)){ return $mdata; } + if (PEAR::isError($mdata)) { + return $mdata; + } $res = $ac->replaceMetaData($mdata, 'string'); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } $this->_setEditFlag($gunid, FALSE, $sessid); return $gunid; } + /** * Delete a Playlist metafile. * - * @param sessid string, session ID - * @param playlistId string, playlist global unique ID - * @param forced boolean, if true don't use trash + * @param string $sessid, session ID + * @param string $playlistId, playlist global unique ID + * @param boolean $forced, if true don't use trash * @return boolean */ function deletePlaylist($sessid, $playlistId, $forced=FALSE) { $ex = $this->existsPlaylist($sessid, $playlistId); - if(PEAR::isError($ex)){ return $ex; } - if(!$ex){ - if($forced) return TRUE; + if (PEAR::isError($ex)) { + return $ex; + } + if (!$ex) { + if ($forced) { + return TRUE; + } return PEAR::raiseError( 'LocStor::deletePlaylist: playlist not exists', GBERR_FILENEX ); } $ac =& StoredFile::recallByGunid($this, $playlistId); - if(PEAR::isError($ac)) return $ac; - if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) + if (PEAR::isError($ac)) { + return $ac; + } + if (($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) { return $res; + } $res = $this->bsDeleteFile($ac->getId(), $forced); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Access (read) a Playlist metafile. * - * @param sessid string, session ID - * @param playlistId string, playlist global unique ID - * @param recursive boolean, flag for recursive access content + * @param string $sessid, session ID + * @param string $playlistId, playlist global unique ID + * @param boolean $recursive, flag for recursive access content * inside playlist (optional, default: false) - * @param parent int parent token + * @param int $parent parent token * @return struct { * url: readable URL for HTTP GET, * token: access token, @@ -622,48 +769,57 @@ class LocStor extends BasicStor{ */ function accessPlaylist($sessid, $playlistId, $recursive=FALSE, $parent='0') { - if($recursive){ + if ($recursive) { require_once"AccessRecur.php"; $r = AccessRecur::accessPlaylist($this, $sessid, $playlistId); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $r; } $ex = $this->existsPlaylist($sessid, $playlistId); - if(PEAR::isError($ex)){ return $ex; } - if(!$ex){ + if (PEAR::isError($ex)) { + return $ex; + } + if (!$ex) { return PEAR::raiseError( "LocStor::accessPlaylist: playlist not found ($playlistId)", GBERR_NOTF ); } $id = $this->_idFromGunid($playlistId); - if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) + if (($res = $this->_authorize('read', $id, $sessid)) !== TRUE) { return $res; + } $res = $this->bsOpenDownload($id, 'metadata', $parent); #unset($res['filename']); return $res; } + /** * Release the resources obtained earlier by accessPlaylist(). * - * @param sessid string, session ID - * @param playlistToken string, playlist access token - * @param recursive boolean, flag for recursive access content + * @param string $sessid, session ID + * @param string $playlistToken, playlist access token + * @param boolean $recursive, flag for recursive access content * inside playlist (optional, default: false) * @return string, playlist ID */ function releasePlaylist($sessid, $playlistToken, $recursive=FALSE) { - if($recursive){ + if ($recursive) { require_once"AccessRecur.php"; $r = AccessRecur::releasePlaylist($this, $sessid, $playlistToken); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } return $r; } return $this->bsCloseDownload($playlistToken, 'metadata'); } + /** * Create a tarfile with playlist export - playlist and all matching * sub-playlists and media files (if desired) @@ -682,7 +838,9 @@ class LocStor extends BasicStor{ function exportPlaylistOpen($sessid, $plids, $type='lspl', $standalone=FALSE) { $res = $r =$this->bsExportPlaylistOpen($plids, $type, !$standalone); - if($this->dbc->isError($r)) return $r; + if ($this->dbc->isError($r)) { + return $r; + } $url = $this->getUrlPart()."access/".basename($res['fname']); $chsum = md5_file($res['fname']); $size = filesize($res['fname']); @@ -692,7 +850,8 @@ class LocStor extends BasicStor{ 'chsum' => $chsum, ); } - + + /** * Close playlist export previously opened by the exportPlaylistOpen method * @@ -704,12 +863,13 @@ class LocStor extends BasicStor{ { return $this->bsExportPlaylistClose($token); } - + + /** * Open writable handle for import playlist in LS Archive format * - * @param sessid string, session id - * @param chsum string, md5 checksum of imported file + * @param string $sessid, session id + * @param string $chsum, md5 checksum of imported file * @return hasharray with: * url string: writable URL * token string: PUT token @@ -717,41 +877,54 @@ class LocStor extends BasicStor{ function importPlaylistOpen($sessid, $chsum) { $userid = $r =$this->getSessUserId($sessid); - if($this->dbc->isError($r)) return $r; + if ($this->dbc->isError($r)) { + return $r; + } $r = $this->bsOpenPut($chsum, NULL, $userid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $r; } - + + /** * Close import-handle and import playlist * - * @param token string, import token obtained by importPlaylistOpen method + * @param string $token, import token obtained by importPlaylistOpen method * @return string, result file global id (or error object) */ function importPlaylistClose($token) { $arr = $r = $this->bsClosePut($token); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $fname = $arr['fname']; $owner = $arr['owner']; $parid = $r= $this->_getHomeDirId($owner); - if(PEAR::isError($r)) { - if(file_exists($fname)) @unlink($fname); + if (PEAR::isError($r)) { + if (file_exists($fname)) { + @unlink($fname); + } return $r; } $res = $r = $this->bsImportPlaylist($parid, $fname); - if(file_exists($fname)) @unlink($fname); - if(PEAR::isError($r)) return $r; + if (file_exists($fname)) { + @unlink($fname); + } + if (PEAR::isError($r)) { + return $r; + } return $this->_gunidFromId($res); } - + /** * Check whether a Playlist metafile with the given playlist ID exists. * - * @param sessid string, session ID - * @param playlistId string, playlist global unique ID + * @param string $sessid, session ID + * @param string $playlistId, playlist global unique ID * @return boolean */ function existsPlaylist($sessid, $playlistId) @@ -759,37 +932,45 @@ class LocStor extends BasicStor{ return $this->existsFile($sessid, $playlistId, 'playlist'); } + /** * Check whether a Playlist metafile with the given playlist ID * is available for editing, i.e., exists and is not marked as * beeing edited. * - * @param sessid string, session ID - * @param playlistId string, playlist global unique ID - * @param getUid boolean, optional flag for returning editedby uid + * @param string $sessid, session ID + * @param string $playlistId, playlist global unique ID + * @param boolean $getUid, optional flag for returning editedby uid * @return boolean */ function playlistIsAvailable($sessid, $playlistId, $getUid=FALSE) { $ex = $this->existsPlaylist($sessid, $playlistId); - if(PEAR::isError($ex)){ return $ex; } - if(!$ex){ + if (PEAR::isError($ex)) { + return $ex; + } + if (!$ex) { return PEAR::raiseError( 'LocStor::playlistIsAvailable: playlist not exists' ); } $ie = $this->_isEdited($playlistId); - if($ie === FALSE) return TRUE; - if($getUid) return $ie; + if ($ie === FALSE) { + return TRUE; + } + if ($getUid) { + return $ie; + } return FALSE; } + /* ------------------------------------------------------- render methods */ /** * Render playlist to ogg file (open handle) * - * @param sessid : string - session id - * @param plid : string - playlist gunid + * @param string $sessid - session id + * @param string $plid - playlist gunid * @return hasharray: * token: string - render token */ @@ -797,14 +978,17 @@ class LocStor extends BasicStor{ { require_once "Renderer.php"; $r = Renderer::rnRender2FileOpen($this, $plid); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $r; } + /** * Render playlist to ogg file (check results) * - * @param token : string - render token + * @param string $token - render token * @return hasharray: * status : string - success | working | fault * url : string - readable url @@ -813,21 +997,26 @@ class LocStor extends BasicStor{ { require_once "Renderer.php"; $r = Renderer::rnRender2FileCheck($this, $token); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return array('status'=>$r['status'], 'url'=>$r['url']); } + /** * Render playlist to ogg file (close handle) * - * @param token : string - render token - * @return status : boolean + * @param string $token - render token + * @return boolean status */ function renderPlaylistToFileClose($token) { require_once "Renderer.php"; $r = Renderer::rnRender2FileClose($this, $token); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return array(TRUE); } @@ -835,24 +1024,29 @@ class LocStor extends BasicStor{ /** * Render playlist to storage media clip (open handle) * - * @param sessid : string - session id - * @param plid : string - playlist gunid - * @return token : string - render token + * @param string $sessid - session id + * @param string $plid - playlist gunid + * @return string - render token */ function renderPlaylistToStorageOpen($sessid, $plid) { require_once "Renderer.php"; $owner = $this->getSessUserId($sessid); - if($this->dbc->isError($owner)) return $owner; + if ($this->dbc->isError($owner)) { + return $owner; + } $r = Renderer::rnRender2FileOpen($this, $plid, $owner); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $r; } + /** * Render playlist to storage media clip (check results) * - * @param token : string - render token + * @param string $token - render token * @return hasharray: * status : string - success | working | fault * gunid : string - gunid of result file @@ -861,7 +1055,9 @@ class LocStor extends BasicStor{ { require_once "Renderer.php"; $r = Renderer::rnRender2StorageCheck($this, $token); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $r; } @@ -869,9 +1065,9 @@ class LocStor extends BasicStor{ /** * Render playlist to RSS file (open handle) * - * @param sessid : string - session id - * @param plid : string - playlist gunid - * @return token : string - render token + * @param string $sessid - session id + * @param string $plid - playlist gunid + * @return string - render token */ function renderPlaylistToRSSOpen($sessid, $plid) { @@ -881,10 +1077,11 @@ class LocStor extends BasicStor{ return array('token'=>$token); } + /** * Render playlist to RSS file (check results) * - * @param token : string - render token + * @param string $token - render token * @return hasharray : * status : string - success | working | fault * url : string - readable url @@ -892,7 +1089,7 @@ class LocStor extends BasicStor{ function renderPlaylistToRSSCheck($token) { $fakeFile = "{$this->accessDir}/$token.rss"; - if($token != '123456789abcdeff' || !file_exists($fakeFile)){ + if ($token != '123456789abcdeff' || !file_exists($fakeFile)) { return PEAR::raiseError( "LocStor::renderPlaylistToRSSCheck: invalid token ($token)" ); @@ -904,15 +1101,16 @@ class LocStor extends BasicStor{ ); } + /** * Render playlist to RSS file (close handle) * - * @param token : string - render token - * @return status : boolean + * @param string $token - render token + * @return boolean status */ function renderPlaylistToRSSClose($token) { - if($token != '123456789abcdeff'){ + if ($token != '123456789abcdeff') { return PEAR::raiseError( "LocStor::renderPlaylistToRSSClose: invalid token" ); @@ -924,12 +1122,14 @@ class LocStor extends BasicStor{ /*================================================= storage admin methods */ + /* ------------------------------------------------------- backup methods */ + /** * Create backup of storage (open handle) * - * @param sessid : string - session id - * @param criteria : struct - see search criteria + * @param string $sessid - session id + * @param array $criteria - see search criteria * @return hasharray: * token : string - backup token */ @@ -937,9 +1137,11 @@ class LocStor extends BasicStor{ { require_once "Backup.php"; $bu = $r = new Backup($this); - if (PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } $r = $bu->openBackup($sessid,$criteria); - if ($r === FALSE){ + if ($r === FALSE) { return PEAR::raiseError( "LocStor::createBackupOpen: false returned from Backup" ); @@ -947,11 +1149,12 @@ class LocStor extends BasicStor{ return $r; } + /** * Create backup of storage (check results) * - * @param token : string - backup token - * @return hasharray with field: + * @param string $token - backup token + * @return hasharray with field: * status : string - susccess | working | fault * faultString: string - description of fault * token : stirng - backup token @@ -961,17 +1164,20 @@ class LocStor extends BasicStor{ { require_once "Backup.php"; $bu = $r = new Backup($this); - if (PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $bu->checkBackup($token); } + /** * Create backup of storage (list results) * - * @param sessid : string - session id - * @param stat : status (optional) + * @param string $sessid - session id + * @param status $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 @@ -980,45 +1186,55 @@ class LocStor extends BasicStor{ { require_once "Backup.php"; $bu = $r = new Backup($this); - if (PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $bu->listBackups($stat); } + /** * Create backup of storage (close handle) * - * @param token : string - backup token - * @return status : boolean + * @param string $token - backup token + * @return boolean status */ function createBackupClose($token) { require_once "Backup.php"; $bu = $r = new Backup($this); - if (PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return $bu->closeBackup($token); } + /* ------------------------------------------------------ restore methods */ + /** * Restore a beckup file (open handle) * - * @param sessid : string - session id - * @param filename : string - backup file path - * @return token : string - restore token + * @param string $sessid - session id + * @param string $filename - backup file path + * @return string $token - restore token */ function restoreBackupOpen($sessid, $filename) { require_once 'Restore.php'; $rs = new Restore($this); - if (PEAR::isError($rs)) return $rs; + if (PEAR::isError($rs)) { + return $rs; + } return $rs->openRestore($sessid,$filename); } + /** * Restore a beckup file (check state) * - * @param token : string - restore token - * @return status : hasharray - fields: + * @param string $token - restore token + * @return array status - fields: * token: string - restore token * status: string - working | fault | success * faultString: string - description of fault @@ -1027,25 +1243,31 @@ class LocStor extends BasicStor{ { require_once 'Restore.php'; $rs = new Restore($this); - if (PEAR::isError($rs)) return $rs; + if (PEAR::isError($rs)) { + return $rs; + } return $rs->checkRestore($token); } - + + /** - * Restore a beckup file (close handle) + * Restore a backup file (close handle) * - * @param token : string - restore token - * @return status : hasharray - fields: + * @param string $token - restore token + * @return array status - fields: * token: string - restore token * status: string - working | fault | success */ function restoreBackupClose($token) { require_once 'Restore.php'; $rs = new Restore($this); - if (PEAR::isError($rs)) return $rs; + if (PEAR::isError($rs)) { + return $rs; + } return $rs->closeRestore($token); } + /*===================================================== auxiliary methods */ /** * Dummy method - only returns livesupport version @@ -1058,5 +1280,5 @@ class LocStor extends BasicStor{ return LS_VERSION; } -} +} // class LocStor ?> \ No newline at end of file diff --git a/livesupport/src/modules/storageServer/var/StoredFile.php b/livesupport/src/modules/storageServer/var/StoredFile.php index 8c0d767e8..35ce8701d 100644 --- a/livesupport/src/modules/storageServer/var/StoredFile.php +++ b/livesupport/src/modules/storageServer/var/StoredFile.php @@ -2,26 +2,26 @@ /*------------------------------------------------------------------------------ Copyright (c) 2004 Media Development Loan Fund - + This file is part of the LiveSupport project. http://livesupport.campware.org/ To report bugs, send an e-mail to bugs@campware.org - + LiveSupport is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + LiveSupport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with LiveSupport; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - + + Author : $Author$ Version : $Revision$ Location : $URL$ @@ -30,7 +30,7 @@ require_once "RawMediaData.php"; require_once "MetaData.php"; require_once dirname(__FILE__)."/../../getid3/var/getid3.php"; - + /** * StoredFile class * @@ -45,13 +45,13 @@ require_once dirname(__FILE__)."/../../getid3/var/getid3.php"; * @see MetaData * @see RawMediaData */ -class StoredFile{ +class StoredFile { /* ========================================================== constructor */ /** * Constructor, but shouldn't be externally called * - * @param gb reference to GreenBox object - * @param gunid string, optional, globally unique id of file + * @param reference $gb to GreenBox object + * @param string $gunid, optional, globally unique id of file * @return this */ function StoredFile(&$gb, $gunid=NULL) @@ -61,7 +61,9 @@ class StoredFile{ $this->filesTable = $gb->filesTable; $this->accessTable= $gb->accessTable; $this->gunid = $gunid; - if(is_null($this->gunid)) $this->gunid = $this->_createGunid(); + if (is_null($this->gunid)) { + $this->gunid = $this->_createGunid(); + } $this->resDir = $this->_getResDir($this->gunid); $this->accessDir = $this->gb->accessDir; $this->rmd =& new RawMediaData($this->gunid, $this->resDir); @@ -69,33 +71,39 @@ class StoredFile{ # return $this->gunid; } + /* ========= 'factory' methods - should be called to construct StoredFile */ /** * Create instance of StoredFile object and insert new file * - * @param gb reference to GreenBox object - * @param oid int, local object id in the tree - * @param name string, name of new file - * @param mediaFileLP string, local path to media file - * @param metadata string, local path to metadata XML file or XML string - * @param mdataLoc string 'file'|'string' (optional) - * @param gunid global unique id (optional) - for insert file with gunid - * @param ftype string, internal file type - * @param className string, class to be constructed (opt.) + * @param reference $gb to GreenBox object + * @param int $oid, local object id in the tree + * @param string $name, name of new file + * @param string $mediaFileLP, local path to media file + * @param string $metadata, local path to metadata XML file or XML string + * @param string $mdataLoc 'file'|'string' (optional) + * @param global $gunid unique id (optional) - for insert file with gunid + * @param string $ftype, internal file type + * @param string $className, class to be constructed (opt.) * @return instance of StoredFile object */ function &insert(&$gb, $oid, $name, $mediaFileLP='', $metadata='', $mdataLoc='file', $gunid=NULL, $ftype=NULL, $className='StoredFile') { - foreach(array('name', 'ftype') as $v) $$v = pg_escape_string($$v); + $name = pg_escape_string($name); + $ftype = pg_escape_string($ftype); $ac =& new $className($gb, ($gunid ? $gunid : NULL)); - if(PEAR::isError($ac)) return $ac; + if (PEAR::isError($ac)) { + return $ac; + } $ac->name = $name; $ac->id = $oid; $ac->mime = "unKnown"; $emptyState = TRUE; - if($ac->name=='') $ac->name=$ac->gunid; + if ($ac->name=='') { + $ac->name=$ac->gunid; + } $ac->dbc->query("BEGIN"); $res = $ac->dbc->query(" INSERT INTO {$ac->filesTable} @@ -104,61 +112,72 @@ class StoredFile{ ('$oid', '{$ac->name}', x'{$ac->gunid}'::bigint, '{$ac->mime}', 'incomplete', '$ftype', now()) "); - if(PEAR::isError($res)){ $ac->dbc->query("ROLLBACK"); return $res; } + if (PEAR::isError($res)) { + $ac->dbc->query("ROLLBACK"); + return $res; + } // --- metadata insert: - if(is_null($metadata) || $metadata == ''){ + if (is_null($metadata) || ($metadata == '') ) { $metadata = dirname(__FILE__).'/emptyMdata.xml'; $mdataLoc = 'file'; - }else{ + } else { $emptyState = FALSE; } - if($mdataLoc=='file' && !file_exists($metadata)) - { + if ( ($mdataLoc == 'file') && !file_exists($metadata)) { return PEAR::raiseError("StoredFile::insert: ". "metadata file not found ($metadata)"); } $res = $ac->md->insert($metadata, $mdataLoc, $ftype); - if(PEAR::isError($res)){ - $ac->dbc->query("ROLLBACK"); return $res; + if (PEAR::isError($res)) { + $ac->dbc->query("ROLLBACK"); + return $res; } // --- media file insert: - if($mediaFileLP != ''){ - if(!file_exists($mediaFileLP)) - { + if ($mediaFileLP != '') { + if (!file_exists($mediaFileLP)) { return PEAR::raiseError("StoredFile::insert: ". "media file not found ($mediaFileLP)"); } $res = $ac->rmd->insert($mediaFileLP); - if(PEAR::isError($res)){ - $ac->dbc->query("ROLLBACK"); return $res; + if (PEAR::isError($res)) { + $ac->dbc->query("ROLLBACK"); + return $res; } $mime = $ac->rmd->getMime(); //$gb->debugLog("gunid={$ac->gunid}, mime=$mime"); - if($mime !== FALSE){ + if ($mime !== FALSE) { $res = $ac->setMime($mime); - if(PEAR::isError($res)){ - $ac->dbc->query("ROLLBACK"); return $res; + if (PEAR::isError($res)) { + $ac->dbc->query("ROLLBACK"); + return $res; } } $emptyState = FALSE; } - if(!$emptyState){ + if (!$emptyState) { $res = $ac->setState('ready'); - if(PEAR::isError($res)){ $ac->dbc->query("ROLLBACK"); return $res; } + if (PEAR::isError($res)) { + $ac->dbc->query("ROLLBACK"); + return $res; + } } $res = $ac->dbc->query("COMMIT"); - if(PEAR::isError($res)){ $ac->dbc->query("ROLLBACK"); return $res; } + if (PEAR::isError($res)) { + $ac->dbc->query("ROLLBACK"); + return $res; + } return $ac; } + /** * Create instance of StoreFile object and recall existing file.
      * Should be supplied oid XOR gunid - not both ;) * - * @param gb reference to GreenBox object - * @param oid int, optional, local object id in the tree - * @param gunid string, optional, global unique id of file - * @param className string, optional classname to recall + * @param reference $gb to GreenBox object + * @param int $oid, optional, local object id in the tree + * @param string $gunid, optional, global unique id of file + * @param string $className, optional classname to recall * @return instance of StoredFile object */ function &recall(&$gb, $oid='', $gunid='', $className='StoredFile') @@ -171,8 +190,10 @@ class StoredFile{ SELECT id, to_hex(gunid)as gunid, mime, name, ftype FROM {$gb->filesTable} WHERE $cond "); - if(PEAR::isError($row)) return $row; - if(is_null($row)){ + if (PEAR::isError($row)) { + return $row; + } + if (is_null($row)) { return PEAR::raiseError( "StoredFile::recall: fileobj not exist ($oid/$gunid)", GBERR_FOBJNEX @@ -187,27 +208,29 @@ class StoredFile{ return $ac; } + /** * Create instance of StoreFile object and recall existing file * by gunid.
      * - * @param gb reference to GreenBox object - * @param gunid string, optional, global unique id of file - * @param className string, optional classname to recall + * @param reference $gb to GreenBox object + * @param string $gunid, optional, global unique id of file + * @param string $className, optional classname to recall * @return instance of StoredFile object */ function &recallByGunid(&$gb, $gunid='', $className='StoredFile') { - return StoredFile::recall($gb, '', $gunid, $className); + return StoredFile::recall($gb, '', $gunid, $className); } + /** * Create instance of StoreFile 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 reference $gb to GreenBox object + * @param string $token, access token + * @param string $className, optional classname to recall * @return instance of StoredFile object */ function recallByToken(&$gb, $token, $className='StoredFile') @@ -217,18 +240,23 @@ class StoredFile{ FROM {$gb->accessTable} WHERE token=x'$token'::bigint "); - if(PEAR::isError($gunid)) return $gunid; - if(is_null($gunid)) return PEAR::raiseError( + if (PEAR::isError($gunid)) { + return $gunid; + } + if (is_null($gunid)) { + return PEAR::raiseError( "StoredFile::recallByToken: invalid token ($token)", GBERR_AOBJNEX); + } $gunid = StoredFile::_normalizeGunid($gunid); return StoredFile::recall($gb, '', $gunid, $className); } + /** * Create instance of StoredFile object and make copy of existing file * - * @param src reference to source object - * @param nid int, new local id + * @param reference $src to source object + * @param int $nid, new local id */ function ©Of(&$src, $nid) { @@ -236,55 +264,65 @@ class StoredFile{ $src->gb, $nid, $src->name, $src->_getRealRADFname(), '', '', NULL, $src->gb->_getType($src->gunid) ); - if(PEAR::isError($ac)) return $ac; + if (PEAR::isError($ac)) { + return $ac; + } $ac->md->replace($src->md->getMetaData(), 'string'); return $ac; } + /* ======================================================= public methods */ /** * Replace existing file with new data * - * @param oid int, local id - * @param name string, name of file - * @param mediaFileLP string, local path to media file - * @param metadata string, local path to metadata XML file or XML string - * @param mdataLoc string 'file'|'string' + * @param int $oid, local id + * @param string $name, name of file + * @param string $mediaFileLP, local path to media file + * @param string $metadata, local path to metadata XML file or XML string + * @param string $mdataLoc 'file'|'string' */ function replace($oid, $name, $mediaFileLP='', $metadata='', $mdataLoc='file') { $this->dbc->query("BEGIN"); $res = $this->rename($name); - if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } - if($mediaFileLP != ''){ // media + if (PEAR::isError($res)) { + $this->dbc->query("ROLLBACK"); + return $res; + } + if ($mediaFileLP != '') { // media $res = $this->replaceRawMediaData($mediaFileLP); - }else{ + } else { $res = $this->rmd->delete(); } - if(PEAR::isError($res)){ - $this->dbc->query("ROLLBACK"); return $res; + if (PEAR::isError($res)) { + $this->dbc->query("ROLLBACK"); + return $res; } - if($metadata != ''){ // metadata + if ($metadata != '') { // metadata $res = $this->replaceMetaData($metadata, $mdataLoc); - }else{ + } else { $res = $this->md->delete(); } - 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; } + /** * Increase access counter, create access token, insert access record, * call access method of RawMediaData * - * @param parent int parent token + * @param int $parent parent token * @return array with: access URL, access token */ function accessRawMediaData($parent='0') @@ -292,50 +330,63 @@ class StoredFile{ $realFname = $this->_getRealRADFname(); $ext = $this->_getExt(); $res = $this->gb->bsAccess($realFname, $ext, $this->gunid, 'access', $parent); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } $resultArray = array('url'=>"file://{$res['fname']}", 'token'=>$res['token']); return $resultArray; } + /** * Decrease access couter, delete access record, * call release method of RawMediaData * - * @param token string, access token + * @param string $token, access token * @return boolean */ function releaseRawMediaData($token) { $res = $this->gb->bsRelease($token); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Replace media file only with new binary file * - * @param mediaFileLP string, local path to media file + * @param string $mediaFileLP, local path to media file */ function replaceRawMediaData($mediaFileLP) { $res = $this->rmd->replace($mediaFileLP); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } $mime = $this->rmd->getMime(); - if($mime !== FALSE){ + if ($mime !== FALSE) { $res = $this->setMime($mime); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } } $r = $this->md->regenerateXmlFile(); - if(PEAR::isError($r)){ return $r; } + if (PEAR::isError($r)) { + return $r; + } } + /** * Replace metadata with new XML file * - * @param metadata string, local path to metadata XML file or XML string - * @param mdataLoc string 'file'|'string' - * @param format string, metadata format for validation + * @param string $metadata, local path to metadata XML file or XML string + * @param string $mdataLoc 'file'|'string' + * @param string $format, metadata format for validation * ('audioclip' | 'playlist' | 'webstream' | NULL) * (NULL = no validation) * @return boolean @@ -344,14 +395,23 @@ class StoredFile{ { $this->dbc->query("BEGIN"); $res = $r = $this->md->replace($metadata, $mdataLoc, $format); - if(PEAR::isError($r)){ $this->dbc->query("ROLLBACK"); return $r; } + if (PEAR::isError($r)) { + $this->dbc->query("ROLLBACK"); + return $r; + } $r = $this->md->regenerateXmlFile(); - if(PEAR::isError($r)){ $this->dbc->query("ROLLBACK"); return $r; } + if (PEAR::isError($r)) { + $this->dbc->query("ROLLBACK"); + return $r; + } $res = $r = $this->dbc->query("COMMIT"); - if(PEAR::isError($r)) return $r; + if (PEAR::isError($r)) { + return $r; + } return TRUE; } + /** * Get metadata as XML string * @@ -363,6 +423,7 @@ class StoredFile{ return $this->md->getMetaData(); } + /** * Analyze file with getid3 module.
      * Obtain some metadata stored in media file.
      @@ -377,61 +438,71 @@ class StoredFile{ return $ia; } + /** * Rename stored virtual file * - * @param newname string + * @param string $newname * @return true or PEAR::error */ function rename($newname) { - foreach(array('newname') as $v) $$v = pg_escape_string($$v); + $newname = pg_escape_string($newname); $res = $this->dbc->query(" UPDATE {$this->filesTable} SET name='$newname', mtime=now() WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Set state of virtual file * - * @param state string, 'empty'|'incomplete'|'ready'|'edited' - * @param editedby int, user id | 'NULL' for clear editedBy field + * @param string $state, 'empty'|'incomplete'|'ready'|'edited' + * @param int $editedby, user id | 'NULL' for clear editedBy field * (optional) * @return boolean or error */ function setState($state, $editedby=NULL) { - foreach(array('state') as $v) $$v = pg_escape_string($$v); + $state = pg_escape_string($state); $eb = (!is_null($editedby) ? ", editedBy=$editedby" : ''); $res = $this->dbc->query(" UPDATE {$this->filesTable} SET state='$state'$eb, mtime=now() WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Set mime-type of virtual file * - * @param mime string, mime-type + * @param string $mime, mime-type * @return boolean or error */ function setMime($mime) { - foreach(array('mime') as $v) $$v = pg_escape_string($$v); + $mime = pg_escape_string($mime); $res = $this->dbc->query(" UPDATE {$this->filesTable} SET mime='$mime', mtime=now() WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($res)){ return $res; } + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Delete stored virtual file * @@ -441,84 +512,112 @@ class StoredFile{ function delete() { $res = $this->rmd->delete(); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $this->md->delete(); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $tokens = $this->dbc->getAll(" SELECT to_hex(token)as token, ext FROM {$this->accessTable} WHERE gunid=x'{$this->gunid}'::bigint "); - if(is_array($tokens)) foreach($tokens as $i=>$item){ - $file = $this->_getAccessFname($item['token'], $item['ext']); - if(file_exists($file)){ @unlink($file); } + if (is_array($tokens)) { + foreach($tokens as $i=>$item){ + $file = $this->_getAccessFname($item['token'], $item['ext']); + if (file_exists($file)) { + @unlink($file); + } + } } $res = $this->dbc->query(" DELETE FROM {$this->accessTable} WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } $res = $this->dbc->query(" DELETE FROM {$this->filesTable} WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($res)) return $res; + if (PEAR::isError($res)) { + return $res; + } return TRUE; } + /** * Returns true if virtual file is accessed.
      * Static or dynamic call is possible. * - * @param gunid string, optional (for static call), global unique id + * @param string $gunid, optional (for static call), global unique id */ function isAccessed($gunid=NULL) { - if(is_null($gunid)) $gunid = $this->gunid; + if (is_null($gunid)) { + $gunid = $this->gunid; + } $ca = $this->dbc->getOne(" SELECT currentlyAccessing FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint "); - if(is_null($ca)){ + if (is_null($ca)) { return PEAR::raiseError( "StoredFile::isAccessed: invalid gunid ($gunid)", GBERR_FOBJNEX ); } return ($ca > 0); - } + } + /** * Returns true if virtual file is edited * - * @param playlistId string, playlist global unique ID + * @param string $playlistId, playlist global unique ID * @return boolean */ function isEdited($playlistId=NULL) { - if(is_null($playlistId)) $playlistId = $this->gunid; + if (is_null($playlistId)) { + $playlistId = $this->gunid; + } $state = $this->_getState($playlistId); - if($state != 'edited'){ return FALSE; } + if ($state != 'edited') { + return FALSE; + } return TRUE; } + /** * Returns id of user editing playlist * - * @param playlistId string, playlist global unique ID + * @param string $playlistId, playlist global unique ID * @return null or int, id of user editing it */ function isEditedBy($playlistId=NULL) { - if(is_null($playlistId)) $playlistId = $this->gunid; + if (is_null($playlistId)) { + $playlistId = $this->gunid; + } $ca = $this->dbc->getOne(" SELECT editedBy FROM {$this->filesTable} WHERE gunid=x'$playlistId'::bigint "); - if($this->dbc->isError($ca)) return $ca; - if(is_null($ca)) return $ca; + if ($this->dbc->isError($ca)) { + return $ca; + } + if (is_null($ca)) { + return $ca; + } return intval($ca); } + /** * Returns local id of virtual file * @@ -526,7 +625,8 @@ class StoredFile{ function getId() { return $this->id; - } + } + /** * Returns true if raw media file exists @@ -538,14 +638,19 @@ class StoredFile{ SELECT to_hex(gunid) FROM {$this->filesTable} WHERE gunid=x'{$this->gunid}'::bigint "); - if(PEAR::isError($indb)) return $indb; - if(is_null($indb)) return FALSE; - if($this->gb->_getType($this->gunid) == 'audioclip'){ + if (PEAR::isError($indb)) { + return $indb; + } + if (is_null($indb)) { + return FALSE; + } + if ($this->gb->_getType($this->gunid) == 'audioclip') { return $this->rmd->exists(); } return TRUE; - } - + } + + /* ==================================================== "private" methods */ /** * Create new global unique id @@ -563,6 +668,7 @@ class StoredFile{ return StoredFile::_normalizeGunid($res); } + /** * Create new global unique id * @@ -572,26 +678,32 @@ class StoredFile{ return str_pad($gunid0, 16, "0", STR_PAD_LEFT); } + /** * Get local id from global id. * Static or dynamic call is possible. * - * @param gunid string, optional (for static call), + * @param string $gunid, optional (for static call), * global unique id of file */ function _idFromGunid($gunid=NULL) { - if(is_null($gunid)) $gunid = $this->$gunid; + if (is_null($gunid)) { + $gunid = $this->$gunid; + } $id = $this->dbc->getOne(" SELECT id FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint "); - if(is_null($id)) return PEAR::raiseError( + if (is_null($id)) { + return PEAR::raiseError( "StoredFile::_idFromGunid: no such global unique id ($gunid)" - ); + ); + } return $id; } + /** * Return suitable extension.
      * TODO: make it general - is any tool for it? @@ -602,70 +714,86 @@ class StoredFile{ { $fname = $this->_getFileName(); $pos = strrpos($fname, '.'); - if($pos !== FALSE){ + if ($pos !== FALSE) { $ext = substr($fname, $pos+1); - if($ext !== FALSE) return $ext; + if ($ext !== FALSE) { + return $ext; + } } - switch(strtolower($this->mime)){ - case"audio/mpeg": - $ext="mp3"; break; - case"audio/x-wav": - case"audio/x-wave": - $ext="wav"; break; - case"audio/x-ogg": - case"application/x-ogg": - $ext="ogg"; break; + switch (strtolower($this->mime)) { + case "audio/mpeg": + $ext = "mp3"; + break; + case "audio/x-wav": + case "audio/x-wave": + $ext = "wav"; + break; + case "audio/x-ogg": + case "application/x-ogg": + $ext = "ogg"; + break; default: - $ext="bin"; break; + $ext = "bin"; + break; } return $ext; } + /** * Get mime-type from global id * - * @param gunid string, optional, global unique id of file + * @param string $gunid, optional, global unique id of file * @return string, mime-type */ function _getMime($gunid=NULL) { - if(is_null($gunid)) $gunid = $this->gunid; + if (is_null($gunid)) { + $gunid = $this->gunid; + } return $this->dbc->getOne(" SELECT mime FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint "); } + /** * Get storage-internal file state * - * @param gunid string, optional, global unique id of file + * @param string $gunid, optional, global unique id of file * @return string, see install() */ function _getState($gunid=NULL) { - if(is_null($gunid)) $gunid = $this->gunid; + if (is_null($gunid)) { + $gunid = $this->gunid; + } return $this->dbc->getOne(" SELECT state FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint "); } + /** * Get mnemonic file name * - * @param gunid string, optional, global unique id of file + * @param string $gunid, optional, global unique id of file * @return string, see install() */ function _getFileName($gunid=NULL) { - if(is_null($gunid)) $gunid = $this->gunid; + if (is_null($gunid)) { + $gunid = $this->gunid; + } return $this->dbc->getOne(" SELECT name FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint "); } + /** * Get and optionaly create subdirectory in real filesystem for storing * raw media data @@ -676,10 +804,14 @@ class StoredFile{ $resDir="{$this->gb->storageDir}/".substr($this->gunid, 0, 3); #$this->gb->debugLog("$resDir"); // see Transport::_getResDir too for resDir name create code - if(!is_dir($resDir)){ mkdir($resDir, 02775); chmod($resDir, 02775); } + if (!is_dir($resDir)) { + mkdir($resDir, 02775); + chmod($resDir, 02775); + } return $resDir; } + /** * Get real filename of raw media data * @@ -690,6 +822,7 @@ class StoredFile{ return $this->rmd->getFname(); } + /** * Get real filename of metadata file * @@ -700,6 +833,7 @@ class StoredFile{ return $this->md->getFname(); } + /** * Create and return name for temporary symlink.
      * TODO: Should be more unique @@ -710,5 +844,6 @@ class StoredFile{ $token = StoredFile::_normalizeGunid($token); return "{$this->accessDir}/$token.$ext"; } -} + +} // class StoredFile ?> \ No newline at end of file