xowiki::markdown_image::drafts (private)

 xowiki::markdown_image::drafts page

Defined in packages/xowiki/tcl/markdown-image-procs.tcl

Collect this user's staged inline images referenced by the page and its form fields.

Parameters:
page (required)

Partial Call Graph (max 5 caller/called nodes):
xowiki::Page instproc save_new xowiki::Page instproc save_new (public) xowiki::markdown_image::drafts xowiki::markdown_image::drafts xowiki::Page instproc save_new->xowiki::markdown_image::drafts acs_object_type acs_object_type (public) xowiki::markdown_image::drafts->acs_object_type ad_conn ad_conn (public) xowiki::markdown_image::drafts->ad_conn content::revision::get_cr_file_path content::revision::get_cr_file_path (public) xowiki::markdown_image::drafts->content::revision::get_cr_file_path db_0or1row db_0or1row (public) xowiki::markdown_image::drafts->db_0or1row xowiki::markdown_image::draft_path xowiki::markdown_image::draft_path (private) xowiki::markdown_image::drafts->xowiki::markdown_image::draft_path

Testcases:
No testcase defined.
Source code:
  if {![ns_conn isconnected] || [ad_conn user_id] == 0
      || [ad_conn package_id] != [$page package_id]} {
    return {}
  }
  set values {}
  if {[$page exists text]} {
    lappend values [$page set text]
  }
  if {[$page exists instance_attributes]} {
    lappend values {*} [dict values [$page set instance_attributes]]
  }

  set prefix [ad_conn package_url]markdown-image?image_id=
  set drafts {}
  foreach html $values {
    if {[string first $prefix $html] == -1} continue
    foreach tag [ns_parsehtml -onlytags -- $html] {
      lassign $tag element attributes
      if {![string equal -nocase $element img] || ![dict exists $attributes src]} continue
      set src [dict get $attributes src]
      if {[string first $prefix $src] != 0} continue
      set image_id [string range $src [string length $prefix] end]
      if {![regexp {^[1-9][0-9]*$} $image_id] || [dict exists $drafts $image_id]} continue

      # Promote images from the earlier attachment implementation on the next
      # save of their owner. Retain the old attachment for historical revisions.
      if {[acs_object_type $image_id] ne ""} {
        if {[$page exists item_id]
            && [namespace which ::attachments::richtext::file_attach] ne ""} {
          set owner_id [$page item_id]
          if {[db_0or1row xowiki_markdown_legacy_image {
            select r.revision_id, r.mime_type
            from attachments a join cr_items i on i.item_id = a.item_id
            join cr_revisions r on r.revision_id = i.live_revision
            where a.object_id = :owner_id and a.item_id = :image_id
              and r.mime_type in ('image/png', 'image/jpeg', 'image/gif')
          }]} {
            set path [content::revision::get_cr_file_path -revision_id $revision_id]
            dict set drafts $image_id [list $path $mime_type legacy]
          }
        }
        continue
      }
      set path [draft_path $image_id]
      set mime [mime_type $path]
      if {$mime eq ""} {
        error "A pasted image is unavailable. Remove it or paste it again."
      }
      dict set drafts $image_id [list $path $mime]
    }
  }
  return $drafts
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: