function any_thing_uri_abs ( $thg_id, $idn_id = null, $lang = null, $commit = null ) { return any_thing_uri($thg_id, $idn_id, $lang, $commit, true); }
function _wiki_runtime_image ( $matches ) { global $_wiki_options; $attr = array(); $src = $matches[1]; $ct = count($matches); for ($i=2; $i<$ct; $i+=3) { $attr[trim($matches[$i+1])] = $matches[$i+2]; } $base_thg_id = !empty($_wiki_options['thg_id']) ? $_wiki_options['thg_id'] : false; $base_width = !empty($_wiki_options['width']) ? $_wiki_options['width'] : 400; $base_height = !empty($_wiki_options['height']) ? $_wiki_options['height'] : 400; $abs_uri = !empty($_wiki_options['abs_uri']) ? $_wiki_options['abs_uri'] : false; // Fetch the requested width and height if (!empty($attr['width'])) { $width = _wiki_runtime_img_size($attr['width'], $base_width); } else { $width = round($base_width); } if (!empty($attr['height'])) { $height = _wiki_runtime_img_size($attr['height'], $base_height); } else { $height = round($base_height); } if (substr($src, 0, 1) == '"' && substr($src, -1) == '"') { $src = substr($src, 1, -1); } $src = trim($src); // See where we have to fetch the image from if (!empty($src)) { if (strpos($src, 'uri:') === 0) { // direct uri $src = substr($src, 4); $id = false; } else if (strpos($src, '://') === false) { if (strpos($src, ':') !== false) { list($a, $b) = explode(':', $src); if (empty($b)) { $thg_id = $a; $lbl = false; } else if (empty($a)) { $thg_id = $base_thg_id; $lbl = $b; } else { $thg_id = $a; $lbl = $b; } } else { $thg_id = $base_thg_id; $lbl = $src; } // Try to translate to a real thg_id if (!is_numeric($thg_id)) { if (empty($lbl)) { $thg_id = any_symbolic2id($thg_id, array('kind'=>'ATTACHMENT')); } else { $thg_id = any_symbolic2id($thg_id); } } // Fetch the thing id of the attachment if (!empty($lbl) && !empty($thg_id)) { list($pred, $nr) = any_attach_label2pred($lbl); @list($aid, $alt, $caption) = any_attach_caption_pred($thg_id, $pred, $nr); } else { // Assume the given src is an attachment id if (!empty($attr['caption'])) { @list($alt, $caption) = any_attach_caption($thg_id); } else { $alt = ''; $caption = ''; } $aid = $thg_id; $lbl = false; } if (empty($caption) && !empty($alt)) { $caption = $alt; } $alt = strip_tags($alt); } else { $id = false; $aid = false; $lbl = false; $alt = ''; $caption = ''; } } else { $src = '#'; // Unknown source $id = false; $aid = false; $lbl = false; } if (!empty($attr['caption'])) { if (!empty($caption)) { $alt = trim($alt); $caption = trim(str_replace(array('<p>', '</p>'), array('','<br/>'), $caption)); while (substr($caption, -5) == '<br/>') { $caption = trim(substr($caption, 0, -5)); } if (!empty($alt) && !empty($intro)) { $cap = '<span class="caption">'; if (!empty($alt)) { $cap .= '<span>' . any_wiki_runtime($alt, $_wiki_options) .'</span>'; } if (!empty($caption)) { $cap .= any_wiki_runtime($caption, $_wiki_options); } $cap .= '</span>'; } else { $cap = ''; } if (strcasecmp($attr['caption'], 'before') == 0) { $cap1 = $cap; $cap2 = ''; } else { $cap1 = ''; $cap2 = $cap; } } else { $cap1 = ''; $cap2 = ''; } unset($attr['caption']); } else { $cap1 = ''; $cap2 = ''; } // // Expand the anchor tag around the image // if (array_key_exists('link',$attr)) { $link = trim($attr['link']); } else { $link = false; } $expand = false; if (empty($link) && !empty($aid)) { // Link to the attachment ;-) $href = 'id/' . $aid; if ($abs_uri) { $href = any_uri_abs($href); } } else if ($link[0] == '#') { // Ref to local anchor $href = $link; } else if ( strpos($link, '://') > 0 || strpos($link, '.php') !== false || strpos($link, '.html') !== false || strpos($link, '.htm') !== false) { // Literal link $href = $link; } else if (strncmp($link, 'javascript:', 12) == 0) { $href = $link; } else if (strncmp($link, 'popup:', 6) == 0) { $popup = substr($link, 6); if (strlen($popup) == 0) { if (is_numeric($thg_id)) { $label = addslashes($lbl); $href = "javascript:popup('$thg_id','$label')"; } else if (!empty($aid) && is_numeric($aid)) { $href = "javascript:popup('{$aid}')"; $expand = true; } } else { // Undefined behaviour for now... $href = false; } } else { // Assume a thing id if (!empty($abs_uri)) { $href = any_thing_uri_abs($link); } else { $href = any_thing_uri($link); } } // Perform any macro expansion (when needed) if (!empty($href) && $expand) { $href = str_replace(array('{$thg_id}', '{$label}', '{$att_id}'), array($thg_id, $lbl, $aid), $href); } $href = htmlspecialchars($href); // unset these so they don't show up as attributes unset($attr['link']); // Build the image tag if (!empty($aid) && is_numeric($aid)) { if (empty($attr['alt'])) { $attr['alt'] = $alt; } if (empty($attr['title'])) { $attr['title'] = $alt; } unset($attr['height']); unset($attr['width']); $pars = $attr; $pars['abs'] = $abs_uri; $img = any_attach_img_tag($aid, $pars, $width, $height); } else { if (!array_key_exists('alt', $attr)) { $attr['alt'] = basename($src); } // A normal src, build the tag ourselves $attr_s = ''; foreach ($attr as $key => $val) { $attr_s .= " $key=\"$val\""; } $img = "<img src=\"$src\"$attr_s />"; } if (!empty($href)) { $html = "$cap1<a href=\"$href\">$img</a>$cap2"; } else { $html = "$cap1$img$cap2"; } return $html; }