- made UploadImage finally working

- integrated with egroupware using appsession vars
- added max sizes when uploading
- added this CHANGELOG
- added the README for developer instructions
- checked copyrights
- changed icon
This commit is contained in:
Pim Snel 2004-09-20 20:40:50 +00:00
parent 7a28a6bcd0
commit 80cd655e2c
10 changed files with 872 additions and 694 deletions

View File

@ -0,0 +1,9 @@
Mon Sep 20 22:23:52 CEST 2004
-----------------------------
- made UploadImage finally working
- integrated with egroupware using appsession vars
- added max sizes when uploading
- added this CHANGELOG
- added the README for developer instructions
- checked copyrights
- changed icon

View File

@ -0,0 +1,48 @@
UploadImage for HtmlArea in eGroupWare
-----------------------------------------------------------
Original Author: Xiang Wei ZHUO <wei@zhuo.org>
Author for eGW: Pim Snel <pim@lingewoud.nl>
Last Updated: Mon Sep 20 19:55:03 CEST 2004
Requirements: eGroupWare 1.x, htmlArea 3rc or higher
Note: UploadImage only works as plugin for htmlArea in eGroupWare.
-----------------------------------------------------------
UploadImage adds an image_upload-icon in the htmlArea-toolbar. When the icon is clicked
the user can Select an image from the Upload Directory or upload an Image to the directory
the upload directory eGW-developer has specified. After insertion the image is shown in the
htmlarea. Future features will be: resizing images, cropping images, rotating images etc ....
To use the plugin you have to do the following:
// thirst setup the sessionvariables UploadImage Need
$sessdata = array(
'UploadImageBaseDir' => /path/to/eg/egw/images , // absolute path to the base directory
'UploadImageBaseURL' => http://yourhost/egw/images, // the complete URL to the base images directory
'UploadImageMaxWidth' => 500, // max, image width in pixels
'UploadImageMaxHeight' => 500 // max. image height in pixels
);
$GLOBALS['phpgw']->session->appsession('UploadImage','phpgwapi',$sessdata);
// then init the html class and call the htmlarea class-method with the UploadPlugin as argument
if (!is_object($GLOBALS['phpgw']->html))
{
$GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
}
$htmlarea = $GLOBALS['phpgw']->html->htmlarea($field_name, $value,$style,false,'UploadImage',$custom_toolbar);
-----------------------------------------------------------
SECURITY WARNING!!!
-----------------------------------------------------------
When you are implementing the UploadImage plugin make sure
your UploadImageBaseDir is set correctly because else it
might give access to other directories apache has access to.
-----------------------------------------------------------
Known issues:
- Create directory doesn't work
- In some cases the OK and cancel buttons won't work anymore (javascript issue)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

After

Width:  |  Height:  |  Size: 181 B

View File

