PageRenderTime 66ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/template.php

http://github.com/splitbrain/dokuwiki
PHP | 1882 lines | 1157 code | 182 blank | 543 comment | 263 complexity | 41ee131f1e343954cc0bd5617eb7b4cc MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * DokuWiki template functions
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. */
  8. use dokuwiki\Extension\AdminPlugin;
  9. use dokuwiki\Extension\Event;
  10. /**
  11. * Access a template file
  12. *
  13. * Returns the path to the given file inside the current template, uses
  14. * default template if the custom version doesn't exist.
  15. *
  16. * @author Andreas Gohr <andi@splitbrain.org>
  17. * @param string $file
  18. * @return string
  19. */
  20. function template($file) {
  21. global $conf;
  22. if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file))
  23. return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$file;
  24. return DOKU_INC.'lib/tpl/dokuwiki/'.$file;
  25. }
  26. /**
  27. * Convenience function to access template dir from local FS
  28. *
  29. * This replaces the deprecated DOKU_TPLINC constant
  30. *
  31. * @author Andreas Gohr <andi@splitbrain.org>
  32. * @param string $tpl The template to use, default to current one
  33. * @return string
  34. */
  35. function tpl_incdir($tpl='') {
  36. global $conf;
  37. if(!$tpl) $tpl = $conf['template'];
  38. return DOKU_INC.'lib/tpl/'.$tpl.'/';
  39. }
  40. /**
  41. * Convenience function to access template dir from web
  42. *
  43. * This replaces the deprecated DOKU_TPL constant
  44. *
  45. * @author Andreas Gohr <andi@splitbrain.org>
  46. * @param string $tpl The template to use, default to current one
  47. * @return string
  48. */
  49. function tpl_basedir($tpl='') {
  50. global $conf;
  51. if(!$tpl) $tpl = $conf['template'];
  52. return DOKU_BASE.'lib/tpl/'.$tpl.'/';
  53. }
  54. /**
  55. * Print the content
  56. *
  57. * This function is used for printing all the usual content
  58. * (defined by the global $ACT var) by calling the appropriate
  59. * outputfunction(s) from html.php
  60. *
  61. * Everything that doesn't use the main template file isn't
  62. * handled by this function. ACL stuff is not done here either.
  63. *
  64. * @author Andreas Gohr <andi@splitbrain.org>
  65. *
  66. * @triggers TPL_ACT_RENDER
  67. * @triggers TPL_CONTENT_DISPLAY
  68. * @param bool $prependTOC should the TOC be displayed here?
  69. * @return bool true if any output
  70. */
  71. function tpl_content($prependTOC = true) {
  72. global $ACT;
  73. global $INFO;
  74. $INFO['prependTOC'] = $prependTOC;
  75. ob_start();
  76. Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
  77. $html_output = ob_get_clean();
  78. Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
  79. return !empty($html_output);
  80. }
  81. /**
  82. * Default Action of TPL_ACT_RENDER
  83. *
  84. * @return bool
  85. */
  86. function tpl_content_core() {
  87. $router = \dokuwiki\ActionRouter::getInstance();
  88. try {
  89. $router->getAction()->tplContent();
  90. } catch(\dokuwiki\Action\Exception\FatalException $e) {
  91. // there was no content for the action
  92. msg(hsc($e->getMessage()), -1);
  93. return false;
  94. }
  95. return true;
  96. }
  97. /**
  98. * Places the TOC where the function is called
  99. *
  100. * If you use this you most probably want to call tpl_content with
  101. * a false argument
  102. *
  103. * @author Andreas Gohr <andi@splitbrain.org>
  104. *
  105. * @param bool $return Should the TOC be returned instead to be printed?
  106. * @return string
  107. */
  108. function tpl_toc($return = false) {
  109. global $TOC;
  110. global $ACT;
  111. global $ID;
  112. global $REV;
  113. global $INFO;
  114. global $conf;
  115. global $INPUT;
  116. $toc = array();
  117. if(is_array($TOC)) {
  118. // if a TOC was prepared in global scope, always use it
  119. $toc = $TOC;
  120. } elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
  121. // get TOC from metadata, render if neccessary
  122. $meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
  123. if(isset($meta['internal']['toc'])) {
  124. $tocok = $meta['internal']['toc'];
  125. } else {
  126. $tocok = true;
  127. }
  128. $toc = isset($meta['description']['tableofcontents']) ? $meta['description']['tableofcontents'] : null;
  129. if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
  130. $toc = array();
  131. }
  132. } elseif($ACT == 'admin') {
  133. // try to load admin plugin TOC
  134. /** @var $plugin AdminPlugin */
  135. if ($plugin = plugin_getRequestAdminPlugin()) {
  136. $toc = $plugin->getTOC();
  137. $TOC = $toc; // avoid later rebuild
  138. }
  139. }
  140. Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
  141. $html = html_TOC($toc);
  142. if($return) return $html;
  143. echo $html;
  144. return '';
  145. }
  146. /**
  147. * Handle the admin page contents
  148. *
  149. * @author Andreas Gohr <andi@splitbrain.org>
  150. *
  151. * @return bool
  152. */
  153. function tpl_admin() {
  154. global $INFO;
  155. global $TOC;
  156. global $INPUT;
  157. $plugin = null;
  158. $class = $INPUT->str('page');
  159. if(!empty($class)) {
  160. $pluginlist = plugin_list('admin');
  161. if(in_array($class, $pluginlist)) {
  162. // attempt to load the plugin
  163. /** @var $plugin AdminPlugin */
  164. $plugin = plugin_load('admin', $class);
  165. }
  166. }
  167. if($plugin !== null) {
  168. if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
  169. if($INFO['prependTOC']) tpl_toc();
  170. $plugin->html();
  171. } else {
  172. $admin = new dokuwiki\Ui\Admin();
  173. $admin->show();
  174. }
  175. return true;
  176. }
  177. /**
  178. * Print the correct HTML meta headers
  179. *
  180. * This has to go into the head section of your template.
  181. *
  182. * @author Andreas Gohr <andi@splitbrain.org>
  183. *
  184. * @triggers TPL_METAHEADER_OUTPUT
  185. * @param bool $alt Should feeds and alternative format links be added?
  186. * @return bool
  187. */
  188. function tpl_metaheaders($alt = true) {
  189. global $ID;
  190. global $REV;
  191. global $INFO;
  192. global $JSINFO;
  193. global $ACT;
  194. global $QUERY;
  195. global $lang;
  196. global $conf;
  197. global $updateVersion;
  198. /** @var Input $INPUT */
  199. global $INPUT;
  200. // prepare the head array
  201. $head = array();
  202. // prepare seed for js and css
  203. $tseed = $updateVersion;
  204. $depends = getConfigFiles('main');
  205. $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
  206. foreach($depends as $f) $tseed .= @filemtime($f);
  207. $tseed = md5($tseed);
  208. // the usual stuff
  209. $head['meta'][] = array('name'=> 'generator', 'content'=> 'DokuWiki');
  210. if(actionOK('search')) {
  211. $head['link'][] = array(
  212. 'rel' => 'search', 'type'=> 'application/opensearchdescription+xml',
  213. 'href'=> DOKU_BASE.'lib/exe/opensearch.php', 'title'=> $conf['title']
  214. );
  215. }
  216. $head['link'][] = array('rel'=> 'start', 'href'=> DOKU_BASE);
  217. if(actionOK('index')) {
  218. $head['link'][] = array(
  219. 'rel' => 'contents', 'href'=> wl($ID, 'do=index', false, '&'),
  220. 'title'=> $lang['btn_index']
  221. );
  222. }
  223. if (actionOK('manifest')) {
  224. $head['link'][] = array('rel'=> 'manifest', 'href'=> DOKU_BASE.'lib/exe/manifest.php');
  225. }
  226. $styleUtil = new \dokuwiki\StyleUtils();
  227. $styleIni = $styleUtil->cssStyleini();
  228. $replacements = $styleIni['replacements'];
  229. if (!empty($replacements['__theme_color__'])) {
  230. $head['meta'][] = array('name' => 'theme-color', 'content' => $replacements['__theme_color__']);
  231. }
  232. if($alt) {
  233. if(actionOK('rss')) {
  234. $head['link'][] = array(
  235. 'rel' => 'alternate', 'type'=> 'application/rss+xml',
  236. 'title'=> $lang['btn_recent'], 'href'=> DOKU_BASE.'feed.php'
  237. );
  238. $head['link'][] = array(
  239. 'rel' => 'alternate', 'type'=> 'application/rss+xml',
  240. 'title'=> $lang['currentns'],
  241. 'href' => DOKU_BASE.'feed.php?mode=list&ns='.(isset($INFO) ? $INFO['namespace'] : '')
  242. );
  243. }
  244. if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
  245. $head['link'][] = array(
  246. 'rel' => 'edit',
  247. 'title'=> $lang['btn_edit'],
  248. 'href' => wl($ID, 'do=edit', false, '&')
  249. );
  250. }
  251. if(actionOK('rss') && $ACT == 'search') {
  252. $head['link'][] = array(
  253. 'rel' => 'alternate', 'type'=> 'application/rss+xml',
  254. 'title'=> $lang['searchresult'],
  255. 'href' => DOKU_BASE.'feed.php?mode=search&q='.$QUERY
  256. );
  257. }
  258. if(actionOK('export_xhtml')) {
  259. $head['link'][] = array(
  260. 'rel' => 'alternate', 'type'=> 'text/html', 'title'=> $lang['plainhtml'],
  261. 'href'=> exportlink($ID, 'xhtml', '', false, '&')
  262. );
  263. }
  264. if(actionOK('export_raw')) {
  265. $head['link'][] = array(
  266. 'rel' => 'alternate', 'type'=> 'text/plain', 'title'=> $lang['wikimarkup'],
  267. 'href'=> exportlink($ID, 'raw', '', false, '&')
  268. );
  269. }
  270. }
  271. // setup robot tags apropriate for different modes
  272. if(($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
  273. if($INFO['exists']) {
  274. //delay indexing:
  275. if((time() - $INFO['lastmod']) >= $conf['indexdelay'] && !isHiddenPage($ID) ) {
  276. $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
  277. } else {
  278. $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
  279. }
  280. $canonicalUrl = wl($ID, '', true, '&');
  281. if ($ID == $conf['start']) {
  282. $canonicalUrl = DOKU_URL;
  283. }
  284. $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
  285. } else {
  286. $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
  287. }
  288. } elseif(defined('DOKU_MEDIADETAIL')) {
  289. $head['meta'][] = array('name'=> 'robots', 'content'=> 'index,follow');
  290. } else {
  291. $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
  292. }
  293. // set metadata
  294. if($ACT == 'show' || $ACT == 'export_xhtml') {
  295. // keywords (explicit or implicit)
  296. if(!empty($INFO['meta']['subject'])) {
  297. $head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
  298. } else {
  299. $head['meta'][] = array('name'=> 'keywords', 'content'=> str_replace(':', ',', $ID));
  300. }
  301. }
  302. // load stylesheets
  303. $head['link'][] = array(
  304. 'rel' => 'stylesheet',
  305. 'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
  306. );
  307. $script = "var NS='".(isset($INFO)?$INFO['namespace']:'')."';";
  308. if($conf['useacl'] && $INPUT->server->str('REMOTE_USER')) {
  309. $script .= "var SIG=".toolbar_signature().";";
  310. }
  311. jsinfo();
  312. $script .= 'var JSINFO = ' . json_encode($JSINFO).';';
  313. $head['script'][] = array('_data'=> $script);
  314. // load jquery
  315. $jquery = getCdnUrls();
  316. foreach($jquery as $src) {
  317. $head['script'][] = array(
  318. 'charset' => 'utf-8',
  319. '_data' => '',
  320. 'src' => $src,
  321. ) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
  322. }
  323. // load our javascript dispatcher
  324. $head['script'][] = array(
  325. 'charset'=> 'utf-8', '_data'=> '',
  326. 'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed,
  327. ) + ($conf['defer_js'] ? [ 'defer' => 'defer'] : []);
  328. // trigger event here
  329. Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
  330. return true;
  331. }
  332. /**
  333. * prints the array build by tpl_metaheaders
  334. *
  335. * $data is an array of different header tags. Each tag can have multiple
  336. * instances. Attributes are given as key value pairs. Values will be HTML
  337. * encoded automatically so they should be provided as is in the $data array.
  338. *
  339. * For tags having a body attribute specify the body data in the special
  340. * attribute '_data'. This field will NOT BE ESCAPED automatically.
  341. *
  342. * @author Andreas Gohr <andi@splitbrain.org>
  343. *
  344. * @param array $data
  345. */
  346. function _tpl_metaheaders_action($data) {
  347. foreach($data as $tag => $inst) {
  348. if($tag == 'script') {
  349. echo "<!--[if gte IE 9]><!-->\n"; // no scripts for old IE
  350. }
  351. foreach($inst as $attr) {
  352. if ( empty($attr) ) { continue; }
  353. echo '<', $tag, ' ', buildAttributes($attr);
  354. if(isset($attr['_data']) || $tag == 'script') {
  355. if($tag == 'script' && $attr['_data'])
  356. $attr['_data'] = "/*<![CDATA[*/".
  357. $attr['_data'].
  358. "\n/*!]]>*/";
  359. echo '>', $attr['_data'], '</', $tag, '>';
  360. } else {
  361. echo '/>';
  362. }
  363. echo "\n";
  364. }
  365. if($tag == 'script') {
  366. echo "<!--<![endif]-->\n";
  367. }
  368. }
  369. }
  370. /**
  371. * Print a link
  372. *
  373. * Just builds a link.
  374. *
  375. * @author Andreas Gohr <andi@splitbrain.org>
  376. *
  377. * @param string $url
  378. * @param string $name
  379. * @param string $more
  380. * @param bool $return if true return the link html, otherwise print
  381. * @return bool|string html of the link, or true if printed
  382. */
  383. function tpl_link($url, $name, $more = '', $return = false) {
  384. $out = '<a href="'.$url.'" ';
  385. if($more) $out .= ' '.$more;
  386. $out .= ">$name</a>";
  387. if($return) return $out;
  388. print $out;
  389. return true;
  390. }
  391. /**
  392. * Prints a link to a WikiPage
  393. *
  394. * Wrapper around html_wikilink
  395. *
  396. * @author Andreas Gohr <andi@splitbrain.org>
  397. *
  398. * @param string $id page id
  399. * @param string|null $name the name of the link
  400. * @param bool $return
  401. * @return true|string
  402. */
  403. function tpl_pagelink($id, $name = null, $return = false) {
  404. $out = '<bdi>'.html_wikilink($id, $name).'</bdi>';
  405. if($return) return $out;
  406. print $out;
  407. return true;
  408. }
  409. /**
  410. * get the parent page
  411. *
  412. * Tries to find out which page is parent.
  413. * returns false if none is available
  414. *
  415. * @author Andreas Gohr <andi@splitbrain.org>
  416. *
  417. * @param string $id page id
  418. * @return false|string
  419. */
  420. function tpl_getparent($id) {
  421. $parent = getNS($id).':';
  422. resolve_pageid('', $parent, $exists);
  423. if($parent == $id) {
  424. $pos = strrpos(getNS($id), ':');
  425. $parent = substr($parent, 0, $pos).':';
  426. resolve_pageid('', $parent, $exists);
  427. if($parent == $id) return false;
  428. }
  429. return $parent;
  430. }
  431. /**
  432. * Print one of the buttons
  433. *
  434. * @author Adrian Lang <mail@adrianlang.de>
  435. * @see tpl_get_action
  436. *
  437. * @param string $type
  438. * @param bool $return
  439. * @return bool|string html, or false if no data, true if printed
  440. * @deprecated 2017-09-01 see devel:menus
  441. */
  442. function tpl_button($type, $return = false) {
  443. dbg_deprecated('see devel:menus');
  444. $data = tpl_get_action($type);
  445. if($data === false) {
  446. return false;
  447. } elseif(!is_array($data)) {
  448. $out = sprintf($data, 'button');
  449. } else {
  450. /**
  451. * @var string $accesskey
  452. * @var string $id
  453. * @var string $method
  454. * @var array $params
  455. */
  456. extract($data);
  457. if($id === '#dokuwiki__top') {
  458. $out = html_topbtn();
  459. } else {
  460. $out = html_btn($type, $id, $accesskey, $params, $method);
  461. }
  462. }
  463. if($return) return $out;
  464. echo $out;
  465. return true;
  466. }
  467. /**
  468. * Like the action buttons but links
  469. *
  470. * @author Adrian Lang <mail@adrianlang.de>
  471. * @see tpl_get_action
  472. *
  473. * @param string $type action command
  474. * @param string $pre prefix of link
  475. * @param string $suf suffix of link
  476. * @param string $inner innerHML of link
  477. * @param bool $return if true it returns html, otherwise prints
  478. * @return bool|string html or false if no data, true if printed
  479. * @deprecated 2017-09-01 see devel:menus
  480. */
  481. function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
  482. dbg_deprecated('see devel:menus');
  483. global $lang;
  484. $data = tpl_get_action($type);
  485. if($data === false) {
  486. return false;
  487. } elseif(!is_array($data)) {
  488. $out = sprintf($data, 'link');
  489. } else {
  490. /**
  491. * @var string $accesskey
  492. * @var string $id
  493. * @var string $method
  494. * @var bool $nofollow
  495. * @var array $params
  496. * @var string $replacement
  497. */
  498. extract($data);
  499. if(strpos($id, '#') === 0) {
  500. $linktarget = $id;
  501. } else {
  502. $linktarget = wl($id, $params);
  503. }
  504. $caption = $lang['btn_'.$type];
  505. if(strpos($caption, '%s')){
  506. $caption = sprintf($caption, $replacement);
  507. }
  508. $akey = $addTitle = '';
  509. if($accesskey) {
  510. $akey = 'accesskey="'.$accesskey.'" ';
  511. $addTitle = ' ['.strtoupper($accesskey).']';
  512. }
  513. $rel = $nofollow ? 'rel="nofollow" ' : '';
  514. $out = tpl_link(
  515. $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
  516. 'class="action '.$type.'" '.
  517. $akey.$rel.
  518. 'title="'.hsc($caption).$addTitle.'"', true
  519. );
  520. }
  521. if($return) return $out;
  522. echo $out;
  523. return true;
  524. }
  525. /**
  526. * Check the actions and get data for buttons and links
  527. *
  528. * @author Andreas Gohr <andi@splitbrain.org>
  529. * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
  530. * @author Adrian Lang <mail@adrianlang.de>
  531. *
  532. * @param string $type
  533. * @return array|bool|string
  534. * @deprecated 2017-09-01 see devel:menus
  535. */
  536. function tpl_get_action($type) {
  537. dbg_deprecated('see devel:menus');
  538. if($type == 'history') $type = 'revisions';
  539. if($type == 'subscription') $type = 'subscribe';
  540. if($type == 'img_backto') $type = 'imgBackto';
  541. $class = '\\dokuwiki\\Menu\\Item\\' . ucfirst($type);
  542. if(class_exists($class)) {
  543. try {
  544. /** @var \dokuwiki\Menu\Item\AbstractItem $item */
  545. $item = new $class;
  546. $data = $item->getLegacyData();
  547. $unknown = false;
  548. } catch(\RuntimeException $ignored) {
  549. return false;
  550. }
  551. } else {
  552. global $ID;
  553. $data = array(
  554. 'accesskey' => null,
  555. 'type' => $type,
  556. 'id' => $ID,
  557. 'method' => 'get',
  558. 'params' => array('do' => $type),
  559. 'nofollow' => true,
  560. 'replacement' => '',
  561. );
  562. $unknown = true;
  563. }
  564. $evt = new Event('TPL_ACTION_GET', $data);
  565. if($evt->advise_before()) {
  566. //handle unknown types
  567. if($unknown) {
  568. $data = '[unknown %s type]';
  569. }
  570. }
  571. $evt->advise_after();
  572. unset($evt);
  573. return $data;
  574. }
  575. /**
  576. * Wrapper around tpl_button() and tpl_actionlink()
  577. *
  578. * @author Anika Henke <anika@selfthinker.org>
  579. *
  580. * @param string $type action command
  581. * @param bool $link link or form button?
  582. * @param string|bool $wrapper HTML element wrapper
  583. * @param bool $return return or print
  584. * @param string $pre prefix for links
  585. * @param string $suf suffix for links
  586. * @param string $inner inner HTML for links
  587. * @return bool|string
  588. * @deprecated 2017-09-01 see devel:menus
  589. */
  590. function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
  591. dbg_deprecated('see devel:menus');
  592. $out = '';
  593. if($link) {
  594. $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
  595. } else {
  596. $out .= tpl_button($type, true);
  597. }
  598. if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
  599. if($return) return $out;
  600. print $out;
  601. return $out ? true : false;
  602. }
  603. /**
  604. * Print the search form
  605. *
  606. * If the first parameter is given a div with the ID 'qsearch_out' will
  607. * be added which instructs the ajax pagequicksearch to kick in and place
  608. * its output into this div. The second parameter controls the propritary
  609. * attribute autocomplete. If set to false this attribute will be set with an
  610. * value of "off" to instruct the browser to disable it's own built in
  611. * autocompletion feature (MSIE and Firefox)
  612. *
  613. * @author Andreas Gohr <andi@splitbrain.org>
  614. *
  615. * @param bool $ajax
  616. * @param bool $autocomplete
  617. * @return bool
  618. */
  619. function tpl_searchform($ajax = true, $autocomplete = true) {
  620. global $lang;
  621. global $ACT;
  622. global $QUERY;
  623. global $ID;
  624. // don't print the search form if search action has been disabled
  625. if(!actionOK('search')) return false;
  626. $searchForm = new dokuwiki\Form\Form([
  627. 'action' => wl(),
  628. 'method' => 'get',
  629. 'role' => 'search',
  630. 'class' => 'search',
  631. 'id' => 'dw__search',
  632. ], true);
  633. $searchForm->addTagOpen('div')->addClass('no');
  634. $searchForm->setHiddenField('do', 'search');
  635. $searchForm->setHiddenField('id', $ID);
  636. $searchForm->addTextInput('q')
  637. ->addClass('edit')
  638. ->attrs([
  639. 'title' => '[F]',
  640. 'accesskey' => 'f',
  641. 'placeholder' => $lang['btn_search'],
  642. 'autocomplete' => $autocomplete ? 'on' : 'off',
  643. ])
  644. ->id('qsearch__in')
  645. ->val($ACT === 'search' ? $QUERY : '')
  646. ->useInput(false)
  647. ;
  648. $searchForm->addButton('', $lang['btn_search'])->attrs([
  649. 'type' => 'submit',
  650. 'title' => $lang['btn_search'],
  651. ]);
  652. if ($ajax) {
  653. $searchForm->addTagOpen('div')->id('qsearch__out')->addClass('ajax_qsearch JSpopup');
  654. $searchForm->addTagClose('div');
  655. }
  656. $searchForm->addTagClose('div');
  657. Event::createAndTrigger('FORM_QUICKSEARCH_OUTPUT', $searchForm);
  658. echo $searchForm->toHTML();
  659. return true;
  660. }
  661. /**
  662. * Print the breadcrumbs trace
  663. *
  664. * @author Andreas Gohr <andi@splitbrain.org>
  665. *
  666. * @param string $sep Separator between entries
  667. * @param bool $return return or print
  668. * @return bool|string
  669. */
  670. function tpl_breadcrumbs($sep = null, $return = false) {
  671. global $lang;
  672. global $conf;
  673. //check if enabled
  674. if(!$conf['breadcrumbs']) return false;
  675. //set default
  676. if(is_null($sep)) $sep = '•';
  677. $out='';
  678. $crumbs = breadcrumbs(); //setup crumb trace
  679. $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
  680. //render crumbs, highlight the last one
  681. $out .= '<span class="bchead">'.$lang['breadcrumb'].'</span>';
  682. $last = count($crumbs);
  683. $i = 0;
  684. foreach($crumbs as $id => $name) {
  685. $i++;
  686. $out .= $crumbs_sep;
  687. if($i == $last) $out .= '<span class="curid">';
  688. $out .= '<bdi>' . tpl_link(wl($id), hsc($name), 'class="breadcrumbs" title="'.$id.'"', true) . '</bdi>';
  689. if($i == $last) $out .= '</span>';
  690. }
  691. if($return) return $out;
  692. print $out;
  693. return $out ? true : false;
  694. }
  695. /**
  696. * Hierarchical breadcrumbs
  697. *
  698. * This code was suggested as replacement for the usual breadcrumbs.
  699. * It only makes sense with a deep site structure.
  700. *
  701. * @author Andreas Gohr <andi@splitbrain.org>
  702. * @author Nigel McNie <oracle.shinoda@gmail.com>
  703. * @author Sean Coates <sean@caedmon.net>
  704. * @author <fredrik@averpil.com>
  705. * @todo May behave strangely in RTL languages
  706. *
  707. * @param string $sep Separator between entries
  708. * @param bool $return return or print
  709. * @return bool|string
  710. */
  711. function tpl_youarehere($sep = null, $return = false) {
  712. global $conf;
  713. global $ID;
  714. global $lang;
  715. // check if enabled
  716. if(!$conf['youarehere']) return false;
  717. //set default
  718. if(is_null($sep)) $sep = ' » ';
  719. $out = '';
  720. $parts = explode(':', $ID);
  721. $count = count($parts);
  722. $out .= '<span class="bchead">'.$lang['youarehere'].' </span>';
  723. // always print the startpage
  724. $out .= '<span class="home">' . tpl_pagelink(':'.$conf['start'], null, true) . '</span>';
  725. // print intermediate namespace links
  726. $part = '';
  727. for($i = 0; $i < $count - 1; $i++) {
  728. $part .= $parts[$i].':';
  729. $page = $part;
  730. if($page == $conf['start']) continue; // Skip startpage
  731. // output
  732. $out .= $sep . tpl_pagelink($page, null, true);
  733. }
  734. // print current page, skipping start page, skipping for namespace index
  735. resolve_pageid('', $page, $exists);
  736. if (isset($page) && $page == $part.$parts[$i]) {
  737. if($return) return $out;
  738. print $out;
  739. return true;
  740. }
  741. $page = $part.$parts[$i];
  742. if($page == $conf['start']) {
  743. if($return) return $out;
  744. print $out;
  745. return true;
  746. }
  747. $out .= $sep;
  748. $out .= tpl_pagelink($page, null, true);
  749. if($return) return $out;
  750. print $out;
  751. return $out ? true : false;
  752. }
  753. /**
  754. * Print info if the user is logged in
  755. * and show full name in that case
  756. *
  757. * Could be enhanced with a profile link in future?
  758. *
  759. * @author Andreas Gohr <andi@splitbrain.org>
  760. *
  761. * @return bool
  762. */
  763. function tpl_userinfo() {
  764. global $lang;
  765. /** @var Input $INPUT */
  766. global $INPUT;
  767. if($INPUT->server->str('REMOTE_USER')) {
  768. print $lang['loggedinas'].' '.userlink();
  769. return true;
  770. }
  771. return false;
  772. }
  773. /**
  774. * Print some info about the current page
  775. *
  776. * @author Andreas Gohr <andi@splitbrain.org>
  777. *
  778. * @param bool $ret return content instead of printing it
  779. * @return bool|string
  780. */
  781. function tpl_pageinfo($ret = false) {
  782. global $conf;
  783. global $lang;
  784. global $INFO;
  785. global $ID;
  786. // return if we are not allowed to view the page
  787. if(!auth_quickaclcheck($ID)) {
  788. return false;
  789. }
  790. // prepare date and path
  791. $fn = $INFO['filepath'];
  792. if(!$conf['fullpath']) {
  793. if($INFO['rev']) {
  794. $fn = str_replace($conf['olddir'].'/', '', $fn);
  795. } else {
  796. $fn = str_replace($conf['datadir'].'/', '', $fn);
  797. }
  798. }
  799. $fn = utf8_decodeFN($fn);
  800. $date = dformat($INFO['lastmod']);
  801. // print it
  802. if($INFO['exists']) {
  803. $out = '';
  804. $out .= '<bdi>'.$fn.'</bdi>';
  805. $out .= ' · ';
  806. $out .= $lang['lastmod'];
  807. $out .= ' ';
  808. $out .= $date;
  809. if($INFO['editor']) {
  810. $out .= ' '.$lang['by'].' ';
  811. $out .= '<bdi>'.editorinfo($INFO['editor']).'</bdi>';
  812. } else {
  813. $out .= ' ('.$lang['external_edit'].')';
  814. }
  815. if($INFO['locked']) {
  816. $out .= ' · ';
  817. $out .= $lang['lockedby'];
  818. $out .= ' ';
  819. $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
  820. }
  821. if($ret) {
  822. return $out;
  823. } else {
  824. echo $out;
  825. return true;
  826. }
  827. }
  828. return false;
  829. }
  830. /**
  831. * Prints or returns the name of the given page (current one if none given).
  832. *
  833. * If useheading is enabled this will use the first headline else
  834. * the given ID is used.
  835. *
  836. * @author Andreas Gohr <andi@splitbrain.org>
  837. *
  838. * @param string $id page id
  839. * @param bool $ret return content instead of printing
  840. * @return bool|string
  841. */
  842. function tpl_pagetitle($id = null, $ret = false) {
  843. global $ACT, $INPUT, $conf, $lang;
  844. if(is_null($id)) {
  845. global $ID;
  846. $id = $ID;
  847. }
  848. $name = $id;
  849. if(useHeading('navigation')) {
  850. $first_heading = p_get_first_heading($id);
  851. if($first_heading) $name = $first_heading;
  852. }
  853. // default page title is the page name, modify with the current action
  854. switch ($ACT) {
  855. // admin functions
  856. case 'admin' :
  857. $page_title = $lang['btn_admin'];
  858. // try to get the plugin name
  859. /** @var $plugin AdminPlugin */
  860. if ($plugin = plugin_getRequestAdminPlugin()){
  861. $plugin_title = $plugin->getMenuText($conf['lang']);
  862. $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
  863. }
  864. break;
  865. // user functions
  866. case 'login' :
  867. case 'profile' :
  868. case 'register' :
  869. case 'resendpwd' :
  870. $page_title = $lang['btn_'.$ACT];
  871. break;
  872. // wiki functions
  873. case 'search' :
  874. case 'index' :
  875. $page_title = $lang['btn_'.$ACT];
  876. break;
  877. // page functions
  878. case 'edit' :
  879. case 'preview' :
  880. $page_title = "✎ ".$name;
  881. break;
  882. case 'revisions' :
  883. $page_title = $name . ' - ' . $lang['btn_revs'];
  884. break;
  885. case 'backlink' :
  886. case 'recent' :
  887. case 'subscribe' :
  888. $page_title = $name . ' - ' . $lang['btn_'.$ACT];
  889. break;
  890. default : // SHOW and anything else not included
  891. $page_title = $name;
  892. }
  893. if($ret) {
  894. return hsc($page_title);
  895. } else {
  896. print hsc($page_title);
  897. return true;
  898. }
  899. }
  900. /**
  901. * Returns the requested EXIF/IPTC tag from the current image
  902. *
  903. * If $tags is an array all given tags are tried until a
  904. * value is found. If no value is found $alt is returned.
  905. *
  906. * Which texts are known is defined in the functions _exifTagNames
  907. * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
  908. * to the names of the latter one)
  909. *
  910. * Only allowed in: detail.php
  911. *
  912. * @author Andreas Gohr <andi@splitbrain.org>
  913. *
  914. * @param array|string $tags tag or array of tags to try
  915. * @param string $alt alternative output if no data was found
  916. * @param null|string $src the image src, uses global $SRC if not given
  917. * @return string
  918. */
  919. function tpl_img_getTag($tags, $alt = '', $src = null) {
  920. // Init Exif Reader
  921. global $SRC;
  922. if(is_null($src)) $src = $SRC;
  923. static $meta = null;
  924. if(is_null($meta)) $meta = new JpegMeta($src);
  925. if($meta === false) return $alt;
  926. $info = cleanText($meta->getField($tags));
  927. if($info == false) return $alt;
  928. return $info;
  929. }
  930. /**
  931. * Returns a description list of the metatags of the current image
  932. *
  933. * @return string html of description list
  934. */
  935. function tpl_img_meta() {
  936. global $lang;
  937. $tags = tpl_get_img_meta();
  938. echo '<dl>';
  939. foreach($tags as $tag) {
  940. $label = $lang[$tag['langkey']];
  941. if(!$label) $label = $tag['langkey'] . ':';
  942. echo '<dt>'.$label.'</dt><dd>';
  943. if ($tag['type'] == 'date') {
  944. echo dformat($tag['value']);
  945. } else {
  946. echo hsc($tag['value']);
  947. }
  948. echo '</dd>';
  949. }
  950. echo '</dl>';
  951. }
  952. /**
  953. * Returns metadata as configured in mediameta config file, ready for creating html
  954. *
  955. * @return array with arrays containing the entries:
  956. * - string langkey key to lookup in the $lang var, if not found printed as is
  957. * - string type type of value
  958. * - string value tag value (unescaped)
  959. */
  960. function tpl_get_img_meta() {
  961. $config_files = getConfigFiles('mediameta');
  962. foreach ($config_files as $config_file) {
  963. if(file_exists($config_file)) {
  964. include($config_file);
  965. }
  966. }
  967. /** @var array $fields the included array with metadata */
  968. $tags = array();
  969. foreach($fields as $tag){
  970. $t = array();
  971. if (!empty($tag[0])) {
  972. $t = array($tag[0]);
  973. }
  974. if(is_array($tag[3])) {
  975. $t = array_merge($t,$tag[3]);
  976. }
  977. $value = tpl_img_getTag($t);
  978. if ($value) {
  979. $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
  980. }
  981. }
  982. return $tags;
  983. }
  984. /**
  985. * Prints the image with a link to the full sized version
  986. *
  987. * Only allowed in: detail.php
  988. *
  989. * @triggers TPL_IMG_DISPLAY
  990. * @param $maxwidth int - maximal width of the image
  991. * @param $maxheight int - maximal height of the image
  992. * @param $link bool - link to the orginal size?
  993. * @param $params array - additional image attributes
  994. * @return bool Result of TPL_IMG_DISPLAY
  995. */
  996. function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
  997. global $IMG;
  998. /** @var Input $INPUT */
  999. global $INPUT;
  1000. global $REV;
  1001. $w = (int) tpl_img_getTag('File.Width');
  1002. $h = (int) tpl_img_getTag('File.Height');
  1003. //resize to given max values
  1004. $ratio = 1;
  1005. if($w >= $h) {
  1006. if($maxwidth && $w >= $maxwidth) {
  1007. $ratio = $maxwidth / $w;
  1008. } elseif($maxheight && $h > $maxheight) {
  1009. $ratio = $maxheight / $h;
  1010. }
  1011. } else {
  1012. if($maxheight && $h >= $maxheight) {
  1013. $ratio = $maxheight / $h;
  1014. } elseif($maxwidth && $w > $maxwidth) {
  1015. $ratio = $maxwidth / $w;
  1016. }
  1017. }
  1018. if($ratio) {
  1019. $w = floor($ratio * $w);
  1020. $h = floor($ratio * $h);
  1021. }
  1022. //prepare URLs
  1023. $url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
  1024. $src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
  1025. //prepare attributes
  1026. $alt = tpl_img_getTag('Simple.Title');
  1027. if(is_null($params)) {
  1028. $p = array();
  1029. } else {
  1030. $p = $params;
  1031. }
  1032. if($w) $p['width'] = $w;
  1033. if($h) $p['height'] = $h;
  1034. $p['class'] = 'img_detail';
  1035. if($alt) {
  1036. $p['alt'] = $alt;
  1037. $p['title'] = $alt;
  1038. } else {
  1039. $p['alt'] = '';
  1040. }
  1041. $p['src'] = $src;
  1042. $data = array('url'=> ($link ? $url : null), 'params'=> $p);
  1043. return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
  1044. }
  1045. /**
  1046. * Default action for TPL_IMG_DISPLAY
  1047. *
  1048. * @param array $data
  1049. * @return bool
  1050. */
  1051. function _tpl_img_action($data) {
  1052. global $lang;
  1053. $p = buildAttributes($data['params']);
  1054. if($data['url']) print '<a href="'.hsc($data['url']).'" title="'.$lang['mediaview'].'">';
  1055. print '<img '.$p.'/>';
  1056. if($data['url']) print '</a>';
  1057. return true;
  1058. }
  1059. /**
  1060. * This function inserts a small gif which in reality is the indexer function.
  1061. *
  1062. * Should be called somewhere at the very end of the main.php
  1063. * template
  1064. *
  1065. * @return bool
  1066. */
  1067. function tpl_indexerWebBug() {
  1068. global $ID;
  1069. $p = array();
  1070. $p['src'] = DOKU_BASE.'lib/exe/taskrunner.php?id='.rawurlencode($ID).
  1071. '&'.time();
  1072. $p['width'] = 2; //no more 1x1 px image because we live in times of ad blockers...
  1073. $p['height'] = 1;
  1074. $p['alt'] = '';
  1075. $att = buildAttributes($p);
  1076. print "<img $att />";
  1077. return true;
  1078. }
  1079. /**
  1080. * tpl_getConf($id)
  1081. *
  1082. * use this function to access template configuration variables
  1083. *
  1084. * @param string $id name of the value to access
  1085. * @param mixed $notset what to return if the setting is not available
  1086. * @return mixed
  1087. */
  1088. function tpl_getConf($id, $notset=false) {
  1089. global $conf;
  1090. static $tpl_configloaded = false;
  1091. $tpl = $conf['template'];
  1092. if(!$tpl_configloaded) {
  1093. $tconf = tpl_loadConfig();
  1094. if($tconf !== false) {
  1095. foreach($tconf as $key => $value) {
  1096. if(isset($conf['tpl'][$tpl][$key])) continue;
  1097. $conf['tpl'][$tpl][$key] = $value;
  1098. }
  1099. $tpl_configloaded = true;
  1100. }
  1101. }
  1102. if(isset($conf['tpl'][$tpl][$id])){
  1103. return $conf['tpl'][$tpl][$id];
  1104. }
  1105. return $notset;
  1106. }
  1107. /**
  1108. * tpl_loadConfig()
  1109. *
  1110. * reads all template configuration variables
  1111. * this function is automatically called by tpl_getConf()
  1112. *
  1113. * @return array
  1114. */
  1115. function tpl_loadConfig() {
  1116. $file = tpl_incdir().'/conf/default.php';
  1117. $conf = array();
  1118. if(!file_exists($file)) return false;
  1119. // load default config file
  1120. include($file);
  1121. return $conf;
  1122. }
  1123. // language methods
  1124. /**
  1125. * tpl_getLang($id)
  1126. *
  1127. * use this function to access template language variables
  1128. *
  1129. * @param string $id key of language string
  1130. * @return string
  1131. */
  1132. function tpl_getLang($id) {
  1133. static $lang = array();
  1134. if(count($lang) === 0) {
  1135. global $conf, $config_cascade; // definitely don't invoke "global $lang"
  1136. $path = tpl_incdir() . 'lang/';
  1137. $lang = array();
  1138. // don't include once
  1139. @include($path . 'en/lang.php');
  1140. foreach($config_cascade['lang']['template'] as $config_file) {
  1141. if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
  1142. include($config_file . $conf['template'] . '/en/lang.php');
  1143. }
  1144. }
  1145. if($conf['lang'] != 'en') {
  1146. @include($path . $conf['lang'] . '/lang.php');
  1147. foreach($config_cascade['lang']['template'] as $config_file) {
  1148. if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
  1149. include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
  1150. }
  1151. }
  1152. }
  1153. }
  1154. return $lang[$id];
  1155. }
  1156. /**
  1157. * Retrieve a language dependent file and pass to xhtml renderer for display
  1158. * template equivalent of p_locale_xhtml()
  1159. *
  1160. * @param string $id id of language dependent wiki page
  1161. * @return string parsed contents of the wiki page in xhtml format
  1162. */
  1163. function tpl_locale_xhtml($id) {
  1164. return p_cached_output(tpl_localeFN($id));
  1165. }
  1166. /**
  1167. * Prepends appropriate path for a language dependent filename
  1168. *
  1169. * @param string $id id of localized text
  1170. * @return string wiki text
  1171. */
  1172. function tpl_localeFN($id) {
  1173. $path = tpl_incdir().'lang/';
  1174. global $conf;
  1175. $file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
  1176. if (!file_exists($file)){
  1177. $file = $path.$conf['lang'].'/'.$id.'.txt';
  1178. if(!file_exists($file)){
  1179. //fall back to english
  1180. $file = $path.'en/'.$id.'.txt';
  1181. }
  1182. }
  1183. return $file;
  1184. }
  1185. /**
  1186. * prints the "main content" in the mediamanager popup
  1187. *
  1188. * Depending on the user's actions this may be a list of
  1189. * files in a namespace, the meta editing dialog or
  1190. * a message of referencing pages
  1191. *
  1192. * Only allowed in mediamanager.php
  1193. *
  1194. * @triggers MEDIAMANAGER_CONTENT_OUTPUT
  1195. * @param bool $fromajax - set true when calling this function via ajax
  1196. * @param string $sort
  1197. *
  1198. * @author Andreas Gohr <andi@splitbrain.org>
  1199. */
  1200. function tpl_mediaContent($fromajax = false, $sort='natural') {
  1201. global $IMG;
  1202. global $AUTH;
  1203. global $INUSE;
  1204. global $NS;
  1205. global $JUMPTO;
  1206. /** @var Input $INPUT */
  1207. global $INPUT;
  1208. $do = $INPUT->extract('do')->str('do');
  1209. if(in_array($do, array('save', 'cancel'))) $do = '';
  1210. if(!$do) {
  1211. if($INPUT->bool('edit')) {
  1212. $do = 'metaform';
  1213. } elseif(is_array($INUSE)) {
  1214. $do = 'filesinuse';
  1215. } else {
  1216. $do = 'filelist';
  1217. }
  1218. }
  1219. // output the content pane, wrapped in an event.
  1220. if(!$fromajax) ptln('<div id="media__content">');
  1221. $data = array('do' => $do);
  1222. $evt = new Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
  1223. if($evt->advise_before()) {
  1224. $do = $data['do'];
  1225. if($do == 'filesinuse') {
  1226. media_filesinuse($INUSE, $IMG);
  1227. } elseif($do == 'filelist') {
  1228. media_filelist($NS, $AUTH, $JUMPTO,false,$sort);
  1229. } elseif($do == 'searchlist') {
  1230. media_searchlist($INPUT->str('q'), $NS, $AUTH);
  1231. } else {
  1232. msg('Unknown action '.hsc($do), -1);
  1233. }
  1234. }
  1235. $evt->advise_after();
  1236. unset($evt);
  1237. if(!$fromajax) ptln('</div>');
  1238. }
  1239. /**
  1240. * Prints the central column in full-screen media manager
  1241. * Depending on the opened tab this may be a list of
  1242. * files in a namespace, upload form or search form
  1243. *
  1244. * @author Kate Arzamastseva <pshns@ukr.net>
  1245. */
  1246. function tpl_mediaFileList() {
  1247. global $AUTH;
  1248. global $NS;
  1249. global $JUMPTO;
  1250. global $lang;
  1251. /** @var Input $INPUT */
  1252. global $INPUT;
  1253. $opened_tab = $INPUT->str('tab_files');
  1254. if(!$opened_tab || !in_array($opened_tab, array('files', 'upload', 'search'))) $opened_tab = 'files';
  1255. if($INPUT->str('mediado') == 'update') $opened_tab = 'upload';
  1256. echo '<h2 class="a11y">'.$lang['mediaselect'].'</h2>'.NL;
  1257. media_tabs_files($opened_tab);
  1258. echo '<div class="panelHeader">'.NL;
  1259. echo '<h3>';
  1260. $tabTitle = ($NS) ? $NS : '['.$lang['mediaroot'].']';
  1261. printf($lang['media_'.$opened_tab], '<strong>'.hsc($tabTitle).'</strong>');
  1262. echo '</h3>'.NL;
  1263. if($opened_tab === 'search' || $opened_tab === 'files') {
  1264. media_tab_files_options();
  1265. }
  1266. echo '</div>'.NL;
  1267. echo '<div class="panelContent">'.NL;
  1268. if($opened_tab == 'files') {
  1269. media_tab_files($NS, $AUTH, $JUMPTO);
  1270. } elseif($opened_tab == 'upload') {
  1271. media_tab_upload($NS, $AUTH, $JUMPTO);
  1272. } elseif($opened_tab == 'search') {
  1273. media_tab_search($NS, $AUTH);
  1274. }
  1275. echo '</div>'.NL;
  1276. }
  1277. /**
  1278. * Prints the third column in full-screen media manager
  1279. * Depending on the opened tab this may be details of the
  1280. * selected file, the meta editing dialog or
  1281. * list of file revisions
  1282. *
  1283. * @author Kate Arzamastseva <pshns@ukr.net>
  1284. *
  1285. * @param string $image
  1286. * @param boolean $rev
  1287. */
  1288. function tpl_mediaFileDetails($image, $rev) {
  1289. global $conf, $DEL, $lang;
  1290. /** @var Input $INPUT */
  1291. global $INPUT;
  1292. $removed = (
  1293. !file_exists(mediaFN($image)) &&
  1294. file_exists(mediaMetaFN($image, '.changes')) &&
  1295. $conf['mediarevisions']
  1296. );
  1297. if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
  1298. if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
  1299. $ns = getNS($image);
  1300. $do = $INPUT->str('mediado');
  1301. $opened_tab = $INPUT->str('tab_details');
  1302. $tab_array = array('view');
  1303. list(, $mime) = mimetype($image);
  1304. if($mime == 'image/jpeg') {
  1305. $tab_array[] = 'edit';
  1306. }
  1307. if($conf['mediarevisions']) {
  1308. $tab_array[] = 'history';
  1309. }
  1310. if(!$opened_tab || !in_array($opened_tab, $tab_array)) $opened_tab = 'view';
  1311. if($INPUT->bool('edit')) $opened_tab = 'edit';
  1312. if($do == 'restore') $opened_tab = 'view';
  1313. media_tabs_details($image, $opened_tab);
  1314. echo '<div class="panelHeader"><h3>';
  1315. list($ext) = mimetype($image, false);
  1316. $class = preg_replace('/[^_\-a-z0-9]+/i', '_', $ext);
  1317. $class = 'select mediafile mf_'.$class;
  1318. $attributes = $rev ? ['rev' => $rev] : [];
  1319. $tabTitle = '<strong><a href="'.ml($image, $attributes).'" class="'.$class.'" title="'.$lang['mediaview'].'">'.
  1320. $image.'</a>'.'</strong>';
  1321. if($opened_tab === 'view' && $rev) {
  1322. printf($lang['media_viewold'], $tabTitle, dformat($rev));
  1323. } else {
  1324. printf($lang['media_'.$opened_tab], $tabTitle);
  1325. }
  1326. echo '</h3></div>'.NL;
  1327. echo '<div class="panelContent">'.NL;
  1328. if($opened_tab == 'view') {
  1329. media_tab_view($image, $ns, null, $rev);
  1330. } elseif($opened_tab == 'edit' && !$removed) {
  1331. media_tab_edit($image, $ns);
  1332. } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
  1333. media_tab_history($image, $ns);
  1334. }
  1335. echo '</div>'.NL;
  1336. }
  1337. /**
  1338. * prints the namespace tree in the mediamanager popup
  1339. *
  1340. * Only allowed in mediamanager.php
  1341. *
  1342. * @author Andreas Gohr <andi@splitbrain.org>
  1343. */
  1344. function tpl_mediaTree() {
  1345. global $NS;
  1346. ptln('<div id="media__tree">');
  1347. media_nstree($NS);
  1348. ptln('</div>');
  1349. }
  1350. /**
  1351. * Print a dropdown menu with all DokuWiki actions
  1352. *
  1353. * Note: this will not use any pretty URLs
  1354. *
  1355. * @author Andreas Gohr <andi@splitbrain.org>
  1356. *
  1357. * @param string $empty empty option label
  1358. * @param string $button submit button label
  1359. * @deprecated 2017-09-01 see devel:menus
  1360. */
  1361. function tpl_actiondropdown($empty = '', $button = '&gt;') {
  1362. dbg_deprecated('see devel:menus');
  1363. $menu = new \dokuwiki\Menu\MobileMenu();
  1364. echo $menu->getDropdown($empty, $button);
  1365. }
  1366. /**
  1367. * Print a informational line about the used license
  1368. *
  1369. * @author Andreas Gohr <andi@splitbrain.org>
  1370. * @param string $img print image? (|button|badge)
  1371. * @param bool $imgonly skip the textual description?
  1372. * @param bool $return when true don't print, but return HTML
  1373. * @param bool $wrap wrap in div with class="license"?
  1374. * @return string
  1375. */
  1376. function tpl_license($img = 'badge', $imgonly = false, $return = false, $wrap = true) {
  1377. global $license;
  1378. global $conf;
  1379. global $lang;
  1380. if(!$conf['license']) return '';
  1381. if(!is_array($license[$conf['license']])) return '';
  1382. $lic = $license[$conf['license']];
  1383. $target = ($conf['target']['extern']) ? ' target="'.$conf['target']['extern'].'"' : '';
  1384. $out = '';
  1385. if($wrap) $out .= '<div class="license">';
  1386. if($img) {
  1387. $src = license_img($img);
  1388. if($src) {
  1389. $out .= '<a href="'.$lic['url'].'" rel="license"'.$target;
  1390. $out .= '><img src="'.DOKU_BASE.$src.'" alt="'.$lic['name'].'" /></a>';
  1391. if(!$imgonly) $out .= ' ';
  1392. }
  1393. }
  1394. if(!$imgonly) {
  1395. $out .= $lang['license'].' ';
  1396. $out .= '<bdi><a href="'.$lic['url'].'" rel="license" class="urlextern"'.$target;
  1397. $out .= '>'.$lic['name'].'</a></bdi>';
  1398. }
  1399. if($wrap) $out .= '</div>';
  1400. if($return) return $out;
  1401. echo $out;
  1402. return '';
  1403. }
  1404. /**
  1405. * Includes the rendered HTML of a given page
  1406. *
  1407. * This function is useful to populate sidebars or similar features in a
  1408. * template
  1409. *
  1410. * @param string $pageid The page name you want to include
  1411. * @param bool $print Should the content be printed or returned only
  1412. * @param bool $propagate Search higher namespaces, too?
  1413. * @param bool $useacl Include the page only if the ACLs check out?
  1414. * @return bool|null|string
  1415. */
  1416. function tpl_include_page($pageid, $print = true, $propagate = false, $useacl = true) {
  1417. if($propagate) {
  1418. $pageid = page_findnearest($pageid, $useacl);
  1419. } elseif($useacl && auth_quickaclcheck($pageid) == AUTH_NONE) {
  1420. return false;
  1421. }
  1422. if(!$pageid) return false;
  1423. global $TOC;
  1424. $oldtoc = $TOC;
  1425. $html = p_wiki_xhtml($pageid, '', false);
  1426. $TOC = $oldtoc;
  1427. if($print) echo $html;
  1428. return $html;
  1429. }
  1430. /**
  1431. * Display the subscribe form
  1432. *
  1433. * @author Adrian Lang <lang@cosmocode.de>
  1434. */
  1435. function tpl_subscribe() {
  1436. global $INFO;
  1437. global $ID;
  1438. global $lang;
  1439. global $conf;
  1440. $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
  1441. echo p_locale_xhtml('subscr_form');
  1442. echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
  1443. echo '<div class="level2">';
  1444. if($INFO['subscribed'] === false) {
  1445. echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
  1446. } else {
  1447. echo '<ul>';
  1448. foreach($INFO['subscribed'] as $sub) {
  1449. echo '<li><div class="li">';
  1450. if($sub['target'] !== $ID) {
  1451. echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
  1452. } else {
  1453. echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
  1454. }
  1455. $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
  1456. if(!$sstl) $sstl = hsc($sub['style']);
  1457. echo ' ('.$sstl.') ';
  1458. echo '<a href="'.wl(
  1459. $ID,
  1460. array(
  1461. 'do' => 'subscribe',
  1462. 'sub_target'=> $sub['target'],
  1463. 'sub_style' => $sub['style'],
  1464. 'sub_action'=> 'unsubscribe',
  1465. 'sectok' => getSecurityToken()
  1466. )
  1467. ).
  1468. '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
  1469. '</a></div></li>';
  1470. }
  1471. echo '</ul>';
  1472. }
  1473. echo '</div>';
  1474. // Add new subscription form
  1475. echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
  1476. echo '<div class="level2">';
  1477. $ns = getNS($ID).':';
  1478. $targets = array(
  1479. $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
  1480. $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
  1481. );
  1482. $styles = array(
  1483. 'every' => $lang['subscr_style_every'],
  1484. 'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
  1485. 'list' => sprintf($lang['subscr_style_list'], $stime_days),
  1486. );
  1487. $form = new Doku_Form(array('id' => 'subscribe__form'));
  1488. $form->startFieldset($lang['subscr_m_subscribe']);
  1489. $form->addRadioSet('sub_target', $targets);
  1490. $form->startFieldset($lang['subscr_m_receive']);
  1491. $form->addRadioSet('sub_style', $styles);
  1492. $form->addHidden('sub_action', 'subscribe');
  1493. $form->addHidden('do', 'subscribe');
  1494. $form->addHidden('id', $ID);
  1495. $form->endFieldset();
  1496. $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
  1497. html_form('SUBSCRIBE', $form);
  1498. echo '</div>';
  1499. }
  1500. /**
  1501. * Tries to send already created content right to the browser
  1502. *
  1503. * Wraps around ob_flush() and flush()
  1504. *
  1505. * @author Andreas Gohr <andi@splitbrain.org>
  1506. */
  1507. function tpl_flush() {
  1508. if( ob_get_level() > 0 ) ob_flush();
  1509. flush();
  1510. }
  1511. /**
  1512. * Tries to find a ressource file in the given locations.
  1513. *
  1514. * If a given location starts with a colon it is assumed to be a media
  1515. * file, otherwise it is assumed to be relative to the current template
  1516. *
  1517. * @param string[] $search locations to look at
  1518. * @param bool $abs if to use absolute URL
  1519. * @param array &$imginfo filled with getimagesize()
  1520. * @return string
  1521. *
  1522. * @author Andreas Gohr <andi@splitbrain.org>
  1523. */
  1524. function tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
  1525. $img = '';
  1526. $file = '';
  1527. $ismedia = false;
  1528. // loop through candidates until a match was found:
  1529. foreach($search as $img) {
  1530. if(substr($img, 0, 1) == ':') {
  1531. $file = mediaFN($img);
  1532. $ismedia = true;
  1533. } else {
  1534. $file = tpl_incdir().$img;
  1535. $ismedia = false;
  1536. }
  1537. if(file_exists($file)) break;
  1538. }
  1539. // fetch image data if requested
  1540. if(!is_null($imginfo)) {
  1541. $imginfo = getimagesize($file);
  1542. }
  1543. // build URL
  1544. if($ismedia) {
  1545. $url = ml($img, '', true, '', $abs);
  1546. } else {
  1547. $url = tpl_basedir().$img;
  1548. if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL));
  1549. }
  1550. return $url;
  1551. }
  1552. /**
  1553. * PHP include a file
  1554. *
  1555. * either from the conf directory if it exists, otherwise use
  1556. * file in the template's root directory.
  1557. *
  1558. * The function honours config cascade settings and looks for the given
  1559. * file next to the ´main´ config files, in the order protected, local,
  1560. * default.
  1561. *
  1562. * Note: no escaping or sanity checking is done here. Never pass user input
  1563. * to this function!
  1564. *
  1565. * @author Anika Henke <anika@selfthinker.org>
  1566. * @author Andreas Gohr <andi@splitbrain.org>
  1567. *
  1568. * @param string $file
  1569. */
  1570. function tpl_includeFile($f

Large files files are truncated, but you can click here to view the full file