Overview

Packages

  • None
  • Wicked

Classes

  • Text_Wiki_Parse_Heading2
  • Text_Wiki_Parse_Toc2
  • Text_Wiki_Render_Latex_Heading2
  • Text_Wiki_Render_Latex_Toc2
  • Text_Wiki_Render_Plain_Heading2
  • Text_Wiki_Render_Plain_Toc2
  • Text_Wiki_Render_Rst
  • Text_Wiki_Render_Rst_Blockquote
  • Text_Wiki_Render_Rst_Bold
  • Text_Wiki_Render_Rst_Code
  • Text_Wiki_Render_Rst_Deflist
  • Text_Wiki_Render_Rst_Emphasis
  • Text_Wiki_Render_Rst_Freelink
  • Text_Wiki_Render_Rst_Heading2
  • Text_Wiki_Render_Rst_Links
  • Text_Wiki_Render_Rst_List
  • Text_Wiki_Render_Rst_Newline
  • Text_Wiki_Render_Rst_Paragraph
  • Text_Wiki_Render_Rst_Raw
  • Text_Wiki_Render_Rst_Toc2
  • Text_Wiki_Render_Rst_Tt
  • Text_Wiki_Render_Rst_Url
  • Text_Wiki_Render_Xhtml_Attribute
  • Text_Wiki_Render_Xhtml_Code2
  • Text_Wiki_Render_Xhtml_Freelink2
  • Text_Wiki_Render_Xhtml_Heading2
  • Text_Wiki_Render_Xhtml_Image2
  • Text_Wiki_Render_Xhtml_Interwiki
  • Text_Wiki_Render_Xhtml_Registrylink
  • Text_Wiki_Render_Xhtml_Toc2
  • Text_Wiki_Render_Xhtml_Url
  • Text_Wiki_Render_Xhtml_Wickedblock
  • Text_Wiki_Render_Xhtml_Wikilink2
  • Wicked
  • Wicked_Api
  • Wicked_Driver
  • Wicked_Driver_Sql
  • Wicked_Exception
  • Wicked_Factory_Driver
  • Wicked_Page
  • Wicked_Page_AddPage
  • Wicked_Page_AllPages
  • Wicked_Page_AttachedFiles
  • Wicked_Page_BackLinks
  • Wicked_Page_DeletePage
  • Wicked_Page_EditPage
  • Wicked_Page_LeastPopular
  • Wicked_Page_LikePages
  • Wicked_Page_MergeOrRename
  • Wicked_Page_MostPopular
  • Wicked_Page_NewPage
  • Wicked_Page_RecentChanges
  • Wicked_Page_RevertPage
  • Wicked_Page_Search
  • Wicked_Page_StandardHistoryPage
  • Wicked_Page_StandardPage
  • Wicked_Page_SyncDiff
  • Wicked_Page_SyncPages
  • Wicked_Sync
  • Wicked_Sync_Wicked
  • Wicked_Test
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This class renders an inline image.
  4:  *
  5:  * @package Wicked
  6:  */
  7: class Text_Wiki_Render_Xhtml_Image2 extends Text_Wiki_Render
  8: {
  9:     public $conf = array(
 10:         'base' => '',
 11:         'url_base' => null,
 12:         'css'  => null,
 13:         'css_link' => null
 14:     );
 15: 
 16:     /**
 17:      * Renders a token into text matching the requested format.
 18:      *
 19:      * @param array $options  The "options" portion of the token (second
 20:      *                        element).
 21:      *
 22:      * @return string  The text rendered from the token options.
 23:      */
 24:     public function token($options)
 25:     {
 26:         if (!isset($options['attr']['alt'])) {
 27:             $options['attr']['alt'] = $options['src'];
 28:         }
 29: 
 30:         if (strpos($options['src'], '://') === false) {
 31:             if ($options['src'][0] != '/') {
 32:                 if (strpos($options['src'], ':')) {
 33:                     list($page, $options['src']) = explode(':', $options['src'], 2);
 34:                 } else {
 35:                     $page = Horde_Util::getFormData('page');
 36:                     if ($page == 'EditPage') {
 37:                         $page = Horde_Util::getFormData('referrer');
 38:                     }
 39:                     if (empty($page)) {
 40:                         $page = 'Wiki/Home';
 41:                     }
 42:                 }
 43:                 $params = array('page' => $page,
 44:                                 'mime' => '1',
 45:                                 'file' => $options['src']);
 46:                 $options['src'] = Horde_Util::addParameter(Horde::url('view.php', true),
 47:                                                      $params, null, false);
 48:             }
 49:         } else {
 50:             $options['src'] = Horde_Util::addParameter(Horde::externalUrl($options['src']), 'untrusted', 1, false);
 51:         }
 52: 
 53:         // Send external links through Horde::externalUrl().
 54:         if (isset($options['attr']['link']) && strpos($options['attr']['link'], '://')) {
 55:             $href = htmlspecialchars($options['attr']['link']);
 56:             unset($options['attr']['link']);
 57:             return Horde::link(Horde::externalUrl($href), $href) . $this->_token($options) . '</a>';
 58:         } else {
 59:             return $this->_token($options);
 60:         }
 61:     }
 62: 
 63:     /**
 64:      * Render code from Text_Wiki's Image with Horde tweaks (remove
 65:      * getimagesize call, etc).
 66:      *
 67:      * @access private
 68:      *
 69:      * @param array $options The "options" portion of the token (second
 70:      * element).
 71:      *
 72:      * @return string The text rendered from the token options.
 73:      */
 74:     protected function _token($options)
 75:     {
 76:         // note the image source
 77:         $src = $options['src'];
 78: 
 79:         // is the source a local file or URL?
 80:         if (strpos($src, '://') === false) {
 81:             // the source refers to a local file.
 82:             // add the URL base to it.
 83:             $src = $this->getConf('base', '/') . $src;
 84:         }
 85: 
 86:         // stephane@metacites.net
 87:         // is the image clickable?
 88:         if (isset($options['attr']['link'])) {
 89:             // yes, the image is clickable.
 90:             // are we linked to a URL or a wiki page?
 91:             if (strpos($options['attr']['link'], '://')) {
 92:                 // it's a URL, prefix the URL base
 93:                 $href = $this->getConf('url_base') . $options['attr']['link'];
 94:             } else {
 95:                 // it's a WikiPage; assume it exists.
 96:                 /** @todo This needs to honor sprintf wikilinks (pmjones) */
 97:                 /** @todo This needs to honor interwiki (pmjones) */
 98:                 /** @todo This needs to honor freelinks (pmjones) */
 99:                 $href = $this->wiki->getRenderConf('xhtml', 'wikilink', 'view_url') .
100:                     $options['attr']['link'];
101:             }
102:         } else {
103:             // image is not clickable.
104:             $href = null;
105:         }
106:         // unset so it won't show up as an attribute
107:         unset($options['attr']['link']);
108: 
109:         // start the HTML output
110:         $output = '<img src="' . htmlspecialchars($src) . '"';
111: 
112:         // get the CSS class but don't add it yet
113:         $css = $this->formatConf(' class="%s"', 'css');
114: 
115:         // add the attributes to the output, and be sure to
116:         // track whether or not we find an "alt" attribute
117:         $alt = false;
118:         foreach ($options['attr'] as $key => $val) {
119: 
120:             // track the 'alt' attribute
121:             if (strtolower($key) == 'alt') {
122:                 $alt = true;
123:             }
124: 
125:             // the 'class' attribute overrides the CSS class conf
126:             if (strtolower($key) == 'class') {
127:                 $css = null;
128:             }
129: 
130:             $key = htmlspecialchars($key);
131:             $val = htmlspecialchars($val);
132:             $output .= " $key=\"$val\"";
133:         }
134: 
135:         // always add an "alt" attribute per Stephane Solliec
136:         if (!$alt) {
137:             $alt = htmlspecialchars(basename($options['src']));
138:             $output .= " alt=\"$alt\"";
139:         }
140: 
141:         // end the image tag with the automatic CSS class (if any)
142:         $output .= "$css />";
143: 
144:         // was the image clickable?
145:         if ($href) {
146:             // yes, add the href and return
147:             $href = htmlspecialchars($href);
148:             $css = $this->formatConf(' class="%s"', 'css_link');
149:             $output = "<a$css href=\"$href\">$output</a>";
150:         }
151: 
152:         return $output;
153:     }
154: }
155: 
API documentation generated by ApiGen