Doku_Handler::internallink PHP Метод

    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;
    }

Usage Example

Пример #1
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     if ($state == DOKU_LEXER_SPECIAL) {
         $text = preg_match('/^\\[(' . $this->nested_brackets_re . ')\\]\\([ \\t]*<?(.+?)>?[ \\t]*(?:[\'"](.*?)[\'"])?[ \\t]*?\\)$/', $match, $matches);
         $target = $matches[2] == '' ? $matches[3] : $matches[2];
         $title = $matches[1];
         $target = preg_replace('/^mailto:/', '', $target);
         $handler->internallink($target . '|' . $title, $state, $pos);
     }
     return true;
 }