@ -1,64 +1,87 @@
<? <?php
/**************************************************************************\
* eGroupWare - UploadImage-plugin for htmlArea *
* http://www.eGroupWare.org *
* Written and (c) by Xiang Wei ZHUO <wei@zhuo.org> *
* Modified for eGW by and (c) by Pim Snel <pim@lingewoud.nl> *
* -------------------------------------------- *
* This program 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; version 2 of the License. *
\**************************************************************************/
//************************** BEGIN CONFIGURATION *****************************// /* $id$ */
//example, this is the actual file system path // FIXME: remove imageMagick shit, we only use gdlib
//of the web server document root. e.g. // FIXME: autodetect safe_mode
// Filesystem == /home/web/www.yourdomain.com // FIXME set current app to the calling app
$BASE_DIR = $GLOBALS[UploadImageBaseDir]; // FIXME include header nicer
$BASE_URL = $GLOBALS[UploadImageBaseURL];
$BASE_ROOT = $GLOBALS[UploadImageRelativePath];
var_dump($BASE_DIR); $phpgw_flags = Array(
var_dump($BASE_URL); 'currentapp' => 'jinn',
var_dump($BASE_ROOT); 'noheader' => True,
'nonavbar' => True,
'noappheader' => True,
'noappfooter' => True,
'nofooter' => True
);
//$BASE_DIR = $_SERVER['DOCUMENT_ROOT']; $GLOBALS['phpgw_info']['flags'] = $phpgw_flags;
//$BASE_DIR = '/home/www';
//the path where the browser sees the document root (i.e. http://www.yourdomain.com/) if(@include('../../../../../../header.inc.php'))
//$BASE_URL = 'https://192.168.0.2/'; {
// I know this is very ugly
}
else
{
@include('../../../../../../../header.inc.php');
}
//this is where the images will be stored relative to the $BASE_DIR (and $BASE_URL) define('IMAGE_CLASS', 'GD');
//this directory MUST be readable AND writable by the web server.
//$BASE_ROOT = '';
//The image manipulation library to use, either GD or ImageMagick or NetPBM //In safe mode, directory creation is not permitted.
//valid definitions are 'GD' or 'IM' or 'NetPBM'. $SAFE_MODE = false;
define('IMAGE_CLASS', 'GD'); //
//After defining which library to use, if it is NetPBM or IM, you need to $sessdata = $GLOBALS['phpgw']->session->appsession('UploadImage','phpgwapi');
//specify where the binary for the selected library are. And of course
//your server and PHP must be able to execute them (i.e. safe mode is OFF). $BASE_DIR = $sessdata[UploadImageBaseDir];
//If you have safe mode ON, or don't have the binaries, your choice is $BASE_URL = $sessdata[UploadImageBaseURL];
//GD only. GD does not require the following definition. $MAX_HEIGHT = $sessdata[UploadImageMaxHeight];
define('IMAGE_TRANSFORM_LIB_PATH', '/usr/bin/netpbm/'); $MAX_WIDTH = $sessdata[UploadImageMaxWidth];
//define('IMAGE_TRANSFORM_LIB_PATH', '"D:\\Program Files\\ImageMagick\\');
if(!$MAX_HEIGHT) $MAX_HEIGHT = 10000;
if(!$MAX_WIDTH) $MAX_WIDTH = 10000;
// _debug_array($sessdata);
//die();
//In safe mode, directory creation is not permitted. //After defining which library to use, if it is NetPBM or IM, you need to
$SAFE_MODE = false; //specify where the binary for the selected library are. And of course
//your server and PHP must be able to execute them (i.e. safe mode is OFF).
//If you have safe mode ON, or don't have the binaries, your choice is
//GD only. GD does not require the following definition.
//define('IMAGE_TRANSFORM_LIB_PATH', '/usr/bin/netpbm/');
//define('IMAGE_TRANSFORM_LIB_PATH', '"D:\\Program Files\\ImageMagick\\');
//************************** END CONFIGURATION *****************************// $BASE_ROOT = '';
$IMG_ROOT = $BASE_ROOT;
$IMG_ROOT = $BASE_ROOT; if(strrpos($BASE_DIR, '/')!= strlen($BASE_DIR)-1)
$BASE_DIR .= '/';
if(strrpos($BASE_DIR, '/')!= strlen($BASE_DIR)-1) if(strrpos($BASE_URL, '/')!= strlen($BASE_URL)-1)
$BASE_DIR .= '/'; $BASE_URL .= '/';
if(strrpos($BASE_URL, '/')!= strlen($BASE_URL)-1) //Built in function of dirname is faulty
$BASE_URL .= '/'; //It assumes that the directory nane can not contain a . (period)
function dir_name($dir)
//Built in function of dirname is faulty {
//It assumes that the directory nane can not contain a . (period) $lastSlash = intval(strrpos($dir, '/'));
function dir_name($dir) if($lastSlash == strlen($dir)-1){
{ return substr($dir, 0, $lastSlash);
$lastSlash = intval(strrpos($dir, '/')); }
if($lastSlash == strlen($dir)-1){ else
return substr($dir, 0, $lastSlash); return dirname($dir);
} }
else
return dirname($dir);
}
?> ?>

View File

@ -0,0 +1,25 @@
<?php
/**************************************************************************\
* eGroupWare - UploadImage-plugin for htmlArea *
* http://www.eGroupWare.org *
* Written and (c) by Xiang Wei ZHUO <wei@zhuo.org> *
* Modified for eGW by and (c) by Pim Snel <pim@lingewoud.nl> *
* -------------------------------------------- *
* This program 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; version 2 of the License. *
\**************************************************************************/
function percent($p, $w)
{
return (real)(100 * ($p / $w));
}
function unpercent($percent, $whole)
{
return (real)(($percent * $whole) / 100);
}
?>

View File

