xref: /dokuwiki/inc/template.php (revision 8d40b4b6e74029367996c169aa3e67507a4cdfe1)
16b13307fSandi<?php
26b13307fSandi/**
36b13307fSandi * DokuWiki template functions
46b13307fSandi *
56b13307fSandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b13307fSandi * @author     Andreas Gohr <andi@splitbrain.org>
76b13307fSandi */
86b13307fSandi
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
106b13307fSandi
116b13307fSandi/**
125a892029SAndreas Gohr * Returns the path to the given template, uses
13524be65dSBen Coburn * default one if the custom version doesn't exist.
145a892029SAndreas Gohr *
155a892029SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
165a892029SAndreas Gohr */
175a892029SAndreas Gohrfunction template($tpl){
185a892029SAndreas Gohr    global $conf;
195a892029SAndreas Gohr
205a892029SAndreas Gohr    if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
215a892029SAndreas Gohr        return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
225a892029SAndreas Gohr
235a892029SAndreas Gohr    return DOKU_INC.'lib/tpl/default/'.$tpl;
245a892029SAndreas Gohr}
255a892029SAndreas Gohr
265a892029SAndreas Gohr/**
276b13307fSandi * Print the content
286b13307fSandi *
296b13307fSandi * This function is used for printing all the usual content
306b13307fSandi * (defined by the global $ACT var) by calling the appropriate
316b13307fSandi * outputfunction(s) from html.php
326b13307fSandi *
33ee4c4a1bSAndreas Gohr * Everything that doesn't use the main template file isn't
34ee4c4a1bSAndreas Gohr * handled by this function. ACL stuff is not done here either.
356b13307fSandi *
366b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
376b13307fSandi */
38b8595a66SAndreas Gohrfunction tpl_content($prependTOC=true) {
397ea0913cSchris    global $ACT;
40b8595a66SAndreas Gohr    global $INFO;
41b8595a66SAndreas Gohr    $INFO['prependTOC'] = $prependTOC;
427ea0913cSchris
437ea0913cSchris    ob_start();
44746855cfSBen Coburn    trigger_event('TPL_ACT_RENDER',$ACT,'tpl_content_core');
457ea0913cSchris    $html_output = ob_get_clean();
46746855cfSBen Coburn    trigger_event('TPL_CONTENT_DISPLAY',$html_output,'ptln');
4754e95700STom N Harris
4854e95700STom N Harris    return !empty($html_output);
497ea0913cSchris}
507ea0913cSchris
517ea0913cSchrisfunction tpl_content_core(){
526b13307fSandi    global $ACT;
536b13307fSandi    global $TEXT;
546b13307fSandi    global $PRE;
556b13307fSandi    global $SUF;
566b13307fSandi    global $SUM;
576b13307fSandi    global $IDX;
586b13307fSandi
596b13307fSandi    switch($ACT){
606b13307fSandi        case 'show':
616b13307fSandi            html_show();
626b13307fSandi            break;
6345a99335SAdrian Lang        case 'locked':
6445a99335SAdrian Lang            html_locked();
656b13307fSandi        case 'edit':
6645a99335SAdrian Lang        case 'recover':
676b13307fSandi            html_edit();
686b13307fSandi            break;
6945a99335SAdrian Lang        case 'preview':
7045a99335SAdrian Lang            html_edit();
7145a99335SAdrian Lang            html_show($TEXT);
7245a99335SAdrian Lang            break;
73ee4c4a1bSAndreas Gohr        case 'draft':
74ee4c4a1bSAndreas Gohr            html_draft();
75ee4c4a1bSAndreas Gohr            break;
766b13307fSandi        case 'search':
776b13307fSandi            html_search();
786b13307fSandi            break;
796b13307fSandi        case 'revisions':
80c66972f2SAdrian Lang            $first = isset($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
8171726d78SBen Coburn            html_revisions($first);
826b13307fSandi            break;
836b13307fSandi        case 'diff':
846b13307fSandi            html_diff();
856b13307fSandi            break;
866b13307fSandi        case 'recent':
87abdcc39fSmichael            if (is_array($_REQUEST['first'])) {
88abdcc39fSmichael                $_REQUEST['first'] = array_keys($_REQUEST['first']);
89abdcc39fSmichael                $_REQUEST['first'] = $_REQUEST['first'][0];
90abdcc39fSmichael            }
915749f1ceSmatthiasgrimm            $first = is_numeric($_REQUEST['first']) ? intval($_REQUEST['first']) : 0;
92*8d40b4b6SKate Arzamastseva            $show_changes = $_REQUEST['show_changes'];
93*8d40b4b6SKate Arzamastseva            html_recent($first, $show_changes);
946b13307fSandi            break;
956b13307fSandi        case 'index':
966b13307fSandi            html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
976b13307fSandi            break;
986b13307fSandi        case 'backlink':
996b13307fSandi            html_backlinks();
1006b13307fSandi            break;
1016b13307fSandi        case 'conflict':
1026b13307fSandi            html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1036b13307fSandi            html_diff(con($PRE,$TEXT,$SUF),false);
1046b13307fSandi            break;
1056b13307fSandi        case 'login':
1066b13307fSandi            html_login();
1076b13307fSandi            break;
1086b13307fSandi        case 'register':
1096b13307fSandi            html_register();
1106b13307fSandi            break;
1118b06d178Schris        case 'resendpwd':
1128b06d178Schris            html_resendpwd();
1138b06d178Schris            break;
114820fa24bSandi        case 'denied':
1155e991bd8Sandi            print p_locale_xhtml('denied');
116820fa24bSandi            break;
1178b06d178Schris        case 'profile' :
1188b06d178Schris            html_updateprofile();
1198b06d178Schris            break;
120c19fe9c0Sandi        case 'admin':
121c19fe9c0Sandi            tpl_admin();
122c19fe9c0Sandi            break;
1235b75cd1fSAdrian Lang        case 'subscribe':
1245b75cd1fSAdrian Lang            tpl_subscribe();
1255b75cd1fSAdrian Lang            break;
1266b13307fSandi        default:
12724bb549bSchris            $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12824bb549bSchris            if ($evt->advise_before())
129ea67f144Sandi                msg("Failed to handle command: ".hsc($ACT),-1);
13024bb549bSchris            $evt->advise_after();
13124bb549bSchris            unset($evt);
13254e95700STom N Harris            return false;
1336b13307fSandi    }
13454e95700STom N Harris    return true;
1356b13307fSandi}
1366b13307fSandi
137c19fe9c0Sandi/**
138b8595a66SAndreas Gohr * Places the TOC where the function is called
139b8595a66SAndreas Gohr *
140b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
141b8595a66SAndreas Gohr * a false argument
142b8595a66SAndreas Gohr *
143b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
144b8595a66SAndreas Gohr */
145b8595a66SAndreas Gohrfunction tpl_toc($return=false){
146b8595a66SAndreas Gohr    global $TOC;
147b8595a66SAndreas Gohr    global $ACT;
148b8595a66SAndreas Gohr    global $ID;
149b8595a66SAndreas Gohr    global $REV;
150b8595a66SAndreas Gohr    global $INFO;
151851f2e89SAnika Henke    global $conf;
152b8595a66SAndreas Gohr    $toc = array();
153b8595a66SAndreas Gohr
154b8595a66SAndreas Gohr    if(is_array($TOC)){
155b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
156b8595a66SAndreas Gohr        $toc = $TOC;
1573c86d7c9SAndreas Gohr    }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){
158b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
15965aa8490SMichael Hamann        $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE);
160b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])){
161b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
162b8595a66SAndreas Gohr        }else{
1632bb0d541Schris            $tocok = true;
164b8595a66SAndreas Gohr        }
165b8595a66SAndreas Gohr        $toc   = $meta['description']['tableofcontents'];
166851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){
167b8595a66SAndreas Gohr            $toc = array();
168b8595a66SAndreas Gohr        }
169b8595a66SAndreas Gohr    }elseif($ACT == 'admin'){
170b8595a66SAndreas Gohr        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
171b8595a66SAndreas Gohr        $plugin = null;
172b8595a66SAndreas Gohr        if (!empty($_REQUEST['page'])) {
173b8595a66SAndreas Gohr            $pluginlist = plugin_list('admin');
174b8595a66SAndreas Gohr            if (in_array($_REQUEST['page'], $pluginlist)) {
175b8595a66SAndreas Gohr                // attempt to load the plugin
176b8595a66SAndreas Gohr                $plugin =& plugin_load('admin',$_REQUEST['page']);
177b8595a66SAndreas Gohr            }
178b8595a66SAndreas Gohr        }
179b8595a66SAndreas Gohr        if ( ($plugin !== null) &&
180b8595a66SAndreas Gohr                (!$plugin->forAdminOnly() || $INFO['isadmin']) ){
181b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
182b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
183b8595a66SAndreas Gohr        }
184b8595a66SAndreas Gohr    }
185b8595a66SAndreas Gohr
1860b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
187b8595a66SAndreas Gohr    $html = html_TOC($toc);
188b8595a66SAndreas Gohr    if($return) return $html;
189b8595a66SAndreas Gohr    echo $html;
190b8595a66SAndreas Gohr}
191b8595a66SAndreas Gohr
192b8595a66SAndreas Gohr/**
193c19fe9c0Sandi * Handle the admin page contents
194c19fe9c0Sandi *
195c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
196c19fe9c0Sandi */
197c19fe9c0Sandifunction tpl_admin(){
198f8cc712eSAndreas Gohr    global $INFO;
199b8595a66SAndreas Gohr    global $TOC;
20011e2ce22Schris
201b8595a66SAndreas Gohr    $plugin = null;
202bb4866bdSchris    if (!empty($_REQUEST['page'])) {
20311e2ce22Schris        $pluginlist = plugin_list('admin');
20411e2ce22Schris
20511e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
20611e2ce22Schris
20711e2ce22Schris            // attempt to load the plugin
20811e2ce22Schris            $plugin =& plugin_load('admin',$_REQUEST['page']);
20911e2ce22Schris        }
21011e2ce22Schris    }
21111e2ce22Schris
212b8595a66SAndreas Gohr    if ($plugin !== null){
213b8595a66SAndreas Gohr        if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
214b8595a66SAndreas Gohr        if($INFO['prependTOC']) tpl_toc();
215f8cc712eSAndreas Gohr        $plugin->html();
216f8cc712eSAndreas Gohr    }else{
217f8cc712eSAndreas Gohr        html_admin();
218f8cc712eSAndreas Gohr    }
21954e95700STom N Harris    return true;
220c19fe9c0Sandi}
2216b13307fSandi
2226b13307fSandi/**
2236b13307fSandi * Print the correct HTML meta headers
2246b13307fSandi *
2256b13307fSandi * This has to go into the head section of your template.
2266b13307fSandi *
227016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
228f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
2296b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2306b13307fSandi */
231f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
2326b13307fSandi    global $ID;
233d98d4540SBen Coburn    global $REV;
2346b13307fSandi    global $INFO;
23572e0dc37SAndreas Gohr    global $JSINFO;
2366b13307fSandi    global $ACT;
2374bb1b5aeSAndreas Gohr    global $QUERY;
2386b13307fSandi    global $lang;
239dc57ef04Sandi    global $conf;
2406b13307fSandi    $it=2;
2416b13307fSandi
2427bff22c0SAndreas Gohr    // prepare the head array
2437bff22c0SAndreas Gohr    $head = array();
2447bff22c0SAndreas Gohr
245202ac28bSMichael Klier    // prepare seed for js and css
246202ac28bSMichael Klier    $tseed = 0;
247202ac28bSMichael Klier    $depends = getConfigFiles('main');
248202ac28bSMichael Klier    foreach($depends as $f) {
249202ac28bSMichael Klier        $time = @filemtime($f);
250202ac28bSMichael Klier        if($time > $tseed) $tseed = $time;
251202ac28bSMichael Klier    }
2527bff22c0SAndreas Gohr
2536b13307fSandi    // the usual stuff
2543f803e5eSGina Haeussge    $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki');
255da96af35SAndreas Gohr    $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
256da96af35SAndreas Gohr            'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
257f4f47358SBen Coburn    $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
2587aedde2eSGina Haeussge    if(actionOK('index')){
2597bff22c0SAndreas Gohr        $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
260bb4866bdSchris                'title'=>$lang['btn_index'] );
2617aedde2eSGina Haeussge    }
262f96fa415SAndreas Gohr
263f96fa415SAndreas Gohr    if($alt){
2647bff22c0SAndreas Gohr        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2657bff22c0SAndreas Gohr                'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2667bff22c0SAndreas Gohr        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2677bff22c0SAndreas Gohr                'title'=>'Current Namespace',
2687bff22c0SAndreas Gohr                'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
269c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){
270a2c734d5SAndreas Gohr            $head['link'][] = array( 'rel'=>'edit',
271715bdf1fSAndreas Gohr                    'title'=>$lang['btn_edit'],
272c35f3875SAndreas Gohr                    'href'=> wl($ID,'do=edit',false,'&'));
273c35f3875SAndreas Gohr        }
274c35f3875SAndreas Gohr
2754bb1b5aeSAndreas Gohr        if($ACT == 'search'){
2764bb1b5aeSAndreas Gohr            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2774bb1b5aeSAndreas Gohr                    'title'=>'Search Result',
2784bb1b5aeSAndreas Gohr                    'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
2794bb1b5aeSAndreas Gohr        }
280bae36d94SAndreas Gohr
281bae36d94SAndreas Gohr        if(actionOK('export_xhtml')){
2827bff22c0SAndreas Gohr            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2837bff22c0SAndreas Gohr                    'href'=>exportlink($ID, 'xhtml', '', false, '&'));
284bae36d94SAndreas Gohr        }
285bae36d94SAndreas Gohr
286bae36d94SAndreas Gohr        if(actionOK('export_raw')){
2877bff22c0SAndreas Gohr            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2887bff22c0SAndreas Gohr                    'href'=>exportlink($ID, 'raw', '', false, '&'));
289f96fa415SAndreas Gohr        }
290bae36d94SAndreas Gohr    }
2916b13307fSandi
2926b13307fSandi    // setup robot tags apropriate for different modes
2934f2e0004STim Weber    if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2946b13307fSandi        if($INFO['exists']){
2956b13307fSandi            //delay indexing:
2966b13307fSandi            if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
2977bff22c0SAndreas Gohr                $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
2986b13307fSandi            }else{
2997bff22c0SAndreas Gohr                $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3006b13307fSandi            }
30169db0cafSAndreas Gohr            $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') );
3026b13307fSandi        }else{
3037bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
3046b13307fSandi        }
3057a24876fSAndreas Gohr    }elseif(defined('DOKU_MEDIADETAIL')){
3067bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
3076b13307fSandi    }else{
3087bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3096b13307fSandi    }
3106b13307fSandi
311831800b8SAndreas Gohr    // set metadata
312831800b8SAndreas Gohr    if($ACT == 'show' || $ACT=='export_xhtml'){
313831800b8SAndreas Gohr        // date of modification
314831800b8SAndreas Gohr        if($REV){
3157bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
316831800b8SAndreas Gohr        }else{
3177bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
318831800b8SAndreas Gohr        }
319831800b8SAndreas Gohr
320831800b8SAndreas Gohr        // keywords (explicit or implicit)
321bb4866bdSchris        if(!empty($INFO['meta']['subject'])){
3227bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
323831800b8SAndreas Gohr        }else{
3247bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
325831800b8SAndreas Gohr        }
326831800b8SAndreas Gohr    }
327831800b8SAndreas Gohr
32878a6aeb1SAndreas Gohr    // load stylesheets
3297bff22c0SAndreas Gohr    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
330202ac28bSMichael Klier            'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed);
331d61e1b3eSMike Frysinger    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
332d61e1b3eSMike Frysinger            'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template'].'&tseed='.$tseed);
3337bff22c0SAndreas Gohr    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
334202ac28bSMichael Klier            'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template'].'&tseed='.$tseed);
335bad31ae9SAndreas Gohr
3368bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
337463d4a65SAndreas Gohr    $json = new JSON();
33872e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
339c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
34072e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
341c591aabeSAndreas Gohr    }
34272e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
34385f81679SAdrian Lang    $head['script'][] = array( 'type'=>'text/javascript', '_data'=> $script);
3448bbcb611SAndreas Gohr
3458bbcb611SAndreas Gohr    // load external javascript
3467bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
347202ac28bSMichael Klier            'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed);
3487bff22c0SAndreas Gohr
3497bff22c0SAndreas Gohr    // trigger event here
350016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
35154e95700STom N Harris    return true;
3527bff22c0SAndreas Gohr}
3537bff22c0SAndreas Gohr
3547bff22c0SAndreas Gohr/**
3557bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3567bff22c0SAndreas Gohr *
3577bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3587bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3597bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3607bff22c0SAndreas Gohr *
3617bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
3621304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3637bff22c0SAndreas Gohr *
3647bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3657bff22c0SAndreas Gohr */
3667bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3677bff22c0SAndreas Gohr    foreach($data as $tag => $inst){
3687bff22c0SAndreas Gohr        foreach($inst as $attr){
3697bff22c0SAndreas Gohr            echo '<',$tag,' ',buildAttributes($attr);
37026afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script'){
371e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
372e226efe1SAndreas Gohr                    $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
373e226efe1SAndreas Gohr                        $attr['_data'].
374e226efe1SAndreas Gohr                        "\n//--><!]]>";
375e226efe1SAndreas Gohr
3761304d1dbSAndreas Gohr                echo '>',$attr['_data'],'</',$tag,'>';
3777bff22c0SAndreas Gohr            }else{
3787bff22c0SAndreas Gohr                echo '/>';
3797bff22c0SAndreas Gohr            }
3807bff22c0SAndreas Gohr            echo "\n";
3817bff22c0SAndreas Gohr        }
3827bff22c0SAndreas Gohr    }
3836b13307fSandi}
3846b13307fSandi
3856b13307fSandi/**
3866b13307fSandi * Print a link
3876b13307fSandi *
3885e163278SAndreas Gohr * Just builds a link.
3896b13307fSandi *
3906b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3916b13307fSandi */
3921af98a77SAnika Henkefunction tpl_link($url,$name,$more='',$return=false){
39301f17825SAnika Henke    $out = '<a href="'.$url.'" ';
3941af98a77SAnika Henke    if ($more) $out .= ' '.$more;
3951af98a77SAnika Henke    $out .= ">$name</a>";
3961af98a77SAnika Henke    if ($return) return $out;
3971af98a77SAnika Henke    print $out;
39854e95700STom N Harris    return true;
3996b13307fSandi}
4006b13307fSandi
4016b13307fSandi/**
40255efc227SAndreas Gohr * Prints a link to a WikiPage
40355efc227SAndreas Gohr *
40455efc227SAndreas Gohr * Wrapper around html_wikilink
40555efc227SAndreas Gohr *
40655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
40755efc227SAndreas Gohr */
4080b17fdc6SAndreas Gohrfunction tpl_pagelink($id,$name=null){
40955efc227SAndreas Gohr    print html_wikilink($id,$name);
41054e95700STom N Harris    return true;
41155efc227SAndreas Gohr}
41255efc227SAndreas Gohr
41355efc227SAndreas Gohr/**
414a3ec5f4aSmatthiasgrimm * get the parent page
415a3ec5f4aSmatthiasgrimm *
416a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
417a3ec5f4aSmatthiasgrimm * returns false if none is available
418a3ec5f4aSmatthiasgrimm *
419377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
420a3ec5f4aSmatthiasgrimm */
421377f9e97SAndreas Gohrfunction tpl_getparent($id){
422a3ec5f4aSmatthiasgrimm    global $conf;
423377f9e97SAndreas Gohr    $parent = getNS($id).':';
424377f9e97SAndreas Gohr    resolve_pageid('',$parent,$exists);
425a197105eSmatthiasgrimm    if($parent == $id) {
426a197105eSmatthiasgrimm        $pos = strrpos (getNS($id),':');
427a197105eSmatthiasgrimm        $parent = substr($parent,0,$pos).':';
428a197105eSmatthiasgrimm        resolve_pageid('',$parent,$exists);
429377f9e97SAndreas Gohr        if($parent == $id) return false;
430a197105eSmatthiasgrimm    }
431377f9e97SAndreas Gohr    return $parent;
432a3ec5f4aSmatthiasgrimm}
433a3ec5f4aSmatthiasgrimm
434a3ec5f4aSmatthiasgrimm/**
4356b13307fSandi * Print one of the buttons
4366b13307fSandi *
437a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
438a453d131SAdrian Lang * @see    tpl_get_action
4396b13307fSandi */
4401af98a77SAnika Henkefunction tpl_button($type,$return=false){
441a453d131SAdrian Lang    $data = tpl_get_action($type);
442a453d131SAdrian Lang    if ($data === false) {
443a453d131SAdrian Lang        return false;
444a453d131SAdrian Lang    } elseif (!is_array($data)) {
445a453d131SAdrian Lang        $out = sprintf($data, 'button');
446409d7af7SAndreas Gohr    } else {
447a453d131SAdrian Lang        extract($data);
448a453d131SAdrian Lang        if ($id === '#dokuwiki__top') {
449a453d131SAdrian Lang            $out = html_topbtn();
450409d7af7SAndreas Gohr        } else {
451a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
452409d7af7SAndreas Gohr        }
453409d7af7SAndreas Gohr    }
4541af98a77SAnika Henke    if ($return) return $out;
455a453d131SAdrian Lang    echo $out;
456a453d131SAdrian Lang    return true;
4576b13307fSandi}
4586b13307fSandi
4596b13307fSandi/**
460ed630903Sandi * Like the action buttons but links
461ed630903Sandi *
462a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
463a453d131SAdrian Lang * @see    tpl_get_action
464a453d131SAdrian Lang */
465a453d131SAdrian Langfunction tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
466a453d131SAdrian Lang    global $lang;
467a453d131SAdrian Lang    $data = tpl_get_action($type);
468a453d131SAdrian Lang    if ($data === false) {
469a453d131SAdrian Lang        return false;
470a453d131SAdrian Lang    } elseif (!is_array($data)) {
471a453d131SAdrian Lang        $out = sprintf($data, 'link');
472a453d131SAdrian Lang    } else {
473a453d131SAdrian Lang        extract($data);
474a453d131SAdrian Lang        if (strpos($id, '#') === 0) {
475a453d131SAdrian Lang            $linktarget = $id;
476a453d131SAdrian Lang        } else {
477a453d131SAdrian Lang            $linktarget = wl($id, $params);
478a453d131SAdrian Lang        }
479a453d131SAdrian Lang        $caption = $lang['btn_' . $type];
480a453d131SAdrian Lang        $out = tpl_link($linktarget, $pre.(($inner)?$inner:$caption).$suf,
481a453d131SAdrian Lang                        'class="action ' . $type . '" ' .
482a453d131SAdrian Lang                        'accesskey="' . $accesskey . '" rel="nofollow" ' .
483a453d131SAdrian Lang                        'title="' . hsc($caption) . '"', 1);
484a453d131SAdrian Lang    }
485a453d131SAdrian Lang    if ($return) return $out;
486a453d131SAdrian Lang    echo $out;
487a453d131SAdrian Lang    return true;
488a453d131SAdrian Lang}
489a453d131SAdrian Lang
490a453d131SAdrian Lang/**
491a453d131SAdrian Lang * Check the actions and get data for buttons and links
492ed630903Sandi *
493a453d131SAdrian Lang * Available actions are
494a453d131SAdrian Lang *
495a453d131SAdrian Lang *  edit        - edit/create/show/draft
496ed630903Sandi *  history     - old revisions
497ed630903Sandi *  recent      - recent changes
498a453d131SAdrian Lang *  login       - login/logout - if ACL enabled
499a453d131SAdrian Lang *  profile     - user profile (if logged in)
500ed630903Sandi *  index       - The index
501ed630903Sandi *  admin       - admin page - if enough rights
502a453d131SAdrian Lang *  top         - back to top
503a453d131SAdrian Lang *  back        - back to parent - if available
504bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
505a453d131SAdrian Lang *  subscribe/subscription- subscribe/unsubscribe
506ed630903Sandi *
507ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
508a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
509a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
510ed630903Sandi */
511a453d131SAdrian Langfunction tpl_get_action($type) {
512ed630903Sandi    global $ID;
513ed630903Sandi    global $INFO;
514ed630903Sandi    global $REV;
515ed630903Sandi    global $ACT;
516ed630903Sandi    global $conf;
517cd52f92dSchris    global $auth;
518ed630903Sandi
51975e487e9SAndreas Gohr    // check disabled actions and fix the badly named ones
520a453d131SAdrian Lang    if($type == 'history') $type='revisions';
521a453d131SAdrian Lang    if(!actionOK($type)) return false;
522409d7af7SAndreas Gohr
523a453d131SAdrian Lang    $accesskey = null;
5246709e843SAdrian Lang    $id        = $ID;
525a453d131SAdrian Lang    $method    = 'get';
526a453d131SAdrian Lang    $params    = array('do' => $type);
527ed630903Sandi    switch($type){
528ed630903Sandi        case 'edit':
5290b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
530ed630903Sandi            if($ACT == 'show' || $ACT == 'search'){
531a453d131SAdrian Lang                $method = 'post';
532ed630903Sandi                if($INFO['writable']){
533a453d131SAdrian Lang                    $accesskey = 'e';
534b8a111f5SMichael Klier                    if(!empty($INFO['draft'])) {
5356709e843SAdrian Lang                        $type = 'draft';
536a453d131SAdrian Lang                        $params['do'] = 'draft';
537b8a111f5SMichael Klier                    } else {
538a453d131SAdrian Lang                        $params['rev'] = $REV;
539a453d131SAdrian Lang                        if(!$INFO['exists']){
5406709e843SAdrian Lang                            $type   = 'create';
541ed630903Sandi                        }
542b8a111f5SMichael Klier                    }
543ed630903Sandi                }else{
544a453d131SAdrian Lang                    if(!actionOK('source')) return false; //pseudo action
545a453d131SAdrian Lang                    $params['rev'] = $REV;
5466709e843SAdrian Lang                    $type = 'source';
547a453d131SAdrian Lang                    $accesskey = 'v';
548ed630903Sandi                }
549ed630903Sandi            }else{
550a453d131SAdrian Lang                $params = '';
5516709e843SAdrian Lang                $type = 'show';
552a453d131SAdrian Lang                $accesskey = 'v';
553ed630903Sandi            }
5541af98a77SAnika Henke            break;
555a453d131SAdrian Lang        case 'revisions':
5566709e843SAdrian Lang            $type = 'revs';
557a453d131SAdrian Lang            $accesskey = 'o';
5581af98a77SAnika Henke            break;
559ed630903Sandi        case 'recent':
560a453d131SAdrian Lang            $accesskey = 'r';
5611af98a77SAnika Henke            break;
562ed630903Sandi        case 'index':
563a453d131SAdrian Lang            $accesskey = 'x';
5641af98a77SAnika Henke            break;
565ed630903Sandi        case 'top':
566a453d131SAdrian Lang            $accesskey = 'x';
567a453d131SAdrian Lang            $params = '';
568a453d131SAdrian Lang            $id = '#dokuwiki__top';
5691af98a77SAnika Henke            break;
570a3ec5f4aSmatthiasgrimm        case 'back':
571a453d131SAdrian Lang            $parent = tpl_getparent($ID);
572a453d131SAdrian Lang            if (!$parent) {
573a453d131SAdrian Lang                return false;
574a3ec5f4aSmatthiasgrimm            }
575a453d131SAdrian Lang            $id = $parent;
576a453d131SAdrian Lang            $params = '';
577a453d131SAdrian Lang            $accesskey = 'b';
5781af98a77SAnika Henke            break;
579ed630903Sandi        case 'login':
580a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
5812380e8a8SAdrian Lang            if(isset($_SERVER['REMOTE_USER'])){
5823a48618aSAnika Henke                if (!actionOK('logout')) {
5832380e8a8SAdrian Lang                    return false;
5842380e8a8SAdrian Lang                }
585a453d131SAdrian Lang                $params['do'] = 'logout';
586a453d131SAdrian Lang                $type = 'logout';
587bf413a4eSAnika Henke            }
588bf413a4eSAnika Henke            break;
589bf413a4eSAnika Henke        case 'register':
590bf413a4eSAnika Henke            if($_SERVER['REMOTE_USER']){
591bf413a4eSAnika Henke                return false;
592bf413a4eSAnika Henke            }
593bf413a4eSAnika Henke            break;
594bf413a4eSAnika Henke        case 'resendpwd':
595bf413a4eSAnika Henke            if($_SERVER['REMOTE_USER']){
596bf413a4eSAnika Henke                return false;
597ed630903Sandi            }
5981af98a77SAnika Henke            break;
599ed630903Sandi        case 'admin':
600a453d131SAdrian Lang            if(!$INFO['ismanager']){
601a453d131SAdrian Lang                return false;
602c059e1a6SAndreas Gohr            }
6031af98a77SAnika Henke            break;
6041246e016SAndreas Gohr        case 'revert':
605a453d131SAdrian Lang            if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
606a453d131SAdrian Lang                return false;
6071246e016SAndreas Gohr            }
608a453d131SAdrian Lang            $params['rev'] = $REV;
609a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
6101246e016SAndreas Gohr            break;
611075f000fSChristopher Arndt        case 'subscription':
6126709e843SAdrian Lang            $type = 'subscribe';
613a453d131SAdrian Lang            $params['do'] = 'subscribe';
6146709e843SAdrian Lang        case 'subscribe':
6153a48618aSAnika Henke            if(!$_SERVER['REMOTE_USER']){
616a453d131SAdrian Lang                return false;
617b158d625SSteven Danz            }
6181af98a77SAnika Henke            break;
619f00151b4Schris        case 'backlink':
6201af98a77SAnika Henke            break;
6218b06d178Schris        case 'profile':
6223a48618aSAnika Henke            if(!isset($_SERVER['REMOTE_USER'])){
623a453d131SAdrian Lang                return false;
6248b06d178Schris            }
6251af98a77SAnika Henke            break;
62685dd53ceSAdrian Lang        case 'subscribens':
6273a48618aSAnika Henke            // Superseded by subscribe/subscription
62885dd53ceSAdrian Lang            return '';
62985dd53ceSAdrian Lang            break;
630ed630903Sandi        default:
631a453d131SAdrian Lang            return '[unknown %s type]';
6321af98a77SAnika Henke            break;
633ed630903Sandi    }
634a453d131SAdrian Lang    return compact('accesskey', 'type', 'id', 'method', 'params');
635ed630903Sandi}
636ed630903Sandi
637ed630903Sandi/**
63801f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
63901f17825SAnika Henke *
64001f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
64101f17825SAnika Henke */
64201f17825SAnika Henkefunction tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') {
64301f17825SAnika Henke    $out = '';
64401f17825SAnika Henke    if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1);
64501f17825SAnika Henke    else $out .= tpl_button($type,1);
64601f17825SAnika Henke    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
64701f17825SAnika Henke
64801f17825SAnika Henke    if ($return) return $out;
64901f17825SAnika Henke    print $out;
65001f17825SAnika Henke    return $out ? true : false;
65101f17825SAnika Henke}
65201f17825SAnika Henke
65301f17825SAnika Henke/**
6546b13307fSandi * Print the search form
6556b13307fSandi *
65672645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
65772645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
65872645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
65972645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
66072645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
66172645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
66272645b75SAndreas Gohr *
6636b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6646b13307fSandi */
66572645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6666b13307fSandi    global $lang;
667c1e3b7d9Smatthiasgrimm    global $ACT;
668ad4aaef7SAndreas Gohr    global $QUERY;
669c1e3b7d9Smatthiasgrimm
670670ff54eSchris    // don't print the search form if search action has been disabled
67154e95700STom N Harris    if (!actionOk('search')) return false;
672670ff54eSchris
673156dbd62SGina Haeussge    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search" method="get"><div class="no">';
6746b13307fSandi    print '<input type="hidden" name="do" value="search" />';
675c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
676ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
67772645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
67807493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
67911ea018fSAndreas Gohr    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
68024a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6814beabca9SAnika Henke    print '</div></form>';
68254e95700STom N Harris    return true;
6836b13307fSandi}
6846b13307fSandi
6856b13307fSandi/**
6866b13307fSandi * Print the breadcrumbs trace
6876b13307fSandi *
6886b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6896b13307fSandi */
6907ec56993SAndreas Gohrfunction tpl_breadcrumbs($sep='&bull;'){
6916b13307fSandi    global $lang;
6926b13307fSandi    global $conf;
6936b13307fSandi
6946b13307fSandi    //check if enabled
695359fab8bSMichael Hamann    if(!$conf['breadcrumbs']) return false;
6966b13307fSandi
6976b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
698265e3787Sandi
6992979a10bSKatriel Traum    //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
7002979a10bSKatriel Traum    if($lang['direction'] == 'rtl') {
7012979a10bSKatriel Traum        $crumbs = array_reverse($crumbs,true);
7022979a10bSKatriel Traum        $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
7032979a10bSKatriel Traum    } else {
7042979a10bSKatriel Traum        $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
7052979a10bSKatriel Traum    }
706265e3787Sandi
70740eb54bbSjan    //render crumbs, highlight the last one
7081b6f3a44SAndreas Gohr    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
70940eb54bbSjan    $last = count($crumbs);
71040eb54bbSjan    $i = 0;
711a77f5846Sjan    foreach ($crumbs as $id => $name){
71240eb54bbSjan        $i++;
7132979a10bSKatriel Traum        echo $crumbs_sep;
71492795d04Sandi        if ($i == $last) print '<span class="curid">';
715e26fd1eeSAndreas Gohr        tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
71692795d04Sandi        if ($i == $last) print '</span>';
7176b13307fSandi    }
71854e95700STom N Harris    return true;
7196b13307fSandi}
7206b13307fSandi
7216b13307fSandi/**
7221734437eSandi * Hierarchical breadcrumbs
7231734437eSandi *
72431e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7251734437eSandi * It only makes sense with a deep site structure.
7261734437eSandi *
7271734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7286bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
72931e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
730f46c9e83SAnika Henke * @author <fredrik@averpil.com>
7316bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
7321734437eSandi */
733796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
7341734437eSandi    global $conf;
7351734437eSandi    global $ID;
7361734437eSandi    global $lang;
7371734437eSandi
73831e187f8SSean Coates    // check if enabled
73954e95700STom N Harris    if(!$conf['youarehere']) return false;
7401734437eSandi
7411734437eSandi    $parts = explode(':', $ID);
742796bafb3SAndreas Gohr    $count = count($parts);
7431734437eSandi
7441b6f3a44SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
7451734437eSandi
7461734437eSandi    // always print the startpage
747e013f48dSAnika Henke    tpl_pagelink(':'.$conf['start']);
748796bafb3SAndreas Gohr
749796bafb3SAndreas Gohr    // print intermediate namespace links
750796bafb3SAndreas Gohr    $part = '';
751796bafb3SAndreas Gohr    for($i=0; $i<$count - 1; $i++){
752796bafb3SAndreas Gohr        $part .= $parts[$i].':';
753796bafb3SAndreas Gohr        $page = $part;
754796bafb3SAndreas Gohr        if ($page == $conf['start']) continue; // Skip startpage
755796bafb3SAndreas Gohr
756796bafb3SAndreas Gohr        // output
757796bafb3SAndreas Gohr        echo $sep;
758e013f48dSAnika Henke        tpl_pagelink($page);
75931e187f8SSean Coates    }
7601734437eSandi
761796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
762e013f48dSAnika Henke    resolve_pageid('',$page,$exists);
763d98d4540SBen Coburn    if(isset($page) && $page==$part.$parts[$i]) return;
764796bafb3SAndreas Gohr    $page = $part.$parts[$i];
765796bafb3SAndreas Gohr    if($page == $conf['start']) return;
766796bafb3SAndreas Gohr    echo $sep;
767e013f48dSAnika Henke    tpl_pagelink($page);
76854e95700STom N Harris    return true;
7691734437eSandi}
7701734437eSandi
7711734437eSandi/**
7726b13307fSandi * Print info if the user is logged in
773a2488c3cSMatthias Grimm * and show full name in that case
7746b13307fSandi *
7756b13307fSandi * Could be enhanced with a profile link in future?
7766b13307fSandi *
7776b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7786b13307fSandi */
7796b13307fSandifunction tpl_userinfo(){
7806b13307fSandi    global $lang;
7813e63b73bSMichael Klier    global $INFO;
782c66972f2SAdrian Lang    if(isset($_SERVER['REMOTE_USER'])){
783d9e0d8dcSVadim Nevorotin        print $lang['loggedinas'].': '.hsc($INFO['userinfo']['name']).' ('.hsc($_SERVER['REMOTE_USER']).')';
78454e95700STom N Harris        return true;
78554e95700STom N Harris    }
78654e95700STom N Harris    return false;
7876b13307fSandi}
7886b13307fSandi
7896b13307fSandi/**
7906b13307fSandi * Print some info about the current page
7916b13307fSandi *
7926b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7936b13307fSandi */
7944b0d3916SAndreas Gohrfunction tpl_pageinfo($ret=false){
7956b13307fSandi    global $conf;
7966b13307fSandi    global $lang;
7976b13307fSandi    global $INFO;
798c6e92a3cSDavid Lorentsen    global $ID;
799c6e92a3cSDavid Lorentsen
800c6e92a3cSDavid Lorentsen    // return if we are not allowed to view the page
8014b0d3916SAndreas Gohr    if (!auth_quickaclcheck($ID)) { return false; }
8026b13307fSandi
8036b13307fSandi    // prepare date and path
8046b13307fSandi    $fn = $INFO['filepath'];
8056b13307fSandi    if(!$conf['fullpath']){
806613bca54SAndreas Gohr        if($INFO['rev']){
80750fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['olddir']).'/','',$fn);
8086b13307fSandi        }else{
80950fbebceSGina Haeussge            $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
8106b13307fSandi        }
8116b13307fSandi    }
812bee6dc82Sandi    $fn = utf8_decodeFN($fn);
813f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
8146b13307fSandi
815faecdfdfSAndreas Gohr    // print it
816faecdfdfSAndreas Gohr    if($INFO['exists']){
8174b0d3916SAndreas Gohr        $out = '';
8184b0d3916SAndreas Gohr        $out .= $fn;
8194b0d3916SAndreas Gohr        $out .= ' &middot; ';
8204b0d3916SAndreas Gohr        $out .= $lang['lastmod'];
8214b0d3916SAndreas Gohr        $out .= ': ';
8224b0d3916SAndreas Gohr        $out .= $date;
8236b13307fSandi        if($INFO['editor']){
8244b0d3916SAndreas Gohr            $out .= ' '.$lang['by'].' ';
825dc58b6f4SAndy Webber            $out .= editorinfo($INFO['editor']);
8265aa52fafSBen Coburn        }else{
8274b0d3916SAndreas Gohr            $out .= ' ('.$lang['external_edit'].')';
8286b13307fSandi        }
8296b13307fSandi        if($INFO['locked']){
8304b0d3916SAndreas Gohr            $out .= ' &middot; ';
8314b0d3916SAndreas Gohr            $out .= $lang['lockedby'];
8324b0d3916SAndreas Gohr            $out .= ': ';
833dc58b6f4SAndy Webber            $out .= editorinfo($INFO['locked']);
8346b13307fSandi        }
8354b0d3916SAndreas Gohr        if($ret){
8364b0d3916SAndreas Gohr            return $out;
8374b0d3916SAndreas Gohr        }else{
8384b0d3916SAndreas Gohr            echo $out;
83954e95700STom N Harris            return true;
8406b13307fSandi        }
8414b0d3916SAndreas Gohr    }
84254e95700STom N Harris    return false;
8436b13307fSandi}
8446b13307fSandi
845820fa24bSandi/**
846a6598f23SBen Coburn * Prints or returns the name of the given page (current one if none given).
84787c434ceSAndreas Gohr *
84887c434ceSAndreas Gohr * If useheading is enabled this will use the first headline else
849a6598f23SBen Coburn * the given ID is used.
85087c434ceSAndreas Gohr *
85187c434ceSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
85287c434ceSAndreas Gohr */
853a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
85487c434ceSAndreas Gohr    global $conf;
85587c434ceSAndreas Gohr    if(is_null($id)){
85687c434ceSAndreas Gohr        global $ID;
85787c434ceSAndreas Gohr        $id = $ID;
85887c434ceSAndreas Gohr    }
85987c434ceSAndreas Gohr
86087c434ceSAndreas Gohr    $name = $id;
861fe9ec250SChris Smith    if (useHeading('navigation')) {
86287c434ceSAndreas Gohr        $title = p_get_first_heading($id);
86387c434ceSAndreas Gohr        if ($title) $name = $title;
86487c434ceSAndreas Gohr    }
865a6598f23SBen Coburn
866a6598f23SBen Coburn    if ($ret) {
867a6598f23SBen Coburn        return hsc($name);
868a6598f23SBen Coburn    } else {
86987c434ceSAndreas Gohr        print hsc($name);
87054e95700STom N Harris        return true;
87187c434ceSAndreas Gohr    }
872a6598f23SBen Coburn}
873340756e4Sandi
87455efc227SAndreas Gohr/**
87555efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
87655efc227SAndreas Gohr *
87755efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
87855efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
87955efc227SAndreas Gohr *
88055efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
88155efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
88255efc227SAndreas Gohr * to the names of the latter one)
88355efc227SAndreas Gohr *
8843df72098SAndreas Gohr * Only allowed in: detail.php
88555efc227SAndreas Gohr *
88655efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
88755efc227SAndreas Gohr */
8883df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
88955efc227SAndreas Gohr    // Init Exif Reader
89055efc227SAndreas Gohr    global $SRC;
8913df72098SAndreas Gohr
8923df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
8933df72098SAndreas Gohr
89455efc227SAndreas Gohr    static $meta = null;
8953df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
89655efc227SAndreas Gohr    if($meta === false) return $alt;
89755efc227SAndreas Gohr    $info = $meta->getField($tags);
89855efc227SAndreas Gohr    if($info == false) return $alt;
89955efc227SAndreas Gohr    return $info;
90055efc227SAndreas Gohr}
90155efc227SAndreas Gohr
90255efc227SAndreas Gohr/**
90355efc227SAndreas Gohr * Prints the image with a link to the full sized version
90455efc227SAndreas Gohr *
90555efc227SAndreas Gohr * Only allowed in: detail.php
906a02d2933SAndreas Gohr *
907a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
908a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
909a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
910a02d2933SAndreas Gohr * @param $params array  - additional image attributes
91155efc227SAndreas Gohr */
912a02d2933SAndreas Gohrfunction tpl_img($maxwidth=0,$maxheight=0,$link=true,$params=null){
91355efc227SAndreas Gohr    global $IMG;
91455efc227SAndreas Gohr    $w = tpl_img_getTag('File.Width');
91555efc227SAndreas Gohr    $h = tpl_img_getTag('File.Height');
91655efc227SAndreas Gohr
91755efc227SAndreas Gohr    //resize to given max values
91823a34783SAndreas Gohr    $ratio = 1;
91923a34783SAndreas Gohr    if($w >= $h){
920f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth){
92155efc227SAndreas Gohr            $ratio = $maxwidth/$w;
922f8925855Sjoe.lapp        }elseif($maxheight && $h > $maxheight){
92355efc227SAndreas Gohr            $ratio = $maxheight/$h;
92455efc227SAndreas Gohr        }
92555efc227SAndreas Gohr    }else{
926f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight){
92755efc227SAndreas Gohr            $ratio = $maxheight/$h;
928f8925855Sjoe.lapp        }elseif($maxwidth && $w > $maxwidth){
92955efc227SAndreas Gohr            $ratio = $maxwidth/$w;
93055efc227SAndreas Gohr        }
93155efc227SAndreas Gohr    }
93255efc227SAndreas Gohr    if($ratio){
93355efc227SAndreas Gohr        $w = floor($ratio*$w);
93455efc227SAndreas Gohr        $h = floor($ratio*$h);
93555efc227SAndreas Gohr    }
93655efc227SAndreas Gohr
9376de3759aSAndreas Gohr    //prepare URLs
938a02d2933SAndreas Gohr    $url=ml($IMG,array('cache'=>$_REQUEST['cache']),true,'&');
939a02d2933SAndreas Gohr    $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h),true,'&');
94055efc227SAndreas Gohr
9412684e50aSAndreas Gohr    //prepare attributes
94255efc227SAndreas Gohr    $alt=tpl_img_getTag('Simple.Title');
943a02d2933SAndreas Gohr    if(is_null($params)){
9442684e50aSAndreas Gohr        $p = array();
945a02d2933SAndreas Gohr    }else{
946a02d2933SAndreas Gohr        $p = $params;
947a02d2933SAndreas Gohr    }
9482684e50aSAndreas Gohr    if($w) $p['width']  = $w;
9492684e50aSAndreas Gohr    if($h) $p['height'] = $h;
9502684e50aSAndreas Gohr    $p['class']  = 'img_detail';
9512684e50aSAndreas Gohr    if($alt){
9522684e50aSAndreas Gohr        $p['alt']   = $alt;
9532684e50aSAndreas Gohr        $p['title'] = $alt;
9542684e50aSAndreas Gohr    }else{
9552684e50aSAndreas Gohr        $p['alt'] = '';
9562684e50aSAndreas Gohr    }
957a02d2933SAndreas Gohr    $p['src'] = $src;
95855efc227SAndreas Gohr
959a02d2933SAndreas Gohr    $data = array('url'=>($link?$url:null), 'params'=>$p);
960a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY',$data,'_tpl_img_action',true);
961a02d2933SAndreas Gohr}
962a02d2933SAndreas Gohr
963a02d2933SAndreas Gohr/**
964a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
965a02d2933SAndreas Gohr */
966a02d2933SAndreas Gohrfunction _tpl_img_action($data, $param=NULL) {
967a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
968a02d2933SAndreas Gohr
969a02d2933SAndreas Gohr    if($data['url']) print '<a href="'.hsc($data['url']).'">';
970a02d2933SAndreas Gohr    print '<img '.$p.'/>';
971a02d2933SAndreas Gohr    if($data['url']) print '</a>';
97254e95700STom N Harris    return true;
97355efc227SAndreas Gohr}
97455efc227SAndreas Gohr
9757367b368SAndreas Gohr/**
9767367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
977c66972f2SAdrian Lang * is the indexer function.
9787367b368SAndreas Gohr *
9797367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9807367b368SAndreas Gohr * template
9817367b368SAndreas Gohr */
9827367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9837367b368SAndreas Gohr    global $ID;
9841dad36f5SAndreas Gohr    global $INFO;
98554e95700STom N Harris    if(!$INFO['exists']) return false;
9861dad36f5SAndreas Gohr
9877367b368SAndreas Gohr    $p = array();
988b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
989e68c51baSAndreas Gohr        '&'.time();
990e20ddf03SAndreas Gohr    $p['width']  = 2;
9917367b368SAndreas Gohr    $p['height'] = 1;
9927367b368SAndreas Gohr    $p['alt']    = '';
9937367b368SAndreas Gohr    $att = buildAttributes($p);
9947367b368SAndreas Gohr    print "<img $att />";
99554e95700STom N Harris    return true;
9967367b368SAndreas Gohr}
9977367b368SAndreas Gohr
99878d4e784SEsther Brunner// configuration methods
99978d4e784SEsther Brunner/**
100078d4e784SEsther Brunner * tpl_getConf($id)
100178d4e784SEsther Brunner *
100278d4e784SEsther Brunner * use this function to access template configuration variables
100378d4e784SEsther Brunner */
100478d4e784SEsther Brunnerfunction tpl_getConf($id){
100578d4e784SEsther Brunner    global $conf;
100617566ac6SAdrian Lang    static $tpl_configloaded = false;
100778d4e784SEsther Brunner
100878d4e784SEsther Brunner    $tpl = $conf['template'];
100978d4e784SEsther Brunner
101078d4e784SEsther Brunner    if (!$tpl_configloaded){
101178d4e784SEsther Brunner        $tconf = tpl_loadConfig();
101278d4e784SEsther Brunner        if ($tconf !== false){
101378d4e784SEsther Brunner            foreach ($tconf as $key => $value){
101478d4e784SEsther Brunner                if (isset($conf['tpl'][$tpl][$key])) continue;
101578d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
101678d4e784SEsther Brunner            }
101778d4e784SEsther Brunner            $tpl_configloaded = true;
101878d4e784SEsther Brunner        }
101978d4e784SEsther Brunner    }
102078d4e784SEsther Brunner
102178d4e784SEsther Brunner    return $conf['tpl'][$tpl][$id];
102278d4e784SEsther Brunner}
102378d4e784SEsther Brunner
102478d4e784SEsther Brunner/**
102578d4e784SEsther Brunner * tpl_loadConfig()
102678d4e784SEsther Brunner * reads all template configuration variables
102778d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
102878d4e784SEsther Brunner */
102978d4e784SEsther Brunnerfunction tpl_loadConfig(){
103078d4e784SEsther Brunner
103178d4e784SEsther Brunner    $file = DOKU_TPLINC.'/conf/default.php';
103278d4e784SEsther Brunner    $conf = array();
103378d4e784SEsther Brunner
103478d4e784SEsther Brunner    if (!@file_exists($file)) return false;
103578d4e784SEsther Brunner
103678d4e784SEsther Brunner    // load default config file
103778d4e784SEsther Brunner    include($file);
103878d4e784SEsther Brunner
103978d4e784SEsther Brunner    return $conf;
104078d4e784SEsther Brunner}
104178d4e784SEsther Brunner
104217566ac6SAdrian Lang// language methods
104317566ac6SAdrian Lang/**
104417566ac6SAdrian Lang * tpl_getLang($id)
104517566ac6SAdrian Lang *
104617566ac6SAdrian Lang * use this function to access template language variables
104717566ac6SAdrian Lang */
104817566ac6SAdrian Langfunction tpl_getLang($id){
104917566ac6SAdrian Lang    static $lang = array();
105017566ac6SAdrian Lang
105117566ac6SAdrian Lang    if (count($lang) === 0){
105217566ac6SAdrian Lang        $path = DOKU_TPLINC.'lang/';
105317566ac6SAdrian Lang
105417566ac6SAdrian Lang        $lang = array();
105517566ac6SAdrian Lang
105617566ac6SAdrian Lang        global $conf;            // definitely don't invoke "global $lang"
105717566ac6SAdrian Lang        // don't include once
105817566ac6SAdrian Lang        @include($path.'en/lang.php');
105917566ac6SAdrian Lang        if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
106017566ac6SAdrian Lang    }
106117566ac6SAdrian Lang
106217566ac6SAdrian Lang    return $lang[$id];
106317566ac6SAdrian Lang}
106417566ac6SAdrian Lang
10653df72098SAndreas Gohr/**
10663df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
10673df72098SAndreas Gohr *
10683df72098SAndreas Gohr * Depending on the user's actions this may be a list of
10693df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
10703df72098SAndreas Gohr * a message of referencing pages
10713df72098SAndreas Gohr *
10723df72098SAndreas Gohr * Only allowed in mediamanager.php
10733df72098SAndreas Gohr *
1074c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1075c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
10763df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10773df72098SAndreas Gohr */
1078c182313eSAndreas Gohrfunction tpl_mediaContent($fromajax=false){
10793df72098SAndreas Gohr    global $IMG;
10803df72098SAndreas Gohr    global $AUTH;
10813df72098SAndreas Gohr    global $INUSE;
10823df72098SAndreas Gohr    global $NS;
10833df72098SAndreas Gohr    global $JUMPTO;
10843df72098SAndreas Gohr
1085c9f56829SAndreas Gohr    if(is_array($_REQUEST['do'])){
1086c9f56829SAndreas Gohr        $do = array_shift(array_keys($_REQUEST['do']));
10873df72098SAndreas Gohr    }else{
1088c182313eSAndreas Gohr        $do = $_REQUEST['do'];
10893df72098SAndreas Gohr    }
1090c182313eSAndreas Gohr    if(in_array($do,array('save','cancel'))) $do = '';
1091c182313eSAndreas Gohr
1092c182313eSAndreas Gohr    if(!$do){
1093c182313eSAndreas Gohr        if($_REQUEST['edit']){
1094c182313eSAndreas Gohr            $do = 'metaform';
1095c182313eSAndreas Gohr        }elseif(is_array($INUSE)){
1096c182313eSAndreas Gohr            $do = 'filesinuse';
1097c182313eSAndreas Gohr        }else{
1098c182313eSAndreas Gohr            $do = 'filelist';
1099c182313eSAndreas Gohr        }
1100c182313eSAndreas Gohr    }
1101c182313eSAndreas Gohr
1102c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1103c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1104c182313eSAndreas Gohr    $data = array( 'do' => $do);
1105c182313eSAndreas Gohr    $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1106c182313eSAndreas Gohr    if ($evt->advise_before()) {
1107c182313eSAndreas Gohr        $do = $data['do'];
1108c182313eSAndreas Gohr        if($do == 'metaform'){
1109c182313eSAndreas Gohr            media_metaform($IMG,$AUTH);
1110c182313eSAndreas Gohr        }elseif($do == 'filesinuse'){
1111c182313eSAndreas Gohr            media_filesinuse($INUSE,$IMG);
1112c182313eSAndreas Gohr        }elseif($do == 'filelist'){
1113c182313eSAndreas Gohr            media_filelist($NS,$AUTH,$JUMPTO);
1114c9f56829SAndreas Gohr        }elseif($do == 'searchlist'){
1115c9f56829SAndreas Gohr            media_searchlist($_REQUEST['q'],$NS,$AUTH);
1116c182313eSAndreas Gohr        }else{
1117c182313eSAndreas Gohr            msg('Unknown action '.hsc($do),-1);
1118c182313eSAndreas Gohr        }
1119c182313eSAndreas Gohr    }
1120c182313eSAndreas Gohr    $evt->advise_after();
1121c182313eSAndreas Gohr    unset($evt);
1122c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1123c182313eSAndreas Gohr
11243df72098SAndreas Gohr}
11253df72098SAndreas Gohr
11263df72098SAndreas Gohr/**
11273df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
11283df72098SAndreas Gohr *
11293df72098SAndreas Gohr * Only allowed in mediamanager.php
11303df72098SAndreas Gohr *
11313df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11323df72098SAndreas Gohr */
11333df72098SAndreas Gohrfunction tpl_mediaTree(){
11343df72098SAndreas Gohr    global $NS;
11353df72098SAndreas Gohr
11363df72098SAndreas Gohr    ptln('<div id="media__tree">');
11373df72098SAndreas Gohr    media_nstree($NS);
11383df72098SAndreas Gohr    ptln('</div>');
11393df72098SAndreas Gohr}
11403df72098SAndreas Gohr
1141a00de5b5SAndreas Gohr
1142a00de5b5SAndreas Gohr/**
1143a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1144a00de5b5SAndreas Gohr *
1145a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1146a00de5b5SAndreas Gohr *
1147a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1148a00de5b5SAndreas Gohr */
1149a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty='',$button='&gt;'){
1150a00de5b5SAndreas Gohr    global $ID;
1151a00de5b5SAndreas Gohr    global $INFO;
1152a00de5b5SAndreas Gohr    global $REV;
1153a00de5b5SAndreas Gohr    global $ACT;
1154a00de5b5SAndreas Gohr    global $conf;
1155a00de5b5SAndreas Gohr    global $lang;
1156a00de5b5SAndreas Gohr    global $auth;
1157a00de5b5SAndreas Gohr
1158de3eb1d7SAdrian Lang    echo '<form action="' . DOKU_SCRIPT . '" method="post" accept-charset="utf-8">';
1159a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1160a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1161a00de5b5SAndreas Gohr    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1162a00de5b5SAndreas Gohr
1163f22c1964SAndreas Gohr    echo '<select name="do" class="edit quickselect">';
1164a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1165a00de5b5SAndreas Gohr
1166a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1167396c218fSAndreas Gohr        $act = tpl_get_action('edit');
1168396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1169a00de5b5SAndreas Gohr
1170396c218fSAndreas Gohr        $act = tpl_get_action('revisions');
1171396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1172396c218fSAndreas Gohr
1173396c218fSAndreas Gohr        $act = tpl_get_action('revert');
1174396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1175396c218fSAndreas Gohr
1176396c218fSAndreas Gohr        $act = tpl_get_action('backlink');
1177396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1178a00de5b5SAndreas Gohr    echo '</optgroup>';
1179a00de5b5SAndreas Gohr
1180a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1181396c218fSAndreas Gohr        $act = tpl_get_action('recent');
1182396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1183396c218fSAndreas Gohr
1184396c218fSAndreas Gohr        $act = tpl_get_action('index');
1185396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1186a00de5b5SAndreas Gohr    echo '</optgroup>';
1187a00de5b5SAndreas Gohr
1188a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1189396c218fSAndreas Gohr        $act = tpl_get_action('login');
1190396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1191a00de5b5SAndreas Gohr
1192396c218fSAndreas Gohr        $act = tpl_get_action('profile');
1193396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1194a00de5b5SAndreas Gohr
1195396c218fSAndreas Gohr        $act = tpl_get_action('subscribe');
1196396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1197a00de5b5SAndreas Gohr
1198396c218fSAndreas Gohr        $act = tpl_get_action('admin');
1199396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1200a00de5b5SAndreas Gohr    echo '</optgroup>';
1201a00de5b5SAndreas Gohr
1202a00de5b5SAndreas Gohr    echo '</select>';
1203f22c1964SAndreas Gohr    echo '<input type="submit" value="'.$button.'" />';
1204a00de5b5SAndreas Gohr    echo '</form>';
1205a00de5b5SAndreas Gohr}
1206a00de5b5SAndreas Gohr
1207066fee30SAndreas Gohr/**
1208066fee30SAndreas Gohr * Print a informational line about the used license
1209066fee30SAndreas Gohr *
1210066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1211066fee30SAndreas Gohr * @param  string $img    - print image? (|button|badge)
1212066fee30SAndreas Gohr * @param  bool   $return - when true don't print, but return HTML
1213066fee30SAndreas Gohr */
12144cefd216SMichael Klierfunction tpl_license($img='badge',$imgonly=false,$return=false){
1215066fee30SAndreas Gohr    global $license;
1216066fee30SAndreas Gohr    global $conf;
1217066fee30SAndreas Gohr    global $lang;
1218066fee30SAndreas Gohr    if(!$conf['license']) return '';
1219066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1220066fee30SAndreas Gohr    $lic = $license[$conf['license']];
1221066fee30SAndreas Gohr
12224cefd216SMichael Klier    $out  = '<div class="license">';
1223066fee30SAndreas Gohr    if($img){
1224066fee30SAndreas Gohr        $src = license_img($img);
1225066fee30SAndreas Gohr        if($src){
1226066fee30SAndreas Gohr            $out .= '<a href="'.$lic['url'].'" rel="license"';
122784645d8cSAndreas Gohr            if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1228a57c7cafSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> ';
1229066fee30SAndreas Gohr        }
1230066fee30SAndreas Gohr    }
12314cefd216SMichael Klier    if(!$imgonly) {
1232066fee30SAndreas Gohr        $out .= $lang['license'];
1233066fee30SAndreas Gohr        $out .= ' <a href="'.$lic['url'].'" rel="license" class="urlextern"';
1234a0b3ecb9SAnika Henke        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1235066fee30SAndreas Gohr        $out .= '>'.$lic['name'].'</a>';
12364cefd216SMichael Klier    }
1237c2a66484SKazutaka Miyasaka    $out .= '</div>';
1238066fee30SAndreas Gohr
1239066fee30SAndreas Gohr    if($return) return $out;
1240066fee30SAndreas Gohr    echo $out;
1241066fee30SAndreas Gohr}
1242066fee30SAndreas Gohr
1243a81910eeSAndreas Gohr
1244a81910eeSAndreas Gohr/**
1245a81910eeSAndreas Gohr * Includes the rendered XHTML of a given page
1246a81910eeSAndreas Gohr *
1247a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1248a81910eeSAndreas Gohr * template
1249a81910eeSAndreas Gohr */
1250a81910eeSAndreas Gohrfunction tpl_include_page($pageid,$print=true){
1251a81910eeSAndreas Gohr    global $ID;
1252a81910eeSAndreas Gohr    $oldid = $ID;
1253a81910eeSAndreas Gohr    $html = p_wiki_xhtml($pageid,'',false);
1254a81910eeSAndreas Gohr    $ID = $oldid;
1255a81910eeSAndreas Gohr
1256a81910eeSAndreas Gohr    if(!$print) return $html;
1257a81910eeSAndreas Gohr    echo $html;
1258a81910eeSAndreas Gohr}
1259a81910eeSAndreas Gohr
12605b75cd1fSAdrian Lang/**
12615b75cd1fSAdrian Lang * Display the subscribe form
12625b75cd1fSAdrian Lang *
12635b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
12645b75cd1fSAdrian Lang */
12655b75cd1fSAdrian Langfunction tpl_subscribe() {
12665b75cd1fSAdrian Lang    global $INFO;
12675b75cd1fSAdrian Lang    global $ID;
12685b75cd1fSAdrian Lang    global $lang;
12696b8f02cfSAdrian Lang    global $conf;
127040c347dbSAdrian Lang    $stime_days = $conf['subscribe_time']/60/60/24;
12715b75cd1fSAdrian Lang
12725b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
12735b75cd1fSAdrian Lang    echo '<h2>' . $lang['subscr_m_current_header'] . '</h2>';
127415741132SAndreas Gohr    echo '<div class="level2">';
12755b75cd1fSAdrian Lang    if ($INFO['subscribed'] === false) {
12765b75cd1fSAdrian Lang        echo '<p>' . $lang['subscr_m_not_subscribed'] . '</p>';
12775b75cd1fSAdrian Lang    } else {
12785b75cd1fSAdrian Lang        echo '<ul>';
12795b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1280056c2049SAndreas Gohr            echo '<li><div class="li">';
12815b75cd1fSAdrian Lang            if ($sub['target'] !== $ID) {
1282056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
12835b75cd1fSAdrian Lang            } else {
1284056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
12855b75cd1fSAdrian Lang            }
128640c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
128715741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1288056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
128915741132SAndreas Gohr
129066d2bed9SAdrian Lang            echo '<a href="' . wl($ID,
129166d2bed9SAdrian Lang                                  array('do'=>'subscribe',
129266d2bed9SAdrian Lang                                        'sub_target'=>$sub['target'],
129366d2bed9SAdrian Lang                                        'sub_style'=>$sub['style'],
129466d2bed9SAdrian Lang                                        'sub_action'=>'unsubscribe',
129566d2bed9SAdrian Lang                                        'sectok' => getSecurityToken())) .
129666d2bed9SAdrian Lang                 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'] .
129766d2bed9SAdrian Lang                 '</a></div></li>';
12985b75cd1fSAdrian Lang        }
12995b75cd1fSAdrian Lang        echo '</ul>';
13005b75cd1fSAdrian Lang    }
130115741132SAndreas Gohr    echo '</div>';
13025b75cd1fSAdrian Lang
130315741132SAndreas Gohr    // Add new subscription form
13045b75cd1fSAdrian Lang    echo '<h2>' . $lang['subscr_m_new_header'] . '</h2>';
130515741132SAndreas Gohr    echo '<div class="level2">';
13065b75cd1fSAdrian Lang    $ns = getNS($ID).':';
130715741132SAndreas Gohr    $targets = array(
130815741132SAndreas Gohr            $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
130915741132SAndreas Gohr            $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
131015741132SAndreas Gohr            );
131115741132SAndreas Gohr    $styles = array(
131215741132SAndreas Gohr            'every'  => $lang['subscr_style_every'],
13136b8f02cfSAdrian Lang            'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
13146b8f02cfSAdrian Lang            'list' => sprintf($lang['subscr_style_list'], $stime_days),
131515741132SAndreas Gohr            );
131615741132SAndreas Gohr
1317056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1318056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1319056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1320056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1321056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1322056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1323056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1324056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1325056c2049SAndreas Gohr    $form->endFieldset();
13265b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
13275b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
132815741132SAndreas Gohr    echo '</div>';
13295b75cd1fSAdrian Lang}
13305b75cd1fSAdrian Lang
1331d059ba9bSAndreas Gohr/**
1332d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1333d059ba9bSAndreas Gohr *
1334d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1335d059ba9bSAndreas Gohr *
1336d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1337d059ba9bSAndreas Gohr */
1338d059ba9bSAndreas Gohrfunction tpl_flush(){
1339d059ba9bSAndreas Gohr    ob_flush();
1340d059ba9bSAndreas Gohr    flush();
1341d059ba9bSAndreas Gohr}
1342d059ba9bSAndreas Gohr
1343d059ba9bSAndreas Gohr
1344afca7e7eSAnika Henke/**
1345afca7e7eSAnika Henke * Use favicon.ico from data/media root directory if it exists, otherwise use
1346afca7e7eSAnika Henke * the one in the template's image directory.
1347afca7e7eSAnika Henke *
1348afca7e7eSAnika Henke * @author Anika Henke <anika@selfthinker.org>
1349afca7e7eSAnika Henke */
1350a7e5f74cSlupo49function tpl_getFavicon($abs=false) {
13511f13e33dSAnika Henke    if (file_exists(mediaFN('favicon.ico'))) {
13521f13e33dSAnika Henke        return ml('favicon.ico', '', true, '', $abs);
13531f13e33dSAnika Henke    }
13540f747863Slupo49
13550f747863Slupo49    if($abs) {
13560f747863Slupo49        return DOKU_URL.substr(DOKU_TPL.'images/favicon.ico', strlen(DOKU_REL));
1357a7e5f74cSlupo49    }
13581f13e33dSAnika Henke
13591f13e33dSAnika Henke    return DOKU_TPL.'images/favicon.ico';
1360afca7e7eSAnika Henke}
1361afca7e7eSAnika Henke
1362afca7e7eSAnika Henke
1363e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
1364a00de5b5SAndreas Gohr
1365