Permalink
Browse files

fix: display of file origin in File and Image prototypes

 * ignore origins with c:\fakepath\ (i.e. uploaded from local file system)
 * use `description_macro()` for output of either this.description or this.origin (if available) or nothing, instead of macro default
 * prevent setting this.description in `update()` methods or from formica bookmarklet
  • Loading branch information...
p3k committed Jun 26, 2016
1 parent 2eeb454 commit fdfee2e50debeb1dbd12be7d9e022ee99a67cd1b
@@ -150,6 +150,10 @@ File.redirectOnExceededQuota = function(url) {
return;
}
File.prototype.setOrigin = function(origin) {
if (!/c:\\fakepath\\/i.test(origin)) this.origin = origin;
};
/**
* @name File
* @constructor
@@ -273,20 +277,16 @@ File.prototype.update = function(data) {
}
if (mime.contentLength > 0) {
this.origin = origin;
var mimeName = mime.normalizeFilename(mime.name);
this.contentLength = mime.contentLength;
this.contentType = mime.contentType;
this.setOrigin(origin);
if (!this.name) {
var name = File.getName(data.name) || mimeName.split('.')[0];
this.name = this.site.files.getAccessName(name);
}
if (!data.description && origin) {
data.description = gettext('Source: {0}', origin);
}
// Make the file persistent before proceeding with writing
// it to disk (also see Helma bug #607)
this.isTransient() && this.persist();
@@ -331,6 +331,17 @@ File.prototype.contentType_macro = function (param, mode) {
return res.write(this.contentType);
}
File.prototype.description_macro = function(param) {
if (this.description) {
res.write(this.description);
} else if (this.origin) {
var text = this.origin.replace(new RegExp('^.+:///?(?:www\.)?([^/]+).*$'), '$1');
var link = html.linkAsString({href: this.origin}, text);
res.write(gettext('Source: {0}', link));
}
return;
};
/**
*
*/
@@ -31,7 +31,7 @@
<div class='av-image-box'>
<figure>
<% image.render | link <% param.link %> class='uk-thumbnail' %>
<% image.origin prefix=<% gettext Source prefix="<figcaption class='uk-text-small'>" suffix=': ' %> suffix=</figcaption> %>
<% image.description prefix="<figcaption class='uk-text-small'>" suffix=</figcaption> %>
</figure>
</div>
@@ -291,17 +291,13 @@ Image.prototype.update = function(data) {
var mimeName = mime.normalizeFilename(mime.name);
this.contentLength = mime.contentLength;
this.contentType = mime.contentType;
this.origin = origin;
File.prototype.setOrigin.call(this, origin);
if (!this.name) {
var name = File.getName(data.name) || mimeName.split('.')[0];
this.name = this.parent.images.getAccessName(name);
}
if (!data.description && origin) {
data.description = gettext('Source: {0}', origin);
}
var thumbnail;
var image = this.getHelmaImage(mime, isLayout ? null :
res.handlers.site.imageDimensionLimits);
@@ -431,6 +427,10 @@ Image.prototype.render_macro = function(param) {
return;
};
Image.prototype.description_macro = function() {
File.prototype.description_macro.apply(this, arguments);
};
/**
*
* @param {Object} name
@@ -3,13 +3,13 @@
<div class="uk-article-meta">
<% gettext "Posted by {0} on {1}" <% image.creator %> <% image.created short %> %>
</div>
<div class='uk-margin-top'>
<a href='<% image.url %>' class='uk-thumbnail' style='width: <% image.width %>px;'>
<% image.render %>
<div class='uk-thumbnail-caption'>
<% image.description default=<% image.name %> %>
</div>
</a>
<div class='av-image-box uk-margin-top'>
<figure>
<a href='<% image.url %>'>
<% image.render class='uk-thumbnail' %>
</a>
<% image.description prefix="<figcaption class='uk-text-small'>" suffix=</figcaption> %>
</figure>
</div>
<div class='uk-margin-top'>
<% image.link edit <% gettext Edit %> class='uk-button' %>
@@ -30,15 +30,6 @@ File.prototype.alias_macro = function(param) {
return;
}
File.prototype.description_macro = function(param) {
if (param.as === "editor") {
this.input_macro(param, "description");
} else {
res.write(this.description);
}
return;
}
File.prototype.filesize_macro = function(param) {
return this.contentLength_macro(param);
}
@@ -270,3 +270,14 @@ Stories.prototype.onCodeUpdate = function() {
return helma.aspects.addBefore(this, "create_action",
aspects.fixStoryEditorParams);
}
File.prototype.onCodeUpdate = function() {
return helma.aspects.addAround(this, 'description_macro', function(args, func, file) {
var param = args[0];
if (param.as === "editor") {
file.input_macro(param, "description");
} else {
func.apply(file, args);
}
})
};
@@ -0,0 +1,27 @@
// The Antville Project
// http://code.google.com/p/antville
//
// Copyright 2001–2014 by the Workers of Antville.
//
// Licensed under the Apache License, Version 2.0 (the ``License'');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ``AS IS'' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Apply with enabled updater repository using `ant patch -Dpatch.id=20160626`
var sql = new Sql();
sql.retrieve("select * from metadata where parent_type in ('Image', 'File') and name = 'origin'");
sql.traverse(function() {
if (/c:\\fakepath\\/i.test(this.value)) {
sql.execute("delete from metadata where id = $0", this.id);
}
});
@@ -305,7 +305,6 @@
save: 1,
file_origin: imageUrl,
name: name,
description: 'Source: ' + url.replace(new RegExp('^.+:///?([^/]+).*$'), '$1'),
maxWidth: args.w || '',
maxHeight: args.h || ''
}).done(function(data) {

0 comments on commit fdfee2e

Please sign in to comment.