Complex classes like Doku_Renderer_xhtml often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Doku_Renderer_xhtml, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Doku_Renderer_xhtml extends Doku_Renderer { |
||
| 26 | /** @var array store the table of contents */ |
||
| 27 | public $toc = array(); |
||
| 28 | |||
| 29 | /** @var array A stack of section edit data */ |
||
| 30 | protected $sectionedits = array(); |
||
| 31 | var $date_at = ''; // link pages and media against this revision |
||
| 32 | |||
| 33 | /** @var int last section edit id, used by startSectionEdit */ |
||
| 34 | protected $lastsecid = 0; |
||
| 35 | |||
| 36 | /** @var array the list of headers used to create unique link ids */ |
||
| 37 | protected $headers = array(); |
||
| 38 | |||
| 39 | /** @var array a list of footnotes, list starts at 1! */ |
||
| 40 | protected $footnotes = array(); |
||
| 41 | |||
| 42 | /** @var int current section level */ |
||
| 43 | protected $lastlevel = 0; |
||
| 44 | /** @var array section node tracker */ |
||
| 45 | protected $node = array(0, 0, 0, 0, 0); |
||
| 46 | |||
| 47 | /** @var string temporary $doc store */ |
||
| 48 | protected $store = ''; |
||
| 49 | |||
| 50 | /** @var array global counter, for table classes etc. */ |
||
| 51 | protected $_counter = array(); // |
||
| 52 | |||
| 53 | /** @var int counts the code and file blocks, used to provide download links */ |
||
| 54 | protected $_codeblock = 0; |
||
| 55 | |||
| 56 | /** @var array list of allowed URL schemes */ |
||
| 57 | protected $schemes = null; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Register a new edit section range |
||
| 61 | * |
||
| 62 | * @param string $type The section type identifier |
||
| 63 | * @param string $title The section title |
||
| 64 | * @param int $start The byte position for the edit start |
||
| 65 | * @return string A marker class for the starting HTML element |
||
| 66 | * |
||
| 67 | * @author Adrian Lang <[email protected]> |
||
| 68 | */ |
||
| 69 | public function startSectionEdit($start, $type, $title = null) { |
||
| 70 | $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title); |
||
| 71 | return 'sectionedit'.$this->lastsecid; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Finish an edit section range |
||
| 76 | * |
||
| 77 | * @param int $end The byte position for the edit end; null for the rest of the page |
||
| 78 | * |
||
| 79 | * @author Adrian Lang <[email protected]> |
||
| 80 | */ |
||
| 81 | public function finishSectionEdit($end = null) { |
||
| 82 | list($id, $start, $type, $title) = array_pop($this->sectionedits); |
||
| 83 | if(!is_null($end) && $end <= $start) { |
||
| 84 | return; |
||
| 85 | } |
||
| 86 | $this->doc .= "<!-- EDIT$id ".strtoupper($type).' '; |
||
| 87 | if(!is_null($title)) { |
||
| 88 | $this->doc .= '"'.str_replace('"', '', $title).'" '; |
||
| 89 | } |
||
| 90 | $this->doc .= "[$start-".(is_null($end) ? '' : $end).'] -->'; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Returns the format produced by this renderer. |
||
| 95 | * |
||
| 96 | * @return string always 'xhtml' |
||
| 97 | */ |
||
| 98 | function getFormat() { |
||
|
|
|||
| 99 | return 'xhtml'; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Initialize the document |
||
| 104 | */ |
||
| 105 | function document_start() { |
||
| 106 | //reset some internals |
||
| 107 | $this->toc = array(); |
||
| 108 | $this->headers = array(); |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Finalize the document |
||
| 113 | */ |
||
| 114 | function document_end() { |
||
| 115 | // Finish open section edits. |
||
| 116 | while(count($this->sectionedits) > 0) { |
||
| 117 | if($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { |
||
| 118 | // If there is only one section, do not write a section edit |
||
| 119 | // marker. |
||
| 120 | array_pop($this->sectionedits); |
||
| 121 | } else { |
||
| 122 | $this->finishSectionEdit(); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if(count($this->footnotes) > 0) { |
||
| 127 | $this->doc .= '<div class="footnotes">'.DOKU_LF; |
||
| 128 | |||
| 129 | foreach($this->footnotes as $id => $footnote) { |
||
| 130 | // check its not a placeholder that indicates actual footnote text is elsewhere |
||
| 131 | if(substr($footnote, 0, 5) != "@@FNT") { |
||
| 132 | |||
| 133 | // open the footnote and set the anchor and backlink |
||
| 134 | $this->doc .= '<div class="fn">'; |
||
| 135 | $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">'; |
||
| 136 | $this->doc .= $id.')</a></sup> '.DOKU_LF; |
||
| 137 | |||
| 138 | // get any other footnotes that use the same markup |
||
| 139 | $alt = array_keys($this->footnotes, "@@FNT$id"); |
||
| 140 | |||
| 141 | if(count($alt)) { |
||
| 142 | foreach($alt as $ref) { |
||
| 143 | // set anchor and backlink for the other footnotes |
||
| 144 | $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">'; |
||
| 145 | $this->doc .= ($ref).')</a></sup> '.DOKU_LF; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | // add footnote markup and close this footnote |
||
| 150 | $this->doc .= $footnote; |
||
| 151 | $this->doc .= '</div>'.DOKU_LF; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | $this->doc .= '</div>'.DOKU_LF; |
||
| 155 | } |
||
| 156 | |||
| 157 | // Prepare the TOC |
||
| 158 | global $conf; |
||
| 159 | if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']) { |
||
| 160 | global $TOC; |
||
| 161 | $TOC = $this->toc; |
||
| 162 | } |
||
| 163 | |||
| 164 | // make sure there are no empty paragraphs |
||
| 165 | $this->doc = preg_replace('#<p>\s*</p>#', '', $this->doc); |
||
| 166 | } |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Add an item to the TOC |
||
| 170 | * |
||
| 171 | * @param string $id the hash link |
||
| 172 | * @param string $text the text to display |
||
| 173 | * @param int $level the nesting level |
||
| 174 | */ |
||
| 175 | function toc_additem($id, $text, $level) { |
||
| 176 | global $conf; |
||
| 177 | |||
| 178 | //handle TOC |
||
| 179 | if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) { |
||
| 180 | $this->toc[] = html_mktocitem($id, $text, $level - $conf['toptoclevel'] + 1); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Render a heading |
||
| 186 | * |
||
| 187 | * @param string $text the text to display |
||
| 188 | * @param int $level header level |
||
| 189 | * @param int $pos byte position in the original source |
||
| 190 | */ |
||
| 191 | function header($text, $level, $pos) { |
||
| 192 | global $conf; |
||
| 193 | |||
| 194 | if(!$text) return; //skip empty headlines |
||
| 195 | |||
| 196 | $hid = $this->_headerToLink($text, true); |
||
| 197 | |||
| 198 | //only add items within configured levels |
||
| 199 | $this->toc_additem($hid, $text, $level); |
||
| 200 | |||
| 201 | // adjust $node to reflect hierarchy of levels |
||
| 202 | $this->node[$level - 1]++; |
||
| 203 | if($level < $this->lastlevel) { |
||
| 204 | for($i = 0; $i < $this->lastlevel - $level; $i++) { |
||
| 205 | $this->node[$this->lastlevel - $i - 1] = 0; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | $this->lastlevel = $level; |
||
| 209 | |||
| 210 | if($level <= $conf['maxseclevel'] && |
||
| 211 | count($this->sectionedits) > 0 && |
||
| 212 | $this->sectionedits[count($this->sectionedits) - 1][2] === 'section' |
||
| 213 | ) { |
||
| 214 | $this->finishSectionEdit($pos - 1); |
||
| 215 | } |
||
| 216 | |||
| 217 | // write the header |
||
| 218 | $this->doc .= DOKU_LF.'<h'.$level; |
||
| 219 | if($level <= $conf['maxseclevel']) { |
||
| 220 | $this->doc .= ' class="'.$this->startSectionEdit($pos, 'section', $text).'"'; |
||
| 221 | } |
||
| 222 | $this->doc .= ' id="'.$hid.'">'; |
||
| 223 | $this->doc .= $this->_xmlEntities($text); |
||
| 224 | $this->doc .= "</h$level>".DOKU_LF; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Open a new section |
||
| 229 | * |
||
| 230 | * @param int $level section level (as determined by the previous header) |
||
| 231 | */ |
||
| 232 | function section_open($level) { |
||
| 233 | $this->doc .= '<div class="level'.$level.'">'.DOKU_LF; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Close the current section |
||
| 238 | */ |
||
| 239 | function section_close() { |
||
| 240 | $this->doc .= DOKU_LF.'</div>'.DOKU_LF; |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Render plain text data |
||
| 245 | * |
||
| 246 | * @param $text |
||
| 247 | */ |
||
| 248 | function cdata($text) { |
||
| 249 | $this->doc .= $this->_xmlEntities($text); |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Open a paragraph |
||
| 254 | */ |
||
| 255 | function p_open() { |
||
| 256 | $this->doc .= DOKU_LF.'<p>'.DOKU_LF; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Close a paragraph |
||
| 261 | */ |
||
| 262 | function p_close() { |
||
| 263 | $this->doc .= DOKU_LF.'</p>'.DOKU_LF; |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Create a line break |
||
| 268 | */ |
||
| 269 | function linebreak() { |
||
| 270 | $this->doc .= '<br/>'.DOKU_LF; |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Create a horizontal line |
||
| 275 | */ |
||
| 276 | function hr() { |
||
| 277 | $this->doc .= '<hr />'.DOKU_LF; |
||
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Start strong (bold) formatting |
||
| 282 | */ |
||
| 283 | function strong_open() { |
||
| 284 | $this->doc .= '<strong>'; |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Stop strong (bold) formatting |
||
| 289 | */ |
||
| 290 | function strong_close() { |
||
| 291 | $this->doc .= '</strong>'; |
||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Start emphasis (italics) formatting |
||
| 296 | */ |
||
| 297 | function emphasis_open() { |
||
| 298 | $this->doc .= '<em>'; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Stop emphasis (italics) formatting |
||
| 303 | */ |
||
| 304 | function emphasis_close() { |
||
| 305 | $this->doc .= '</em>'; |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Start underline formatting |
||
| 310 | */ |
||
| 311 | function underline_open() { |
||
| 312 | $this->doc .= '<em class="u">'; |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Stop underline formatting |
||
| 317 | */ |
||
| 318 | function underline_close() { |
||
| 319 | $this->doc .= '</em>'; |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Start monospace formatting |
||
| 324 | */ |
||
| 325 | function monospace_open() { |
||
| 326 | $this->doc .= '<code>'; |
||
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Stop monospace formatting |
||
| 331 | */ |
||
| 332 | function monospace_close() { |
||
| 333 | $this->doc .= '</code>'; |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Start a subscript |
||
| 338 | */ |
||
| 339 | function subscript_open() { |
||
| 340 | $this->doc .= '<sub>'; |
||
| 341 | } |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Stop a subscript |
||
| 345 | */ |
||
| 346 | function subscript_close() { |
||
| 347 | $this->doc .= '</sub>'; |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Start a superscript |
||
| 352 | */ |
||
| 353 | function superscript_open() { |
||
| 354 | $this->doc .= '<sup>'; |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Stop a superscript |
||
| 359 | */ |
||
| 360 | function superscript_close() { |
||
| 361 | $this->doc .= '</sup>'; |
||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Start deleted (strike-through) formatting |
||
| 366 | */ |
||
| 367 | function deleted_open() { |
||
| 368 | $this->doc .= '<del>'; |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Stop deleted (strike-through) formatting |
||
| 373 | */ |
||
| 374 | function deleted_close() { |
||
| 375 | $this->doc .= '</del>'; |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Callback for footnote start syntax |
||
| 380 | * |
||
| 381 | * All following content will go to the footnote instead of |
||
| 382 | * the document. To achieve this the previous rendered content |
||
| 383 | * is moved to $store and $doc is cleared |
||
| 384 | * |
||
| 385 | * @author Andreas Gohr <[email protected]> |
||
| 386 | */ |
||
| 387 | function footnote_open() { |
||
| 388 | |||
| 389 | // move current content to store and record footnote |
||
| 390 | $this->store = $this->doc; |
||
| 391 | $this->doc = ''; |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Callback for footnote end syntax |
||
| 396 | * |
||
| 397 | * All rendered content is moved to the $footnotes array and the old |
||
| 398 | * content is restored from $store again |
||
| 399 | * |
||
| 400 | * @author Andreas Gohr |
||
| 401 | */ |
||
| 402 | function footnote_close() { |
||
| 403 | /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */ |
||
| 404 | static $fnid = 0; |
||
| 405 | // assign new footnote id (we start at 1) |
||
| 406 | $fnid++; |
||
| 407 | |||
| 408 | // recover footnote into the stack and restore old content |
||
| 409 | $footnote = $this->doc; |
||
| 410 | $this->doc = $this->store; |
||
| 411 | $this->store = ''; |
||
| 412 | |||
| 413 | // check to see if this footnote has been seen before |
||
| 414 | $i = array_search($footnote, $this->footnotes); |
||
| 415 | |||
| 416 | if($i === false) { |
||
| 417 | // its a new footnote, add it to the $footnotes array |
||
| 418 | $this->footnotes[$fnid] = $footnote; |
||
| 419 | } else { |
||
| 420 | // seen this one before, save a placeholder |
||
| 421 | $this->footnotes[$fnid] = "@@FNT".($i); |
||
| 422 | } |
||
| 423 | |||
| 424 | // output the footnote reference and link |
||
| 425 | $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>'; |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Open an unordered list |
||
| 430 | */ |
||
| 431 | function listu_open() { |
||
| 432 | $this->doc .= '<ul>'.DOKU_LF; |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Close an unordered list |
||
| 437 | */ |
||
| 438 | function listu_close() { |
||
| 439 | $this->doc .= '</ul>'.DOKU_LF; |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Open an ordered list |
||
| 444 | */ |
||
| 445 | function listo_open() { |
||
| 446 | $this->doc .= '<ol>'.DOKU_LF; |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Close an ordered list |
||
| 451 | */ |
||
| 452 | function listo_close() { |
||
| 453 | $this->doc .= '</ol>'.DOKU_LF; |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Open a list item |
||
| 458 | * |
||
| 459 | * @param int $level the nesting level |
||
| 460 | * @param bool $node true when a node; false when a leaf |
||
| 461 | */ |
||
| 462 | function listitem_open($level, $node=false) { |
||
| 463 | $branching = $node ? ' node' : ''; |
||
| 464 | $this->doc .= '<li class="level'.$level.$branching.'">'; |
||
| 465 | } |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Close a list item |
||
| 469 | */ |
||
| 470 | function listitem_close() { |
||
| 471 | $this->doc .= '</li>'.DOKU_LF; |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Start the content of a list item |
||
| 476 | */ |
||
| 477 | function listcontent_open() { |
||
| 478 | $this->doc .= '<div class="li">'; |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Stop the content of a list item |
||
| 483 | */ |
||
| 484 | function listcontent_close() { |
||
| 485 | $this->doc .= '</div>'.DOKU_LF; |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Output unformatted $text |
||
| 490 | * |
||
| 491 | * Defaults to $this->cdata() |
||
| 492 | * |
||
| 493 | * @param string $text |
||
| 494 | */ |
||
| 495 | function unformatted($text) { |
||
| 496 | $this->doc .= $this->_xmlEntities($text); |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Execute PHP code if allowed |
||
| 501 | * |
||
| 502 | * @param string $text PHP code that is either executed or printed |
||
| 503 | * @param string $wrapper html element to wrap result if $conf['phpok'] is okff |
||
| 504 | * |
||
| 505 | * @author Andreas Gohr <[email protected]> |
||
| 506 | */ |
||
| 507 | function php($text, $wrapper = 'code') { |
||
| 508 | global $conf; |
||
| 509 | |||
| 510 | if($conf['phpok']) { |
||
| 511 | ob_start(); |
||
| 512 | eval($text); |
||
| 513 | $this->doc .= ob_get_contents(); |
||
| 514 | ob_end_clean(); |
||
| 515 | } else { |
||
| 516 | $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); |
||
| 517 | } |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Output block level PHP code |
||
| 522 | * |
||
| 523 | * If $conf['phpok'] is true this should evaluate the given code and append the result |
||
| 524 | * to $doc |
||
| 525 | * |
||
| 526 | * @param string $text The PHP code |
||
| 527 | */ |
||
| 528 | function phpblock($text) { |
||
| 529 | $this->php($text, 'pre'); |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Insert HTML if allowed |
||
| 534 | * |
||
| 535 | * @param string $text html text |
||
| 536 | * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff |
||
| 537 | * |
||
| 538 | * @author Andreas Gohr <[email protected]> |
||
| 539 | */ |
||
| 540 | function html($text, $wrapper = 'code') { |
||
| 541 | global $conf; |
||
| 542 | |||
| 543 | if($conf['htmlok']) { |
||
| 544 | $this->doc .= $text; |
||
| 545 | } else { |
||
| 546 | $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); |
||
| 547 | } |
||
| 548 | } |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Output raw block-level HTML |
||
| 552 | * |
||
| 553 | * If $conf['htmlok'] is true this should add the code as is to $doc |
||
| 554 | * |
||
| 555 | * @param string $text The HTML |
||
| 556 | */ |
||
| 557 | function htmlblock($text) { |
||
| 558 | $this->html($text, 'pre'); |
||
| 559 | } |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Start a block quote |
||
| 563 | */ |
||
| 564 | function quote_open() { |
||
| 565 | $this->doc .= '<blockquote><div class="no">'.DOKU_LF; |
||
| 566 | } |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Stop a block quote |
||
| 570 | */ |
||
| 571 | function quote_close() { |
||
| 572 | $this->doc .= '</div></blockquote>'.DOKU_LF; |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Output preformatted text |
||
| 577 | * |
||
| 578 | * @param string $text |
||
| 579 | */ |
||
| 580 | function preformatted($text) { |
||
| 581 | $this->doc .= '<pre class="code">'.trim($this->_xmlEntities($text), "\n\r").'</pre>'.DOKU_LF; |
||
| 582 | } |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Display text as file content, optionally syntax highlighted |
||
| 586 | * |
||
| 587 | * @param string $text text to show |
||
| 588 | * @param string $language programming language to use for syntax highlighting |
||
| 589 | * @param string $filename file path label |
||
| 590 | */ |
||
| 591 | function file($text, $language = null, $filename = null) { |
||
| 592 | $this->_highlight('file', $text, $language, $filename); |
||
| 593 | } |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Display text as code content, optionally syntax highlighted |
||
| 597 | * |
||
| 598 | * @param string $text text to show |
||
| 599 | * @param string $language programming language to use for syntax highlighting |
||
| 600 | * @param string $filename file path label |
||
| 601 | */ |
||
| 602 | function code($text, $language = null, $filename = null) { |
||
| 603 | $this->_highlight('code', $text, $language, $filename); |
||
| 604 | } |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Use GeSHi to highlight language syntax in code and file blocks |
||
| 608 | * |
||
| 609 | * @author Andreas Gohr <[email protected]> |
||
| 610 | * @param string $type code|file |
||
| 611 | * @param string $text text to show |
||
| 612 | * @param string $language programming language to use for syntax highlighting |
||
| 613 | * @param string $filename file path label |
||
| 614 | */ |
||
| 615 | function _highlight($type, $text, $language = null, $filename = null) { |
||
| 616 | global $ID; |
||
| 617 | global $lang; |
||
| 618 | |||
| 619 | if($filename) { |
||
| 620 | // add icon |
||
| 621 | list($ext) = mimetype($filename, false); |
||
| 622 | $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); |
||
| 623 | $class = 'mediafile mf_'.$class; |
||
| 624 | |||
| 625 | $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; |
||
| 626 | $this->doc .= '<dt><a href="'.exportlink($ID, 'code', array('codeblock' => $this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; |
||
| 627 | $this->doc .= hsc($filename); |
||
| 628 | $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; |
||
| 629 | } |
||
| 630 | |||
| 631 | if($text{0} == "\n") { |
||
| 632 | $text = substr($text, 1); |
||
| 633 | } |
||
| 634 | if(substr($text, -1) == "\n") { |
||
| 635 | $text = substr($text, 0, -1); |
||
| 636 | } |
||
| 637 | |||
| 638 | if(is_null($language)) { |
||
| 639 | $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; |
||
| 640 | } else { |
||
| 641 | $class = 'code'; //we always need the code class to make the syntax highlighting apply |
||
| 642 | if($type != 'code') $class .= ' '.$type; |
||
| 643 | |||
| 644 | $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; |
||
| 645 | } |
||
| 646 | |||
| 647 | if($filename) { |
||
| 648 | $this->doc .= '</dd></dl>'.DOKU_LF; |
||
| 649 | } |
||
| 650 | |||
| 651 | $this->_codeblock++; |
||
| 652 | } |
||
| 653 | |||
| 654 | /** |
||
| 655 | * Format an acronym |
||
| 656 | * |
||
| 657 | * Uses $this->acronyms |
||
| 658 | * |
||
| 659 | * @param string $acronym |
||
| 660 | */ |
||
| 661 | function acronym($acronym) { |
||
| 662 | |||
| 663 | if(array_key_exists($acronym, $this->acronyms)) { |
||
| 664 | |||
| 665 | $title = $this->_xmlEntities($this->acronyms[$acronym]); |
||
| 666 | |||
| 667 | $this->doc .= '<abbr title="'.$title |
||
| 668 | .'">'.$this->_xmlEntities($acronym).'</abbr>'; |
||
| 669 | |||
| 670 | } else { |
||
| 671 | $this->doc .= $this->_xmlEntities($acronym); |
||
| 672 | } |
||
| 673 | } |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Format a smiley |
||
| 677 | * |
||
| 678 | * Uses $this->smiley |
||
| 679 | * |
||
| 680 | * @param string $smiley |
||
| 681 | */ |
||
| 682 | function smiley($smiley) { |
||
| 683 | if(array_key_exists($smiley, $this->smileys)) { |
||
| 684 | $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. |
||
| 685 | '" class="icon" alt="'. |
||
| 686 | $this->_xmlEntities($smiley).'" />'; |
||
| 687 | } else { |
||
| 688 | $this->doc .= $this->_xmlEntities($smiley); |
||
| 689 | } |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Format an entity |
||
| 694 | * |
||
| 695 | * Entities are basically small text replacements |
||
| 696 | * |
||
| 697 | * Uses $this->entities |
||
| 698 | * |
||
| 699 | * @param string $entity |
||
| 700 | */ |
||
| 701 | function entity($entity) { |
||
| 702 | if(array_key_exists($entity, $this->entities)) { |
||
| 703 | $this->doc .= $this->entities[$entity]; |
||
| 704 | } else { |
||
| 705 | $this->doc .= $this->_xmlEntities($entity); |
||
| 706 | } |
||
| 707 | } |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Typographically format a multiply sign |
||
| 711 | * |
||
| 712 | * Example: ($x=640, $y=480) should result in "640×480" |
||
| 713 | * |
||
| 714 | * @param string|int $x first value |
||
| 715 | * @param string|int $y second value |
||
| 716 | */ |
||
| 717 | function multiplyentity($x, $y) { |
||
| 718 | $this->doc .= "$x×$y"; |
||
| 719 | } |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Render an opening single quote char (language specific) |
||
| 723 | */ |
||
| 724 | function singlequoteopening() { |
||
| 725 | global $lang; |
||
| 726 | $this->doc .= $lang['singlequoteopening']; |
||
| 727 | } |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Render a closing single quote char (language specific) |
||
| 731 | */ |
||
| 732 | function singlequoteclosing() { |
||
| 733 | global $lang; |
||
| 734 | $this->doc .= $lang['singlequoteclosing']; |
||
| 735 | } |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Render an apostrophe char (language specific) |
||
| 739 | */ |
||
| 740 | function apostrophe() { |
||
| 741 | global $lang; |
||
| 742 | $this->doc .= $lang['apostrophe']; |
||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Render an opening double quote char (language specific) |
||
| 747 | */ |
||
| 748 | function doublequoteopening() { |
||
| 749 | global $lang; |
||
| 750 | $this->doc .= $lang['doublequoteopening']; |
||
| 751 | } |
||
| 752 | |||
| 753 | /** |
||
| 754 | * Render an closinging double quote char (language specific) |
||
| 755 | */ |
||
| 756 | function doublequoteclosing() { |
||
| 757 | global $lang; |
||
| 758 | $this->doc .= $lang['doublequoteclosing']; |
||
| 759 | } |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Render a CamelCase link |
||
| 763 | * |
||
| 764 | * @param string $link The link name |
||
| 765 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 766 | * @see http://en.wikipedia.org/wiki/CamelCase |
||
| 767 | */ |
||
| 768 | function camelcaselink($link, $returnonly = false) { |
||
| 769 | if($returnonly) { |
||
| 770 | return $this->internallink($link, $link, null, true); |
||
| 771 | } else { |
||
| 772 | $this->internallink($link, $link); |
||
| 773 | } |
||
| 774 | } |
||
| 775 | |||
| 776 | /** |
||
| 777 | * Render a page local link |
||
| 778 | * |
||
| 779 | * @param string $hash hash link identifier |
||
| 780 | * @param string $name name for the link |
||
| 781 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 782 | */ |
||
| 783 | function locallink($hash, $name = null, $returnonly = false) { |
||
| 784 | global $ID; |
||
| 785 | $name = $this->_getLinkTitle($name, $hash, $isImage); |
||
| 786 | $hash = $this->_headerToLink($hash); |
||
| 787 | $title = $ID.' ↵'; |
||
| 788 | |||
| 789 | $doc = '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; |
||
| 790 | $doc .= $name; |
||
| 791 | $doc .= '</a>'; |
||
| 792 | |||
| 793 | if($returnonly) { |
||
| 794 | return $doc; |
||
| 795 | } else { |
||
| 796 | $this->doc .= $doc; |
||
| 797 | } |
||
| 798 | } |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Render an internal Wiki Link |
||
| 802 | * |
||
| 803 | * $search,$returnonly & $linktype are not for the renderer but are used |
||
| 804 | * elsewhere - no need to implement them in other renderers |
||
| 805 | * |
||
| 806 | * @author Andreas Gohr <[email protected]> |
||
| 807 | * @param string $id pageid |
||
| 808 | * @param string|null $name link name |
||
| 809 | * @param string|null $search adds search url param |
||
| 810 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 811 | * @param string $linktype type to set use of headings |
||
| 812 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 813 | */ |
||
| 814 | function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { |
||
| 815 | global $conf; |
||
| 816 | global $ID; |
||
| 817 | global $INFO; |
||
| 818 | |||
| 819 | $params = ''; |
||
| 820 | $parts = explode('?', $id, 2); |
||
| 821 | if(count($parts) === 2) { |
||
| 822 | $id = $parts[0]; |
||
| 823 | $params = $parts[1]; |
||
| 824 | } |
||
| 825 | |||
| 826 | // For empty $id we need to know the current $ID |
||
| 827 | // We need this check because _simpleTitle needs |
||
| 828 | // correct $id and resolve_pageid() use cleanID($id) |
||
| 829 | // (some things could be lost) |
||
| 830 | if($id === '') { |
||
| 831 | $id = $ID; |
||
| 832 | } |
||
| 833 | |||
| 834 | // default name is based on $id as given |
||
| 835 | $default = $this->_simpleTitle($id); |
||
| 836 | |||
| 837 | // now first resolve and clean up the $id |
||
| 838 | resolve_pageid(getNS($ID), $id, $exists, $this->date_at, true); |
||
| 839 | |||
| 840 | $link = array(); |
||
| 841 | $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); |
||
| 842 | if(!$isImage) { |
||
| 843 | if($exists) { |
||
| 844 | $class = 'wikilink1'; |
||
| 845 | } else { |
||
| 846 | $class = 'wikilink2'; |
||
| 847 | $link['rel'] = 'nofollow'; |
||
| 848 | } |
||
| 849 | } else { |
||
| 850 | $class = 'media'; |
||
| 851 | } |
||
| 852 | |||
| 853 | //keep hash anchor |
||
| 854 | @list($id, $hash) = explode('#', $id, 2); |
||
|
1 ignored issue
–
show
|
|||
| 855 | if(!empty($hash)) $hash = $this->_headerToLink($hash); |
||
| 856 | |||
| 857 | //prepare for formating |
||
| 858 | $link['target'] = $conf['target']['wiki']; |
||
| 859 | $link['style'] = ''; |
||
| 860 | $link['pre'] = ''; |
||
| 861 | $link['suf'] = ''; |
||
| 862 | // highlight link to current page |
||
| 863 | if($id == $INFO['id']) { |
||
| 864 | $link['pre'] = '<span class="curid">'; |
||
| 865 | $link['suf'] = '</span>'; |
||
| 866 | } |
||
| 867 | $link['more'] = ''; |
||
| 868 | $link['class'] = $class; |
||
| 869 | if($this->date_at) { |
||
| 870 | $params['at'] = $this->date_at; |
||
| 871 | } |
||
| 872 | $link['url'] = wl($id, $params); |
||
| 873 | $link['name'] = $name; |
||
| 874 | $link['title'] = $id; |
||
| 875 | //add search string |
||
| 876 | if($search) { |
||
| 877 | ($conf['userewrite']) ? $link['url'] .= '?' : $link['url'] .= '&'; |
||
| 878 | if(is_array($search)) { |
||
| 879 | $search = array_map('rawurlencode', $search); |
||
| 880 | $link['url'] .= 's[]='.join('&s[]=', $search); |
||
| 881 | } else { |
||
| 882 | $link['url'] .= 's='.rawurlencode($search); |
||
| 883 | } |
||
| 884 | } |
||
| 885 | |||
| 886 | //keep hash |
||
| 887 | if($hash) $link['url'] .= '#'.$hash; |
||
| 888 | |||
| 889 | //output formatted |
||
| 890 | if($returnonly) { |
||
| 891 | return $this->_formatLink($link); |
||
| 892 | } else { |
||
| 893 | $this->doc .= $this->_formatLink($link); |
||
| 894 | } |
||
| 895 | } |
||
| 896 | |||
| 897 | /** |
||
| 898 | * Render an external link |
||
| 899 | * |
||
| 900 | * @param string $url full URL with scheme |
||
| 901 | * @param string|array $name name for the link, array for media file |
||
| 902 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 903 | */ |
||
| 904 | function externallink($url, $name = null, $returnonly = false) { |
||
| 955 | |||
| 956 | /** |
||
| 957 | * Render an interwiki link |
||
| 958 | * |
||
| 959 | * You may want to use $this->_resolveInterWiki() here |
||
| 960 | * |
||
| 961 | * @param string $match original link - probably not much use |
||
| 962 | * @param string|array $name name for the link, array for media file |
||
| 963 | * @param string $wikiName indentifier (shortcut) for the remote wiki |
||
| 964 | * @param string $wikiUri the fragment parsed from the original link |
||
| 965 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 966 | */ |
||
| 967 | function interwikilink($match, $name = null, $wikiName, $wikiUri, $returnonly = false) { |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * Link to windows share |
||
| 1016 | * |
||
| 1017 | * @param string $url the link |
||
| 1018 | * @param string|array $name name for the link, array for media file |
||
| 1019 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1020 | */ |
||
| 1021 | function windowssharelink($url, $name = null, $returnonly = false) { |
||
| 1022 | global $conf; |
||
| 1023 | |||
| 1024 | //simple setup |
||
| 1025 | $link = array(); |
||
| 1026 | $link['target'] = $conf['target']['windows']; |
||
| 1027 | $link['pre'] = ''; |
||
| 1028 | $link['suf'] = ''; |
||
| 1029 | $link['style'] = ''; |
||
| 1030 | |||
| 1031 | $link['name'] = $this->_getLinkTitle($name, $url, $isImage); |
||
| 1032 | if(!$isImage) { |
||
| 1033 | $link['class'] = 'windows'; |
||
| 1034 | } else { |
||
| 1035 | $link['class'] = 'media'; |
||
| 1036 | } |
||
| 1037 | |||
| 1038 | $link['title'] = $this->_xmlEntities($url); |
||
| 1039 | $url = str_replace('\\', '/', $url); |
||
| 1040 | $url = 'file:///'.$url; |
||
| 1041 | $link['url'] = $url; |
||
| 1042 | |||
| 1043 | //output formatted |
||
| 1044 | if($returnonly) { |
||
| 1045 | return $this->_formatLink($link); |
||
| 1046 | } else { |
||
| 1047 | $this->doc .= $this->_formatLink($link); |
||
| 1048 | } |
||
| 1049 | } |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Render a linked E-Mail Address |
||
| 1053 | * |
||
| 1054 | * Honors $conf['mailguard'] setting |
||
| 1055 | * |
||
| 1056 | * @param string $address Email-Address |
||
| 1057 | * @param string|array $name name for the link, array for media file |
||
| 1058 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1059 | */ |
||
| 1060 | function emaillink($address, $name = null, $returnonly = false) { |
||
| 1061 | global $conf; |
||
| 1062 | //simple setup |
||
| 1063 | $link = array(); |
||
| 1064 | $link['target'] = ''; |
||
| 1065 | $link['pre'] = ''; |
||
| 1066 | $link['suf'] = ''; |
||
| 1067 | $link['style'] = ''; |
||
| 1068 | $link['more'] = ''; |
||
| 1069 | |||
| 1070 | $name = $this->_getLinkTitle($name, '', $isImage); |
||
| 1071 | if(!$isImage) { |
||
| 1072 | $link['class'] = 'mail'; |
||
| 1073 | } else { |
||
| 1074 | $link['class'] = 'media'; |
||
| 1075 | } |
||
| 1076 | |||
| 1077 | $address = $this->_xmlEntities($address); |
||
| 1078 | $address = obfuscate($address); |
||
| 1079 | $title = $address; |
||
| 1080 | |||
| 1081 | if(empty($name)) { |
||
| 1082 | $name = $address; |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | if($conf['mailguard'] == 'visible') $address = rawurlencode($address); |
||
| 1086 | |||
| 1087 | $link['url'] = 'mailto:'.$address; |
||
| 1088 | $link['name'] = $name; |
||
| 1089 | $link['title'] = $title; |
||
| 1090 | |||
| 1091 | //output formatted |
||
| 1092 | if($returnonly) { |
||
| 1093 | return $this->_formatLink($link); |
||
| 1094 | } else { |
||
| 1095 | $this->doc .= $this->_formatLink($link); |
||
| 1096 | } |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * Render an internal media file |
||
| 1101 | * |
||
| 1102 | * @param string $src media ID |
||
| 1103 | * @param string $title descriptive text |
||
| 1104 | * @param string $align left|center|right |
||
| 1105 | * @param int $width width of media in pixel |
||
| 1106 | * @param int $height height of media in pixel |
||
| 1107 | * @param string $cache cache|recache|nocache |
||
| 1108 | * @param string $linking linkonly|detail|nolink |
||
| 1109 | * @param bool $return return HTML instead of adding to $doc |
||
| 1110 | * @return void|string |
||
| 1111 | */ |
||
| 1112 | function internalmedia($src, $title = null, $align = null, $width = null, |
||
| 1113 | $height = null, $cache = null, $linking = null, $return = false) { |
||
| 1114 | global $ID; |
||
| 1115 | list($src, $hash) = explode('#', $src, 2); |
||
| 1116 | resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true); |
||
| 1117 | |||
| 1118 | $noLink = false; |
||
| 1119 | $render = ($linking == 'linkonly') ? false : true; |
||
| 1120 | $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); |
||
| 1121 | |||
| 1122 | list($ext, $mime) = mimetype($src, false); |
||
| 1123 | if(substr($mime, 0, 5) == 'image' && $render) { |
||
| 1124 | $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct')); |
||
| 1125 | } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { |
||
| 1126 | // don't link movies |
||
| 1127 | $noLink = true; |
||
| 1128 | } else { |
||
| 1129 | // add file icons |
||
| 1130 | $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); |
||
| 1131 | $link['class'] .= ' mediafile mf_'.$class; |
||
| 1132 | $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true); |
||
| 1133 | if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')'; |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | if($hash) $link['url'] .= '#'.$hash; |
||
| 1137 | |||
| 1138 | //markup non existing files |
||
| 1139 | if(!$exists) { |
||
| 1140 | $link['class'] .= ' wikilink2'; |
||
| 1141 | } |
||
| 1142 | |||
| 1143 | //output formatted |
||
| 1144 | if($return) { |
||
| 1145 | if($linking == 'nolink' || $noLink) return $link['name']; |
||
| 1146 | else return $this->_formatLink($link); |
||
| 1147 | } else { |
||
| 1148 | if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; |
||
| 1149 | else $this->doc .= $this->_formatLink($link); |
||
| 1150 | } |
||
| 1151 | } |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Render an external media file |
||
| 1155 | * |
||
| 1156 | * @param string $src full media URL |
||
| 1157 | * @param string $title descriptive text |
||
| 1158 | * @param string $align left|center|right |
||
| 1159 | * @param int $width width of media in pixel |
||
| 1160 | * @param int $height height of media in pixel |
||
| 1161 | * @param string $cache cache|recache|nocache |
||
| 1162 | * @param string $linking linkonly|detail|nolink |
||
| 1163 | * @param bool $return return HTML instead of adding to $doc |
||
| 1164 | */ |
||
| 1165 | function externalmedia($src, $title = null, $align = null, $width = null, |
||
| 1166 | $height = null, $cache = null, $linking = null, $return = false) { |
||
| 1167 | list($src, $hash) = explode('#', $src, 2); |
||
| 1168 | $noLink = false; |
||
| 1169 | $render = ($linking == 'linkonly') ? false : true; |
||
| 1170 | $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); |
||
| 1171 | |||
| 1172 | $link['url'] = ml($src, array('cache' => $cache)); |
||
| 1173 | |||
| 1174 | list($ext, $mime) = mimetype($src, false); |
||
| 1175 | if(substr($mime, 0, 5) == 'image' && $render) { |
||
| 1176 | // link only jpeg images |
||
| 1177 | // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; |
||
| 1178 | } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { |
||
| 1179 | // don't link movies |
||
| 1180 | $noLink = true; |
||
| 1181 | } else { |
||
| 1182 | // add file icons |
||
| 1183 | $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); |
||
| 1184 | $link['class'] .= ' mediafile mf_'.$class; |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | if($hash) $link['url'] .= '#'.$hash; |
||
| 1188 | |||
| 1189 | //output formatted |
||
| 1190 | if($return) { |
||
| 1191 | if($linking == 'nolink' || $noLink) return $link['name']; |
||
| 1192 | else return $this->_formatLink($link); |
||
| 1193 | } else { |
||
| 1194 | if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; |
||
| 1195 | else $this->doc .= $this->_formatLink($link); |
||
| 1196 | } |
||
| 1197 | } |
||
| 1198 | |||
| 1199 | /** |
||
| 1200 | * Renders an RSS feed |
||
| 1201 | * |
||
| 1202 | * @author Andreas Gohr <[email protected]> |
||
| 1203 | */ |
||
| 1204 | function rss($url, $params) { |
||
| 1205 | global $lang; |
||
| 1206 | global $conf; |
||
| 1207 | |||
| 1208 | require_once(DOKU_INC.'inc/FeedParser.php'); |
||
| 1209 | $feed = new FeedParser(); |
||
| 1210 | $feed->set_feed_url($url); |
||
| 1211 | |||
| 1212 | //disable warning while fetching |
||
| 1213 | if(!defined('DOKU_E_LEVEL')) { |
||
| 1214 | $elvl = error_reporting(E_ERROR); |
||
| 1215 | } |
||
| 1216 | $rc = $feed->init(); |
||
| 1217 | if(isset($elvl)) { |
||
| 1218 | error_reporting($elvl); |
||
| 1219 | } |
||
| 1220 | |||
| 1221 | if($params['nosort']) $feed->enable_order_by_date(false); |
||
| 1222 | |||
| 1223 | //decide on start and end |
||
| 1224 | if($params['reverse']) { |
||
| 1225 | $mod = -1; |
||
| 1226 | $start = $feed->get_item_quantity() - 1; |
||
| 1227 | $end = $start - ($params['max']); |
||
| 1228 | $end = ($end < -1) ? -1 : $end; |
||
| 1229 | } else { |
||
| 1230 | $mod = 1; |
||
| 1231 | $start = 0; |
||
| 1232 | $end = $feed->get_item_quantity(); |
||
| 1233 | $end = ($end > $params['max']) ? $params['max'] : $end; |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | $this->doc .= '<ul class="rss">'; |
||
| 1237 | if($rc) { |
||
| 1238 | for($x = $start; $x != $end; $x += $mod) { |
||
| 1239 | $item = $feed->get_item($x); |
||
| 1240 | $this->doc .= '<li><div class="li">'; |
||
| 1241 | // support feeds without links |
||
| 1242 | $lnkurl = $item->get_permalink(); |
||
| 1243 | if($lnkurl) { |
||
| 1244 | // title is escaped by SimplePie, we unescape here because it |
||
| 1245 | // is escaped again in externallink() FS#1705 |
||
| 1246 | $this->externallink( |
||
| 1247 | $item->get_permalink(), |
||
| 1248 | html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8') |
||
| 1249 | ); |
||
| 1250 | } else { |
||
| 1251 | $this->doc .= ' '.$item->get_title(); |
||
| 1252 | } |
||
| 1253 | if($params['author']) { |
||
| 1254 | $author = $item->get_author(0); |
||
| 1255 | if($author) { |
||
| 1256 | $name = $author->get_name(); |
||
| 1257 | if(!$name) $name = $author->get_email(); |
||
| 1258 | if($name) $this->doc .= ' '.$lang['by'].' '.$name; |
||
| 1259 | } |
||
| 1260 | } |
||
| 1261 | if($params['date']) { |
||
| 1262 | $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; |
||
| 1263 | } |
||
| 1264 | if($params['details']) { |
||
| 1265 | $this->doc .= '<div class="detail">'; |
||
| 1266 | if($conf['htmlok']) { |
||
| 1267 | $this->doc .= $item->get_description(); |
||
| 1268 | } else { |
||
| 1269 | $this->doc .= strip_tags($item->get_description()); |
||
| 1270 | } |
||
| 1271 | $this->doc .= '</div>'; |
||
| 1272 | } |
||
| 1273 | |||
| 1274 | $this->doc .= '</div></li>'; |
||
| 1275 | } |
||
| 1276 | } else { |
||
| 1277 | $this->doc .= '<li><div class="li">'; |
||
| 1278 | $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; |
||
| 1279 | $this->externallink($url); |
||
| 1280 | if($conf['allowdebug']) { |
||
| 1281 | $this->doc .= '<!--'.hsc($feed->error).'-->'; |
||
| 1282 | } |
||
| 1283 | $this->doc .= '</div></li>'; |
||
| 1284 | } |
||
| 1285 | $this->doc .= '</ul>'; |
||
| 1286 | } |
||
| 1287 | |||
| 1288 | /** |
||
| 1289 | * Start a table |
||
| 1290 | * |
||
| 1291 | * @param int $maxcols maximum number of columns |
||
| 1292 | * @param int $numrows NOT IMPLEMENTED |
||
| 1293 | * @param int $pos byte position in the original source |
||
| 1294 | */ |
||
| 1295 | function table_open($maxcols = null, $numrows = null, $pos = null) { |
||
| 1296 | // initialize the row counter used for classes |
||
| 1297 | $this->_counter['row_counter'] = 0; |
||
| 1298 | $class = 'table'; |
||
| 1299 | if($pos !== null) { |
||
| 1300 | $class .= ' '.$this->startSectionEdit($pos, 'table'); |
||
| 1301 | } |
||
| 1302 | $this->doc .= '<div class="'.$class.'"><table class="inline">'. |
||
| 1303 | DOKU_LF; |
||
| 1304 | } |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Close a table |
||
| 1308 | * |
||
| 1309 | * @param int $pos byte position in the original source |
||
| 1310 | */ |
||
| 1311 | function table_close($pos = null) { |
||
| 1312 | $this->doc .= '</table></div>'.DOKU_LF; |
||
| 1313 | if($pos !== null) { |
||
| 1314 | $this->finishSectionEdit($pos); |
||
| 1315 | } |
||
| 1316 | } |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Open a table header |
||
| 1320 | */ |
||
| 1321 | function tablethead_open() { |
||
| 1322 | $this->doc .= DOKU_TAB.'<thead>'.DOKU_LF; |
||
| 1323 | } |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * Close a table header |
||
| 1327 | */ |
||
| 1328 | function tablethead_close() { |
||
| 1329 | $this->doc .= DOKU_TAB.'</thead>'.DOKU_LF; |
||
| 1330 | } |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Open a table body |
||
| 1334 | */ |
||
| 1335 | function tabletbody_open() { |
||
| 1336 | $this->doc .= DOKU_TAB.'<tbody>'.DOKU_LF; |
||
| 1337 | } |
||
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Close a table body |
||
| 1341 | */ |
||
| 1342 | function tabletbody_close() { |
||
| 1343 | $this->doc .= DOKU_TAB.'</tbody>'.DOKU_LF; |
||
| 1344 | } |
||
| 1345 | |||
| 1346 | /** |
||
| 1347 | * Open a table row |
||
| 1348 | */ |
||
| 1349 | function tablerow_open() { |
||
| 1350 | // initialize the cell counter used for classes |
||
| 1351 | $this->_counter['cell_counter'] = 0; |
||
| 1352 | $class = 'row'.$this->_counter['row_counter']++; |
||
| 1353 | $this->doc .= DOKU_TAB.'<tr class="'.$class.'">'.DOKU_LF.DOKU_TAB.DOKU_TAB; |
||
| 1354 | } |
||
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Close a table row |
||
| 1358 | */ |
||
| 1359 | function tablerow_close() { |
||
| 1360 | $this->doc .= DOKU_LF.DOKU_TAB.'</tr>'.DOKU_LF; |
||
| 1361 | } |
||
| 1362 | |||
| 1363 | /** |
||
| 1364 | * Open a table header cell |
||
| 1365 | * |
||
| 1366 | * @param int $colspan |
||
| 1367 | * @param string $align left|center|right |
||
| 1368 | * @param int $rowspan |
||
| 1369 | */ |
||
| 1370 | function tableheader_open($colspan = 1, $align = null, $rowspan = 1) { |
||
| 1371 | $class = 'class="col'.$this->_counter['cell_counter']++; |
||
| 1372 | if(!is_null($align)) { |
||
| 1373 | $class .= ' '.$align.'align'; |
||
| 1374 | } |
||
| 1375 | $class .= '"'; |
||
| 1376 | $this->doc .= '<th '.$class; |
||
| 1377 | if($colspan > 1) { |
||
| 1378 | $this->_counter['cell_counter'] += $colspan - 1; |
||
| 1379 | $this->doc .= ' colspan="'.$colspan.'"'; |
||
| 1380 | } |
||
| 1381 | if($rowspan > 1) { |
||
| 1382 | $this->doc .= ' rowspan="'.$rowspan.'"'; |
||
| 1383 | } |
||
| 1384 | $this->doc .= '>'; |
||
| 1385 | } |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Close a table header cell |
||
| 1389 | */ |
||
| 1390 | function tableheader_close() { |
||
| 1391 | $this->doc .= '</th>'; |
||
| 1392 | } |
||
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Open a table cell |
||
| 1396 | * |
||
| 1397 | * @param int $colspan |
||
| 1398 | * @param string $align left|center|right |
||
| 1399 | * @param int $rowspan |
||
| 1400 | */ |
||
| 1401 | function tablecell_open($colspan = 1, $align = null, $rowspan = 1) { |
||
| 1402 | $class = 'class="col'.$this->_counter['cell_counter']++; |
||
| 1403 | if(!is_null($align)) { |
||
| 1404 | $class .= ' '.$align.'align'; |
||
| 1405 | } |
||
| 1406 | $class .= '"'; |
||
| 1407 | $this->doc .= '<td '.$class; |
||
| 1408 | if($colspan > 1) { |
||
| 1409 | $this->_counter['cell_counter'] += $colspan - 1; |
||
| 1410 | $this->doc .= ' colspan="'.$colspan.'"'; |
||
| 1411 | } |
||
| 1412 | if($rowspan > 1) { |
||
| 1413 | $this->doc .= ' rowspan="'.$rowspan.'"'; |
||
| 1414 | } |
||
| 1415 | $this->doc .= '>'; |
||
| 1416 | } |
||
| 1417 | |||
| 1418 | /** |
||
| 1419 | * Close a table cell |
||
| 1420 | */ |
||
| 1421 | function tablecell_close() { |
||
| 1422 | $this->doc .= '</td>'; |
||
| 1423 | } |
||
| 1424 | |||
| 1425 | /** |
||
| 1426 | * Returns the current header level. |
||
| 1427 | * (required e.g. by the filelist plugin) |
||
| 1428 | * |
||
| 1429 | * @return int The current header level |
||
| 1430 | */ |
||
| 1431 | function getLastlevel() { |
||
| 1434 | |||
| 1435 | #region Utility functions |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Build a link |
||
| 1439 | * |
||
| 1440 | * Assembles all parts defined in $link returns HTML for the link |
||
| 1441 | * |
||
| 1442 | * @author Andreas Gohr <[email protected]> |
||
| 1443 | */ |
||
| 1444 | function _formatLink($link) { |
||
| 1445 | //make sure the url is XHTML compliant (skip mailto) |
||
| 1446 | if(substr($link['url'], 0, 7) != 'mailto:') { |
||
| 1447 | $link['url'] = str_replace('&', '&', $link['url']); |
||
| 1448 | $link['url'] = str_replace('&amp;', '&', $link['url']); |
||
| 1449 | } |
||
| 1450 | //remove double encodings in titles |
||
| 1451 | $link['title'] = str_replace('&amp;', '&', $link['title']); |
||
| 1452 | |||
| 1453 | // be sure there are no bad chars in url or title |
||
| 1454 | // (we can't do this for name because it can contain an img tag) |
||
| 1455 | $link['url'] = strtr($link['url'], array('>' => '%3E', '<' => '%3C', '"' => '%22')); |
||
| 1456 | $link['title'] = strtr($link['title'], array('>' => '>', '<' => '<', '"' => '"')); |
||
| 1457 | |||
| 1458 | $ret = ''; |
||
| 1459 | $ret .= $link['pre']; |
||
| 1460 | $ret .= '<a href="'.$link['url'].'"'; |
||
| 1461 | if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; |
||
| 1462 | if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; |
||
| 1463 | if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; |
||
| 1464 | if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; |
||
| 1465 | if(!empty($link['rel'])) $ret .= ' rel="'.trim($link['rel']).'"'; |
||
| 1466 | if(!empty($link['more'])) $ret .= ' '.$link['more']; |
||
| 1467 | $ret .= '>'; |
||
| 1468 | $ret .= $link['name']; |
||
| 1469 | $ret .= '</a>'; |
||
| 1470 | $ret .= $link['suf']; |
||
| 1471 | return $ret; |
||
| 1472 | } |
||
| 1473 | |||
| 1474 | /** |
||
| 1475 | * Renders internal and external media |
||
| 1476 | * |
||
| 1477 | * @author Andreas Gohr <[email protected]> |
||
| 1478 | * @param string $src media ID |
||
| 1479 | * @param string $title descriptive text |
||
| 1480 | * @param string $align left|center|right |
||
| 1481 | * @param int $width width of media in pixel |
||
| 1482 | * @param int $height height of media in pixel |
||
| 1483 | * @param string $cache cache|recache|nocache |
||
| 1484 | * @param bool $render should the media be embedded inline or just linked |
||
| 1485 | * @return string |
||
| 1486 | */ |
||
| 1487 | function _media($src, $title = null, $align = null, $width = null, |
||
| 1488 | $height = null, $cache = null, $render = true) { |
||
| 1489 | |||
| 1490 | $ret = ''; |
||
| 1491 | |||
| 1492 | list($ext, $mime) = mimetype($src); |
||
| 1493 | if(substr($mime, 0, 5) == 'image') { |
||
| 1494 | // first get the $title |
||
| 1495 | if(!is_null($title)) { |
||
| 1496 | $title = $this->_xmlEntities($title); |
||
| 1497 | } elseif($ext == 'jpg' || $ext == 'jpeg') { |
||
| 1498 | //try to use the caption from IPTC/EXIF |
||
| 1499 | require_once(DOKU_INC.'inc/JpegMeta.php'); |
||
| 1500 | $jpeg = new JpegMeta(mediaFN($src)); |
||
| 1501 | if($jpeg !== false) $cap = $jpeg->getTitle(); |
||
| 1502 | if(!empty($cap)) { |
||
| 1503 | $title = $this->_xmlEntities($cap); |
||
| 1504 | } |
||
| 1505 | } |
||
| 1506 | if(!$render) { |
||
| 1507 | // if the picture is not supposed to be rendered |
||
| 1508 | // return the title of the picture |
||
| 1509 | if(!$title) { |
||
| 1510 | // just show the sourcename |
||
| 1511 | $title = $this->_xmlEntities(utf8_basename(noNS($src))); |
||
| 1512 | } |
||
| 1513 | return $title; |
||
| 1514 | } |
||
| 1515 | //add image tag |
||
| 1516 | $ret .= '<img src="'.ml($src, array('w' => $width, 'h' => $height, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src))).'"'; |
||
| 1517 | $ret .= ' class="media'.$align.'"'; |
||
| 1518 | |||
| 1519 | if($title) { |
||
| 1520 | $ret .= ' title="'.$title.'"'; |
||
| 1521 | $ret .= ' alt="'.$title.'"'; |
||
| 1522 | } else { |
||
| 1523 | $ret .= ' alt=""'; |
||
| 1524 | } |
||
| 1525 | |||
| 1526 | if(!is_null($width)) |
||
| 1527 | $ret .= ' width="'.$this->_xmlEntities($width).'"'; |
||
| 1528 | |||
| 1529 | if(!is_null($height)) |
||
| 1530 | $ret .= ' height="'.$this->_xmlEntities($height).'"'; |
||
| 1531 | |||
| 1532 | $ret .= ' />'; |
||
| 1533 | |||
| 1534 | } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) { |
||
| 1535 | // first get the $title |
||
| 1536 | $title = !is_null($title) ? $this->_xmlEntities($title) : false; |
||
| 1537 | if(!$render) { |
||
| 1538 | // if the file is not supposed to be rendered |
||
| 1539 | // return the title of the file (just the sourcename if there is no title) |
||
| 1540 | return $title ? $title : $this->_xmlEntities(utf8_basename(noNS($src))); |
||
| 1541 | } |
||
| 1542 | |||
| 1543 | $att = array(); |
||
| 1544 | $att['class'] = "media$align"; |
||
| 1545 | if($title) { |
||
| 1546 | $att['title'] = $title; |
||
| 1547 | } |
||
| 1548 | |||
| 1549 | if(media_supportedav($mime, 'video')) { |
||
| 1550 | //add video |
||
| 1551 | $ret .= $this->_video($src, $width, $height, $att); |
||
| 1552 | } |
||
| 1553 | if(media_supportedav($mime, 'audio')) { |
||
| 1554 | //add audio |
||
| 1555 | $ret .= $this->_audio($src, $att); |
||
| 1556 | } |
||
| 1557 | |||
| 1558 | } elseif($mime == 'application/x-shockwave-flash') { |
||
| 1559 | if(!$render) { |
||
| 1560 | // if the flash is not supposed to be rendered |
||
| 1561 | // return the title of the flash |
||
| 1562 | if(!$title) { |
||
| 1563 | // just show the sourcename |
||
| 1564 | $title = utf8_basename(noNS($src)); |
||
| 1565 | } |
||
| 1566 | return $this->_xmlEntities($title); |
||
| 1567 | } |
||
| 1568 | |||
| 1569 | $att = array(); |
||
| 1570 | $att['class'] = "media$align"; |
||
| 1571 | if($align == 'right') $att['align'] = 'right'; |
||
| 1572 | if($align == 'left') $att['align'] = 'left'; |
||
| 1573 | $ret .= html_flashobject( |
||
| 1574 | ml($src, array('cache' => $cache), true, '&'), $width, $height, |
||
| 1575 | array('quality' => 'high'), |
||
| 1576 | null, |
||
| 1577 | $att, |
||
| 1578 | $this->_xmlEntities($title) |
||
| 1579 | ); |
||
| 1580 | } elseif($title) { |
||
| 1581 | // well at least we have a title to display |
||
| 1582 | $ret .= $this->_xmlEntities($title); |
||
| 1583 | } else { |
||
| 1584 | // just show the sourcename |
||
| 1585 | $ret .= $this->_xmlEntities(utf8_basename(noNS($src))); |
||
| 1586 | } |
||
| 1587 | |||
| 1588 | return $ret; |
||
| 1589 | } |
||
| 1590 | |||
| 1591 | /** |
||
| 1592 | * Escape string for output |
||
| 1593 | * |
||
| 1594 | * @param $string |
||
| 1595 | * @return string |
||
| 1596 | */ |
||
| 1597 | function _xmlEntities($string) { |
||
| 1598 | return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); |
||
| 1599 | } |
||
| 1600 | |||
| 1601 | /** |
||
| 1602 | * Creates a linkid from a headline |
||
| 1603 | * |
||
| 1604 | * @author Andreas Gohr <[email protected]> |
||
| 1605 | * @param string $title The headline title |
||
| 1606 | * @param boolean $create Create a new unique ID? |
||
| 1607 | * @return string |
||
| 1608 | */ |
||
| 1609 | function _headerToLink($title, $create = false) { |
||
| 1610 | if($create) { |
||
| 1611 | return sectionID($title, $this->headers); |
||
| 1612 | } else { |
||
| 1613 | $check = false; |
||
| 1614 | return sectionID($title, $check); |
||
| 1615 | } |
||
| 1616 | } |
||
| 1617 | |||
| 1618 | /** |
||
| 1619 | * Construct a title and handle images in titles |
||
| 1620 | * |
||
| 1621 | * @author Harry Fuecks <[email protected]> |
||
| 1622 | * @param string|array $title either string title or media array |
||
| 1623 | * @param string $default default title if nothing else is found |
||
| 1624 | * @param bool $isImage will be set to true if it's a media file |
||
| 1625 | * @param null|string $id linked page id (used to extract title from first heading) |
||
| 1626 | * @param string $linktype content|navigation |
||
| 1627 | * @return string HTML of the title, might be full image tag or just escaped text |
||
| 1628 | */ |
||
| 1629 | function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { |
||
| 1630 | $isImage = false; |
||
| 1631 | if(is_array($title)) { |
||
| 1632 | $isImage = true; |
||
| 1633 | return $this->_imageTitle($title); |
||
| 1634 | } elseif(is_null($title) || trim($title) == '') { |
||
| 1635 | if(useHeading($linktype) && $id) { |
||
| 1636 | $heading = p_get_first_heading($id); |
||
| 1637 | if($heading) { |
||
| 1638 | return $this->_xmlEntities($heading); |
||
| 1639 | } |
||
| 1640 | } |
||
| 1641 | return $this->_xmlEntities($default); |
||
| 1642 | } else { |
||
| 1643 | return $this->_xmlEntities($title); |
||
| 1644 | } |
||
| 1645 | } |
||
| 1646 | |||
| 1647 | /** |
||
| 1648 | * Returns HTML code for images used in link titles |
||
| 1649 | * |
||
| 1650 | * @author Andreas Gohr <[email protected]> |
||
| 1651 | * @param array $img |
||
| 1652 | * @return string HTML img tag or similar |
||
| 1653 | */ |
||
| 1654 | function _imageTitle($img) { |
||
| 1655 | global $ID; |
||
| 1656 | |||
| 1657 | // some fixes on $img['src'] |
||
| 1658 | // see internalmedia() and externalmedia() |
||
| 1659 | list($img['src']) = explode('#', $img['src'], 2); |
||
| 1660 | if($img['type'] == 'internalmedia') { |
||
| 1661 | resolve_mediaid(getNS($ID), $img['src'], $exists ,$this->date_at, true); |
||
| 1662 | } |
||
| 1663 | |||
| 1664 | return $this->_media( |
||
| 1665 | $img['src'], |
||
| 1666 | $img['title'], |
||
| 1667 | $img['align'], |
||
| 1668 | $img['width'], |
||
| 1669 | $img['height'], |
||
| 1670 | $img['cache'] |
||
| 1671 | ); |
||
| 1672 | } |
||
| 1673 | |||
| 1674 | /** |
||
| 1675 | * helperfunction to return a basic link to a media |
||
| 1676 | * |
||
| 1677 | * used in internalmedia() and externalmedia() |
||
| 1678 | * |
||
| 1679 | * @author Pierre Spring <[email protected]> |
||
| 1680 | * @param string $src media ID |
||
| 1681 | * @param string $title descriptive text |
||
| 1682 | * @param string $align left|center|right |
||
| 1683 | * @param int $width width of media in pixel |
||
| 1684 | * @param int $height height of media in pixel |
||
| 1685 | * @param string $cache cache|recache|nocache |
||
| 1686 | * @param bool $render should the media be embedded inline or just linked |
||
| 1687 | * @return array associative array with link config |
||
| 1688 | */ |
||
| 1689 | function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) { |
||
| 1705 | |||
| 1706 | /** |
||
| 1707 | * Embed video(s) in HTML |
||
| 1708 | * |
||
| 1709 | * @author Anika Henke <[email protected]> |
||
| 1710 | * |
||
| 1711 | * @param string $src - ID of video to embed |
||
| 1712 | * @param int $width - width of the video in pixels |
||
| 1713 | * @param int $height - height of the video in pixels |
||
| 1714 | * @param array $atts - additional attributes for the <video> tag |
||
| 1715 | * @return string |
||
| 1716 | */ |
||
| 1717 | function _video($src, $width, $height, $atts = null) { |
||
| 1718 | // prepare width and height |
||
| 1719 | if(is_null($atts)) $atts = array(); |
||
| 1720 | $atts['width'] = (int) $width; |
||
| 1721 | $atts['height'] = (int) $height; |
||
| 1722 | if(!$atts['width']) $atts['width'] = 320; |
||
| 1723 | if(!$atts['height']) $atts['height'] = 240; |
||
| 1724 | |||
| 1725 | $posterUrl = ''; |
||
| 1726 | $files = array(); |
||
| 1727 | $isExternal = media_isexternal($src); |
||
| 1728 | |||
| 1729 | if ($isExternal) { |
||
| 1730 | // take direct source for external files |
||
| 1731 | list(/*ext*/, $srcMime) = mimetype($src); |
||
| 1732 | $files[$srcMime] = $src; |
||
| 1733 | } else { |
||
| 1734 | // prepare alternative formats |
||
| 1735 | $extensions = array('webm', 'ogv', 'mp4'); |
||
| 1736 | $files = media_alternativefiles($src, $extensions); |
||
| 1737 | $poster = media_alternativefiles($src, array('jpg', 'png')); |
||
| 1738 | if(!empty($poster)) { |
||
| 1739 | $posterUrl = ml(reset($poster), '', true, '&'); |
||
| 1740 | } |
||
| 1741 | } |
||
| 1742 | |||
| 1743 | $out = ''; |
||
| 1744 | // open video tag |
||
| 1745 | $out .= '<video '.buildAttributes($atts).' controls="controls"'; |
||
| 1746 | if($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"'; |
||
| 1747 | $out .= '>'.NL; |
||
| 1748 | $fallback = ''; |
||
| 1749 | |||
| 1750 | // output source for each alternative video format |
||
| 1751 | foreach($files as $mime => $file) { |
||
| 1752 | if ($isExternal) { |
||
| 1753 | $url = $file; |
||
| 1754 | $linkType = 'externalmedia'; |
||
| 1755 | } else { |
||
| 1756 | $url = ml($file, '', true, '&'); |
||
| 1757 | $linkType = 'internalmedia'; |
||
| 1758 | } |
||
| 1759 | $title = $atts['title'] ? $atts['title'] : $this->_xmlEntities(utf8_basename(noNS($file))); |
||
| 1760 | |||
| 1761 | $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; |
||
| 1762 | // alternative content (just a link to the file) |
||
| 1763 | $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); |
||
| 1764 | } |
||
| 1765 | |||
| 1766 | // finish |
||
| 1767 | $out .= $fallback; |
||
| 1768 | $out .= '</video>'.NL; |
||
| 1769 | return $out; |
||
| 1770 | } |
||
| 1771 | |||
| 1772 | /** |
||
| 1773 | * Embed audio in HTML |
||
| 1774 | * |
||
| 1775 | * @author Anika Henke <[email protected]> |
||
| 1776 | * |
||
| 1777 | * @param string $src - ID of audio to embed |
||
| 1778 | * @param array $atts - additional attributes for the <audio> tag |
||
| 1779 | * @return string |
||
| 1780 | */ |
||
| 1781 | function _audio($src, $atts = array()) { |
||
| 1782 | $files = array(); |
||
| 1783 | $isExternal = media_isexternal($src); |
||
| 1784 | |||
| 1785 | if ($isExternal) { |
||
| 1786 | // take direct source for external files |
||
| 1787 | list(/*ext*/, $srcMime) = mimetype($src); |
||
| 1788 | $files[$srcMime] = $src; |
||
| 1789 | } else { |
||
| 1790 | // prepare alternative formats |
||
| 1821 | |||
| 1822 | /** |
||
| 1823 | * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media() |
||
| 1824 | * which returns an existing media revision less or equal to rev or date_at |
||
| 1825 | * |
||
| 1826 | * @author lisps |
||
| 1827 | * @param string $media_id |
||
| 1828 | * @access protected |
||
| 1829 | * @return string revision ('' for current) |
||
| 1830 | */ |
||
| 1831 | function _getLastMediaRevisionAt($media_id){ |
||
| 1836 | |||
| 1837 | #endregion |
||
| 1838 | } |
||
| 1839 | |||
| 1841 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.