~yoboy-leguesh/ubuntu-fr-doc/maj20150810a

« back to all changes in this revision

Viewing changes to inc/template.php

  • Committer: YoBoY
  • Date: 2015-11-11 10:05:14 UTC
  • Revision ID: yoboy.leguesh@gmail.com-20151111100514-bw7p06lrhban4g2t
Mise à jour vers Dokuwiki 2015-08-10a avec nos patchs

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 * handled by this function. ACL stuff is not done here either.
69
69
 *
70
70
 * @author Andreas Gohr <andi@splitbrain.org>
 
71
 *
71
72
 * @triggers TPL_ACT_RENDER
72
73
 * @triggers TPL_CONTENT_DISPLAY
73
74
 * @param bool $prependTOC should the TOC be displayed here?
170
171
            break;
171
172
        default:
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);
 
176
            }
175
177
            $evt->advise_after();
176
178
            unset($evt);
177
179
            return false;
186
188
 * a false argument
187
189
 *
188
190
 * @author Andreas Gohr <andi@splitbrain.org>
 
191
 *
189
192
 * @param bool $return Should the TOC be returned instead to be printed?
190
193
 * @return string
191
194
 */
204
207
        $toc = $TOC;
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'];
210
213
        } else {
215
218
            $toc = array();
216
219
        }
217
220
    } elseif($ACT == 'admin') {
218
 
        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
219
 
        $plugin = null;
220
 
        $class  = $INPUT->str('page');
221
 
        if(!empty($class)) {
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);
227
 
            }
228
 
        }
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
232
226
        }
243
237
 * Handle the admin page contents
244
238
 *
245
239
 * @author Andreas Gohr <andi@splitbrain.org>
 
240
 *
 
241
 * @return bool
246
242
 */
247
243
function tpl_admin() {
248
244
    global $INFO;
277
273
 * This has to go into the head section of your template.
278
274
 *
279
275
 * @author Andreas Gohr <andi@splitbrain.org>
 
276
 *
280
277
 * @triggers TPL_METAHEADER_OUTPUT
281
278
 * @param  bool $alt Should feeds and alternative format links be added?
282
279
 * @return bool
300
297
    // prepare seed for js and css
301
298
    $tseed   = $updateVersion;
302
299
    $depends = getConfigFiles('main');
 
300
    $depends[] = DOKU_CONF."tpl/".$conf['template']."/style.ini";
303
301
    foreach($depends as $f) $tseed .= @filemtime($f);
304
302
    $tseed   = md5($tseed);
305
303
 
369
367
            } else {
370
368
                $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,nofollow');
371
369
            }
372
 
            $head['link'][] = array('rel'=> 'canonical', 'href'=> wl($ID, '', true, '&'));
 
370
            $canonicalUrl = wl($ID, '', true, '&');
 
371
            if ($ID == $conf['start']) {
 
372
                $canonicalUrl = DOKU_URL;
 
373
            }
 
374
            $head['link'][] = array('rel'=> 'canonical', 'href'=> $canonicalUrl);
373
375
        } else {
374
376
            $head['meta'][] = array('name'=> 'robots', 'content'=> 'noindex,follow');
375
377
        }
381
383
 
382
384
    // set metadata
383
385
    if($ACT == 'show' || $ACT == 'export_xhtml') {
384
 
        // date of modification
385
 
        if($REV) {
386
 
            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $REV));
387
 
        } else {
388
 
            $head['meta'][] = array('name'=> 'date', 'content'=> date('Y-m-d\TH:i:sO', $INFO['lastmod']));
389
 
        }
390
 
 
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
403
398
    );
404
399
 
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
418
413
    );
419
414
 
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.
431
426
 *
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.
434
429
 *
435
430
 * @author Andreas Gohr <andi@splitbrain.org>
 
431
 *
 
432
 * @param array $data
436
433
 */
