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) { |
||
| 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) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Returns the format produced by this renderer. |
||
| 95 | * |
||
| 96 | * @return string always 'xhtml' |
||
| 97 | */ |
||
| 98 | function getFormat() { |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Initialize the document |
||
| 104 | */ |
||
| 105 | function document_start() { |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Finalize the document |
||
| 113 | */ |
||
| 114 | function document_end() { |
||
| 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) { |
||
| 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) { |
||
| 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) { |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Close the current section |
||
| 238 | */ |
||
| 239 | function section_close() { |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Render plain text data |
||
| 245 | * |
||
| 246 | * @param $text |
||
| 247 | */ |
||
| 248 | function cdata($text) { |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Open a paragraph |
||
| 254 | */ |
||
| 255 | function p_open() { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Close a paragraph |
||
| 261 | */ |
||
| 262 | function p_close() { |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Create a line break |
||
| 268 | */ |
||
| 269 | function linebreak() { |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Create a horizontal line |
||
| 275 | */ |
||
| 276 | function hr() { |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Start strong (bold) formatting |
||
| 282 | */ |
||
| 283 | function strong_open() { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Stop strong (bold) formatting |
||
| 289 | */ |
||
| 290 | function strong_close() { |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Start emphasis (italics) formatting |
||
| 296 | */ |
||
| 297 | function emphasis_open() { |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Stop emphasis (italics) formatting |
||
| 303 | */ |
||
| 304 | function emphasis_close() { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Start underline formatting |
||
| 310 | */ |
||
| 311 | function underline_open() { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Stop underline formatting |
||
| 317 | */ |
||
| 318 | function underline_close() { |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Start monospace formatting |
||
| 324 | */ |
||
| 325 | function monospace_open() { |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Stop monospace formatting |
||
| 331 | */ |
||
| 332 | function monospace_close() { |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Start a subscript |
||
| 338 | */ |
||
| 339 | function subscript_open() { |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Stop a subscript |
||
| 345 | */ |
||
| 346 | function subscript_close() { |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Start a superscript |
||
| 352 | */ |
||
| 353 | function superscript_open() { |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Stop a superscript |
||
| 359 | */ |
||
| 360 | function superscript_close() { |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Start deleted (strike-through) formatting |
||
| 366 | */ |
||
| 367 | function deleted_open() { |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Stop deleted (strike-through) formatting |
||
| 373 | */ |
||
| 374 | function deleted_close() { |
||
| 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() { |
||
| 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() { |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Open an unordered list |
||
| 430 | * |
||
| 431 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 432 | */ |
||
| 433 | function listu_open($classes = null) { |
||
| 434 | $class = ''; |
||
| 435 | if($classes !== null) { |
||
| 436 | if(is_array($classes)) $classes = join(' ', $classes); |
||
| 437 | $class = " class=\"$classes\""; |
||
| 438 | } |
||
| 439 | $this->doc .= "<ul$class>".DOKU_LF; |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Close an unordered list |
||
| 444 | */ |
||
| 445 | function listu_close() { |
||
| 446 | $this->doc .= '</ul>'.DOKU_LF; |
||
| 447 | } |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Open an ordered list |
||
| 451 | * |
||
| 452 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 453 | */ |
||
| 454 | function listo_open($classes = null) { |
||
| 455 | $class = ''; |
||
| 456 | if($classes !== null) { |
||
| 457 | if(is_array($classes)) $classes = join(' ', $classes); |
||
| 458 | $class = " class=\"$classes\""; |
||
| 459 | } |
||
| 460 | $this->doc .= "<ol$class>".DOKU_LF; |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Close an ordered list |
||
| 465 | */ |
||
| 466 | function listo_close() { |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Open a list item |
||
| 472 | * |
||
| 473 | * @param int $level the nesting level |
||
| 474 | * @param bool $node true when a node; false when a leaf |
||
| 475 | */ |
||
| 476 | function listitem_open($level, $node=false) { |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Close a list item |
||
| 483 | */ |
||
| 484 | function listitem_close() { |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Start the content of a list item |
||
| 490 | */ |
||
| 491 | function listcontent_open() { |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Stop the content of a list item |
||
| 497 | */ |
||
| 498 | function listcontent_close() { |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Output unformatted $text |
||
| 504 | * |
||
| 505 | * Defaults to $this->cdata() |
||
| 506 | * |
||
| 507 | * @param string $text |
||
| 508 | */ |
||
| 509 | function unformatted($text) { |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Execute PHP code if allowed |
||
| 515 | * |
||
| 516 | * @param string $text PHP code that is either executed or printed |
||
| 517 | * @param string $wrapper html element to wrap result if $conf['phpok'] is okff |
||
| 518 | * |
||
| 519 | * @author Andreas Gohr <[email protected]> |
||
| 520 | */ |
||
| 521 | function php($text, $wrapper = 'code') { |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Output block level PHP code |
||
| 536 | * |
||
| 537 | * If $conf['phpok'] is true this should evaluate the given code and append the result |
||
| 538 | * to $doc |
||
| 539 | * |
||
| 540 | * @param string $text The PHP code |
||
| 541 | */ |
||
| 542 | function phpblock($text) { |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Insert HTML if allowed |
||
| 548 | * |
||
| 549 | * @param string $text html text |
||
| 550 | * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff |
||
| 551 | * |
||
| 552 | * @author Andreas Gohr <[email protected]> |
||
| 553 | */ |
||
| 554 | function html($text, $wrapper = 'code') { |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Output raw block-level HTML |
||
| 566 | * |
||
| 567 | * If $conf['htmlok'] is true this should add the code as is to $doc |
||
| 568 | * |
||
| 569 | * @param string $text The HTML |
||
| 570 | */ |
||
| 571 | function htmlblock($text) { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Start a block quote |
||
| 577 | */ |
||
| 578 | function quote_open() { |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Stop a block quote |
||
| 584 | */ |
||
| 585 | function quote_close() { |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Output preformatted text |
||
| 591 | * |
||
| 592 | * @param string $text |
||
| 593 | */ |
||
| 594 | function preformatted($text) { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Display text as file content, optionally syntax highlighted |
||
| 600 | * |
||
| 601 | * @param string $text text to show |
||
| 602 | * @param string $language programming language to use for syntax highlighting |
||
| 603 | * @param string $filename file path label |
||
| 604 | */ |
||
| 605 | function file($text, $language = null, $filename = null) { |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Display text as code content, optionally syntax highlighted |
||
| 611 | * |
||
| 612 | * @param string $text text to show |
||
| 613 | * @param string $language programming language to use for syntax highlighting |
||
| 614 | * @param string $filename file path label |
||
| 615 | */ |
||
| 616 | function code($text, $language = null, $filename = null) { |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Use GeSHi to highlight language syntax in code and file blocks |
||
| 622 | * |
||
| 623 | * @author Andreas Gohr <[email protected]> |
||
| 624 | * @param string $type code|file |
||
| 625 | * @param string $text text to show |
||
| 626 | * @param string $language programming language to use for syntax highlighting |
||
| 627 | * @param string $filename file path label |
||
| 628 | */ |
||
| 629 | function _highlight($type, $text, $language = null, $filename = null) { |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Format an acronym |
||
| 670 | * |
||
| 671 | * Uses $this->acronyms |
||
| 672 | * |
||
| 673 | * @param string $acronym |
||
| 674 | */ |
||
| 675 | function acronym($acronym) { |
||
| 688 | |||
| 689 | /** |
||
| 690 | * Format a smiley |
||
| 691 | * |
||
| 692 | * Uses $this->smiley |
||
| 693 | * |
||
| 694 | * @param string $smiley |
||
| 695 | */ |
||
| 696 | function smiley($smiley) { |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Format an entity |
||
| 708 | * |
||
| 709 | * Entities are basically small text replacements |
||
| 710 | * |
||
| 711 | * Uses $this->entities |
||
| 712 | * |
||
| 713 | * @param string $entity |
||
| 714 | */ |
||
| 715 | function entity($entity) { |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Typographically format a multiply sign |
||
| 725 | * |
||
| 726 | * Example: ($x=640, $y=480) should result in "640×480" |
||
| 727 | * |
||
| 728 | * @param string|int $x first value |
||
| 729 | * @param string|int $y second value |
||
| 730 | */ |
||
| 731 | function multiplyentity($x, $y) { |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Render an opening single quote char (language specific) |
||
| 737 | */ |
||
| 738 | function singlequoteopening() { |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Render a closing single quote char (language specific) |
||
| 745 | */ |
||
| 746 | function singlequoteclosing() { |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Render an apostrophe char (language specific) |
||
| 753 | */ |
||
| 754 | function apostrophe() { |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Render an opening double quote char (language specific) |
||
| 761 | */ |
||
| 762 | function doublequoteopening() { |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Render an closinging double quote char (language specific) |
||
| 769 | */ |
||
| 770 | function doublequoteclosing() { |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Render a CamelCase link |
||
| 777 | * |
||
| 778 | * @param string $link The link name |
||
| 779 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 780 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 781 | * |
||
| 782 | * @see http://en.wikipedia.org/wiki/CamelCase |
||
| 783 | */ |
||
| 784 | function camelcaselink($link, $returnonly = false) { |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Render a page local link |
||
| 794 | * |
||
| 795 | * @param string $hash hash link identifier |
||
| 796 | * @param string $name name for the link |
||
| 797 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 798 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 799 | */ |
||
| 800 | function locallink($hash, $name = null, $returnonly = false) { |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Render an internal Wiki Link |
||
| 819 | * |
||
| 820 | * $search,$returnonly & $linktype are not for the renderer but are used |
||
| 821 | * elsewhere - no need to implement them in other renderers |
||
| 822 | * |
||
| 823 | * @author Andreas Gohr <[email protected]> |
||
| 824 | * @param string $id pageid |
||
| 825 | * @param string|null $name link name |
||
| 826 | * @param string|null $search adds search url param |
||
| 827 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 828 | * @param string $linktype type to set use of headings |
||
| 829 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 830 | */ |
||
| 831 | function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content') { |
||
| 913 | |||
| 914 | /** |
||
| 915 | * Render an external link |
||
| 916 | * |
||
| 917 | * @param string $url full URL with scheme |
||
| 918 | * @param string|array $name name for the link, array for media file |
||
| 919 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 920 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 921 | */ |
||
| 922 | function externallink($url, $name = null, $returnonly = false) { |
||
| 923 | global $conf; |
||
| 924 | |||
| 925 | $name = $this->_getLinkTitle($name, $url, $isImage); |
||
| 926 | |||
| 927 | // url might be an attack vector, only allow registered protocols |
||
| 928 | if(is_null($this->schemes)) $this->schemes = getSchemes(); |
||
| 929 | list($scheme) = explode('://', $url); |
||
| 930 | $scheme = strtolower($scheme); |
||
| 931 | if(!in_array($scheme, $this->schemes)) $url = ''; |
||
| 932 | |||
| 933 | // is there still an URL? |
||
| 934 | if(!$url) { |
||
| 935 | if($returnonly) { |
||
| 936 | return $name; |
||
| 937 | } else { |
||
| 938 | $this->doc .= $name; |
||
| 939 | } |
||
| 940 | return; |
||
| 941 | } |
||
| 942 | |||
| 943 | // set class |
||
| 944 | if(!$isImage) { |
||
| 945 | $class = 'urlextern'; |
||
| 946 | } else { |
||
| 947 | $class = 'media'; |
||
| 948 | } |
||
| 949 | |||
| 950 | //prepare for formating |
||
| 951 | $link = array(); |
||
| 952 | $link['target'] = $conf['target']['extern']; |
||
| 953 | $link['style'] = ''; |
||
| 954 | $link['pre'] = ''; |
||
| 955 | $link['suf'] = ''; |
||
| 956 | $link['more'] = ''; |
||
| 957 | $link['class'] = $class; |
||
| 958 | $link['url'] = $url; |
||
| 959 | $link['rel'] = ''; |
||
| 960 | |||
| 961 | $link['name'] = $name; |
||
| 962 | $link['title'] = $this->_xmlEntities($url); |
||
| 963 | if($conf['relnofollow']) $link['rel'] .= ' nofollow'; |
||
| 964 | if($conf['target']['extern']) $link['rel'] .= ' noopener'; |
||
| 965 | |||
| 966 | //output formatted |
||
| 967 | if($returnonly) { |
||
| 968 | return $this->_formatLink($link); |
||
| 969 | } else { |
||
| 970 | $this->doc .= $this->_formatLink($link); |
||
| 971 | } |
||
| 972 | } |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Render an interwiki link |
||
| 976 | * |
||
| 977 | * You may want to use $this->_resolveInterWiki() here |
||
| 978 | * |
||
| 979 | * @param string $match original link - probably not much use |
||
| 980 | * @param string|array $name name for the link, array for media file |
||
| 981 | * @param string $wikiName indentifier (shortcut) for the remote wiki |
||
| 982 | * @param string $wikiUri the fragment parsed from the original link |
||
| 983 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 984 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 985 | */ |
||
| 986 | function interwikilink($match, $name = null, $wikiName, $wikiUri, $returnonly = false) { |
||
| 987 | global $conf; |
||
| 988 | |||
| 989 | $link = array(); |
||
| 990 | $link['target'] = $conf['target']['interwiki']; |
||
| 991 | $link['pre'] = ''; |
||
| 992 | $link['suf'] = ''; |
||
| 993 | $link['more'] = ''; |
||
| 994 | $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); |
||
| 995 | $link['rel'] = ''; |
||
| 996 | |||
| 997 | //get interwiki URL |
||
| 998 | $exists = null; |
||
| 999 | $url = $this->_resolveInterWiki($wikiName, $wikiUri, $exists); |
||
| 1000 | |||
| 1001 | if(!$isImage) { |
||
| 1002 | $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $wikiName); |
||
| 1003 | $link['class'] = "interwiki iw_$class"; |
||
| 1004 | } else { |
||
| 1005 | $link['class'] = 'media'; |
||
| 1006 | } |
||
| 1007 | |||
| 1008 | //do we stay at the same server? Use local target |
||
| 1009 | if(strpos($url, DOKU_URL) === 0 OR strpos($url, DOKU_BASE) === 0) { |
||
| 1010 | $link['target'] = $conf['target']['wiki']; |
||
| 1011 | } |
||
| 1012 | if($exists !== null && !$isImage) { |
||
| 1013 | if($exists) { |
||
| 1014 | $link['class'] .= ' wikilink1'; |
||
| 1015 | } else { |
||
| 1016 | $link['class'] .= ' wikilink2'; |
||
| 1017 | $link['rel'] .= ' nofollow'; |
||
| 1018 | } |
||
| 1019 | } |
||
| 1020 | if($conf['target']['interwiki']) $link['rel'] .= ' noopener'; |
||
| 1021 | |||
| 1022 | $link['url'] = $url; |
||
| 1023 | $link['title'] = htmlspecialchars($link['url']); |
||
| 1024 | |||
| 1025 | //output formatted |
||
| 1026 | if($returnonly) { |
||
| 1027 | return $this->_formatLink($link); |
||
| 1028 | } else { |
||
| 1029 | $this->doc .= $this->_formatLink($link); |
||
| 1030 | } |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Link to windows share |
||
| 1035 | * |
||
| 1036 | * @param string $url the link |
||
| 1037 | * @param string|array $name name for the link, array for media file |
||
| 1038 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1039 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 1040 | */ |
||
| 1041 | function windowssharelink($url, $name = null, $returnonly = false) { |
||
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Render a linked E-Mail Address |
||
| 1073 | * |
||
| 1074 | * Honors $conf['mailguard'] setting |
||
| 1075 | * |
||
| 1076 | * @param string $address Email-Address |
||
| 1077 | * @param string|array $name name for the link, array for media file |
||
| 1078 | * @param bool $returnonly whether to return html or write to doc attribute |
||
| 1079 | * @return void|string writes to doc attribute or returns html depends on $returnonly |
||
| 1080 | */ |
||
| 1081 | function emaillink($address, $name = null, $returnonly = false) { |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Render an internal media file |
||
| 1122 | * |
||
| 1123 | * @param string $src media ID |
||
| 1124 | * @param string $title descriptive text |
||
| 1125 | * @param string $align left|center|right |
||
| 1126 | * @param int $width width of media in pixel |
||
| 1127 | * @param int $height height of media in pixel |
||
| 1128 | * @param string $cache cache|recache|nocache |
||
| 1129 | * @param string $linking linkonly|detail|nolink |
||
| 1130 | * @param bool $return return HTML instead of adding to $doc |
||
| 1131 | * @return void|string writes to doc attribute or returns html depends on $return |
||
| 1132 | */ |
||
| 1133 | function internalmedia($src, $title = null, $align = null, $width = null, |
||
| 1134 | $height = null, $cache = null, $linking = null, $return = false) { |
||
| 1135 | global $ID; |
||
| 1136 | if (strpos($src, '#') !== false) { |
||
| 1137 | list($src, $hash) = explode('#', $src, 2); |
||
| 1138 | } |
||
| 1139 | resolve_mediaid(getNS($ID), $src, $exists, $this->date_at, true); |
||
| 1140 | |||
| 1141 | $noLink = false; |
||
| 1142 | $render = ($linking == 'linkonly') ? false : true; |
||
| 1143 | $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); |
||
| 1144 | |||
| 1145 | list($ext, $mime) = mimetype($src, false); |
||
| 1146 | if(substr($mime, 0, 5) == 'image' && $render) { |
||
| 1147 | $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache, 'rev'=>$this->_getLastMediaRevisionAt($src)), ($linking == 'direct')); |
||
| 1148 | } elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render) { |
||
| 1149 | // don't link movies |
||
| 1150 | $noLink = true; |
||
| 1151 | } else { |
||
| 1152 | // add file icons |
||
| 1153 | $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext); |
||
| 1154 | $link['class'] .= ' mediafile mf_'.$class; |
||
| 1155 | $link['url'] = ml($src, array('id' => $ID, 'cache' => $cache , 'rev'=>$this->_getLastMediaRevisionAt($src)), true); |
||
| 1156 | if($exists) $link['title'] .= ' ('.filesize_h(filesize(mediaFN($src))).')'; |
||
| 1157 | } |
||
| 1158 | |||
| 1159 | if (!empty($hash)) $link['url'] .= '#'.$hash; |
||
| 1160 | |||
| 1161 | //markup non existing files |
||
| 1162 | if(!$exists) { |
||
| 1163 | $link['class'] .= ' wikilink2'; |
||
| 1164 | } |
||
| 1165 | |||
| 1166 | //output formatted |
||
| 1167 | if($return) { |
||
| 1168 | if($linking == 'nolink' || $noLink) return $link['name']; |
||
| 1169 | else return $this->_formatLink($link); |
||
| 1170 | } else { |
||
| 1171 | if($linking == 'nolink' || $noLink) $this->doc .= $link['name']; |
||
| 1172 | else $this->doc .= $this->_formatLink($link); |
||
| 1173 | } |
||
| 1174 | } |
||
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Render an external media file |
||
| 1178 | * |
||
| 1179 | * @param string $src full media URL |
||
| 1180 | * @param string $title descriptive text |
||
| 1181 | * @param string $align left|center|right |
||
| 1182 | * @param int $width width of media in pixel |
||
| 1183 | * @param int $height height of media in pixel |
||
| 1184 | * @param string $cache cache|recache|nocache |
||
| 1185 | * @param string $linking linkonly|detail|nolink |
||
| 1186 | * @param bool $return return HTML instead of adding to $doc |
||
| 1187 | * @return void|string writes to doc attribute or returns html depends on $return |
||
| 1188 | */ |
||
| 1189 | function externalmedia($src, $title = null, $align = null, $width = null, |
||
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Renders an RSS feed |
||
| 1230 | * |
||
| 1231 | * @param string $url URL of the feed |
||
| 1232 | * @param array $params Finetuning of the output |
||
| 1233 | * |
||
| 1234 | * @author Andreas Gohr <[email protected]> |
||
| 1235 | */ |
||
| 1236 | function rss($url, $params) { |
||
| 1319 | |||
| 1320 | /** |
||
| 1321 | * Start a table |
||
| 1322 | * |
||
| 1323 | * @param int $maxcols maximum number of columns |
||
| 1324 | * @param int $numrows NOT IMPLEMENTED |
||
| 1325 | * @param int $pos byte position in the original source |
||
| 1326 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1327 | */ |
||
| 1328 | function table_open($maxcols = null, $numrows = null, $pos = null, $classes = null) { |
||
| 1342 | |||
| 1343 | /** |
||
| 1344 | * Close a table |
||
| 1345 | * |
||
| 1346 | * @param int $pos byte position in the original source |
||
| 1347 | */ |
||
| 1348 | function table_close($pos = null) { |
||
| 1354 | |||
| 1355 | /** |
||
| 1356 | * Open a table header |
||
| 1357 | */ |
||
| 1358 | function tablethead_open() { |
||
| 1361 | |||
| 1362 | /** |
||
| 1363 | * Close a table header |
||
| 1364 | */ |
||
| 1365 | function tablethead_close() { |
||
| 1368 | |||
| 1369 | /** |
||
| 1370 | * Open a table body |
||
| 1371 | */ |
||
| 1372 | function tabletbody_open() { |
||
| 1375 | |||
| 1376 | /** |
||
| 1377 | * Close a table body |
||
| 1378 | */ |
||
| 1379 | function tabletbody_close() { |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * Open a table footer |
||
| 1385 | */ |
||
| 1386 | function tabletfoot_open() { |
||
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Close a table footer |
||
| 1392 | */ |
||
| 1393 | function tabletfoot_close() { |
||
| 1396 | |||
| 1397 | /** |
||
| 1398 | * Open a table row |
||
| 1399 | * |
||
| 1400 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1401 | */ |
||
| 1402 | function tablerow_open($classes = null) { |
||
| 1412 | |||
| 1413 | /** |
||
| 1414 | * Close a table row |
||
| 1415 | */ |
||
| 1416 | function tablerow_close() { |
||
| 1419 | |||
| 1420 | /** |
||
| 1421 | * Open a table header cell |
||
| 1422 | * |
||
| 1423 | * @param int $colspan |
||
| 1424 | * @param string $align left|center|right |
||
| 1425 | * @param int $rowspan |
||
| 1426 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1427 | */ |
||
| 1428 | function tableheader_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) { |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Close a table header cell |
||
| 1451 | */ |
||
| 1452 | function tableheader_close() { |
||
| 1455 | |||
| 1456 | /** |
||
| 1457 | * Open a table cell |
||
| 1458 | * |
||
| 1459 | * @param int $colspan |
||
| 1460 | * @param string $align left|center|right |
||
| 1461 | * @param int $rowspan |
||
| 1462 | * @param string|string[] $classes css classes - have to be valid, do not pass unfiltered user input |
||
| 1463 | */ |
||
| 1464 | function tablecell_open($colspan = 1, $align = null, $rowspan = 1, $classes = null) { |
||
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Close a table cell |
||
| 1487 | */ |
||
| 1488 | function tablecell_close() { |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Returns the current header level. |
||
| 1494 | * (required e.g. by the filelist plugin) |
||
| 1495 | * |
||
| 1496 | * @return int The current header level |
||
| 1497 | */ |
||
| 1498 | function getLastlevel() { |
||
| 1501 | |||
| 1502 | #region Utility functions |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Build a link |
||
| 1506 | * |
||
| 1507 | * Assembles all parts defined in $link returns HTML for the link |
||
| 1508 | * |
||
| 1509 | * @param array $link attributes of a link |
||
| 1510 | * @return string |
||
| 1511 | * |
||
| 1512 | * @author Andreas Gohr <[email protected]> |
||
| 1513 | */ |
||
| 1514 | function _formatLink($link) { |
||
| 1543 | |||
| 1544 | /** |
||
| 1545 | * Renders internal and external media |
||
| 1546 | * |
||
| 1547 | * @author Andreas Gohr <[email protected]> |
||
| 1548 | * @param string $src media ID |
||
| 1549 | * @param string $title descriptive text |
||
| 1550 | * @param string $align left|center|right |
||
| 1551 | * @param int $width width of media in pixel |
||
| 1552 | * @param int $height height of media in pixel |
||
| 1553 | * @param string $cache cache|recache|nocache |
||
| 1554 | * @param bool $render should the media be embedded inline or just linked |
||
| 1555 | * @return string |
||
| 1556 | */ |
||
| 1557 | function _media($src, $title = null, $align = null, $width = null, |
||
| 1660 | |||
| 1661 | /** |
||
| 1662 | * Escape string for output |
||
| 1663 | * |
||
| 1664 | * @param $string |
||
| 1665 | * @return string |
||
| 1666 | */ |
||
| 1667 | function _xmlEntities($string) { |
||
| 1670 | |||
| 1671 | /** |
||
| 1672 | * Creates a linkid from a headline |
||
| 1673 | * |
||
| 1674 | * @author Andreas Gohr <[email protected]> |
||
| 1675 | * @param string $title The headline title |
||
| 1676 | * @param boolean $create Create a new unique ID? |
||
| 1677 | * @return string |
||
| 1678 | */ |
||
| 1679 | function _headerToLink($title, $create = false) { |
||
| 1687 | |||
| 1688 | /** |
||
| 1689 | * Construct a title and handle images in titles |
||
| 1690 | * |
||
| 1691 | * @author Harry Fuecks <[email protected]> |
||
| 1692 | * @param string|array $title either string title or media array |
||
| 1693 | * @param string $default default title if nothing else is found |
||
| 1694 | * @param bool $isImage will be set to true if it's a media file |
||
| 1695 | * @param null|string $id linked page id (used to extract title from first heading) |
||
| 1696 | * @param string $linktype content|navigation |
||
| 1697 | * @return string HTML of the title, might be full image tag or just escaped text |
||
| 1698 | */ |
||
| 1699 | function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { |
||
| 1716 | |||
| 1717 | /** |
||
| 1718 | * Returns HTML code for images used in link titles |
||
| 1719 | * |
||
| 1720 | * @author Andreas Gohr <[email protected]> |
||
| 1721 | * @param array $img |
||
| 1722 | * @return string HTML img tag or similar |
||
| 1723 | */ |
||
| 1724 | function _imageTitle($img) { |
||
| 1743 | |||
| 1744 | /** |
||
| 1745 | * helperfunction to return a basic link to a media |
||
| 1746 | * |
||
| 1747 | * used in internalmedia() and externalmedia() |
||
| 1748 | * |
||
| 1749 | * @author Pierre Spring <[email protected]> |
||
| 1750 | * @param string $src media ID |
||
| 1751 | * @param string $title descriptive text |
||
| 1752 | * @param string $align left|center|right |
||
| 1753 | * @param int $width width of media in pixel |
||
| 1754 | * @param int $height height of media in pixel |
||
| 1755 | * @param string $cache cache|recache|nocache |
||
| 1756 | * @param bool $render should the media be embedded inline or just linked |
||
| 1757 | * @return array associative array with link config |
||
| 1758 | */ |
||
| 1759 | function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) { |
||
| 1775 | |||
| 1776 | /** |
||
| 1777 | * Embed video(s) in HTML |
||
| 1778 | * |
||
| 1779 | * @author Anika Henke <[email protected]> |
||
| 1780 | * |
||
| 1781 | * @param string $src - ID of video to embed |
||
| 1782 | * @param int $width - width of the video in pixels |
||
| 1783 | * @param int $height - height of the video in pixels |
||
| 1784 | * @param array $atts - additional attributes for the <video> tag |
||
| 1785 | * @return string |
||
| 1786 | */ |
||
| 1787 | function _video($src, $width, $height, $atts = null) { |
||
| 1841 | |||
| 1842 | /** |
||
| 1843 | * Embed audio in HTML |
||
| 1844 | * |
||
| 1845 | * @author Anika Henke <[email protected]> |
||
| 1846 | * |
||
| 1847 | * @param string $src - ID of audio to embed |
||
| 1848 | * @param array $atts - additional attributes for the <audio> tag |
||
| 1849 | * @return string |
||
| 1850 | */ |
||
| 1851 | function _audio($src, $atts = array()) { |
||
| 1891 | |||
| 1892 | /** |
||
| 1893 | * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media() |
||
| 1894 | * which returns an existing media revision less or equal to rev or date_at |
||
| 1895 | * |
||
| 1896 | * @author lisps |
||
| 1897 | * @param string $media_id |
||
| 1898 | * @access protected |
||
| 1899 | * @return string revision ('' for current) |
||
| 1900 | */ |
||
| 1901 | function _getLastMediaRevisionAt($media_id){ |
||
| 1906 | |||
| 1907 | #endregion |
||
| 1908 | } |
||
| 1909 | |||
| 1911 |
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.