make UploadImage plugin actualy work (beta1)

This commit is contained in:
Pim Snel 2004-06-15 00:27:03 +00:00
parent 8d833331ff
commit dd1ed0f786
6 changed files with 148 additions and 25 deletions

View File

@ -21,5 +21,6 @@ UploadImage.I18N = {
"Document title:": "Document title:",
"OK": "OK",
"Primary style-sheet:": "Primary style-sheet:",
"Text color:": "Text color:"
"Text color:": "Text color:",
"Upload Image": "Upload Image"
};

View File

@ -79,7 +79,7 @@ Class Image_Transform_Driver_GD extends Image_Transform
function load($image)
{
$this->uid = md5($_SERVER['REMOTE_ADDR']);
$this->image = $image;
$this->image = $image;
$this->_get_image_details($image);
$functionName = 'ImageCreateFrom' . $this->type;
$this->imageHandle = $functionName($this->image);
@ -413,7 +413,6 @@ Class Image_Transform_Driver_GD extends Image_Transform
imagesetpixel($this->imageHandle, $right, $j, $t);
$left++; $right--;
}
}
return true;

View File

@ -36,6 +36,7 @@ include '../ImageManager/config.inc.php';
// set this to whatever subdir you make
$path = $BASE_ROOT.'/';
//$path = $BASE_DIR.'/';
//***************************************************************************
@ -76,12 +77,14 @@ if(isset($params)) {
//manipulate the images
function manipulate($img_file, $action, $values)
{
global $path, $save_file, $BASE_DIR;
global $path, $save_file, $BASE_DIR,$BASE_ROOT;
$img_location=$BASE_DIR.$BASE_ROOT.'/';
//Load the Image Manipulation Driver
$img = Image_Transform::factory(IMAGE_CLASS);
$img->load($BASE_DIR.$path.$img_file);
//var_dump($_SERVER['DOCUMENT_ROOT'].$path.$img_file);
$img->load($img_location.$img_file);
switch ($action) {
case 'crop':
$img->crop(intval($values[0]),intval($values[1]),intval($values[2]),intval($values[3]));
@ -105,15 +108,15 @@ function manipulate($img_file, $action, $values)
$quality = intval($values[1]);
if($quality <0)
$quality = 85;
$img->save($BASE_DIR.$path.$save_file, $values[0], $quality);
$img->save($img_location.$save_file, $values[0], $quality);
}
break;
}
//get the unique file name
$filename = $img->createUnique($BASE_DIR.$path);
$filename = $img->createUnique($img_location);
//save the manipulated image
$img->save($BASE_DIR.$path.$filename);
$img->save($img_location.$filename);
$img->free();
$imagesize = @getimagesize($filename);
@ -135,4 +138,4 @@ if (isset($file) && is_array($file))
//now display the image with
include 'man_image.html';
?>
?>

View File

@ -5,14 +5,23 @@
//example, this is the actual file system path
//of the web server document root. e.g.
// Filesystem == /home/web/www.yourdomain.com
$BASE_DIR = $_SERVER['DOCUMENT_ROOT'];
$BASE_DIR = $GLOBALS[UploadImageBaseDir];
$BASE_URL = $GLOBALS[UploadImageBaseURL];
$BASE_ROOT = $GLOBALS[UploadImageRelativePath];
var_dump($BASE_DIR);
var_dump($BASE_URL);
var_dump($BASE_ROOT);
//$BASE_DIR = $_SERVER['DOCUMENT_ROOT'];
//$BASE_DIR = '/home/www';
//the path where the browser sees the document root (i.e. http://www.yourdomain.com/)
$BASE_URL = '/';
//$BASE_URL = 'https://192.168.0.2/';
//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 = 'test';
//$BASE_ROOT = '';
//The image manipulation library to use, either GD or ImageMagick or NetPBM
//valid definitions are 'GD' or 'IM' or 'NetPBM'.
@ -38,7 +47,7 @@ if(strrpos($BASE_DIR, '/')!= strlen($BASE_DIR)-1)
$BASE_DIR .= '/';
if(strrpos($BASE_URL, '/')!= strlen($BASE_URL)-1)
$BASE_URL .= '/';
$BASE_URL .= '/';
//Built in function of dirname is faulty
//It assumes that the directory nane can not contain a . (period)

View File

@ -58,7 +58,8 @@
var id = fields[i];
var el = MM_findObj(id);
if(id == "f_url")
param[id] = "<? echo 'http://'.$_SERVER['SERVER_NAME']; ?>" + el.value;
// param[id] = "<? echo 'http://'.$_SERVER['SERVER_NAME']; ?>" + el.value;
param[id] = "" + el.value;
else
param[id] = el.value;
}

View File

