1<?php 2 3namespace dokuwiki\template\sprintdoc; 4 5/** 6 * Class tpl 7 * 8 * Provides additional template functions for the dokuwiki template 9 * @package dokuwiki\tpl\dokuwiki 10 */ 11 12class tpl { 13 static $icons = array( 14 'default' => '00-default_checkbox-blank-circle-outline.svg', 15 'edit' => '01-edit_pencil.svg', 16 'create' => '02-create_pencil.svg', 17 'draft' => '03-draft_android-studio.svg', 18 'show' => '04-show_file-document.svg', 19 'source' => '05-source_file-xml.svg', 20 'revert' => '06-revert_replay.svg', 21 'revs' => '07-revisions_history.svg', 22 'backlink' => '08-backlink_link-variant.svg', 23 'subscribe' => '09-subscribe_email-outline.svg', 24 'top' => '10-top_arrow-up.svg', 25 'mediaManager' => '11-mediamanager_folder-image.svg', 26 'img_backto' => '12-back_arrow-left.svg', 27 ); 28 29/** 30 * Return the HTML for one of the default actions 31 * 32 * Reimplements parts of tpl_actionlink 33 * 34 * @param string $action 35 * @return string 36 */ 37 static public function pageToolAction($action) { 38 $data = tpl_get_action($action); 39 if(!is_array($data)) return ''; 40 global $lang; 41 42 if($data['id'][0] == '#') { 43 $linktarget = $data['id']; 44 } else { 45 $linktarget = wl($data['id'], $data['params'], false, '&'); 46 } 47 $caption = $lang['btn_' . $data['type']]; 48 if(strpos($caption, '%s')) { 49 $caption = sprintf($caption, $data['replacement']); 50 } 51 52 $svg = __DIR__ . '/images/tools/' . self::$icons[$data['type']]; 53 54 return self::pageToolItem( 55 $linktarget, 56 $caption, 57 $svg, 58 array('accesskey' => $data['accesskey']) 59 ); 60 } 61 62/** 63 * Return the HTML for a page action 64 * 65 * Plugins may use this in TEMPLATE_PAGETOOLS_DISPLAY 66 * 67 * @param string $link The link 68 * @param string $caption The label of the action 69 * @param string $svg The icon to show 70 * @param string[] $args HTML attributes for the item 71 * @return string 72 */ 73 static public function pageToolItem($link, $caption, $svg, $args = array()) { 74 if(blank($args['title'])) { 75 $args['title'] = $caption; 76 } 77 78 if(!blank($args['accesskey'])) { 79 $args['title'] .= ' [' . strtoupper($args['accesskey']) . ']'; 80 } 81 82 if(blank($args['rel'])) { 83 $args['rel'] = 'nofollow'; 84 } 85 86 $args['href'] = $link; 87 88 $svg = inlineSVG($svg); 89 if(!$svg) $svg = inlineSVG(__DIR__ . '/images/tools/' . self::$icons['default']); 90 91 $attributes = buildAttributes($args, true); 92 93 $out = "<a $attributes>"; 94 $out .= '<span>' . hsc($caption) . '</span>'; 95 $out .= $svg; 96 $out .= '</a>'; 97 98 return $out; 99 } 100} 101