Initial revision

This commit is contained in:
Robert Gaggl 2001-06-18 08:57:33 +00:00
parent 1ba4e8011b
commit bbfcb3d4f4
104 changed files with 3100 additions and 0 deletions

14
code/Image/delete.hac Normal file
View file

@ -0,0 +1,14 @@
// check if user is logged in and is the owner of this weblog
this.checkPermissions();
if (req.data.submit == "delete")
this.__parent__.deleteImage(this);
else if (req.data.submit == "cancel")
res.redirect(this.weblog.images.href("main"));
res.skin = "main";
res.title = "Antville - " + this.weblog.title;
res.head = this.weblog.renderSkinAsString("style");
res.body = this.weblog.renderSkinAsString("header");
res.body += this.renderSkinAsString("delete");

4
code/Image/delete.skin Normal file
View file

@ -0,0 +1,4 @@
<FORM METHOD="POST">
<P>Warning! You are about to delete the image <B><% this.alias %></B>! Be aware of the fact that there is no "undo", so if you klick on delete here the image will be gone forever!</P>
<P><% this.input type="button" value="delete" %>&nbsp;<% this.input type="button" value="cancel" %></P>
</FORM>

14
code/Image/edit.hac Normal file
View file

@ -0,0 +1,14 @@
// check if user is logged in and is the owner of this weblog
this.checkPermissions();
if (req.data.submit == "cancel")
res.redirect(this.weblog.images.href());
this.evalImg();
res.skin = "main";
res.title = "Antville - " + this.weblog.title;
res.head = this.weblog.renderSkinAsString("style");
res.body = this.weblog.renderSkinAsString("header");
res.body += this.renderSkinAsString("edit");

6
code/Image/edit.skin Normal file
View file

@ -0,0 +1,6 @@
<FORM METHOD="POST">
<P><% this.show %></P>
<P>Alias:<% this.alias as="editor" %></P>
<P>Alttext:<% this.alttext as="editor" %></P>
<P><% this.input type="button" value="save" %>&nbsp;<% this.input type="button" value="cancel" %>
</FORM>

76
code/Image/macros.js Normal file
View file

@ -0,0 +1,76 @@
/**
* macro rendering alias of image
*/
function alias_macro(param) {
renderPrefix(param);
if (param.as == "editor")
this.renderInputText(this.createInputParam("alias",param));
else
res.write(this.alias);
renderSuffix(param);
}
/**
* macro rendering alternate text of image
*/
function alttext_macro(param) {
renderPrefix(param);
if (param.as == "editor")
this.renderInputText(this.createInputParam("alttext",param));
else
res.write(this.alttext);
renderSuffix(param);
}
/**
* macro renders a link for editing image
*/
function editlink_macro(param) {
renderPrefix(param);
var linkParam = new HopObject();
linkParam.linkto = "edit";
this.openLink(linkParam);
if (!param.image)
res.write(param.text ? param.text : "edit");
else
this.renderImage(param);
this.closeLink();
renderSuffix(param);
}
/**
* macro rendering a link to delete
* if user is owner of this story
*/
function deletelink_macro(param) {
renderPrefix(param);
if (this.weblog && this.weblog.owner == user) {
var linkParam = new HopObject();
linkParam.linkto = "delete";
this.openLink(linkParam);
if (!param.image)
res.write(param.text ? param.text : "delete");
else
this.renderImage(param);
this.closeLink();
}
renderSuffix(param);
}
/**
* macro renders a preview of this image
*/
function show_macro(param) {
renderPrefix(param);
res.write("<IMG SRC=\"" + getProperty("imgUrl") + this.weblog.alias + "/" + this.filename + "." + this.fileext + "\"");
res.write(" WIDTH=\"" + (param && param.as == "preview" ? Math.round(this.width / 2) : this.width) + "\"");
res.write(" HEIGHT=\"" + (param && param.as == "preview" ? Math.round(this.height / 2) : this.height) + "\"");
res.write(" BORDER=\"0\">");
renderSuffix(param);
}

