require 'scrivito/cms_routing' module Scrivito class CmsRouting def convert_links(html) if html html.to_str.gsub(%r{\bobjid:([a-f0-9]{4,})\b([^"']*)}) do if obj = Obj.find_by_id($1) options = {} if $2.present? begin uri = URI.parse($2) options.merge!(extract_query(uri)) options[:anchor] = uri.fragment rescue end end if editing_context.display_mode == 'editing' options[:id] = obj.id scrivito_engine.base_id_path(options) else path_or_url(obj, :path, options) end else "#__target_object_not_reachable" end end end end # patch for handling direct descendants of Scrivito::BasicObj 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?(::Scrivito::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_url(target) else raise "scrivito_path or scrivito_url was called with an instance of #{target.class}. "+ "It must only be called with an Obj or a Link or a non-empty LinkList." end end # Use fiona connector permalinks in legacy mode def path_or_url_for_objs(obj, path_or_url, options) permalink = obj.permalink if permalink && route_defined?(:permalink) if Fiona7.mode == :legacy context.public_send("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink)) else use_route(:permalink, path_or_url, options.merge(:permalink => permalink)) end elsif homepage?(obj) && route_defined?(:homepage) use_route(:homepage, path_or_url, options) elsif obj.binary? # use fiona connector routes when possible if Fiona7.mode == :legacy if binary = obj.binary params = { id: obj.id, slug: obj.slug, format: obj.file_extension } context.public_send("cms_id_#{path_or_url}", params) else LINK_TO_EMPTY_BLOB end else binary_obj_url(obj) || LINK_TO_EMPTY_BLOB end elsif route_defined?(:slug_id) slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil id_path_or_url_for_objs(obj, path_or_url, options.merge(slug: slug)) else raise ScrivitoError, "The required scrivito route 'slug_id' is not defined. "\ "Please add a 'slug_id' definition to your routes.rb. See the documentation"\ " of 'scrivito_route' for further details." end end # use fiona connector routes when possible def id_path_or_url_for_objs(obj, path_or_url, options) if Fiona7.mode == :standalone options[:id] = obj.id # Options must have the key slug. # Otherwise Rails will use the slug from current request params. options[:slug] ||= nil use_route(:slug_id, path_or_url, options) else options[:id] = obj.id # Options must have the key slug. # Otherwise Rails will use the slug from current request params. options[:slug] ||= nil context.public_send("cms_id_#{path_or_url}", options) end end end end