102dbc7faSSilke Pisulla<?php 202dbc7faSSilke Pisulla 302dbc7faSSilke Pisullanamespace dokuwiki\template\sprintdoc; 402dbc7faSSilke Pisulla 502dbc7faSSilke Pisulla/** 602dbc7faSSilke Pisulla * Class tpl 702dbc7faSSilke Pisulla * 802dbc7faSSilke Pisulla * Provides additional template functions for the dokuwiki template 902dbc7faSSilke Pisulla * @package dokuwiki\tpl\dokuwiki 1002dbc7faSSilke Pisulla */ 1102dbc7faSSilke Pisulla 1202dbc7faSSilke Pisullaclass tpl { 1302dbc7faSSilke Pisulla static $icons = array( 1402dbc7faSSilke Pisulla 'default' => '00-default_checkbox-blank-circle-outline.svg', 1502dbc7faSSilke Pisulla 'edit' => '01-edit_pencil.svg', 1602dbc7faSSilke Pisulla 'create' => '02-create_pencil.svg', 1702dbc7faSSilke Pisulla 'draft' => '03-draft_android-studio.svg', 1802dbc7faSSilke Pisulla 'show' => '04-show_file-document.svg', 1902dbc7faSSilke Pisulla 'source' => '05-source_file-xml.svg', 2002dbc7faSSilke Pisulla 'revert' => '06-revert_replay.svg', 2102dbc7faSSilke Pisulla 'revs' => '07-revisions_history.svg', 2202dbc7faSSilke Pisulla 'backlink' => '08-backlink_link-variant.svg', 2302dbc7faSSilke Pisulla 'subscribe' => '09-subscribe_email-outline.svg', 2402dbc7faSSilke Pisulla 'top' => '10-top_arrow-up.svg', 2502dbc7faSSilke Pisulla 'mediaManager' => '11-mediamanager_folder-image.svg', 2602dbc7faSSilke Pisulla 'img_backto' => '12-back_arrow-left.svg', 2702dbc7faSSilke Pisulla ); 2802dbc7faSSilke Pisulla 2902dbc7faSSilke Pisulla/** 3002dbc7faSSilke Pisulla * Return the HTML for one of the default actions 3102dbc7faSSilke Pisulla * 3202dbc7faSSilke Pisulla * Reimplements parts of tpl_actionlink 3302dbc7faSSilke Pisulla * 3402dbc7faSSilke Pisulla * @param string $action 3502dbc7faSSilke Pisulla * @return string 3602dbc7faSSilke Pisulla */ 3702dbc7faSSilke Pisulla static public function pageToolAction($action) { 3802dbc7faSSilke Pisulla $data = tpl_get_action($action); 3902dbc7faSSilke Pisulla if(!is_array($data)) return ''; 4002dbc7faSSilke Pisulla global $lang; 4102dbc7faSSilke Pisulla 4202dbc7faSSilke Pisulla if($data['id'][0] == '#') { 4302dbc7faSSilke Pisulla $linktarget = $data['id']; 4402dbc7faSSilke Pisulla } else { 457910e1c9SSilke Pisulla $linktarget = wl($data['id'], $data['params'], false, '&'); 4602dbc7faSSilke Pisulla } 4702dbc7faSSilke Pisulla $caption = $lang['btn_' . $data['type']]; 48*2e98afbdSfiwswe if(strpos($caption, '%s') !== false) { 4902dbc7faSSilke Pisulla $caption = sprintf($caption, $data['replacement']); 5002dbc7faSSilke Pisulla } 5102dbc7faSSilke Pisulla 5202dbc7faSSilke Pisulla $svg = __DIR__ . '/images/tools/' . self::$icons[$data['type']]; 5302dbc7faSSilke Pisulla 5402dbc7faSSilke Pisulla return self::pageToolItem( 5502dbc7faSSilke Pisulla $linktarget, 5602dbc7faSSilke Pisulla $caption, 5702dbc7faSSilke Pisulla $svg, 5802dbc7faSSilke Pisulla array('accesskey' => $data['accesskey']) 5902dbc7faSSilke Pisulla ); 6002dbc7faSSilke Pisulla } 6102dbc7faSSilke Pisulla 6202dbc7faSSilke Pisulla/** 6302dbc7faSSilke Pisulla * Return the HTML for a page action 6402dbc7faSSilke Pisulla * 6502dbc7faSSilke Pisulla * Plugins may use this in TEMPLATE_PAGETOOLS_DISPLAY 6602dbc7faSSilke Pisulla * 6702dbc7faSSilke Pisulla * @param string $link The link 6802dbc7faSSilke Pisulla * @param string $caption The label of the action 6902dbc7faSSilke Pisulla * @param string $svg The icon to show 7002dbc7faSSilke Pisulla * @param string[] $args HTML attributes for the item 7102dbc7faSSilke Pisulla * @return string 7202dbc7faSSilke Pisulla */ 7302dbc7faSSilke Pisulla static public function pageToolItem($link, $caption, $svg, $args = array()) { 7402dbc7faSSilke Pisulla if(blank($args['title'])) { 7502dbc7faSSilke Pisulla $args['title'] = $caption; 7602dbc7faSSilke Pisulla } 7702dbc7faSSilke Pisulla 7802dbc7faSSilke Pisulla if(!blank($args['accesskey'])) { 7902dbc7faSSilke Pisulla $args['title'] .= ' [' . strtoupper($args['accesskey']) . ']'; 8002dbc7faSSilke Pisulla } 8102dbc7faSSilke Pisulla 8202dbc7faSSilke Pisulla if(blank($args['rel'])) { 8302dbc7faSSilke Pisulla $args['rel'] = 'nofollow'; 8402dbc7faSSilke Pisulla } 8502dbc7faSSilke Pisulla 8689102c92SMichael Große $args['href'] = $link ?: '#'; 8702dbc7faSSilke Pisulla 8802dbc7faSSilke Pisulla $svg = inlineSVG($svg); 8902dbc7faSSilke Pisulla if(!$svg) $svg = inlineSVG(__DIR__ . '/images/tools/' . self::$icons['default']); 9002dbc7faSSilke Pisulla 9102dbc7faSSilke Pisulla $attributes = buildAttributes($args, true); 9202dbc7faSSilke Pisulla 9302dbc7faSSilke Pisulla $out = "<a $attributes>"; 9402dbc7faSSilke Pisulla $out .= '<span>' . hsc($caption) . '</span>'; 9502dbc7faSSilke Pisulla $out .= $svg; 9602dbc7faSSilke Pisulla $out .= '</a>'; 9702dbc7faSSilke Pisulla 9802dbc7faSSilke Pisulla return $out; 9902dbc7faSSilke Pisulla } 100d012fad7SMichael Große 101d012fad7SMichael Große /** 102d012fad7SMichael Große * Assemble the tools for the current page 103d012fad7SMichael Große * 104d012fad7SMichael Große * It also includes the tools for some plugins, if they are installed and enabled. This does currently not trigger 105d012fad7SMichael Große * any events, but should be adjusted to the standard dokuwiki template, once that has svg-functionality implemented. 106d012fad7SMichael Große * 107d012fad7SMichael Große * @return array 108d012fad7SMichael Große */ 109d012fad7SMichael Große static public function assemblePageTools() { 110d012fad7SMichael Große $data = array( 111d012fad7SMichael Große 'view' => 'main-svg', 112d012fad7SMichael Große 'items' => array( 113d012fad7SMichael Große 'edit' => static::pageToolAction('edit'), 114d012fad7SMichael Große 'revert' => static::pageToolAction('revert'), 115d012fad7SMichael Große 'revisions' => static::pageToolAction('revisions'), 116d012fad7SMichael Große 'backlink' => static::pageToolAction('backlink'), 117d012fad7SMichael Große 'subscribe' => static::pageToolAction('subscribe'), 118d012fad7SMichael Große ) 119d012fad7SMichael Große ); 120d012fad7SMichael Große 121d012fad7SMichael Große $data['items'] = array_map(function ($elem) { 122d012fad7SMichael Große return '<li>' . $elem . '</li>'; 123d012fad7SMichael Große },array_filter($data['items'])); 124d012fad7SMichael Große 125d012fad7SMichael Große /** 126d012fad7SMichael Große * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 127d012fad7SMichael Große * Begin shims as a temporary solution until the svg-approach is mainlined and the plugins have adapted 128d012fad7SMichael Große * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 129d012fad7SMichael Große */ 130d012fad7SMichael Große global $ACT; 131d012fad7SMichael Große if (act_clean($ACT) === 'show') { 132d012fad7SMichael Große /** @var \action_plugin_move_rename $move */ 133d012fad7SMichael Große $move = plugin_load('action', 'move_rename'); 134d012fad7SMichael Große if ($move && $move->getConf('pagetools_integration')) { 135d012fad7SMichael Große $attr = array( 136d012fad7SMichael Große 'style' => 'background-image: none;', 137d012fad7SMichael Große ); 138d012fad7SMichael Große $item = \dokuwiki\template\sprintdoc\tpl::pageToolItem('', $move->getLang('renamepage'), __DIR__ . '/images/tools/41-format-paint.svg', $attr); 139d012fad7SMichael Große $data['items'][] = '<li class="plugin_move_page">' . $item . '</li>'; 140d012fad7SMichael Große } 141d012fad7SMichael Große 142d012fad7SMichael Große /** @var \action_plugin_odt_export $odt */ 143d012fad7SMichael Große $odt = plugin_load('action', 'odt_export'); 144d012fad7SMichael Große if ($odt && $odt->getConf('showexportbutton')) { 145d012fad7SMichael Große global $ID, $REV; 146d012fad7SMichael Große $params = array('do' => 'export_odt'); 147d012fad7SMichael Große if ($REV) { 148d012fad7SMichael Große $params['rev'] = $REV; 149d012fad7SMichael Große } 150d012fad7SMichael Große $attr = array( 151d012fad7SMichael Große 'class' => 'action export_pdf', 152d012fad7SMichael Große 'style' => 'background-image: none;', 153d012fad7SMichael Große ); 154d012fad7SMichael Große $svg = __DIR__ . '/images/tools/43-file-delimeted.svg'; 155d012fad7SMichael Große $item = \dokuwiki\template\sprintdoc\tpl::pageToolItem(wl($ID, $params, false, '&'), $odt->getLang('export_odt_button'), $svg, $attr); 156d012fad7SMichael Große $data['items'][] = '<li>' . $item . '</li>'; 157d012fad7SMichael Große } 158d012fad7SMichael Große 159d012fad7SMichael Große /** @var \action_plugin_dw2pdf $dw2pdf */ 160d012fad7SMichael Große $dw2pdf = plugin_load('action', 'dw2pdf'); 161d012fad7SMichael Große if ($dw2pdf && $dw2pdf->getConf('showexportbutton')) { 162d012fad7SMichael Große global $ID, $REV; 163d012fad7SMichael Große 164d012fad7SMichael Große $params = array('do' => 'export_pdf'); 165d012fad7SMichael Große if ($REV) { 166d012fad7SMichael Große $params['rev'] = $REV; 167d012fad7SMichael Große } 168d012fad7SMichael Große $attr = array( 169d012fad7SMichael Große 'class' => 'action export_pdf', 170d012fad7SMichael Große 'style' => 'background-image: none;', 171d012fad7SMichael Große ); 172d012fad7SMichael Große $svg = __DIR__ . '/images/tools/40-pdf-file.svg'; 173d012fad7SMichael Große $item = \dokuwiki\template\sprintdoc\tpl::pageToolItem(wl($ID, $params, false, '&'), $dw2pdf->getLang('export_pdf_button'), $svg, $attr); 174d012fad7SMichael Große $data['items'][] = '<li>' . $item . '</li>'; 175d012fad7SMichael Große } 176d012fad7SMichael Große } 177d012fad7SMichael Große /** 178d012fad7SMichael Große * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 179d012fad7SMichael Große * End of shims 180d012fad7SMichael Große * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 181d012fad7SMichael Große */ 182d012fad7SMichael Große 183d012fad7SMichael Große $data['items']['top'] = '<li>' . static::pageToolAction('top') . '</li>'; 184d012fad7SMichael Große return $data; 185d012fad7SMichael Große } 18602dbc7faSSilke Pisulla} 187