68
68
* handled by this function. ACL stuff is not done here either.
70
70
* @author Andreas Gohr <andi@splitbrain.org>
71
72
* @triggers TPL_ACT_RENDER
72
73
* @triggers TPL_CONTENT_DISPLAY
73
74
* @param bool $prependTOC should the TOC be displayed here?
172
173
$evt = new Doku_Event('TPL_ACT_UNKNOWN', $ACT);
173
if($evt->advise_before())
174
if($evt->advise_before()) {
174
175
msg("Failed to handle command: ".hsc($ACT), -1);
175
177
$evt->advise_after();
205
208
} elseif(($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
206
209
// get TOC from metadata, render if neccessary
207
$meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE);
210
$meta = p_get_metadata($ID, '', METADATA_RENDER_USING_CACHE);
208
211
if(isset($meta['internal']['toc'])) {
209
212
$tocok = $meta['internal']['toc'];
217
220
} elseif($ACT == 'admin') {
218
// try to load admin plugin TOC FIXME: duplicates code from tpl_admin
220
$class = $INPUT->str('page');
222
$pluginlist = plugin_list('admin');
223
if(in_array($class, $pluginlist)) {
224
// attempt to load the plugin
225
/** @var $plugin DokuWiki_Admin_Plugin */
226
$plugin = plugin_load('admin', $class);
229
if( ($plugin !== null) && (!$plugin->forAdminOnly() || $INFO['isadmin']) ) {
221
// try to load admin plugin TOC
222
/** @var $plugin DokuWiki_Admin_Plugin */
223
if ($plugin = plugin_getRequestAdminPlugin()) {
230
224
$toc = $plugin->getTOC();
231
225
$TOC = $toc; // avoid later rebuild
370
368
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
372
$head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&'));
370
$canonicalUrl = wl($ID, '', true, '&');
371
if ($ID == $conf['start']) {
372
$canonicalUrl = DOKU_URL;
374
$head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
374
376
$head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
383
385
if($ACT == 'show' || $ACT == 'export_xhtml') {
384
// date of modification
386
$head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV));
388
$head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod']));
391
386
// keywords (explicit or implicit)
392
387
if(!empty($INFO['meta']['subject'])) {
393
388
$head['meta'][] = array('name'=> 'keywords', 'content'=> join(',', $INFO['meta']['subject']));
399
394
// load stylesheets
400
395
$head['link'][] = array(
401
396
'rel' => 'stylesheet', 'type'=> 'text/css',
402
'href'=> DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed
397
'href'=> DOKU_BASE.'lib/exe/css.php?t='.rawurlencode($conf['template']).'&tseed='.$tseed
405
400
// make $INFO and other vars available to JavaScripts
414
409
// load external javascript
415
410
$head['script'][] = array(
416
411
'type'=> 'text/javascript', 'charset'=> 'utf-8', '_data'=> '',
417
'src' => DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed
412
'src' => DOKU_BASE.'lib/exe/js.php'.'?t='.rawurlencode($conf['template']).'&tseed='.$tseed
420
415
// trigger event here
429
424
* instances. Attributes are given as key value pairs. Values will be HTML
430
425
* encoded automatically so they should be provided as is in the $data array.
432
* For tags having a body attribute specify the the body data in the special
427
* For tags having a body attribute specify the body data in the special
433
428
* attribute '_data'. This field will NOT BE ESCAPED automatically.
435
430
* @author Andreas Gohr <andi@splitbrain.org>
437
434
function _tpl_metaheaders_action($data) {
438
435
foreach($data as $tag => $inst) {
459
456
* Just builds a link.
461
458
* @author Andreas Gohr <andi@splitbrain.org>
461
* @param string $name
462
* @param string $more
463
* @param bool $return if true return the link html, otherwise print
464
* @return bool|string html of the link, or true if printed
463
466
function tpl_link($url, $name, $more = '', $return = false) {
464
467
$out = '<a href="'.$url.'" ';
475
478
* Wrapper around html_wikilink
477
480
* @author Andreas Gohr <andi@splitbrain.org>
482
* @param string $id page id
483
* @param string|null $name the name of the link
479
486
function tpl_pagelink($id, $name = null) {
480
487
print '<bdi>'.html_wikilink($id, $name).'</bdi>';
488
495
* returns false if none is available
490
497
* @author Andreas Gohr <andi@splitbrain.org>
499
* @param string $id page id
500
* @return false|string
492
502
function tpl_getparent($id) {
493
503
$parent = getNS($id).':';
507
517
* @author Adrian Lang <mail@adrianlang.de>
508
518
* @see tpl_get_action
520
* @param string $type
521
* @param bool $return
522
* @return bool|string html, or false if no data, true if printed
510
524
function tpl_button($type, $return = false) {
511
525
$data = tpl_get_action($type);
538
552
* @author Adrian Lang <mail@adrianlang.de>
539
553
* @see tpl_get_action
555
* @param string $type action command
556
* @param string $pre prefix of link
557
* @param string $suf suffix of link
558
* @param string $inner innerHML of link
559
* @param bool $return if true it returns html, otherwise prints
560
* @return bool|string html or false if no data, true if printed
541
562
function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
574
595
$linktarget, $pre.(($inner) ? $inner : $caption).$suf,
575
596
'class="action '.$type.'" '.
577
'title="'.hsc($caption).$addTitle.'"', 1
598
'title="'.hsc($caption).$addTitle.'"', true
580
601
if($return) return $out;
752
776
//$type = 'media';
755
return '[unknown %s type]';
758
return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement');
783
$data = compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement');
785
$evt = new Doku_Event('TPL_ACTION_GET', $data);
786
if($evt->advise_before()) {
787
//handle unknown types
789
$data = '[unknown %s type]';
792
$evt->advise_after();
762
799
* Wrapper around tpl_button() and tpl_actionlink()
764
801
* @author Anika Henke <anika@selfthinker.org>
766
* @param bool $link link or form button?
767
* @param bool $wrapper HTML element wrapper
768
* @param bool $return return or print
769
* @param string $pre prefix for links
770
* @param string $suf suffix for links
771
* @param string $inner inner HTML for links
803
* @param string $type action command
804
* @param bool $link link or form button?
805
* @param string|bool $wrapper HTML element wrapper
806
* @param bool $return return or print
807
* @param string $pre prefix for links
808
* @param string $suf suffix for links
809
* @param string $inner inner HTML for links
772
810
* @return bool|string
774
812
function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
777
$out .= tpl_actionlink($type, $pre, $suf, $inner, 1);
815
$out .= tpl_actionlink($type, $pre, $suf, $inner, true);
779
$out .= tpl_button($type, 1);
817
$out .= tpl_button($type, true);
781
819
if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
812
851
print '<input type="hidden" name="do" value="search" />';
813
852
print '<input type="text" ';
814
853
if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
854
print 'placeholder="'.$lang['btn_search'].'" ';
815
855
if(!$autocomplete) print 'autocomplete="off" ';
816
856
print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
817
print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
857
print '<button type="submit" title="'.$lang['btn_search'].'">'.$lang['btn_search'].'</button>';
818
858
if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
819
859
print '</div></form>';
839
880
$crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
841
882
//render crumbs, highlight the last one
842
print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
883
print '<span class="bchead">'.$lang['breadcrumb'].'</span>';
843
884
$last = count($crumbs);
845
886
foreach($crumbs as $id => $name) {
879
921
$parts = explode(':', $ID);
880
922
$count = count($parts);
882
echo '<span class="bchead">'.$lang['youarehere'].': </span>';
924
echo '<span class="bchead">'.$lang['youarehere'].' </span>';
884
926
// always print the startpage
885
927
echo '<span class="home">';
996
1040
* the given ID is used.
998
1042
* @author Andreas Gohr <andi@splitbrain.org>
999
1044
* @param string $id page id
1000
1045
* @param bool $ret return content instead of printing
1001
1046
* @return bool|string
1003
1048
function tpl_pagetitle($id = null, $ret = false) {
1049
global $ACT, $INPUT, $conf, $lang;
1004
1051
if(is_null($id)) {
1010
1057
if(useHeading('navigation')) {
1011
$title = p_get_first_heading($id);
1012
if($title) $name = $title;
1058
$first_heading = p_get_first_heading($id);
1059
if($first_heading) $name = $first_heading;
1062
// default page title is the page name, modify with the current action
1066
$page_title = $lang['btn_admin'];
1067
// try to get the plugin name
1068
/** @var $plugin DokuWiki_Admin_Plugin */
1069
if ($plugin = plugin_getRequestAdminPlugin()){
1070
$plugin_title = $plugin->getMenuText($conf['lang']);
1071
$page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
1080
$page_title = $lang['btn_'.$ACT];
1086
$page_title = $lang['btn_'.$ACT];
1091
$page_title = "✎ ".$name;
1095
$page_title = $name . ' - ' . $lang['btn_revs'];
1101
$page_title = $name . ' - ' . $lang['btn_'.$ACT];
1104
default : // SHOW and anything else not included
1105
$page_title = $name;
1109
return hsc($page_title);
1111
print hsc($page_title);
1033
1126
* Only allowed in: detail.php
1035
1128
* @author Andreas Gohr <andi@splitbrain.org>
1036
* @param array $tags tags to try
1037
* @param string $alt alternative output if no data was found
1038
* @param null $src the image src, uses global $SRC if not given
1130
* @param array|string $tags tag or array of tags to try
1131
* @param string $alt alternative output if no data was found
1132
* @param null|string $src the image src, uses global $SRC if not given
1039
1133
* @return string
1041
1135
function tpl_img_getTag($tags, $alt = '', $src = null) {
1066
1160
foreach($tags as $tag) {
1067
1161
$label = $lang[$tag['langkey']];
1068
if(!$label) $label = $tag['langkey'];
1162
if(!$label) $label = $tag['langkey'] . ':';
1070
echo '<dt>'.$label.':</dt><dd>';
1164
echo '<dt>'.$label.'</dt><dd>';
1071
1165
if ($tag['type'] == 'date') {
1072
1166
echo dformat($tag['value']);
1123
1217
* @param $maxheight int - maximal height of the image
1124
1218
* @param $link bool - link to the orginal size?
1125
1219
* @param $params array - additional image attributes
1126
* @return mixed Result of TPL_IMG_DISPLAY
1220
* @return bool Result of TPL_IMG_DISPLAY
1128
1222
function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
1130
1224
/** @var Input $INPUT */
1132
1227
$w = tpl_img_getTag('File.Width');
1133
1228
$h = tpl_img_getTag('File.Height');
1156
$url = ml($IMG, array('cache'=> $INPUT->str('cache')), true, '&');
1157
$src = ml($IMG, array('cache'=> $INPUT->str('cache'), 'w'=> $w, 'h'=> $h), true, '&');
1251
$url = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV), true, '&');
1252
$src = ml($IMG, array('cache'=> $INPUT->str('cache'),'rev'=>$REV, 'w'=> $w, 'h'=> $h), true, '&');
1159
1254
//prepare attributes
1160
1255
$alt = tpl_img_getTag('Simple.Title');
1275
1370
* tpl_getLang($id)
1277
1372
* use this function to access template language variables
1374
* @param string $id key of language string
1279
1377
function tpl_getLang($id) {
1280
1378
static $lang = array();
1282
1380
if(count($lang) === 0) {
1283
$path = tpl_incdir().'lang/';
1381
global $conf, $config_cascade; // definitely don't invoke "global $lang"
1383
$path = tpl_incdir() . 'lang/';
1285
1385
$lang = array();
1287
global $conf; // definitely don't invoke "global $lang"
1288
1387
// don't include once
1289
@include($path.'en/lang.php');
1290
if($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
1388
@include($path . 'en/lang.php');
1389
foreach($config_cascade['lang']['template'] as $config_file) {
1390
if(file_exists($config_file . $conf['template'] . '/en/lang.php')) {
1391
include($config_file . $conf['template'] . '/en/lang.php');
1395
if($conf['lang'] != 'en') {
1396
@include($path . $conf['lang'] . '/lang.php');
1397
foreach($config_cascade['lang']['template'] as $config_file) {
1398
if(file_exists($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php')) {
1399
include($config_file . $conf['template'] . '/' . $conf['lang'] . '/lang.php');
1293
1404
return $lang[$id];
1308
1419
* Prepends appropriate path for a language dependent filename
1421
* @param string $id id of localized text
1422
* @return string wiki text
1310
1424
function tpl_localeFN($id) {
1311
1425
$path = tpl_incdir().'lang/';
1313
$file = DOKU_CONF.'/template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
1314
if (!@file_exists($file)){
1427
$file = DOKU_CONF.'template_lang/'.$conf['template'].'/'.$conf['lang'].'/'.$id.'.txt';
1428
if (!file_exists($file)){
1315
1429
$file = $path.$conf['lang'].'/'.$id.'.txt';
1316
if(!@file_exists($file)){
1430
if(!file_exists($file)){
1317
1431
//fall back to english
1318
1432
$file = $path.'en/'.$id.'.txt';
1333
1447
* @triggers MEDIAMANAGER_CONTENT_OUTPUT
1334
1448
* @param bool $fromajax - set true when calling this function via ajax
1449
* @param string $sort
1335
1451
* @author Andreas Gohr <andi@splitbrain.org>
1337
1453
function tpl_mediaContent($fromajax = false, $sort='natural') {
1431
1547
* @author Kate Arzamastseva <pshns@ukr.net>
1433
1549
function tpl_mediaFileDetails($image, $rev) {
1434
global $AUTH, $NS, $conf, $DEL, $lang;
1550
global $conf, $DEL, $lang;
1435
1551
/** @var Input $INPUT */
1438
1554
$removed = (!file_exists(mediaFN($image)) && file_exists(mediaMetaFN($image, '.changes')) && $conf['mediarevisions']);
1439
1555
if(!$image || (!file_exists(mediaFN($image)) && !$removed) || $DEL) return;
1440
1556
if($rev && !file_exists(mediaFN($image, $rev))) $rev = false;
1441
if(isset($NS) && getNS($image) != $NS) return;
1557
$ns = getNS($image);
1442
1558
$do = $INPUT->str('mediado');
1444
1560
$opened_tab = $INPUT->str('tab_details');
1474
1590
echo '<div class="panelContent">'.NL;
1476
1592
if($opened_tab == 'view') {
1477
media_tab_view($image, $NS, $AUTH, $rev);
1593
media_tab_view($image, $ns, null, $rev);
1479
1595
} elseif($opened_tab == 'edit' && !$removed) {
1480
media_tab_edit($image, $NS, $AUTH);
1596
media_tab_edit($image, $ns);
1482
1598
} elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1483
media_tab_history($image, $NS, $AUTH);
1599
media_tab_history($image, $ns);
1486
1602
echo '</div>'.NL;
1506
1622
* Note: this will not use any pretty URLs
1508
1624
* @author Andreas Gohr <andi@splitbrain.org>
1626
* @param string $empty empty option label
1627
* @param string $button submit button label
1510
1629
function tpl_actiondropdown($empty = '', $button = '>') {
1514
1633
/** @var Input $INPUT */
1636
$action_structure = array(
1637
'page_tools' => array('edit', 'revert', 'revisions', 'backlink', 'subscribe'),
1638
'site_tools' => array('recent', 'media', 'index'),
1639
'user_tools' => array('login', 'register', 'profile', 'admin'),
1517
1642
echo '<form action="'.script().'" method="get" accept-charset="utf-8">';
1518
1643
echo '<div class="no">';
1519
1644
echo '<input type="hidden" name="id" value="'.$ID.'" />';
1525
1650
echo '<select name="do" class="edit quickselect" title="'.$lang['tools'].'">';
1526
1651
echo '<option value="">'.$empty.'</option>';
1528
echo '<optgroup label="'.$lang['page_tools'].'">';
1529
$act = tpl_get_action('edit');
1530
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1532
$act = tpl_get_action('revert');
1533
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1535
$act = tpl_get_action('revisions');
1536
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1538
$act = tpl_get_action('backlink');
1539
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1541
$act = tpl_get_action('subscribe');
1542
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1545
echo '<optgroup label="'.$lang['site_tools'].'">';
1546
$act = tpl_get_action('recent');
1547
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1549
$act = tpl_get_action('media');
1550
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1552
$act = tpl_get_action('index');
1553
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1556
echo '<optgroup label="'.$lang['user_tools'].'">';
1557
$act = tpl_get_action('login');
1558
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1560
$act = tpl_get_action('register');
1561
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1563
$act = tpl_get_action('profile');
1564
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1566
$act = tpl_get_action('admin');
1567
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1653
foreach($action_structure as $tools => $actions) {
1654
echo '<optgroup label="'.$lang[$tools].'">';
1655
foreach($actions as $action) {
1656
$act = tpl_get_action($action);
1657
if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1570
1662
echo '</select>';
1571
echo '<input type="submit" value="'.$button.'" />';
1663
echo '<button type="submit">'.$button.'</button>';
1573
1665
echo '</form>';
1620
1712
* This function is useful to populate sidebars or similar features in a
1715
* @param string $pageid
1716
* @param bool $print
1717
* @param bool $propagate
1718
* @return bool|null|string
1623
1720
function tpl_include_page($pageid, $print = true, $propagate = false) {
1624
1721
if (!$pageid) return false;
1727
1824
* If a given location starts with a colon it is assumed to be a media
1728
1825
* file, otherwise it is assumed to be relative to the current template
1730
* @param array $search locations to look at
1731
* @param bool $abs if to use absolute URL
1732
* @param array &$imginfo filled with getimagesize()
1827
* @param string[] $search locations to look at
1828
* @param bool $abs if to use absolute URL
1829
* @param array &$imginfo filled with getimagesize()
1733
1830
* @return string
1734
1832
* @author Andreas Gohr <andi@splitbrain.org>
1736
1834
function tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1898
2001
return join(' ', $classes);
2005
* Create event for tools menues
2007
* @author Anika Henke <anika@selfthinker.org>
2008
* @param string $toolsname name of menu
2009
* @param array $items
2010
* @param string $view e.g. 'main', 'detail', ...
2012
function tpl_toolsevent($toolsname, $items, $view = 'main') {
2018
$hook = 'TEMPLATE_' . strtoupper($toolsname) . '_DISPLAY';
2019
$evt = new Doku_Event($hook, $data);
2020
if($evt->advise_before()) {
2021
foreach($evt->data['items'] as $k => $html) echo $html;
2023
$evt->advise_after();
1901
2026
//Setup VIM: ex: et ts=4 :