8
code/Image/new.skin Normal file
View file

@ -0,0 +1,8 @@
<FORM METHOD="POST" ENCTYPE="multipart/form-data">
<P>Alias:<% this.alias as="editor" %></P>
<P>Alttext:<% this.alttext as="editor" %></P>
<P>Upload: <% this.input type="file" name="rawimage" %></P>
<P>maximum width: <% this.input type="text" name="maxWidth" width="5" %><BR>
maximum height: <% this.input type="text" name="maxHeight" width="5" %><BR></P>
<P><% this.input type="button" value="save" %>&nbsp;<% this.input type="button" value="cancel" %>
</FORM>

View file

@ -0,0 +1,66 @@
/**
* save image as file on local disk
* but before check if image should be resized
* input params: - uploaded image
* - parameter-object
* return param: - parameter-object with add. props
*/
function saveImg(rawimage) {
if (rawimage && (!rawimage.contentType || rawimage.contentType.indexOf("image/") < 0)) {
// whatever the user has uploaded, it was no image!
this.cache.error = true;
res.message = "This was definetly no image!";
} else {
// determine filetype of image (one could do this also by checking the mimetype)
this.fileext = rawimage.name.substring(rawimage.name.lastIndexOf(".") + 1);
var img = new Image(rawimage.getContent());
// check if resizing is necessary
if (this.cache.maxWidth && this.cache.maxHeight && img.width > this.cache.maxWidth && img.height > this.cache.maxHeight) {
var hfact = this.cache.maxWidth / img.width;
var vfact = this.cache.maxHeight / img.height;
this.width = Math.round(img.width * (hfact < vfact ? hfact : vfact));
this.height = Math.round(img.height * (hfact < vfact ? hfact : vfact));
var doResize = true;
} else if (this.cache.maxWidth && img.width > this.cache.maxWidth) {
var fact = this.cache.maxWidth / img.width;
this.width = this.cache.maxWidth;
this.height = Math.round(img.height * fact);
var doResize = true;
} else if (this.cache.maxHeight && img.height > this.cache.maxHeight) {
var fact = this.cache.maxHeight / img.height;
this.height = this.cache.maxHeight;
this.width = Math.round(img.width * fact);
var doResize = true;
} else {
// no resizing done
this.width = img.width;
this.height = img.height;
}
if (doResize) {
img.resize(this.width,this.height);
if (rawimage.contentType == 'image/gif')
img.reduceColors(256);
}
// finally we save the image
img.saveAs(this.cache.saveTo + this.filename + "." + this.fileext);
}
return;
}
/**
* function checks if new image-parameters are correct ...
*/
function evalImg() {
if (req.data.alias) {
if (req.data.alias != this.alias) {
// alias has changed ...
this.weblog.images.changeAlias(this);
}
this.alttext = req.data.alttext;
res.message = "Changes saved successfully!";
res.redirect(this.weblog.images.href());
}
}

1
code/Image/preview.skin Normal file
View file

@ -0,0 +1 @@
<% this.show as="preview" %><% this.editlink prefix="&nbsp;" %><% this.deletelink prefix="&nbsp;" %><BR>

View file

@ -0,0 +1,10 @@
/**
* check if user is allowed to edit this story
*/
function checkPermissions() {
if (this.creator != user || user.isBlocked()) {
res.message = "Sorry, you're not allowed to edit this image!";
res.redirect(this.weblog.href());
}
}

View file

@ -0,0 +1,17 @@
_datasource=antville
_tablename=IMAGE
_id=ID
_parent=weblog.images[named]
weblog=WEBLOG_ID>weblog.ID
alias=ALIAS
filename=FILENAME
fileext=FILEEXT
width=WIDTH
height=HEIGHT
alttext=ALTTEXT
createtime=CREATETIME
creator=CREATOR>user.ID
modifytime=MODIFYTIME
modifier=MODIFIER>user.ID