lib/zena/use/urls.rb in zena-1.2.2 vs lib/zena/use/urls.rb in zena-1.2.3
- old
+ new
@@ -16,14 +16,16 @@
'edit' => {:url => '/nodes/#{node_zip}/versions/0/edit'},
'create' => {:url => '/nodes', :method => 'post', :query => {:parent_id => 'node_zip'}},
}
- ALLOWED_REGEXP = /\A(([a-zA-Z]+)([0-9]+)|([#{String::ALLOWED_CHARS_IN_URL}\-%]+))(_[a-zA-Z]+|)(\..+|)\Z/
+ ALLOWED_REGEXP = /\A(([a-zA-Z]+)([0-9]+)|([#{String::ALLOWED_CHARS_IN_URL}\-%]+))(_[a-zA-Z]+|)(=[a-z0-9]+|)(\..+|)\Z/
module Common
- CACHESTAMP_FORMATS = ['jpg', 'png', 'gif', 'css', 'js']
+ # This is directly related to the FileMatch clause in httpd.rhtml (mod_expires for apaches)
+ CACHESTAMP_FORMATS = %w{ico flv jpg jpeg png gif js css swf}
+
def prefix
if visitor.is_anon?
visitor.lang
else
AUTHENTICATED_PREFIX
@@ -97,42 +99,41 @@
else
abs_url_prefix = ''
end
if node.kind_of?(Document) && format == node.ext
- if node.public? && !visitor.site.authentication?
+ if node.v_public? && !visitor.site.authentication?
# force the use of a cacheable path for the data, even when navigating in '/oo'
pre = node.version.lang
end
end
if asset = opts.delete(:asset)
mode = nil
end
-
-
+
if should_cachestamp?(node, format, asset)
- opts[:cachestamp] = make_cachestamp(node, mode)
- else
- opts.delete(:cachestamp) # cachestamp
+ stamp = make_cachestamp(node, mode)
end
path = if !asset && node[:id] == visitor.site[:root_id] && mode.nil? && format == 'html'
"#{abs_url_prefix}/#{pre}" # index page
elsif node[:custom_base]
"#{abs_url_prefix}/#{pre}/" +
basepath_as_url(node.basepath) +
(mode ? "_#{mode}" : '') +
- (asset ? ".#{asset}" : '') +
+ (asset ? "=#{asset}" : '') +
+ (stamp ? ".#{stamp}" : '') +
(format == 'html' ? '' : ".#{format}")
else
"#{abs_url_prefix}/#{pre}/" +
(node.basepath.blank? ? '' : "#{basepath_as_url(node.basepath)}/") +
(node.klass.downcase ) +
(node[:zip].to_s ) +
(mode ? "_#{mode}" : '') +
- (asset ? ".#{asset}" : '') +
+ (asset ? "=#{asset}" : '') +
+ (stamp ? ".#{stamp}" : '') +
".#{format}"
end
append_query_params(path, opts)
end
@@ -148,11 +149,10 @@
def append_query_params(path, opts)
if opts == {}
path
else
- cachestamp = opts.delete(:cachestamp)
tz = opts.delete(:tz)
list = opts.keys.map do |k|
# FIXME: DOC
if k.to_s == 'encode_params'
opts[k].split(',').map(&:strip).map do |key|
@@ -179,18 +179,14 @@
end
else
nil
end
end.flatten.compact
- if cachestamp
- result = path + "?#{cachestamp}" + (list.empty? ? '' : "&#{list.sort.join('&')}")
- result
- else
- # TODO: replace '&' by '&' ? Or escape later ? Use h before zen_path in templates ? What about css/xls/other stuff ?
- # Best solution: use 'h' in template when set in default
- path + (list.empty? ? '' : "?#{list.sort.join('&')}")
- end
+
+ # TODO: replace '&' by '&' ? Or escape later ? Use h before zen_path in templates ? What about css/xls/other stuff ?
+ # Best solution: use 'h' in template when set in default
+ path + (list.empty? ? '' : "?#{list.sort.join('&')}")
end
end
# Url for a node. Options are 'mode' and 'format'
# ex 'http://test.host/en/document34_print.html'
@@ -216,11 +212,11 @@
# &&
# ((node.kind_of?(Document) && node.prop['ext'] == format) || asset)
end
def make_cachestamp(node, mode)
- if mode
+ str = if mode
if node.kind_of?(Image)
if iformat = Iformat[mode]
"#{node.updated_at.to_i + iformat[:hash_id]}"
else
# random (will raise a 404 error anyway)
@@ -232,10 +228,12 @@
node.updated_at.to_i.to_s
end
else
node.updated_at.to_i.to_s
end
+
+ Digest::SHA1.hexdigest(str)[0..4]
end
# Url parameters (without format/mode/prefix...)
def query_params
res = {}
@@ -693,11 +691,11 @@
::RubyLess.translate(self, method)
end
def insert_ajax_args(target, hash_params, action)
hash_params << ":s => start_id"
- hash_params << ":link_id => this.link_id" if @context[:has_link_id] && node.will_be?(Node)
+ hash_params << ":link_id => this.link_id" if @context[:has_link_id] && node.will_be?(Node) && !node.list_context?
# FIXME: when we have proper markup.dyn_params[:id] support,
# we should not need this crap anymore.
case action
when 'edit'
@@ -814,28 +812,33 @@
parser_error("unkown option for 'page' #{@params[:page].inspect} should be ('previous', 'next' or 'list')")
end
end
def text_for_link(default = nil)
+
if dynamic_blocks?
expand_with
else
method = get_attribute_or_eval(false)
if !method && (@params.keys & [:attr, :eval, :text, :t]) != []
out @errors.last
end
if method
- method.literal ? erb_escape(method.literal) : "<%= #{method} %>"
+ if method.opts[:html_safe]
+ method.literal || "<%= #{method} %>"
+ else
+ method.literal ? ::ERB::Util.html_escape(method.literal) : "<%=h #{method} %>"
+ end
elsif default
default
elsif node.will_be?(Node)
- "<%= #{node(Node)}.prop['title'] %>"
+ "<%=h #{node(Node)}.prop['title'] %>"
elsif node.will_be?(Version)
- "<%= #{node(Version)}.node.prop['title'] %>"
+ "<%=h #{node(Version)}.node.prop['title'] %>"
elsif node.will_be?(Link)
- "<%= #{node(Link)}.name %>"
+ "<%=h #{node(Link)}.name %>"
else
_('edit')
end
end
end