mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 00:29:38 +01:00
Store pictures now like file attachments with name .picture.jpg
(they are suppressed from being displayed as regular attachment). Thumbnails are handled via etemplates thumbnail facility.
This commit is contained in:
parent
868c532beb
commit
b7d41043ac
@ -18,9 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
class bo_resources
|
class bo_resources
|
||||||
{
|
{
|
||||||
var $vfs_basedir = '/resources/';
|
const PICTURE_NAME = '.picture.jpg';
|
||||||
var $pictures_dir = '/resources/pictures/';
|
|
||||||
var $thumbs_dir = '/resources/pictures/thumbs/';
|
|
||||||
var $resource_icons = '/resources/templates/default/images/resource_icons/';
|
var $resource_icons = '/resources/templates/default/images/resource_icons/';
|
||||||
var $debug = 0;
|
var $debug = 0;
|
||||||
/**
|
/**
|
||||||
@ -382,7 +380,7 @@ class bo_resources
|
|||||||
|
|
||||||
// search events matching our timestamps
|
// search events matching our timestamps
|
||||||
$resource_list=array();
|
$resource_list=array();
|
||||||
foreach($data as $num => $resource)
|
foreach($data as $num => $resource)
|
||||||
{
|
{
|
||||||
// we only need resources id for the search, but with a 'r' prefix
|
// we only need resources id for the search, but with a 'r' prefix
|
||||||
// now we take this loop to store a new resource array indexed with resource id
|
// now we take this loop to store a new resource array indexed with resource id
|
||||||
@ -410,7 +408,7 @@ class bo_resources
|
|||||||
// now we are interested only on resources booked by theses events
|
// now we are interested only on resources booked by theses events
|
||||||
if (isset($event['participants']) && is_array($event['participants'])){
|
if (isset($event['participants']) && is_array($event['participants'])){
|
||||||
foreach($event['participants'] as $part_key => $part_detail){
|
foreach($event['participants'] as $part_key => $part_detail){
|
||||||
if ($part_key{0}=='r')
|
if ($part_key{0}=='r')
|
||||||
{ //now we gatta resource here
|
{ //now we gatta resource here
|
||||||
//need to check the quantity of this resource
|
//need to check the quantity of this resource
|
||||||
$resource_id=substr($part_key,1);
|
$resource_id=substr($part_key,1);
|
||||||
@ -439,7 +437,7 @@ class bo_resources
|
|||||||
foreach($res_info_cache as $id => $resource) {
|
foreach($res_info_cache as $id => $resource) {
|
||||||
//maybe this resource is reserved
|
//maybe this resource is reserved
|
||||||
if ( ($resource['useable'] < 1) )
|
if ( ($resource['useable'] < 1) )
|
||||||
{
|
{
|
||||||
if($show_conflict) {
|
if($show_conflict) {
|
||||||
$list[$id] = ' ('.lang('conflict').') '.$resource['name']. ($resource['short_description'] ? ', ['.$resource['short_description'].']':'');
|
$list[$id] = ' ('.lang('conflict').') '.$resource['name']. ($resource['short_description'] ? ', ['.$resource['short_description'].']':'');
|
||||||
}
|
}
|
||||||
@ -481,18 +479,9 @@ class bo_resources
|
|||||||
* @param array $file array with key => value
|
* @param array $file array with key => value
|
||||||
* @param int $resource_id
|
* @param int $resource_id
|
||||||
* @return mixed string with msg if somthing went wrong; nothing if all right
|
* @return mixed string with msg if somthing went wrong; nothing if all right
|
||||||
* TODO make thumb an picture sizes choosable by preferences
|
|
||||||
*/
|
*/
|
||||||
function save_picture($file,$resouce_id)
|
function save_picture($file,$resouce_id)
|
||||||
{
|
{
|
||||||
// test upload dir
|
|
||||||
if (!is_dir(egw_vfs::PREFIX.$this->vfs_basedir))
|
|
||||||
{
|
|
||||||
egw_vfs::$is_root = true;
|
|
||||||
egw_vfs::mkdir($this->pictures_dir,0777,STREAM_MKDIR_RECURSIVE);
|
|
||||||
egw_vfs::mkdir($this->thumbs_dir,0777,STREAM_MKDIR_RECURSIVE);
|
|
||||||
egw_vfs::$is_root = false;
|
|
||||||
}
|
|
||||||
switch($file['type'])
|
switch($file['type'])
|
||||||
{
|
{
|
||||||
case 'image/gif':
|
case 'image/gif':
|
||||||
@ -512,51 +501,38 @@ class bo_resources
|
|||||||
|
|
||||||
$src_img_size = getimagesize($file['tmp_name']);
|
$src_img_size = getimagesize($file['tmp_name']);
|
||||||
$dst_img_size = array( 0 => 320, 1 => 240);
|
$dst_img_size = array( 0 => 320, 1 => 240);
|
||||||
$thumb_size = array( 0 => 64, 1 => 48);
|
|
||||||
|
|
||||||
$tmp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
|
$tmp_name = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'resources-picture');
|
||||||
if($src_img_size[0] > 64 || $src_img_size[1] > 48)
|
if($src_img_size[0] > $dst_img_size[0] || $src_img_size[1] > $dst_img_size[1])
|
||||||
{
|
{
|
||||||
$f = $thumb_size[0] / $src_img_size[0];
|
$f = $dst_img_size[0] / $src_img_size[0];
|
||||||
$f = $thumb_size[1] / $src_img_size[1] < $f ? $thumb_size[1] / $src_img_size[1] : $f;
|
$f = $dst_img_size[1] / $src_img_size[1] < $f ? $dst_img_size[1] / $src_img_size[1] : $f;
|
||||||
$dst_img = imagecreatetruecolor($src_img_size[0] * $f, $src_img_size[1] * $f);
|
$dst_img = imagecreatetruecolor($src_img_size[0] * $f, $src_img_size[1] * $f);
|
||||||
imagecopyresized($dst_img,$src_img,0,0,0,0,$src_img_size[0] * $f,$src_img_size[1] * $f,$src_img_size[0],$src_img_size[1]);
|
imagecopyresized($dst_img,$src_img,0,0,0,0,$src_img_size[0] * $f,$src_img_size[1] * $f,$src_img_size[0],$src_img_size[1]);
|
||||||
imagejpeg($dst_img,$tmp_dir.$resouce_id.'.thumb.jpg');
|
imagejpeg($dst_img,$tmp_name);
|
||||||
if($src_img_size[0] > $dst_img_size[0] || $src_img_size[1] > $dst_img_size[1])
|
|
||||||
{
|
|
||||||
$f = $dst_img_size[0] / $src_img_size[0];
|
|
||||||
$f = $dst_img_size[1] / $src_img_size[1] < $f ? $dst_img_size[1] / $src_img_size[1] : $f;
|
|
||||||
$dst_img = imagecreatetruecolor($src_img_size[0] * $f, $src_img_size[1] * $f);
|
|
||||||
imagecopyresized($dst_img,$src_img,0,0,0,0,$src_img_size[0] * $f,$src_img_size[1] * $f,$src_img_size[0],$src_img_size[1]);
|
|
||||||
imagejpeg($dst_img,$tmp_dir.$resouce_id.'.jpg');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
imagejpeg($src_img,$tmp_dir.$resouce_id.'.jpg');
|
|
||||||
}
|
|
||||||
imagedestroy($dst_img);
|
imagedestroy($dst_img);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imagejpeg($src_img,$tmp_dir.$resouce_id.'.jpg');
|
imagejpeg($src_img,$tmp_name);
|
||||||
imagejpeg($src_img,$tmp_dir.$resouce_id.'.thumb.jpg');
|
|
||||||
}
|
}
|
||||||
imagedestroy($src_img);
|
imagedestroy($src_img);
|
||||||
|
|
||||||
egw_vfs::$is_root = true;
|
egw_link::attach_file('resources',$resouce_id,array(
|
||||||
copy($tmp_dir.$resouce_id.'.jpg',egw_vfs::PREFIX.$this->pictures_dir.$resouce_id.'.jpg');
|
'tmp_name' => $tmp_name,
|
||||||
copy($tmp_dir.$resouce_id.'.thumb.jpg',egw_vfs::PREFIX.$this->thumbs_dir.$resouce_id.'.jpg');
|
'name' => self::PICTURE_NAME,
|
||||||
egw_vfs::$is_root = false;
|
'type' => 'image/jpeg',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get resource picture either from vfs or from symlink
|
* get resource picture either from vfs or from symlink
|
||||||
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
||||||
* @param int $res_id id of resource
|
* @param int $res_id id of resource
|
||||||
* @param bool $size false = thumb, true = full pic
|
* @param bool $fullsize false = thumb, true = full pic
|
||||||
* @return string url of picture
|
* @return string url of picture
|
||||||
*/
|
*/
|
||||||
function get_picture($res_id=0,$size=false)
|
function get_picture($res_id=0,$fullsize=false)
|
||||||
{
|
{
|
||||||
if ($res_id > 0)
|
if ($res_id > 0)
|
||||||
{
|
{
|
||||||
@ -565,7 +541,15 @@ class bo_resources
|
|||||||
switch($src)
|
switch($src)
|
||||||
{
|
{
|
||||||
case 'own_src':
|
case 'own_src':
|
||||||
$picture = egw::link(egw_vfs::download_url($size ? $this->pictures_dir.$res_id.'.jpg' : $this->thumbs_dir.$res_id.'.jpg'));
|
$picture = egw_link::vfs_path('resources',$res_id,self::PICTURE_NAME,true); // vfs path
|
||||||
|
if ($fullsize)
|
||||||
|
{
|
||||||
|
$picture = egw::link(egw_vfs::download_url($picture));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$picture = egw::link('/etemplate/thumbnail.php',array('path' => $picture));
|
||||||
|
}
|
||||||
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));
|
||||||
@ -593,10 +577,11 @@ class bo_resources
|
|||||||
*/
|
*/
|
||||||
function remove_picture($res_id)
|
function remove_picture($res_id)
|
||||||
{
|
{
|
||||||
egw_vfs::$is_root = true;
|
if (($arr = egw_link::delete_attached('resources',$res_id,self::PICTURE_NAME)))
|
||||||
egw_vfs::unlink($this->pictures_dir.$res_id.'.jpg');
|
{
|
||||||
egw_vfs::unlink($this->thumbs_dir.$res_id.'.jpg');
|
return array_shift($arr); // $arr = array($path => (bool)$ok);
|
||||||
egw_vfs::$is_root = false;
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,6 +109,7 @@ class resources_hooks
|
|||||||
'add_app' => 'link_app',
|
'add_app' => 'link_app',
|
||||||
'add_id' => 'link_id',
|
'add_id' => 'link_id',
|
||||||
'add_popup' => '800x600',
|
'add_popup' => '800x600',
|
||||||
|
'find_extra' => array('name_preg' => '/^(?!.picture.jpg)$/'), // remove pictures from regular attachment list
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user