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 293784 2010-01-20 18:48:09Z justinpatrin $
  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 '/((?:\[\[ *((?:\w+:\/\/|mailto:|\/)[^\|\]\n ]*)( *\| *([^\]\n]*))? *\]\])|((?<=[^\~\w])(https?:\/\/|ftps?:\/\/|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.         if (isset($matches[2])) $href trim($matches[2]);
  70.         if (isset($matches[4])) $text trim($matches[4]);
  71.         if (isset($matches[5])) $rawurl $matches[5];
  72.         if (empty($href)) $href $rawurl;
  73.  
  74.         if (empty($text)) {
  75.             $text $href;
  76.             if (strpos($text'/'=== FALSE{
  77.                 $text str_replace('http://'''$text);
  78.                 $text str_replace('mailto:'''$text);
  79.             }
  80.             return $this->wiki->addToken(
  81.                 $this->rule,
  82.                 array(
  83.                     'type' => 'inline',
  84.                     'href' => $href,
  85.                     'text' => $text
  86.                 )
  87.             );
  88.         else {
  89.             return $this->wiki->addToken(
  90.                 $this->rule,
  91.                 array(
  92.                     'type' => 'start',
  93.                     'href' => $href,
  94.                     'text' => $text
  95.                 )
  96.             $text .
  97.             $this->wiki->addToken(
  98.                 $this->rule,
  99.                 array(
  100.                     'type' => 'end',
  101.                     'href' => $href,
  102.                     'text' => $text
  103.                 )
  104.             );
  105.         }
  106.     }
  107.  
  108. }
  109. ?>

Documentation generated on Mon, 11 Mar 2019 15:40:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.