xref: /dokuwiki/inc/template.php (revision 40c347db9c34fc92dd5a6185ac8d8e31c819c5a1)
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;
92a39955b0Smatthiasgrimm            html_recent($first);
936b13307fSandi            break;
946b13307fSandi        case 'index':
956b13307fSandi            html_index($IDX); #FIXME can this be pulled from globals? is it sanitized correctly?
966b13307fSandi                break;
976b13307fSandi        case 'backlink':
986b13307fSandi            html_backlinks();
996b13307fSandi            break;
1006b13307fSandi        case 'conflict':
1016b13307fSandi            html_conflict(con($PRE,$TEXT,$SUF),$SUM);
1026b13307fSandi            html_diff(con($PRE,$TEXT,$SUF),false);
1036b13307fSandi            break;
1046b13307fSandi        case 'login':
1056b13307fSandi            html_login();
1066b13307fSandi            break;
1076b13307fSandi        case 'register':
1086b13307fSandi            html_register();
1096b13307fSandi            break;
1108b06d178Schris        case 'resendpwd':
1118b06d178Schris            html_resendpwd();
1128b06d178Schris            break;
113820fa24bSandi        case 'denied':
1145e991bd8Sandi            print p_locale_xhtml('denied');
115820fa24bSandi            break;
1168b06d178Schris        case 'profile' :
1178b06d178Schris            html_updateprofile();
1188b06d178Schris            break;
119c19fe9c0Sandi        case 'admin':
120c19fe9c0Sandi            tpl_admin();
121c19fe9c0Sandi            break;
1225b75cd1fSAdrian Lang        case 'subscribe':
1235b75cd1fSAdrian Lang            tpl_subscribe();
1245b75cd1fSAdrian Lang            break;
1256b13307fSandi        default:
12624bb549bSchris            $evt = new Doku_Event('TPL_ACT_UNKNOWN',$ACT);
12724bb549bSchris            if ($evt->advise_before())
128ea67f144Sandi                msg("Failed to handle command: ".hsc($ACT),-1);
12924bb549bSchris            $evt->advise_after();
13024bb549bSchris            unset($evt);
13154e95700STom N Harris            return false;
1326b13307fSandi    }
13354e95700STom N Harris    return true;
1346b13307fSandi}
1356b13307fSandi
136c19fe9c0Sandi/**
137b8595a66SAndreas Gohr * Places the TOC where the function is called
138b8595a66SAndreas Gohr *
139b8595a66SAndreas Gohr * If you use this you most probably want to call tpl_content with
140b8595a66SAndreas Gohr * a false argument
141b8595a66SAndreas Gohr *
142b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
143b8595a66SAndreas Gohr */
144b8595a66SAndreas Gohrfunction tpl_toc($return=false){
145b8595a66SAndreas Gohr    global $TOC;
146b8595a66SAndreas Gohr    global $ACT;
147b8595a66SAndreas Gohr    global $ID;
148b8595a66SAndreas Gohr    global $REV;
149b8595a66SAndreas Gohr    global $INFO;
150851f2e89SAnika Henke    global $conf;
151b8595a66SAndreas Gohr    $toc = array();
152b8595a66SAndreas Gohr
153b8595a66SAndreas Gohr    if(is_array($TOC)){
154b8595a66SAndreas Gohr        // if a TOC was prepared in global scope, always use it
155b8595a66SAndreas Gohr        $toc = $TOC;
1563c86d7c9SAndreas Gohr    }elseif(($ACT == 'show' || substr($ACT,0,6) == 'export') && !$REV && $INFO['exists']){
157b8595a66SAndreas Gohr        // get TOC from metadata, render if neccessary
158b8595a66SAndreas Gohr        $meta = p_get_metadata($ID, false, true);
159b8595a66SAndreas Gohr        if(isset($meta['internal']['toc'])){
160b8595a66SAndreas Gohr            $tocok = $meta['internal']['toc'];
161b8595a66SAndreas Gohr        }else{
1622bb0d541Schris            $tocok = true;
163b8595a66SAndreas Gohr        }
164b8595a66SAndreas Gohr        $toc   = $meta['description']['tableofcontents'];
165851f2e89SAnika Henke        if(!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']){
166b8595a66SAndreas Gohr            $toc = array();
167b8595a66SAndreas Gohr        }
168b8595a66SAndreas Gohr    }elseif($ACT == 'admin'){
169b8595a66SAndreas Gohr        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
170b8595a66SAndreas Gohr        $plugin = null;
171b8595a66SAndreas Gohr        if (!empty($_REQUEST['page'])) {
172b8595a66SAndreas Gohr            $pluginlist = plugin_list('admin');
173b8595a66SAndreas Gohr            if (in_array($_REQUEST['page'], $pluginlist)) {
174b8595a66SAndreas Gohr                // attempt to load the plugin
175b8595a66SAndreas Gohr                $plugin =& plugin_load('admin',$_REQUEST['page']);
176b8595a66SAndreas Gohr            }
177b8595a66SAndreas Gohr        }
178b8595a66SAndreas Gohr        if ( ($plugin !== null) &&
179b8595a66SAndreas Gohr                (!$plugin->forAdminOnly() || $INFO['isadmin']) ){
180b8595a66SAndreas Gohr            $toc = $plugin->getTOC();
181b8595a66SAndreas Gohr            $TOC = $toc; // avoid later rebuild
182b8595a66SAndreas Gohr        }
183b8595a66SAndreas Gohr    }
184b8595a66SAndreas Gohr
1850b17fdc6SAndreas Gohr    trigger_event('TPL_TOC_RENDER', $toc, null, false);
186b8595a66SAndreas Gohr    $html = html_TOC($toc);
187b8595a66SAndreas Gohr    if($return) return $html;
188b8595a66SAndreas Gohr    echo $html;
189b8595a66SAndreas Gohr}
190b8595a66SAndreas Gohr
191b8595a66SAndreas Gohr/**
192c19fe9c0Sandi * Handle the admin page contents
193c19fe9c0Sandi *
194c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
195c19fe9c0Sandi */
196c19fe9c0Sandifunction tpl_admin(){
197f8cc712eSAndreas Gohr    global $INFO;
198b8595a66SAndreas Gohr    global $TOC;
19911e2ce22Schris
200b8595a66SAndreas Gohr    $plugin = null;
201bb4866bdSchris    if (!empty($_REQUEST['page'])) {
20211e2ce22Schris        $pluginlist = plugin_list('admin');
20311e2ce22Schris
20411e2ce22Schris        if (in_array($_REQUEST['page'], $pluginlist)) {
20511e2ce22Schris
20611e2ce22Schris            // attempt to load the plugin
20711e2ce22Schris            $plugin =& plugin_load('admin',$_REQUEST['page']);
20811e2ce22Schris        }
20911e2ce22Schris    }
21011e2ce22Schris
211b8595a66SAndreas Gohr    if ($plugin !== null){
212f8cc712eSAndreas Gohr        if($plugin->forAdminOnly() && !$INFO['isadmin']){
213f8cc712eSAndreas Gohr            msg('For admins only',-1);
21411e2ce22Schris            html_admin();
215f8cc712eSAndreas Gohr        }else{
216b8595a66SAndreas Gohr            if(!is_array($TOC)) $TOC = $plugin->getTOC(); //if TOC wasn't requested yet
217b8595a66SAndreas Gohr            if($INFO['prependTOC']) tpl_toc();
218f8cc712eSAndreas Gohr            $plugin->html();
219f8cc712eSAndreas Gohr        }
220f8cc712eSAndreas Gohr    }else{
221f8cc712eSAndreas Gohr        html_admin();
222f8cc712eSAndreas Gohr    }
22354e95700STom N Harris    return true;
224c19fe9c0Sandi}
2256b13307fSandi
2266b13307fSandi/**
2276b13307fSandi * Print the correct HTML meta headers
2286b13307fSandi *
2296b13307fSandi * This has to go into the head section of your template.
2306b13307fSandi *
231016b6153SAndreas Gohr * @triggers TPL_METAHEADER_OUTPUT
232f96fa415SAndreas Gohr * @param  boolean $alt Should feeds and alternative format links be added?
2336b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
2346b13307fSandi */
235f96fa415SAndreas Gohrfunction tpl_metaheaders($alt=true){
2366b13307fSandi    global $ID;
237d98d4540SBen Coburn    global $REV;
2386b13307fSandi    global $INFO;
23972e0dc37SAndreas Gohr    global $JSINFO;
2406b13307fSandi    global $ACT;
2414bb1b5aeSAndreas Gohr    global $QUERY;
2426b13307fSandi    global $lang;
243dc57ef04Sandi    global $conf;
2446b13307fSandi    $it=2;
2456b13307fSandi
2467bff22c0SAndreas Gohr    // prepare the head array
2477bff22c0SAndreas Gohr    $head = array();
2487bff22c0SAndreas Gohr
249202ac28bSMichael Klier    // prepare seed for js and css
250202ac28bSMichael Klier    $tseed = 0;
251202ac28bSMichael Klier    $depends = getConfigFiles('main');
252202ac28bSMichael Klier    foreach($depends as $f) {
253202ac28bSMichael Klier        $time = @filemtime($f);
254202ac28bSMichael Klier        if($time > $tseed) $tseed = $time;
255202ac28bSMichael Klier    }
2567bff22c0SAndreas Gohr
2576b13307fSandi    // the usual stuff
2583f803e5eSGina Haeussge    $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki');
259da96af35SAndreas Gohr    $head['link'][] = array( 'rel'=>'search', 'type'=>'application/opensearchdescription+xml',
260da96af35SAndreas Gohr            'href'=>DOKU_BASE.'lib/exe/opensearch.php', 'title'=>$conf['title'] );
261f4f47358SBen Coburn    $head['link'][] = array( 'rel'=>'start', 'href'=>DOKU_BASE );
2627aedde2eSGina Haeussge    if(actionOK('index')){
2637bff22c0SAndreas Gohr        $head['link'][] = array( 'rel'=>'contents', 'href'=> wl($ID,'do=index',false,'&'),
264bb4866bdSchris                'title'=>$lang['btn_index'] );
2657aedde2eSGina Haeussge    }
266f96fa415SAndreas Gohr
267f96fa415SAndreas Gohr    if($alt){
2687bff22c0SAndreas Gohr        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2697bff22c0SAndreas Gohr                'title'=>'Recent Changes', 'href'=>DOKU_BASE.'feed.php');
2707bff22c0SAndreas Gohr        $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2717bff22c0SAndreas Gohr                'title'=>'Current Namespace',
2727bff22c0SAndreas Gohr                'href'=>DOKU_BASE.'feed.php?mode=list&ns='.$INFO['namespace']);
273c35f3875SAndreas Gohr        if(($ACT == 'show' || $ACT == 'search') && $INFO['writable']){
274a2c734d5SAndreas Gohr            $head['link'][] = array( 'rel'=>'edit',
275715bdf1fSAndreas Gohr                    'title'=>$lang['btn_edit'],
276c35f3875SAndreas Gohr                    'href'=> wl($ID,'do=edit',false,'&'));
277c35f3875SAndreas Gohr        }
278c35f3875SAndreas Gohr
2794bb1b5aeSAndreas Gohr        if($ACT == 'search'){
2804bb1b5aeSAndreas Gohr            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'application/rss+xml',
2814bb1b5aeSAndreas Gohr                    'title'=>'Search Result',
2824bb1b5aeSAndreas Gohr                    'href'=>DOKU_BASE.'feed.php?mode=search&q='.$QUERY);
2834bb1b5aeSAndreas Gohr        }
284bae36d94SAndreas Gohr
285bae36d94SAndreas Gohr        if(actionOK('export_xhtml')){
2867bff22c0SAndreas Gohr            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/html', 'title'=>'Plain HTML',
2877bff22c0SAndreas Gohr                    'href'=>exportlink($ID, 'xhtml', '', false, '&'));
288bae36d94SAndreas Gohr        }
289bae36d94SAndreas Gohr
290bae36d94SAndreas Gohr        if(actionOK('export_raw')){
2917bff22c0SAndreas Gohr            $head['link'][] = array( 'rel'=>'alternate', 'type'=>'text/plain', 'title'=>'Wiki Markup',
2927bff22c0SAndreas Gohr                    'href'=>exportlink($ID, 'raw', '', false, '&'));
293f96fa415SAndreas Gohr        }
294bae36d94SAndreas Gohr    }
2956b13307fSandi
2966b13307fSandi    // setup robot tags apropriate for different modes
2974f2e0004STim Weber    if( ($ACT=='show' || $ACT=='export_xhtml') && !$REV){
2986b13307fSandi        if($INFO['exists']){
2996b13307fSandi            //delay indexing:
3006b13307fSandi            if((time() - $INFO['lastmod']) >= $conf['indexdelay']){
3017bff22c0SAndreas Gohr                $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
3026b13307fSandi            }else{
3037bff22c0SAndreas Gohr                $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3046b13307fSandi            }
30569db0cafSAndreas Gohr            $head['link'][] = array( 'rel'=>'canonical', 'href'=>wl($ID,'',true,'&') );
3066b13307fSandi        }else{
3077bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,follow');
3086b13307fSandi        }
3097a24876fSAndreas Gohr    }elseif(defined('DOKU_MEDIADETAIL')){
3107bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'index,follow');
3116b13307fSandi    }else{
3127bff22c0SAndreas Gohr        $head['meta'][] = array( 'name'=>'robots', 'content'=>'noindex,nofollow');
3136b13307fSandi    }
3146b13307fSandi
315831800b8SAndreas Gohr    // set metadata
316831800b8SAndreas Gohr    if($ACT == 'show' || $ACT=='export_xhtml'){
317831800b8SAndreas Gohr        // date of modification
318831800b8SAndreas Gohr        if($REV){
3197bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$REV));
320831800b8SAndreas Gohr        }else{
3217bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'date', 'content'=>date('Y-m-d\TH:i:sO',$INFO['lastmod']));
322831800b8SAndreas Gohr        }
323831800b8SAndreas Gohr
324831800b8SAndreas Gohr        // keywords (explicit or implicit)
325bb4866bdSchris        if(!empty($INFO['meta']['subject'])){
3267bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'keywords', 'content'=>join(',',$INFO['meta']['subject']));
327831800b8SAndreas Gohr        }else{
3287bff22c0SAndreas Gohr            $head['meta'][] = array( 'name'=>'keywords', 'content'=>str_replace(':',',',$ID));
329831800b8SAndreas Gohr        }
330831800b8SAndreas Gohr    }
331831800b8SAndreas Gohr
33278a6aeb1SAndreas Gohr    // load stylesheets
3337bff22c0SAndreas Gohr    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'screen', 'type'=>'text/css',
334202ac28bSMichael Klier            'href'=>DOKU_BASE.'lib/exe/css.php?t='.$conf['template'].'&tseed='.$tseed);
335d61e1b3eSMike Frysinger    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'all', 'type'=>'text/css',
336d61e1b3eSMike Frysinger            'href'=>DOKU_BASE.'lib/exe/css.php?s=all&t='.$conf['template'].'&tseed='.$tseed);
3377bff22c0SAndreas Gohr    $head['link'][] = array('rel'=>'stylesheet', 'media'=>'print', 'type'=>'text/css',
338202ac28bSMichael Klier            'href'=>DOKU_BASE.'lib/exe/css.php?s=print&t='.$conf['template'].'&tseed='.$tseed);
339bad31ae9SAndreas Gohr
3408bbcb611SAndreas Gohr    // make $INFO and other vars available to JavaScripts
341463d4a65SAndreas Gohr    $json = new JSON();
34272e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
343c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
34472e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
345c591aabeSAndreas Gohr    }
34672e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
34785f81679SAdrian Lang    $head['script'][] = array( 'type'=>'text/javascript', '_data'=> $script);
3488bbcb611SAndreas Gohr
3498bbcb611SAndreas Gohr    // load external javascript
3507bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
351202ac28bSMichael Klier            'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed);
3527bff22c0SAndreas Gohr
3537bff22c0SAndreas Gohr    // trigger event here
354016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
35554e95700STom N Harris    return true;
3567bff22c0SAndreas Gohr}
3577bff22c0SAndreas Gohr
3587bff22c0SAndreas Gohr/**
3597bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3607bff22c0SAndreas Gohr *
3617bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3627bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3637bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3647bff22c0SAndreas Gohr *
3657bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
3661304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3677bff22c0SAndreas Gohr *
3687bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3697bff22c0SAndreas Gohr */
3707bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3717bff22c0SAndreas Gohr    foreach($data as $tag => $inst){
3727bff22c0SAndreas Gohr        foreach($inst as $attr){
3737bff22c0SAndreas Gohr            echo '<',$tag,' ',buildAttributes($attr);
37426afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script'){
375e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
376e226efe1SAndreas Gohr                    $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
377e226efe1SAndreas Gohr                        $attr['_data'].
378e226efe1SAndreas Gohr                        "\n//--><!]]>";
379e226efe1SAndreas Gohr
3801304d1dbSAndreas Gohr                echo '>',$attr['_data'],'</',$tag,'>';
3817bff22c0SAndreas Gohr            }else{
3827bff22c0SAndreas Gohr                echo '/>';
3837bff22c0SAndreas Gohr            }
3847bff22c0SAndreas Gohr            echo "\n";
3857bff22c0SAndreas Gohr        }
3867bff22c0SAndreas Gohr    }
3876b13307fSandi}
3886b13307fSandi
3896b13307fSandi/**
3906b13307fSandi * Print a link
3916b13307fSandi *
3925e163278SAndreas Gohr * Just builds a link.
3936b13307fSandi *
3946b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3956b13307fSandi */
3961af98a77SAnika Henkefunction tpl_link($url,$name,$more='',$return=false){
39701f17825SAnika Henke    $out = '<a href="'.$url.'" ';
3981af98a77SAnika Henke    if ($more) $out .= ' '.$more;
3991af98a77SAnika Henke    $out .= ">$name</a>";
4001af98a77SAnika Henke    if ($return) return $out;
4011af98a77SAnika Henke    print $out;
40254e95700STom N Harris    return true;
4036b13307fSandi}
4046b13307fSandi
4056b13307fSandi/**
40655efc227SAndreas Gohr * Prints a link to a WikiPage
40755efc227SAndreas Gohr *
40855efc227SAndreas Gohr * Wrapper around html_wikilink
40955efc227SAndreas Gohr *
41055efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
41155efc227SAndreas Gohr */
4120b17fdc6SAndreas Gohrfunction tpl_pagelink($id,$name=null){
41355efc227SAndreas Gohr    print html_wikilink($id,$name);
41454e95700STom N Harris    return true;
41555efc227SAndreas Gohr}
41655efc227SAndreas Gohr
41755efc227SAndreas Gohr/**
418a3ec5f4aSmatthiasgrimm * get the parent page
419a3ec5f4aSmatthiasgrimm *
420a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
421a3ec5f4aSmatthiasgrimm * returns false if none is available
422a3ec5f4aSmatthiasgrimm *
423377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
424a3ec5f4aSmatthiasgrimm */
425377f9e97SAndreas Gohrfunction tpl_getparent($id){
426a3ec5f4aSmatthiasgrimm    global $conf;
427377f9e97SAndreas Gohr    $parent = getNS($id).':';
428377f9e97SAndreas Gohr    resolve_pageid('',$parent,$exists);
429a197105eSmatthiasgrimm    if($parent == $id) {
430a197105eSmatthiasgrimm        $pos = strrpos (getNS($id),':');
431a197105eSmatthiasgrimm        $parent = substr($parent,0,$pos).':';
432a197105eSmatthiasgrimm        resolve_pageid('',$parent,$exists);
433377f9e97SAndreas Gohr        if($parent == $id) return false;
434a197105eSmatthiasgrimm    }
435377f9e97SAndreas Gohr    return $parent;
436a3ec5f4aSmatthiasgrimm}
437a3ec5f4aSmatthiasgrimm
438a3ec5f4aSmatthiasgrimm/**
4396b13307fSandi * Print one of the buttons
4406b13307fSandi *
441a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
442a453d131SAdrian Lang * @see    tpl_get_action
4436b13307fSandi */
4441af98a77SAnika Henkefunction tpl_button($type,$return=false){
445a453d131SAdrian Lang    $data = tpl_get_action($type);
446a453d131SAdrian Lang    if ($data === false) {
447a453d131SAdrian Lang        return false;
448a453d131SAdrian Lang    } elseif (!is_array($data)) {
449a453d131SAdrian Lang        $out = sprintf($data, 'button');
450409d7af7SAndreas Gohr    } else {
451a453d131SAdrian Lang        extract($data);
452a453d131SAdrian Lang        if ($id === '#dokuwiki__top') {
453a453d131SAdrian Lang            $out = html_topbtn();
454409d7af7SAndreas Gohr        } else {
455a453d131SAdrian Lang            $out = html_btn($type, $id, $accesskey, $params, $method);
456409d7af7SAndreas Gohr        }
457409d7af7SAndreas Gohr    }
4581af98a77SAnika Henke    if ($return) return $out;
459a453d131SAdrian Lang    echo $out;
460a453d131SAdrian Lang    return true;
4616b13307fSandi}
4626b13307fSandi
4636b13307fSandi/**
464ed630903Sandi * Like the action buttons but links
465ed630903Sandi *
466a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
467a453d131SAdrian Lang * @see    tpl_get_action
468a453d131SAdrian Lang */
469a453d131SAdrian Langfunction tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
470a453d131SAdrian Lang    global $lang;
471a453d131SAdrian Lang    $data = tpl_get_action($type);
472a453d131SAdrian Lang    if ($data === false) {
473a453d131SAdrian Lang        return false;
474a453d131SAdrian Lang    } elseif (!is_array($data)) {
475a453d131SAdrian Lang        $out = sprintf($data, 'link');
476a453d131SAdrian Lang    } else {
477a453d131SAdrian Lang        extract($data);
478a453d131SAdrian Lang        if (strpos($id, '#') === 0) {
479a453d131SAdrian Lang            $linktarget = $id;
480a453d131SAdrian Lang        } else {
481a453d131SAdrian Lang            $linktarget = wl($id, $params);
482a453d131SAdrian Lang        }
483a453d131SAdrian Lang        $caption = $lang['btn_' . $type];
484a453d131SAdrian Lang        $out = tpl_link($linktarget, $pre.(($inner)?$inner:$caption).$suf,
485a453d131SAdrian Lang                        'class="action ' . $type . '" ' .
486a453d131SAdrian Lang                        'accesskey="' . $accesskey . '" rel="nofollow" ' .
487a453d131SAdrian Lang                        'title="' . hsc($caption) . '"', 1);
488a453d131SAdrian Lang    }
489a453d131SAdrian Lang    if ($return) return $out;
490a453d131SAdrian Lang    echo $out;
491a453d131SAdrian Lang    return true;
492a453d131SAdrian Lang}
493a453d131SAdrian Lang
494a453d131SAdrian Lang/**
495a453d131SAdrian Lang * Check the actions and get data for buttons and links
496ed630903Sandi *
497a453d131SAdrian Lang * Available actions are
498a453d131SAdrian Lang *
499a453d131SAdrian Lang *  edit        - edit/create/show/draft
500ed630903Sandi *  history     - old revisions
501ed630903Sandi *  recent      - recent changes
502a453d131SAdrian Lang *  login       - login/logout - if ACL enabled
503a453d131SAdrian Lang *  profile     - user profile (if logged in)
504ed630903Sandi *  index       - The index
505ed630903Sandi *  admin       - admin page - if enough rights
506a453d131SAdrian Lang *  top         - back to top
507a453d131SAdrian Lang *  back        - back to parent - if available
508bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
509a453d131SAdrian Lang *  subscribe/subscription- subscribe/unsubscribe
510ed630903Sandi *
511ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
512a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
513a453d131SAdrian Lang * @author Adrian Lang <mail@adrianlang.de>
514ed630903Sandi */
515a453d131SAdrian Langfunction tpl_get_action($type) {
516ed630903Sandi    global $ID;
517ed630903Sandi    global $INFO;
518ed630903Sandi    global $REV;
519ed630903Sandi    global $ACT;
520ed630903Sandi    global $conf;
521cd52f92dSchris    global $auth;
522ed630903Sandi
52375e487e9SAndreas Gohr    // check disabled actions and fix the badly named ones
524a453d131SAdrian Lang    if($type == 'history') $type='revisions';
525a453d131SAdrian Lang    if(!actionOK($type)) return false;
526409d7af7SAndreas Gohr
527a453d131SAdrian Lang    $accesskey = null;
5286709e843SAdrian Lang    $id        = $ID;
529a453d131SAdrian Lang    $method    = 'get';
530a453d131SAdrian Lang    $params    = array('do' => $type);
531ed630903Sandi    switch($type){
532ed630903Sandi        case 'edit':
5330b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
534ed630903Sandi            if($ACT == 'show' || $ACT == 'search'){
535a453d131SAdrian Lang                $method = 'post';
536ed630903Sandi                if($INFO['writable']){
537a453d131SAdrian Lang                    $accesskey = 'e';
538b8a111f5SMichael Klier                    if(!empty($INFO['draft'])) {
5396709e843SAdrian Lang                        $type = 'draft';
540a453d131SAdrian Lang                        $params['do'] = 'draft';
541b8a111f5SMichael Klier                    } else {
542a453d131SAdrian Lang                        $params['rev'] = $REV;
543a453d131SAdrian Lang                        if(!$INFO['exists']){
5446709e843SAdrian Lang                            $type   = 'create';
545ed630903Sandi                        }
546b8a111f5SMichael Klier                    }
547ed630903Sandi                }else{
548a453d131SAdrian Lang                    if(!actionOK('source')) return false; //pseudo action
549a453d131SAdrian Lang                    $params['rev'] = $REV;
5506709e843SAdrian Lang                    $type = 'source';
551a453d131SAdrian Lang                    $accesskey = 'v';
552ed630903Sandi                }
553ed630903Sandi            }else{
554a453d131SAdrian Lang                $params = '';
5556709e843SAdrian Lang                $type = 'show';
556a453d131SAdrian Lang                $accesskey = 'v';
557ed630903Sandi            }
5581af98a77SAnika Henke            break;
559a453d131SAdrian Lang        case 'revisions':
5606709e843SAdrian Lang            $type = 'revs';
561a453d131SAdrian Lang            $accesskey = 'o';
5621af98a77SAnika Henke            break;
563ed630903Sandi        case 'recent':
564a453d131SAdrian Lang            $accesskey = 'r';
5651af98a77SAnika Henke            break;
566ed630903Sandi        case 'index':
567a453d131SAdrian Lang            $accesskey = 'x';
5681af98a77SAnika Henke            break;
569ed630903Sandi        case 'top':
570a453d131SAdrian Lang            $accesskey = 'x';
571a453d131SAdrian Lang            $params = '';
572a453d131SAdrian Lang            $id = '#dokuwiki__top';
5731af98a77SAnika Henke            break;
574a3ec5f4aSmatthiasgrimm        case 'back':
575a453d131SAdrian Lang            $parent = tpl_getparent($ID);
576a453d131SAdrian Lang            if (!$parent) {
577a453d131SAdrian Lang                return false;
578a3ec5f4aSmatthiasgrimm            }
579a453d131SAdrian Lang            $id = $parent;
580a453d131SAdrian Lang            $params = '';
581a453d131SAdrian Lang            $accesskey = 'b';
5821af98a77SAnika Henke            break;
583ed630903Sandi        case 'login':
584a453d131SAdrian Lang            if(!$conf['useacl'] || !$auth){
585a453d131SAdrian Lang                return false;
586ed630903Sandi            }
587a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
5882380e8a8SAdrian Lang            if(isset($_SERVER['REMOTE_USER'])){
589880f62faSAndreas Gohr                if (!$auth->canDo('logout')) {
5902380e8a8SAdrian Lang                    return false;
5912380e8a8SAdrian Lang                }
592a453d131SAdrian Lang                $params['do'] = 'logout';
593a453d131SAdrian Lang                $type = 'logout';
594ed630903Sandi            }
5951af98a77SAnika Henke            break;
596ed630903Sandi        case 'admin':
597a453d131SAdrian Lang            if(!$INFO['ismanager']){
598a453d131SAdrian Lang                return false;
599c059e1a6SAndreas Gohr            }
6001af98a77SAnika Henke            break;
6011246e016SAndreas Gohr        case 'revert':
602a453d131SAdrian Lang            if(!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
603a453d131SAdrian Lang                return false;
6041246e016SAndreas Gohr            }
605a453d131SAdrian Lang            $params['rev'] = $REV;
606a453d131SAdrian Lang            $params['sectok'] = getSecurityToken();
6071246e016SAndreas Gohr            break;
608075f000fSChristopher Arndt        case 'subscription':
6096709e843SAdrian Lang            $type = 'subscribe';
610a453d131SAdrian Lang            $params['do'] = 'subscribe';
6116709e843SAdrian Lang        case 'subscribe':
612a453d131SAdrian Lang            if(!$conf['useacl'] || !$auth || $ACT !== 'show' || !$conf['subscribers'] || !$_SERVER['REMOTE_USER']){
613a453d131SAdrian Lang                return false;
614b158d625SSteven Danz            }
6151af98a77SAnika Henke            break;
616f00151b4Schris        case 'backlink':
6171af98a77SAnika Henke            break;
6188b06d178Schris        case 'profile':
619a453d131SAdrian Lang            if(!$conf['useacl'] || !$auth || !isset($_SERVER['REMOTE_USER']) ||
620a453d131SAdrian Lang                    !$auth->canDo('Profile') || ($ACT=='profile')){
621a453d131SAdrian Lang                return false;
6228b06d178Schris            }
6231af98a77SAnika Henke            break;
624ed630903Sandi        default:
625a453d131SAdrian Lang            return '[unknown %s type]';
6261af98a77SAnika Henke            break;
627ed630903Sandi    }
628a453d131SAdrian Lang    return compact('accesskey', 'type', 'id', 'method', 'params');
629ed630903Sandi}
630ed630903Sandi
631ed630903Sandi/**
63201f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
63301f17825SAnika Henke *
63401f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
63501f17825SAnika Henke */
63601f17825SAnika Henkefunction tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') {
63701f17825SAnika Henke    $out = '';
63801f17825SAnika Henke    if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1);
63901f17825SAnika Henke    else $out .= tpl_button($type,1);
64001f17825SAnika Henke    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
64101f17825SAnika Henke
64201f17825SAnika Henke    if ($return) return $out;
64301f17825SAnika Henke    print $out;
64401f17825SAnika Henke    return $out ? true : false;
64501f17825SAnika Henke}
64601f17825SAnika Henke
64701f17825SAnika Henke/**
6486b13307fSandi * Print the search form
6496b13307fSandi *
65072645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
65172645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
65272645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
65372645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
65472645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
65572645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
65672645b75SAndreas Gohr *
6576b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6586b13307fSandi */
65972645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
6606b13307fSandi    global $lang;
661c1e3b7d9Smatthiasgrimm    global $ACT;
662ad4aaef7SAndreas Gohr    global $QUERY;
663c1e3b7d9Smatthiasgrimm
664670ff54eSchris    // don't print the search form if search action has been disabled
66554e95700STom N Harris    if (!actionOk('search')) return false;
666670ff54eSchris
6671dd0c202SAnika Henke    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
6686b13307fSandi    print '<input type="hidden" name="do" value="search" />';
669c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
670ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
67172645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
67207493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
67311ea018fSAndreas Gohr    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
67424a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
6754beabca9SAnika Henke    print '</div></form>';
67654e95700STom N Harris    return true;
6776b13307fSandi}
6786b13307fSandi
6796b13307fSandi/**
6806b13307fSandi * Print the breadcrumbs trace
6816b13307fSandi *
6826b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
6836b13307fSandi */
68454e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
6856b13307fSandi    global $lang;
6866b13307fSandi    global $conf;
6876b13307fSandi
6886b13307fSandi    //check if enabled
68954e95700STom N Harris    if(!$conf['breadcrumbs']) return false;
6906b13307fSandi
6916b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
692265e3787Sandi
6932979a10bSKatriel Traum    //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
6942979a10bSKatriel Traum    if($lang['direction'] == 'rtl') {
6952979a10bSKatriel Traum        $crumbs = array_reverse($crumbs,true);
6962979a10bSKatriel Traum        $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
6972979a10bSKatriel Traum    } else {
6982979a10bSKatriel Traum        $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
6992979a10bSKatriel Traum    }
700265e3787Sandi
70140eb54bbSjan    //render crumbs, highlight the last one
7021b6f3a44SAndreas Gohr    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
70340eb54bbSjan    $last = count($crumbs);
70440eb54bbSjan    $i = 0;
705a77f5846Sjan    foreach ($crumbs as $id => $name){
70640eb54bbSjan        $i++;
7072979a10bSKatriel Traum        echo $crumbs_sep;
70892795d04Sandi        if ($i == $last) print '<span class="curid">';
709e26fd1eeSAndreas Gohr        tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
71092795d04Sandi        if ($i == $last) print '</span>';
7116b13307fSandi    }
71254e95700STom N Harris    return true;
7136b13307fSandi}
7146b13307fSandi
7156b13307fSandi/**
7161734437eSandi * Hierarchical breadcrumbs
7171734437eSandi *
71831e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
7191734437eSandi * It only makes sense with a deep site structure.
7201734437eSandi *
7211734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
7226bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
72331e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
724f46c9e83SAnika Henke * @author <fredrik@averpil.com>
7256bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
7261734437eSandi */
727796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
7281734437eSandi    global $conf;
7291734437eSandi    global $ID;
7301734437eSandi    global $lang;
7311734437eSandi
73231e187f8SSean Coates    // check if enabled
73354e95700STom N Harris    if(!$conf['youarehere']) return false;
7341734437eSandi
7351734437eSandi    $parts = explode(':', $ID);
736796bafb3SAndreas Gohr    $count = count($parts);
7371734437eSandi
7383b437163SAlexey Torkhov    if($GLOBALS['ACT'] == 'search')
7393b437163SAlexey Torkhov    {
7403b437163SAlexey Torkhov        $parts = array($conf['start']);
7413b437163SAlexey Torkhov        $count = 1;
7423b437163SAlexey Torkhov    }
7433b437163SAlexey Torkhov
7441b6f3a44SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
7451734437eSandi
7461734437eSandi    // always print the startpage
747fe9ec250SChris Smith    $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start'];
748796bafb3SAndreas Gohr    if(!$title) $title = $conf['start'];
749e26fd1eeSAndreas Gohr    tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
750796bafb3SAndreas Gohr
751796bafb3SAndreas Gohr    // print intermediate namespace links
752796bafb3SAndreas Gohr    $part = '';
753796bafb3SAndreas Gohr    for($i=0; $i<$count - 1; $i++){
754796bafb3SAndreas Gohr        $part .= $parts[$i].':';
755796bafb3SAndreas Gohr        $page = $part;
756796bafb3SAndreas Gohr        resolve_pageid('',$page,$exists);
757796bafb3SAndreas Gohr        if ($page == $conf['start']) continue; // Skip startpage
758796bafb3SAndreas Gohr
759796bafb3SAndreas Gohr        // output
760796bafb3SAndreas Gohr        echo $sep;
761796bafb3SAndreas Gohr        if($exists){
762af03da1aSAndreas Gohr            $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
763e26fd1eeSAndreas Gohr            tpl_link(wl($page),hsc($title),'title="'.$page.'"');
76431e187f8SSean Coates        }else{
76578cbfcb6SAndreas Gohr            tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
76631e187f8SSean Coates        }
76731e187f8SSean Coates    }
7681734437eSandi
769796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
770d98d4540SBen Coburn    if(isset($page) && $page==$part.$parts[$i]) return;
771796bafb3SAndreas Gohr    $page = $part.$parts[$i];
772796bafb3SAndreas Gohr    if($page == $conf['start']) return;
773796bafb3SAndreas Gohr    echo $sep;
774103c256aSChris Smith    if(page_exists($page)){
775af03da1aSAndreas Gohr        $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
776e26fd1eeSAndreas Gohr        tpl_link(wl($page),hsc($title),'title="'.$page.'"');
77731e187f8SSean Coates    }else{
77878cbfcb6SAndreas Gohr        tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
7791734437eSandi    }
78054e95700STom N Harris    return true;
7811734437eSandi}
7821734437eSandi
7831734437eSandi/**
7846b13307fSandi * Print info if the user is logged in
785a2488c3cSMatthias Grimm * and show full name in that case
7866b13307fSandi *
7876b13307fSandi * Could be enhanced with a profile link in future?
7886b13307fSandi *
7896b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7906b13307fSandi */
7916b13307fSandifunction tpl_userinfo(){
7926b13307fSandi    global $lang;
7933e63b73bSMichael Klier    global $INFO;
794c66972f2SAdrian Lang    if(isset($_SERVER['REMOTE_USER'])){
7953e63b73bSMichael Klier        print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')';
79654e95700STom N Harris                return true;
79754e95700STom N Harris                }
79854e95700STom N Harris                return false;
7996b13307fSandi                }
8006b13307fSandi
8016b13307fSandi                /**
8026b13307fSandi                 * Print some info about the current page
8036b13307fSandi                 *
8046b13307fSandi                 * @author Andreas Gohr <andi@splitbrain.org>
8056b13307fSandi                 */
8064b0d3916SAndreas Gohr                function tpl_pageinfo($ret=false){
8076b13307fSandi                global $conf;
8086b13307fSandi                global $lang;
8096b13307fSandi                global $INFO;
810c6e92a3cSDavid Lorentsen                global $ID;
811c6e92a3cSDavid Lorentsen
812c6e92a3cSDavid Lorentsen                // return if we are not allowed to view the page
8134b0d3916SAndreas Gohr                if (!auth_quickaclcheck($ID)) { return false; }
8146b13307fSandi
8156b13307fSandi                // prepare date and path
8166b13307fSandi                $fn = $INFO['filepath'];
8176b13307fSandi                if(!$conf['fullpath']){
818613bca54SAndreas Gohr                    if($INFO['rev']){
81950fbebceSGina Haeussge                        $fn = str_replace(fullpath($conf['olddir']).'/','',$fn);
8206b13307fSandi                    }else{
82150fbebceSGina Haeussge                        $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
8226b13307fSandi                    }
8236b13307fSandi                }
824bee6dc82Sandi                $fn = utf8_decodeFN($fn);
825f2263577SAndreas Gohr                $date = dformat($INFO['lastmod']);
8266b13307fSandi
827faecdfdfSAndreas Gohr                // print it
828faecdfdfSAndreas Gohr                if($INFO['exists']){
8294b0d3916SAndreas Gohr                    $out = '';
8304b0d3916SAndreas Gohr                    $out .= $fn;
8314b0d3916SAndreas Gohr                    $out .= ' &middot; ';
8324b0d3916SAndreas Gohr                    $out .= $lang['lastmod'];
8334b0d3916SAndreas Gohr                    $out .= ': ';
8344b0d3916SAndreas Gohr                    $out .= $date;
8356b13307fSandi                    if($INFO['editor']){
8364b0d3916SAndreas Gohr                        $out .= ' '.$lang['by'].' ';
837dc58b6f4SAndy Webber                        $out .= editorinfo($INFO['editor']);
8385aa52fafSBen Coburn                    }else{
8394b0d3916SAndreas Gohr                        $out .= ' ('.$lang['external_edit'].')';
8406b13307fSandi                                }
8416b13307fSandi                                if($INFO['locked']){
8424b0d3916SAndreas Gohr                                $out .= ' &middot; ';
8434b0d3916SAndreas Gohr                                $out .= $lang['lockedby'];
8444b0d3916SAndreas Gohr                                $out .= ': ';
845dc58b6f4SAndy Webber                                $out .= editorinfo($INFO['locked']);
8466b13307fSandi                                }
8474b0d3916SAndreas Gohr                                if($ret){
8484b0d3916SAndreas Gohr                                return $out;
8494b0d3916SAndreas Gohr                                }else{
8504b0d3916SAndreas Gohr                                echo $out;
85154e95700STom N Harris                                return true;
8526b13307fSandi                                }
8534b0d3916SAndreas Gohr                                }
85454e95700STom N Harris                                return false;
8556b13307fSandi                                }
8566b13307fSandi
857820fa24bSandi                                /**
858a6598f23SBen Coburn                                 * Prints or returns the name of the given page (current one if none given).
85987c434ceSAndreas Gohr                                 *
86087c434ceSAndreas Gohr                                 * If useheading is enabled this will use the first headline else
861a6598f23SBen Coburn                                 * the given ID is used.
86287c434ceSAndreas Gohr                                 *
86387c434ceSAndreas Gohr                                 * @author Andreas Gohr <andi@splitbrain.org>
86487c434ceSAndreas Gohr                                 */
865a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
86687c434ceSAndreas Gohr    global $conf;
86787c434ceSAndreas Gohr    if(is_null($id)){
86887c434ceSAndreas Gohr        global $ID;
86987c434ceSAndreas Gohr        $id = $ID;
87087c434ceSAndreas Gohr    }
87187c434ceSAndreas Gohr
87287c434ceSAndreas Gohr    $name = $id;
873fe9ec250SChris Smith    if (useHeading('navigation')) {
87487c434ceSAndreas Gohr        $title = p_get_first_heading($id);
87587c434ceSAndreas Gohr        if ($title) $name = $title;
87687c434ceSAndreas Gohr    }
877a6598f23SBen Coburn
878a6598f23SBen Coburn    if ($ret) {
879a6598f23SBen Coburn        return hsc($name);
880a6598f23SBen Coburn    } else {
88187c434ceSAndreas Gohr        print hsc($name);
88254e95700STom N Harris        return true;
88387c434ceSAndreas Gohr    }
884a6598f23SBen Coburn}
885340756e4Sandi
88655efc227SAndreas Gohr/**
88755efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
88855efc227SAndreas Gohr *
88955efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
89055efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
89155efc227SAndreas Gohr *
89255efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
89355efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
89455efc227SAndreas Gohr * to the names of the latter one)
89555efc227SAndreas Gohr *
8963df72098SAndreas Gohr * Only allowed in: detail.php
89755efc227SAndreas Gohr *
89855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
89955efc227SAndreas Gohr */
9003df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
90155efc227SAndreas Gohr    // Init Exif Reader
90255efc227SAndreas Gohr    global $SRC;
9033df72098SAndreas Gohr
9043df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
9053df72098SAndreas Gohr
90655efc227SAndreas Gohr    static $meta = null;
9073df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
90855efc227SAndreas Gohr    if($meta === false) return $alt;
90955efc227SAndreas Gohr    $info = $meta->getField($tags);
91055efc227SAndreas Gohr    if($info == false) return $alt;
91155efc227SAndreas Gohr    return $info;
91255efc227SAndreas Gohr}
91355efc227SAndreas Gohr
91455efc227SAndreas Gohr/**
91555efc227SAndreas Gohr * Prints the image with a link to the full sized version
91655efc227SAndreas Gohr *
91755efc227SAndreas Gohr * Only allowed in: detail.php
918a02d2933SAndreas Gohr *
919a02d2933SAndreas Gohr * @param $maxwidth  int - maximal width of the image
920a02d2933SAndreas Gohr * @param $maxheight int - maximal height of the image
921a02d2933SAndreas Gohr * @param $link bool     - link to the orginal size?
922a02d2933SAndreas Gohr * @param $params array  - additional image attributes
92355efc227SAndreas Gohr */
924a02d2933SAndreas Gohrfunction tpl_img($maxwidth=0,$maxheight=0,$link=true,$params=null){
92555efc227SAndreas Gohr    global $IMG;
92655efc227SAndreas Gohr    $w = tpl_img_getTag('File.Width');
92755efc227SAndreas Gohr    $h = tpl_img_getTag('File.Height');
92855efc227SAndreas Gohr
92955efc227SAndreas Gohr    //resize to given max values
93023a34783SAndreas Gohr    $ratio = 1;
93123a34783SAndreas Gohr    if($w >= $h){
932f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth){
93355efc227SAndreas Gohr            $ratio = $maxwidth/$w;
934f8925855Sjoe.lapp        }elseif($maxheight && $h > $maxheight){
93555efc227SAndreas Gohr            $ratio = $maxheight/$h;
93655efc227SAndreas Gohr        }
93755efc227SAndreas Gohr    }else{
938f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight){
93955efc227SAndreas Gohr            $ratio = $maxheight/$h;
940f8925855Sjoe.lapp        }elseif($maxwidth && $w > $maxwidth){
94155efc227SAndreas Gohr            $ratio = $maxwidth/$w;
94255efc227SAndreas Gohr        }
94355efc227SAndreas Gohr    }
94455efc227SAndreas Gohr    if($ratio){
94555efc227SAndreas Gohr        $w = floor($ratio*$w);
94655efc227SAndreas Gohr        $h = floor($ratio*$h);
94755efc227SAndreas Gohr    }
94855efc227SAndreas Gohr
9496de3759aSAndreas Gohr    //prepare URLs
950a02d2933SAndreas Gohr    $url=ml($IMG,array('cache'=>$_REQUEST['cache']),true,'&');
951a02d2933SAndreas Gohr    $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h),true,'&');
95255efc227SAndreas Gohr
9532684e50aSAndreas Gohr    //prepare attributes
95455efc227SAndreas Gohr    $alt=tpl_img_getTag('Simple.Title');
955a02d2933SAndreas Gohr    if(is_null($params)){
9562684e50aSAndreas Gohr        $p = array();
957a02d2933SAndreas Gohr    }else{
958a02d2933SAndreas Gohr        $p = $params;
959a02d2933SAndreas Gohr    }
9602684e50aSAndreas Gohr    if($w) $p['width']  = $w;
9612684e50aSAndreas Gohr    if($h) $p['height'] = $h;
9622684e50aSAndreas Gohr    $p['class']  = 'img_detail';
9632684e50aSAndreas Gohr    if($alt){
9642684e50aSAndreas Gohr        $p['alt']   = $alt;
9652684e50aSAndreas Gohr        $p['title'] = $alt;
9662684e50aSAndreas Gohr    }else{
9672684e50aSAndreas Gohr        $p['alt'] = '';
9682684e50aSAndreas Gohr    }
969a02d2933SAndreas Gohr    $p['src'] = $src;
97055efc227SAndreas Gohr
971a02d2933SAndreas Gohr    $data = array('url'=>($link?$url:null), 'params'=>$p);
972a02d2933SAndreas Gohr    return trigger_event('TPL_IMG_DISPLAY',$data,'_tpl_img_action',true);
973a02d2933SAndreas Gohr}
974a02d2933SAndreas Gohr
975a02d2933SAndreas Gohr/**
976a02d2933SAndreas Gohr * Default action for TPL_IMG_DISPLAY
977a02d2933SAndreas Gohr */
978a02d2933SAndreas Gohrfunction _tpl_img_action($data, $param=NULL) {
979a02d2933SAndreas Gohr    $p = buildAttributes($data['params']);
980a02d2933SAndreas Gohr
981a02d2933SAndreas Gohr    if($data['url']) print '<a href="'.hsc($data['url']).'">';
982a02d2933SAndreas Gohr    print '<img '.$p.'/>';
983a02d2933SAndreas Gohr    if($data['url']) print '</a>';
98454e95700STom N Harris    return true;
98555efc227SAndreas Gohr}
98655efc227SAndreas Gohr
9877367b368SAndreas Gohr/**
9887367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
989c66972f2SAdrian Lang * is the indexer function.
9907367b368SAndreas Gohr *
9917367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
9927367b368SAndreas Gohr * template
9937367b368SAndreas Gohr */
9947367b368SAndreas Gohrfunction tpl_indexerWebBug(){
9957367b368SAndreas Gohr    global $ID;
9961dad36f5SAndreas Gohr    global $INFO;
99754e95700STom N Harris    if(!$INFO['exists']) return false;
9981dad36f5SAndreas Gohr
99954e95700STom N Harris    if(isHiddenPage($ID)) return false; //no need to index hidden pages
10000dc92c6fSAndreas Gohr
10017367b368SAndreas Gohr    $p = array();
1002b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1003e68c51baSAndreas Gohr        '&'.time();
10047367b368SAndreas Gohr    $p['width']  = 1;
10057367b368SAndreas Gohr    $p['height'] = 1;
10067367b368SAndreas Gohr    $p['alt']    = '';
10077367b368SAndreas Gohr    $att = buildAttributes($p);
10087367b368SAndreas Gohr    print "<img $att />";
100954e95700STom N Harris    return true;
10107367b368SAndreas Gohr}
10117367b368SAndreas Gohr
101278d4e784SEsther Brunner// configuration methods
101378d4e784SEsther Brunner/**
101478d4e784SEsther Brunner * tpl_getConf($id)
101578d4e784SEsther Brunner *
101678d4e784SEsther Brunner * use this function to access template configuration variables
101778d4e784SEsther Brunner */
101878d4e784SEsther Brunnerfunction tpl_getConf($id){
101978d4e784SEsther Brunner    global $conf;
102078d4e784SEsther Brunner    global $tpl_configloaded;
102178d4e784SEsther Brunner
102278d4e784SEsther Brunner    $tpl = $conf['template'];
102378d4e784SEsther Brunner
102478d4e784SEsther Brunner    if (!$tpl_configloaded){
102578d4e784SEsther Brunner        $tconf = tpl_loadConfig();
102678d4e784SEsther Brunner        if ($tconf !== false){
102778d4e784SEsther Brunner            foreach ($tconf as $key => $value){
102878d4e784SEsther Brunner                if (isset($conf['tpl'][$tpl][$key])) continue;
102978d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
103078d4e784SEsther Brunner            }
103178d4e784SEsther Brunner            $tpl_configloaded = true;
103278d4e784SEsther Brunner        }
103378d4e784SEsther Brunner    }
103478d4e784SEsther Brunner
103578d4e784SEsther Brunner    return $conf['tpl'][$tpl][$id];
103678d4e784SEsther Brunner}
103778d4e784SEsther Brunner
103878d4e784SEsther Brunner/**
103978d4e784SEsther Brunner * tpl_loadConfig()
104078d4e784SEsther Brunner * reads all template configuration variables
104178d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
104278d4e784SEsther Brunner */
104378d4e784SEsther Brunnerfunction tpl_loadConfig(){
104478d4e784SEsther Brunner
104578d4e784SEsther Brunner    $file = DOKU_TPLINC.'/conf/default.php';
104678d4e784SEsther Brunner    $conf = array();
104778d4e784SEsther Brunner
104878d4e784SEsther Brunner    if (!@file_exists($file)) return false;
104978d4e784SEsther Brunner
105078d4e784SEsther Brunner    // load default config file
105178d4e784SEsther Brunner    include($file);
105278d4e784SEsther Brunner
105378d4e784SEsther Brunner    return $conf;
105478d4e784SEsther Brunner}
105578d4e784SEsther Brunner
10563df72098SAndreas Gohr/**
10573df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
10583df72098SAndreas Gohr *
10593df72098SAndreas Gohr * Depending on the user's actions this may be a list of
10603df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
10613df72098SAndreas Gohr * a message of referencing pages
10623df72098SAndreas Gohr *
10633df72098SAndreas Gohr * Only allowed in mediamanager.php
10643df72098SAndreas Gohr *
1065c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1066c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
10673df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
10683df72098SAndreas Gohr */
1069c182313eSAndreas Gohrfunction tpl_mediaContent($fromajax=false){
10703df72098SAndreas Gohr    global $IMG;
10713df72098SAndreas Gohr    global $AUTH;
10723df72098SAndreas Gohr    global $INUSE;
10733df72098SAndreas Gohr    global $NS;
10743df72098SAndreas Gohr    global $JUMPTO;
10753df72098SAndreas Gohr
1076c9f56829SAndreas Gohr    if(is_array($_REQUEST['do'])){
1077c9f56829SAndreas Gohr        $do = array_shift(array_keys($_REQUEST['do']));
10783df72098SAndreas Gohr    }else{
1079c182313eSAndreas Gohr        $do = $_REQUEST['do'];
10803df72098SAndreas Gohr    }
1081c182313eSAndreas Gohr    if(in_array($do,array('save','cancel'))) $do = '';
1082c182313eSAndreas Gohr
1083c182313eSAndreas Gohr    if(!$do){
1084c182313eSAndreas Gohr        if($_REQUEST['edit']){
1085c182313eSAndreas Gohr            $do = 'metaform';
1086c182313eSAndreas Gohr        }elseif(is_array($INUSE)){
1087c182313eSAndreas Gohr            $do = 'filesinuse';
1088c182313eSAndreas Gohr        }else{
1089c182313eSAndreas Gohr            $do = 'filelist';
1090c182313eSAndreas Gohr        }
1091c182313eSAndreas Gohr    }
1092c182313eSAndreas Gohr
1093c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1094c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1095c182313eSAndreas Gohr    $data = array( 'do' => $do);
1096c182313eSAndreas Gohr    $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1097c182313eSAndreas Gohr    if ($evt->advise_before()) {
1098c182313eSAndreas Gohr        $do = $data['do'];
1099c182313eSAndreas Gohr        if($do == 'metaform'){
1100c182313eSAndreas Gohr            media_metaform($IMG,$AUTH);
1101c182313eSAndreas Gohr        }elseif($do == 'filesinuse'){
1102c182313eSAndreas Gohr            media_filesinuse($INUSE,$IMG);
1103c182313eSAndreas Gohr        }elseif($do == 'filelist'){
1104c182313eSAndreas Gohr            media_filelist($NS,$AUTH,$JUMPTO);
1105c9f56829SAndreas Gohr        }elseif($do == 'searchlist'){
1106c9f56829SAndreas Gohr            media_searchlist($_REQUEST['q'],$NS,$AUTH);
1107c182313eSAndreas Gohr        }else{
1108c182313eSAndreas Gohr            msg('Unknown action '.hsc($do),-1);
1109c182313eSAndreas Gohr        }
1110c182313eSAndreas Gohr    }
1111c182313eSAndreas Gohr    $evt->advise_after();
1112c182313eSAndreas Gohr    unset($evt);
1113c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1114c182313eSAndreas Gohr
11153df72098SAndreas Gohr}
11163df72098SAndreas Gohr
11173df72098SAndreas Gohr/**
11183df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
11193df72098SAndreas Gohr *
11203df72098SAndreas Gohr * Only allowed in mediamanager.php
11213df72098SAndreas Gohr *
11223df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11233df72098SAndreas Gohr */
11243df72098SAndreas Gohrfunction tpl_mediaTree(){
11253df72098SAndreas Gohr    global $NS;
11263df72098SAndreas Gohr
11273df72098SAndreas Gohr    ptln('<div id="media__tree">');
11283df72098SAndreas Gohr    media_nstree($NS);
11293df72098SAndreas Gohr    ptln('</div>');
11303df72098SAndreas Gohr}
11313df72098SAndreas Gohr
1132a00de5b5SAndreas Gohr
1133a00de5b5SAndreas Gohr/**
1134a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1135a00de5b5SAndreas Gohr *
1136a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1137a00de5b5SAndreas Gohr *
1138a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1139a00de5b5SAndreas Gohr */
1140a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty='',$button='&gt;'){
1141a00de5b5SAndreas Gohr    global $ID;
1142a00de5b5SAndreas Gohr    global $INFO;
1143a00de5b5SAndreas Gohr    global $REV;
1144a00de5b5SAndreas Gohr    global $ACT;
1145a00de5b5SAndreas Gohr    global $conf;
1146a00de5b5SAndreas Gohr    global $lang;
1147a00de5b5SAndreas Gohr    global $auth;
1148a00de5b5SAndreas Gohr
1149a00de5b5SAndreas Gohr    echo '<form method="post" accept-charset="utf-8">'; #FIXME action
1150a00de5b5SAndreas Gohr    echo '<input type="hidden" name="id" value="'.$ID.'" />';
1151a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1152a00de5b5SAndreas Gohr    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1153a00de5b5SAndreas Gohr
1154a00de5b5SAndreas Gohr    echo '<select name="do" id="action__selector" class="edit">';
1155a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1156a00de5b5SAndreas Gohr
1157a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1158396c218fSAndreas Gohr        $act = tpl_get_action('edit');
1159396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1160a00de5b5SAndreas Gohr
1161396c218fSAndreas Gohr        $act = tpl_get_action('revisions');
1162396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1163396c218fSAndreas Gohr
1164396c218fSAndreas Gohr        $act = tpl_get_action('revert');
1165396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1166396c218fSAndreas Gohr
1167396c218fSAndreas Gohr        $act = tpl_get_action('backlink');
1168396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1169a00de5b5SAndreas Gohr    echo '</optgroup>';
1170a00de5b5SAndreas Gohr
1171a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1172396c218fSAndreas Gohr        $act = tpl_get_action('recent');
1173396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1174396c218fSAndreas Gohr
1175396c218fSAndreas Gohr        $act = tpl_get_action('index');
1176396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1177a00de5b5SAndreas Gohr    echo '</optgroup>';
1178a00de5b5SAndreas Gohr
1179a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1180396c218fSAndreas Gohr        $act = tpl_get_action('login');
1181396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1182a00de5b5SAndreas Gohr
1183396c218fSAndreas Gohr        $act = tpl_get_action('profile');
1184396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1185a00de5b5SAndreas Gohr
1186396c218fSAndreas Gohr        $act = tpl_get_action('subscribe');
1187396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1188a00de5b5SAndreas Gohr
1189396c218fSAndreas Gohr        $act = tpl_get_action('admin');
1190396c218fSAndreas Gohr        if($act) echo '<option value="'.$act['params']['do'].'">'.$lang['btn_'.$act['type']].'</option>';
1191a00de5b5SAndreas Gohr    echo '</optgroup>';
1192a00de5b5SAndreas Gohr
1193a00de5b5SAndreas Gohr    echo '</select>';
1194a00de5b5SAndreas Gohr    echo '<input type="submit" value="'.$button.'" id="action__selectorbtn" />';
1195a00de5b5SAndreas Gohr    echo '</form>';
1196a00de5b5SAndreas Gohr}
1197a00de5b5SAndreas Gohr
1198066fee30SAndreas Gohr/**
1199066fee30SAndreas Gohr * Print a informational line about the used license
1200066fee30SAndreas Gohr *
1201066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1202066fee30SAndreas Gohr * @param  string $img    - print image? (|button|badge)
1203066fee30SAndreas Gohr * @param  bool   $return - when true don't print, but return HTML
1204066fee30SAndreas Gohr */
12054cefd216SMichael Klierfunction tpl_license($img='badge',$imgonly=false,$return=false){
1206066fee30SAndreas Gohr    global $license;
1207066fee30SAndreas Gohr    global $conf;
1208066fee30SAndreas Gohr    global $lang;
1209066fee30SAndreas Gohr    if(!$conf['license']) return '';
1210066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1211066fee30SAndreas Gohr    $lic = $license[$conf['license']];
1212066fee30SAndreas Gohr
12134cefd216SMichael Klier    $out  = '<div class="license">';
1214066fee30SAndreas Gohr    if($img){
1215066fee30SAndreas Gohr        $src = license_img($img);
1216066fee30SAndreas Gohr        if($src){
1217066fee30SAndreas Gohr            $out .= '<a href="'.$lic['url'].'" rel="license"';
121884645d8cSAndreas Gohr            if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1219a57c7cafSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> ';
1220066fee30SAndreas Gohr        }
1221066fee30SAndreas Gohr    }
12224cefd216SMichael Klier    if(!$imgonly) {
1223066fee30SAndreas Gohr        $out .= $lang['license'];
1224066fee30SAndreas Gohr        $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"';
1225a0b3ecb9SAnika Henke        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1226066fee30SAndreas Gohr        $out .= '>'.$lic['name'].'</a>';
12274cefd216SMichael Klier    }
1228c2a66484SKazutaka Miyasaka    $out .= '</div>';
1229066fee30SAndreas Gohr
1230066fee30SAndreas Gohr    if($return) return $out;
1231066fee30SAndreas Gohr    echo $out;
1232066fee30SAndreas Gohr}
1233066fee30SAndreas Gohr
1234a81910eeSAndreas Gohr
1235a81910eeSAndreas Gohr/**
1236a81910eeSAndreas Gohr * Includes the rendered XHTML of a given page
1237a81910eeSAndreas Gohr *
1238a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1239a81910eeSAndreas Gohr * template
1240a81910eeSAndreas Gohr */
1241a81910eeSAndreas Gohrfunction tpl_include_page($pageid,$print=true){
1242a81910eeSAndreas Gohr    global $ID;
1243a81910eeSAndreas Gohr    $oldid = $ID;
1244a81910eeSAndreas Gohr    $html = p_wiki_xhtml($pageid,'',false);
1245a81910eeSAndreas Gohr    $ID = $oldid;
1246a81910eeSAndreas Gohr
1247a81910eeSAndreas Gohr    if(!$print) return $html;
1248a81910eeSAndreas Gohr    echo $html;
1249a81910eeSAndreas Gohr}
1250a81910eeSAndreas Gohr
12515b75cd1fSAdrian Lang/**
12525b75cd1fSAdrian Lang * Display the subscribe form
12535b75cd1fSAdrian Lang *
12545b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
12555b75cd1fSAdrian Lang */
12565b75cd1fSAdrian Langfunction tpl_subscribe() {
12575b75cd1fSAdrian Lang    global $INFO;
12585b75cd1fSAdrian Lang    global $ID;
12595b75cd1fSAdrian Lang    global $lang;
12606b8f02cfSAdrian Lang    global $conf;
1261*40c347dbSAdrian Lang    $stime_days = $conf['subscribe_time']/60/60/24;
12625b75cd1fSAdrian Lang
12635b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
12645b75cd1fSAdrian Lang    echo '<h2>' . $lang['subscr_m_current_header'] . '</h2>';
126515741132SAndreas Gohr    echo '<div class="level2">';
12665b75cd1fSAdrian Lang    if ($INFO['subscribed'] === false) {
12675b75cd1fSAdrian Lang        echo '<p>' . $lang['subscr_m_not_subscribed'] . '</p>';
12685b75cd1fSAdrian Lang    } else {
12695b75cd1fSAdrian Lang        echo '<ul>';
12705b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1271056c2049SAndreas Gohr            echo '<li><div class="li">';
12725b75cd1fSAdrian Lang            if ($sub['target'] !== $ID) {
1273056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
12745b75cd1fSAdrian Lang            } else {
1275056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
12765b75cd1fSAdrian Lang            }
1277*40c347dbSAdrian Lang            $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
127815741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1279056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
128015741132SAndreas Gohr
128166d2bed9SAdrian Lang            echo '<a href="' . wl($ID,
128266d2bed9SAdrian Lang                                  array('do'=>'subscribe',
128366d2bed9SAdrian Lang                                        'sub_target'=>$sub['target'],
128466d2bed9SAdrian Lang                                        'sub_style'=>$sub['style'],
128566d2bed9SAdrian Lang                                        'sub_action'=>'unsubscribe',
128666d2bed9SAdrian Lang                                        'sectok' => getSecurityToken())) .
128766d2bed9SAdrian Lang                 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'] .
128866d2bed9SAdrian Lang                 '</a></div></li>';
12895b75cd1fSAdrian Lang        }
12905b75cd1fSAdrian Lang        echo '</ul>';
12915b75cd1fSAdrian Lang    }
129215741132SAndreas Gohr    echo '</div>';
12935b75cd1fSAdrian Lang
129415741132SAndreas Gohr    // Add new subscription form
12955b75cd1fSAdrian Lang    echo '<h2>' . $lang['subscr_m_new_header'] . '</h2>';
129615741132SAndreas Gohr    echo '<div class="level2">';
12975b75cd1fSAdrian Lang    $ns = getNS($ID).':';
129815741132SAndreas Gohr    $targets = array(
129915741132SAndreas Gohr            $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
130015741132SAndreas Gohr            $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
130115741132SAndreas Gohr            );
130215741132SAndreas Gohr    $styles = array(
130315741132SAndreas Gohr            'every'  => $lang['subscr_style_every'],
13046b8f02cfSAdrian Lang            'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
13056b8f02cfSAdrian Lang            'list' => sprintf($lang['subscr_style_list'], $stime_days),
130615741132SAndreas Gohr            );
130715741132SAndreas Gohr
1308056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1309056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1310056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1311056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1312056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1313056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1314056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1315056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1316056c2049SAndreas Gohr    $form->endFieldset();
13175b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
13185b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
131915741132SAndreas Gohr    echo '</div>';
13205b75cd1fSAdrian Lang}
13215b75cd1fSAdrian Lang
1322d059ba9bSAndreas Gohr/**
1323d059ba9bSAndreas Gohr * Tries to send already created content right to the browser
1324d059ba9bSAndreas Gohr *
1325d059ba9bSAndreas Gohr * Wraps around ob_flush() and flush()
1326d059ba9bSAndreas Gohr *
1327d059ba9bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1328d059ba9bSAndreas Gohr */
1329d059ba9bSAndreas Gohrfunction tpl_flush(){
1330d059ba9bSAndreas Gohr    ob_flush();
1331d059ba9bSAndreas Gohr    flush();
1332d059ba9bSAndreas Gohr}
1333d059ba9bSAndreas Gohr
1334d059ba9bSAndreas Gohr
1335b8595a66SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
1336a00de5b5SAndreas Gohr
1337