xref: /dokuwiki/inc/template.php (revision 84645d8c01570c5ea4cda556e70beccdec25ee22)
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
2587bff22c0SAndreas Gohr    $head['meta'][] = array( 'name'=>'generator', 'content'=>'DokuWiki '.getVersion() );
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    require_once(DOKU_INC.'inc/JSON.php');
342463d4a65SAndreas Gohr    $json = new JSON();
34372e0dc37SAndreas Gohr    $script = "var NS='".$INFO['namespace']."';";
344c591aabeSAndreas Gohr    if($conf['useacl'] && $_SERVER['REMOTE_USER']){
345aeaccbf9SAndreas Gohr        require_once(DOKU_INC.'inc/toolbar.php');
34672e0dc37SAndreas Gohr        $script .= "var SIG='".toolbar_signature()."';";
347c591aabeSAndreas Gohr    }
34872e0dc37SAndreas Gohr    $script .= 'var JSINFO = '.$json->encode($JSINFO).';';
3497bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8',
3507bff22c0SAndreas Gohr            '_data'=> $script);
3518bbcb611SAndreas Gohr
3528bbcb611SAndreas Gohr    // load external javascript
3537bff22c0SAndreas Gohr    $head['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>'',
354202ac28bSMichael Klier            'src'=>DOKU_BASE.'lib/exe/js.php'.'?tseed='.$tseed);
3557bff22c0SAndreas Gohr
3567bff22c0SAndreas Gohr    // trigger event here
357016b6153SAndreas Gohr    trigger_event('TPL_METAHEADER_OUTPUT',$head,'_tpl_metaheaders_action',true);
35854e95700STom N Harris    return true;
3597bff22c0SAndreas Gohr}
3607bff22c0SAndreas Gohr
3617bff22c0SAndreas Gohr/**
3627bff22c0SAndreas Gohr * prints the array build by tpl_metaheaders
3637bff22c0SAndreas Gohr *
3647bff22c0SAndreas Gohr * $data is an array of different header tags. Each tag can have multiple
3657bff22c0SAndreas Gohr * instances. Attributes are given as key value pairs. Values will be HTML
3667bff22c0SAndreas Gohr * encoded automatically so they should be provided as is in the $data array.
3677bff22c0SAndreas Gohr *
3687bff22c0SAndreas Gohr * For tags having a body attribute specify the the body data in the special
3691304d1dbSAndreas Gohr * attribute '_data'. This field will NOT BE ESCAPED automatically.
3707bff22c0SAndreas Gohr *
3717bff22c0SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
3727bff22c0SAndreas Gohr */
3737bff22c0SAndreas Gohrfunction _tpl_metaheaders_action($data){
3747bff22c0SAndreas Gohr    foreach($data as $tag => $inst){
3757bff22c0SAndreas Gohr        foreach($inst as $attr){
3767bff22c0SAndreas Gohr            echo '<',$tag,' ',buildAttributes($attr);
37726afa874SMikhail I. Izmestev            if(isset($attr['_data']) || $tag == 'script'){
378e226efe1SAndreas Gohr                if($tag == 'script' && $attr['_data'])
379e226efe1SAndreas Gohr                    $attr['_data'] = "<!--//--><![CDATA[//><!--\n".
380e226efe1SAndreas Gohr                        $attr['_data'].
381e226efe1SAndreas Gohr                        "\n//--><!]]>";
382e226efe1SAndreas Gohr
3831304d1dbSAndreas Gohr                echo '>',$attr['_data'],'</',$tag,'>';
3847bff22c0SAndreas Gohr            }else{
3857bff22c0SAndreas Gohr                echo '/>';
3867bff22c0SAndreas Gohr            }
3877bff22c0SAndreas Gohr            echo "\n";
3887bff22c0SAndreas Gohr        }
3897bff22c0SAndreas Gohr    }
3906b13307fSandi}
3916b13307fSandi
3926b13307fSandi/**
3936b13307fSandi * Print a link
3946b13307fSandi *
3955e163278SAndreas Gohr * Just builds a link.
3966b13307fSandi *
3976b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
3986b13307fSandi */
3991af98a77SAnika Henkefunction tpl_link($url,$name,$more='',$return=false){
40001f17825SAnika Henke    $out = '<a href="'.$url.'" ';
4011af98a77SAnika Henke    if ($more) $out .= ' '.$more;
4021af98a77SAnika Henke    $out .= ">$name</a>";
4031af98a77SAnika Henke    if ($return) return $out;
4041af98a77SAnika Henke    print $out;
40554e95700STom N Harris    return true;
4066b13307fSandi}
4076b13307fSandi
4086b13307fSandi/**
40955efc227SAndreas Gohr * Prints a link to a WikiPage
41055efc227SAndreas Gohr *
41155efc227SAndreas Gohr * Wrapper around html_wikilink
41255efc227SAndreas Gohr *
41355efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
41455efc227SAndreas Gohr */
4150b17fdc6SAndreas Gohrfunction tpl_pagelink($id,$name=null){
41655efc227SAndreas Gohr    print html_wikilink($id,$name);
41754e95700STom N Harris    return true;
41855efc227SAndreas Gohr}
41955efc227SAndreas Gohr
42055efc227SAndreas Gohr/**
421a3ec5f4aSmatthiasgrimm * get the parent page
422a3ec5f4aSmatthiasgrimm *
423a3ec5f4aSmatthiasgrimm * Tries to find out which page is parent.
424a3ec5f4aSmatthiasgrimm * returns false if none is available
425a3ec5f4aSmatthiasgrimm *
426377f9e97SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
427a3ec5f4aSmatthiasgrimm */
428377f9e97SAndreas Gohrfunction tpl_getparent($id){
429a3ec5f4aSmatthiasgrimm    global $conf;
430377f9e97SAndreas Gohr    $parent = getNS($id).':';
431377f9e97SAndreas Gohr    resolve_pageid('',$parent,$exists);
432a197105eSmatthiasgrimm    if($parent == $id) {
433a197105eSmatthiasgrimm        $pos = strrpos (getNS($id),':');
434a197105eSmatthiasgrimm        $parent = substr($parent,0,$pos).':';
435a197105eSmatthiasgrimm        resolve_pageid('',$parent,$exists);
436377f9e97SAndreas Gohr        if($parent == $id) return false;
437a197105eSmatthiasgrimm    }
438377f9e97SAndreas Gohr    return $parent;
439a3ec5f4aSmatthiasgrimm}
440a3ec5f4aSmatthiasgrimm
441a3ec5f4aSmatthiasgrimm/**
4426b13307fSandi * Print one of the buttons
4436b13307fSandi *
4446b13307fSandi * Available Buttons are
4456b13307fSandi *
446ee4c4a1bSAndreas Gohr *  edit        - edit/create/show/draft button
4476b13307fSandi *  history     - old revisions
4486b13307fSandi *  recent      - recent changes
4496b13307fSandi *  login       - login/logout button - if ACL enabled
450d449b912SDenis Simakov *  profile     - user profile button (if logged in)
4516b13307fSandi *  index       - The index
452c19fe9c0Sandi *  admin       - admin page - if enough rights
4536b13307fSandi *  top         - a back to top button
454a3ec5f4aSmatthiasgrimm *  back        - a back to parent button - if available
455bbd37938SAndreas Gohr *  backlink    - links to the list of backlinks
456d449b912SDenis Simakov *  subscription- subscribe/unsubscribe button
4576b13307fSandi *
4586b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
459a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
4606b13307fSandi */
4611af98a77SAnika Henkefunction tpl_button($type,$return=false){
462b158d625SSteven Danz    global $ACT;
4636b13307fSandi    global $ID;
464d98d4540SBen Coburn    global $REV;
465d67ca2c0Smatthiasgrimm    global $NS;
466c19fe9c0Sandi    global $INFO;
4676b13307fSandi    global $conf;
468cd52f92dSchris    global $auth;
4696b13307fSandi
47075e487e9SAndreas Gohr    // check disabled actions and fix the badly named ones
47175e487e9SAndreas Gohr    $ctype = $type;
47275e487e9SAndreas Gohr    if($type == 'history') $ctype='revisions';
47354e95700STom N Harris    if(!actionOK($ctype)) return false;
474409d7af7SAndreas Gohr
4751af98a77SAnika Henke    $out = '';
4766b13307fSandi    switch($type){
4776b13307fSandi        case 'edit':
4780b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
479409d7af7SAndreas Gohr            if($ACT == 'show' || $ACT == 'search'){
480409d7af7SAndreas Gohr                if($INFO['writable']){
481bb4866bdSchris                    if(!empty($INFO['draft'])){
4821af98a77SAnika Henke                        $out .= html_btn('draft',$ID,'e',array('do' => 'draft'),'post');
483409d7af7SAndreas Gohr                    }else{
484409d7af7SAndreas Gohr                        if($INFO['exists']){
4851af98a77SAnika Henke                            $out .= html_btn('edit',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
486409d7af7SAndreas Gohr                        }else{
4871af98a77SAnika Henke                            $out .= html_btn('create',$ID,'e',array('do' => 'edit','rev' => $REV),'post');
488409d7af7SAndreas Gohr                        }
489409d7af7SAndreas Gohr                    }
490409d7af7SAndreas Gohr                }else{
491409d7af7SAndreas Gohr                    if(!actionOK('source')) return false; //pseudo action
4921af98a77SAnika Henke                    $out .= html_btn('source',$ID,'v',array('do' => 'edit','rev' => $REV),'post');
493409d7af7SAndreas Gohr                }
494409d7af7SAndreas Gohr            }else{
4951af98a77SAnika Henke                $out .= html_btn('show',$ID,'v',array('do' => 'show'));
496409d7af7SAndreas Gohr            }
4971af98a77SAnika Henke            break;
4986b13307fSandi        case 'history':
4991af98a77SAnika Henke            if(actionOK('revisions'))
5001af98a77SAnika Henke                $out .= html_btn('revs',$ID,'o',array('do' => 'revisions'));
5011af98a77SAnika Henke            break;
5026b13307fSandi        case 'recent':
5031af98a77SAnika Henke            if(actionOK('recent'))
5041af98a77SAnika Henke                $out .= html_btn('recent',$ID,'r',array('do' => 'recent'));
5051af98a77SAnika Henke            break;
5066b13307fSandi        case 'index':
5071af98a77SAnika Henke            if(actionOK('index'))
5081af98a77SAnika Henke                $out .= html_btn('index',$ID,'x',array('do' => 'index'));
5091af98a77SAnika Henke            break;
510a3ec5f4aSmatthiasgrimm        case 'back':
5116222040cSmatthiasgrimm            if ($parent = tpl_getparent($ID)) {
5121af98a77SAnika Henke                $out .= html_btn('back',$parent,'b',array('do' => 'show'));
513a3ec5f4aSmatthiasgrimm            }
5141af98a77SAnika Henke            break;
5156b13307fSandi        case 'top':
5161af98a77SAnika Henke            $out .= html_topbtn();
5171af98a77SAnika Henke            break;
5186b13307fSandi        case 'login':
5196957b2eaSAndreas Gohr            if($conf['useacl'] && $auth){
520c66972f2SAdrian Lang                if(isset($_SERVER['REMOTE_USER'])){
5211af98a77SAnika Henke                    $out .= html_btn('logout',$ID,'',array('do' => 'logout', 'sectok' => getSecurityToken()));
5226b13307fSandi                }else{
5231af98a77SAnika Henke                    $out .= html_btn('login',$ID,'',array('do' => 'login', 'sectok' => getSecurityToken()));
5246b13307fSandi                }
5256b13307fSandi            }
5261af98a77SAnika Henke            break;
527c19fe9c0Sandi        case 'admin':
52854e95700STom N Harris            if($INFO['ismanager']){
5291af98a77SAnika Henke                $out .= html_btn('admin',$ID,'',array('do' => 'admin'));
53054e95700STom N Harris            }
5311af98a77SAnika Henke            break;
5321246e016SAndreas Gohr        case 'revert':
5331246e016SAndreas Gohr            if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
5341246e016SAndreas Gohr                $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken()));
5351246e016SAndreas Gohr            }
5361246e016SAndreas Gohr            break;
537582c5bfeSAndreas Gohr        case 'subscribe':
5385b75cd1fSAdrian Lang            if ($conf['useacl'] && $auth && $ACT == 'show' &&
5395b75cd1fSAdrian Lang                    $conf['subscribers'] && isset($_SERVER['REMOTE_USER']) &&
5405b75cd1fSAdrian Lang                    actionOK('subscribe')) {
5411af98a77SAnika Henke                $out .= html_btn('subscribe',$ID,'',array('do' => 'subscribe',));
542582c5bfeSAndreas Gohr            }
5431af98a77SAnika Henke            break;
544f00151b4Schris        case 'backlink':
5451af98a77SAnika Henke            if(actionOK('backlink'))
5461af98a77SAnika Henke                $out .= html_btn('backlink',$ID,'',array('do' => 'backlink'));
5474c30ec5fSAndreas Gohr            break;
5488b06d178Schris        case 'profile':
549c66972f2SAdrian Lang            if($conf['useacl'] && isset($_SERVER['REMOTE_USER']) && $auth &&
55036223ba7SAndreas Gohr                    $auth->canDo('Profile') && ($ACT!='profile')){
5511af98a77SAnika Henke                $out .= html_btn('profile',$ID,'',array('do' => 'profile'));
5528b06d178Schris            }
5531af98a77SAnika Henke            break;
554c19fe9c0Sandi        default:
5551af98a77SAnika Henke            $out .= '[unknown button type]';
5561af98a77SAnika Henke            break;
5576b13307fSandi    }
5581af98a77SAnika Henke    if ($return) return $out;
5591af98a77SAnika Henke    print $out;
5601af98a77SAnika Henke    return $out ? true : false;
5616b13307fSandi}
5626b13307fSandi
5636b13307fSandi/**
564ed630903Sandi * Like the action buttons but links
565ed630903Sandi *
566ed630903Sandi * Available links are
567ed630903Sandi *
568d449b912SDenis Simakov *  edit    - edit/create/show link
569ed630903Sandi *  history - old revisions
570ed630903Sandi *  recent  - recent changes
571d449b912SDenis Simakov *  login   - login/logout link - if ACL enabled
572d449b912SDenis Simakov *  profile - user profile link (if logged in)
573ed630903Sandi *  index   - The index
574ed630903Sandi *  admin   - admin page - if enough rights
575d449b912SDenis Simakov *  top     - a back to top link
576d449b912SDenis Simakov *  back    - a back to parent link - if available
577bbd37938SAndreas Gohr *  backlink - links to the list of backlinks
578d449b912SDenis Simakov *  subscribe/subscription - subscribe/unsubscribe link
579ed630903Sandi *
580ed630903Sandi * @author Andreas Gohr <andi@splitbrain.org>
581a3ec5f4aSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
582ed630903Sandi * @see    tpl_button
583ed630903Sandi */
5841af98a77SAnika Henkefunction tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
585ed630903Sandi    global $ID;
586ed630903Sandi    global $INFO;
587ed630903Sandi    global $REV;
588ed630903Sandi    global $ACT;
589ed630903Sandi    global $conf;
590ed630903Sandi    global $lang;
591cd52f92dSchris    global $auth;
592ed630903Sandi
59375e487e9SAndreas Gohr    // check disabled actions and fix the badly named ones
59475e487e9SAndreas Gohr    $ctype = $type;
59575e487e9SAndreas Gohr    if($type == 'history') $ctype='revisions';
59654e95700STom N Harris    if(!actionOK($ctype)) return false;
597409d7af7SAndreas Gohr
5981af98a77SAnika Henke    $out = '';
599ed630903Sandi    switch($type){
600ed630903Sandi        case 'edit':
6010b17fdc6SAndreas Gohr            // most complicated type - we need to decide on current action
602ed630903Sandi            if($ACT == 'show' || $ACT == 'search'){
603ed630903Sandi                if($INFO['writable']){
604b8a111f5SMichael Klier                    if(!empty($INFO['draft'])) {
6051af98a77SAnika Henke                        $out .= tpl_link(wl($ID,'do=draft'),
606c97dfb07SAndreas Gohr                                $pre.(($inner)?$inner:$lang['btn_draft']).$suf,
6071af98a77SAnika Henke                                'class="action edit" accesskey="e" rel="nofollow"',1);
608b8a111f5SMichael Klier                    } else {
609ed630903Sandi                        if($INFO['exists']){
6101af98a77SAnika Henke                            $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
611c97dfb07SAndreas Gohr                                    $pre.(($inner)?$inner:$lang['btn_edit']).$suf,
6121af98a77SAnika Henke                                    'class="action edit" accesskey="e" rel="nofollow"',1);
613ed630903Sandi                        }else{
6141af98a77SAnika Henke                            $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
615c97dfb07SAndreas Gohr                                    $pre.(($inner)?$inner:$lang['btn_create']).$suf,
6161af98a77SAnika Henke                                    'class="action create" accesskey="e" rel="nofollow"',1);
617ed630903Sandi                        }
618b8a111f5SMichael Klier                    }
619ed630903Sandi                }else{
6201af98a77SAnika Henke                    if(actionOK('source')) //pseudo action
6211af98a77SAnika Henke                        $out .= tpl_link(wl($ID,'do=edit&amp;rev='.$REV),
622c97dfb07SAndreas Gohr                                $pre.(($inner)?$inner:$lang['btn_source']).$suf,
6231af98a77SAnika Henke                                'class="action source" accesskey="v" rel="nofollow"',1);
624ed630903Sandi                }
625ed630903Sandi            }else{
6264fc51abcSStephen Warren                $out .= tpl_link(wl($ID,''),
627c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_show']).$suf,
6281af98a77SAnika Henke                        'class="action show" accesskey="v" rel="nofollow"',1);
629ed630903Sandi            }
6301af98a77SAnika Henke            break;
631ed630903Sandi        case 'history':
6321af98a77SAnika Henke            if(actionOK('revisions'))
6331af98a77SAnika Henke                $out .= tpl_link(wl($ID,'do=revisions'),
634c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_revs']).$suf,
6351af98a77SAnika Henke                        'class="action revisions" accesskey="o" rel="nofollow"',1);
6361af98a77SAnika Henke            break;
637ed630903Sandi        case 'recent':
6381af98a77SAnika Henke            if(actionOK('recent'))
6391af98a77SAnika Henke                $out .= tpl_link(wl($ID,'do=recent'),
640c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_recent']).$suf,
6411af98a77SAnika Henke                        'class="action recent" accesskey="r" rel="nofollow"',1);
6421af98a77SAnika Henke            break;
643ed630903Sandi        case 'index':
6441af98a77SAnika Henke            if(actionOK('index'))
6451af98a77SAnika Henke                $out .= tpl_link(wl($ID,'do=index'),
646c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_index']).$suf,
6471af98a77SAnika Henke                        'class="action index" accesskey="x" rel="nofollow"',1);
6481af98a77SAnika Henke            break;
649ed630903Sandi        case 'top':
6501af98a77SAnika Henke            $out .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'.
651c97dfb07SAndreas Gohr                $pre.(($inner)?$inner:$lang['btn_top']).$suf.'</a>';
6521af98a77SAnika Henke            break;
653a3ec5f4aSmatthiasgrimm        case 'back':
654f7569b7bSAndreas Gohr            if ($parent = tpl_getparent($ID)) {
6554fc51abcSStephen Warren                $out .= tpl_link(wl($parent,''),
656c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_back']).$suf,
6571af98a77SAnika Henke                        'class="action back" accesskey="b" rel="nofollow"',1);
658a3ec5f4aSmatthiasgrimm            }
6591af98a77SAnika Henke            break;
660ed630903Sandi        case 'login':
6616957b2eaSAndreas Gohr            if($conf['useacl'] && $auth){
662ed630903Sandi                if($_SERVER['REMOTE_USER']){
6631af98a77SAnika Henke                    $out .= tpl_link(wl($ID,'do=logout&amp;sectok='.getSecurityToken()),
664c97dfb07SAndreas Gohr                            $pre.(($inner)?$inner:$lang['btn_logout']).$suf,
6651af98a77SAnika Henke                            'class="action logout" rel="nofollow"',1);
666ed630903Sandi                }else{
6671af98a77SAnika Henke                    $out .= tpl_link(wl($ID,'do=login&amp;sectok='.getSecurityToken()),
668c97dfb07SAndreas Gohr                            $pre.(($inner)?$inner:$lang['btn_login']).$suf,
6691af98a77SAnika Henke                            'class="action login" rel="nofollow"',1);
670ed630903Sandi                }
671ed630903Sandi            }
6721af98a77SAnika Henke            break;
673ed630903Sandi        case 'admin':
674f8cc712eSAndreas Gohr            if($INFO['ismanager']){
6751af98a77SAnika Henke                $out .= tpl_link(wl($ID,'do=admin'),
676c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_admin']).$suf,
6771af98a77SAnika Henke                        'class="action admin" rel="nofollow"',1);
678c059e1a6SAndreas Gohr            }
6791af98a77SAnika Henke            break;
6801246e016SAndreas Gohr        case 'revert':
6811246e016SAndreas Gohr            if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
6821246e016SAndreas Gohr                $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())),
6831246e016SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_revert']).$suf,
6841246e016SAndreas Gohr                        'class="action revert" rel="nofollow"',1);
6851246e016SAndreas Gohr            }
6861246e016SAndreas Gohr            break;
687f9eb5648Ssteven-danz        case 'subscribe':
688075f000fSChristopher Arndt        case 'subscription':
6895b75cd1fSAdrian Lang            if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']) {
690b158d625SSteven Danz                if($_SERVER['REMOTE_USER']){
6911af98a77SAnika Henke                    if(actionOK('subscribe'))
6921af98a77SAnika Henke                        $out .= tpl_link(wl($ID,'do=subscribe'),
693c97dfb07SAndreas Gohr                                $pre.(($inner)?$inner:$lang['btn_subscribe']).$suf,
6941af98a77SAnika Henke                                'class="action subscribe" rel="nofollow"',1);
695b158d625SSteven Danz                }
696b158d625SSteven Danz            }
6971af98a77SAnika Henke            break;
698f00151b4Schris        case 'backlink':
6991af98a77SAnika Henke            if(actionOK('backlink'))
7001af98a77SAnika Henke                $out .= tpl_link(wl($ID,'do=backlink'),
701c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_backlink']).$suf,
7021af98a77SAnika Henke                        'class="action backlink" rel="nofollow"',1);
7031af98a77SAnika Henke            break;
7048b06d178Schris        case 'profile':
7056957b2eaSAndreas Gohr            if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
70636223ba7SAndreas Gohr                    $auth->canDo('Profile') && ($ACT!='profile')){
7071af98a77SAnika Henke                $out .= tpl_link(wl($ID,'do=profile'),
708c97dfb07SAndreas Gohr                        $pre.(($inner)?$inner:$lang['btn_profile']).$suf,
7091af98a77SAnika Henke                        'class="action profile" rel="nofollow"',1);
7108b06d178Schris            }
7111af98a77SAnika Henke            break;
712ed630903Sandi        default:
7131af98a77SAnika Henke            $out .= '[unknown link type]';
7141af98a77SAnika Henke            break;
715ed630903Sandi    }
7161af98a77SAnika Henke    if ($return) return $out;
7171af98a77SAnika Henke    print $out;
7181af98a77SAnika Henke    return $out ? true : false;
719ed630903Sandi}
720ed630903Sandi
721ed630903Sandi/**
72201f17825SAnika Henke * Wrapper around tpl_button() and tpl_actionlink()
72301f17825SAnika Henke *
72401f17825SAnika Henke * @author Anika Henke <anika@selfthinker.org>
72501f17825SAnika Henke */
72601f17825SAnika Henkefunction tpl_action($type,$link=0,$wrapper=false,$return=false,$pre='',$suf='',$inner='') {
72701f17825SAnika Henke    $out = '';
72801f17825SAnika Henke    if ($link) $out .= tpl_actionlink($type,$pre,$suf,$inner,1);
72901f17825SAnika Henke    else $out .= tpl_button($type,1);
73001f17825SAnika Henke    if ($out && $wrapper) $out = "<$wrapper>$out</$wrapper>";
73101f17825SAnika Henke
73201f17825SAnika Henke    if ($return) return $out;
73301f17825SAnika Henke    print $out;
73401f17825SAnika Henke    return $out ? true : false;
73501f17825SAnika Henke}
73601f17825SAnika Henke
73701f17825SAnika Henke/**
7386b13307fSandi * Print the search form
7396b13307fSandi *
74072645b75SAndreas Gohr * If the first parameter is given a div with the ID 'qsearch_out' will
74172645b75SAndreas Gohr * be added which instructs the ajax pagequicksearch to kick in and place
74272645b75SAndreas Gohr * its output into this div. The second parameter controls the propritary
74372645b75SAndreas Gohr * attribute autocomplete. If set to false this attribute will be set with an
74472645b75SAndreas Gohr * value of "off" to instruct the browser to disable it's own built in
74572645b75SAndreas Gohr * autocompletion feature (MSIE and Firefox)
74672645b75SAndreas Gohr *
7476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7486b13307fSandi */
74972645b75SAndreas Gohrfunction tpl_searchform($ajax=true,$autocomplete=true){
7506b13307fSandi    global $lang;
751c1e3b7d9Smatthiasgrimm    global $ACT;
752ad4aaef7SAndreas Gohr    global $QUERY;
753c1e3b7d9Smatthiasgrimm
754670ff54eSchris    // don't print the search form if search action has been disabled
75554e95700STom N Harris    if (!actionOk('search')) return false;
756670ff54eSchris
7571dd0c202SAnika Henke    print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
7586b13307fSandi    print '<input type="hidden" name="do" value="search" />';
759c1e3b7d9Smatthiasgrimm    print '<input type="text" ';
760ad4aaef7SAndreas Gohr    if($ACT == 'search') print 'value="'.htmlspecialchars($QUERY).'" ';
76172645b75SAndreas Gohr    if(!$autocomplete) print 'autocomplete="off" ';
76207493d05SAnika Henke    print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';
76311ea018fSAndreas Gohr    print '<input type="submit" value="'.$lang['btn_search'].'" class="button" title="'.$lang['btn_search'].'" />';
76424a33b42SAndreas Gohr    if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
7654beabca9SAnika Henke    print '</div></form>';
76654e95700STom N Harris    return true;
7676b13307fSandi}
7686b13307fSandi
7696b13307fSandi/**
7706b13307fSandi * Print the breadcrumbs trace
7716b13307fSandi *
7726b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
7736b13307fSandi */
77454e95700STom N Harrisfunction tpl_breadcrumbs($sep='&raquo;'){
7756b13307fSandi    global $lang;
7766b13307fSandi    global $conf;
7776b13307fSandi
7786b13307fSandi    //check if enabled
77954e95700STom N Harris    if(!$conf['breadcrumbs']) return false;
7806b13307fSandi
7816b13307fSandi    $crumbs = breadcrumbs(); //setup crumb trace
782265e3787Sandi
7832979a10bSKatriel Traum    //reverse crumborder in right-to-left mode, add RLM character to fix heb/eng display mixups
7842979a10bSKatriel Traum    if($lang['direction'] == 'rtl') {
7852979a10bSKatriel Traum        $crumbs = array_reverse($crumbs,true);
7862979a10bSKatriel Traum        $crumbs_sep = ' &#8207;<span class="bcsep">'.$sep.'</span>&#8207; ';
7872979a10bSKatriel Traum    } else {
7882979a10bSKatriel Traum        $crumbs_sep = ' <span class="bcsep">'.$sep.'</span> ';
7892979a10bSKatriel Traum    }
790265e3787Sandi
79140eb54bbSjan    //render crumbs, highlight the last one
7921b6f3a44SAndreas Gohr    print '<span class="bchead">'.$lang['breadcrumb'].':</span>';
79340eb54bbSjan    $last = count($crumbs);
79440eb54bbSjan    $i = 0;
795a77f5846Sjan    foreach ($crumbs as $id => $name){
79640eb54bbSjan        $i++;
7972979a10bSKatriel Traum        echo $crumbs_sep;
79892795d04Sandi        if ($i == $last) print '<span class="curid">';
799e26fd1eeSAndreas Gohr        tpl_link(wl($id),hsc($name),'class="breadcrumbs" title="'.$id.'"');
80092795d04Sandi        if ($i == $last) print '</span>';
8016b13307fSandi    }
80254e95700STom N Harris    return true;
8036b13307fSandi}
8046b13307fSandi
8056b13307fSandi/**
8061734437eSandi * Hierarchical breadcrumbs
8071734437eSandi *
80831e187f8SSean Coates * This code was suggested as replacement for the usual breadcrumbs.
8091734437eSandi * It only makes sense with a deep site structure.
8101734437eSandi *
8111734437eSandi * @author Andreas Gohr <andi@splitbrain.org>
8126bd812dfSNigel McNie * @author Nigel McNie <oracle.shinoda@gmail.com>
81331e187f8SSean Coates * @author Sean Coates <sean@caedmon.net>
814f46c9e83SAnika Henke * @author <fredrik@averpil.com>
8156bd812dfSNigel McNie * @todo   May behave strangely in RTL languages
8161734437eSandi */
817796bafb3SAndreas Gohrfunction tpl_youarehere($sep=' &raquo; '){
8181734437eSandi    global $conf;
8191734437eSandi    global $ID;
8201734437eSandi    global $lang;
8211734437eSandi
82231e187f8SSean Coates    // check if enabled
82354e95700STom N Harris    if(!$conf['youarehere']) return false;
8241734437eSandi
8251734437eSandi    $parts = explode(':', $ID);
826796bafb3SAndreas Gohr    $count = count($parts);
8271734437eSandi
8283b437163SAlexey Torkhov    if($GLOBALS['ACT'] == 'search')
8293b437163SAlexey Torkhov    {
8303b437163SAlexey Torkhov        $parts = array($conf['start']);
8313b437163SAlexey Torkhov        $count = 1;
8323b437163SAlexey Torkhov    }
8333b437163SAlexey Torkhov
8341b6f3a44SAndreas Gohr    echo '<span class="bchead">'.$lang['youarehere'].': </span>';
8351734437eSandi
8361734437eSandi    // always print the startpage
837fe9ec250SChris Smith    $title = useHeading('navigation') ? p_get_first_heading($conf['start']) : $conf['start'];
838796bafb3SAndreas Gohr    if(!$title) $title = $conf['start'];
839e26fd1eeSAndreas Gohr    tpl_link(wl($conf['start']),hsc($title),'title="'.$conf['start'].'"');
840796bafb3SAndreas Gohr
841796bafb3SAndreas Gohr    // print intermediate namespace links
842796bafb3SAndreas Gohr    $part = '';
843796bafb3SAndreas Gohr    for($i=0; $i<$count - 1; $i++){
844796bafb3SAndreas Gohr        $part .= $parts[$i].':';
845796bafb3SAndreas Gohr        $page = $part;
846796bafb3SAndreas Gohr        resolve_pageid('',$page,$exists);
847796bafb3SAndreas Gohr        if ($page == $conf['start']) continue; // Skip startpage
848796bafb3SAndreas Gohr
849796bafb3SAndreas Gohr        // output
850796bafb3SAndreas Gohr        echo $sep;
851796bafb3SAndreas Gohr        if($exists){
852af03da1aSAndreas Gohr            $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
853e26fd1eeSAndreas Gohr            tpl_link(wl($page),hsc($title),'title="'.$page.'"');
85431e187f8SSean Coates        }else{
85578cbfcb6SAndreas Gohr            tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
85631e187f8SSean Coates        }
85731e187f8SSean Coates    }
8581734437eSandi
859796bafb3SAndreas Gohr    // print current page, skipping start page, skipping for namespace index
860d98d4540SBen Coburn    if(isset($page) && $page==$part.$parts[$i]) return;
861796bafb3SAndreas Gohr    $page = $part.$parts[$i];
862796bafb3SAndreas Gohr    if($page == $conf['start']) return;
863796bafb3SAndreas Gohr    echo $sep;
864103c256aSChris Smith    if(page_exists($page)){
865af03da1aSAndreas Gohr        $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i];
866e26fd1eeSAndreas Gohr        tpl_link(wl($page),hsc($title),'title="'.$page.'"');
86731e187f8SSean Coates    }else{
86878cbfcb6SAndreas Gohr        tpl_link(wl($page),$parts[$i],'title="'.$page.'" class="wikilink2" rel="nofollow"');
8691734437eSandi    }
87054e95700STom N Harris    return true;
8711734437eSandi}
8721734437eSandi
8731734437eSandi/**
8746b13307fSandi * Print info if the user is logged in
875a2488c3cSMatthias Grimm * and show full name in that case
8766b13307fSandi *
8776b13307fSandi * Could be enhanced with a profile link in future?
8786b13307fSandi *
8796b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
8806b13307fSandi */
8816b13307fSandifunction tpl_userinfo(){
8826b13307fSandi    global $lang;
8833e63b73bSMichael Klier    global $INFO;
884c66972f2SAdrian Lang    if(isset($_SERVER['REMOTE_USER'])){
8853e63b73bSMichael Klier        print $lang['loggedinas'].': '.$INFO['userinfo']['name'].' ('.$_SERVER['REMOTE_USER'].')';
88654e95700STom N Harris                return true;
88754e95700STom N Harris                }
88854e95700STom N Harris                return false;
8896b13307fSandi                }
8906b13307fSandi
8916b13307fSandi                /**
8926b13307fSandi                 * Print some info about the current page
8936b13307fSandi                 *
8946b13307fSandi                 * @author Andreas Gohr <andi@splitbrain.org>
8956b13307fSandi                 */
8964b0d3916SAndreas Gohr                function tpl_pageinfo($ret=false){
8976b13307fSandi                global $conf;
8986b13307fSandi                global $lang;
8996b13307fSandi                global $INFO;
900c6e92a3cSDavid Lorentsen                global $ID;
901c6e92a3cSDavid Lorentsen
902c6e92a3cSDavid Lorentsen                // return if we are not allowed to view the page
9034b0d3916SAndreas Gohr                if (!auth_quickaclcheck($ID)) { return false; }
9046b13307fSandi
9056b13307fSandi                // prepare date and path
9066b13307fSandi                $fn = $INFO['filepath'];
9076b13307fSandi                if(!$conf['fullpath']){
908613bca54SAndreas Gohr                    if($INFO['rev']){
90950fbebceSGina Haeussge                        $fn = str_replace(fullpath($conf['olddir']).'/','',$fn);
9106b13307fSandi                    }else{
91150fbebceSGina Haeussge                        $fn = str_replace(fullpath($conf['datadir']).'/','',$fn);
9126b13307fSandi                    }
9136b13307fSandi                }
914bee6dc82Sandi                $fn = utf8_decodeFN($fn);
915f2263577SAndreas Gohr                $date = dformat($INFO['lastmod']);
9166b13307fSandi
917faecdfdfSAndreas Gohr                // print it
918faecdfdfSAndreas Gohr                if($INFO['exists']){
9194b0d3916SAndreas Gohr                    $out = '';
9204b0d3916SAndreas Gohr                    $out .= $fn;
9214b0d3916SAndreas Gohr                    $out .= ' &middot; ';
9224b0d3916SAndreas Gohr                    $out .= $lang['lastmod'];
9234b0d3916SAndreas Gohr                    $out .= ': ';
9244b0d3916SAndreas Gohr                    $out .= $date;
9256b13307fSandi                    if($INFO['editor']){
9264b0d3916SAndreas Gohr                        $out .= ' '.$lang['by'].' ';
927dc58b6f4SAndy Webber                        $out .= editorinfo($INFO['editor']);
9285aa52fafSBen Coburn                    }else{
9294b0d3916SAndreas Gohr                        $out .= ' ('.$lang['external_edit'].')';
9306b13307fSandi                                }
9316b13307fSandi                                if($INFO['locked']){
9324b0d3916SAndreas Gohr                                $out .= ' &middot; ';
9334b0d3916SAndreas Gohr                                $out .= $lang['lockedby'];
9344b0d3916SAndreas Gohr                                $out .= ': ';
935dc58b6f4SAndy Webber                                $out .= editorinfo($INFO['locked']);
9366b13307fSandi                                }
9374b0d3916SAndreas Gohr                                if($ret){
9384b0d3916SAndreas Gohr                                return $out;
9394b0d3916SAndreas Gohr                                }else{
9404b0d3916SAndreas Gohr                                echo $out;
94154e95700STom N Harris                                return true;
9426b13307fSandi                                }
9434b0d3916SAndreas Gohr                                }
94454e95700STom N Harris                                return false;
9456b13307fSandi                                }
9466b13307fSandi
947820fa24bSandi                                /**
948a6598f23SBen Coburn                                 * Prints or returns the name of the given page (current one if none given).
94987c434ceSAndreas Gohr                                 *
95087c434ceSAndreas Gohr                                 * If useheading is enabled this will use the first headline else
951a6598f23SBen Coburn                                 * the given ID is used.
95287c434ceSAndreas Gohr                                 *
95387c434ceSAndreas Gohr                                 * @author Andreas Gohr <andi@splitbrain.org>
95487c434ceSAndreas Gohr                                 */
955a6598f23SBen Coburnfunction tpl_pagetitle($id=null, $ret=false){
95687c434ceSAndreas Gohr    global $conf;
95787c434ceSAndreas Gohr    if(is_null($id)){
95887c434ceSAndreas Gohr        global $ID;
95987c434ceSAndreas Gohr        $id = $ID;
96087c434ceSAndreas Gohr    }
96187c434ceSAndreas Gohr
96287c434ceSAndreas Gohr    $name = $id;
963fe9ec250SChris Smith    if (useHeading('navigation')) {
96487c434ceSAndreas Gohr        $title = p_get_first_heading($id);
96587c434ceSAndreas Gohr        if ($title) $name = $title;
96687c434ceSAndreas Gohr    }
967a6598f23SBen Coburn
968a6598f23SBen Coburn    if ($ret) {
969a6598f23SBen Coburn        return hsc($name);
970a6598f23SBen Coburn    } else {
97187c434ceSAndreas Gohr        print hsc($name);
97254e95700STom N Harris        return true;
97387c434ceSAndreas Gohr    }
974a6598f23SBen Coburn}
975340756e4Sandi
97655efc227SAndreas Gohr/**
97755efc227SAndreas Gohr * Returns the requested EXIF/IPTC tag from the current image
97855efc227SAndreas Gohr *
97955efc227SAndreas Gohr * If $tags is an array all given tags are tried until a
98055efc227SAndreas Gohr * value is found. If no value is found $alt is returned.
98155efc227SAndreas Gohr *
98255efc227SAndreas Gohr * Which texts are known is defined in the functions _exifTagNames
98355efc227SAndreas Gohr * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC
98455efc227SAndreas Gohr * to the names of the latter one)
98555efc227SAndreas Gohr *
9863df72098SAndreas Gohr * Only allowed in: detail.php
98755efc227SAndreas Gohr *
98855efc227SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
98955efc227SAndreas Gohr */
9903df72098SAndreas Gohrfunction tpl_img_getTag($tags,$alt='',$src=null){
99155efc227SAndreas Gohr    // Init Exif Reader
99255efc227SAndreas Gohr    global $SRC;
9933df72098SAndreas Gohr
9943df72098SAndreas Gohr    if(is_null($src)) $src = $SRC;
9953df72098SAndreas Gohr
99655efc227SAndreas Gohr    static $meta = null;
9973df72098SAndreas Gohr    if(is_null($meta)) $meta = new JpegMeta($src);
99855efc227SAndreas Gohr    if($meta === false) return $alt;
99955efc227SAndreas Gohr    $info = $meta->getField($tags);
100055efc227SAndreas Gohr    if($info == false) return $alt;
100155efc227SAndreas Gohr    return $info;
100255efc227SAndreas Gohr}
100355efc227SAndreas Gohr
100455efc227SAndreas Gohr/**
100555efc227SAndreas Gohr * Prints the image with a link to the full sized version
100655efc227SAndreas Gohr *
100755efc227SAndreas Gohr * Only allowed in: detail.php
100855efc227SAndreas Gohr */
1009f8925855Sjoe.lappfunction tpl_img($maxwidth=0,$maxheight=0){
101055efc227SAndreas Gohr    global $IMG;
101155efc227SAndreas Gohr    $w = tpl_img_getTag('File.Width');
101255efc227SAndreas Gohr    $h = tpl_img_getTag('File.Height');
101355efc227SAndreas Gohr
101455efc227SAndreas Gohr    //resize to given max values
101523a34783SAndreas Gohr    $ratio = 1;
101623a34783SAndreas Gohr    if($w >= $h){
1017f8925855Sjoe.lapp        if($maxwidth && $w >= $maxwidth){
101855efc227SAndreas Gohr            $ratio = $maxwidth/$w;
1019f8925855Sjoe.lapp        }elseif($maxheight && $h > $maxheight){
102055efc227SAndreas Gohr            $ratio = $maxheight/$h;
102155efc227SAndreas Gohr        }
102255efc227SAndreas Gohr    }else{
1023f8925855Sjoe.lapp        if($maxheight && $h >= $maxheight){
102455efc227SAndreas Gohr            $ratio = $maxheight/$h;
1025f8925855Sjoe.lapp        }elseif($maxwidth && $w > $maxwidth){
102655efc227SAndreas Gohr            $ratio = $maxwidth/$w;
102755efc227SAndreas Gohr        }
102855efc227SAndreas Gohr    }
102955efc227SAndreas Gohr    if($ratio){
103055efc227SAndreas Gohr        $w = floor($ratio*$w);
103155efc227SAndreas Gohr        $h = floor($ratio*$h);
103255efc227SAndreas Gohr    }
103355efc227SAndreas Gohr
10346de3759aSAndreas Gohr    //prepare URLs
10356de3759aSAndreas Gohr    $url=ml($IMG,array('cache'=>$_REQUEST['cache']));
10366de3759aSAndreas Gohr    $src=ml($IMG,array('cache'=>$_REQUEST['cache'],'w'=>$w,'h'=>$h));
103755efc227SAndreas Gohr
10382684e50aSAndreas Gohr    //prepare attributes
103955efc227SAndreas Gohr    $alt=tpl_img_getTag('Simple.Title');
10402684e50aSAndreas Gohr    $p = array();
10412684e50aSAndreas Gohr    if($w) $p['width']  = $w;
10422684e50aSAndreas Gohr    if($h) $p['height'] = $h;
10432684e50aSAndreas Gohr    $p['class']  = 'img_detail';
10442684e50aSAndreas Gohr    if($alt){
10452684e50aSAndreas Gohr        $p['alt']   = $alt;
10462684e50aSAndreas Gohr        $p['title'] = $alt;
10472684e50aSAndreas Gohr    }else{
10482684e50aSAndreas Gohr        $p['alt'] = '';
10492684e50aSAndreas Gohr    }
10502684e50aSAndreas Gohr    $p = buildAttributes($p);
105155efc227SAndreas Gohr
105255efc227SAndreas Gohr    print '<a href="'.$url.'">';
10536de3759aSAndreas Gohr    print '<img src="'.$src.'" '.$p.'/>';
105455efc227SAndreas Gohr    print '</a>';
105554e95700STom N Harris    return true;
105655efc227SAndreas Gohr}
105755efc227SAndreas Gohr
10587367b368SAndreas Gohr/**
10597367b368SAndreas Gohr * This function inserts a 1x1 pixel gif which in reality
1060c66972f2SAdrian Lang * is the indexer function.
10617367b368SAndreas Gohr *
10627367b368SAndreas Gohr * Should be called somewhere at the very end of the main.php
10637367b368SAndreas Gohr * template
10647367b368SAndreas Gohr */
10657367b368SAndreas Gohrfunction tpl_indexerWebBug(){
10667367b368SAndreas Gohr    global $ID;
10671dad36f5SAndreas Gohr    global $INFO;
106854e95700STom N Harris    if(!$INFO['exists']) return false;
10691dad36f5SAndreas Gohr
107054e95700STom N Harris    if(isHiddenPage($ID)) return false; //no need to index hidden pages
10710dc92c6fSAndreas Gohr
10727367b368SAndreas Gohr    $p = array();
1073b6c6979fSAndreas Gohr    $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.rawurlencode($ID).
1074e68c51baSAndreas Gohr        '&'.time();
10757367b368SAndreas Gohr    $p['width']  = 1;
10767367b368SAndreas Gohr    $p['height'] = 1;
10777367b368SAndreas Gohr    $p['alt']    = '';
10787367b368SAndreas Gohr    $att = buildAttributes($p);
10797367b368SAndreas Gohr    print "<img $att />";
108054e95700STom N Harris    return true;
10817367b368SAndreas Gohr}
10827367b368SAndreas Gohr
108378d4e784SEsther Brunner// configuration methods
108478d4e784SEsther Brunner/**
108578d4e784SEsther Brunner * tpl_getConf($id)
108678d4e784SEsther Brunner *
108778d4e784SEsther Brunner * use this function to access template configuration variables
108878d4e784SEsther Brunner */
108978d4e784SEsther Brunnerfunction tpl_getConf($id){
109078d4e784SEsther Brunner    global $conf;
109178d4e784SEsther Brunner    global $tpl_configloaded;
109278d4e784SEsther Brunner
109378d4e784SEsther Brunner    $tpl = $conf['template'];
109478d4e784SEsther Brunner
109578d4e784SEsther Brunner    if (!$tpl_configloaded){
109678d4e784SEsther Brunner        $tconf = tpl_loadConfig();
109778d4e784SEsther Brunner        if ($tconf !== false){
109878d4e784SEsther Brunner            foreach ($tconf as $key => $value){
109978d4e784SEsther Brunner                if (isset($conf['tpl'][$tpl][$key])) continue;
110078d4e784SEsther Brunner                $conf['tpl'][$tpl][$key] = $value;
110178d4e784SEsther Brunner            }
110278d4e784SEsther Brunner            $tpl_configloaded = true;
110378d4e784SEsther Brunner        }
110478d4e784SEsther Brunner    }
110578d4e784SEsther Brunner
110678d4e784SEsther Brunner    return $conf['tpl'][$tpl][$id];
110778d4e784SEsther Brunner}
110878d4e784SEsther Brunner
110978d4e784SEsther Brunner/**
111078d4e784SEsther Brunner * tpl_loadConfig()
111178d4e784SEsther Brunner * reads all template configuration variables
111278d4e784SEsther Brunner * this function is automatically called by tpl_getConf()
111378d4e784SEsther Brunner */
111478d4e784SEsther Brunnerfunction tpl_loadConfig(){
111578d4e784SEsther Brunner
111678d4e784SEsther Brunner    $file = DOKU_TPLINC.'/conf/default.php';
111778d4e784SEsther Brunner    $conf = array();
111878d4e784SEsther Brunner
111978d4e784SEsther Brunner    if (!@file_exists($file)) return false;
112078d4e784SEsther Brunner
112178d4e784SEsther Brunner    // load default config file
112278d4e784SEsther Brunner    include($file);
112378d4e784SEsther Brunner
112478d4e784SEsther Brunner    return $conf;
112578d4e784SEsther Brunner}
112678d4e784SEsther Brunner
11273df72098SAndreas Gohr/**
11283df72098SAndreas Gohr * prints the "main content" in the mediamanger popup
11293df72098SAndreas Gohr *
11303df72098SAndreas Gohr * Depending on the user's actions this may be a list of
11313df72098SAndreas Gohr * files in a namespace, the meta editing dialog or
11323df72098SAndreas Gohr * a message of referencing pages
11333df72098SAndreas Gohr *
11343df72098SAndreas Gohr * Only allowed in mediamanager.php
11353df72098SAndreas Gohr *
1136c182313eSAndreas Gohr * @triggers MEDIAMANAGER_CONTENT_OUTPUT
1137c182313eSAndreas Gohr * @param bool $fromajax - set true when calling this function via ajax
11383df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11393df72098SAndreas Gohr */
1140c182313eSAndreas Gohrfunction tpl_mediaContent($fromajax=false){
11413df72098SAndreas Gohr    global $IMG;
11423df72098SAndreas Gohr    global $AUTH;
11433df72098SAndreas Gohr    global $INUSE;
11443df72098SAndreas Gohr    global $NS;
11453df72098SAndreas Gohr    global $JUMPTO;
11463df72098SAndreas Gohr
1147c9f56829SAndreas Gohr    if(is_array($_REQUEST['do'])){
1148c9f56829SAndreas Gohr        $do = array_shift(array_keys($_REQUEST['do']));
11493df72098SAndreas Gohr    }else{
1150c182313eSAndreas Gohr        $do = $_REQUEST['do'];
11513df72098SAndreas Gohr    }
1152c182313eSAndreas Gohr    if(in_array($do,array('save','cancel'))) $do = '';
1153c182313eSAndreas Gohr
1154c182313eSAndreas Gohr    if(!$do){
1155c182313eSAndreas Gohr        if($_REQUEST['edit']){
1156c182313eSAndreas Gohr            $do = 'metaform';
1157c182313eSAndreas Gohr        }elseif(is_array($INUSE)){
1158c182313eSAndreas Gohr            $do = 'filesinuse';
1159c182313eSAndreas Gohr        }else{
1160c182313eSAndreas Gohr            $do = 'filelist';
1161c182313eSAndreas Gohr        }
1162c182313eSAndreas Gohr    }
1163c182313eSAndreas Gohr
1164c182313eSAndreas Gohr    // output the content pane, wrapped in an event.
1165c182313eSAndreas Gohr    if(!$fromajax) ptln('<div id="media__content">');
1166c182313eSAndreas Gohr    $data = array( 'do' => $do);
1167c182313eSAndreas Gohr    $evt = new Doku_Event('MEDIAMANAGER_CONTENT_OUTPUT', $data);
1168c182313eSAndreas Gohr    if ($evt->advise_before()) {
1169c182313eSAndreas Gohr        $do = $data['do'];
1170c182313eSAndreas Gohr        if($do == 'metaform'){
1171c182313eSAndreas Gohr            media_metaform($IMG,$AUTH);
1172c182313eSAndreas Gohr        }elseif($do == 'filesinuse'){
1173c182313eSAndreas Gohr            media_filesinuse($INUSE,$IMG);
1174c182313eSAndreas Gohr        }elseif($do == 'filelist'){
1175c182313eSAndreas Gohr            media_filelist($NS,$AUTH,$JUMPTO);
1176c9f56829SAndreas Gohr        }elseif($do == 'searchlist'){
1177c9f56829SAndreas Gohr            media_searchlist($_REQUEST['q'],$NS,$AUTH);
1178c182313eSAndreas Gohr        }else{
1179c182313eSAndreas Gohr            msg('Unknown action '.hsc($do),-1);
1180c182313eSAndreas Gohr        }
1181c182313eSAndreas Gohr    }
1182c182313eSAndreas Gohr    $evt->advise_after();
1183c182313eSAndreas Gohr    unset($evt);
1184c182313eSAndreas Gohr    if(!$fromajax) ptln('</div>');
1185c182313eSAndreas Gohr
11863df72098SAndreas Gohr}
11873df72098SAndreas Gohr
11883df72098SAndreas Gohr/**
11893df72098SAndreas Gohr * prints the namespace tree in the mediamanger popup
11903df72098SAndreas Gohr *
11913df72098SAndreas Gohr * Only allowed in mediamanager.php
11923df72098SAndreas Gohr *
11933df72098SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
11943df72098SAndreas Gohr */
11953df72098SAndreas Gohrfunction tpl_mediaTree(){
11963df72098SAndreas Gohr    global $NS;
11973df72098SAndreas Gohr
11983df72098SAndreas Gohr    ptln('<div id="media__tree">');
11993df72098SAndreas Gohr    media_nstree($NS);
12003df72098SAndreas Gohr    ptln('</div>');
12013df72098SAndreas Gohr}
12023df72098SAndreas Gohr
1203a00de5b5SAndreas Gohr
1204a00de5b5SAndreas Gohr/**
1205a00de5b5SAndreas Gohr * Print a dropdown menu with all DokuWiki actions
1206a00de5b5SAndreas Gohr *
1207a00de5b5SAndreas Gohr * Note: this will not use any pretty URLs
1208a00de5b5SAndreas Gohr *
1209a00de5b5SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1210a00de5b5SAndreas Gohr */
1211a00de5b5SAndreas Gohrfunction tpl_actiondropdown($empty='',$button='&gt;'){
1212a00de5b5SAndreas Gohr    global $ID;
1213a00de5b5SAndreas Gohr    global $INFO;
1214a00de5b5SAndreas Gohr    global $REV;
1215a00de5b5SAndreas Gohr    global $ACT;
1216a00de5b5SAndreas Gohr    global $conf;
1217a00de5b5SAndreas Gohr    global $lang;
1218a00de5b5SAndreas Gohr    global $auth;
1219a00de5b5SAndreas Gohr
1220a00de5b5SAndreas Gohr    echo '<form method="post" accept-charset="utf-8">'; #FIXME action
1221a00de5b5SAndreas Gohr        echo '<input type="hidden" name="id" value="'.$ID.'" />';
1222a00de5b5SAndreas Gohr    if($REV) echo '<input type="hidden" name="rev" value="'.$REV.'" />';
1223a00de5b5SAndreas Gohr    echo '<input type="hidden" name="sectok" value="'.getSecurityToken().'" />';
1224a00de5b5SAndreas Gohr
1225a00de5b5SAndreas Gohr    echo '<select name="do" id="action__selector" class="edit">';
1226a00de5b5SAndreas Gohr    echo '<option value="">'.$empty.'</option>';
1227a00de5b5SAndreas Gohr
1228a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1229a00de5b5SAndreas Gohr    // 'edit' - most complicated type, we need to decide on current action
1230a00de5b5SAndreas Gohr    if($ACT == 'show' || $ACT == 'search'){
1231a00de5b5SAndreas Gohr        if($INFO['writable']){
1232a00de5b5SAndreas Gohr            if(!empty($INFO['draft'])) {
1233a00de5b5SAndreas Gohr                echo '<option value="edit">'.$lang['btn_draft'].'</option>';
1234a00de5b5SAndreas Gohr            } else {
1235a00de5b5SAndreas Gohr                if($INFO['exists']){
1236a00de5b5SAndreas Gohr                    echo '<option value="edit">'.$lang['btn_edit'].'</option>';
1237a00de5b5SAndreas Gohr                }else{
1238a00de5b5SAndreas Gohr                    echo '<option value="edit">'.$lang['btn_create'].'</option>';
1239a00de5b5SAndreas Gohr                }
1240a00de5b5SAndreas Gohr            }
1241a00de5b5SAndreas Gohr        }else if(actionOK('source')) { //pseudo action
1242a00de5b5SAndreas Gohr            echo '<option value="edit">'.$lang['btn_source'].'</option>';
1243a00de5b5SAndreas Gohr        }
1244a00de5b5SAndreas Gohr    }else{
1245a00de5b5SAndreas Gohr        echo '<option value="show">'.$lang['btn_show'].'</option>';
1246a00de5b5SAndreas Gohr    }
1247a00de5b5SAndreas Gohr
1248a00de5b5SAndreas Gohr    echo '<option value="revisions">'.$lang['btn_revs'].'</option>';
12491246e016SAndreas Gohr    if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
12501246e016SAndreas Gohr        echo '<option value="revert">'.$lang['btn_revert'].'</option>';
12511246e016SAndreas Gohr    }
1252a00de5b5SAndreas Gohr    echo '<option value="backlink">'.$lang['btn_backlink'].'</option>';
1253a00de5b5SAndreas Gohr    echo '</optgroup>';
1254a00de5b5SAndreas Gohr
1255a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1256a00de5b5SAndreas Gohr    echo '<option value="recent">'.$lang['btn_recent'].'</option>';
1257a00de5b5SAndreas Gohr    echo '<option value="index">'.$lang['btn_index'].'</option>';
1258a00de5b5SAndreas Gohr    echo '</optgroup>';
1259a00de5b5SAndreas Gohr
1260a00de5b5SAndreas Gohr    echo '<optgroup label=" &mdash; ">';
1261a00de5b5SAndreas Gohr    if($conf['useacl'] && $auth){
1262a00de5b5SAndreas Gohr        if($_SERVER['REMOTE_USER']){
1263a00de5b5SAndreas Gohr            echo '<option value="logout">'.$lang['btn_logout'].'</option>';
1264a00de5b5SAndreas Gohr        }else{
1265a00de5b5SAndreas Gohr            echo '<option value="login">'.$lang['btn_login'].'</option>';
1266a00de5b5SAndreas Gohr        }
1267a00de5b5SAndreas Gohr    }
1268a00de5b5SAndreas Gohr
1269a00de5b5SAndreas Gohr    if($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] &&
1270a00de5b5SAndreas Gohr            $auth->canDo('Profile') && ($ACT!='profile')){
1271a00de5b5SAndreas Gohr        echo '<option value="profile">'.$lang['btn_profile'].'</option>';
1272a00de5b5SAndreas Gohr    }
1273a00de5b5SAndreas Gohr
12745b75cd1fSAdrian Lang    if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers']){
1275a00de5b5SAndreas Gohr        if($_SERVER['REMOTE_USER']){
1276a00de5b5SAndreas Gohr            echo '<option value="subscribe">'.$lang['btn_subscribe'].'</option>';
1277a00de5b5SAndreas Gohr        }
1278a00de5b5SAndreas Gohr    }
1279a00de5b5SAndreas Gohr
1280a00de5b5SAndreas Gohr    if($INFO['ismanager']){
1281a00de5b5SAndreas Gohr        echo '<option value="admin">'.$lang['btn_admin'].'</option>';
1282a00de5b5SAndreas Gohr    }
1283a00de5b5SAndreas Gohr    echo '</optgroup>';
1284a00de5b5SAndreas Gohr
1285a00de5b5SAndreas Gohr    echo '</select>';
1286a00de5b5SAndreas Gohr    echo '<input type="submit" value="'.$button.'" id="action__selectorbtn" />';
1287a00de5b5SAndreas Gohr    echo '</form>';
1288a00de5b5SAndreas Gohr}
1289a00de5b5SAndreas Gohr
1290066fee30SAndreas Gohr/**
1291066fee30SAndreas Gohr * Print a informational line about the used license
1292066fee30SAndreas Gohr *
1293066fee30SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1294066fee30SAndreas Gohr * @param  string $img    - print image? (|button|badge)
1295066fee30SAndreas Gohr * @param  bool   $return - when true don't print, but return HTML
1296066fee30SAndreas Gohr */
12974cefd216SMichael Klierfunction tpl_license($img='badge',$imgonly=false,$return=false){
1298066fee30SAndreas Gohr    global $license;
1299066fee30SAndreas Gohr    global $conf;
1300066fee30SAndreas Gohr    global $lang;
1301066fee30SAndreas Gohr    if(!$conf['license']) return '';
1302066fee30SAndreas Gohr    if(!is_array($license[$conf['license']])) return '';
1303066fee30SAndreas Gohr    $lic = $license[$conf['license']];
1304066fee30SAndreas Gohr
13054cefd216SMichael Klier    $out  = '<div class="license">';
1306066fee30SAndreas Gohr    if($img){
1307066fee30SAndreas Gohr        $src = license_img($img);
1308066fee30SAndreas Gohr        if($src){
1309066fee30SAndreas Gohr            $out .= '<a href="'.$lic['url'].'" rel="license"';
1310*84645d8cSAndreas Gohr            if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1311a57c7cafSAnika Henke            $out .= '><img src="'.DOKU_BASE.$src.'" class="medialeft lic'.$img.'" alt="'.$lic['name'].'" /></a> ';
1312066fee30SAndreas Gohr        }
1313066fee30SAndreas Gohr    }
13144cefd216SMichael Klier    if(!$imgonly) {
1315066fee30SAndreas Gohr        $out .= $lang['license'];
1316066fee30SAndreas Gohr        $out .= '<a href="'.$lic['url'].'" rel="license" class="urlextern"';
1317*84645d8cSAndreas Gohr        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1318066fee30SAndreas Gohr        $out .= '>'.$lic['name'].'</a>';
13194cefd216SMichael Klier    }
1320c2a66484SKazutaka Miyasaka    $out .= '</div>';
1321066fee30SAndreas Gohr
1322066fee30SAndreas Gohr    if($return) return $out;
1323066fee30SAndreas Gohr    echo $out;
1324066fee30SAndreas Gohr}
1325066fee30SAndreas Gohr
1326a81910eeSAndreas Gohr
1327a81910eeSAndreas Gohr/**
1328a81910eeSAndreas Gohr * Includes the rendered XHTML of a given page
1329a81910eeSAndreas Gohr *
1330a81910eeSAndreas Gohr * This function is useful to populate sidebars or similar features in a
1331a81910eeSAndreas Gohr * template
1332a81910eeSAndreas Gohr */
1333a81910eeSAndreas Gohrfunction tpl_include_page($pageid,$print=true){
1334a81910eeSAndreas Gohr    global $ID;
1335a81910eeSAndreas Gohr    $oldid = $ID;
1336a81910eeSAndreas Gohr    $html = p_wiki_xhtml($pageid,'',false);
1337a81910eeSAndreas Gohr    $ID = $oldid;
1338a81910eeSAndreas Gohr
1339a81910eeSAndreas Gohr    if(!$print) return $html;
1340a81910eeSAndreas Gohr    echo $html;
1341a81910eeSAndreas Gohr}
1342a81910eeSAndreas Gohr
13435b75cd1fSAdrian Lang/**
13445b75cd1fSAdrian Lang * Display the subscribe form
13455b75cd1fSAdrian Lang *
13465b75cd1fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
13475b75cd1fSAdrian Lang */
13485b75cd1fSAdrian Langfunction tpl_subscribe() {
13495b75cd1fSAdrian Lang    global $INFO;
13505b75cd1fSAdrian Lang    global $ID;
13515b75cd1fSAdrian Lang    global $lang;
13525b75cd1fSAdrian Lang
13535b75cd1fSAdrian Lang    echo p_locale_xhtml('subscr_form');
13545b75cd1fSAdrian Lang    echo '<h2>' . $lang['subscr_m_current_header'] . '</h2>';
135515741132SAndreas Gohr    echo '<div class="level2">';
13565b75cd1fSAdrian Lang    if ($INFO['subscribed'] === false) {
13575b75cd1fSAdrian Lang        echo '<p>' . $lang['subscr_m_not_subscribed'] . '</p>';
13585b75cd1fSAdrian Lang    } else {
13595b75cd1fSAdrian Lang        echo '<ul>';
13605b75cd1fSAdrian Lang        foreach($INFO['subscribed'] as $sub) {
1361056c2049SAndreas Gohr            echo '<li><div class="li">';
13625b75cd1fSAdrian Lang            if ($sub['target'] !== $ID) {
1363056c2049SAndreas Gohr                echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
13645b75cd1fSAdrian Lang            } else {
1365056c2049SAndreas Gohr                echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
13665b75cd1fSAdrian Lang            }
136715741132SAndreas Gohr            $sstl = $lang['subscr_style_'.$sub['style']];
136815741132SAndreas Gohr            if(!$sstl) $sstl = hsc($sub['style']);
1369056c2049SAndreas Gohr            echo ' ('.$sstl.') ';
137015741132SAndreas Gohr
137166d2bed9SAdrian Lang            echo '<a href="' . wl($ID,
137266d2bed9SAdrian Lang                                  array('do'=>'subscribe',
137366d2bed9SAdrian Lang                                        'sub_target'=>$sub['target'],
137466d2bed9SAdrian Lang                                        'sub_style'=>$sub['style'],
137566d2bed9SAdrian Lang                                        'sub_action'=>'unsubscribe',
137666d2bed9SAdrian Lang                                        'sectok' => getSecurityToken())) .
137766d2bed9SAdrian Lang                 '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'] .
137866d2bed9SAdrian Lang                 '</a></div></li>';
13795b75cd1fSAdrian Lang        }
13805b75cd1fSAdrian Lang        echo '</ul>';
13815b75cd1fSAdrian Lang    }
138215741132SAndreas Gohr    echo '</div>';
13835b75cd1fSAdrian Lang
138415741132SAndreas Gohr    // Add new subscription form
13855b75cd1fSAdrian Lang    echo '<h2>' . $lang['subscr_m_new_header'] . '</h2>';
138615741132SAndreas Gohr    echo '<div class="level2">';
13875b75cd1fSAdrian Lang    $ns = getNS($ID).':';
138815741132SAndreas Gohr    $targets = array(
138915741132SAndreas Gohr            $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
139015741132SAndreas Gohr            $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
139115741132SAndreas Gohr            );
139215741132SAndreas Gohr    $styles = array(
139315741132SAndreas Gohr            'every'  => $lang['subscr_style_every'],
139415741132SAndreas Gohr            'digest' => $lang['subscr_style_digest'],
139515741132SAndreas Gohr            'list'   => $lang['subscr_style_list'],
139615741132SAndreas Gohr            );
139715741132SAndreas Gohr
1398056c2049SAndreas Gohr    $form = new Doku_Form(array('id' => 'subscribe__form'));
1399056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_subscribe']);
1400056c2049SAndreas Gohr    $form->addRadioSet('sub_target', $targets);
1401056c2049SAndreas Gohr    $form->startFieldset($lang['subscr_m_receive']);
1402056c2049SAndreas Gohr    $form->addRadioSet('sub_style', $styles);
1403056c2049SAndreas Gohr    $form->addHidden('sub_action', 'subscribe');
1404056c2049SAndreas Gohr    $form->addHidden('do', 'subscribe');
1405056c2049SAndreas Gohr    $form->addHidden('id', $ID);
1406056c2049SAndreas Gohr    $form->endFieldset();
14075b75cd1fSAdrian Lang    $form->addElement(form_makeButton('submit', 'subscribe', $lang['subscr_m_subscribe']));
14085b75cd1fSAdrian Lang    html_form('SUBSCRIBE', $form);
140915741132SAndreas Gohr    echo '</div>';
14105b75cd1fSAdrian Lang}
14115b75cd1fSAdrian Lang
1412b8595a66SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 :
1413a00de5b5SAndreas Gohr
1414