function internallink($match, $state, $pos) { // Strip the opening and closing markup $link = preg_replace(array('/^\\[\\[/', '/\\]\\]$/u'), '', $match); // Split title from URL $link = explode('|', $link, 2); if (!isset($link[1])) { $link[1] = null; } else { if (preg_match('/^\\{\\{[^\\}]+\\}\\}$/', $link[1])) { // If the title is an image, convert it to an array containing the image details $link[1] = Doku_Handler_Parse_Media($link[1]); } } $link[0] = trim($link[0]); //decide which kind of link it is if (link_isinterwiki($link[0])) { // Interwiki $interwiki = explode('>', $link[0], 2); $this->_addCall('interwikilink', array($link[0], $link[1], strtolower($interwiki[0]), $interwiki[1]), $pos); } elseif (preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u', $link[0])) { // Windows Share $this->_addCall('windowssharelink', array($link[0], $link[1]), $pos); } elseif (preg_match('#^([a-z0-9\\-\\.+]+?)://#i', $link[0])) { // external link (accepts all protocols) $this->_addCall('externallink', array($link[0], $link[1]), $pos); } elseif (preg_match('<' . PREG_PATTERN_VALID_EMAIL . '>', $link[0])) { // E-Mail (pattern above is defined in inc/mail.php) $this->_addCall('emaillink', array($link[0], $link[1]), $pos); } elseif (preg_match('!^#.+!', $link[0])) { // local link $this->_addCall('locallink', array(substr($link[0], 1), $link[1]), $pos); } else { // internal link $this->_addCall('internallink', array($link[0], $link[1]), $pos); } return true; }
/** * Render an external media file * * @param string $src full media URL * @param string $title descriptive text * @param string $align left|center|right * @param int $width width of media in pixel * @param int $height height of media in pixel * @param string $cache cache|recache|nocache * @param string $linking linkonly|detail|nolink * @param bool $return return HTML instead of adding to $doc * @return void|string writes to doc attribute or returns html depends on $return */ function externalmedia($src, $title = null, $align = null, $width = null, $height = null, $cache = null, $linking = null, $return = false) { if (link_isinterwiki($src)) { list($shortcut, $reference) = explode('>', $src, 2); $exists = null; $src = $this->_resolveInterWiki($shortcut, $reference, $exists); } list($src, $hash) = explode('#', $src, 2); $noLink = false; $render = $linking == 'linkonly' ? false : true; $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); $link['url'] = ml($src, array('cache' => $cache)); list($ext, $mime) = mimetype($src, false); if (substr($mime, 0, 5) == 'image' && $render) { // link only jpeg images // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; } elseif (($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { // don't link movies $noLink = true; } else { // add file icons $class = preg_replace('/[^_\\-a-z0-9]+/i', '_', $ext); $link['class'] .= ' mediafile mf_' . $class; } if ($hash) { $link['url'] .= '#' . $hash; } //output formatted if ($return) { if ($linking == 'nolink' || $noLink) { return $link['name']; } else { return $this->_formatLink($link); } } else { if ($linking == 'nolink' || $noLink) { $this->doc .= $link['name']; } else { $this->doc .= $this->_formatLink($link); } } }