Source for file url.php
Documentation is available at url.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Paul M. Jones <pmjones@ciaweb.net> |
// +----------------------------------------------------------------------+
// $Id: url.php,v 1.4 2004/03/11 03:18:33 pmjones Exp $
* This class implements a Text_Wiki_Rule to find source text marked as a
* URL. Various URL markings are supported: inline (the URL by itself),
* numbered or footnote reference (where the URL is enclosed in square brackets), and
* named reference (where the URL is enclosed in square brackets and has a
* name included inside the brackets). E.g.:
* inline -- http://example.com
* numbered -- [http://example.com]
* described -- [http://example.com Example Description]
* When rendering a URL token, this will convert URLs pointing to a .gif,
* .jpg, or .png image into an inline <img /> tag (for the 'xhtml'
* @author Paul M. Jones <pmjones@ciaweb.net>
* When doing numbered references (footnote-style references), we
* need to keep a running count of how many references there are.
* An array of filename extensions that indicate a file is an image.
var $img_ext = array ('.jpg', '.png', '.gif');
"(http:\/\/|https:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|mailto:)" . // protocols
" [^ \\/\"\'{$this->_wiki->delim }]*\\/" . // no spaces, \, /, ", or single quotes;
" [^ \\t\\n\\/\"\'{$this->_wiki->delim }]*" .
* A somewhat complex parsing method to find three different kinds
* of URLs in the source text.
// -------------------------------------------------------------
// Described-reference (named) URLs.
// the regular expression for this kind of URL
$tmp_regex = '/\[(' . $this->regex . ') ([^\]]+)\]/';
// use a custom callback processing method to generate
// the replacement text for matches.
array (&$this, 'processDescr'),
// -------------------------------------------------------------
// Numbered-reference (footnote-style) URLs.
// the regular expression for this kind of URL
$tmp_regex = '/\[(' . $this->regex . ')\]/U';
// use a custom callback processing method to generate
// the replacement text for matches.
array (&$this, 'processFootnote'),
// -------------------------------------------------------------
// the regular expression for this kind of URL
$tmp_regex = '/(^|[^A-Za-z])(' . $this->regex . ')(.*?)/';
// use the standard callback for inline URLs
array (&$this, 'process'),
* Process inline URLs and return replacement text with a delimited
* 'type' => ['inline'|'footnote'|'descr'] the type of URL
* 'href' => the URL link href portion
* 'text' => the displayed text of the URL link
* @param array $matches An array of matches from the parse() method
* as generated by preg_replace_callback. $matches[0] is the full
* matched string, $matches[1] is the first matched pattern,
* $matches[2] is the second matched pattern, and so on.
* @return string The processed text replacement.
return $matches[1 ] . $this->addToken($options) . $matches[5 ];
* Process numbered (footnote) URLs and return replacement text with
* 'type' => ['inline'|'footnote'|'descr'] the type of URL
* 'href' => the URL link href portion
* 'text' => the displayed text of the URL link
* @param array $matches An array of matches from the parse() method
* as generated by preg_replace_callback. $matches[0] is the full
* matched string, $matches[1] is the first matched pattern,
* $matches[2] is the second matched pattern, and so on.
* @return string The processed text replacement.
// keep a running count for footnotes
* Process described-reference (named-reference) URLs and return
* replacement text with a delimited token.
* 'type' => ['inline'|'footnote'|'descr'] the type of URL
* 'href' => the URL link href portion
* 'text' => the displayed text of the URL link
* @param array $matches An array of matches from the parse() method
* as generated by preg_replace_callback. $matches[0] is the full
* matched string, $matches[1] is the first matched pattern,
* $matches[2] is the second matched pattern, and so on.
* @return string The processed text replacement.
* Renders a token into text matching the requested format.
* @param array $options The "options" portion of the token (second
* @return string The text rendered from the token options.
// create local variables from the options array (text,
// find the rightmost dot and determine the filename
// does the filename extension indicate an image file?
// create alt text for the image
if (! isset ($text) || $text == '') {
$output = " <img src=\"$href\" alt=\"$text\" />";
// generate a regular link (not an image)
$output = " <a href=\"$href\">$text</a>";
// make numbered references look like footnotes
if ($type == 'footnote') {
$output = '<sup>' . $output . '</sup>';
Documentation generated on Mon, 11 Mar 2019 10:14:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|