@ -16,18 +16,23 @@ function UploadImage(editor) {
this.editor = editor;
var cfg = editor.config;
cfg.fullPage = true;
// cfg.fullPage = true;
var tt = UploadImage.I18N;
var self = this;
cfg.registerButton("FP-docprop", tt["Document properties"], editor.imgURL("up_image.gif", "UploadImage"), false,
/* cfg.registerButton("UploadImage", tt["Upload Image"], editor.imgURL("up_image.gif", "UploadImage"), false,
function(editor, id) {
self.buttonPress(editor, id);
});
*/
cfg.registerButton("UploadImage", tt["Upload Image"], editor.imgURL("up_image.gif", "UploadImage"), false,
function(editor, id) {
self.buttonPress(editor, id);
self.buttonPress();
});
// add a new line in the toolbar
cfg.toolbar[0].splice(0, 0, "separator");
cfg.toolbar[0].splice(0, 0, "FP-docprop");
cfg.toolbar[0].splice(29, 0, "separator");
cfg.toolbar[0].splice(30, 0, "UploadImage");
};
UploadImage._pluginInfo = {
@ -41,12 +46,12 @@ UploadImage._pluginInfo = {
license : "GPL"
};
UploadImage.prototype.buttonPress = function(editor, id)
UploadImage.prototype.zzzbuttonPress = function(editor, id)
{
var self = this;
switch (id)
{
case "FP-docprop":
case "UploadImage":
var doc = editor._doc;
var links = doc.getElementsByTagName("link");
var style1 = '';
@ -64,6 +69,7 @@ UploadImage.prototype.buttonPress = function(editor, id)
}
var title = doc.getElementsByTagName("title")[0];
title = title ? title.innerHTML : '';
var init =
{
f_doctype : editor.doctype,
@ -75,9 +81,12 @@ UploadImage.prototype.buttonPress = function(editor, id)
editor : editor
};
Dialog(_editor_url+"plugins/UploadImage/popups/insert_image.php", function(params)
Dialog(_editor_url+"plugins/UploadImage/popups/insert_image.php", function(image)
{
self.setDocProp(params);
self._insertImage(image);
// self.setDocProp(params);
// alert(params[1]);
}, init);
/* editor._popupDialog("plugin://UploadImage/insert_image.php", function(params) {
@ -87,6 +96,79 @@ UploadImage.prototype.buttonPress = function(editor, id)
}
};
// Called when the user clicks on "InsertImage" button. If an image is already
// there, it will just modify it's properties.
UploadImage.prototype.buttonPress = function(image) {
var doc = editor._doc;
// var editor = this; // for nested functions
var outparam = null;
var init =
{
f_doctype : editor.doctype,
editor : editor
};
if (typeof image == "undefined") {
image = editor.getParentElement();
if (image && !/^img$/i.test(image.tagName))
image = null;
}
if (image) outparam = {
f_url : HTMLArea.is_ie ? editor.stripBaseURL(image.src) : image.getAttribute("src"),
f_alt : image.alt,
f_border : image.border,
f_align : image.align,
f_vert : image.vspace,
f_horiz : image.hspace
};
Dialog(_editor_url+"plugins/UploadImage/popups/insert_image.php", function(param){
if (!param) { // user must have pressed Cancel
return false;
}
var img = image;
// alert(param.f_url);
if (!img) {
var sel = editor._getSelection();
var range = editor._createRange(sel);
editor._doc.execCommand("insertimage", false, param.f_url);
if (HTMLArea.is_ie) {
img = range.parentElement();
// wonder if this works...
if (img.tagName.toLowerCase() != "img") {
img = img.previousSibling;
}
} else {
img = range.startContainer.previousSibling;
}
} else {
img.src = param.f_url;
}
for (field in param) {
var value = param[field];
switch (field) {
case "f_alt" : img.alt = value; break;
case "f_border" : img.border = parseInt(value || "0"); break;
case "f_align" : img.align = value; break;
case "f_vert" : img.vspace = parseInt(value || "0"); break;
case "f_horiz" : img.hspace = parseInt(value || "0"); break;
}
}
}, outparam);
};
UploadImage.prototype.setDocProp = function(params) {
var txt = "";
var doc = this.editor._doc;
@ -124,7 +206,35 @@ UploadImage.prototype.setDocProp = function(params) {
else if (style2)
head.removeChild(style2);
for (var i in params) {
//cfg.registerButton("my-sample", "Class: sample", "ed_custom.gif", false,
function testinsert(arg1,arg2) {
if (HTMLArea.is_ie) {
editor.insertHTML("<img src=\"arg1\" alt=\"\" />");
var r = editor._doc.selection.createRange();
r.move("character", -2);
r.moveEnd("character", 2);
r.select();
} else { // Gecko/W3C compliant
var n = editor._doc.createElement("img");
n.className = "sample";
editor.insertNodeAtSelection(n);
var sel = editor._iframe.contentWindow.getSelection();
sel.removeAllRanges();
var r = editor._doc.createRange();
r.setStart(n, 0);
r.setEnd(n, 0);
sel.addRange(r);
}
}
testinsert(params[1]);
for (var i in params) {
// alert(params[i]);
var val = params[i];
switch (i) {
case "f_title":