use new vfs end egw_link class

This commit is contained in:
Ralf Becker 2008-04-20 19:37:12 +00:00
parent a5b58e57e8
commit b484528188
5 changed files with 108 additions and 187 deletions

View File

@ -1,4 +0,0 @@
pictures are stored in vfs.
Thus eTemplate can't read pictures from vfs yet, u need to create a symlink into your resources directory!
ln -s {outside-doc-root-path}/resources/pictures {egroupware-base-dir}/resources

View File

@ -35,10 +35,6 @@ class bo_resources
$this->so =& CreateObject('resources.so_resources'); $this->so =& CreateObject('resources.so_resources');
$this->acl =& CreateObject('resources.bo_acl'); $this->acl =& CreateObject('resources.bo_acl');
$this->cats = $this->acl->egw_cats; $this->cats = $this->acl->egw_cats;
$this->vfs =& CreateObject('phpgwapi.vfs');
$this->link =& CreateObject('phpgwapi.bolink');
$this->conf =& CreateObject('phpgwapi.config');
$this->conf->read_repository();
$this->cal_right_transform = array( $this->cal_right_transform = array(
EGW_ACL_CALREAD => EGW_ACL_READ, EGW_ACL_CALREAD => EGW_ACL_READ,
@ -117,7 +113,7 @@ class bo_resources
$readonlys["buyable[$resource[res_id]]"] = true; $readonlys["buyable[$resource[res_id]]"] = true;
} }
$readonlys["view_acc[$resource[res_id]]"] = true; $readonlys["view_acc[$resource[res_id]]"] = true;
$links = $this->link->get_links('resources',$resource['res_id']); $links = egw_link::get_links('resources',$resource['res_id']);
if(count($links) != 0 && $accessory_of == -1) if(count($links) != 0 && $accessory_of == -1)
{ {
foreach ($links as $link_num => $link) foreach ($links as $link_num => $link)
@ -178,13 +174,12 @@ class bo_resources
switch ($resource['picture_src']) switch ($resource['picture_src'])
{ {
case 'own_src': case 'own_src':
$vfs_data = array('string' => $this->pictures_dir.$resource['res_id'].'.jpg','relatives' => array(RELATIVE_ROOT));
if($resource['own_file']['size'] > 0) if($resource['own_file']['size'] > 0)
{ {
$msg = $this->save_picture($resource['own_file'],$resource['res_id']); $msg = $this->save_picture($resource['own_file'],$resource['res_id']);
break; break;
} }
elseif($this->vfs->file_exists($vfs_data)) elseif(@egw_vfs::stat($this->pictures_dir.$resource['res_id'].'.jpg'))
{ {
break; break;
} }
@ -220,11 +215,11 @@ class bo_resources
// save links // save links
if(is_array($resource['link_to']['to_id'])) if(is_array($resource['link_to']['to_id']))
{ {
$this->link->link('resources',$resource['res_id'],$resource['link_to']['to_id']); egw_link::link('resources',$resource['res_id'],$resource['link_to']['to_id']);
} }
if($resource['accessory_of'] != -1) if($resource['accessory_of'] != -1)
{ {
$this->link->link('resources',$resource['res_id'],'resources',$resource['accessory_of']); egw_link::link('resources',$resource['res_id'],'resources',$resource['accessory_of']);
} }
if(!empty($resource['res_id']) && $this->so->get_value("cat_id",$resource['res_id']) != $resource['cat_id'] && $resource['accessory_of'] == -1) if(!empty($resource['res_id']) && $this->so->get_value("cat_id",$resource['res_id']) != $resource['cat_id'] && $resource['accessory_of'] == -1)
@ -258,7 +253,7 @@ class bo_resources
if ($this->so->delete(array('res_id'=>$res_id))) if ($this->so->delete(array('res_id'=>$res_id)))
{ {
$this->remove_picture($res_id); $this->remove_picture($res_id);
$this->link->unlink(0,'resources',$res_id); egw_link::unlink(0,'resources',$res_id);
// delete the resource from the calendar // delete the resource from the calendar
ExecMethod('calendar.socal.change_delete_user','r'.$res_id); ExecMethod('calendar.socal.change_delete_user','r'.$res_id);
return false; return false;
@ -375,18 +370,13 @@ class bo_resources
function save_picture($file,$resouce_id) function save_picture($file,$resouce_id)
{ {
// test upload dir // test upload dir
$vfs_data = array('string'=>$this->vfs_basedir,'relatives'=>array(RELATIVE_ROOT)); if (!is_dir(egw_vfs::PREFIX.$this->vfs_basedir))
if (!($this->vfs->file_exists($vfs_data)))
{ {
$this->vfs->override_acl = 1; egw_vfs::$is_root = true;
$this->vfs->mkdir($vfs_data); egw_vfs::mkdir($this->pictures_dir,0777,STREAM_MKDIR_RECURSIVE);
$vfs_data['string'] = $this->pictures_dir; egw_vfs::mkdir($this->thumbs_dir,0777,STREAM_MKDIR_RECURSIVE);
$this->vfs->mkdir($vfs_data); egw_vfs::$is_root = false;
$vfs_data['string'] = $this->thumbs_dir;
$this->vfs->mkdir($vfs_data);
$this->vfs->override_acl = 0;
} }
switch($file['type']) switch($file['type'])
{ {
case 'image/gif': case 'image/gif':
@ -437,35 +427,10 @@ class bo_resources
} }
imagedestroy($src_img); imagedestroy($src_img);
$this->vfs->override_acl = 1; egw_vfs::$is_root = true;
$this->vfs->cp(array( copy($tmp_dir.$resouce_id.'.jpg',egw_vfs::PREFIX.$this->pictures_dir.$resouce_id.'.jpg');
'from' => $tmp_dir.$resouce_id.'.jpg', copy($tmp_dir.$resouce_id.'.thumb.jpg',egw_vfs::PREFIX.$this->thumbs_dir.$resouce_id.'.jpg');
'to' => $this->pictures_dir.$resouce_id.'.jpg', egw_vfs::$is_root = false;
'relatives' => array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)
));
$this->vfs->set_attributes(array(
'string' => $this->pictures_dir.$resouce_id.'.jpg',
'relatives' => array (RELATIVE_ROOT),
'attributes' => array (
'mime_type' => 'image/jpeg',
'comment' => 'picture of resource no.'.$resouce_id,
'app' => $GLOBALS['egw_info']['flags']['currentapp']
)));
$this->vfs->cp(array(
'from' => $tmp_dir.$resouce_id.'.thumb.jpg',
'to' => $this->thumbs_dir.$resouce_id.'.jpg',
'relatives' => array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)
));
$this->vfs->set_attributes(array(
'string' => $this->thumbs_dir.$resouce_id.'.jpg',
'relatives' => array (RELATIVE_ROOT),
'attributes' => array (
'mime_type' => 'image/jpeg',
'comment' => 'thumbnail of resource no.'.$resouce_id,
'app' => $GLOBALS['egw_info']['flags']['currentapp']
)));
$this->vfs->override_acl = 0;
return;
} }
/** /**
@ -484,8 +449,7 @@ class bo_resources
switch($src) switch($src)
{ {
case 'own_src': case 'own_src':
$picture = $this->conf->config_data['dont_use_vfs'] ? $GLOBALS['egw_info']['server']['webserver_url'] : 'vfs:'; $picture = egw::link(egw_vfs::download_url($size ? $this->pictures_dir.$res_id.'.jpg' : $this->thumbs_dir.$res_id.'.jpg'));
$picture .= $size ? $this->pictures_dir.$res_id.'.jpg' : $this->thumbs_dir.$res_id.'.jpg';
break; break;
case 'cat_src': case 'cat_src':
list($picture) = $this->cats->return_single($this->so->get_value('cat_id',$res_id)); list($picture) = $this->cats->return_single($this->so->get_value('cat_id',$res_id));
@ -513,15 +477,10 @@ class bo_resources
*/ */
function remove_picture($res_id) function remove_picture($res_id)
{ {
$vfs_data = array('string' => $this->pictures_dir.$res_id.'.jpg','relatives' => array(RELATIVE_ROOT)); egw_vfs::$is_root = true;
$this->vfs->override_acl = 1; egw_vfs::unlink($this->pictures_dir.$res_id.'.jpg');
if($this->vfs->file_exists($vfs_data)) egw_vfs::unlink($this->thumbs_dir.$res_id.'.jpg');
{ egw_vfs::$is_root = false;
$this->vfs->rm($vfs_data);
$vfs_data['string'] = $this->thumbs_dir.$res_id.'.jpg';
$this->vfs->rm($vfs_data);
}
$this->vfs->override_acl = 0;
} }
/** /**

View File

@ -73,8 +73,6 @@ class resources_hooks
if ($GLOBALS['egw_info']['user']['apps']['admin'] && $location != 'preferences') if ($GLOBALS['egw_info']['user']['apps']['admin'] && $location != 'preferences')
{ {
$file = Array( $file = Array(
'Site configuration' => $GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'resources.ui_resources.admin' )),
'Global Categories' => $GLOBALS['egw']->link('/index.php',array( 'Global Categories' => $GLOBALS['egw']->link('/index.php',array(
'menuaction' => 'admin.uicategories.index', 'menuaction' => 'admin.uicategories.index',
'appname' => $appname, 'appname' => $appname,
@ -83,7 +81,6 @@ class resources_hooks
'menuaction=resources.ui_acl.acllist'), 'menuaction=resources.ui_acl.acllist'),
'Custom Fields'=>$GLOBALS['egw']->link('/index.php', 'Custom Fields'=>$GLOBALS['egw']->link('/index.php',
'menuaction=admin.customfields.edit&appname=resources'), 'menuaction=admin.customfields.edit&appname=resources'),
// 'CSV-Import' => $GLOBALS['egw']->link('/infolog/csv_import.php')
); );
if ($location == 'admin') if ($location == 'admin')
{ {
@ -132,5 +129,3 @@ class resources_hooks
); );
} }
} }
?>

View File

@ -22,7 +22,6 @@ class ui_resources
'edit' => True, 'edit' => True,
'show' => True, 'show' => True,
'select' => True, 'select' => True,
'admin' => True,
'writeLangFile' => True 'writeLangFile' => True
); );
@ -248,30 +247,6 @@ class ui_resources
} }
/**
* adminsection of resources
*
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
*/
function admin($content='')
{
if(is_array($content))
{
if(isset($content['save']))
{
$this->bo->conf->read_repository();
$this->bo->conf->save_value('dont_use_vfs',$content['dont_use_vfs']);
}
else
{
return $GLOBALS['egw']->redirect_link('/admin/index.php');
}
}
$content = $this->bo->conf->read_repository();
$this->tmpl->read('resources.admin');
$this->tmpl->exec('resources.ui_resources.admin',$content,$sel_options,$no_button,$preserv);
}
/** /**
* showes a single resource * showes a single resource
* *

View File

@ -43,7 +43,3 @@
'appname' => 'etemplate', 'appname' => 'etemplate',
'versions' => Array('1.3','1.4','1.5') 'versions' => Array('1.3','1.4','1.5')
); );
$setup_info['resources']['depends'][] = array( // cause of vfs psuedoprotocol is not fully in the api yet
'appname' => 'filemanager',
'versions' => Array('1.3','1.4','1.5')
);