- 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
//of the web server document root. e.g.
// Filesystem == /home/web/www.yourdomain.com
$BASE_DIR = $GLOBALS[UploadImageBaseDir];
$BASE_URL = $GLOBALS[UploadImageBaseURL];
$BASE_ROOT = $GLOBALS[UploadImageRelativePath];
// FIXME: remove imageMagick shit, we only use gdlib
// FIXME: autodetect safe_mode
// FIXME set current app to the calling app
// FIXME include header nicer
var_dump($BASE_DIR);
var_dump($BASE_URL);
var_dump($BASE_ROOT);
$phpgw_flags = Array(
'currentapp' => 'jinn',
'noheader' => True,
'nonavbar' => True,
'noappheader' => True,
'noappfooter' => True,
'nofooter' => True
);
//$BASE_DIR = $_SERVER['DOCUMENT_ROOT'];
//$BASE_DIR = '/home/www';
$GLOBALS['phpgw_info']['flags'] = $phpgw_flags;
//the path where the browser sees the document root (i.e. http://www.yourdomain.com/)
//$BASE_URL = 'https://192.168.0.2/';
if(@include('../../../../../../header.inc.php'))
{
// 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)
//this directory MUST be readable AND writable by the web server.
//$BASE_ROOT = '';
define('IMAGE_CLASS', 'GD');
//The image manipulation library to use, either GD or ImageMagick or NetPBM
//valid definitions are 'GD' or 'IM' or 'NetPBM'.
define('IMAGE_CLASS', 'GD'); //
//In safe mode, directory creation is not permitted.
$SAFE_MODE = false;
//After defining which library to use, if it is NetPBM or IM, you need to
//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\\');
$sessdata = $GLOBALS['phpgw']->session->appsession('UploadImage','phpgwapi');
$BASE_DIR = $sessdata[UploadImageBaseDir];
$BASE_URL = $sessdata[UploadImageBaseURL];
$MAX_HEIGHT = $sessdata[UploadImageMaxHeight];
$MAX_WIDTH = $sessdata[UploadImageMaxWidth];
if(!$MAX_HEIGHT) $MAX_HEIGHT = 10000;
if(!$MAX_WIDTH) $MAX_WIDTH = 10000;
// _debug_array($sessdata);
//die();
//In safe mode, directory creation is not permitted.
$SAFE_MODE = false;
//After defining which library to use, if it is NetPBM or IM, you need to
//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)
$BASE_DIR .= '/';
if(strrpos($BASE_URL, '/')!= strlen($BASE_URL)-1)
$BASE_URL .= '/';
if(strrpos($BASE_URL, '/')!= strlen($BASE_URL)-1)
$BASE_URL .= '/';
//Built in function of dirname is faulty
//It assumes that the directory nane can not contain a . (period)
function dir_name($dir)
{
$lastSlash = intval(strrpos($dir, '/'));
if($lastSlash == strlen($dir)-1){
return substr($dir, 0, $lastSlash);
}
else
return dirname($dir);
}
//Built in function of dirname is faulty
//It assumes that the directory nane can not contain a . (period)
function dir_name($dir)
{
$lastSlash = intval(strrpos($dir, '/'));
if($lastSlash == strlen($dir)-1){
return substr($dir, 0, $lastSlash);
}
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
/***********************************************************************
** Title.........: Thumbnail generator, with cache.
** Version.......: 1.0
** Author........: Xiang Wei ZHUO <wei@zhuo.org>
** Filename......: thumbs.php
** Last changed..: 1 Mar 2003
** Notes.........: Configuration in config.inc.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. *
* -------------------------------------------- *
* 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
file is newer, create a new thumbnail.
/* $id */
***********************************************************************/
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';
require_once '../ImageEditor/Transform.php';
if(is_file($img)) {
make_thumbs(urldecode($_GET['img']));
}
$img = $BASE_DIR.urldecode($_GET['img']);
function make_thumbs($img)
{
global $BASE_DIR, $BASE_URL;
if(is_file($img)) {
make_thumbs(urldecode($_GET['img']));
}
$path_info = pathinfo($img);
$path = $path_info['dirname']."/";
$img_file = $path_info['basename'];
$thumb = $path.'.'.$img_file;
function make_thumbs($img)
{
global $BASE_DIR, $BASE_URL;
$img_info = getimagesize($BASE_DIR.$path.$img_file);
$w = $img_info[0]; $h = $img_info[1];
$nw = 96; $nh = 96;
$path_info = pathinfo($img);
$path = $path_info['dirname']."/";
$img_file = $path_info['basename'];
if($w <= $nw && $h <= $nh) {
header('Location: '.$BASE_URL.$path.$img_file);
exit();
}
$thumb = $path.'.'.$img_file;
if(is_file($BASE_DIR.$thumb)) {
$img_info = getimagesize($BASE_DIR.$path.$img_file);
$w = $img_info[0]; $h = $img_info[1];
$nw = 96; $nh = 96;
$t_mtime = filemtime($BASE_DIR.$thumb);
$o_mtime = filemtime($BASE_DIR.$img);
if($w <= $nw && $h <= $nh) {
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) {
if($t_mtime > $o_mtime) {
//echo $BASE_URL.$path.'.'.$img_file;
header('Location: '.$BASE_URL.$path.'.'.$img_file);
exit();
}
}
}
}
$img_thumbs = Image_Transform::factory(IMAGE_CLASS);
$img_thumbs->load($BASE_DIR.$path.$img_file);
$img_thumbs = Image_Transform::factory(IMAGE_CLASS);
$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)
$nh = unpercent(percent($nw, $w), $h);
else if ($h > $w)
$nw = unpercent(percent($nh, $h), $w);
$img_thumbs->resize($nw, $nh);
$img_thumbs->resize($nw, $nh);
$img_thumbs->save($BASE_DIR.$thumb);
$img_thumbs->free();
$img_thumbs->save($BASE_DIR.$thumb);
$img_thumbs->free();
chmod($BASE_DIR.$thumb, 0666);
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
** 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';
$no_dir = false;
if(!is_dir($BASE_DIR.$BASE_ROOT)) {
if(!is_dir($BASE_DIR)) {
$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;">
<head>
@ -326,38 +360,12 @@ function toggleConstrains(constrains)
<td>
<select name="dirPath" id="dirPath" style="width:30em" onChange="updateDir(this)">
<option value="/">/</option>
<?
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++)
<?php
if($no_dir == false)
{
$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);
dirs($BASE_DIR,'');
}
}
if($no_dir == false) {
dirs($BASE_DIR.$BASE_ROOT,'');
}
?>
?>
</select>
</td>
<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
//
// htmlArea v3.0 - Copyright (c) 2002 interactivetools.com, inc.
// This notice MUST stay intact for use (see license.txt).
//
// A free WYSIWYG editor replacement for <textarea> fields.
// For full source code and docs, visit http://www.interactivetools.com/
//
// Version 3.0 developed by Mihai Bazon for InteractiveTools.
// http://dynarch.com/mishoo
//
// $Id$
/**************************************************************************\
* eGroupWare - UploadImage-plugin for htmlArea in eGroupWare *
* http://www.eGroupWare.org *
* Written and (c) by Xiang Wei ZHUO <wei@zhuo.org> *
* Used code fragments from plugins by Mihai Bazon *
* 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. *
\**************************************************************************/
// $id$
// FIXME: clean up code
function UploadImage(editor) {
this.editor = editor;
@ -36,12 +38,12 @@ function UploadImage(editor) {
};
UploadImage._pluginInfo = {
name : "UploadImage",
name : "UploadImage for eGroupWare",
version : "1.0",
developer : "Pim Snel",
developer_url : "http://lingewoud.com",
c_owner : "Mihai Bazon",
sponsor : "Lingewoud b.v. - Netherlands",
c_owner : "Pim Snel, Xiang Wei ZHUO, Mihai Bazon",
sponsor : "Lingewoud bv., Netherlands",
sponsor_url : "http://lingewoud.com",
license : "GPL"
};