/** * Handle the match */ function handle($match, $state, $pos, &$handler) { // Strip the opening and closing markup $link = preg_replace(array('/^\\[\\[/', '/\\]\\]$/u'), '', $match); // Split title from URL $link = preg_split('/\\|/u', $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 (preg_match('/^[a-zA-Z]+>{1}.*$/u', $link[0])) { // Interwiki $interwiki = preg_split('/>/u', $link[0]); $handler->_addCall('interwikilink', array($link[0], $link[1], strtolower($interwiki[0]), $interwiki[1]), $pos); } elseif (preg_match('/^\\\\\\\\[\\w.:?\\-;,]+?\\\\/u', $link[0])) { // Windows Share $handler->_addCall('windowssharelink', array($link[0], $link[1]), $pos); } elseif (preg_match('#^([a-z0-9\\-\\.+]+?)://#i', $link[0])) { // external link (accepts all protocols) $handler->_addCall('externallink', array($link[0], $link[1]), $pos); } elseif (preg_match('#([a-z0-9\\-_.]+?)@([\\w\\-]+\\.([\\w\\-\\.]+\\.)*[\\w]+)#i', $link[0])) { // E-Mail $handler->_addCall('emaillink', array($link[0], $link[1]), $pos); } elseif (preg_match('!^#.+!', $link[0])) { // local link $handler->_addCall('locallink', array(substr($link[0], 1), $link[1]), $pos); } else { return array($link[0], $link[1]); } }
/** * Rewrite a media syntax * * @param string $match The text match of the media syntax * @return string The rewritten syntax */ protected function rewrite_media($match) { $p = Doku_Handler_Parse_Media($match); if ($p['type'] == 'internalmedia') { // else: external media $new_src = $this->resolveMoves($p['src'], 'media'); $new_src = $this->relativeLink($p['src'], $new_src, 'media'); if ($new_src !== $p['src']) { // do a simple replace of the first match so really only the id is changed and not e.g. the alignment $srcpos = strpos($match, $p['src']); $srclen = strlen($p['src']); return substr_replace($match, $new_src, $srcpos, $srclen); } } return $match; }
function media($match, $state, $pos) { $p = Doku_Handler_Parse_Media($match); $this->_addCall($p['type'], array($p['src'], $p['title'], $p['align'], $p['width'], $p['height'], $p['cache'], $p['linking']), $pos); return true; }
function clean_link($xBody) { // evaluate the media link by DW embedded function $link = Doku_Handler_Parse_Media($xBody); if (stripos($link['src'], '>') === false) { $xBody = $link['src']; } else { $xBody = ''; } return $xBody; }
function handle($match, $state, $pos, &$handler) { global $ID, $INFO; switch ($state) { case DOKU_LEXER_ENTER: $this->insideToc = true; $options = explode(' ', substr($match, 5, -1)); return array('start' => true, 'pos' => $pos, 'options' => $options); break; case DOKU_LEXER_SPECIAL: if ($this->insideToc) { $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]); if (!(preg_match('/^[a-zA-Z0-9\\.]+>{1}.*$/u', $link[0]) || preg_match('/^\\\\\\\\[\\w.:?\\-;,]+?\\\\/u', $link[0]) || preg_match('#^([a-z0-9\\-\\.+]+?)://#i', $link[0]) || preg_match('<' . PREG_PATTERN_VALID_EMAIL . '>', $link[0]) || preg_match('!^#.+!', $link[0]))) { // Get current depth from call stack $depth = 1; if ($handler->CallWriter instanceof Doku_Handler_List) { $calls = array_reverse($handler->CallWriter->calls); $call = $calls[0]; foreach ($calls as $item) { if (in_array($item[0], array('list_item', 'list_open'))) { $call = $item; break; } } $depth = $handler->CallWriter->interpretSyntax($call[1][0], $listType); } if (empty($link[0])) { break; } // No empty elements. This would lead to problems return array($link[0], $link[1], $depth); break; } else { // use parser! - but with another p $handler->internallink($match, $state, $pos); } } else { // use parser! $handler->internallink($match, $state, $pos); } return false; case DOKU_LEXER_UNMATCHED: $handler->_addCall('cdata', array($match), $pos); return false; break; case DOKU_LEXER_EXIT: $this->insideToc = false; return 'save__meta'; break; } return false; }