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 |
||
| 14 | class Doku_Renderer_xhtml extends Doku_Renderer { |
||
| 15 | /** @var array store the table of contents */ |
||
| 16 | public $toc = array(); |
||
| 17 | |||
| 18 | /** @var array A stack of section edit data */ |
||
| 19 | protected $sectionedits = array(); |
||
| 20 | |||
| 21 | /** @var string|int link pages and media against this revision */ |
||
| 22 | public $date_at = ''; |
||
| 23 | |||
| 24 | /** @var int last section edit id, used by startSectionEdit */ |
||
| 25 | protected $lastsecid = 0; |
||
| 26 | |||
| 27 | /** @var array a list of footnotes, list starts at 1! */ |
||
| 28 | protected $footnotes = array(); |
||
| 29 | |||
| 30 | /** @var int current section level */ |
||
| 31 | protected $lastlevel = 0; |
||
| 32 | /** @var array section node tracker */ |
||
| 33 | protected $node = array(0, 0, 0, 0, 0); |
||
| 34 | |||
| 35 | /** @var string temporary $doc store */ |
||
| 36 | protected $store = ''; |
||
| 37 | |||
| 38 | /** @var array global counter, for table classes etc. */ |
||
| 39 | protected $_counter = array(); // |
||
| 40 | |||
| 41 | /** @var int counts the code and file blocks, used to provide download links */ |
||
| 42 | protected $_codeblock = 0; |
||
| 43 | |||
| 44 | /** @var array list of allowed URL schemes */ |
||
| 45 | protected $schemes = null; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Register a new edit section range |
||
| 49 | * |
||
| 50 | * @param int $start The byte position for the edit start |
||
| 51 | * @param array $data Associative array with section data: |
||
| 52 | * Key 'name': the section name/title |
||
| 53 | * Key 'target': the target for the section edit, |
||
| 54 | * e.g. 'section' or 'table' |
||
| 55 | * Key 'hid': header id |
||
| 56 | * Key 'codeblockOffset': actual code block index |
||
| 57 | * Key 'start': set in startSectionEdit(), |
||
| 58 | * do not set yourself |
||
| 59 | * Key 'range': calculated from 'start' and |
||
| 60 | * $key in finishSectionEdit(), |
||
| 61 | * do not set yourself |
||
| 62 | * @return string A marker class for the starting HTML element |
||
| 63 | * |
||
| 64 | * @author Adrian Lang <[email protected]> |
||
| 65 | */ |
||
| 66 | public function startSectionEdit($start, $data) { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Finish an edit section range |
||
| 90 | * |
||
| 91 | * @param int $end The byte position for the edit end; null for the rest of the page |
||
| 92 | * |
||
| 93 | * @author Adrian Lang <[email protected]> |
||
| 94 | */ |
||
| 95 | public function finishSectionEdit($end = null, $hid = null) { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Returns the format produced by this renderer. |
||
| 110 | * |
||
| 111 | * @return string always 'xhtml' |
||
| 112 | */ |
||
| 113 | public function getFormat() { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Initialize the document |
||
| 119 | */ |
||
| 120 | public function document_start() { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Finalize the document |
||
| 127 | */ |
||
| 128 | public function document_end() { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Add an item to the TOC |
||
| 188 | * |
||
| 189 | * @param string $id the hash link |
||
| 190 | * @param string $text the text to display |
||
| 191 | * @param int $level the nesting level |
||
| 192 | */ |
||
| 193 | public function toc_additem($id, $text, $level) { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Render a heading |
||
| 204 | * |
||
| 205 | * @param string $text the text to display |
||
| 206 | * @param int $level header level |
||
| 207 | * @param int $pos byte position in the original source |
||
| 208 | */ |
||
| 209 | public function header($text, $level, $pos) { |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Open a new section |
||
| 252 | * |
||
| 253 | * @param int $level section level (as determined by the previous header) |
||
| 254 | */ |
||
| 255 | public function section_open($level) { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Close the current section |
||
| 261 | */ |
||
| 262 | public function section_close() { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Render plain text data |
||
| 268 | * |
||
| 269 | * @param $text |
||
| 270 | */ |
||
| 271 | public function cdata($text) { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Open a paragraph |
||
| 277 | */ |
||
| 278 | public function p_open() { |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Close a paragraph |
||
| 284 | */ |
||
| 285 | public function p_close() { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Create a line break |
||
| 291 | */ |
||
| 292 | public function linebreak() { |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Create a horizontal line |
||
| 298 | */ |
||
| 299 | public function hr() { |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Start strong (bold) formatting |
||
| 305 | */ |
||
| 306 | public function strong_open() { |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Stop strong (bold) formatting |
||
| 312 | */ |
||
| 313 | public function strong_close() { |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Start emphasis (italics) formatting |
||
| 319 | */ |
||
| 320 | public function emphasis_open() { |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Stop emphasis (italics) formatting |
||
| 326 | */ |
||
| 327 | public function emphasis_close() { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * Start underline formatting |
||
| 333 | */ |
||
| 334 | public function underline_open() { |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Stop underline formatting |
||
| 340 | */ |
||
| 341 | public function underline_close() { |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Start monospace formatting |
||
| 347 | */ |
||
| 348 | public function monospace_open() { |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Stop monospace formatting |
||
| 354 | */ |
||
| 355 | public function monospace_close() { |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Start a subscript |
||
| 361 | */ |
||
| 362 | public function subscript_open() { |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Stop a subscript |
||
| 368 | */ |
||
| 369 | public function subscript_close() { |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Start a superscript |
||
| 375 | */ |
||
| 376 | public function superscript_open() { |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Stop a superscript |
||
| 382 | */ |
||
| 383 | public function superscript_close() { |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Start deleted (strike-through) formatting |
||
| 389 | */ |
||
| 390 | public function deleted_open() { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Stop deleted (strike-through) formatting |
||
| 396 | */ |
||
| 397 | public function deleted_close() { |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Callback for footnote start syntax |
||
| 403 | * |
||
| 404 | * All following content will go to the footnote instead of |
||
| 405 | * the document. To achieve this the previous rendered content |
||
| 406 | * is moved to $store and $doc is cleared |
||
| 407 | * |
||
| 408 | * @author Andreas Gohr <[email protected]> |
||
| 409 | */ |
||
| 410 | public function footnote_open() { |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Callback for footnote end syntax |
||
| 419 | * |
||
| 420 | * All rendered content is moved to the $footnotes array and the old |
||
| 421 | * content is restored from $store again |
||
| 422 | * |
||
| 423 | * @author Andreas Gohr |
||
| 424 | */ |
||
| 425 | public function footnote_close() { |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Open an unordered list |
||
| 453 | * |
||
| 454 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 455 | */ |
||
| 456 | public function listu_open($classes = null) { |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Close an unordered list |
||
| 467 | */ |
||
| 468 | public function listu_close() { |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Open an ordered list |
||
| 474 | * |
||
| 475 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 476 | */ |
||
| 477 | public function listo_open($classes = null) { |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Close an ordered list |
||
| 488 | */ |
||
| 489 | public function listo_close() { |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Open a list item |
||
| 495 | * |
||
| 496 | * @param int $level the nesting level |
||
| 497 | * @param bool $node true when a node; false when a leaf |
||
| 498 | */ |
||
| 499 | public function listitem_open($level, $node=false) { |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Close a list item |
||
| 506 | */ |
||
| 507 | public function listitem_close() { |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Start the content of a list item |
||
| 513 | */ |
||
| 514 | public function listcontent_open() { |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Stop the content of a list item |
||
| 520 | */ |
||
| 521 | public function listcontent_close() { |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Output unformatted $text |
||
| 527 | * |
||
| 528 | * Defaults to $this->cdata() |
||
| 529 | * |
||
| 530 | * @param string $text |
||
| 531 | */ |
||
| 532 | public function unformatted($text) { |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Execute PHP code if allowed |
||
| 538 | * |
||
| 539 | * @param string $text PHP code that is either executed or printed |
||
| 540 | * @param string $wrapper html element to wrap result if $conf['phpok'] is okff |
||
| 541 | * |
||
| 542 | * @author Andreas Gohr <[email protected]> |
||
| 543 | */ |
||
| 544 | public function php($text, $wrapper = 'code') { |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Output block level PHP code |
||
| 559 | * |
||
| 560 | * If $conf['phpok'] is true this should evaluate the given code and append the result |
||
| 561 | * to $doc |
||
| 562 | * |
||
| 563 | * @param string $text The PHP code |
||
| 564 | */ |
||
| 565 | public function phpblock($text) { |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Insert HTML if allowed |
||
| 571 | * |
||
| 572 | * @param string $text html text |
||
| 573 | * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff |
||
| 574 | * |
||
| 575 | * @author Andreas Gohr <[email protected]> |
||
| 576 | */ |
||
| 577 | public function html($text, $wrapper = 'code') { |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Output raw block-level HTML |
||
| 589 | * |
||
| 590 | * If $conf['htmlok'] is true this should add the code as is to $doc |
||
| 591 | * |
||
| 592 | * @param string $text The HTML |
||
| 593 | */ |
||
| 594 | public function htmlblock($text) { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Start a block quote |
||
| 600 | */ |
||
| 601 | public function quote_open() { |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Stop a block quote |
||
| 607 | */ |
||
| 608 | public function quote_close() { |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Output preformatted text |
||
| 614 | * |
||
| 615 | * @param string $text |
||
| 616 | */ |
||
| 617 | public function preformatted($text) { |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Display text as file content, optionally syntax highlighted |
||
| 623 | * |
||
| 624 | * @param string $text text to show |
||
| 625 | * @param string $language programming language to use for syntax highlighting |
||
| 626 | * @param string $filename file path label |
||
| 627 | * @param array $options assoziative array with additional geshi options |
||
| 628 | */ |
||
| 629 | public function file($text, $language = null, $filename = null, $options=null) { |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Display text as code content, optionally syntax highlighted |
||
| 635 | * |
||
| 636 | * @param string $text text to show |
||
| 637 | * @param string $language programming language to use for syntax highlighting |
||
| 638 | * @param string $filename file path label |
||
| 639 | * @param array $options assoziative array with additional geshi options |
||
| 640 | */ |
||
| 641 | public function code($text, $language = null, $filename = null, $options=null) { |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Use GeSHi to highlight language syntax in code and file blocks |
||
| 647 | * |
||
| 648 | * @author Andreas Gohr <[email protected]> |
||
| 649 | * @param string $type code|file |
||
| 650 | * @param string $text text to show |
||
| 651 | * @param string $language programming language to use for syntax highlighting |
||
| 652 | * @param string $filename file path label |
||
| 653 | * @param array $options assoziative array with additional geshi options |
||
| 654 | */ |
||
| 655 | public function _highlight($type, $text, $language = null, $filename = null, $options = null) { |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Format an acronym |
||
| 710 | * |
||
| 711 | * Uses $this->acronyms |
||
| 712 | * |
||
| 713 | * @param string $acronym |
||
| 714 | */ |
||
| 715 | public function acronym($acronym) { |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Format a smiley |
||
| 731 | * |
||
| 732 | * Uses $this->smiley |
||
| 733 | * |
||
| 734 | * @param string $smiley |
||
| 735 | */ |
||
| 736 | public function smiley($smiley) { |
||
| 745 | |||
| 746 | /** |
||
| 747 | * Format an entity |
||
| 748 | * |
||
| 749 | * Entities are basically small text replacements |
||
| 750 | * |
||
| 751 | * Uses $this->entities |
||
| 752 | * |
||
| 753 | * @param string $entity |
||
| 754 | */ |
||
| 755 | public function entity($entity) { |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Typographically format a multiply sign |
||
| 765 | * |
||
| 766 | * Example: ($x=640, $y=480) should result in "640×480" |
||
| 767 | * |
||
| 768 | * @param string|int $x first value |
||
| 769 | * @param string|int $y second value |
||
| 770 | */ |
||
| 771 | public function multiplyentity($x, $y) { |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Render an opening single quote char (language specific) |
||
| 777 | */ |
||
| 778 | public function singlequoteopening() { |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Render a closing single quote char (language specific) |
||
| 785 | */ |
||
| 786 | public function singlequoteclosing() { |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Render an apostrophe char (language specific) |
||
| 793 | */ |
||
| 794 | public function apostrophe() { |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Render an opening double quote char (language specific) |
||
| 801 | */ |
||
| 802 | public function doublequoteopening() { |
||
| 806 | |||
| 807 | /** |
||
| 808 | * Render an closinging double quote char (language specific) |
||
| 809 | */ |
||
| 810 | public function doublequoteclosing() { |
||
| 814 | |||
| 815 | /** |
||
| 816 | * Render a CamelCase link |
||
| 817 | * |
||
| 818 | * @param string $link The link name |
||
| 819 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 820 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 821 | * |
||
| 822 | * @see http://en.wikipedia.org/wiki/CamelCase |
||
| 823 | */ |
||
| 824 | public function camelcaselink($link, $returnonly = false) { |
||
| 831 | |||
| 832 | /** |
||
| 833 | * Render a page local link |
||
| 834 | * |
||
| 835 | * @param string $hash hash link identifier |
||
| 836 | * @param string $name name for the link |
||
| 837 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 838 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 839 | */ |
||
| 840 | public function locallink($hash, $name = null, $returnonly = false) { |
||
| 856 | |||
| 857 | /** |
||
| 858 | * Render an internal Wiki Link |
||
| 859 | * |
||
| 860 | * $search,$returnonly & $linktype are not for the renderer but are used |
||
| 861 | * elsewhere - no need to implement them in other renderers |
||
| 862 | * |
||
| 863 | * @author Andreas Gohr <[email protected]> |
||
| 864 | * @param string $id pageid |
||
| 865 | * @param string|null $name link name |
||
| 866 | * @param string|null $search adds search url param |
||
| 867 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 868 | * @param string $linktype type to set use of headings |
||
| 869 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 870 | */ |
||
| 871 | public function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Render an external link |
||
| 951 | * |
||
| 952 | * @param string $url full URL with scheme |
||
| 953 | * @param string|array $name name for the link, array for media file |
||
| 954 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 955 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 956 | */ |
||
| 957 | public function externallink($url, $name = null, $returnonly = false) { |
||
| 1008 | |||
| 1009 | /** |
||
| 1010 | * Render an interwiki link |
||
| 1011 | * |
||
| 1012 | * You may want to use $this->_resolveInterWiki() here |
||
| 1013 | * |
||
| 1014 | * @param string $match original link - probably not much use |
||
| 1015 | * @param string|array $name name for the link, array for media file |
||
| 1016 | * @param string $wikiName indentifier (shortcut) for the remote wiki |
||
| 1017 | * @param string $wikiUri the fragment parsed from the original link |
||
| 1018 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1019 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 1020 | */ |
||
| 1021 | public function interwikilink($match, $name, $wikiName, $wikiUri, $returnonly = false) { |
||
| 1069 | |||
| 1070 | /** |
||
| 1071 | * Link to windows share |
||
| 1072 | * |
||
| 1073 | * @param string $url the link |
||
| 1074 | * @param string|array $name name for the link, array for media file |
||
| 1075 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1076 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 1077 | */ |
||
| 1078 | public function windowssharelink($url, $name = null, $returnonly = false) { |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Render a linked E-Mail Address |
||
| 1110 | * |
||
| 1111 | * Honors $conf['mailguard'] setting |
||
| 1112 | * |
||
| 1113 | * @param string $address Email-Address |
||
| 1114 | * @param string|array $name name for the link, array for media file |
||
| 1115 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1116 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 1117 | */ |
||
| 1118 | public function emaillink($address, $name = null, $returnonly = false) { |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Render an internal media file |
||
| 1159 | * |
||
| 1160 | * @param string $src media ID |
||
| 1161 | * @param string $title descriptive text |
||
| 1162 | * @param string $align left|center|right |
||
| 1163 | * @param int $width width of media in pixel |
||
| 1164 | * @param int $height height of media in pixel |
||
| 1165 | * @param string $cache cache|recache|nocache |
||
| 1166 | * @param string $linking linkonly|detail|nolink |
||
| 1167 | * @param bool $return return HTML instead of adding to $doc |
||
| 1168 | * @return void|string writes to doc attribute or returns html depends on $return |
||
| 1169 | */ |
||
| 1170 | public function internalmedia($src, $title = null, $align = null, $width = null, |
||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * Render an external media file |
||
| 1231 | * |
||
| 1232 | * @param string $src full media URL |
||
| 1233 | * @param string $title descriptive text |
||
| 1234 | * @param string $align left|center|right |
||
| 1235 | * @param int $width width of media in pixel |
||
| 1236 | * @param int $height height of media in pixel |
||
| 1237 | * @param string $cache cache|recache|nocache |
||
| 1238 | * @param string $linking linkonly|detail|nolink |
||
| 1239 | * @param bool $return return HTML instead of adding to $doc |
||
| 1240 | * @return void|string writes to doc attribute or returns html depends on $return |
||
| 1241 | */ |
||
| 1242 | public function externalmedia($src, $title = null, $align = null, $width = null, |
||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * Renders an RSS feed |
||
| 1291 | * |
||
| 1292 | * @param string $url URL of the feed |
||
| 1293 | * @param array $params Finetuning of the output |
||
| 1294 | * |
||
| 1295 | * @author Andreas Gohr <[email protected]> |
||
| 1296 | */ |
||
| 1297 | public function rss($url, $params) { |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * Start a table |
||
| 1383 | * |
||
| 1384 | * @param int $maxcols maximum number of columns |
||
| 1385 | * @param int $numrows NOT IMPLEMENTED |
||
| 1386 | * @param int $pos byte position in the original source |
||
| 1387 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1388 | */ |
||
| 1389 | public function table_open($maxcols = null, $numrows = null, $pos = null, $classes = null) { |
||
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Close a table |
||
| 1411 | * |
||
| 1412 | * @param int $pos byte position in the original source |
||
| 1413 | */ |
||
| 1414 | public function table_close($pos = null) { |
||
| 1420 | |||
| 1421 | /** |
||
| 1422 | * Open a table header |
||
| 1423 | */ |
||
| 1424 | public function tablethead_open() { |
||
| 1427 | |||
| 1428 | /** |
||
| 1429 | * Close a table header |
||
| 1430 | */ |
||
| 1431 | public function tablethead_close() { |
||
| 1434 | |||
| 1435 | /** |
||
| 1436 | * Open a table body |
||
| 1437 | */ |
||
| 1438 | public function tabletbody_open() { |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Close a table body |
||
| 1444 | */ |
||
| 1445 | public function tabletbody_close() { |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Open a table footer |
||
| 1451 | */ |
||
| 1452 | public function tabletfoot_open() { |
||
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Close a table footer |
||
| 1458 | */ |
||
| 1459 | public function tabletfoot_close() { |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Open a table row |
||
| 1465 | * |
||
| 1466 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1467 | */ |
||
| 1468 | public function tablerow_open($classes = null) { |
||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * Close a table row |
||
| 1481 | */ |
||
| 1482 | public function tablerow_close() { |
||
| 1485 | |||
| 1486 | /** |
||
| 1487 | * Open a table header cell |
||
| 1488 | * |
||
| 1489 | * @param int $colspan |
||
| 1490 | * @param string $align left|center|right |
||
| 1491 | * @param int $rowspan |
||
| 1492 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1493 | */ |
||
| 1494 | public function tableheader_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) { |
||
| 1514 | |||
| 1515 | /** |
||
| 1516 | * Close a table header cell |
||
| 1517 | */ |
||
| 1518 | public function tableheader_close() { |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * Open a table cell |
||
| 1524 | * |
||
| 1525 | * @param int $colspan |
||
| 1526 | * @param string $align left|center|right |
||
| 1527 | * @param int $rowspan |
||
| 1528 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1529 | */ |
||
| 1530 | public function tablecell_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) { |
||
| 1550 | |||
| 1551 | /** |
||
| 1552 | * Close a table cell |
||
| 1553 | */ |
||
| 1554 | public function tablecell_close() { |
||
| 1557 | |||
| 1558 | /** |
||
| 1559 | * Returns the current header level. |
||
| 1560 | * (required e.g. by the filelist plugin) |
||
| 1561 | * |
||
| 1562 | * @return int The current header level |
||
| 1563 | */ |
||
| 1564 | public function getLastlevel() { |
||
| 1567 | |||
| 1568 | #region Utility functions |
||
| 1569 | |||
| 1570 | /** |
||
| 1571 | * Build a link |
||
| 1572 | * |
||
| 1573 | * Assembles all parts defined in $link returns HTML for the link |
||
| 1574 | * |
||
| 1575 | * @param array $link attributes of a link |
||
| 1576 | * @return string |
||
| 1577 | * |
||
| 1578 | * @author Andreas Gohr <[email protected]> |
||
| 1579 | */ |
||
| 1580 | public function _formatLink($link) { |
||
| 1609 | |||
| 1610 | /** |
||
| 1611 | * Renders internal and external media |
||
| 1612 | * |
||
| 1613 | * @author Andreas Gohr <[email protected]> |
||
| 1614 | * @param string $src media ID |
||
| 1615 | * @param string $title descriptive text |
||
| 1616 | * @param string $align left|center|right |
||
| 1617 | * @param int $width width of media in pixel |
||
| 1618 | * @param int $height height of media in pixel |
||
| 1619 | * @param string $cache cache|recache|nocache |
||
| 1620 | * @param bool $render should the media be embedded inline or just linked |
||
| 1621 | * @return string |
||
| 1622 | */ |
||
| 1623 | public function _media($src, $title = null, $align = null, $width = null, |
||
| 1624 | $height = null, $cache = null, $render = true) { |
||
| 1625 | |||
| 1626 | $ret = ''; |
||
| 1627 | |||
| 1628 | list($ext, $mime) = mimetype($src); |
||
| 1629 | if(substr($mime, 0, 5) == 'image') { |
||
| 1630 | // first get the $title |
||
| 1631 | if(!is_null($title)) { |
||
| 1632 | $title = $this->_xmlEntities($title); |
||
| 1633 | } elseif($ext == 'jpg' || $ext == 'jpeg') { |
||
| 1634 | //try to use the caption from IPTC/EXIF |
||
| 1635 | require_once(DOKU_INC.'inc/JpegMeta.php'); |
||
| 1636 | $jpeg = new JpegMeta(mediaFN($src)); |
||
| 1637 | if($jpeg !== false) $cap = $jpeg->getTitle(); |
||
| 1638 | if(!empty($cap)) { |
||
| 1639 | $title = $this->_xmlEntities($cap); |
||
| 1640 | } |
||
| 1641 | } |
||
| 1642 | if(!$render) { |
||
| 1643 | // if the picture is not supposed to be rendered |
||
| 1644 | // return the title of the picture |
||
| 1645 | if($title === null || $title === "") { |
||
| 1646 | // just show the sourcename |
||
| 1647 | $title = $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($src))); |
||
| 1648 | } |
||
| 1649 | return $title; |
||
| 1650 | } |
||
| 1651 | //add image tag |
||
| 1652 | $ret .= '<img src="' . ml( |
||
| 1653 | $src, |
||
| 1654 | array( |
||
| 1655 | 'w' => $width, 'h' => $height, |
||
| 1656 | 'cache' => $cache, |
||
| 1657 | 'rev' => $this->_getLastMediaRevisionAt($src) |
||
| 1658 | ) |
||
| 1659 | ) . '"'; |
||
| 1660 | $ret .= ' class="media'.$align.'"'; |
||
| 1661 | |||
| 1662 | if($title) { |
||
| 1663 | $ret .= ' title="'.$title.'"'; |
||
| 1664 | $ret .= ' alt="'.$title.'"'; |
||
| 1665 | } else { |
||
| 1666 | $ret .= ' alt=""'; |
||
| 1667 | } |
||
| 1668 | |||
| 1669 | if(!is_null($width)) |
||
| 1670 | $ret .= ' width="'.$this->_xmlEntities($width).'"'; |
||
| 1671 | |||
| 1672 | if(!is_null($height)) |
||
| 1673 | $ret .= ' height="'.$this->_xmlEntities($height).'"'; |
||
| 1674 | |||
| 1675 | $ret .= ' />'; |
||
| 1676 | |||
| 1677 | } elseif(media_supportedav($mime, 'video') || media_supportedav($mime, 'audio')) { |
||
| 1678 | // first get the $title |
||
| 1679 | $title = !is_null($title) ? $title : false; |
||
| 1680 | if(!$render) { |
||
| 1681 | // if the file is not supposed to be rendered |
||
| 1682 | // return the title of the file (just the sourcename if there is no title) |
||
| 1683 | return $this->_xmlEntities($title ? $title : \dokuwiki\Utf8\PhpString::basename(noNS($src))); |
||
| 1684 | } |
||
| 1685 | |||
| 1686 | $att = array(); |
||
| 1687 | $att['class'] = "media$align"; |
||
| 1688 | if($title) { |
||
| 1689 | $att['title'] = $title; |
||
| 1690 | } |
||
| 1691 | |||
| 1692 | if(media_supportedav($mime, 'video')) { |
||
| 1693 | //add video |
||
| 1694 | $ret .= $this->_video($src, $width, $height, $att); |
||
| 1695 | } |
||
| 1696 | if(media_supportedav($mime, 'audio')) { |
||
| 1697 | //add audio |
||
| 1698 | $ret .= $this->_audio($src, $att); |
||
| 1699 | } |
||
| 1700 | |||
| 1701 | } elseif($mime == 'application/x-shockwave-flash') { |
||
| 1702 | if(!$render) { |
||
| 1703 | // if the flash is not supposed to be rendered |
||
| 1704 | // return the title of the flash |
||
| 1705 | if(!$title) { |
||
| 1706 | // just show the sourcename |
||
| 1707 | $title = \dokuwiki\Utf8\PhpString::basename(noNS($src)); |
||
| 1708 | } |
||
| 1709 | return $this->_xmlEntities($title); |
||
| 1710 | } |
||
| 1711 | |||
| 1712 | $att = array(); |
||
| 1713 | $att['class'] = "media$align"; |
||
| 1714 | if($align == 'right') $att['align'] = 'right'; |
||
| 1715 | if($align == 'left') $att['align'] = 'left'; |
||
| 1716 | $ret .= html_flashobject( |
||
| 1717 | ml($src, array('cache' => $cache), true, '&'), $width, $height, |
||
| 1718 | array('quality' => 'high'), |
||
| 1719 | null, |
||
| 1720 | $att, |
||
| 1721 | $this->_xmlEntities($title) |
||
| 1722 | ); |
||
| 1723 | } elseif($title) { |
||
| 1724 | // well at least we have a title to display |
||
| 1725 | $ret .= $this->_xmlEntities($title); |
||
| 1726 | } else { |
||
| 1727 | // just show the sourcename |
||
| 1728 | $ret .= $this->_xmlEntities(\dokuwiki\Utf8\PhpString::basename(noNS($src))); |
||
| 1729 | } |
||
| 1730 | |||
| 1731 | return $ret; |
||
| 1732 | } |
||
| 1733 | |||
| 1734 | /** |
||
| 1735 | * Escape string for output |
||
| 1736 | * |
||
| 1737 | * @param $string |
||
| 1738 | * @return string |
||
| 1739 | */ |
||
| 1740 | public function _xmlEntities($string) { |
||
| 1743 | |||
| 1744 | |||
| 1745 | |||
| 1746 | /** |
||
| 1747 | * Construct a title and handle images in titles |
||
| 1748 | * |
||
| 1749 | * @author Harry Fuecks <[email protected]> |
||
| 1750 | * @param string|array $title either string title or media array |
||
| 1751 | * @param string $default default title if nothing else is found |
||
| 1752 | * @param bool $isImage will be set to true if it's a media file |
||
| 1753 | * @param null|string $id linked page id (used to extract title from first heading) |
||
| 1754 | * @param string $linktype content|navigation |
||
| 1755 | * @return string HTML of the title, might be full image tag or just escaped text |
||
| 1756 | */ |
||
| 1757 | public function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { |
||
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Returns HTML code for images used in link titles |
||
| 1777 | * |
||
| 1778 | * @author Andreas Gohr <[email protected]> |
||
| 1779 | * @param array $img |
||
| 1780 | * @return string HTML img tag or similar |
||
| 1781 | */ |
||
| 1782 | public function _imageTitle($img) { |
||
| 1801 | |||
| 1802 | /** |
||
| 1803 | * helperfunction to return a basic link to a media |
||
| 1804 | * |
||
| 1805 | * used in internalmedia() and externalmedia() |
||
| 1806 | * |
||
| 1807 | * @author Pierre Spring <[email protected]> |
||
| 1808 | * @param string $src media ID |
||
| 1809 | * @param string $title descriptive text |
||
| 1810 | * @param string $align left|center|right |
||
| 1811 | * @param int $width width of media in pixel |
||
| 1812 | * @param int $height height of media in pixel |
||
| 1813 | * @param string $cache cache|recache|nocache |
||
| 1814 | * @param bool $render should the media be embedded inline or just linked |
||
| 1815 | * @return array associative array with link config |
||
| 1816 | */ |
||
| 1817 | public function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) { |
||
| 1833 | |||
| 1834 | /** |
||
| 1835 | * Embed video(s) in HTML |
||
| 1836 | * |
||
| 1837 | * @author Anika Henke <[email protected]> |
||
| 1838 | * @author Schplurtz le Déboulonné <[email protected]> |
||
| 1839 | * |
||
| 1840 | * @param string $src - ID of video to embed |
||
| 1841 | * @param int $width - width of the video in pixels |
||
| 1842 | * @param int $height - height of the video in pixels |
||
| 1843 | * @param array $atts - additional attributes for the <video> tag |
||
| 1844 | * @return string |
||
| 1845 | */ |
||
| 1846 | public function _video($src, $width, $height, $atts = null) { |
||
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Embed audio in HTML |
||
| 1922 | * |
||
| 1923 | * @author Anika Henke <[email protected]> |
||
| 1924 | * |
||
| 1925 | * @param string $src - ID of audio to embed |
||
| 1926 | * @param array $atts - additional attributes for the <audio> tag |
||
| 1927 | * @return string |
||
| 1928 | */ |
||
| 1929 | public function _audio($src, $atts = array()) { |
||
| 1978 | |||
| 1979 | /** |
||
| 1980 | * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media() |
||
| 1981 | * which returns an existing media revision less or equal to rev or date_at |
||
| 1982 | * |
||
| 1983 | * @author lisps |
||
| 1984 | * @param string $media_id |
||
| 1985 | * @access protected |
||
| 1986 | * @return string revision ('' for current) |
||
| 1987 | */ |
||
| 1988 | protected function _getLastMediaRevisionAt($media_id){ |
||
| 1993 | |||
| 1994 | #endregion |
||
| 1995 | } |
||
| 1996 | |||
| 1998 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: