You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

187 lines
6.7 KiB

  1. <?php
  2. namespace dokuwiki\template\sprintdoc;
  3. /**
  4. * Class tpl
  5. *
  6. * Provides additional template functions for the dokuwiki template
  7. * @package dokuwiki\tpl\dokuwiki
  8. */
  9. class tpl {
  10. static $icons = array(
  11. 'default' => '00-default_checkbox-blank-circle-outline.svg',
  12. 'edit' => '01-edit_pencil.svg',
  13. 'create' => '02-create_pencil.svg',
  14. 'draft' => '03-draft_android-studio.svg',
  15. 'show' => '04-show_file-document.svg',
  16. 'source' => '05-source_file-xml.svg',
  17. 'revert' => '06-revert_replay.svg',
  18. 'revs' => '07-revisions_history.svg',
  19. 'backlink' => '08-backlink_link-variant.svg',
  20. 'subscribe' => '09-subscribe_email-outline.svg',
  21. 'top' => '10-top_arrow-up.svg',
  22. 'mediaManager' => '11-mediamanager_folder-image.svg',
  23. 'img_backto' => '12-back_arrow-left.svg',
  24. );
  25. /**
  26. * Return the HTML for one of the default actions
  27. *
  28. * Reimplements parts of tpl_actionlink
  29. *
  30. * @param string $action
  31. * @return string
  32. */
  33. static public function pageToolAction($action) {
  34. $data = tpl_get_action($action);
  35. if(!is_array($data)) return '';
  36. global $lang;
  37. if($data['id'][0] == '#') {
  38. $linktarget = $data['id'];
  39. } else {
  40. $linktarget = wl($data['id'], $data['params'], false, '&');
  41. }
  42. $caption = $lang['btn_' . $data['type']];
  43. if(strpos($caption, '%s') !== false) {
  44. $caption = sprintf($caption, $data['replacement']);
  45. }
  46. $svg = __DIR__ . '/images/tools/' . self::$icons[$data['type']];
  47. return self::pageToolItem(
  48. $linktarget,
  49. $caption,
  50. $svg,
  51. array('accesskey' => $data['accesskey'])
  52. );
  53. }
  54. /**
  55. * Return the HTML for a page action
  56. *
  57. * Plugins may use this in TEMPLATE_PAGETOOLS_DISPLAY
  58. *
  59. * @param string $link The link
  60. * @param string $caption The label of the action
  61. * @param string $svg The icon to show
  62. * @param string[] $args HTML attributes for the item
  63. * @return string
  64. */
  65. static public function pageToolItem($link, $caption, $svg, $args = array()) {
  66. if(blank($args['title'])) {
  67. $args['title'] = $caption;
  68. }
  69. if(!blank($args['accesskey'])) {
  70. $args['title'] .= ' [' . strtoupper($args['accesskey']) . ']';
  71. }
  72. if(blank($args['rel'])) {
  73. $args['rel'] = 'nofollow';
  74. }
  75. $args['href'] = $link ?: '#';
  76. $svg = inlineSVG($svg);
  77. if(!$svg) $svg = inlineSVG(__DIR__ . '/images/tools/' . self::$icons['default']);
  78. $attributes = buildAttributes($args, true);
  79. $out = "<a $attributes>";
  80. $out .= '<span>' . hsc($caption) . '</span>';
  81. $out .= $svg;
  82. $out .= '</a>';
  83. return $out;
  84. }
  85. /**
  86. * Assemble the tools for the current page
  87. *
  88. * It also includes the tools for some plugins, if they are installed and enabled. This does currently not trigger
  89. * any events, but should be adjusted to the standard dokuwiki template, once that has svg-functionality implemented.
  90. *
  91. * @return array
  92. */
  93. static public function assemblePageTools() {
  94. $data = array(
  95. 'view' => 'main-svg',
  96. 'items' => array(
  97. 'edit' => static::pageToolAction('edit'),
  98. 'revert' => static::pageToolAction('revert'),
  99. 'revisions' => static::pageToolAction('revisions'),
  100. 'backlink' => static::pageToolAction('backlink'),
  101. 'subscribe' => static::pageToolAction('subscribe'),
  102. )
  103. );
  104. $data['items'] = array_map(function ($elem) {
  105. return '<li>' . $elem . '</li>';
  106. },array_filter($data['items']));
  107. /**
  108. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  109. * Begin shims as a temporary solution until the svg-approach is mainlined and the plugins have adapted
  110. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  111. */
  112. global $ACT;
  113. if (act_clean($ACT) === 'show') {
  114. /** @var \action_plugin_move_rename $move */
  115. $move = plugin_load('action', 'move_rename');
  116. if ($move && $move->getConf('pagetools_integration')) {
  117. $attr = array(
  118. 'style' => 'background-image: none;',
  119. );
  120. $item = \dokuwiki\template\sprintdoc\tpl::pageToolItem('', $move->getLang('renamepage'), __DIR__ . '/images/tools/41-format-paint.svg', $attr);
  121. $data['items'][] = '<li class="plugin_move_page">' . $item . '</li>';
  122. }
  123. /** @var \action_plugin_odt_export $odt */
  124. $odt = plugin_load('action', 'odt_export');
  125. if ($odt && $odt->getConf('showexportbutton')) {
  126. global $ID, $REV;
  127. $params = array('do' => 'export_odt');
  128. if ($REV) {
  129. $params['rev'] = $REV;
  130. }
  131. $attr = array(
  132. 'class' => 'action export_pdf',
  133. 'style' => 'background-image: none;',
  134. );
  135. $svg = __DIR__ . '/images/tools/43-file-delimeted.svg';
  136. $item = \dokuwiki\template\sprintdoc\tpl::pageToolItem(wl($ID, $params, false, '&'), $odt->getLang('export_odt_button'), $svg, $attr);
  137. $data['items'][] = '<li>' . $item . '</li>';
  138. }
  139. /** @var \action_plugin_dw2pdf $dw2pdf */
  140. $dw2pdf = plugin_load('action', 'dw2pdf');
  141. if ($dw2pdf && $dw2pdf->getConf('showexportbutton')) {
  142. global $ID, $REV;
  143. $params = array('do' => 'export_pdf');
  144. if ($REV) {
  145. $params['rev'] = $REV;
  146. }
  147. $attr = array(
  148. 'class' => 'action export_pdf',
  149. 'style' => 'background-image: none;',
  150. );
  151. $svg = __DIR__ . '/images/tools/40-pdf-file.svg';
  152. $item = \dokuwiki\template\sprintdoc\tpl::pageToolItem(wl($ID, $params, false, '&'), $dw2pdf->getLang('export_pdf_button'), $svg, $attr);
  153. $data['items'][] = '<li>' . $item . '</li>';
  154. }
  155. }
  156. /**
  157. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  158. * End of shims
  159. * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  160. */
  161. $data['items']['top'] = '<li>' . static::pageToolAction('top') . '</li>';
  162. return $data;
  163. }
  164. }