@ -1,91 +1,87 @@
<?php <?php
/*********************************************************************** /**************************************************************************\
** Title.........: Thumbnail generator, with cache. * eGroupWare - UploadImage-plugin for htmlArea *
** Version.......: 1.0 * http://www.eGroupWare.org *
** Author........: Xiang Wei ZHUO <wei@zhuo.org> * Written and (c) by Xiang Wei ZHUO <wei@zhuo.org> *
** Filename......: thumbs.php * Modified for eGW by and (c) by Pim Snel <pim@lingewoud.nl> *
** Last changed..: 1 Mar 2003 * -------------------------------------------- *
** Notes.........: Configuration in config.inc.php * This program 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; version 2 of the License. *
* -------------------------------------------- *
* Title.........: Thumbnail generator, with cache. *
* Version.......: 1.01 *
* Author........: Xiang Wei ZHUO <wei@zhuo.org> *
* Notes.........: Configuration in config.inc.php *
* *
* Functions *
* - if the thumbnail does not exists or the source file is newer, create a *
* new thumbnail. *
\**************************************************************************/
- if the thumbnail does not exists or the source /* $id */
file is newer, create a new thumbnail.
***********************************************************************/ require_once 'config.inc.php';
require_once 'std_functions.inc.php';
require_once '../ImageEditor/Transform.php';
$img = $BASE_DIR.urldecode($_GET['img']);
include 'config.inc.php'; if(is_file($img)) {
require_once '../ImageEditor/Transform.php'; make_thumbs(urldecode($_GET['img']));
}
$img = $BASE_DIR.urldecode($_GET['img']); function make_thumbs($img)
{
global $BASE_DIR, $BASE_URL;
if(is_file($img)) { $path_info = pathinfo($img);
make_thumbs(urldecode($_GET['img'])); $path = $path_info['dirname']."/";
} $img_file = $path_info['basename'];
$thumb = $path.'.'.$img_file;
function make_thumbs($img) $img_info = getimagesize($BASE_DIR.$path.$img_file);
{ $w = $img_info[0]; $h = $img_info[1];
global $BASE_DIR, $BASE_URL;
$nw = 96; $nh = 96;
$path_info = pathinfo($img); if($w <= $nw && $h <= $nh) {
$path = $path_info['dirname']."/"; header('Location: '.$BASE_URL.$path.$img_file);
$img_file = $path_info['basename']; exit();
}
$thumb = $path.'.'.$img_file; if(is_file($BASE_DIR.$thumb)) {
$img_info = getimagesize($BASE_DIR.$path.$img_file); $t_mtime = filemtime($BASE_DIR.$thumb);
$w = $img_info[0]; $h = $img_info[1]; $o_mtime = filemtime($BASE_DIR.$img);
$nw = 96; $nh = 96;
if($w <= $nw && $h <= $nh) { if($t_mtime > $o_mtime) {
header('Location: '.$BASE_URL.$path.$img_file);
exit();
}
if(is_file($BASE_DIR.$thumb)) {
$t_mtime = filemtime($BASE_DIR.$thumb);
$o_mtime = filemtime($BASE_DIR.$img);
if($t_mtime > $o_mtime) {
//echo $BASE_URL.$path.'.'.$img_file; //echo $BASE_URL.$path.'.'.$img_file;
header('Location: '.$BASE_URL.$path.'.'.$img_file); header('Location: '.$BASE_URL.$path.'.'.$img_file);
exit(); exit();
} }
} }
$img_thumbs = Image_Transform::factory(IMAGE_CLASS); $img_thumbs = Image_Transform::factory(IMAGE_CLASS);
$img_thumbs->load($BASE_DIR.$path.$img_file); $img_thumbs->load($BASE_DIR.$path.$img_file);
if ($w > $h)
$nh = unpercent(percent($nw, $w), $h);
else if ($h > $w)
$nw = unpercent(percent($nh, $h), $w);
if ($w > $h) $img_thumbs->resize($nw, $nh);
$nh = unpercent(percent($nw, $w), $h);
else if ($h > $w)
$nw = unpercent(percent($nh, $h), $w);
$img_thumbs->resize($nw, $nh); $img_thumbs->save($BASE_DIR.$thumb);
$img_thumbs->free();
$img_thumbs->save($BASE_DIR.$thumb); chmod($BASE_DIR.$thumb, 0666);
$img_thumbs->free();
chmod($BASE_DIR.$thumb, 0666); if(is_file($BASE_DIR.$thumb)) {
header('Location: '.$BASE_URL.$path.'.'.$img_file);
exit();
}
}
if(is_file($BASE_DIR.$thumb)) { ?>
//echo "Made:".$BASE_URL.$path.'.'.$img_file;
header('Location: '.$BASE_URL.$path.'.'.$img_file);
exit();
}
}
function percent($p, $w)
{
return (real)(100 * ($p / $w));
}
function unpercent($percent, $whole)
{
return (real)(($percent * $whole) / 100);
}
?>

View File

