xref: /dokuwiki/inc/html.php (revision c95a5b7dd09aa1bd32e773cc1d582de72fb3e54c)
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 */
165d822118cSAdrian Langfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
166f3f0262cSandi    global $conf;
167f3f0262cSandi    global $lang;
168f3f0262cSandi
169f3f0262cSandi    $label = $lang['btn_'.$name];
170f3f0262cSandi
171f3f0262cSandi    $ret = '';
17235dae8b0SBen Coburn    $tip = '';
173f3f0262cSandi
17449c713a3Sandi    //filter id (without urlencoding)
17549c713a3Sandi    $id = idfilter($id,false);
176f3f0262cSandi
177f3f0262cSandi    //make nice URLs even for buttons
1786c7843b5Sandi    if($conf['userewrite'] == 2){
1796c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1806c7843b5Sandi    }elseif($conf['userewrite']){
1816c7843b5Sandi        $script = DOKU_BASE.$id;
1826c7843b5Sandi    }else{
1838b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
184f3f0262cSandi        $params['id'] = $id;
185f3f0262cSandi    }
186f3f0262cSandi
187b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
188f3f0262cSandi
18906a4bf8fSAndreas Gohr    if(is_array($params)){
190f3f0262cSandi        reset($params);
191f3f0262cSandi        while (list($key, $val) = each($params)) {
192f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
193f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
194f3f0262cSandi        }
19506a4bf8fSAndreas Gohr    }
196f3f0262cSandi
19735dae8b0SBen Coburn    if ($tooltip!='') {
19835dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
19911ea018fSAndreas Gohr    }else{
20011ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
20111ea018fSAndreas Gohr    }
20211ea018fSAndreas Gohr
203d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
20411ea018fSAndreas Gohr    if($akey){
20507493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
20687cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
20735dae8b0SBen Coburn    }
20835dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
209f3f0262cSandi    $ret .= '/>';
2104beabca9SAnika Henke    $ret .= '</div></form>';
211f3f0262cSandi
212f3f0262cSandi    return $ret;
213f3f0262cSandi}
214f3f0262cSandi
215f3f0262cSandi/**
21615fae107Sandi * show a wiki page
21715fae107Sandi *
21815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
21915fae107Sandi */
22011c78c94SAndreas Gohrfunction html_show($txt=null){
221f3f0262cSandi    global $ID;
222f3f0262cSandi    global $REV;
223f3f0262cSandi    global $HIGH;
224b8595a66SAndreas Gohr    global $INFO;
225f3f0262cSandi    //disable section editing for old revisions or in preview
2265400331dSandi    if($txt || $REV){
2276bbae538Sandi        $secedit = false;
2286bbae538Sandi    }else{
2296bbae538Sandi        $secedit = true;
230f3f0262cSandi    }
231f3f0262cSandi
23211c78c94SAndreas Gohr    if (!is_null($txt)){
233f3f0262cSandi        //PreviewHeader
234b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
235b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
236b8595a66SAndreas Gohr        echo '<div class="preview">';
237b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
238b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
239b8595a66SAndreas Gohr        echo $html;
240b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
241b8595a66SAndreas Gohr        echo '</div>';
2426bbae538Sandi
243f3f0262cSandi    }else{
244c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
245c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2466bbae538Sandi        $html = html_secedit($html,$secedit);
247b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
248b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
249b8595a66SAndreas Gohr        echo $html;
250f3f0262cSandi    }
251f3f0262cSandi}
252f3f0262cSandi
253f3f0262cSandi/**
254ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
255ee4c4a1bSAndreas Gohr *
256ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
257ee4c4a1bSAndreas Gohr */
258ee4c4a1bSAndreas Gohrfunction html_draft(){
259ee4c4a1bSAndreas Gohr    global $INFO;
260ee4c4a1bSAndreas Gohr    global $ID;
261ee4c4a1bSAndreas Gohr    global $lang;
262ee4c4a1bSAndreas Gohr    global $conf;
263ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
264ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
265ee4c4a1bSAndreas Gohr
266fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
267e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
268fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
269fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
270fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
271fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
272f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
273fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
274fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
275fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
276fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
277fdb8d77bSTom N Harris    html_form('draft', $form);
278ee4c4a1bSAndreas Gohr}
279ee4c4a1bSAndreas Gohr
280ee4c4a1bSAndreas Gohr/**
281f3f0262cSandi * Highlights searchqueries in HTML code
28215fae107Sandi *
28315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2847209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
285f3f0262cSandi */
286546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
287808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
288808551e3SAndreas Gohr    $regex = join('|',array_map('preg_quote_cb',$phrases));
28960c15d7dSAndreas Gohr
29060c15d7dSAndreas Gohr    if ($regex === '') return $html;
2911db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
292f3f0262cSandi    return $html;
293f3f0262cSandi}
294f3f0262cSandi
295f3f0262cSandi/**
2967209be23SAndreas Gohr * Callback used by html_hilight()
2977209be23SAndreas Gohr *
2987209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2997209be23SAndreas Gohr */
3007209be23SAndreas Gohrfunction html_hilight_callback($m) {
3017209be23SAndreas Gohr    $hlight = unslash($m[0]);
3027209be23SAndreas Gohr    if ( !isset($m[2])) {
303688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3047209be23SAndreas Gohr    }
3057209be23SAndreas Gohr    return $hlight;
3067209be23SAndreas Gohr}
3077209be23SAndreas Gohr
3087209be23SAndreas Gohr/**
30915fae107Sandi * Run a search and display the result
31015fae107Sandi *
31115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
312f3f0262cSandi */
313f3f0262cSandifunction html_search(){
314f3f0262cSandi    global $conf;
315f3f0262cSandi    global $QUERY;
316f3f0262cSandi    global $ID;
317f3f0262cSandi    global $lang;
318f3f0262cSandi
319c112d578Sandi    print p_locale_xhtml('searchpage');
320f3f0262cSandi    flush();
321f3f0262cSandi
322d0ab54f6SMichael Klier chi@chimeric.de    //check if search is restricted to namespace
323b42bcfe7Sdaniel.lindgren    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
324d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($match[1]);
325d0ab54f6SMichael Klier chi@chimeric.de    } else {
326d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($QUERY);
327d0ab54f6SMichael Klier chi@chimeric.de    }
328d0ab54f6SMichael Klier chi@chimeric.de
3294d9ff3d5Sandi    //show progressbar
330e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
331e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
332e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
333e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
334e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3359edac8a8SAndreas Gohr    flush();
3364d9ff3d5Sandi
337f3f0262cSandi    //do quick pagesearch
338f3f0262cSandi    $data = array();
339d0ab54f6SMichael Klier chi@chimeric.de
3408d22f1e9SAndreas Gohr    if($id) $data = ft_pageLookup($id,true,useHeading('navigation'));
341f3f0262cSandi    if(count($data)){
342f3f0262cSandi        print '<div class="search_quickresult">';
343746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3444f732f0eSAnika Henke        print '<ul class="search_quickhits">';
3458d22f1e9SAndreas Gohr        foreach($data as $id => $title){
3464f732f0eSAnika Henke            print '<li> ';
3478d22f1e9SAndreas Gohr            if (useHeading('navigation')) {
3488d22f1e9SAndreas Gohr                $name = $title;
3498d22f1e9SAndreas Gohr            }else{
350bd2f6c2fSAndreas Gohr                $ns = getNS($id);
351bd2f6c2fSAndreas Gohr                if($ns){
352bd2f6c2fSAndreas Gohr                    $name = shorten(noNS($id), ' ('.$ns.')',30);
353bd2f6c2fSAndreas Gohr                }else{
354bd2f6c2fSAndreas Gohr                    $name = $id;
355bd2f6c2fSAndreas Gohr                }
3568d22f1e9SAndreas Gohr            }
357bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3584f732f0eSAnika Henke            print '</li> ';
359f3f0262cSandi        }
360140c93f3SAnika Henke        print '</ul> ';
361f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
362f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
363f3f0262cSandi        print '</div>';
364f3f0262cSandi    }
365f3f0262cSandi    flush();
366f3f0262cSandi
367f3f0262cSandi    //do fulltext search
36860c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
369f3f0262cSandi    if(count($data)){
370506fa893SAndreas Gohr        $num = 1;
371506fa893SAndreas Gohr        foreach($data as $id => $cnt){
372f3f0262cSandi            print '<div class="search_result">';
373db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
374865c2687SKazutaka Miyasaka            if($cnt !== 0){
375506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
376bd0293e7SAndreas Gohr                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
37760c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
378506fa893SAndreas Gohr                }
379865c2687SKazutaka Miyasaka                $num++;
380865c2687SKazutaka Miyasaka            }
381f3f0262cSandi            print '</div>';
382506fa893SAndreas Gohr            flush();
383f3f0262cSandi        }
384f3f0262cSandi    }else{
385820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
386f3f0262cSandi    }
3874d9ff3d5Sandi
3884d9ff3d5Sandi    //hide progressbar
389e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
390e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
391e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3929edac8a8SAndreas Gohr    flush();
393f3f0262cSandi}
394f3f0262cSandi
39515fae107Sandi/**
39615fae107Sandi * Display error on locked pages
39715fae107Sandi *
39815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39915fae107Sandi */
400ee20e7d1Sandifunction html_locked(){
401f3f0262cSandi    global $ID;
402f3f0262cSandi    global $conf;
403f3f0262cSandi    global $lang;
40488f522e9Sandi    global $INFO;
405f3f0262cSandi
406c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
407f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
408f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
409f3f0262cSandi
410c112d578Sandi    print p_locale_xhtml('locked');
411f3f0262cSandi    print '<ul>';
4126d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
4130c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
414f3f0262cSandi    print '</ul>';
415f3f0262cSandi}
416f3f0262cSandi
41715fae107Sandi/**
41815fae107Sandi * list old revisions
41915fae107Sandi *
42015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
42171726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
42215fae107Sandi */
42371726d78SBen Coburnfunction html_revisions($first=0){
424f3f0262cSandi    global $ID;
425f3f0262cSandi    global $INFO;
426f3f0262cSandi    global $conf;
427f3f0262cSandi    global $lang;
42871726d78SBen Coburn    /* we need to get one additionally log entry to be able to
42971726d78SBen Coburn     * decide if this is the last page or is there another one.
43071726d78SBen Coburn     * see html_recent()
43171726d78SBen Coburn     */
43271726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
43371726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43471726d78SBen Coburn        $first=0;
43571726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
43671726d78SBen Coburn    }
43771726d78SBen Coburn    $hasNext = false;
43871726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
43971726d78SBen Coburn        $hasNext = true;
44071726d78SBen Coburn        array_pop($revisions); // remove extra log entry
44171726d78SBen Coburn    }
44271726d78SBen Coburn
443f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
444f3f0262cSandi
445c112d578Sandi    print p_locale_xhtml('revisions');
44637a1dc12Smichael
447e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
44837a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
44971726d78SBen Coburn    if($INFO['exists'] && $first==0){
45037a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
45137a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
45237a1dc12Smichael        else
45337a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
45437a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
45537a1dc12Smichael        $form->addElement(form_makeTag('input', array(
45637a1dc12Smichael                        'type' => 'checkbox',
45737a1dc12Smichael                        'name' => 'rev2[]',
45837a1dc12Smichael                        'value' => 'current')));
459f9b2fe70Sandi
46037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
46137a1dc12Smichael        $form->addElement($date);
46237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
463f9b2fe70Sandi
46437a1dc12Smichael        $form->addElement(form_makeTag('img', array(
46537a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
46637a1dc12Smichael                        'width' => '15',
46737a1dc12Smichael                        'height' => '11',
46837a1dc12Smichael                        'alt'    => '')));
469cffcc403Sandi
47037a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
47137a1dc12Smichael                        'class' => 'wikilink1',
47237a1dc12Smichael                        'href'  => wl($ID))));
47337a1dc12Smichael        $form->addElement($ID);
47437a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
475652610a2Sandi
47637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
47737a1dc12Smichael        $form->addElement(' &ndash; ');
47837a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
47937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
480652610a2Sandi
48137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
48237a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
48337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
48437a1dc12Smichael
48537a1dc12Smichael        $form->addElement('('.$lang['current'].')');
48637a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
48737a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
488f3f0262cSandi    }
489f3f0262cSandi
490f3f0262cSandi    foreach($revisions as $rev){
491f2263577SAndreas Gohr        $date   = dformat($rev);
492fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
493103c256aSChris Smith        $exists = page_exists($ID,$rev);
494652610a2Sandi
49537a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
49637a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
49737a1dc12Smichael        else
49837a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
49937a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
50077707b04SAndreas Gohr        if($exists){
50137a1dc12Smichael            $form->addElement(form_makeTag('input', array(
50237a1dc12Smichael                            'type' => 'checkbox',
50337a1dc12Smichael                            'name' => 'rev2[]',
50437a1dc12Smichael                            'value' => $rev)));
50577707b04SAndreas Gohr        }else{
50637a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50737a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
50837a1dc12Smichael                            'width' => 14,
50937a1dc12Smichael                            'height' => 11,
51037a1dc12Smichael                            'alt' => '')));
51141396b71SAndreas Gohr        }
512f9b2fe70Sandi
51337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
51437a1dc12Smichael        $form->addElement($date);
51537a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
51637a1dc12Smichael
51737a1dc12Smichael        if($exists){
51837a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
51937a1dc12Smichael            $form->addElement(form_makeTag('img', array(
52037a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
52137a1dc12Smichael                            'width'  => 15,
52237a1dc12Smichael                            'height' => 11,
52337a1dc12Smichael                            'title'  => $lang['diff'],
52437a1dc12Smichael                            'alt'    => $lang['diff'])));
52537a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52637a1dc12Smichael
52737a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
52837a1dc12Smichael            $form->addElement($ID);
52937a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
53037a1dc12Smichael        }else{
53137a1dc12Smichael            $form->addElement(form_makeTag('img', array(
53237a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
53337a1dc12Smichael                            'width' => '15',
53437a1dc12Smichael                            'height' => '11',
53537a1dc12Smichael                            'alt'   => '')));
53637a1dc12Smichael            $form->addElement($ID);
53737a1dc12Smichael        }
53837a1dc12Smichael
53937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
54037a1dc12Smichael        $form->addElement(' &ndash; ');
54137a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
54237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
54337a1dc12Smichael
54437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
54588f522e9Sandi        if($info['user']){
54637a1dc12Smichael            $form->addElement(editorinfo($info['user']));
547433efb25SAndreas Gohr            if(auth_ismanager()){
548433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
549433efb25SAndreas Gohr            }
55088f522e9Sandi        }else{
55137a1dc12Smichael            $form->addElement($info['ip']);
55288f522e9Sandi        }
55337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
554652610a2Sandi
55537a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
55637a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
557f3f0262cSandi    }
55837a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
55937a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
56037a1dc12Smichael    html_form('revisions', $form);
56171726d78SBen Coburn
56271726d78SBen Coburn    print '<div class="pagenav">';
56371726d78SBen Coburn    $last = $first + $conf['recent'];
56471726d78SBen Coburn    if ($first > 0) {
56571726d78SBen Coburn        $first -= $conf['recent'];
56671726d78SBen Coburn        if ($first < 0) $first = 0;
56771726d78SBen Coburn        print '<div class="pagenav-prev">';
568eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
56971726d78SBen Coburn        print '</div>';
57071726d78SBen Coburn    }
57171726d78SBen Coburn    if ($hasNext) {
57271726d78SBen Coburn        print '<div class="pagenav-next">';
573eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
57471726d78SBen Coburn        print '</div>';
57571726d78SBen Coburn    }
57671726d78SBen Coburn    print '</div>';
57771726d78SBen Coburn
578f3f0262cSandi}
579f3f0262cSandi
58015fae107Sandi/**
58115fae107Sandi * display recent changes
58215fae107Sandi *
58315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5845749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
58571726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
58615fae107Sandi */
587a39955b0Smatthiasgrimmfunction html_recent($first=0){
588f3f0262cSandi    global $conf;
589cffcc403Sandi    global $lang;
590dbb00abcSEsther Brunner    global $ID;
5915749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5925749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5935749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5945749f1ceSmatthiasgrimm     */
595b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5965749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5975749f1ceSmatthiasgrimm        $first=0;
59871726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5995749f1ceSmatthiasgrimm    }
60071726d78SBen Coburn    $hasNext = false;
60171726d78SBen Coburn    if (count($recents)>$conf['recent']) {
60271726d78SBen Coburn        $hasNext = true;
60371726d78SBen Coburn        array_pop($recents); // remove extra log entry
60471726d78SBen Coburn    }
605f3f0262cSandi
606c112d578Sandi    print p_locale_xhtml('recent');
607e83cef14SGina Haeussge
608e83cef14SGina Haeussge    if (getNS($ID) != '')
6099e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
610e83cef14SGina Haeussge
611e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
612abdcc39fSmichael    $form->addHidden('sectok', null);
613abdcc39fSmichael    $form->addHidden('do', 'recent');
614abdcc39fSmichael    $form->addHidden('id', $ID);
615abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
616a39955b0Smatthiasgrimm
617d437bcc4SAndreas Gohr    foreach($recents as $recent){
618f2263577SAndreas Gohr        $date = dformat($recent['date']);
619abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
620abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
621abdcc39fSmichael        else
622abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
623cffcc403Sandi
624abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
625f9b2fe70Sandi
626abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
627abdcc39fSmichael        $form->addElement($date);
628abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
629cffcc403Sandi
630cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
631abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
632abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
633abdcc39fSmichael                        'width' => 15,
634abdcc39fSmichael                        'height'=> 11,
635abdcc39fSmichael                        'title' => $lang['diff'],
636abdcc39fSmichael                        'alt'   => $lang['diff']
637abdcc39fSmichael                        )));
638abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
639cffcc403Sandi
640cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
641abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
642abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
643abdcc39fSmichael                        'width' => 12,
644abdcc39fSmichael                        'height'=> 14,
645abdcc39fSmichael                        'title' => $lang['btn_revs'],
646abdcc39fSmichael                        'alt'   => $lang['btn_revs']
647abdcc39fSmichael                        )));
648abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
649b6912aeaSAndreas Gohr
650db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
651abdcc39fSmichael
652abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
653abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
654abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
655abdcc39fSmichael
656abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
657d437bcc4SAndreas Gohr        if($recent['user']){
658abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
659433efb25SAndreas Gohr            if(auth_ismanager()){
660433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
661433efb25SAndreas Gohr            }
66288f522e9Sandi        }else{
663abdcc39fSmichael            $form->addElement($recent['ip']);
66488f522e9Sandi        }
665abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
666cffcc403Sandi
667abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
668abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
669f3f0262cSandi    }
670abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
671a39955b0Smatthiasgrimm
672abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6735749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
674a39955b0Smatthiasgrimm    if ($first > 0) {
675a39955b0Smatthiasgrimm        $first -= $conf['recent'];
676a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
677abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
678abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
679abdcc39fSmichael                    'type'  => 'submit',
680abdcc39fSmichael                    'name'  => 'first['.$first.']',
681cddd152cSmichael                    'value' => $lang['btn_newer'],
682cddd152cSmichael                    'accesskey' => 'n',
683f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
68418d107cbSMichael Klier                    'class' => 'button'
685abdcc39fSmichael                    )));
686abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
687a39955b0Smatthiasgrimm    }
68871726d78SBen Coburn    if ($hasNext) {
689abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
690abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
691abdcc39fSmichael                        'type'  => 'submit',
692abdcc39fSmichael                        'name'  => 'first['.$last.']',
693cddd152cSmichael                        'value' => $lang['btn_older'],
694cddd152cSmichael                        'accesskey' => 'p',
695f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
69618d107cbSMichael Klier                        'class' => 'button'
697abdcc39fSmichael                        )));
698abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
699a39955b0Smatthiasgrimm    }
700abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
701abdcc39fSmichael    html_form('recent', $form);
702f3f0262cSandi}
703f3f0262cSandi
70415fae107Sandi/**
70515fae107Sandi * Display page index
70615fae107Sandi *
70715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
70815fae107Sandi */
709f3f0262cSandifunction html_index($ns){
710f3f0262cSandi    global $conf;
711f3f0262cSandi    global $ID;
712f3f0262cSandi    $dir = $conf['datadir'];
713f3f0262cSandi    $ns  = cleanID($ns);
71430f1737dSandi    #fixme use appropriate function
715f3f0262cSandi    if(empty($ns)){
716f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
717f3f0262cSandi        if($ns == '.') $ns ='';
718f3f0262cSandi    }
71988d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
720f3f0262cSandi
721a06884abSAndreas Gohr    echo p_locale_xhtml('index');
722a06884abSAndreas Gohr    echo '<div id="index__tree">';
723f3f0262cSandi
724f3f0262cSandi    $data = array();
725f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
726a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
727a06884abSAndreas Gohr
728a06884abSAndreas Gohr    echo '</div>';
729f3f0262cSandi}
730f3f0262cSandi
731f3f0262cSandi/**
73215fae107Sandi * Index item formatter
73315fae107Sandi *
734f3f0262cSandi * User function for html_buildlist()
73515fae107Sandi *
73615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
737f3f0262cSandi */
738f3f0262cSandifunction html_list_index($item){
739d98d4540SBen Coburn    global $ID;
740f3f0262cSandi    $ret = '';
741f3f0262cSandi    $base = ':'.$item['id'];
742f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
743f3f0262cSandi    if($item['type']=='d'){
7444a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
745f3f0262cSandi        $ret .= $base;
746ed7ecb79SAnika Henke        $ret .= '</strong></a>';
747f3f0262cSandi    }else{
748f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
749f3f0262cSandi    }
750f3f0262cSandi    return $ret;
751f3f0262cSandi}
752f3f0262cSandi
753f3f0262cSandi/**
754cb70c441Sandi * Index List item
755cb70c441Sandi *
756cb70c441Sandi * This user function is used in html_build_lidt to build the
757cb70c441Sandi * <li> tags for namespaces when displaying the page index
758cb70c441Sandi * it gives different classes to opened or closed "folders"
759cb70c441Sandi *
760cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
761cb70c441Sandi */
762cb70c441Sandifunction html_li_index($item){
763cb70c441Sandi    if($item['type'] == "f"){
764cb70c441Sandi        return '<li class="level'.$item['level'].'">';
765cb70c441Sandi    }elseif($item['open']){
766cb70c441Sandi        return '<li class="open">';
767cb70c441Sandi    }else{
768cb70c441Sandi        return '<li class="closed">';
769cb70c441Sandi    }
770cb70c441Sandi}
771cb70c441Sandi
772cb70c441Sandi/**
773cb70c441Sandi * Default List item
774cb70c441Sandi *
775cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
776cb70c441Sandi */
777cb70c441Sandifunction html_li_default($item){
778cb70c441Sandi    return '<li class="level'.$item['level'].'">';
779cb70c441Sandi}
780cb70c441Sandi
781cb70c441Sandi/**
78215fae107Sandi * Build an unordered list
78315fae107Sandi *
784f3f0262cSandi * Build an unordered list from the given $data array
785f3f0262cSandi * Each item in the array has to have a 'level' property
786f3f0262cSandi * the item itself gets printed by the given $func user
787cb70c441Sandi * function. The second and optional function is used to
788cb70c441Sandi * print the <li> tag. Both user function need to accept
789cb70c441Sandi * a single item.
79015fae107Sandi *
791c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
792c5a8fd96SAndreas Gohr * a member of an object.
793c5a8fd96SAndreas Gohr *
79415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
795f3f0262cSandi */
796cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
797f3f0262cSandi    $level = 0;
798f3f0262cSandi    $opens = 0;
799f3f0262cSandi    $ret   = '';
800f3f0262cSandi
801f3f0262cSandi    foreach ($data as $item){
802f3f0262cSandi
803f3f0262cSandi        if( $item['level'] > $level ){
804f3f0262cSandi            //open new list
805df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
806df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
807f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
808df52d0feSandi            }
809f3f0262cSandi        }elseif( $item['level'] < $level ){
810f3f0262cSandi            //close last item
811f3f0262cSandi            $ret .= "</li>\n";
812f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
813f3f0262cSandi                //close higher lists
814f3f0262cSandi                $ret .= "</ul>\n</li>\n";
815f3f0262cSandi            }
816f3f0262cSandi        }else{
817f3f0262cSandi            //close last item
818f3f0262cSandi            $ret .= "</li>\n";
819f3f0262cSandi        }
820f3f0262cSandi
821f3f0262cSandi        //remember current level
822f3f0262cSandi        $level = $item['level'];
823f3f0262cSandi
824f3f0262cSandi        //print item
82534dbe711Schris        $ret .= call_user_func($lifunc,$item);
8260c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
82734dbe711Schris
82834dbe711Schris        $ret .= call_user_func($func,$item);
8290c6b58a8SAndreas Gohr        $ret .= '</div>';
830f3f0262cSandi    }
831f3f0262cSandi
832f3f0262cSandi    //close remaining items and lists
833f3f0262cSandi    for ($i=0; $i < $level; $i++){
834f3f0262cSandi        $ret .= "</li></ul>\n";
835f3f0262cSandi    }
836f3f0262cSandi
837f3f0262cSandi    return $ret;
838f3f0262cSandi}
839f3f0262cSandi
84015fae107Sandi/**
84115fae107Sandi * display backlinks
84215fae107Sandi *
84315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
84411df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
84515fae107Sandi */
846f3f0262cSandifunction html_backlinks(){
847f3f0262cSandi    global $ID;
848f3f0262cSandi    global $conf;
84911df47ecSMichael Klier    global $lang;
850f3f0262cSandi
851c112d578Sandi    print p_locale_xhtml('backlinks');
852f3f0262cSandi
85354f4c056SAndreas Gohr    $data = ft_backlinks($ID);
854f3f0262cSandi
85511df47ecSMichael Klier    if(!empty($data)) {
856f3f0262cSandi        print '<ul class="idx">';
85754f4c056SAndreas Gohr        foreach($data as $blink){
8580c6b58a8SAndreas Gohr            print '<li><div class="li">';
859db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8600c6b58a8SAndreas Gohr            print '</div></li>';
861f3f0262cSandi        }
862f3f0262cSandi        print '</ul>';
86311df47ecSMichael Klier    } else {
86411df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
86511df47ecSMichael Klier    }
866f3f0262cSandi}
867f3f0262cSandi
86815fae107Sandi/**
86915fae107Sandi * show diff
87015fae107Sandi *
87115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
87215fae107Sandi */
873f3f0262cSandifunction html_diff($text='',$intro=true){
874f3f0262cSandi    global $ID;
875f3f0262cSandi    global $REV;
876f3f0262cSandi    global $lang;
877f3f0262cSandi    global $conf;
878e1bd90ffSAndreas Gohr
87977707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
88077707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
88177707b04SAndreas Gohr    // array in rev2.
88277707b04SAndreas Gohr    $rev1 = $REV;
8837b3f8b16SAndreas Gohr
88477707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
88577707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
88677707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
88754041c77SAndreas Gohr
88854041c77SAndreas Gohr        if(!$rev1){
88954041c77SAndreas Gohr            $rev1 = $rev2;
89054041c77SAndreas Gohr            unset($rev2);
89154041c77SAndreas Gohr        }
892f3f0262cSandi    }else{
89377707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
8944d58bd99Sandi    }
8954d58bd99Sandi
89677707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
89777707b04SAndreas Gohr        $l_rev   = '';
89877707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
89977707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
900f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
90177707b04SAndreas Gohr            $lang['current'];
90277707b04SAndreas Gohr
90377707b04SAndreas Gohr        $r_rev   = '';
90477707b04SAndreas Gohr        $r_text  = cleanText($text);
90577707b04SAndreas Gohr        $r_head  = $lang['yours'];
906e1bd90ffSAndreas Gohr    }else{
90777707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
90854041c77SAndreas Gohr            // make sure order is correct (older on the left)
90977707b04SAndreas Gohr            if($rev1 < $rev2){
91077707b04SAndreas Gohr                $l_rev = $rev1;
91177707b04SAndreas Gohr                $r_rev = $rev2;
91277707b04SAndreas Gohr            }else{
91377707b04SAndreas Gohr                $l_rev = $rev2;
91477707b04SAndreas Gohr                $r_rev = $rev1;
915e1bd90ffSAndreas Gohr            }
91677707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
91777707b04SAndreas Gohr            $r_rev = '';
91877707b04SAndreas Gohr            $l_rev = $rev1;
91977707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
92077707b04SAndreas Gohr            $r_rev = '';
92177707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
92277707b04SAndreas Gohr            $l_rev = $revs[0];
9236f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
92477707b04SAndreas Gohr        }
92577707b04SAndreas Gohr
9267b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9277b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9287b3f8b16SAndreas Gohr            $l_text = '';
9297b3f8b16SAndreas Gohr        }else{
93077707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9317b3f8b16SAndreas Gohr        }
93277707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
93377707b04SAndreas Gohr
9347b3f8b16SAndreas Gohr        if(!$l_rev){
9357b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9367b3f8b16SAndreas Gohr        }else{
937e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
938db959ae3SAndreas Gohr            if($l_info['user']){
939db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
940e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
941db959ae3SAndreas Gohr            } else {
942db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
943db959ae3SAndreas Gohr            }
944e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
945e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
946e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
947e5e61eb0SAnika Henke
94877707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
949f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
950e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9517b3f8b16SAndreas Gohr        }
95277707b04SAndreas Gohr
95377707b04SAndreas Gohr        if($r_rev){
954e5e61eb0SAnika Henke            $r_info   = getRevisionInfo($ID,$r_rev,true);
955db959ae3SAndreas Gohr            if($r_info['user']){
956db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
957e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
958db959ae3SAndreas Gohr            } else {
959db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
960db959ae3SAndreas Gohr            }
961e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
962e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
963e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
964e5e61eb0SAnika Henke
96577707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
966f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
967e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9687b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
969e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
970db959ae3SAndreas Gohr            if($_info['user']){
971db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
972e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
973db959ae3SAndreas Gohr            } else {
974db959ae3SAndreas Gohr                $_user = $_info['ip'];
975db959ae3SAndreas Gohr            }
976e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
977e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
978e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
979e5e61eb0SAnika Henke
98077707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
981f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
982658b1aa0SAnika Henke            '('.$lang['current'].')'.
983e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9847b3f8b16SAndreas Gohr        }else{
985658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
986f3f0262cSandi        }
98777707b04SAndreas Gohr    }
98877707b04SAndreas Gohr
98977707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
99077707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
99177707b04SAndreas Gohr
992f3f0262cSandi    $tdf = new TableDiffFormatter();
993c112d578Sandi    if($intro) print p_locale_xhtml('diff');
994226bf2dcSGina Haeussge
995226bf2dcSGina Haeussge    if (!$text) {
9968d9e6ae7SAnika Henke        $diffurl = wl($ID, array('do'=>'diff', 'rev2[0]'=>$l_rev, 'rev2[1]'=>$r_rev));
9978d9e6ae7SAnika Henke        ptln('<p class="difflink">');
9988d9e6ae7SAnika Henke        ptln('  <a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>');
9998d9e6ae7SAnika Henke        ptln('</p>');
1000226bf2dcSGina Haeussge    }
1001f3f0262cSandi    ?>
1002daf4ca4eSAnika Henke    <table class="diff">
1003f3f0262cSandi    <tr>
1004e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
100577707b04SAndreas Gohr    <?php echo $l_head?>
1006daf4ca4eSAnika Henke    </th>
1007e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
100877707b04SAndreas Gohr    <?php echo $r_head?>
1009daf4ca4eSAnika Henke    </th>
1010f3f0262cSandi    </tr>
10114da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
1012f3f0262cSandi    </table>
10134da078a3Smatthiasgrimm    <?php
1014f3f0262cSandi}
1015f3f0262cSandi
101615fae107Sandi/**
101715fae107Sandi * show warning on conflict detection
101815fae107Sandi *
101915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
102015fae107Sandi */
1021f3f0262cSandifunction html_conflict($text,$summary){
1022f3f0262cSandi    global $ID;
1023f3f0262cSandi    global $lang;
1024f3f0262cSandi
1025c112d578Sandi    print p_locale_xhtml('conflict');
1026e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1027fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1028fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1029fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1030fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1031fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1032fdb8d77bSTom N Harris    html_form('conflict', $form);
1033fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1034f3f0262cSandi}
1035f3f0262cSandi
1036f3f0262cSandi/**
103715fae107Sandi * Prints the global message array
103815fae107Sandi *
103915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1040f3f0262cSandi */
1041f3f0262cSandifunction html_msgarea(){
1042f3f0262cSandi    global $MSG;
1043f3f0262cSandi    if(!isset($MSG)) return;
1044f3f0262cSandi
10454af9f0d4SAndreas Gohr    $shown = array();
1046f3f0262cSandi    foreach($MSG as $msg){
10474af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10484af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1049f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1050f3f0262cSandi        print $msg['msg'];
1051f3f0262cSandi        print '</div>';
10524af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1053f3f0262cSandi    }
1054f3f0262cSandi}
1055f3f0262cSandi
1056f3f0262cSandi/**
1057f3f0262cSandi * Prints the registration form
105815fae107Sandi *
105915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1060f3f0262cSandi */
1061f3f0262cSandifunction html_register(){
1062f3f0262cSandi    global $lang;
1063cab2716aSmatthias.grimm    global $conf;
1064f3f0262cSandi    global $ID;
1065f3f0262cSandi
1066c112d578Sandi    print p_locale_xhtml('register');
1067fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1068e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1069fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1070fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1071fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1072fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1073cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1074fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1075fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1076cab2716aSmatthias.grimm    }
1077fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1078fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1079fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1080fdb8d77bSTom N Harris    $form->endFieldset();
1081fdb8d77bSTom N Harris    html_form('register', $form);
1082cab2716aSmatthias.grimm
1083fdb8d77bSTom N Harris    print '</div>'.NL;
1084f3f0262cSandi}
1085f3f0262cSandi
1086f3f0262cSandi/**
10878b06d178Schris * Print the update profile form
10888b06d178Schris *
10898b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10908b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10918b06d178Schris */
10928b06d178Schrisfunction html_updateprofile(){
10938b06d178Schris    global $lang;
10948b06d178Schris    global $conf;
10958b06d178Schris    global $ID;
10968b06d178Schris    global $INFO;
109782fd59b6SAndreas Gohr    global $auth;
10988b06d178Schris
10998b06d178Schris    print p_locale_xhtml('updateprofile');
11008b06d178Schris
11018b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
11028b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1103fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1104e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1105fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1106fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1107fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1108fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1109fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1110fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1111fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
111239ba8890SAndreas Gohr    $attr = array('size'=>'50');
111339ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1114fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1115fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1116fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1117fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1118fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1119fdb8d77bSTom N Harris    }
1120fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1121fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1122fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1123fdb8d77bSTom N Harris    }
1124fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1125fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1126fdb8d77bSTom N Harris    $form->endFieldset();
1127fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1128fdb8d77bSTom N Harris    print '</div>'.NL;
11298b06d178Schris}
11308b06d178Schris
11318b06d178Schris/**
11327c4635c4SAdrian Lang * Preprocess edit form data
113315fae107Sandi *
113415fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
11352ffea8f2SAdrian Lang *
11362ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1137f3f0262cSandi */
11385a932e77SAdrian Langfunction html_edit(){
1139f3f0262cSandi    global $ID;
1140f3f0262cSandi    global $REV;
1141f3f0262cSandi    global $DATE;
1142f3f0262cSandi    global $PRE;
1143f3f0262cSandi    global $SUF;
1144f3f0262cSandi    global $INFO;
1145f3f0262cSandi    global $SUM;
1146f3f0262cSandi    global $lang;
1147f3f0262cSandi    global $conf;
114845a99335SAdrian Lang    global $TEXT;
1149d141c8dcSAdrian Lang    global $RANGE;
1150f3f0262cSandi
11518fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
11528fe3bb00STom N Harris        $check = $_REQUEST['changecheck'];
115345a99335SAdrian Lang    } elseif(!$INFO['exists']){
115445a99335SAdrian Lang        // $TEXT has been loaded from page template
115545a99335SAdrian Lang        $check = md5('');
11568fe3bb00STom N Harris    } else {
115745a99335SAdrian Lang        $check = md5($TEXT);
11588fe3bb00STom N Harris    }
115945a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1160f3f0262cSandi
116127eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
116245a99335SAdrian Lang    $include = 'edit';
1163f3f0262cSandi    if($wr){
1164ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1165f3f0262cSandi    }else{
1166409d7af7SAndreas Gohr        // check pseudo action 'source'
1167409d7af7SAndreas Gohr        if(!actionOK('source')){
1168409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1169409d7af7SAndreas Gohr            return;
1170409d7af7SAndreas Gohr        }
1171ffde0ac9SAdrian Lang        $include = 'read';
1172f3f0262cSandi    }
11737c4635c4SAdrian Lang
11747c4635c4SAdrian Lang    global $license;
117542c7abd6SAndreas Gohr
1176e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1177fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1178fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1179fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
1180fdb8d77bSTom N Harris    $form->addHidden('prefix', $PRE);
1181fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1182fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
11838e4da260SAdrian Lang
11842ffea8f2SAdrian Lang    $data = array('form' => $form,
11852ffea8f2SAdrian Lang                  'wr'   => $wr,
11862ffea8f2SAdrian Lang                  'media_manager' => true,
118712c96aceSAdrian Lang                  'target' => (isset($_REQUEST['target']) && $wr &&
118812c96aceSAdrian Lang                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
11892ffea8f2SAdrian Lang                  'intro_locale' => $include);
119012c96aceSAdrian Lang
119112c96aceSAdrian Lang    if ($data['target'] !== 'section') {
119212c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
119312c96aceSAdrian Lang        // edit target is not section.
11948e4da260SAdrian Lang        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
11952ffea8f2SAdrian Lang    } else {
11962ffea8f2SAdrian Lang        html_edit_form($data);
11972ffea8f2SAdrian Lang    }
1198ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1199ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1200ffde0ac9SAdrian Lang    }
12018e4da260SAdrian Lang
1202b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
1203fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1204fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1205fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1206fdb8d77bSTom N Harris    if ($wr) {
1207fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1208fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1209fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1210fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1211fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1212fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1213fdb8d77bSTom N Harris        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1214fdb8d77bSTom N Harris        $elem = html_minoredit();
1215fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1216fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1217fdb8d77bSTom N Harris    }
1218fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
12195808bc54SAndreas Gohr    if($wr && $conf['license']){
1220066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1221066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1222066fee30SAndreas Gohr        $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
122384645d8cSAndreas Gohr        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1224066fee30SAndreas Gohr        $out .= '> '.$license[$conf['license']]['name'].'</a>';
1225066fee30SAndreas Gohr        $form->addElement($out);
1226066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1227066fee30SAndreas Gohr    }
12288e4da260SAdrian Lang
12298e4da260SAdrian Lang    if ($wr) {
12308e4da260SAdrian Lang        // sets changed to true when previewed
12312e61e4dfSAdrian Lang        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
12328e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
12332e61e4dfSAdrian Lang        echo '//--><!]]></script>' . NL;
12348e4da260SAdrian Lang    } ?>
12358e4da260SAdrian Lang    <div style="width:99%;">
12368e4da260SAdrian Lang
12378e4da260SAdrian Lang    <div class="toolbar">
12388e4da260SAdrian Lang    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
12398e4da260SAdrian 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']?>"
12408e4da260SAdrian Lang        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
12418e4da260SAdrian Lang
12428e4da260SAdrian Lang    </div>
12438e4da260SAdrian Lang    <?php
12448e4da260SAdrian Lang
1245fdb8d77bSTom N Harris    html_form('edit', $form);
1246fdb8d77bSTom N Harris    print '</div>'.NL;
1247f3f0262cSandi}
1248f3f0262cSandi
1249f3f0262cSandi/**
12508e4da260SAdrian Lang * Display the default edit form
12518e4da260SAdrian Lang *
12528e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
12538e4da260SAdrian Lang */
12548e4da260SAdrian Langfunction html_edit_form($param) {
125545a99335SAdrian Lang    global $TEXT;
125612c96aceSAdrian Lang
125712c96aceSAdrian Lang    if ($param['target'] !== 'section') {
125812c96aceSAdrian Lang        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
125912c96aceSAdrian Lang    }
126012c96aceSAdrian Lang
12618e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
126212c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
126312c96aceSAdrian Lang
126412c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
12658e4da260SAdrian Lang}
12668e4da260SAdrian Lang
12678e4da260SAdrian Lang/**
1268b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1269b6912aeaSAndreas Gohr *
1270b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1271b6912aeaSAndreas Gohr */
1272b6912aeaSAndreas Gohrfunction html_minoredit(){
1273b6912aeaSAndreas Gohr    global $conf;
1274b6912aeaSAndreas Gohr    global $lang;
1275b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1276b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1277fdb8d77bSTom N Harris        return false;
1278b6912aeaSAndreas Gohr    }
1279b6912aeaSAndreas Gohr
1280b6912aeaSAndreas Gohr    $p = array();
1281b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1282bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1283fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1284b6912aeaSAndreas Gohr}
1285b6912aeaSAndreas Gohr
1286b6912aeaSAndreas Gohr/**
1287f3f0262cSandi * prints some debug info
128815fae107Sandi *
128915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1290f3f0262cSandi */
1291f3f0262cSandifunction html_debug(){
1292f3f0262cSandi    global $conf;
1293d16a4edaSandi    global $lang;
12945298a619SAndreas Gohr    global $auth;
1295100a97e3SAndreas Gohr    global $INFO;
1296100a97e3SAndreas Gohr
129728fb55ffSandi    //remove sensitive data
129828fb55ffSandi    $cnf = $conf;
129924297a69SAndreas Gohr    debug_guard($cnf);
1300100a97e3SAndreas Gohr    $nfo = $INFO;
130124297a69SAndreas Gohr    debug_guard($nfo);
1302100a97e3SAndreas Gohr    $ses = $_SESSION;
130324297a69SAndreas Gohr    debug_guard($ses);
1304f3f0262cSandi
1305f3f0262cSandi    print '<html><body>';
1306f3f0262cSandi
1307f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1308f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1309f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1310f3f0262cSandi
1311100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1312100a97e3SAndreas Gohr    print_r($nfo);
1313100a97e3SAndreas Gohr    print '</pre>';
1314100a97e3SAndreas Gohr
1315f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1316f3f0262cSandi    print_r($_SERVER);
1317f3f0262cSandi    print '</pre>';
1318f3f0262cSandi
1319f3f0262cSandi    print '<b>$conf:</b><pre>';
132028fb55ffSandi    print_r($cnf);
1321f3f0262cSandi    print '</pre>';
1322f3f0262cSandi
1323ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1324ed7b5f09Sandi    print DOKU_BASE;
1325f3f0262cSandi    print '</pre>';
1326f3f0262cSandi
1327ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1328ed7b5f09Sandi    print DOKU_URL;
1329ed7b5f09Sandi    print '</pre>';
1330ed7b5f09Sandi
1331ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1332f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1333f3f0262cSandi    print '</pre>';
1334f3f0262cSandi
1335f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1336f3f0262cSandi    print phpversion();
1337f3f0262cSandi    print '</pre>';
1338f3f0262cSandi
1339f3f0262cSandi    print '<b>locale:</b><pre>';
1340f3f0262cSandi    print setlocale(LC_ALL,0);
1341f3f0262cSandi    print '</pre>';
1342f3f0262cSandi
1343d16a4edaSandi    print '<b>encoding:</b><pre>';
1344d16a4edaSandi    print $lang['encoding'];
1345d16a4edaSandi    print '</pre>';
1346d16a4edaSandi
13475298a619SAndreas Gohr    if($auth){
13485298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13495298a619SAndreas Gohr        print_r($auth->cando);
13505298a619SAndreas Gohr        print '</pre>';
13515298a619SAndreas Gohr    }
13525298a619SAndreas Gohr
13533aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1354100a97e3SAndreas Gohr    print_r($ses);
13553aa54d7cSAndreas Gohr    print '</pre>';
13563aa54d7cSAndreas Gohr
1357f3f0262cSandi    print '<b>Environment:</b><pre>';
1358f3f0262cSandi    print_r($_ENV);
1359f3f0262cSandi    print '</pre>';
1360f3f0262cSandi
1361f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1362f3f0262cSandi    $inis = ini_get_all();
1363f3f0262cSandi    print_r($inis);
1364f3f0262cSandi    print '</pre>';
1365f3f0262cSandi
1366f3f0262cSandi    print '</body></html>';
1367f3f0262cSandi}
1368f3f0262cSandi
136910271ce4SAndreas Gohr/**
137010271ce4SAndreas Gohr * List available Administration Tasks
137110271ce4SAndreas Gohr *
137210271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
137310271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
137410271ce4SAndreas Gohr */
1375c19fe9c0Sandifunction html_admin(){
1376c19fe9c0Sandi    global $ID;
1377f8cc712eSAndreas Gohr    global $INFO;
1378c19fe9c0Sandi    global $lang;
1379ca3a6df1SMatthias Grimm    global $conf;
138010271ce4SAndreas Gohr    global $auth;
1381c19fe9c0Sandi
138211e2ce22Schris    // build menu of admin functions from the plugins that handle them
138311e2ce22Schris    $pluginlist = plugin_list('admin');
138411e2ce22Schris    $menu = array();
138511e2ce22Schris    foreach ($pluginlist as $p) {
1386db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1387f8cc712eSAndreas Gohr
1388f8cc712eSAndreas Gohr        // check permissions
1389f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1390f8cc712eSAndreas Gohr
139110271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
139211e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
139311e2ce22Schris                'sort' => $obj->getMenuSort()
139411e2ce22Schris                );
139511e2ce22Schris    }
139611e2ce22Schris
1397*c95a5b7dSAndreas Gohr    // data security check
1398*c95a5b7dSAndreas Gohr    echo '<a style="background: transparent url(data/security.png) left top no-repeat;
1399*c95a5b7dSAndreas Gohr                  display: block; width:380px; height:73px; border:none; float:right"
1400*c95a5b7dSAndreas Gohr           target="_blank"
1401*c95a5b7dSAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>';
1402*c95a5b7dSAndreas Gohr
140310271ce4SAndreas Gohr    print p_locale_xhtml('admin');
140410271ce4SAndreas Gohr
140510271ce4SAndreas Gohr    // Admin Tasks
140610271ce4SAndreas Gohr    if($INFO['isadmin']){
140710271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
140810271ce4SAndreas Gohr
140976c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
141010271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
141110271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
141210271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
141310271ce4SAndreas Gohr        }
141410271ce4SAndreas Gohr        unset($menu['usermanager']);
141510271ce4SAndreas Gohr
141676c65fd3SAndreas Gohr        if($menu['acl']){
141710271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
141810271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
141910271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
142076c65fd3SAndreas Gohr        }
142110271ce4SAndreas Gohr        unset($menu['acl']);
142210271ce4SAndreas Gohr
142376c65fd3SAndreas Gohr        if($menu['plugin']){
142410271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
142510271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
142610271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
142776c65fd3SAndreas Gohr        }
142810271ce4SAndreas Gohr        unset($menu['plugin']);
142910271ce4SAndreas Gohr
143076c65fd3SAndreas Gohr        if($menu['config']){
143110271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
143210271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
143310271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
143476c65fd3SAndreas Gohr        }
143510271ce4SAndreas Gohr        unset($menu['config']);
143610271ce4SAndreas Gohr    }
143710271ce4SAndreas Gohr    ptln('</ul>');
143810271ce4SAndreas Gohr
143910271ce4SAndreas Gohr    // Manager Tasks
144010271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
144110271ce4SAndreas Gohr
144276c65fd3SAndreas Gohr    if($menu['revert']){
144310271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
144410271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
144510271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
144676c65fd3SAndreas Gohr    }
144710271ce4SAndreas Gohr    unset($menu['revert']);
144810271ce4SAndreas Gohr
144976c65fd3SAndreas Gohr    if($menu['popularity']){
145010271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
145110271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
145210271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
145376c65fd3SAndreas Gohr    }
145410271ce4SAndreas Gohr    unset($menu['popularity']);
145510271ce4SAndreas Gohr
14569a2cec2eSAndreas Gohr    // print DokuWiki version:
145710271ce4SAndreas Gohr    ptln('</ul>');
14589a2cec2eSAndreas Gohr    echo '<div id="admin__version">';
14599a2cec2eSAndreas Gohr    echo getVersion();
14609a2cec2eSAndreas Gohr    echo '</div>';
146110271ce4SAndreas Gohr
146210271ce4SAndreas Gohr    // print the rest as sorted list
146310271ce4SAndreas Gohr    if(count($menu)){
1464746855cfSBen Coburn        usort($menu, 'p_sort_modes');
146511e2ce22Schris        // output the menu
146610271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
146710271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
146811e2ce22Schris        ptln('<ul>');
146911e2ce22Schris        foreach ($menu as $item) {
147011e2ce22Schris            if (!$item['prompt']) continue;
14710c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
147211e2ce22Schris        }
147311e2ce22Schris        ptln('</ul>');
1474ca3a6df1SMatthias Grimm    }
147510271ce4SAndreas Gohr}
1476c19fe9c0Sandi
14778b06d178Schris/**
14788b06d178Schris * Form to request a new password for an existing account
14798b06d178Schris *
14808b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
148111e2ce22Schris */
14828b06d178Schrisfunction html_resendpwd() {
14838b06d178Schris    global $lang;
14848b06d178Schris    global $conf;
14858b06d178Schris    global $ID;
1486c19fe9c0Sandi
14878b06d178Schris    print p_locale_xhtml('resendpwd');
1488fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1489e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1490fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1491fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1492fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1493fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1494fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1495fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1496fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1497fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1498fdb8d77bSTom N Harris    $form->endFieldset();
1499fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1500fdb8d77bSTom N Harris    print '</div>'.NL;
1501fdb8d77bSTom N Harris}
1502fdb8d77bSTom N Harris
1503fdb8d77bSTom N Harris/**
1504b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1505b8595a66SAndreas Gohr *
1506b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1507b8595a66SAndreas Gohr */
1508b8595a66SAndreas Gohrfunction html_TOC($toc){
1509b8595a66SAndreas Gohr    if(!count($toc)) return '';
1510b8595a66SAndreas Gohr    global $lang;
1511b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1512b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1513b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1514b8595a66SAndreas Gohr    $out .= $lang['toc'];
1515b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1516b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1517b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1518b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1519b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1520db959ae3SAndreas Gohr    return $out;
1521db959ae3SAndreas Gohr}
1522b8595a66SAndreas Gohr
1523b8595a66SAndreas Gohr/**
1524b8595a66SAndreas Gohr * Callback for html_buildlist
1525b8595a66SAndreas Gohr */
1526b8595a66SAndreas Gohrfunction html_list_toc($item){
1527c66972f2SAdrian Lang    if(isset($item['hid'])){
15287d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15297d91652aSAndreas Gohr    }else{
15307d91652aSAndreas Gohr        $link = $item['link'];
15317d91652aSAndreas Gohr    }
15327d91652aSAndreas Gohr
15337d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1534b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1535b8595a66SAndreas Gohr}
1536b8595a66SAndreas Gohr
1537b8595a66SAndreas Gohr/**
1538b8595a66SAndreas Gohr * Helper function to build TOC items
1539b8595a66SAndreas Gohr *
1540b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1541b8595a66SAndreas Gohr *
1542b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1543b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1544b8595a66SAndreas Gohr * @param int    $level - nesting level
1545b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1546b8595a66SAndreas Gohr */
1547b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1548b8595a66SAndreas Gohr    global $conf;
1549b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1550b8595a66SAndreas Gohr            'title' => $text,
1551b8595a66SAndreas Gohr            'type'  => 'ul',
15522bb0d541Schris            'level' => $level);
1553b8595a66SAndreas Gohr}
1554b8595a66SAndreas Gohr
1555b8595a66SAndreas Gohr/**
1556fdb8d77bSTom N Harris * Output a Doku_Form object.
1557fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1558fdb8d77bSTom N Harris *
1559fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1560fdb8d77bSTom N Harris */
1561fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1562fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1563fdb8d77bSTom N Harris    $form->endFieldset();
1564fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1565fdb8d77bSTom N Harris}
1566fdb8d77bSTom N Harris
1567fdb8d77bSTom N Harris/**
1568fdb8d77bSTom N Harris * Form print function.
1569fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1570fdb8d77bSTom N Harris */
1571fdb8d77bSTom N Harrisfunction html_form_output($data) {
1572fdb8d77bSTom N Harris    $data->printForm();
15738b06d178Schris}
1574340756e4Sandi
157507bf32b2SAndreas Gohr/**
157607bf32b2SAndreas Gohr * Embed a flash object in HTML
157707bf32b2SAndreas Gohr *
157807bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
157907bf32b2SAndreas Gohr * compatble way using valid XHTML
158007bf32b2SAndreas Gohr *
158107bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
158207bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
158307bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
158407bf32b2SAndreas Gohr * $lang['noflash'] is used.
158507bf32b2SAndreas Gohr *
158607bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
158707bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
158807bf32b2SAndreas Gohr *
158907bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
159007bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
159107bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
159207bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
159307bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
159407bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
159507bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
159607bf32b2SAndreas Gohr * @returns string         - the XHTML markup
159707bf32b2SAndreas Gohr */
159807bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
159907bf32b2SAndreas Gohr    global $lang;
160007bf32b2SAndreas Gohr
160107bf32b2SAndreas Gohr    $out = '';
160207bf32b2SAndreas Gohr
160307bf32b2SAndreas Gohr    // prepare the object attributes
160407bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
160507bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1606d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
160707bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
160807bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
160907bf32b2SAndreas Gohr
161007bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
161107bf32b2SAndreas Gohr    $std = $atts;
161207bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
161307bf32b2SAndreas Gohr    $std['data'] = $swf;
161407bf32b2SAndreas Gohr
161507bf32b2SAndreas Gohr    // add object attributes for IE
161607bf32b2SAndreas Gohr    $ie  = $atts;
161707bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
161807bf32b2SAndreas Gohr
161907bf32b2SAndreas Gohr    // open object (with conditional comments)
162007bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
162107bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
162207bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
162307bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
162407bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
162507bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16269ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
162707bf32b2SAndreas Gohr
162807bf32b2SAndreas Gohr    // print params
162907bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
163007bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
163107bf32b2SAndreas Gohr    }
163207bf32b2SAndreas Gohr
163307bf32b2SAndreas Gohr    // add flashvars
163407bf32b2SAndreas Gohr    if(is_array($flashvars)){
1635d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
163607bf32b2SAndreas Gohr    }
163707bf32b2SAndreas Gohr
163807bf32b2SAndreas Gohr    // alternative content
163907bf32b2SAndreas Gohr    if($alt){
164007bf32b2SAndreas Gohr        $out .= $alt.NL;
164107bf32b2SAndreas Gohr    }else{
164207bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
164307bf32b2SAndreas Gohr    }
164407bf32b2SAndreas Gohr
164507bf32b2SAndreas Gohr    // finish
164607bf32b2SAndreas Gohr    $out .= '</object>'.NL;
164707bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
164807bf32b2SAndreas Gohr
164907bf32b2SAndreas Gohr    return $out;
165007bf32b2SAndreas Gohr}
165107bf32b2SAndreas Gohr
1652