437
434
function _tpl_metaheaders_action($data) {
438
435
    foreach($data as $tag => $inst) {
459
456
 * Just builds a link.
460
457
 *
461
458
 * @author Andreas Gohr <andi@splitbrain.org>
 
459
 *
 
460
 * @param string $url
 
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
462
465
 */
463
466
function tpl_link($url, $name, $more = '', $return = false) {
464
467
    $out = '<a href="'.$url.'" ';
475
478
 * Wrapper around html_wikilink
476
479
 *
477
480
 * @author Andreas Gohr <andi@splitbrain.org>
 
481
 *
 
482
 * @param string      $id   page id
 
483
 * @param string|null $name the name of the link
 
484
 * @return bool true
478
485
 */
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
489
496
 *
490
497
 * @author Andreas Gohr <andi@splitbrain.org>
 
498
 *
 
499
 * @param string $id page id
 
500
 * @return false|string
491
501
 */
492
502
function tpl_getparent($id) {
493
503
    $parent = getNS($id).':';
506
516
 *
507
517
 * @author Adrian Lang <mail@adrianlang.de>
508
518
 * @see    tpl_get_action
 
519
 *
 
520
 * @param string $type
 
521
 * @param bool $return
 
522
 * @return bool|string html, or false if no data, true if printed
509
523
 */
510
524
function tpl_button($type, $return = false) {
511
525
    $data = tpl_get_action($type);
537
551
 *
538
552
 * @author Adrian Lang <mail@adrianlang.de>
539
553
 * @see    tpl_get_action
 
554
 *
 
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
540
561
 */
541
562
function tpl_actionlink($type, $pre = '', $suf = '', $inner = '', $return = false) {
542
563
    global $lang;
574
595
            $linktarget, $pre.(($inner) ? $inner : $caption).$suf,
575
596
            'class="action '.$type.'" '.
576
597
                $akey.$rel.
577
 
                'title="'.hsc($caption).$addTitle.'"', 1
 
598
                'title="'.hsc($caption).$addTitle.'"', true
578
599
        );
579
600
    }
580
601
    if($return) return $out;
602
623
 * @author Andreas Gohr <andi@splitbrain.org>
603
624
 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
604
625
 * @author Adrian Lang <mail@adrianlang.de>
 
626
 *
605
627
 * @param string $type
606
628
 * @return array|bool|string
607
629
 */
625
647
    $params      = array('do' => $type);
626
648
    $nofollow    = true;
627
649
    $replacement = '';
 
650
 
 
651
    $unknown = false;
628
652
    switch($type) {
629
653
        case 'edit':
630
654
            // most complicated type - we need to decide on current action
752
776
            //$type = 'media';
753
777
            break;
754
778
        default:
755
 
            return '[unknown %s type]';
756
 
            break;
757
 
    }
758
 
    return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement');
 
779
            //unknown type
 
780
            $unknown = true;
 
781
    }
 
782
 
 
783
    $data = compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement');
 
784
 
 
785
    $evt = new Doku_Event('TPL_ACTION_GET', $data);
 
786
    if($evt->advise_before()) {
 
787
        //handle unknown types
 
788
        if($unknown) {
 
789
            $data = '[unknown %s type]';
 
790
        }
 
791
    }
 
792
    $evt->advise_after();
 
793
    unset($evt);
 
794
 
 
795
    return $data;
759
796
}
760
797
 
761
798
/**
762
799
 * Wrapper around tpl_button() and tpl_actionlink()
763
800
 *
764
801
 * @author Anika Henke <anika@selfthinker.org>
765
 
 * @param
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
 
802
 *
 
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
773
811
 */
774
812
function tpl_action($type, $link = false, $wrapper = false, $return = false, $pre = '', $suf = '', $inner = '') {
775
813
    $out = '';
776
814
    if($link) {
777
 
        $out .= tpl_actionlink($type, $pre, $suf, $inner, 1);
 
815
        $out .= tpl_actionlink($type, $pre, $suf, $inner, true);
778
816
    } else {
779
 
        $out .= tpl_button($type, 1);
 
817
        $out .= tpl_button($type, true);
780
818
    }
781
819
    if($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
782
820
 
796
834
 * autocompletion feature (MSIE and Firefox)
797
835
 *
798
836
 * @author Andreas Gohr <andi@splitbrain.org>
 
837
 *
799
838
 * @param bool $ajax
800
839
 * @param bool $autocomplete
801
840
 * @return bool
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>';
820
860
    return true;
824
864
 * Print the breadcrumbs trace
825
865
 *
826
866
 * @author Andreas Gohr <andi@splitbrain.org>
 
867
 *
827
868
 * @param string $sep Separator between entries
828
869
 * @return bool
829
870
 */
839
880
    $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
840
881
 
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);
844
885
    $i    = 0;
845
886
    foreach($crumbs as $id => $name) {
865
906
 * @author Sean Coates <sean@caedmon.net>
866
907
 * @author <fredrik@averpil.com>
867
908
 * @todo   May behave strangely in RTL languages
 
909
 *
868
910
 * @param string $sep Separator between entries
869
911
 * @return bool
870
912
 */
879
921
    $parts = explode(':', $ID);
880
922
    $count = count($parts);
881
923
 
882
 
    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
 
924
    echo '<span class="bchead">'.$lang['youarehere'].' </span>';
883
925
 
884
926
    // always print the startpage
885
927
    echo '<span class="home">';
915
957
 * Could be enhanced with a profile link in future?
916
958
 *
917
959
 * @author Andreas Gohr <andi@splitbrain.org>
 
960
 *
918
961
 * @return bool
919
962
 */
920
963
function tpl_userinfo() {
923
966
    global $INPUT;
924
967
 
925
968
    if($INPUT->server->str('REMOTE_USER')) {
926
 
        print $lang['loggedinas'].': '.userlink();
 
969
        print $lang['loggedinas'].' '.userlink();
927
970
        return true;
928
971
    }
929
972
    return false;
933
976
 * Print some info about the current page
934
977
 *
935
978
 * @author Andreas Gohr <andi@splitbrain.org>
 
979
 *
936
980
 * @param bool $ret return content instead of printing it
937
981
 * @return bool|string
938
982
 */
965
1009
        $out .= '<bdi>'.$fn.'</bdi>';
966
1010
        $out .= ' · ';
967
1011
        $out .= $lang['lastmod'];
968
 
        $out .= ': ';
 
1012
        $out .= ' ';
969
1013
        $out .= $date;
970
1014
        if($INFO['editor']) {
971
1015
            $out .= ' '.$lang['by'].' ';
976
1020
        if($INFO['locked']) {
977
1021
            $out .= ' · ';
978
1022
            $out .= $lang['lockedby'];
979
 
            $out .= ': ';
 
1023
            $out .= ' ';
980
1024
            $out .= '<bdi>'.editorinfo($INFO['locked']).'</bdi>';
981
1025
        }
982
1026
        if($ret) {
996
1040
 * the given ID is used.
997
1041
 *
998
1042
 * @author Andreas Gohr <andi@splitbrain.org>
 
1043
 *
999
1044
 * @param string $id page id
1000
1045
 * @param bool   $ret return content instead of printing
1001
1046
 * @return bool|string
1002
1047
 */
1003
1048
function tpl_pagetitle($id = null, $ret = false) {
 
1049
    global $ACT, $INPUT, $conf, $lang;
 
1050
 
1004
1051
    if(is_null($id)) {
1005
1052
        global $ID;
1006
1053
        $id = $ID;
1008
1055
 
1009
1056
    $name = $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;
 
1060
    }
 
1061
 
 
1062
    // default page title is the page name, modify with the current action
 
1063
    switch ($ACT) {
 
1064
        // admin functions
 
1065
        case 'admin' :
 
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();
 
1072
            }
 
1073
            break;
 
1074
 
 
1075
        // user functions
 
1076
        case 'login' :
 
1077
        case 'profile' :
 
1078
        case 'register' :
 
1079
        case 'resendpwd' :
 
1080
            $page_title = $lang['btn_'.$ACT];
 
1081
            break;
 
1082
 
 
1083
         // wiki functions
 
1084
        case 'search' :
 
1085
        case 'index' :
 
1086
            $page_title = $lang['btn_'.$ACT];
 
1087
            break;
 
1088
 
 
1089
        // page functions
 
1090
        case 'edit' :
 
1091
            $page_title = "✎ ".$name;
 
1092
            break;
 
1093
 
 
1094
        case 'revisions' :
 
1095
            $page_title = $name . ' - ' . $lang['btn_revs'];
 
1096
            break;
 
1097
 
 
1098
        case 'backlink' :
 
1099
        case 'recent' :
 
1100
        case 'subscribe' :
 
1101
            $page_title = $name . ' - ' . $lang['btn_'.$ACT];
 
1102
            break;
 
1103
 
 
1104
        default : // SHOW and anything else not included
 
1105
            $page_title = $name;
1013
1106
    }
1014
1107
 
1015
1108
    if($ret) {
1016
 
        return hsc($name);
 
1109
        return hsc($page_title);
1017
1110
    } else {
1018
 
        print hsc($name);
 
1111
        print hsc($page_title);
1019
1112
        return true;
1020
1113
    }
1021
1114
}
1033
1126
 * Only allowed in: detail.php
1034
1127
 *
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
 
1129
 *
 
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
1040
1134
 */
1041
1135
function tpl_img_getTag($tags, $alt = '', $src = null) {
1065
1159
    echo '<dl>';
1066
1160
    foreach($tags as $tag) {
1067
1161
        $label = $lang[$tag['langkey']];
1068
 
        if(!$label) $label = $tag['langkey'];
 
1162
        if(!$label) $label = $tag['langkey'] . ':';
1069
1163
 
1070
 
        echo '<dt>'.$label.':</dt><dd>';
 
1164
        echo '<dt>'.$label.'</dt><dd>';
1071
1165
        if ($tag['type'] == 'date') {
1072
1166
            echo dformat($tag['value']);
1073
1167
        } else {
1090
1184
 
1091
1185
    $config_files = getConfigFiles('mediameta');
1092
1186
    foreach ($config_files as $config_file) {
1093
 
        if(@file_exists($config_file)) {
 
1187
        if(file_exists($config_file)) {
1094
1188
            include($config_file);
1095
1189
        }
1096
1190
    }
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
1127
1221
 */
1128
1222
function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
1129
1223
    global $IMG;
1130
1224
    /** @var Input $INPUT */
1131
1225
    global $INPUT;
 
1226
    global $REV;
1132
1227
    $w = tpl_img_getTag('File.Width');
1133
1228
    $h = tpl_img_getTag('File.Height');
1134
1229
 
1153
1248
    }
1154
1249
 
1155
1250
    //prepare URLs
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, '&');
1158
1253
 
1159
1254
    //prepare attributes
1160
1255
    $alt = tpl_img_getTag('Simple.Title');
1262
1357
    $file = tpl_incdir().'/conf/default.php';
1263
1358
    $conf = array();
1264
1359
 
1265
 
    if(!@file_exists($file)) return false;
 
1360
    if(!file_exists($file)) return false;
1266
1361
 
1267
1362
    // load default config file
1268
1363
    include($file);
1275
1370
 * tpl_getLang($id)
1276
1371
 *
1277
1372
 * use this function to access template language variables
 
1373
 *
 
1374
 * @param string $id key of language string
 
1375
 * @return string
1278
1376
 */
1279
1377
function tpl_getLang($id) {
1280
1378
    static $lang = array();
1281
1379
 
1282
1380
    if(count($lang) === 0) {
1283
 
        $path = tpl_incdir().'lang/';
 
1381
        global $conf, $config_cascade; // definitely don't invoke "global $lang"
 
1382
 
 
1383
        $path = tpl_incdir() . 'lang/';
1284
1384
 
1285
1385
        $lang = array();
1286
1386
 
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');
 
1392
            }
 
1393
        }
 
1394
 
 
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');
 
1400
                }
 
1401
            }
 
1402
        }
1291
1403
    }
1292
 
 
1293
1404
    return $lang[$id];
1294
1405
}
1295
1406
 
1306
1417
 
1307
1418
/**
1308
1419
 * Prepends appropriate path for a language dependent filename
 
1420
 *
 
1421
 * @param string $id id of localized text
 
1422
 * @return string wiki text
1309
1423
 */
1310
1424
function tpl_localeFN($id) {
1311
1425
    $path = tpl_incdir().'lang/';
1312
1426
    global $conf;
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';
1319
1433
        }
1332
1446
 *
1333
1447
 * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1334
1448
 * @param bool $fromajax - set true when calling this function via ajax
 
1449
 * @param string $sort
 
1450
 *
1335
1451
 * @author Andreas Gohr <andi@splitbrain.org>
1336
1452
 */
1337
1453
function tpl_mediaContent($fromajax = false, $sort='natural') {
1431
1547
 * @author Kate Arzamastseva <pshns@ukr.net>
1432
1548
 */
1433
1549
function tpl_mediaFileDetails($image, $rev) {
1434
 
    global $AUTH, $NS, $conf, $DEL, $lang;
 
1550
    global $conf, $DEL, $lang;
1435
1551
    /** @var Input $INPUT */
1436
1552
    global $INPUT;
1437
1553
 
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');
1443
1559
 
1444
1560
    $opened_tab = $INPUT->str('tab_details');
1474
1590
    echo '<div class="panelContent">'.NL;
1475
1591
 
1476
1592
    if($opened_tab == 'view') {
1477
 
        media_tab_view($image, $NS, $AUTH, $rev);
 
1593
        media_tab_view($image, $ns, null, $rev);
1478
1594
 
1479
1595
    } elseif($opened_tab == 'edit' && !$removed) {
1480
 
        media_tab_edit($image, $NS, $AUTH);
 
1596
        media_tab_edit($image, $ns);
1481
1597
 
1482
1598
    } elseif($opened_tab == 'history' && $conf['mediarevisions']) {
1483
 
        media_tab_history($image, $NS, $AUTH);
 
1599
        media_tab_history($image, $ns);
1484
1600
    }
1485
1601
 
1486
1602
    echo '</div>'.NL;
1506
1622
 * Note: this will not use any pretty URLs
1507
1623
 *
1508
1624
 * @author Andreas Gohr <andi@splitbrain.org>
 
1625
 *
 
1626
 * @param string $empty empty option label
 
1627
 * @param string $button submit button label
1509
1628
 */
1510
1629
function tpl_actiondropdown($empty = '', $button = '&gt;') {
1511
1630
    global $ID;
1514
1633
    /** @var Input $INPUT */
1515
1634
    global $INPUT;
1516
1635
 
 
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'),
 
1640
    );
 
1641
 
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>';
1527
1652
 
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>';
1531
 
 
1532
 
    $act = tpl_get_action('revert');
1533
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1534
 
 
1535
 
    $act = tpl_get_action('revisions');
1536
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1537
 
 
1538
 
    $act = tpl_get_action('backlink');
1539
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1540
 
 
1541
 
    $act = tpl_get_action('subscribe');
1542
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1543
 
    echo '</optgroup>';
1544
 
 
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>';
1548
 
 
1549
 
    $act = tpl_get_action('media');
1550
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1551
 
 
1552
 
    $act = tpl_get_action('index');
1553
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1554
 
    echo '</optgroup>';
1555
 
 
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>';
1559
 
 
1560
 
    $act = tpl_get_action('register');
1561
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1562
 
 
1563
 
    $act = tpl_get_action('profile');
1564
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1565
 
 
1566
 
    $act = tpl_get_action('admin');
1567
 
    if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1568
 
    echo '</optgroup>';
 
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>';
 
1658
        }
 
1659
        echo '</optgroup>';
 
1660
    }
1569
1661
 
1570
1662
    echo '</select>';
1571
 
    echo '<input type="submit" value="'.$button.'" />';
 
1663
    echo '<button type="submit">'.$button.'</button>';
1572
1664
    echo '</div>';
1573
1665
    echo '</form>';
1574
1666
}
1619
1711
 *
1620
1712
 * This function is useful to populate sidebars or similar features in a
1621
1713
 * template
 
1714
 *
 
1715
 * @param string $pageid
 
1716
 * @param bool $print
 
1717
 * @param bool $propagate
 
1718
 * @return bool|null|string
1622
1719
 */
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
1729
1826
 *
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
 
1831
 *
1734
1832
 * @author Andreas  Gohr <andi@splitbrain.org>
1735
1833
 */
1736
1834
function tpl_getMediaFile($search, $abs = false, &$imginfo = null) {
1781
1879
 *
1782
1880
 * @author Anika Henke <anika@selfthinker.org>
1783
1881
 * @author Andreas Gohr <andi@splitbrain.org>
 
1882
 *
 
1883
 * @param string $file
1784
1884
 */
1785
1885
function tpl_includeFile($file) {
1786
1886
    global $config_cascade;
1806
1906
 * Returns <link> tag for various icon types (favicon|mobile|generic)
1807
1907
 *
1808
1908
 * @author Anika Henke <anika@selfthinker.org>
 
1909
 *
1809
1910
 * @param  array $types - list of icon types to display (favicon|mobile|generic)
1810
1911
 * @return string
1811
1912
 */
1881
1982
 * Return useful layout classes
1882
1983
 *
1883
1984
 * @author Anika Henke <anika@selfthinker.org>
 
1985
 *
 
1986
 * @return string
1884
1987
 */
1885
1988
function tpl_classes() {
1886
1989
    global $ACT, $conf, $ID, $INFO;
1898
2001
    return join(' ', $classes);
1899
2002
}
1900
2003
 
 
2004
/**
 
2005
 * Create event for tools menues
 
2006
 *
 
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', ...
 
2011
 */
 
2012
function tpl_toolsevent($toolsname, $items, $view = 'main') {
 
2013
    $data = array(
 
2014
        'view' => $view,
 
2015
        'items' => $items
 
2016
    );
 
2017
 
 
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;
 
2022
    }
 
2023
    $evt->advise_after();
 
2024
}
 
2025
 
1901
2026
//Setup VIM: ex: et ts=4 :
1902
2027