xref: /dokuwiki/inc/html.php (revision f5baf821ee5f6ab5b009bb94aff6f43f686d3329)
1ed7b5f09Sandi<?php
215fae107Sandi/**
315fae107Sandi * HTML output functions
415fae107Sandi *
515fae107Sandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
615fae107Sandi * @author     Andreas Gohr <andi@splitbrain.org>
715fae107Sandi */
815fae107Sandi
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
10e226efe1SAndreas Gohrif(!defined('NL')) define('NL',"\n");
116bbae538Sandi
12f3f0262cSandi/**
13f3f0262cSandi * Convenience function to quickly build a wikilink
1415fae107Sandi *
1515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
16f3f0262cSandi */
17db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
18db959ae3SAndreas Gohr    static $xhtml_renderer = null;
19723d78dbSandi    if(is_null($xhtml_renderer)){
207aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
21f3f0262cSandi    }
22f3f0262cSandi
23fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
24f3f0262cSandi}
25f3f0262cSandi
26f3f0262cSandi/**
27c19fe9c0Sandi * Helps building long attribute lists
28c19fe9c0Sandi *
29c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
30c19fe9c0Sandi */
31c19fe9c0Sandifunction html_attbuild($attributes){
32c19fe9c0Sandi    $ret = '';
33c19fe9c0Sandi    foreach ( $attributes as $key => $value ) {
34e351c80dSAdrian Lang        $ret .= $key.'="'.formText($value).'" ';
35c19fe9c0Sandi    }
36c19fe9c0Sandi    return trim($ret);
37c19fe9c0Sandi}
38c19fe9c0Sandi
39c19fe9c0Sandi/**
40f3f0262cSandi * The loginform
4115fae107Sandi *
4215fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
43f3f0262cSandi */
44f3f0262cSandifunction html_login(){
45f3f0262cSandi    global $lang;
46f3f0262cSandi    global $conf;
47f3f0262cSandi    global $ID;
48f3f0262cSandi
49c112d578Sandi    print p_locale_xhtml('login');
50fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
51e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__login'));
52fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
53fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
54fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
55aab557e9SGina Haeussge    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
56fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
5717f89d7eSMichael Klier    if($conf['rememberme']) {
58fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
5917f89d7eSMichael Klier    }
60fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
61fdb8d77bSTom N Harris    $form->endFieldset();
625b62573aSAndreas Gohr
63de4d479aSAdrian Lang    if(actionOK('register')){
6476ec5467SMichael Klier        $form->addElement('<p>'
6576ec5467SMichael Klier                          . $lang['reghere']
6676ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
6776ec5467SMichael Klier                          . '</p>');
68f3f0262cSandi    }
698b06d178Schris
70de4d479aSAdrian Lang    if (actionOK('resendpwd')) {
7176ec5467SMichael Klier        $form->addElement('<p>'
7276ec5467SMichael Klier                          . $lang['pwdforget']
7376ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
7476ec5467SMichael Klier                          . '</p>');
758b06d178Schris    }
7676ec5467SMichael Klier
7776ec5467SMichael Klier    html_form('login', $form);
78fdb8d77bSTom N Harris    print '</div>'.NL;
79f3f0262cSandi}
80f3f0262cSandi
81f3f0262cSandi/**
8215fae107Sandi * inserts section edit buttons if wanted or removes the markers
8315fae107Sandi *
8415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8515fae107Sandi */
86f3f0262cSandifunction html_secedit($text,$show=true){
87f3f0262cSandi    global $INFO;
8835dae8b0SBen Coburn
893f9e3215SAdrian Lang    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
90b081e262SAdrian Lang
9140868f2fSAdrian Lang    if(!$INFO['writable'] || !$show || $INFO['rev']){
9240868f2fSAdrian Lang        return preg_replace($regexp,'',$text);
93f3f0262cSandi    }
9435dae8b0SBen Coburn
9540868f2fSAdrian Lang    return preg_replace_callback($regexp,
9640868f2fSAdrian Lang                'html_secedit_button', $text);
9740868f2fSAdrian Lang}
9840868f2fSAdrian Lang
9940868f2fSAdrian Lang/**
10040868f2fSAdrian Lang * prepares section edit button data for event triggering
10140868f2fSAdrian Lang * used as a callback in html_secedit
10240868f2fSAdrian Lang *
10340868f2fSAdrian Lang * @triggers HTML_SECEDIT_BUTTON
10440868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
10540868f2fSAdrian Lang */
10640868f2fSAdrian Langfunction html_secedit_button($matches){
107905fa971SAdrian Lang    $data = array('secid'  => $matches[1],
10840868f2fSAdrian Lang                  'target' => strtolower($matches[2]),
10940868f2fSAdrian Lang                  'range'  => $matches[count($matches) - 1]);
11040868f2fSAdrian Lang    if (count($matches) === 5) {
11140868f2fSAdrian Lang        $data['name'] = $matches[3];
11240868f2fSAdrian Lang    }
11340868f2fSAdrian Lang
11440868f2fSAdrian Lang    return trigger_event('HTML_SECEDIT_BUTTON', $data,
11540868f2fSAdrian Lang                         'html_secedit_get_button');
11640868f2fSAdrian Lang}
11740868f2fSAdrian Lang
11840868f2fSAdrian Lang/**
11940868f2fSAdrian Lang * prints a section editing button
12040868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
12140868f2fSAdrian Lang *
12240868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
12340868f2fSAdrian Lang */
12440868f2fSAdrian Langfunction html_secedit_get_button($data) {
12540868f2fSAdrian Lang    global $ID;
12640868f2fSAdrian Lang    global $INFO;
12740868f2fSAdrian Lang
12840868f2fSAdrian Lang    if (!isset($data['name']) || $data['name'] === '') return;
12940868f2fSAdrian Lang
13040868f2fSAdrian Lang    $name = $data['name'];
13140868f2fSAdrian Lang    unset($data['name']);
13240868f2fSAdrian Lang
133905fa971SAdrian Lang    $secid = $data['secid'];
134905fa971SAdrian Lang    unset($data['secid']);
135905fa971SAdrian Lang
13640868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
137defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
13840868f2fSAdrian Lang           html_btn('secedit', $ID, '',
13940868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
140b150cd2cSGina Haeussge                                      'rev' => $INFO['lastmod'],
141b150cd2cSGina Haeussge                                      'summary' => '['.$name.'] '), $data),
14240868f2fSAdrian Lang                    'post', $name) . '</div>';
143f3f0262cSandi}
144f3f0262cSandi
145f3f0262cSandi/**
146d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1476b13307fSandi *
1486b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1496b13307fSandi */
1506b13307fSandifunction html_topbtn(){
1516b13307fSandi    global $lang;
1526b13307fSandi
1536b13307fSandi    $ret  = '';
15411ea018fSAndreas Gohr    $ret  = '<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="'.$lang['btn_top'].'" onclick="window.scrollTo(0, 0)" title="'.$lang['btn_top'].'" /></a>';
155df7b6005Sandi
1566b13307fSandi    return $ret;
1576b13307fSandi}
1586b13307fSandi
1596b13307fSandi/**
160d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
16135dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
16215fae107Sandi *
16315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
164f3f0262cSandi */
165*f5baf821SAnika Henkefunction html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){
166f3f0262cSandi    global $conf;
167f3f0262cSandi    global $lang;
168f3f0262cSandi
169*f5baf821SAnika Henke    if (!$label)
170f3f0262cSandi        $label = $lang['btn_'.$name];
171f3f0262cSandi
172f3f0262cSandi    $ret = '';
17335dae8b0SBen Coburn    $tip = '';
174f3f0262cSandi
17549c713a3Sandi    //filter id (without urlencoding)
17649c713a3Sandi    $id = idfilter($id,false);
177f3f0262cSandi
178f3f0262cSandi    //make nice URLs even for buttons
1796c7843b5Sandi    if($conf['userewrite'] == 2){
1806c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1816c7843b5Sandi    }elseif($conf['userewrite']){
1826c7843b5Sandi        $script = DOKU_BASE.$id;
1836c7843b5Sandi    }else{
1848b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
185f3f0262cSandi        $params['id'] = $id;
186f3f0262cSandi    }
187f3f0262cSandi
188b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
189f3f0262cSandi
19006a4bf8fSAndreas Gohr    if(is_array($params)){
191f3f0262cSandi        reset($params);
192f3f0262cSandi        while (list($key, $val) = each($params)) {
193f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
194f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
195f3f0262cSandi        }
19606a4bf8fSAndreas Gohr    }
197f3f0262cSandi
19835dae8b0SBen Coburn    if ($tooltip!='') {
19935dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
20011ea018fSAndreas Gohr    }else{
20111ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
20211ea018fSAndreas Gohr    }
20311ea018fSAndreas Gohr
204d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
20511ea018fSAndreas Gohr    if($akey){
20607493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
20787cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
20835dae8b0SBen Coburn    }
20935dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
210f3f0262cSandi    $ret .= '/>';
2114beabca9SAnika Henke    $ret .= '</div></form>';
212f3f0262cSandi
213f3f0262cSandi    return $ret;
214f3f0262cSandi}
215f3f0262cSandi
216f3f0262cSandi/**
21715fae107Sandi * show a wiki page
21815fae107Sandi *
21915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
22015fae107Sandi */
22111c78c94SAndreas Gohrfunction html_show($txt=null){
222f3f0262cSandi    global $ID;
223f3f0262cSandi    global $REV;
224f3f0262cSandi    global $HIGH;
225b8595a66SAndreas Gohr    global $INFO;
226f3f0262cSandi    //disable section editing for old revisions or in preview
2275400331dSandi    if($txt || $REV){
2286bbae538Sandi        $secedit = false;
2296bbae538Sandi    }else{
2306bbae538Sandi        $secedit = true;
231f3f0262cSandi    }
232f3f0262cSandi
23311c78c94SAndreas Gohr    if (!is_null($txt)){
234f3f0262cSandi        //PreviewHeader
235b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
236b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
237b8595a66SAndreas Gohr        echo '<div class="preview">';
238b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
239b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
240b8595a66SAndreas Gohr        echo $html;
241b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
242b8595a66SAndreas Gohr        echo '</div>';
2436bbae538Sandi
244f3f0262cSandi    }else{
245c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
246c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2476bbae538Sandi        $html = html_secedit($html,$secedit);
248b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
249b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
250b8595a66SAndreas Gohr        echo $html;
251f3f0262cSandi    }
252f3f0262cSandi}
253f3f0262cSandi
254f3f0262cSandi/**
255ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
256ee4c4a1bSAndreas Gohr *
257ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
258ee4c4a1bSAndreas Gohr */
259ee4c4a1bSAndreas Gohrfunction html_draft(){
260ee4c4a1bSAndreas Gohr    global $INFO;
261ee4c4a1bSAndreas Gohr    global $ID;
262ee4c4a1bSAndreas Gohr    global $lang;
263ee4c4a1bSAndreas Gohr    global $conf;
264ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
265ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
266ee4c4a1bSAndreas Gohr
267fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
268e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
269fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
270fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
271fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
272fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
273f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
274fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
275fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
276fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
277fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
278fdb8d77bSTom N Harris    html_form('draft', $form);
279ee4c4a1bSAndreas Gohr}
280ee4c4a1bSAndreas Gohr
281ee4c4a1bSAndreas Gohr/**
282f3f0262cSandi * Highlights searchqueries in HTML code
28315fae107Sandi *
28415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2857209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
286f3f0262cSandi */
287546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
288808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
2892237b4faSAndreas Gohr    $regex = join('|',array_map('ft_snippet_re_preprocess', array_map('preg_quote_cb',$phrases)));
29060c15d7dSAndreas Gohr
29160c15d7dSAndreas Gohr    if ($regex === '') return $html;
2921db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
293f3f0262cSandi    return $html;
294f3f0262cSandi}
295f3f0262cSandi
296f3f0262cSandi/**
2977209be23SAndreas Gohr * Callback used by html_hilight()
2987209be23SAndreas Gohr *
2997209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
3007209be23SAndreas Gohr */
3017209be23SAndreas Gohrfunction html_hilight_callback($m) {
3027209be23SAndreas Gohr    $hlight = unslash($m[0]);
3037209be23SAndreas Gohr    if ( !isset($m[2])) {
304688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3057209be23SAndreas Gohr    }
3067209be23SAndreas Gohr    return $hlight;
3077209be23SAndreas Gohr}
3087209be23SAndreas Gohr
3097209be23SAndreas Gohr/**
31015fae107Sandi * Run a search and display the result
31115fae107Sandi *
31215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
313f3f0262cSandi */
314f3f0262cSandifunction html_search(){
315f3f0262cSandi    global $conf;
316f3f0262cSandi    global $QUERY;
317f3f0262cSandi    global $ID;
318f3f0262cSandi    global $lang;
319f3f0262cSandi
320c112d578Sandi    print p_locale_xhtml('searchpage');
321f3f0262cSandi    flush();
322f3f0262cSandi
3234d9ff3d5Sandi    //show progressbar
324e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
325e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
326e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
327e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
328e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3299edac8a8SAndreas Gohr    flush();
3304d9ff3d5Sandi
331f3f0262cSandi    //do quick pagesearch
332f3f0262cSandi    $data = array();
333d0ab54f6SMichael Klier chi@chimeric.de
3346ef71970SAdrian Lang    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
335f3f0262cSandi    if(count($data)){
336f3f0262cSandi        print '<div class="search_quickresult">';
337746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3384f732f0eSAnika Henke        print '<ul class="search_quickhits">';
3398d22f1e9SAndreas Gohr        foreach($data as $id => $title){
3404f732f0eSAnika Henke            print '<li> ';
3418d22f1e9SAndreas Gohr            if (useHeading('navigation')) {
3428d22f1e9SAndreas Gohr                $name = $title;
3438d22f1e9SAndreas Gohr            }else{
344bd2f6c2fSAndreas Gohr                $ns = getNS($id);
345bd2f6c2fSAndreas Gohr                if($ns){
346bd2f6c2fSAndreas Gohr                    $name = shorten(noNS($id), ' ('.$ns.')',30);
347bd2f6c2fSAndreas Gohr                }else{
348bd2f6c2fSAndreas Gohr                    $name = $id;
349bd2f6c2fSAndreas Gohr                }
3508d22f1e9SAndreas Gohr            }
351bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3524f732f0eSAnika Henke            print '</li> ';
353f3f0262cSandi        }
354140c93f3SAnika Henke        print '</ul> ';
355f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
356f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
357f3f0262cSandi        print '</div>';
358f3f0262cSandi    }
359f3f0262cSandi    flush();
360f3f0262cSandi
361f3f0262cSandi    //do fulltext search
36260c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
363f3f0262cSandi    if(count($data)){
364506fa893SAndreas Gohr        $num = 1;
365506fa893SAndreas Gohr        foreach($data as $id => $cnt){
366f3f0262cSandi            print '<div class="search_result">';
367db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
368865c2687SKazutaka Miyasaka            if($cnt !== 0){
369506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
370bd0293e7SAndreas Gohr                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
37160c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
372506fa893SAndreas Gohr                }
373865c2687SKazutaka Miyasaka                $num++;
374865c2687SKazutaka Miyasaka            }
375f3f0262cSandi            print '</div>';
376506fa893SAndreas Gohr            flush();
377f3f0262cSandi        }
378f3f0262cSandi    }else{
379820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
380f3f0262cSandi    }
3814d9ff3d5Sandi
3824d9ff3d5Sandi    //hide progressbar
383e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
384e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
385e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3869edac8a8SAndreas Gohr    flush();
387f3f0262cSandi}
388f3f0262cSandi
38915fae107Sandi/**
39015fae107Sandi * Display error on locked pages
39115fae107Sandi *
39215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39315fae107Sandi */
394ee20e7d1Sandifunction html_locked(){
395f3f0262cSandi    global $ID;
396f3f0262cSandi    global $conf;
397f3f0262cSandi    global $lang;
39888f522e9Sandi    global $INFO;
399f3f0262cSandi
400c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
401f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
402f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
403f3f0262cSandi
404c112d578Sandi    print p_locale_xhtml('locked');
405f3f0262cSandi    print '<ul>';
4066d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
4070c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
408f3f0262cSandi    print '</ul>';
409f3f0262cSandi}
410f3f0262cSandi
41115fae107Sandi/**
41215fae107Sandi * list old revisions
41315fae107Sandi *
41415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
41571726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
41615fae107Sandi */
41771726d78SBen Coburnfunction html_revisions($first=0){
418f3f0262cSandi    global $ID;
419f3f0262cSandi    global $INFO;
420f3f0262cSandi    global $conf;
421f3f0262cSandi    global $lang;
42271726d78SBen Coburn    /* we need to get one additionally log entry to be able to
42371726d78SBen Coburn     * decide if this is the last page or is there another one.
42471726d78SBen Coburn     * see html_recent()
42571726d78SBen Coburn     */
42671726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
42771726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
42871726d78SBen Coburn        $first=0;
42971726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
43071726d78SBen Coburn    }
43171726d78SBen Coburn    $hasNext = false;
43271726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
43371726d78SBen Coburn        $hasNext = true;
43471726d78SBen Coburn        array_pop($revisions); // remove extra log entry
43571726d78SBen Coburn    }
43671726d78SBen Coburn
437f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
438f3f0262cSandi
439c112d578Sandi    print p_locale_xhtml('revisions');
44037a1dc12Smichael
441e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
44237a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
44371726d78SBen Coburn    if($INFO['exists'] && $first==0){
44437a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
44537a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
44637a1dc12Smichael        else
44737a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
44837a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
44937a1dc12Smichael        $form->addElement(form_makeTag('input', array(
45037a1dc12Smichael                        'type' => 'checkbox',
45137a1dc12Smichael                        'name' => 'rev2[]',
45237a1dc12Smichael                        'value' => 'current')));
453f9b2fe70Sandi
45437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
45537a1dc12Smichael        $form->addElement($date);
45637a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
457f9b2fe70Sandi
45837a1dc12Smichael        $form->addElement(form_makeTag('img', array(
45937a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
46037a1dc12Smichael                        'width' => '15',
46137a1dc12Smichael                        'height' => '11',
46237a1dc12Smichael                        'alt'    => '')));
463cffcc403Sandi
46437a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
46537a1dc12Smichael                        'class' => 'wikilink1',
46637a1dc12Smichael                        'href'  => wl($ID))));
46737a1dc12Smichael        $form->addElement($ID);
46837a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
469652610a2Sandi
47037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
47137a1dc12Smichael        $form->addElement(' &ndash; ');
47237a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
47337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
474652610a2Sandi
47537a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
47637a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
47737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
47837a1dc12Smichael
47937a1dc12Smichael        $form->addElement('('.$lang['current'].')');
48037a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
48137a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
482f3f0262cSandi    }
483f3f0262cSandi
484f3f0262cSandi    foreach($revisions as $rev){
485f2263577SAndreas Gohr        $date   = dformat($rev);
486fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
487103c256aSChris Smith        $exists = page_exists($ID,$rev);
488652610a2Sandi
48937a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
49037a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
49137a1dc12Smichael        else
49237a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
49337a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
49477707b04SAndreas Gohr        if($exists){
49537a1dc12Smichael            $form->addElement(form_makeTag('input', array(
49637a1dc12Smichael                            'type' => 'checkbox',
49737a1dc12Smichael                            'name' => 'rev2[]',
49837a1dc12Smichael                            'value' => $rev)));
49977707b04SAndreas Gohr        }else{
50037a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50137a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
50237a1dc12Smichael                            'width' => 14,
50337a1dc12Smichael                            'height' => 11,
50437a1dc12Smichael                            'alt' => '')));
50541396b71SAndreas Gohr        }
506f9b2fe70Sandi
50737a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
50837a1dc12Smichael        $form->addElement($date);
50937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
51037a1dc12Smichael
51137a1dc12Smichael        if($exists){
51237a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
51337a1dc12Smichael            $form->addElement(form_makeTag('img', array(
51437a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
51537a1dc12Smichael                            'width'  => 15,
51637a1dc12Smichael                            'height' => 11,
51737a1dc12Smichael                            'title'  => $lang['diff'],
51837a1dc12Smichael                            'alt'    => $lang['diff'])));
51937a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52037a1dc12Smichael
52137a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
52237a1dc12Smichael            $form->addElement($ID);
52337a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52437a1dc12Smichael        }else{
52537a1dc12Smichael            $form->addElement(form_makeTag('img', array(
52637a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
52737a1dc12Smichael                            'width' => '15',
52837a1dc12Smichael                            'height' => '11',
52937a1dc12Smichael                            'alt'   => '')));
53037a1dc12Smichael            $form->addElement($ID);
53137a1dc12Smichael        }
53237a1dc12Smichael
53337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
53437a1dc12Smichael        $form->addElement(' &ndash; ');
53537a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
53637a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
53737a1dc12Smichael
53837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
53988f522e9Sandi        if($info['user']){
54037a1dc12Smichael            $form->addElement(editorinfo($info['user']));
541433efb25SAndreas Gohr            if(auth_ismanager()){
542433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
543433efb25SAndreas Gohr            }
54488f522e9Sandi        }else{
54537a1dc12Smichael            $form->addElement($info['ip']);
54688f522e9Sandi        }
54737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
548652610a2Sandi
54937a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
55037a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
551f3f0262cSandi    }
55237a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
55337a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
55437a1dc12Smichael    html_form('revisions', $form);
55571726d78SBen Coburn
55671726d78SBen Coburn    print '<div class="pagenav">';
55771726d78SBen Coburn    $last = $first + $conf['recent'];
55871726d78SBen Coburn    if ($first > 0) {
55971726d78SBen Coburn        $first -= $conf['recent'];
56071726d78SBen Coburn        if ($first < 0) $first = 0;
56171726d78SBen Coburn        print '<div class="pagenav-prev">';
562eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
56371726d78SBen Coburn        print '</div>';
56471726d78SBen Coburn    }
56571726d78SBen Coburn    if ($hasNext) {
56671726d78SBen Coburn        print '<div class="pagenav-next">';
567eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
56871726d78SBen Coburn        print '</div>';
56971726d78SBen Coburn    }
57071726d78SBen Coburn    print '</div>';
57171726d78SBen Coburn
572f3f0262cSandi}
573f3f0262cSandi
57415fae107Sandi/**
57515fae107Sandi * display recent changes
57615fae107Sandi *
57715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5785749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
57971726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
58015fae107Sandi */
581a39955b0Smatthiasgrimmfunction html_recent($first=0){
582f3f0262cSandi    global $conf;
583cffcc403Sandi    global $lang;
584dbb00abcSEsther Brunner    global $ID;
5855749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5865749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5875749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5885749f1ceSmatthiasgrimm     */
589b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5905749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5915749f1ceSmatthiasgrimm        $first=0;
59271726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5935749f1ceSmatthiasgrimm    }
59471726d78SBen Coburn    $hasNext = false;
59571726d78SBen Coburn    if (count($recents)>$conf['recent']) {
59671726d78SBen Coburn        $hasNext = true;
59771726d78SBen Coburn        array_pop($recents); // remove extra log entry
59871726d78SBen Coburn    }
599f3f0262cSandi
600c112d578Sandi    print p_locale_xhtml('recent');
601e83cef14SGina Haeussge
602e83cef14SGina Haeussge    if (getNS($ID) != '')
6039e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
604e83cef14SGina Haeussge
605e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
606abdcc39fSmichael    $form->addHidden('sectok', null);
607abdcc39fSmichael    $form->addHidden('do', 'recent');
608abdcc39fSmichael    $form->addHidden('id', $ID);
609abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
610a39955b0Smatthiasgrimm
611d437bcc4SAndreas Gohr    foreach($recents as $recent){
612f2263577SAndreas Gohr        $date = dformat($recent['date']);
613abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
614abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
615abdcc39fSmichael        else
616abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
617cffcc403Sandi
618abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
619f9b2fe70Sandi
620abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
621abdcc39fSmichael        $form->addElement($date);
622abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
623cffcc403Sandi
624cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
625abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
626abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
627abdcc39fSmichael                        'width' => 15,
628abdcc39fSmichael                        'height'=> 11,
629abdcc39fSmichael                        'title' => $lang['diff'],
630abdcc39fSmichael                        'alt'   => $lang['diff']
631abdcc39fSmichael                        )));
632abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
633cffcc403Sandi
634cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
635abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
636abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
637abdcc39fSmichael                        'width' => 12,
638abdcc39fSmichael                        'height'=> 14,
639abdcc39fSmichael                        'title' => $lang['btn_revs'],
640abdcc39fSmichael                        'alt'   => $lang['btn_revs']
641abdcc39fSmichael                        )));
642abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
643b6912aeaSAndreas Gohr
644db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
645abdcc39fSmichael
646abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
647abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
648abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
649abdcc39fSmichael
650abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
651d437bcc4SAndreas Gohr        if($recent['user']){
652abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
653433efb25SAndreas Gohr            if(auth_ismanager()){
654433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
655433efb25SAndreas Gohr            }
65688f522e9Sandi        }else{
657abdcc39fSmichael            $form->addElement($recent['ip']);
65888f522e9Sandi        }
659abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
660cffcc403Sandi
661abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
662abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
663f3f0262cSandi    }
664abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
665a39955b0Smatthiasgrimm
666abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6675749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
668a39955b0Smatthiasgrimm    if ($first > 0) {
669a39955b0Smatthiasgrimm        $first -= $conf['recent'];
670a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
671abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
672abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
673abdcc39fSmichael                    'type'  => 'submit',
674abdcc39fSmichael                    'name'  => 'first['.$first.']',
675cddd152cSmichael                    'value' => $lang['btn_newer'],
676cddd152cSmichael                    'accesskey' => 'n',
677f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
67818d107cbSMichael Klier                    'class' => 'button'
679abdcc39fSmichael                    )));
680abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
681a39955b0Smatthiasgrimm    }
68271726d78SBen Coburn    if ($hasNext) {
683abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
684abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
685abdcc39fSmichael                        'type'  => 'submit',
686abdcc39fSmichael                        'name'  => 'first['.$last.']',
687cddd152cSmichael                        'value' => $lang['btn_older'],
688cddd152cSmichael                        'accesskey' => 'p',
689f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
69018d107cbSMichael Klier                        'class' => 'button'
691abdcc39fSmichael                        )));
692abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
693a39955b0Smatthiasgrimm    }
694abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
695abdcc39fSmichael    html_form('recent', $form);
696f3f0262cSandi}
697f3f0262cSandi
69815fae107Sandi/**
69915fae107Sandi * Display page index
70015fae107Sandi *
70115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
70215fae107Sandi */
703f3f0262cSandifunction html_index($ns){
704f3f0262cSandi    global $conf;
705f3f0262cSandi    global $ID;
706f3f0262cSandi    $dir = $conf['datadir'];
707f3f0262cSandi    $ns  = cleanID($ns);
70830f1737dSandi    #fixme use appropriate function
709f3f0262cSandi    if(empty($ns)){
710f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
711f3f0262cSandi        if($ns == '.') $ns ='';
712f3f0262cSandi    }
71388d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
714f3f0262cSandi
715a06884abSAndreas Gohr    echo p_locale_xhtml('index');
716a06884abSAndreas Gohr    echo '<div id="index__tree">';
717f3f0262cSandi
718f3f0262cSandi    $data = array();
719f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
720a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
721a06884abSAndreas Gohr
722a06884abSAndreas Gohr    echo '</div>';
723f3f0262cSandi}
724f3f0262cSandi
725f3f0262cSandi/**
72615fae107Sandi * Index item formatter
72715fae107Sandi *
728f3f0262cSandi * User function for html_buildlist()
72915fae107Sandi *
73015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
731f3f0262cSandi */
732f3f0262cSandifunction html_list_index($item){
733d98d4540SBen Coburn    global $ID;
734f3f0262cSandi    $ret = '';
735f3f0262cSandi    $base = ':'.$item['id'];
736f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
737f3f0262cSandi    if($item['type']=='d'){
7384a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
739f3f0262cSandi        $ret .= $base;
740ed7ecb79SAnika Henke        $ret .= '</strong></a>';
741f3f0262cSandi    }else{
742f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
743f3f0262cSandi    }
744f3f0262cSandi    return $ret;
745f3f0262cSandi}
746f3f0262cSandi
747f3f0262cSandi/**
748cb70c441Sandi * Index List item
749cb70c441Sandi *
750cb70c441Sandi * This user function is used in html_build_lidt to build the
751cb70c441Sandi * <li> tags for namespaces when displaying the page index
752cb70c441Sandi * it gives different classes to opened or closed "folders"
753cb70c441Sandi *
754cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
755cb70c441Sandi */
756cb70c441Sandifunction html_li_index($item){
757cb70c441Sandi    if($item['type'] == "f"){
758cb70c441Sandi        return '<li class="level'.$item['level'].'">';
759cb70c441Sandi    }elseif($item['open']){
760cb70c441Sandi        return '<li class="open">';
761cb70c441Sandi    }else{
762cb70c441Sandi        return '<li class="closed">';
763cb70c441Sandi    }
764cb70c441Sandi}
765cb70c441Sandi
766cb70c441Sandi/**
767cb70c441Sandi * Default List item
768cb70c441Sandi *
769cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
770cb70c441Sandi */
771cb70c441Sandifunction html_li_default($item){
772cb70c441Sandi    return '<li class="level'.$item['level'].'">';
773cb70c441Sandi}
774cb70c441Sandi
775cb70c441Sandi/**
77615fae107Sandi * Build an unordered list
77715fae107Sandi *
778f3f0262cSandi * Build an unordered list from the given $data array
779f3f0262cSandi * Each item in the array has to have a 'level' property
780f3f0262cSandi * the item itself gets printed by the given $func user
781cb70c441Sandi * function. The second and optional function is used to
782cb70c441Sandi * print the <li> tag. Both user function need to accept
783cb70c441Sandi * a single item.
78415fae107Sandi *
785c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
786c5a8fd96SAndreas Gohr * a member of an object.
787c5a8fd96SAndreas Gohr *
78815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
789f3f0262cSandi */
790cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
791f3f0262cSandi    $level = 0;
792f3f0262cSandi    $opens = 0;
793f3f0262cSandi    $ret   = '';
794f3f0262cSandi
795f3f0262cSandi    foreach ($data as $item){
796f3f0262cSandi
797f3f0262cSandi        if( $item['level'] > $level ){
798f3f0262cSandi            //open new list
799df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
800df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
801f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
802df52d0feSandi            }
803f3f0262cSandi        }elseif( $item['level'] < $level ){
804f3f0262cSandi            //close last item
805f3f0262cSandi            $ret .= "</li>\n";
806f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
807f3f0262cSandi                //close higher lists
808f3f0262cSandi                $ret .= "</ul>\n</li>\n";
809f3f0262cSandi            }
810f3f0262cSandi        }else{
811f3f0262cSandi            //close last item
812f3f0262cSandi            $ret .= "</li>\n";
813f3f0262cSandi        }
814f3f0262cSandi
815f3f0262cSandi        //remember current level
816f3f0262cSandi        $level = $item['level'];
817f3f0262cSandi
818f3f0262cSandi        //print item
81934dbe711Schris        $ret .= call_user_func($lifunc,$item);
8200c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
82134dbe711Schris
82234dbe711Schris        $ret .= call_user_func($func,$item);
8230c6b58a8SAndreas Gohr        $ret .= '</div>';
824f3f0262cSandi    }
825f3f0262cSandi
826f3f0262cSandi    //close remaining items and lists
827f3f0262cSandi    for ($i=0; $i < $level; $i++){
828f3f0262cSandi        $ret .= "</li></ul>\n";
829f3f0262cSandi    }
830f3f0262cSandi
831f3f0262cSandi    return $ret;
832f3f0262cSandi}
833f3f0262cSandi
83415fae107Sandi/**
83515fae107Sandi * display backlinks
83615fae107Sandi *
83715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
83811df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
83915fae107Sandi */
840f3f0262cSandifunction html_backlinks(){
841f3f0262cSandi    global $ID;
842f3f0262cSandi    global $conf;
84311df47ecSMichael Klier    global $lang;
844f3f0262cSandi
845c112d578Sandi    print p_locale_xhtml('backlinks');
846f3f0262cSandi
84754f4c056SAndreas Gohr    $data = ft_backlinks($ID);
848f3f0262cSandi
84911df47ecSMichael Klier    if(!empty($data)) {
850f3f0262cSandi        print '<ul class="idx">';
85154f4c056SAndreas Gohr        foreach($data as $blink){
8520c6b58a8SAndreas Gohr            print '<li><div class="li">';
853db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8540c6b58a8SAndreas Gohr            print '</div></li>';
855f3f0262cSandi        }
856f3f0262cSandi        print '</ul>';
85711df47ecSMichael Klier    } else {
85811df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
85911df47ecSMichael Klier    }
860f3f0262cSandi}
861f3f0262cSandi
86215fae107Sandi/**
86315fae107Sandi * show diff
86415fae107Sandi *
86515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
86615fae107Sandi */
867f3f0262cSandifunction html_diff($text='',$intro=true){
868f3f0262cSandi    global $ID;
869f3f0262cSandi    global $REV;
870f3f0262cSandi    global $lang;
871f3f0262cSandi    global $conf;
872e1bd90ffSAndreas Gohr
87377707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
87477707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
87577707b04SAndreas Gohr    // array in rev2.
87677707b04SAndreas Gohr    $rev1 = $REV;
8777b3f8b16SAndreas Gohr
87877707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
87977707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
88077707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
88154041c77SAndreas Gohr
88254041c77SAndreas Gohr        if(!$rev1){
88354041c77SAndreas Gohr            $rev1 = $rev2;
88454041c77SAndreas Gohr            unset($rev2);
88554041c77SAndreas Gohr        }
886f3f0262cSandi    }else{
88777707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
8884d58bd99Sandi    }
8894d58bd99Sandi
89077707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
89177707b04SAndreas Gohr        $l_rev   = '';
89277707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
89377707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
894f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
89577707b04SAndreas Gohr            $lang['current'];
89677707b04SAndreas Gohr
89777707b04SAndreas Gohr        $r_rev   = '';
89877707b04SAndreas Gohr        $r_text  = cleanText($text);
89977707b04SAndreas Gohr        $r_head  = $lang['yours'];
900e1bd90ffSAndreas Gohr    }else{
90177707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
90254041c77SAndreas Gohr            // make sure order is correct (older on the left)
90377707b04SAndreas Gohr            if($rev1 < $rev2){
90477707b04SAndreas Gohr                $l_rev = $rev1;
90577707b04SAndreas Gohr                $r_rev = $rev2;
90677707b04SAndreas Gohr            }else{
90777707b04SAndreas Gohr                $l_rev = $rev2;
90877707b04SAndreas Gohr                $r_rev = $rev1;
909e1bd90ffSAndreas Gohr            }
91077707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
91177707b04SAndreas Gohr            $r_rev = '';
91277707b04SAndreas Gohr            $l_rev = $rev1;
91377707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
91477707b04SAndreas Gohr            $r_rev = '';
91577707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
91677707b04SAndreas Gohr            $l_rev = $revs[0];
9176f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
91877707b04SAndreas Gohr        }
91977707b04SAndreas Gohr
9207b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9217b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9227b3f8b16SAndreas Gohr            $l_text = '';
9237b3f8b16SAndreas Gohr        }else{
92477707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9257b3f8b16SAndreas Gohr        }
92677707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
92777707b04SAndreas Gohr
9287b3f8b16SAndreas Gohr        if(!$l_rev){
9297b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9307b3f8b16SAndreas Gohr        }else{
931e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
932db959ae3SAndreas Gohr            if($l_info['user']){
933db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
934e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
935db959ae3SAndreas Gohr            } else {
936db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
937db959ae3SAndreas Gohr            }
938e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
939e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
940e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
941e5e61eb0SAnika Henke
94277707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
943f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
944e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9457b3f8b16SAndreas Gohr        }
94677707b04SAndreas Gohr
94777707b04SAndreas Gohr        if($r_rev){
948e5e61eb0SAnika Henke            $r_info   = getRevisionInfo($ID,$r_rev,true);
949db959ae3SAndreas Gohr            if($r_info['user']){
950db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
951e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
952db959ae3SAndreas Gohr            } else {
953db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
954db959ae3SAndreas Gohr            }
955e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
956e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
957e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
958e5e61eb0SAnika Henke
95977707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
960f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
961e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9627b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
963e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
964db959ae3SAndreas Gohr            if($_info['user']){
965db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
966e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
967db959ae3SAndreas Gohr            } else {
968db959ae3SAndreas Gohr                $_user = $_info['ip'];
969db959ae3SAndreas Gohr            }
970e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
971e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
972e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
973e5e61eb0SAnika Henke
97477707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
975f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
976658b1aa0SAnika Henke            '('.$lang['current'].')'.
977e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9787b3f8b16SAndreas Gohr        }else{
979658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
980f3f0262cSandi        }
98177707b04SAndreas Gohr    }
98277707b04SAndreas Gohr
98377707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
98477707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
98577707b04SAndreas Gohr
986f3f0262cSandi    $tdf = new TableDiffFormatter();
987c112d578Sandi    if($intro) print p_locale_xhtml('diff');
988226bf2dcSGina Haeussge
989226bf2dcSGina Haeussge    if (!$text) {
9908d9e6ae7SAnika Henke        $diffurl = wl($ID, array('do'=>'diff', 'rev2[0]'=>$l_rev, 'rev2[1]'=>$r_rev));
9918d9e6ae7SAnika Henke        ptln('<p class="difflink">');
9928d9e6ae7SAnika Henke        ptln('  <a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>');
9938d9e6ae7SAnika Henke        ptln('</p>');
994226bf2dcSGina Haeussge    }
995f3f0262cSandi    ?>
996daf4ca4eSAnika Henke    <table class="diff">
997f3f0262cSandi    <tr>
998e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
99977707b04SAndreas Gohr    <?php echo $l_head?>
1000daf4ca4eSAnika Henke    </th>
1001e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
100277707b04SAndreas Gohr    <?php echo $r_head?>
1003daf4ca4eSAnika Henke    </th>
1004f3f0262cSandi    </tr>
10054da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
1006f3f0262cSandi    </table>
10074da078a3Smatthiasgrimm    <?php
1008f3f0262cSandi}
1009f3f0262cSandi
101015fae107Sandi/**
101115fae107Sandi * show warning on conflict detection
101215fae107Sandi *
101315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
101415fae107Sandi */
1015f3f0262cSandifunction html_conflict($text,$summary){
1016f3f0262cSandi    global $ID;
1017f3f0262cSandi    global $lang;
1018f3f0262cSandi
1019c112d578Sandi    print p_locale_xhtml('conflict');
1020e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1021fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1022fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1023fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1024fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1025fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1026fdb8d77bSTom N Harris    html_form('conflict', $form);
1027fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1028f3f0262cSandi}
1029f3f0262cSandi
1030f3f0262cSandi/**
103115fae107Sandi * Prints the global message array
103215fae107Sandi *
103315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1034f3f0262cSandi */
1035f3f0262cSandifunction html_msgarea(){
1036f3f0262cSandi    global $MSG;
1037f3f0262cSandi    if(!isset($MSG)) return;
1038f3f0262cSandi
10394af9f0d4SAndreas Gohr    $shown = array();
1040f3f0262cSandi    foreach($MSG as $msg){
10414af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10424af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1043f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1044f3f0262cSandi        print $msg['msg'];
1045f3f0262cSandi        print '</div>';
10464af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1047f3f0262cSandi    }
1048f3f0262cSandi}
1049f3f0262cSandi
1050f3f0262cSandi/**
1051f3f0262cSandi * Prints the registration form
105215fae107Sandi *
105315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1054f3f0262cSandi */
1055f3f0262cSandifunction html_register(){
1056f3f0262cSandi    global $lang;
1057cab2716aSmatthias.grimm    global $conf;
1058f3f0262cSandi    global $ID;
1059f3f0262cSandi
1060c112d578Sandi    print p_locale_xhtml('register');
1061fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1062e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1063fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1064fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1065fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1066fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1067cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1068fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1069fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1070cab2716aSmatthias.grimm    }
1071fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1072fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1073fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1074fdb8d77bSTom N Harris    $form->endFieldset();
1075fdb8d77bSTom N Harris    html_form('register', $form);
1076cab2716aSmatthias.grimm
1077fdb8d77bSTom N Harris    print '</div>'.NL;
1078f3f0262cSandi}
1079f3f0262cSandi
1080f3f0262cSandi/**
10818b06d178Schris * Print the update profile form
10828b06d178Schris *
10838b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10848b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10858b06d178Schris */
10868b06d178Schrisfunction html_updateprofile(){
10878b06d178Schris    global $lang;
10888b06d178Schris    global $conf;
10898b06d178Schris    global $ID;
10908b06d178Schris    global $INFO;
109182fd59b6SAndreas Gohr    global $auth;
10928b06d178Schris
10938b06d178Schris    print p_locale_xhtml('updateprofile');
10948b06d178Schris
10958b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10968b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1097fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1098e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1099fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1100fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1101fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1102fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1103fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1104fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1105fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
110639ba8890SAndreas Gohr    $attr = array('size'=>'50');
110739ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1108fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1109fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1110fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1111fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1112fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1113fdb8d77bSTom N Harris    }
1114fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1115fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1116fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1117fdb8d77bSTom N Harris    }
1118fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1119fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1120fdb8d77bSTom N Harris    $form->endFieldset();
1121fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1122fdb8d77bSTom N Harris    print '</div>'.NL;
11238b06d178Schris}
11248b06d178Schris
11258b06d178Schris/**
11267c4635c4SAdrian Lang * Preprocess edit form data
112715fae107Sandi *
112815fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
11292ffea8f2SAdrian Lang *
11302ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1131f3f0262cSandi */
11325a932e77SAdrian Langfunction html_edit(){
1133f3f0262cSandi    global $ID;
1134f3f0262cSandi    global $REV;
1135f3f0262cSandi    global $DATE;
1136f3f0262cSandi    global $PRE;
1137f3f0262cSandi    global $SUF;
1138f3f0262cSandi    global $INFO;
1139f3f0262cSandi    global $SUM;
1140f3f0262cSandi    global $lang;
1141f3f0262cSandi    global $conf;
114245a99335SAdrian Lang    global $TEXT;
1143d141c8dcSAdrian Lang    global $RANGE;
1144f3f0262cSandi
11458fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
11468fe3bb00STom N Harris        $check = $_REQUEST['changecheck'];
114745a99335SAdrian Lang    } elseif(!$INFO['exists']){
114845a99335SAdrian Lang        // $TEXT has been loaded from page template
114945a99335SAdrian Lang        $check = md5('');
11508fe3bb00STom N Harris    } else {
115145a99335SAdrian Lang        $check = md5($TEXT);
11528fe3bb00STom N Harris    }
115345a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1154f3f0262cSandi
115527eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
115645a99335SAdrian Lang    $include = 'edit';
1157f3f0262cSandi    if($wr){
1158ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1159f3f0262cSandi    }else{
1160409d7af7SAndreas Gohr        // check pseudo action 'source'
1161409d7af7SAndreas Gohr        if(!actionOK('source')){
1162409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1163409d7af7SAndreas Gohr            return;
1164409d7af7SAndreas Gohr        }
1165ffde0ac9SAdrian Lang        $include = 'read';
1166f3f0262cSandi    }
11677c4635c4SAdrian Lang
11687c4635c4SAdrian Lang    global $license;
116942c7abd6SAndreas Gohr
1170e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1171fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1172fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1173fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
117442de51b1SAdrian Lang    $form->addHidden('prefix', $PRE . '.');
1175fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1176fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
11778e4da260SAdrian Lang
11782ffea8f2SAdrian Lang    $data = array('form' => $form,
11792ffea8f2SAdrian Lang                  'wr'   => $wr,
11802ffea8f2SAdrian Lang                  'media_manager' => true,
118112c96aceSAdrian Lang                  'target' => (isset($_REQUEST['target']) && $wr &&
118212c96aceSAdrian Lang                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
11832ffea8f2SAdrian Lang                  'intro_locale' => $include);
118412c96aceSAdrian Lang
118512c96aceSAdrian Lang    if ($data['target'] !== 'section') {
118612c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
118712c96aceSAdrian Lang        // edit target is not section.
11888e4da260SAdrian Lang        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
11892ffea8f2SAdrian Lang    } else {
11902ffea8f2SAdrian Lang        html_edit_form($data);
11912ffea8f2SAdrian Lang    }
1192ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1193ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1194ffde0ac9SAdrian Lang    }
11958e4da260SAdrian Lang
1196b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
1197fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1198fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1199fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1200fdb8d77bSTom N Harris    if ($wr) {
1201fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1202fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1203fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1204fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1205fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1206fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1207fdb8d77bSTom N Harris        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1208fdb8d77bSTom N Harris        $elem = html_minoredit();
1209fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1210fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1211fdb8d77bSTom N Harris    }
1212fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
12135808bc54SAndreas Gohr    if($wr && $conf['license']){
1214066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1215066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1216066fee30SAndreas Gohr        $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
121784645d8cSAndreas Gohr        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1218066fee30SAndreas Gohr        $out .= '> '.$license[$conf['license']]['name'].'</a>';
1219066fee30SAndreas Gohr        $form->addElement($out);
1220066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1221066fee30SAndreas Gohr    }
12228e4da260SAdrian Lang
12238e4da260SAdrian Lang    if ($wr) {
12248e4da260SAdrian Lang        // sets changed to true when previewed
12252e61e4dfSAdrian Lang        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
12268e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
12272e61e4dfSAdrian Lang        echo '//--><!]]></script>' . NL;
12288e4da260SAdrian Lang    } ?>
12298e4da260SAdrian Lang    <div style="width:99%;">
12308e4da260SAdrian Lang
12318e4da260SAdrian Lang    <div class="toolbar">
12328e4da260SAdrian Lang    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
12338e4da260SAdrian Lang    <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
12348e4da260SAdrian Lang        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
12358e4da260SAdrian Lang
12368e4da260SAdrian Lang    </div>
12378e4da260SAdrian Lang    <?php
12388e4da260SAdrian Lang
1239fdb8d77bSTom N Harris    html_form('edit', $form);
1240fdb8d77bSTom N Harris    print '</div>'.NL;
1241f3f0262cSandi}
1242f3f0262cSandi
1243f3f0262cSandi/**
12448e4da260SAdrian Lang * Display the default edit form
12458e4da260SAdrian Lang *
12468e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
12478e4da260SAdrian Lang */
12488e4da260SAdrian Langfunction html_edit_form($param) {
124945a99335SAdrian Lang    global $TEXT;
125012c96aceSAdrian Lang
125112c96aceSAdrian Lang    if ($param['target'] !== 'section') {
125212c96aceSAdrian Lang        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
125312c96aceSAdrian Lang    }
125412c96aceSAdrian Lang
12558e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
125612c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
125712c96aceSAdrian Lang
125812c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
12598e4da260SAdrian Lang}
12608e4da260SAdrian Lang
12618e4da260SAdrian Lang/**
1262b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1263b6912aeaSAndreas Gohr *
1264b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1265b6912aeaSAndreas Gohr */
1266b6912aeaSAndreas Gohrfunction html_minoredit(){
1267b6912aeaSAndreas Gohr    global $conf;
1268b6912aeaSAndreas Gohr    global $lang;
1269b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1270b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1271fdb8d77bSTom N Harris        return false;
1272b6912aeaSAndreas Gohr    }
1273b6912aeaSAndreas Gohr
1274b6912aeaSAndreas Gohr    $p = array();
1275b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1276bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1277fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1278b6912aeaSAndreas Gohr}
1279b6912aeaSAndreas Gohr
1280b6912aeaSAndreas Gohr/**
1281f3f0262cSandi * prints some debug info
128215fae107Sandi *
128315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1284f3f0262cSandi */
1285f3f0262cSandifunction html_debug(){
1286f3f0262cSandi    global $conf;
1287d16a4edaSandi    global $lang;
12885298a619SAndreas Gohr    global $auth;
1289100a97e3SAndreas Gohr    global $INFO;
1290100a97e3SAndreas Gohr
129128fb55ffSandi    //remove sensitive data
129228fb55ffSandi    $cnf = $conf;
129324297a69SAndreas Gohr    debug_guard($cnf);
1294100a97e3SAndreas Gohr    $nfo = $INFO;
129524297a69SAndreas Gohr    debug_guard($nfo);
1296100a97e3SAndreas Gohr    $ses = $_SESSION;
129724297a69SAndreas Gohr    debug_guard($ses);
1298f3f0262cSandi
1299f3f0262cSandi    print '<html><body>';
1300f3f0262cSandi
1301f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1302f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1303f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1304f3f0262cSandi
1305100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1306100a97e3SAndreas Gohr    print_r($nfo);
1307100a97e3SAndreas Gohr    print '</pre>';
1308100a97e3SAndreas Gohr
1309f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1310f3f0262cSandi    print_r($_SERVER);
1311f3f0262cSandi    print '</pre>';
1312f3f0262cSandi
1313f3f0262cSandi    print '<b>$conf:</b><pre>';
131428fb55ffSandi    print_r($cnf);
1315f3f0262cSandi    print '</pre>';
1316f3f0262cSandi
1317ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1318ed7b5f09Sandi    print DOKU_BASE;
1319f3f0262cSandi    print '</pre>';
1320f3f0262cSandi
1321ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1322ed7b5f09Sandi    print DOKU_URL;
1323ed7b5f09Sandi    print '</pre>';
1324ed7b5f09Sandi
1325ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1326f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1327f3f0262cSandi    print '</pre>';
1328f3f0262cSandi
1329f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1330f3f0262cSandi    print phpversion();
1331f3f0262cSandi    print '</pre>';
1332f3f0262cSandi
1333f3f0262cSandi    print '<b>locale:</b><pre>';
1334f3f0262cSandi    print setlocale(LC_ALL,0);
1335f3f0262cSandi    print '</pre>';
1336f3f0262cSandi
1337d16a4edaSandi    print '<b>encoding:</b><pre>';
1338d16a4edaSandi    print $lang['encoding'];
1339d16a4edaSandi    print '</pre>';
1340d16a4edaSandi
13415298a619SAndreas Gohr    if($auth){
13425298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13435298a619SAndreas Gohr        print_r($auth->cando);
13445298a619SAndreas Gohr        print '</pre>';
13455298a619SAndreas Gohr    }
13465298a619SAndreas Gohr
13473aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1348100a97e3SAndreas Gohr    print_r($ses);
13493aa54d7cSAndreas Gohr    print '</pre>';
13503aa54d7cSAndreas Gohr
1351f3f0262cSandi    print '<b>Environment:</b><pre>';
1352f3f0262cSandi    print_r($_ENV);
1353f3f0262cSandi    print '</pre>';
1354f3f0262cSandi
1355f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1356f3f0262cSandi    $inis = ini_get_all();
1357f3f0262cSandi    print_r($inis);
1358f3f0262cSandi    print '</pre>';
1359f3f0262cSandi
1360f3f0262cSandi    print '</body></html>';
1361f3f0262cSandi}
1362f3f0262cSandi
136310271ce4SAndreas Gohr/**
136410271ce4SAndreas Gohr * List available Administration Tasks
136510271ce4SAndreas Gohr *
136610271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
136710271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
136810271ce4SAndreas Gohr */
1369c19fe9c0Sandifunction html_admin(){
1370c19fe9c0Sandi    global $ID;
1371f8cc712eSAndreas Gohr    global $INFO;
1372c19fe9c0Sandi    global $lang;
1373ca3a6df1SMatthias Grimm    global $conf;
137410271ce4SAndreas Gohr    global $auth;
1375c19fe9c0Sandi
137611e2ce22Schris    // build menu of admin functions from the plugins that handle them
137711e2ce22Schris    $pluginlist = plugin_list('admin');
137811e2ce22Schris    $menu = array();
137911e2ce22Schris    foreach ($pluginlist as $p) {
1380db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1381f8cc712eSAndreas Gohr
1382f8cc712eSAndreas Gohr        // check permissions
1383f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1384f8cc712eSAndreas Gohr
138510271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
138611e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
138711e2ce22Schris                'sort' => $obj->getMenuSort()
138811e2ce22Schris                );
138911e2ce22Schris    }
139011e2ce22Schris
1391c95a5b7dSAndreas Gohr    // data security check
1392c95a5b7dSAndreas Gohr    echo '<a style="background: transparent url(data/security.png) left top no-repeat;
1393c95a5b7dSAndreas Gohr                  display: block; width:380px; height:73px; border:none; float:right"
1394c95a5b7dSAndreas Gohr           target="_blank"
1395c95a5b7dSAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>';
1396c95a5b7dSAndreas Gohr
139710271ce4SAndreas Gohr    print p_locale_xhtml('admin');
139810271ce4SAndreas Gohr
139910271ce4SAndreas Gohr    // Admin Tasks
140010271ce4SAndreas Gohr    if($INFO['isadmin']){
140110271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
140210271ce4SAndreas Gohr
140376c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
140410271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
140510271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
140610271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
140710271ce4SAndreas Gohr        }
140810271ce4SAndreas Gohr        unset($menu['usermanager']);
140910271ce4SAndreas Gohr
141076c65fd3SAndreas Gohr        if($menu['acl']){
141110271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
141210271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
141310271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
141476c65fd3SAndreas Gohr        }
141510271ce4SAndreas Gohr        unset($menu['acl']);
141610271ce4SAndreas Gohr
141776c65fd3SAndreas Gohr        if($menu['plugin']){
141810271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
141910271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
142010271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
142176c65fd3SAndreas Gohr        }
142210271ce4SAndreas Gohr        unset($menu['plugin']);
142310271ce4SAndreas Gohr
142476c65fd3SAndreas Gohr        if($menu['config']){
142510271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
142610271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
142710271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
142876c65fd3SAndreas Gohr        }
142910271ce4SAndreas Gohr        unset($menu['config']);
143010271ce4SAndreas Gohr    }
143110271ce4SAndreas Gohr    ptln('</ul>');
143210271ce4SAndreas Gohr
143310271ce4SAndreas Gohr    // Manager Tasks
143410271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
143510271ce4SAndreas Gohr
143676c65fd3SAndreas Gohr    if($menu['revert']){
143710271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
143810271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
143910271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
144076c65fd3SAndreas Gohr    }
144110271ce4SAndreas Gohr    unset($menu['revert']);
144210271ce4SAndreas Gohr
144376c65fd3SAndreas Gohr    if($menu['popularity']){
144410271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
144510271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
144610271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
144776c65fd3SAndreas Gohr    }
144810271ce4SAndreas Gohr    unset($menu['popularity']);
144910271ce4SAndreas Gohr
14509a2cec2eSAndreas Gohr    // print DokuWiki version:
145110271ce4SAndreas Gohr    ptln('</ul>');
14529a2cec2eSAndreas Gohr    echo '<div id="admin__version">';
14539a2cec2eSAndreas Gohr    echo getVersion();
14549a2cec2eSAndreas Gohr    echo '</div>';
145510271ce4SAndreas Gohr
145610271ce4SAndreas Gohr    // print the rest as sorted list
145710271ce4SAndreas Gohr    if(count($menu)){
1458746855cfSBen Coburn        usort($menu, 'p_sort_modes');
145911e2ce22Schris        // output the menu
146010271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
146110271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
146211e2ce22Schris        ptln('<ul>');
146311e2ce22Schris        foreach ($menu as $item) {
146411e2ce22Schris            if (!$item['prompt']) continue;
14650c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
146611e2ce22Schris        }
146711e2ce22Schris        ptln('</ul>');
1468ca3a6df1SMatthias Grimm    }
146910271ce4SAndreas Gohr}
1470c19fe9c0Sandi
14718b06d178Schris/**
14728b06d178Schris * Form to request a new password for an existing account
14738b06d178Schris *
14748b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
147511e2ce22Schris */
14768b06d178Schrisfunction html_resendpwd() {
14778b06d178Schris    global $lang;
14788b06d178Schris    global $conf;
14798b06d178Schris    global $ID;
1480c19fe9c0Sandi
14818b06d178Schris    print p_locale_xhtml('resendpwd');
1482fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1483e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1484fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1485fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1486fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1487fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1488fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1489fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1490fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1491fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1492fdb8d77bSTom N Harris    $form->endFieldset();
1493fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1494fdb8d77bSTom N Harris    print '</div>'.NL;
1495fdb8d77bSTom N Harris}
1496fdb8d77bSTom N Harris
1497fdb8d77bSTom N Harris/**
1498b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1499b8595a66SAndreas Gohr *
1500b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1501b8595a66SAndreas Gohr */
1502b8595a66SAndreas Gohrfunction html_TOC($toc){
1503b8595a66SAndreas Gohr    if(!count($toc)) return '';
1504b8595a66SAndreas Gohr    global $lang;
1505b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1506b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1507b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1508b8595a66SAndreas Gohr    $out .= $lang['toc'];
1509b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1510b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1511b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1512b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1513b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1514db959ae3SAndreas Gohr    return $out;
1515db959ae3SAndreas Gohr}
1516b8595a66SAndreas Gohr
1517b8595a66SAndreas Gohr/**
1518b8595a66SAndreas Gohr * Callback for html_buildlist
1519b8595a66SAndreas Gohr */
1520b8595a66SAndreas Gohrfunction html_list_toc($item){
1521c66972f2SAdrian Lang    if(isset($item['hid'])){
15227d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15237d91652aSAndreas Gohr    }else{
15247d91652aSAndreas Gohr        $link = $item['link'];
15257d91652aSAndreas Gohr    }
15267d91652aSAndreas Gohr
15277d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1528b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1529b8595a66SAndreas Gohr}
1530b8595a66SAndreas Gohr
1531b8595a66SAndreas Gohr/**
1532b8595a66SAndreas Gohr * Helper function to build TOC items
1533b8595a66SAndreas Gohr *
1534b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1535b8595a66SAndreas Gohr *
1536b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1537b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1538b8595a66SAndreas Gohr * @param int    $level - nesting level
1539b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1540b8595a66SAndreas Gohr */
1541b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1542b8595a66SAndreas Gohr    global $conf;
1543b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1544b8595a66SAndreas Gohr            'title' => $text,
1545b8595a66SAndreas Gohr            'type'  => 'ul',
15462bb0d541Schris            'level' => $level);
1547b8595a66SAndreas Gohr}
1548b8595a66SAndreas Gohr
1549b8595a66SAndreas Gohr/**
1550fdb8d77bSTom N Harris * Output a Doku_Form object.
1551fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1552fdb8d77bSTom N Harris *
1553fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1554fdb8d77bSTom N Harris */
1555fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1556fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1557fdb8d77bSTom N Harris    $form->endFieldset();
1558fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1559fdb8d77bSTom N Harris}
1560fdb8d77bSTom N Harris
1561fdb8d77bSTom N Harris/**
1562fdb8d77bSTom N Harris * Form print function.
1563fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1564fdb8d77bSTom N Harris */
1565fdb8d77bSTom N Harrisfunction html_form_output($data) {
1566fdb8d77bSTom N Harris    $data->printForm();
15678b06d178Schris}
1568340756e4Sandi
156907bf32b2SAndreas Gohr/**
157007bf32b2SAndreas Gohr * Embed a flash object in HTML
157107bf32b2SAndreas Gohr *
157207bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
157307bf32b2SAndreas Gohr * compatble way using valid XHTML
157407bf32b2SAndreas Gohr *
157507bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
157607bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
157707bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
157807bf32b2SAndreas Gohr * $lang['noflash'] is used.
157907bf32b2SAndreas Gohr *
158007bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
158107bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
158207bf32b2SAndreas Gohr *
158307bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
158407bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
158507bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
158607bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
158707bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
158807bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
158907bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
159007bf32b2SAndreas Gohr * @returns string         - the XHTML markup
159107bf32b2SAndreas Gohr */
159207bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
159307bf32b2SAndreas Gohr    global $lang;
159407bf32b2SAndreas Gohr
159507bf32b2SAndreas Gohr    $out = '';
159607bf32b2SAndreas Gohr
159707bf32b2SAndreas Gohr    // prepare the object attributes
159807bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
159907bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1600d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
160107bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
160207bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
160307bf32b2SAndreas Gohr
160407bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
160507bf32b2SAndreas Gohr    $std = $atts;
160607bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
160707bf32b2SAndreas Gohr    $std['data'] = $swf;
160807bf32b2SAndreas Gohr
160907bf32b2SAndreas Gohr    // add object attributes for IE
161007bf32b2SAndreas Gohr    $ie  = $atts;
161107bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
161207bf32b2SAndreas Gohr
161307bf32b2SAndreas Gohr    // open object (with conditional comments)
161407bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
161507bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
161607bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
161707bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
161807bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
161907bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16209ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
162107bf32b2SAndreas Gohr
162207bf32b2SAndreas Gohr    // print params
162307bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
162407bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
162507bf32b2SAndreas Gohr    }
162607bf32b2SAndreas Gohr
162707bf32b2SAndreas Gohr    // add flashvars
162807bf32b2SAndreas Gohr    if(is_array($flashvars)){
1629d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
163007bf32b2SAndreas Gohr    }
163107bf32b2SAndreas Gohr
163207bf32b2SAndreas Gohr    // alternative content
163307bf32b2SAndreas Gohr    if($alt){
163407bf32b2SAndreas Gohr        $out .= $alt.NL;
163507bf32b2SAndreas Gohr    }else{
163607bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
163707bf32b2SAndreas Gohr    }
163807bf32b2SAndreas Gohr
163907bf32b2SAndreas Gohr    // finish
164007bf32b2SAndreas Gohr    $out .= '</object>'.NL;
164107bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
164207bf32b2SAndreas Gohr
164307bf32b2SAndreas Gohr    return $out;
164407bf32b2SAndreas Gohr}
164507bf32b2SAndreas Gohr
1646