Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Url.php

Documentation is available at Url.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Parse for URLS in the source text.
  6.  *
  7.  * raw       -- http://example.com
  8.  * no descr. -- [[http://example.com]]
  9.  * described -- [[http://example.com|Example Description]]
  10.  *
  11.  * When rendering a URL token, this will convert URLs pointing to a .gif,
  12.  * .jpg, or .png image into an inline <img /> tag (for the 'xhtml'
  13.  * format).
  14.  *
  15.  * @category Text
  16.  *
  17.  * @package Text_Wiki
  18.  *
  19.  * @author Michele Tomaiuolo <tomamic@yahoo.it>
  20.  *
  21.  * @license LGPL
  22.  *
  23.  * @version $Id: Url.php,v 1.2 2006/10/24 14:53:31 mic Exp $
  24.  *
  25.  */
  26.  
  27. class Text_Wiki_Parse_Url extends Text_Wiki_Parse {
  28.  
  29.     /**
  30.      *
  31.      * Constructor.  Overrides the Text_Wiki_Parse constructor so that we
  32.      * can set the $regex property dynamically (we need to include the
  33.      * Text_Wiki $delim character).
  34.      *
  35.      * @param object &$obj The calling "parent" Text_Wiki object.
  36.      *
  37.      * @param string $name The token name to use for this rule.
  38.      *
  39.      */
  40.  
  41.     function Text_Wiki_Parse_Url(&$obj)
  42.     {
  43.         parent::Text_Wiki_Parse($obj);
  44.         $this->regex '/(\[\[((?:http:\/\/|https:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|mailto:|\/)[^\|\]\n ]*)(\|([^\]\n]*))?\]\]|((http:\/\/|https:\/\/|ftp:\/\/|gopher:\/\/|news:\/\/|mailto:)[^\'\"\n ' $this->wiki->delim . ']*[A-Za-z0-9\/\?\=\&\~\_]))/';
  45.     }
  46.  
  47.  
  48.     /**
  49.      *
  50.      * Generates a replacement for the matched text.
  51.      *
  52.      * Token options are:
  53.      *
  54.      * 'href' => the URL link href portion
  55.      *
  56.      * 'text' => the displayed text of the URL link
  57.      *
  58.      * @access public
  59.      *
  60.      * @param array &$matches The array of matches from parse().
  61.      *
  62.      * @return string A token to be used as a placeholder
  63.      *  in the source text for the preformatted text.
  64.      *
  65.      */
  66.  
  67.     function process(&$matches)
  68.     {
  69.         $href trim($matches[2]);
  70.         $text trim($matches[4]);
  71.         $rawurl $matches[5];
  72.         if ($href$href $rawurl;
  73.         if ($text$text $href;
  74.  
  75.         if (strlen($text|| $text == $href{
  76.             return $this->wiki->addToken(
  77.                 $this->rule,
  78.                 array(
  79.                     'href' => $href
  80.                 )
  81.             );
  82.         else {
  83.             return $this->wiki->addToken(
  84.                 $this->rule,
  85.                 array(
  86.                     'type' => 'start',
  87.                     'href' => $href,
  88.                     'text' => $text
  89.                 )
  90.             $text .
  91.             $this->wiki->addToken(
  92.                 $this->rule,
  93.                 array(
  94.                     'type' => 'end',
  95.                     'href' => $href,
  96.                     'text' => $text
  97.                 )
  98.             );
  99.         }
  100.     }
  101.  
  102. }
  103. ?>

Documentation generated on Mon, 11 Mar 2019 14:55:49 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.