@ -7,15 +7,49 @@
** Last changed..: 8 Mar 2003 ** Last changed..: 8 Mar 2003
** Notes.........: Configuration in config.inc.php ** Notes.........: Configuration in config.inc.php
- Only compatible with IE 5.5+ - FIXME Only compatible with IE 5.5+
***********************************************************************/ ***********************************************************************/
/* $id */
include 'ImageManager/config.inc.php'; include 'ImageManager/config.inc.php';
$no_dir = false; $no_dir = false;
if(!is_dir($BASE_DIR.$BASE_ROOT)) { if(!is_dir($BASE_DIR)) {
$no_dir = true; $no_dir = true;
} }
// _debug_array($_GET);
// die();
function dirs($dir,$abs_path)
{
$d = dir($dir);
$dirs = array();
while (false !== ($entry = $d->read()))
{
if(is_dir($dir.'/'.$entry) && substr($entry,0,1) != '.')
{
$path['path'] = $dir.'/'.$entry;
$path['name'] = $entry;
$dirs[$entry] = $path;
}
}
$d->close();
ksort($dirs);
for($i=0; $i<count($dirs); $i++)
{
$name = key($dirs);
$current_dir = $abs_path.'/'.$dirs[$name]['name'];
echo "<option value=\"$current_dir\">$current_dir</option>\n";
dirs($dirs[$name]['path'],$current_dir);
next($dirs);
}
}
?> ?>
<html style="width: 580; height: 440;"> <html style="width: 580; height: 440;">
<head> <head>
@ -326,38 +360,12 @@ function toggleConstrains(constrains)
<td> <td>
<select name="dirPath" id="dirPath" style="width:30em" onChange="updateDir(this)"> <select name="dirPath" id="dirPath" style="width:30em" onChange="updateDir(this)">
<option value="/">/</option> <option value="/">/</option>
<? <?php
if($no_dir == false)
function dirs($dir,$abs_path)
{
$d = dir($dir);
$dirs = array();
while (false !== ($entry = $d->read())) {
if(is_dir($dir.'/'.$entry) && substr($entry,0,1) != '.')
{
$path['path'] = $dir.'/'.$entry;
$path['name'] = $entry;
$dirs[$entry] = $path;
}
}
$d->close();
ksort($dirs);
for($i=0; $i<count($dirs); $i++)
{ {
$name = key($dirs); dirs($BASE_DIR,'');
$current_dir = $abs_path.'/'.$dirs[$name]['name'];
echo "<option value=\"$current_dir\">$current_dir</option>\n";
dirs($dirs[$name]['path'],$current_dir);
next($dirs);
} }
} ?>
if($no_dir == false) {
dirs($BASE_DIR.$BASE_ROOT,'');
}
?>
</select> </select>
</td> </td>
<td class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <td class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')">

View File

@ -1,16 +1,18 @@
// UploadImage Plugin for HTMLArea-3.0 /**************************************************************************\
// Implementation by Mihai Bazon. Sponsored by http://thycotic.com * eGroupWare - UploadImage-plugin for htmlArea in eGroupWare *
// * http://www.eGroupWare.org *
// htmlArea v3.0 - Copyright (c) 2002 interactivetools.com, inc. * Written and (c) by Xiang Wei ZHUO <wei@zhuo.org> *
// This notice MUST stay intact for use (see license.txt). * Used code fragments from plugins by Mihai Bazon *
// * Modified for eGW by and (c) by Pim Snel <pim@lingewoud.nl> *
// A free WYSIWYG editor replacement for <textarea> fields. * -------------------------------------------- *
// For full source code and docs, visit http://www.interactivetools.com/ * This program is free software; you can redistribute it and/or modify it *
// * under the terms of the GNU General Public License as published by the *
// Version 3.0 developed by Mihai Bazon for InteractiveTools. * Free Software Foundation; version 2 of the License. *
// http://dynarch.com/mishoo \**************************************************************************/
//
// $Id$ // $id$
// FIXME: clean up code
function UploadImage(editor) { function UploadImage(editor) {
this.editor = editor; this.editor = editor;
@ -36,12 +38,12 @@ function UploadImage(editor) {
}; };
UploadImage._pluginInfo = { UploadImage._pluginInfo = {
name : "UploadImage", name : "UploadImage for eGroupWare",
version : "1.0", version : "1.0",
developer : "Pim Snel", developer : "Pim Snel",
developer_url : "http://lingewoud.com", developer_url : "http://lingewoud.com",
c_owner : "Mihai Bazon", c_owner : "Pim Snel, Xiang Wei ZHUO, Mihai Bazon",
sponsor : "Lingewoud b.v. - Netherlands", sponsor : "Lingewoud bv., Netherlands",
sponsor_url : "http://lingewoud.com", sponsor_url : "http://lingewoud.com",
license : "GPL" license : "GPL"
}; };