Removed double <div> from Picasa2 album render
[tip.git] / Renderer.php
blob5e8d848fb69e9f4b64150acc3bc7f0b1dc83d46b
1 <?php
2 /* vim: set expandtab shiftwidth=4 softtabstop=4 tabstop=4 foldmethod=marker: */
4 /**
5 * Renderers collection
7 * LICENSE: This source file is subject to the New BSD license that is
8 * available through the world-wide-web at the following URI:
9 * http://www.opensource.org/licenses/bsd-license.php
10 * If you did not receive a copy of the New BSD License and are unable to
11 * obtain it through the web, please send a note to license@php.net so we
12 * can mail you a copy immediately.
14 * @author Nicola Fontana <ntd@entidi.it>
15 * @copyright Copyright &copy; 2006-2008 Nicola Fontana
16 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
17 * @package TIP
18 * @since 0.0.1
21 /**
22 * Collection of renderers used by TIP
24 * @package TIP
26 class TIP_Renderer
28 //{{{ Static methods
30 /**
31 * Get the HTML_Menu_Renderer
33 * Singleton to get the HTML_Menu_Renderer instance properly configured for
34 * the TIP system.
36 * @param int $levels Number of levels to keep online
37 * @return HTML_Menu_Renderer The renderer
39 static public function &getMenu($levels = null)
41 static $renderer = null;
43 if (is_null($renderer)) {
44 require_once 'HTML/Menu/TipRenderer.php';
45 $renderer = new HTML_Menu_TipRenderer();
48 $renderer->setLevels($levels);
49 return $renderer;
52 /**
53 * Get the Text_Wiki renderer
55 * Singleton to get the Text_Wiki instance properly configured for the
56 * TIP system. You can specify an array of rules to use in the $rules
57 * array, or leave it undefined to use all the available rules.
59 * @param array|null $rules The array of rules to enable
60 * @param string|null $toc_title TOC title or null to use a default value
61 * @param string|null $wiki_base Base URI for wiki links
62 * @return Text_Wiki The renderer
64 static public function &getWiki($rules = null, $toc_title = null, $wiki_base = '')
66 static $renderer = null;
67 static $all_rules = array(
68 'Prefilter', 'Delimiter', 'Code', 'Function', 'Html', 'Raw',
69 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', 'Break',
70 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup',
71 'Center', 'Paragraph', 'Url', 'Freelink', 'Interwiki',
72 'Wikilink', 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic',
73 'Underline', 'Tt', 'Superscript', 'Subscript', 'Revise', 'Tighten'
75 static $base_rules = array(
76 'Prefilter', 'Break', 'Paragraph', 'Tighten'
79 if (is_null($renderer)) {
80 require_once 'Text/Wiki.php';
81 isset($toc_title) || $toc_title = TIP::getLocale('index', 'wiki');
82 $renderer =& Text_Wiki::singleton('Default');
83 $renderer->disable = array();
84 $renderer->setFormatConf('Xhtml', 'charset', 'UTF-8');
85 /* According to the following comment:
86 * http://php.net/manual/function.htmlentities.php#78509
87 * "There's no sane reason to use htmlentities() instead of htmlspecialchars()"
89 $renderer->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS);
90 $renderer->setRenderConf('Xhtml', 'url', array(
91 'target' => '',
92 'regexes' => array(
93 '|http://picasaweb\.google\.com/.*/photo/.*|' => array('TIP_Renderer', 'picasa2PhotoCallback'),
94 '|http://picasaweb\.google\.com/.*/albumid/.*|' => array('TIP_Renderer', 'picasa2AlbumCallback')
96 ));
97 $renderer->setRenderConf('Xhtml', 'code', array(
98 'css' => 'programlisting'
99 ));
101 $renderer->setRenderConf('Xhtml', 'toc', array(
102 'title' => '<p><strong>' . $toc_title . '</strong></p>',
103 'div_id' => 'idToc',
104 'use_ul' => true,
105 'collapse' => false
107 $renderer->setRenderConf('Xhtml', 'freelink', array(
108 'pages' => null,
109 'view_url' => $wiki_base,
110 'new_text_pos' => null
114 if (is_array($rules)) {
115 // Capitalize the $rules values
116 $rules = array_map('ucfirst', array_map('strtolower', $rules));
117 // Join the forced rules
118 $rules = array_merge($rules, $base_rules);
119 // Get the real rules to apply
120 $rules = array_intersect($all_rules, $rules);
121 } else {
122 $rules = $base_rules;
125 $renderer->rules = $rules;
126 return $renderer;
130 * Get the HTML_QuickForm_Renderer
132 * Singleton to get the HTML_QuickForm_Renderer instance properly
133 * configured for the TIP system.
135 * @return HTML_QuickForm_Renderer The renderer
137 static public function &getForm()
139 static $renderer = null;
141 if (is_null($renderer)) {
142 require_once 'HTML/QuickForm/Renderer/Tip.php';
143 $renderer = new HTML_QuickForm_Renderer_Tip();
146 return $renderer;
150 * Render to html the URI of a picasa photo
152 * Checks if there are registered picasa2 modules and
153 * sequentially tries to render $uri by calling the
154 * toHtml() method from every picasa2 module found.
156 * @param string $uri The PicasaWeb uri
157 * @return string|false The string to render or false if not found
159 static public function picasa2PhotoCallback($uri)
161 global $cfg;
162 foreach ($cfg as $id => $options) {
163 if (end($options['type']) == 'picasa2') {
164 $instance = TIP_Type::getInstance($id);
165 $output = $instance->toHtml($uri);
166 if (is_string($output))
167 return $output;
170 return false;
174 * Render to html the URI of a picasa album feed
176 * Creates a temporary picasa2 module with $uri as
177 * data property and render the result by calling the
178 * toHtmlAlbum() method.
180 * @param string $uri The uri of the album feed
181 * @return string|false The string to render or false on errors
183 static public function picasa2AlbumCallback($uri)
185 global $cfg;
187 $id = 'picasa2::' . $uri;
188 isset($cfg[$id]) || $cfg[$id] = array(
189 'type' => array('module', 'content', 'picasa2'),
190 'data' => $uri
193 $instance = TIP_Type::getInstance($id);
194 $output = $instance->toHtmlAlbum();
196 return is_string($output) ? $output : false;
199 //}}}