_authorize('write', $parid, $sessid)) !== TRUE) return $res; return $this->bsCreateFolder($parid, $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 sessid string, session id * @param gunid string, global unique id OPTIONAL * @return int * @exception PEAR::error */ function putFile($parid, $fileName, $mediaFileLP, $mdataFileLP, $sessid='', $gunid=NULL) { if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) return $res; return $this->bsPutFile( $parid, $fileName, $mediaFileLP, $mdataFileLP, $gunid ); } /** * Analyze media file for internal metadata information * * @param id int, virt.file's local id * @param sessid string, session id * @return array */ function analyzeFile($id, $sessid='') { if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) return $res; return $this->bsAnalyzeFile($id); } /** * Rename file * * @param id int, virt.file's local id * @param newName string * @param sessid string, session id * @return boolean or PEAR::error */ function renameFile($id, $newName, $sessid='') { $parid = $this->getParent($id); if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) return $res; return $this->bsRenameFile($id, $newName); } /** * Move file * * @param id int, virt.file's local id * @param did int, destination folder local id * @param sessid string, session id * @return boolean or PEAR::error */ function moveFile($id, $did, $sessid='') { if(($res = $this->_authorize( array('read', 'write'), array($id, $did), $sessid )) !== TRUE) return $res; return $this->bsMoveFile($id, $did); } /** * Copy file * * @param id int, virt.file's local id * @param did int, destination folder local id * @param sessid string, session id * @return boolean or PEAR::error */ function copyFile($id, $did, $sessid='') { if(($res = $this->_authorize( array('read', 'write'), array($id, $did), $sessid )) !== TRUE) return $res; return $this->bsCopyFile($id, $did); } /** * Delete file * * @param id int, virt.file's local id * @param sessid int * @return true or PEAR::error */ function deleteFile($id, $sessid='') { $parid = $this->getParent($id); if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) return $res; return $this->bsDeleteFile($id); } /* ----------------------------------------------------- put, access etc. */ /** * Create and return access link to media file * * @param id int, virt.file's local id * @param sessid string, session id * @return array with: seekable filehandle, access token */ function access($id, $sessid='') { $ac =& StoredFile::recall(&$this, $id); if(PEAR::isError($ac)) return $ac; if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) return $res; return $ac->accessRawMediaData($sessid); } /** * Release access link to media file * * @param sessid string, session id * @param token string, access token * @return boolean or PEAR::error */ function release($token, $sessid='') { $ac =& StoredFile::recallByToken(&$this, $token); if(PEAR::isError($ac)) return $ac; return $ac->releaseRawMediaData($sessid, $token); } /* ---------------------------------------------- replicas, versions etc. */ /** * Create replica.
* TODO: NOT FINISHED * * @param id int, virt.file's local id * @param did int, destination folder local id * @param replicaName string, name of new replica * @param sessid string, session id * @return int, local id of new object */ function createReplica($id, $did, $replicaName='', $sessid='') { if(($res = $this->_authorize( array('read', 'write'), array($id, $did), $sessid )) !== TRUE) return $res; return $this->bsCreateReplica($id, $did, $replicaName); } /** * Create version.
* TODO: NOT FINISHED * * @param id int, virt.file's local id * @param did int, destination folder local id * @param versionLabel string, name of new version * @param sessid string, session id * @return int, local id of new object */ function createVersion($id, $did, $versionLabel, $sessid='') { return $this->bsCreateVersion($id, $did, $versionLabel); } /* ------------------------------------------------------------- metadata */ /** * Update metadata tree * * @param id int, virt.file's local id * @param mdataFile string, local path of metadata XML file * @param sessid string, session id * @return boolean or PEAR::error */ function updateMetadata($id, $mdataFile, $sessid='') { if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) return $res; return $this->bsUpdateMetadata($id, $mdataFile); } /** * Update object namespace and value of one metadata record * * @param id int, virt.file's local id * @param mdid int, metadata record id * @param object string, object value, e.g. title string * @param objns string, object namespace prefix, have to be defined * in file's metadata (or reserved prefix) * @param sessid string, session id * @return boolean or PEAR::error * @see MetaData */ function updateMetadataRecord($id, $mdid, $object, $objns='_L', $sessid='') { if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) return $res; return $this->bsUpdateMetadataRecord($id, $mdid, $object, $objns); } /** * Add single metadata record.
* TODO: NOT FINISHED
* Params could be changed! * * @param id int, virt.file's local id * @param propertyName string * @param propertyValue string * @param sessid string, session id * @return boolean or PEAR::error * @see MetaData */ function addMetaDataRecord($id, $propertyName, $propertyValue, $sessid='') { if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) return $res; return $this->bsAddMetaDataRecord($id, $propertyName, $propertyValue); } /** * Get metadata XML tree as string * * @param id int, virt.file's local id * @param sessid string, session id * @return string or PEAR::error */ function getMdata($id, $sessid='') { if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) return $res; return $this->bsGetMdata($id); } /** * Search in local metadata database.
* TODO: NOT FINISHED
* It will support structured queries - array of mode and query parts. * Mode is "match all" or "match any". * Query parts is array of [fieldname, operator, value] entities. * * * @param searchData string, search query - * only one SQL LIKE term supported now. * It will be searched in all literal object values * in metadata database * @param sessid string, session id * @return array of gunid strings */ function localSearch($searchData, $sessid='') { return $this->bsLocalSearch($searchData); } /* --------------------------------------------------------- info methods */ /** * List files in folder * * @param id int, local id of folder * @param sessid string, session id * @return array */ function listFolder($id, $sessid='') { if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) return $res; return $this->bsListFolder($id); } /* ---------------------------------------------------- redefined methods */ /** * Logout and destroy session * * @param sessid string * @return true/err */ function logout($sessid) { /* release all accessed files on logout - probably not useful $acfa = $this->dbc->getAll("SELECT * FROM {$this->accessTable} WHERE sessid='$sessid'"); if(PEAR::isError($acfa)) return $acfa; foreach($acfa as $i=>$acf){ $ac =& StoredFile::recallByToken(&$this, $acf['token']); $ac->releaseRawMediaData($sessid, $acf['token']); } */ return parent::logout($sessid); } /** * Add new user with home folder * * @param login string * @param pass string OPT * @return int/err */ function addSubj($login, $pass=NULL) { $uid = parent::addSubj($login, $pass); if(PEAR::isError($uid)) return $uid; $fid = $this->addObj($login , 'Folder', $this->storId); if(PEAR::isError($fid)) return $fid; $res = $this->addPerm($uid, '_all', $fid, 'A'); if(PEAR::isError($res)) return $res; return $uid; } /** * Remove user and his home folder * * @param login string * @param uid int OPT * @return boolean/err */ function removeSubj($login, $uid=NULL) { $res = parent::removeSubj($login, $pass); if(PEAR::isError($res)) return $res; $id = $this->getObjId($login, $this->storId); if(PEAR::isError($id)) return $id; $res = $this->removeObj($id); if(PEAR::isError($res)) return $res; return TRUE; } /** * Get file's path in virtual filesystem * * @param id int * @return array */ function getPath($id) { $pa = parent::getPath($id, 'id, name, type'); array_shift($pa); return $pa; } /* ==================================================== "private" methods */ /** * Copy virtual file.
* Redefined from parent class. * * @return id */ function copyObj($id, $newParid, $after='') { $nid = parent::copyObj($id, $newParid, $after=''); if($this->getObjType($id)==='File'){ $ac =& StoredFile::recall(&$this, $id); if(PEAR::isError($ac)){ return $ac; } $ac2 =& StoredFile::copyOf(&$ac, $nid); } return $nid; } /** * Optionaly remove virtual file with the same name and add new one.
* Redefined from parent class. * * @return id */ function addObj($name, $type, $parid=1, $aftid=NULL, $param='') { if(!is_null($exid = $this->getObjId($name, $parid))) { $this->removeObj($exid); } return parent::addObj($name, $type, $parid, $aftid, $param); } /** * Remove virtual file.
* Redefined from parent class. * * @param id int, local id of removed object * @return true or PEAR::error */ function removeObj($id) { switch($this->getObjType($id)){ case"File": $ac =& StoredFile::recall(&$this, $id); if(!PEAR::isError($ac)){ $ac->delete(); } parent::removeObj($id); break; case"Folder": parent::removeObj($id); break; case"Replica": parent::removeObj($id); break; default: } return TRUE; } /** * Check authorization - auxiliary method * * @param acts array of actions * @param pars array of parameters - e.g. ids * @param sessid string, session id * @return true or PEAR::error */ function _authorize($acts, $pars, $sessid='') { $userid = $this->getSessUserId($sessid); if(!is_array($pars)) $pars = array($pars); if(!is_array($acts)) $acts = array($acts); $perm = true; foreach($acts as $i=>$action){ $res = $this->checkPerm($userid, $action, $pars[$i]); if(PEAR::isError($res)) return $res; $perm = $perm && $res; } if($perm) return TRUE; $adesc = "[".join(',',$acts)."]"; return PEAR::raiseError("GreenBox::$adesc: access denied", GBERR_DENY); } /** * Create fake session for downloaded files * * @param userid user id * @return string sessid */ function _fakeSession($userid) { $sessid = $this->_createSessid(); if(PEAR::isError($sessid)) return $sessid; $login = $this->getSubjName($userid); $r = $this->dbc->query("INSERT INTO {$this->sessTable} (sessid, userid, login, ts) VALUES ('$sessid', '$userid', '$login', now())"); if(PEAR::isError($r)) return $r; return $sessid; } /** * Get local id from global id * * @param gunid string global id * @return int local id */ function _idFromGunid($gunid) { return $this->dbc->getOne( "SELECT id FROM {$this->filesTable} WHERE gunid='$gunid'" ); } /** * Get global id from local id * * @param id int local id * @return string global id */ function _gunidFromId($id) { if(!is_numeric($id)) return NULL; return $this->dbc->getOne( "SELECT gunid FROM {$this->filesTable} WHERE id='$id'" ); } } ?>