sintonia/livesupport/modules/storageServer/var/GreenBox.php

331 lines
10 KiB
PHP

<?php
/*------------------------------------------------------------------------------
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: tomas $
Version : $Revision: 1.23 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
------------------------------------------------------------------------------*/
require_once "BasicStor.php";
/**
* GreenBox class
*
* LiveSupport file storage module
*
* @author $Author: tomas $
* @version $Revision: 1.23 $
* @see BasicStor
*/
class GreenBox extends BasicStor{
/* ======================================================= public methods */
/**
* Create new folder
*
* @param parid int, parent id
* @param folderName string, name for new folder
* @param sessid string, session id
* @return id of new folder
* @exception PEAR::error
*/
function createFolder($parid, $folderName, $sessid='')
{
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
return $res;
return $this->bsCreateFolder($parid, $folderName);
}
/**
* 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
* @param ftype string, internal file type
* @return int
* @exception PEAR::error
*/
function putFile($parid, $fileName,
$mediaFileLP, $mdataFileLP, $sessid='',
$gunid=NULL, $ftype='audioclip')
{
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
return $res;
return $this->bsPutFile(
$parid, $fileName, $mediaFileLP, $mdataFileLP, $gunid, $ftype
);
}
/**
* 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);
}
/* ---------------------------------------------- replicas, versions etc. */
/**
* Create replica.<br>
* <b>TODO: NOT FINISHED</b>
*
* @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.<br>
* <b>TODO: NOT FINISHED</b>
*
* @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 */
/**
* 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 sessid string, session id
* @return boolean or PEAR::error
*/
function replaceMetadata($id, $mdata, $mdataLoc='file', $sessid='')
{
if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE)
return $res;
return $this->bsReplaceMetadata($id, $mdata, $mdataLoc);
}
/**
* 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->bsGetMetadata($id);
}
/**
* Search in local metadata database.
*
* @param criteria hash, with following structure:<br>
* <ul>
* <li>filetype - string, type of searched files,
* meaningful values: 'audioclip', 'playlist'</li>
* <li>operator - string, type of conditions join
* (any condition matches / all conditions match),
* meaningful values: 'and', 'or', ''
* (may be empty or ommited only with less then 2 items in
* &quot;conditions&quot; field)
* </li>
* <li>conditions - array of hashes with structure:
* <ul>
* <li>cat - string, metadata category name</li>
* <li>op - string, operator - meaningful values:
* 'full', 'partial', 'prefix', '=', '&lt;',
* '&lt;=', '&gt;', '&gt;='</li>
* <li>val - string, search value</li>
* </ul>
* </li>
* </ul>
* @param sessid string, session id
* @return hash, field 'results' is an array with gunid strings
* of files have been found
* @see BasicStor::bsLocalSearch
*/
function localSearch($criteria, $sessid='')
{
return $this->bsLocalSearch($criteria);
}
/* --------------------------------------------------------- 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;
$listArr = $this->bsListFolder($id);
return $listArr;
}
/* ---------------------------------------------------- redefined methods */
/**
* 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->bsCreateFolder($this->storId, $login);
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->bsDeleteFile($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 */
}
?>