require 'scrivito/cms_routing' module Scrivito class CmsRouting # patch link converter to understand numerical IDs def convert_links(html) if html html.gsub(%r{?}) do if obj = Obj.find_by_id($1) path_or_url(obj, "path") else "#__target_object_not_reachable" end end end end # patch router to output proper binary urls fo uploaded files def path_or_url_without_editing_context(target, path_or_url, options) if target.is_a?(Link) path_or_url_for_links(target, path_or_url, options) elsif target.is_a?(BasicObj) path_or_url_for_objs(target, path_or_url, options) elsif target.respond_to?(:first) if target.first.is_a?(Link) path_or_url_for_links(target.first, path_or_url, options) else return LINK_TO_EMPTY_LINKLIST end elsif target.is_a?(Binary) binary = target main_app.public_send("fiona7_blob_#{path_or_url}", {id: binary.send(:id), name: binary.filename}) else raise "scrivito_path or scrivito_url was called with an instance of #{target.class}. "+ "It must only be called with a descendant of Scrivito::BasicObj or a Link or a non-empty LinkList." end end # patch router to output proper binary urls fo uploaded files def path_or_url_for_objs(obj, path_or_url, options = {}) permalink = obj.permalink if permalink main_app.public_send("scrivito_permalink_#{path_or_url}", options.merge(:permalink => permalink)) elsif obj.homepage? main_app.public_send("scrivito_root_#{path_or_url}", options) else if obj.binary? && editing_context.display_mode != "editing" if obj.binary main_app.public_send("fiona7_blob_#{path_or_url}", {id: obj.binary.send(:id), name: obj.binary.filename}) else LINK_TO_EMPTY_BLOB end else main_app.public_send( "scrivito_id_#{path_or_url}", options.merge( id: obj.id, slug: obj.slug.presence ) ) end end end end end