Sourcecode in ImageMgr/objectFunctions.js:
1: function evalImg(param, creator) {
2: if (param.uploadError) {
3: // looks like the file uploaded has exceeded uploadLimit ...
4: throw new Exception("imageFileTooBig");
5: } else if (!param.rawimage || param.rawimage.contentLength == 0) {
6: // looks like nothing was uploaded ...
7: throw new Exception("imageNoUpload");
8: } else if (param.rawimage && (!param.rawimage.contentType || !evalImgType(param.rawimage.contentType))) {
9: // whatever the user has uploaded wasn't recognized as an image
10: throw new Exception("imageNoImage");
11: }
12: var filesize = Math.round(param.rawimage.contentLength / 1024);
13: if (this._parent.getDiskUsage() + filesize > this._parent.getDiskQuota()) {
14: // disk quota has already been exceeded
15: throw new Exception("siteQuotaExceeded");
16: }
17:
18: var newImg = new Image(creator);
19: // if no alias given try to determine it
20: if (!param.alias)
21: newImg.alias = buildAliasFromFile(param.rawimage, this);
22: else {
23: if (!param.alias.isFileName())
24: throw new Exception("noSpecialChars");
25: newImg.alias = buildAlias(param.alias, this);
26: }
27: // check name of topic (if specified)
28: var topicName = null;
29: if (param.topic) {
30: if (!param.topic.isURL())
31: throw new Exception("topicNoSpecialChars");
32: topicName = param.topic;
33: } else if (param.addToTopic)
34: topicName = param.addToTopic;
35: newImg.topic = topicName;
36: // store properties necessary for saving image on disk
37: newImg.filename = newImg.alias;
38: // check if user wants to resize image
39: var maxWidth = param.maxwidth ? parseInt(param.maxwidth, 10) : null;
40: var maxHeight = param.maxheight ? parseInt(param.maxheight, 10) : null;
41: // save/resize the image
42: var dir = this._parent.getStaticDir("images");
43: newImg.save(param.rawimage, dir, maxWidth, maxHeight);
44: // the fullsize-image is on disk, so we add the image-object (and create the thumbnail-image too)
45: newImg.alttext = param.alttext;
46: if (!this.add(newImg))
47: throw new Exception("imageAdd");
48: // the fullsize-image is stored, so we check if a thumbnail should be created too
49: if (newImg.width > THUMBNAILWIDTH)
50: newImg.createThumbnail(param.rawimage, dir);
51: // send e-mail notification
52: if (newImg.site && newImg.site.isNotificationEnabled())
53: newImg.site.sendNotification("upload", newImg);
54: newImg.site.diskusage += newImg.filesize;
55: var result = new Message("imageCreate", newImg.alias, newImg);
56: result.url = newImg.href();
57: return result;
58: }
|