xref: /dokuwiki/inc/html.php (revision 1b885c58f9e8294f0b866e2c327942ce3ab9de3f)
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 *
29c277a6bdSTom N Harris * @deprecated Use buildAttributes instead
30c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
31c19fe9c0Sandi */
32c19fe9c0Sandifunction html_attbuild($attributes){
33c19fe9c0Sandi    $ret = '';
34c19fe9c0Sandi    foreach ( $attributes as $key => $value ) {
35e351c80dSAdrian Lang        $ret .= $key.'="'.formText($value).'" ';
36c19fe9c0Sandi    }
37c19fe9c0Sandi    return trim($ret);
38c19fe9c0Sandi}
39c19fe9c0Sandi
40c19fe9c0Sandi/**
41f3f0262cSandi * The loginform
4215fae107Sandi *
4315fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
44f3f0262cSandi */
45f3f0262cSandifunction html_login(){
46f3f0262cSandi    global $lang;
47f3f0262cSandi    global $conf;
48f3f0262cSandi    global $ID;
49f3f0262cSandi
50c112d578Sandi    print p_locale_xhtml('login');
51fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
52e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__login'));
53fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
54fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
55fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
56aab557e9SGina Haeussge    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
57fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
5817f89d7eSMichael Klier    if($conf['rememberme']) {
59fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6017f89d7eSMichael Klier    }
61fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
62fdb8d77bSTom N Harris    $form->endFieldset();
635b62573aSAndreas Gohr
64de4d479aSAdrian Lang    if(actionOK('register')){
6576ec5467SMichael Klier        $form->addElement('<p>'
6676ec5467SMichael Klier                          . $lang['reghere']
6776ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
6876ec5467SMichael Klier                          . '</p>');
69f3f0262cSandi    }
708b06d178Schris
71de4d479aSAdrian Lang    if (actionOK('resendpwd')) {
7276ec5467SMichael Klier        $form->addElement('<p>'
7376ec5467SMichael Klier                          . $lang['pwdforget']
7476ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
7576ec5467SMichael Klier                          . '</p>');
768b06d178Schris    }
7776ec5467SMichael Klier
7876ec5467SMichael Klier    html_form('login', $form);
79fdb8d77bSTom N Harris    print '</div>'.NL;
80f3f0262cSandi}
81f3f0262cSandi
82f3f0262cSandi/**
8315fae107Sandi * inserts section edit buttons if wanted or removes the markers
8415fae107Sandi *
8515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8615fae107Sandi */
87f3f0262cSandifunction html_secedit($text,$show=true){
88f3f0262cSandi    global $INFO;
8935dae8b0SBen Coburn
903f9e3215SAdrian Lang    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
91b081e262SAdrian Lang
9240868f2fSAdrian Lang    if(!$INFO['writable'] || !$show || $INFO['rev']){
9340868f2fSAdrian Lang        return preg_replace($regexp,'',$text);
94f3f0262cSandi    }
9535dae8b0SBen Coburn
9640868f2fSAdrian Lang    return preg_replace_callback($regexp,
9740868f2fSAdrian Lang                'html_secedit_button', $text);
9840868f2fSAdrian Lang}
9940868f2fSAdrian Lang
10040868f2fSAdrian Lang/**
10140868f2fSAdrian Lang * prepares section edit button data for event triggering
10240868f2fSAdrian Lang * used as a callback in html_secedit
10340868f2fSAdrian Lang *
10440868f2fSAdrian Lang * @triggers HTML_SECEDIT_BUTTON
10540868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
10640868f2fSAdrian Lang */
10740868f2fSAdrian Langfunction html_secedit_button($matches){
108905fa971SAdrian Lang    $data = array('secid'  => $matches[1],
10940868f2fSAdrian Lang                  'target' => strtolower($matches[2]),
11040868f2fSAdrian Lang                  'range'  => $matches[count($matches) - 1]);
11140868f2fSAdrian Lang    if (count($matches) === 5) {
11240868f2fSAdrian Lang        $data['name'] = $matches[3];
11340868f2fSAdrian Lang    }
11440868f2fSAdrian Lang
11540868f2fSAdrian Lang    return trigger_event('HTML_SECEDIT_BUTTON', $data,
11640868f2fSAdrian Lang                         'html_secedit_get_button');
11740868f2fSAdrian Lang}
11840868f2fSAdrian Lang
11940868f2fSAdrian Lang/**
12040868f2fSAdrian Lang * prints a section editing button
12140868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
12240868f2fSAdrian Lang *
12340868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
12440868f2fSAdrian Lang */
12540868f2fSAdrian Langfunction html_secedit_get_button($data) {
12640868f2fSAdrian Lang    global $ID;
12740868f2fSAdrian Lang    global $INFO;
12840868f2fSAdrian Lang
12940868f2fSAdrian Lang    if (!isset($data['name']) || $data['name'] === '') return;
13040868f2fSAdrian Lang
13140868f2fSAdrian Lang    $name = $data['name'];
13240868f2fSAdrian Lang    unset($data['name']);
13340868f2fSAdrian Lang
134905fa971SAdrian Lang    $secid = $data['secid'];
135905fa971SAdrian Lang    unset($data['secid']);
136905fa971SAdrian Lang
13740868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
138defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
13940868f2fSAdrian Lang           html_btn('secedit', $ID, '',
14040868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
141b150cd2cSGina Haeussge                                      'rev' => $INFO['lastmod'],
142b150cd2cSGina Haeussge                                      'summary' => '['.$name.'] '), $data),
14340868f2fSAdrian Lang                    'post', $name) . '</div>';
144f3f0262cSandi}
145f3f0262cSandi
146f3f0262cSandi/**
147d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1486b13307fSandi *
1496b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1506b13307fSandi */
1516b13307fSandifunction html_topbtn(){
1526b13307fSandi    global $lang;
1536b13307fSandi
1546b13307fSandi    $ret  = '';
15511ea018fSAndreas 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>';
156df7b6005Sandi
1576b13307fSandi    return $ret;
1586b13307fSandi}
1596b13307fSandi
1606b13307fSandi/**
161d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
16235dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
16315fae107Sandi *
16415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
165f3f0262cSandi */
166f5baf821SAnika Henkefunction html_btn($name,$id,$akey,$params,$method='get',$tooltip='',$label=false){
167f3f0262cSandi    global $conf;
168f3f0262cSandi    global $lang;
169f3f0262cSandi
170f5baf821SAnika Henke    if (!$label)
171f3f0262cSandi        $label = $lang['btn_'.$name];
172f3f0262cSandi
173f3f0262cSandi    $ret = '';
17435dae8b0SBen Coburn    $tip = '';
175f3f0262cSandi
17649c713a3Sandi    //filter id (without urlencoding)
17749c713a3Sandi    $id = idfilter($id,false);
178f3f0262cSandi
179f3f0262cSandi    //make nice URLs even for buttons
1806c7843b5Sandi    if($conf['userewrite'] == 2){
1816c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1826c7843b5Sandi    }elseif($conf['userewrite']){
1836c7843b5Sandi        $script = DOKU_BASE.$id;
1846c7843b5Sandi    }else{
1858b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
186f3f0262cSandi        $params['id'] = $id;
187f3f0262cSandi    }
188f3f0262cSandi
189b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
190f3f0262cSandi
19106a4bf8fSAndreas Gohr    if(is_array($params)){
192f3f0262cSandi        reset($params);
193f3f0262cSandi        while (list($key, $val) = each($params)) {
194f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
195f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
196f3f0262cSandi        }
19706a4bf8fSAndreas Gohr    }
198f3f0262cSandi
19935dae8b0SBen Coburn    if ($tooltip!='') {
20035dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
20111ea018fSAndreas Gohr    }else{
20211ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
20311ea018fSAndreas Gohr    }
20411ea018fSAndreas Gohr
205d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
20611ea018fSAndreas Gohr    if($akey){
20707493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
20887cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
20935dae8b0SBen Coburn    }
21035dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
211f3f0262cSandi    $ret .= '/>';
2124beabca9SAnika Henke    $ret .= '</div></form>';
213f3f0262cSandi
214f3f0262cSandi    return $ret;
215f3f0262cSandi}
216f3f0262cSandi
217f3f0262cSandi/**
21815fae107Sandi * show a wiki page
21915fae107Sandi *
22015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
22115fae107Sandi */
22211c78c94SAndreas Gohrfunction html_show($txt=null){
223f3f0262cSandi    global $ID;
224f3f0262cSandi    global $REV;
225f3f0262cSandi    global $HIGH;
226b8595a66SAndreas Gohr    global $INFO;
227f3f0262cSandi    //disable section editing for old revisions or in preview
2285400331dSandi    if($txt || $REV){
2296bbae538Sandi        $secedit = false;
2306bbae538Sandi    }else{
2316bbae538Sandi        $secedit = true;
232f3f0262cSandi    }
233f3f0262cSandi
23411c78c94SAndreas Gohr    if (!is_null($txt)){
235f3f0262cSandi        //PreviewHeader
236b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
237b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
238b8595a66SAndreas Gohr        echo '<div class="preview">';
239b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
240b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
241b8595a66SAndreas Gohr        echo $html;
242b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
243b8595a66SAndreas Gohr        echo '</div>';
2446bbae538Sandi
245f3f0262cSandi    }else{
246c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
247c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2486bbae538Sandi        $html = html_secedit($html,$secedit);
249b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
250b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
251b8595a66SAndreas Gohr        echo $html;
252f3f0262cSandi    }
253f3f0262cSandi}
254f3f0262cSandi
255f3f0262cSandi/**
256ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
257ee4c4a1bSAndreas Gohr *
258ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
259ee4c4a1bSAndreas Gohr */
260ee4c4a1bSAndreas Gohrfunction html_draft(){
261ee4c4a1bSAndreas Gohr    global $INFO;
262ee4c4a1bSAndreas Gohr    global $ID;
263ee4c4a1bSAndreas Gohr    global $lang;
264ee4c4a1bSAndreas Gohr    global $conf;
265ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
266ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
267ee4c4a1bSAndreas Gohr
268fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
269e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
270fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
271fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
272fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
273fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
274f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
275fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
276fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
277fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
278fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
279fdb8d77bSTom N Harris    html_form('draft', $form);
280ee4c4a1bSAndreas Gohr}
281ee4c4a1bSAndreas Gohr
282ee4c4a1bSAndreas Gohr/**
283f3f0262cSandi * Highlights searchqueries in HTML code
28415fae107Sandi *
28515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2867209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
287f3f0262cSandi */
288546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
289808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
2902237b4faSAndreas Gohr    $regex = join('|',array_map('ft_snippet_re_preprocess', array_map('preg_quote_cb',$phrases)));
29160c15d7dSAndreas Gohr
29260c15d7dSAndreas Gohr    if ($regex === '') return $html;
2931db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
294f3f0262cSandi    return $html;
295f3f0262cSandi}
296f3f0262cSandi
297f3f0262cSandi/**
2987209be23SAndreas Gohr * Callback used by html_hilight()
2997209be23SAndreas Gohr *
3007209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
3017209be23SAndreas Gohr */
3027209be23SAndreas Gohrfunction html_hilight_callback($m) {
3037209be23SAndreas Gohr    $hlight = unslash($m[0]);
3047209be23SAndreas Gohr    if ( !isset($m[2])) {
305688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3067209be23SAndreas Gohr    }
3077209be23SAndreas Gohr    return $hlight;
3087209be23SAndreas Gohr}
3097209be23SAndreas Gohr
3107209be23SAndreas Gohr/**
31115fae107Sandi * Run a search and display the result
31215fae107Sandi *
31315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
314f3f0262cSandi */
315f3f0262cSandifunction html_search(){
316f3f0262cSandi    global $conf;
317f3f0262cSandi    global $QUERY;
318f3f0262cSandi    global $ID;
319f3f0262cSandi    global $lang;
320f3f0262cSandi
32106756ad2SAndreas Gohr    $intro = p_locale_xhtml('searchpage');
32206756ad2SAndreas Gohr    // allow use of placeholder in search intro
32306756ad2SAndreas Gohr    $intro = str_replace(
32406756ad2SAndreas Gohr                array('@QUERY@','@SEARCH@'),
32506756ad2SAndreas Gohr                array(hsc(rawurlencode($QUERY)),hsc($QUERY)),
32606756ad2SAndreas Gohr                $intro);
32706756ad2SAndreas Gohr    echo $intro;
328f3f0262cSandi    flush();
329f3f0262cSandi
3304d9ff3d5Sandi    //show progressbar
331e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
332e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
333e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
334e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
335e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3369edac8a8SAndreas Gohr    flush();
3374d9ff3d5Sandi
338f3f0262cSandi    //do quick pagesearch
339f3f0262cSandi    $data = array();
340d0ab54f6SMichael Klier chi@chimeric.de
3416ef71970SAdrian Lang    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
342f3f0262cSandi    if(count($data)){
343f3f0262cSandi        print '<div class="search_quickresult">';
344746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3454f732f0eSAnika Henke        print '<ul class="search_quickhits">';
3468d22f1e9SAndreas Gohr        foreach($data as $id => $title){
3474f732f0eSAnika Henke            print '<li> ';
3488d22f1e9SAndreas Gohr            if (useHeading('navigation')) {
3498d22f1e9SAndreas Gohr                $name = $title;
3508d22f1e9SAndreas Gohr            }else{
351bd2f6c2fSAndreas Gohr                $ns = getNS($id);
352bd2f6c2fSAndreas Gohr                if($ns){
353bd2f6c2fSAndreas Gohr                    $name = shorten(noNS($id), ' ('.$ns.')',30);
354bd2f6c2fSAndreas Gohr                }else{
355bd2f6c2fSAndreas Gohr                    $name = $id;
356bd2f6c2fSAndreas Gohr                }
3578d22f1e9SAndreas Gohr            }
358bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3594f732f0eSAnika Henke            print '</li> ';
360f3f0262cSandi        }
361140c93f3SAnika Henke        print '</ul> ';
362f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
363f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
364f3f0262cSandi        print '</div>';
365f3f0262cSandi    }
366f3f0262cSandi    flush();
367f3f0262cSandi
368f3f0262cSandi    //do fulltext search
36960c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
370f3f0262cSandi    if(count($data)){
371506fa893SAndreas Gohr        $num = 1;
372506fa893SAndreas Gohr        foreach($data as $id => $cnt){
373f3f0262cSandi            print '<div class="search_result">';
374db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
375865c2687SKazutaka Miyasaka            if($cnt !== 0){
376506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
377bd0293e7SAndreas Gohr                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
37860c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
379506fa893SAndreas Gohr                }
380865c2687SKazutaka Miyasaka                $num++;
381865c2687SKazutaka Miyasaka            }
382f3f0262cSandi            print '</div>';
383506fa893SAndreas Gohr            flush();
384f3f0262cSandi        }
385f3f0262cSandi    }else{
386820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
387f3f0262cSandi    }
3884d9ff3d5Sandi
3894d9ff3d5Sandi    //hide progressbar
390e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
391e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
392e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3939edac8a8SAndreas Gohr    flush();
394f3f0262cSandi}
395f3f0262cSandi
39615fae107Sandi/**
39715fae107Sandi * Display error on locked pages
39815fae107Sandi *
39915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40015fae107Sandi */
401ee20e7d1Sandifunction html_locked(){
402f3f0262cSandi    global $ID;
403f3f0262cSandi    global $conf;
404f3f0262cSandi    global $lang;
40588f522e9Sandi    global $INFO;
406f3f0262cSandi
407c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
408f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
409f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
410f3f0262cSandi
411c112d578Sandi    print p_locale_xhtml('locked');
412f3f0262cSandi    print '<ul>';
4136d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
4140c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
415f3f0262cSandi    print '</ul>';
416f3f0262cSandi}
417f3f0262cSandi
41815fae107Sandi/**
41915fae107Sandi * list old revisions
42015fae107Sandi *
42115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
42271726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
42315fae107Sandi */
42471726d78SBen Coburnfunction html_revisions($first=0){
425f3f0262cSandi    global $ID;
426f3f0262cSandi    global $INFO;
427f3f0262cSandi    global $conf;
428f3f0262cSandi    global $lang;
42971726d78SBen Coburn    /* we need to get one additionally log entry to be able to
43071726d78SBen Coburn     * decide if this is the last page or is there another one.
43171726d78SBen Coburn     * see html_recent()
43271726d78SBen Coburn     */
43371726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
43471726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43571726d78SBen Coburn        $first=0;
43671726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
43771726d78SBen Coburn    }
43871726d78SBen Coburn    $hasNext = false;
43971726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
44071726d78SBen Coburn        $hasNext = true;
44171726d78SBen Coburn        array_pop($revisions); // remove extra log entry
44271726d78SBen Coburn    }
44371726d78SBen Coburn
444f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
445f3f0262cSandi
446c112d578Sandi    print p_locale_xhtml('revisions');
44737a1dc12Smichael
448e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
44937a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
45071726d78SBen Coburn    if($INFO['exists'] && $first==0){
45137a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
45237a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
45337a1dc12Smichael        else
45437a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
45537a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
45637a1dc12Smichael        $form->addElement(form_makeTag('input', array(
45737a1dc12Smichael                        'type' => 'checkbox',
45837a1dc12Smichael                        'name' => 'rev2[]',
45937a1dc12Smichael                        'value' => 'current')));
460f9b2fe70Sandi
46137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
46237a1dc12Smichael        $form->addElement($date);
46337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
464f9b2fe70Sandi
46537a1dc12Smichael        $form->addElement(form_makeTag('img', array(
46637a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
46737a1dc12Smichael                        'width' => '15',
46837a1dc12Smichael                        'height' => '11',
46937a1dc12Smichael                        'alt'    => '')));
470cffcc403Sandi
47137a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
47237a1dc12Smichael                        'class' => 'wikilink1',
47337a1dc12Smichael                        'href'  => wl($ID))));
47437a1dc12Smichael        $form->addElement($ID);
47537a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
476652610a2Sandi
47737a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
47837a1dc12Smichael        $form->addElement(' &ndash; ');
47937a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
48037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
481652610a2Sandi
48237a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
48337a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
48437a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
48537a1dc12Smichael
48637a1dc12Smichael        $form->addElement('('.$lang['current'].')');
48737a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
48837a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
489f3f0262cSandi    }
490f3f0262cSandi
491f3f0262cSandi    foreach($revisions as $rev){
492f2263577SAndreas Gohr        $date   = dformat($rev);
493fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
494103c256aSChris Smith        $exists = page_exists($ID,$rev);
495652610a2Sandi
49637a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
49737a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
49837a1dc12Smichael        else
49937a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
50037a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
50177707b04SAndreas Gohr        if($exists){
50237a1dc12Smichael            $form->addElement(form_makeTag('input', array(
50337a1dc12Smichael                            'type' => 'checkbox',
50437a1dc12Smichael                            'name' => 'rev2[]',
50537a1dc12Smichael                            'value' => $rev)));
50677707b04SAndreas Gohr        }else{
50737a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50837a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
50937a1dc12Smichael                            'width' => 14,
51037a1dc12Smichael                            'height' => 11,
51137a1dc12Smichael                            'alt' => '')));
51241396b71SAndreas Gohr        }
513f9b2fe70Sandi
51437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
51537a1dc12Smichael        $form->addElement($date);
51637a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
51737a1dc12Smichael
51837a1dc12Smichael        if($exists){
51937a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
52037a1dc12Smichael            $form->addElement(form_makeTag('img', array(
52137a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
52237a1dc12Smichael                            'width'  => 15,
52337a1dc12Smichael                            'height' => 11,
52437a1dc12Smichael                            'title'  => $lang['diff'],
52537a1dc12Smichael                            'alt'    => $lang['diff'])));
52637a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52737a1dc12Smichael
52837a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
52937a1dc12Smichael            $form->addElement($ID);
53037a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
53137a1dc12Smichael        }else{
53237a1dc12Smichael            $form->addElement(form_makeTag('img', array(
53337a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
53437a1dc12Smichael                            'width' => '15',
53537a1dc12Smichael                            'height' => '11',
53637a1dc12Smichael                            'alt'   => '')));
53737a1dc12Smichael            $form->addElement($ID);
53837a1dc12Smichael        }
53937a1dc12Smichael
54037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
54137a1dc12Smichael        $form->addElement(' &ndash; ');
54237a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
54337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
54437a1dc12Smichael
54537a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
54688f522e9Sandi        if($info['user']){
54737a1dc12Smichael            $form->addElement(editorinfo($info['user']));
548433efb25SAndreas Gohr            if(auth_ismanager()){
549433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
550433efb25SAndreas Gohr            }
55188f522e9Sandi        }else{
55237a1dc12Smichael            $form->addElement($info['ip']);
55388f522e9Sandi        }
55437a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
555652610a2Sandi
55637a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
55737a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
558f3f0262cSandi    }
55937a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
56037a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
56137a1dc12Smichael    html_form('revisions', $form);
56271726d78SBen Coburn
56371726d78SBen Coburn    print '<div class="pagenav">';
56471726d78SBen Coburn    $last = $first + $conf['recent'];
56571726d78SBen Coburn    if ($first > 0) {
56671726d78SBen Coburn        $first -= $conf['recent'];
56771726d78SBen Coburn        if ($first < 0) $first = 0;
56871726d78SBen Coburn        print '<div class="pagenav-prev">';
569eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
57071726d78SBen Coburn        print '</div>';
57171726d78SBen Coburn    }
57271726d78SBen Coburn    if ($hasNext) {
57371726d78SBen Coburn        print '<div class="pagenav-next">';
574eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
57571726d78SBen Coburn        print '</div>';
57671726d78SBen Coburn    }
57771726d78SBen Coburn    print '</div>';
57871726d78SBen Coburn
579f3f0262cSandi}
580f3f0262cSandi
58115fae107Sandi/**
58215fae107Sandi * display recent changes
58315fae107Sandi *
58415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5855749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
58671726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
58715fae107Sandi */
588a39955b0Smatthiasgrimmfunction html_recent($first=0){
589f3f0262cSandi    global $conf;
590cffcc403Sandi    global $lang;
591dbb00abcSEsther Brunner    global $ID;
5925749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5935749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5945749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5955749f1ceSmatthiasgrimm     */
596b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5975749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5985749f1ceSmatthiasgrimm        $first=0;
59971726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
6005749f1ceSmatthiasgrimm    }
60171726d78SBen Coburn    $hasNext = false;
60271726d78SBen Coburn    if (count($recents)>$conf['recent']) {
60371726d78SBen Coburn        $hasNext = true;
60471726d78SBen Coburn        array_pop($recents); // remove extra log entry
60571726d78SBen Coburn    }
606f3f0262cSandi
607c112d578Sandi    print p_locale_xhtml('recent');
608e83cef14SGina Haeussge
609e83cef14SGina Haeussge    if (getNS($ID) != '')
6109e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
611e83cef14SGina Haeussge
612e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
613abdcc39fSmichael    $form->addHidden('sectok', null);
614abdcc39fSmichael    $form->addHidden('do', 'recent');
615abdcc39fSmichael    $form->addHidden('id', $ID);
616abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
617a39955b0Smatthiasgrimm
618d437bcc4SAndreas Gohr    foreach($recents as $recent){
619f2263577SAndreas Gohr        $date = dformat($recent['date']);
620abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
621abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
622abdcc39fSmichael        else
623abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
624cffcc403Sandi
625abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
626f9b2fe70Sandi
627abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
628abdcc39fSmichael        $form->addElement($date);
629abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
630cffcc403Sandi
631cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
632abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
633abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
634abdcc39fSmichael                        'width' => 15,
635abdcc39fSmichael                        'height'=> 11,
636abdcc39fSmichael                        'title' => $lang['diff'],
637abdcc39fSmichael                        'alt'   => $lang['diff']
638abdcc39fSmichael                        )));
639abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
640cffcc403Sandi
641cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
642abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
643abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
644abdcc39fSmichael                        'width' => 12,
645abdcc39fSmichael                        'height'=> 14,
646abdcc39fSmichael                        'title' => $lang['btn_revs'],
647abdcc39fSmichael                        'alt'   => $lang['btn_revs']
648abdcc39fSmichael                        )));
649abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
650b6912aeaSAndreas Gohr
651db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
652abdcc39fSmichael
653abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
654abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
655abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
656abdcc39fSmichael
657abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
658d437bcc4SAndreas Gohr        if($recent['user']){
659abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
660433efb25SAndreas Gohr            if(auth_ismanager()){
661433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
662433efb25SAndreas Gohr            }
66388f522e9Sandi        }else{
664abdcc39fSmichael            $form->addElement($recent['ip']);
66588f522e9Sandi        }
666abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
667cffcc403Sandi
668abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
669abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
670f3f0262cSandi    }
671abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
672a39955b0Smatthiasgrimm
673abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6745749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
675a39955b0Smatthiasgrimm    if ($first > 0) {
676a39955b0Smatthiasgrimm        $first -= $conf['recent'];
677a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
678abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
679abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
680abdcc39fSmichael                    'type'  => 'submit',
681abdcc39fSmichael                    'name'  => 'first['.$first.']',
682cddd152cSmichael                    'value' => $lang['btn_newer'],
683cddd152cSmichael                    'accesskey' => 'n',
684f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
68518d107cbSMichael Klier                    'class' => 'button'
686abdcc39fSmichael                    )));
687abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
688a39955b0Smatthiasgrimm    }
68971726d78SBen Coburn    if ($hasNext) {
690abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
691abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
692abdcc39fSmichael                        'type'  => 'submit',
693abdcc39fSmichael                        'name'  => 'first['.$last.']',
694cddd152cSmichael                        'value' => $lang['btn_older'],
695cddd152cSmichael                        'accesskey' => 'p',
696f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
69718d107cbSMichael Klier                        'class' => 'button'
698abdcc39fSmichael                        )));
699abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
700a39955b0Smatthiasgrimm    }
701abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
702abdcc39fSmichael    html_form('recent', $form);
703f3f0262cSandi}
704f3f0262cSandi
70515fae107Sandi/**
70615fae107Sandi * Display page index
70715fae107Sandi *
70815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
70915fae107Sandi */
710f3f0262cSandifunction html_index($ns){
711f3f0262cSandi    global $conf;
712f3f0262cSandi    global $ID;
713f3f0262cSandi    $dir = $conf['datadir'];
714f3f0262cSandi    $ns  = cleanID($ns);
71530f1737dSandi    #fixme use appropriate function
716f3f0262cSandi    if(empty($ns)){
717f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
718f3f0262cSandi        if($ns == '.') $ns ='';
719f3f0262cSandi    }
72088d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
721f3f0262cSandi
722a06884abSAndreas Gohr    echo p_locale_xhtml('index');
723a06884abSAndreas Gohr    echo '<div id="index__tree">';
724f3f0262cSandi
725f3f0262cSandi    $data = array();
726f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
727a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
728a06884abSAndreas Gohr
729a06884abSAndreas Gohr    echo '</div>';
730f3f0262cSandi}
731f3f0262cSandi
732f3f0262cSandi/**
73315fae107Sandi * Index item formatter
73415fae107Sandi *
735f3f0262cSandi * User function for html_buildlist()
73615fae107Sandi *
73715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
738f3f0262cSandi */
739f3f0262cSandifunction html_list_index($item){
740d98d4540SBen Coburn    global $ID;
741f3f0262cSandi    $ret = '';
742f3f0262cSandi    $base = ':'.$item['id'];
743f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
744f3f0262cSandi    if($item['type']=='d'){
7454a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
746f3f0262cSandi        $ret .= $base;
747ed7ecb79SAnika Henke        $ret .= '</strong></a>';
748f3f0262cSandi    }else{
749f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
750f3f0262cSandi    }
751f3f0262cSandi    return $ret;
752f3f0262cSandi}
753f3f0262cSandi
754f3f0262cSandi/**
755cb70c441Sandi * Index List item
756cb70c441Sandi *
757cb70c441Sandi * This user function is used in html_build_lidt to build the
758cb70c441Sandi * <li> tags for namespaces when displaying the page index
759cb70c441Sandi * it gives different classes to opened or closed "folders"
760cb70c441Sandi *
761cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
762cb70c441Sandi */
763cb70c441Sandifunction html_li_index($item){
764cb70c441Sandi    if($item['type'] == "f"){
765cb70c441Sandi        return '<li class="level'.$item['level'].'">';
766cb70c441Sandi    }elseif($item['open']){
767cb70c441Sandi        return '<li class="open">';
768cb70c441Sandi    }else{
769cb70c441Sandi        return '<li class="closed">';
770cb70c441Sandi    }
771cb70c441Sandi}
772cb70c441Sandi
773cb70c441Sandi/**
774cb70c441Sandi * Default List item
775cb70c441Sandi *
776cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
777cb70c441Sandi */
778cb70c441Sandifunction html_li_default($item){
779cb70c441Sandi    return '<li class="level'.$item['level'].'">';
780cb70c441Sandi}
781cb70c441Sandi
782cb70c441Sandi/**
78315fae107Sandi * Build an unordered list
78415fae107Sandi *
785f3f0262cSandi * Build an unordered list from the given $data array
786f3f0262cSandi * Each item in the array has to have a 'level' property
787f3f0262cSandi * the item itself gets printed by the given $func user
788cb70c441Sandi * function. The second and optional function is used to
789cb70c441Sandi * print the <li> tag. Both user function need to accept
790cb70c441Sandi * a single item.
79115fae107Sandi *
792c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
793c5a8fd96SAndreas Gohr * a member of an object.
794c5a8fd96SAndreas Gohr *
79515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
796f3f0262cSandi */
797cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
798f3f0262cSandi    $level = 0;
799f3f0262cSandi    $opens = 0;
800f3f0262cSandi    $ret   = '';
801f3f0262cSandi
802f3f0262cSandi    foreach ($data as $item){
803f3f0262cSandi
804f3f0262cSandi        if( $item['level'] > $level ){
805f3f0262cSandi            //open new list
806df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
807df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
808f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
809df52d0feSandi            }
810f3f0262cSandi        }elseif( $item['level'] < $level ){
811f3f0262cSandi            //close last item
812f3f0262cSandi            $ret .= "</li>\n";
813f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
814f3f0262cSandi                //close higher lists
815f3f0262cSandi                $ret .= "</ul>\n</li>\n";
816f3f0262cSandi            }
817f3f0262cSandi        }else{
818f3f0262cSandi            //close last item
819f3f0262cSandi            $ret .= "</li>\n";
820f3f0262cSandi        }
821f3f0262cSandi
822f3f0262cSandi        //remember current level
823f3f0262cSandi        $level = $item['level'];
824f3f0262cSandi
825f3f0262cSandi        //print item
82634dbe711Schris        $ret .= call_user_func($lifunc,$item);
8270c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
82834dbe711Schris
82934dbe711Schris        $ret .= call_user_func($func,$item);
8300c6b58a8SAndreas Gohr        $ret .= '</div>';
831f3f0262cSandi    }
832f3f0262cSandi
833f3f0262cSandi    //close remaining items and lists
834f3f0262cSandi    for ($i=0; $i < $level; $i++){
835f3f0262cSandi        $ret .= "</li></ul>\n";
836f3f0262cSandi    }
837f3f0262cSandi
838f3f0262cSandi    return $ret;
839f3f0262cSandi}
840f3f0262cSandi
84115fae107Sandi/**
84215fae107Sandi * display backlinks
84315fae107Sandi *
84415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
84511df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
84615fae107Sandi */
847f3f0262cSandifunction html_backlinks(){
848f3f0262cSandi    global $ID;
849f3f0262cSandi    global $conf;
85011df47ecSMichael Klier    global $lang;
851f3f0262cSandi
852c112d578Sandi    print p_locale_xhtml('backlinks');
853f3f0262cSandi
85454f4c056SAndreas Gohr    $data = ft_backlinks($ID);
855f3f0262cSandi
85611df47ecSMichael Klier    if(!empty($data)) {
857f3f0262cSandi        print '<ul class="idx">';
85854f4c056SAndreas Gohr        foreach($data as $blink){
8590c6b58a8SAndreas Gohr            print '<li><div class="li">';
860db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8610c6b58a8SAndreas Gohr            print '</div></li>';
862f3f0262cSandi        }
863f3f0262cSandi        print '</ul>';
86411df47ecSMichael Klier    } else {
86511df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
86611df47ecSMichael Klier    }
867f3f0262cSandi}
868f3f0262cSandi
86915fae107Sandi/**
87015fae107Sandi * show diff
87115fae107Sandi *
87215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
87372165381SAndreas Gohr * @param  string $text - compare with this text with most current version
87472165381SAndreas Gohr * @param  bool   $intr - display the intro text
87515fae107Sandi */
87672165381SAndreas Gohrfunction html_diff($text='',$intro=true,$type=null){
877f3f0262cSandi    global $ID;
878f3f0262cSandi    global $REV;
879f3f0262cSandi    global $lang;
880f3f0262cSandi    global $conf;
881e1bd90ffSAndreas Gohr
88272165381SAndreas Gohr    if(!$type) $type = $_REQUEST['difftype'];
88372165381SAndreas Gohr    if($type != 'inline') $type = 'sidebyside';
88472165381SAndreas Gohr
88577707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
88677707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
88777707b04SAndreas Gohr    // array in rev2.
88877707b04SAndreas Gohr    $rev1 = $REV;
8897b3f8b16SAndreas Gohr
89077707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
89177707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
89277707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
89354041c77SAndreas Gohr
89454041c77SAndreas Gohr        if(!$rev1){
89554041c77SAndreas Gohr            $rev1 = $rev2;
89654041c77SAndreas Gohr            unset($rev2);
89754041c77SAndreas Gohr        }
898f3f0262cSandi    }else{
89977707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
9004d58bd99Sandi    }
9014d58bd99Sandi
9023733161eSAdrian Lang    $r_minor = '';
9033733161eSAdrian Lang    $l_minor = '';
9043733161eSAdrian Lang
90577707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
90677707b04SAndreas Gohr        $l_rev   = '';
90777707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
90877707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
909f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
91077707b04SAndreas Gohr            $lang['current'];
91177707b04SAndreas Gohr
91277707b04SAndreas Gohr        $r_rev   = '';
91377707b04SAndreas Gohr        $r_text  = cleanText($text);
91477707b04SAndreas Gohr        $r_head  = $lang['yours'];
915e1bd90ffSAndreas Gohr    }else{
91677707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
91754041c77SAndreas Gohr            // make sure order is correct (older on the left)
91877707b04SAndreas Gohr            if($rev1 < $rev2){
91977707b04SAndreas Gohr                $l_rev = $rev1;
92077707b04SAndreas Gohr                $r_rev = $rev2;
92177707b04SAndreas Gohr            }else{
92277707b04SAndreas Gohr                $l_rev = $rev2;
92377707b04SAndreas Gohr                $r_rev = $rev1;
924e1bd90ffSAndreas Gohr            }
92577707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
92677707b04SAndreas Gohr            $r_rev = '';
92777707b04SAndreas Gohr            $l_rev = $rev1;
92877707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
92977707b04SAndreas Gohr            $r_rev = '';
93077707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
93177707b04SAndreas Gohr            $l_rev = $revs[0];
9326f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
93377707b04SAndreas Gohr        }
93477707b04SAndreas Gohr
9357b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9367b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9377b3f8b16SAndreas Gohr            $l_text = '';
9387b3f8b16SAndreas Gohr        }else{
93977707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9407b3f8b16SAndreas Gohr        }
94177707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
94277707b04SAndreas Gohr
9437b3f8b16SAndreas Gohr        if(!$l_rev){
9447b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9457b3f8b16SAndreas Gohr        }else{
946e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
947db959ae3SAndreas Gohr            if($l_info['user']){
948db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
949e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
950db959ae3SAndreas Gohr            } else {
951db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
952db959ae3SAndreas Gohr            }
953e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
954e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
955e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
956e5e61eb0SAnika Henke
95777707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
958f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
959e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9607b3f8b16SAndreas Gohr        }
96177707b04SAndreas Gohr
962820923f1SMichael Hamann        if($r_rev){
963820923f1SMichael Hamann            $r_info   = getRevisionInfo($ID,$r_rev,true);
964db959ae3SAndreas Gohr            if($r_info['user']){
965db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
966e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
967db959ae3SAndreas Gohr            } else {
968db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
969db959ae3SAndreas Gohr            }
970e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
971e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
972e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
973e5e61eb0SAnika Henke
97477707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
975f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
976e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9777b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
978e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
979db959ae3SAndreas Gohr            if($_info['user']){
980db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
981e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
982db959ae3SAndreas Gohr            } else {
983db959ae3SAndreas Gohr                $_user = $_info['ip'];
984db959ae3SAndreas Gohr            }
985e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
986e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
987e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
988e5e61eb0SAnika Henke
98977707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
990f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
991658b1aa0SAnika Henke            '('.$lang['current'].')'.
992e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9937b3f8b16SAndreas Gohr        }else{
994658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
995f3f0262cSandi        }
99677707b04SAndreas Gohr    }
99777707b04SAndreas Gohr
99877707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
99977707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
100077707b04SAndreas Gohr
100172165381SAndreas Gohr    if($type == 'inline'){
100272165381SAndreas Gohr        $tdf = new InlineDiffFormatter();
100372165381SAndreas Gohr    } else {
1004f3f0262cSandi        $tdf = new TableDiffFormatter();
100572165381SAndreas Gohr    }
100672165381SAndreas Gohr
100772165381SAndreas Gohr
100872165381SAndreas Gohr
1009c112d578Sandi    if($intro) print p_locale_xhtml('diff');
1010226bf2dcSGina Haeussge
1011226bf2dcSGina Haeussge    if (!$text) {
10128d9e6ae7SAnika Henke        ptln('<p class="difflink">');
101372165381SAndreas Gohr
101472165381SAndreas Gohr        $form = new Doku_Form(array('action'=>wl()));
1015*1b885c58SAndreas Gohr        $form->addHidden('id',$ID);
101672165381SAndreas Gohr        $form->addHidden('rev2[0]',$l_rev);
101772165381SAndreas Gohr        $form->addHidden('rev2[1]',$r_rev);
101872165381SAndreas Gohr        $form->addHidden('do','diff');
101972165381SAndreas Gohr        $form->addElement(form_makeListboxField(
102072165381SAndreas Gohr                            'difftype',
102172165381SAndreas Gohr                            array(
102272165381SAndreas Gohr                                'sidebyside' => $lang['diff_side'],
102372165381SAndreas Gohr                                'inline'     => $lang['diff_inline']),
102472165381SAndreas Gohr                            $type,
102572165381SAndreas Gohr                            $lang['diff_type'],
102672165381SAndreas Gohr                            '','',
102772165381SAndreas Gohr                            array('class'=>'quickselect')));
102872165381SAndreas Gohr        $form->addElement(form_makeButton('submit', 'diff','Go'));
102972165381SAndreas Gohr        $form->printForm();
103072165381SAndreas Gohr
103172165381SAndreas Gohr
103272165381SAndreas Gohr        $diffurl = wl($ID, array(
103372165381SAndreas Gohr                        'do'       => 'diff',
103472165381SAndreas Gohr                        'rev2[0]'  => $l_rev,
103572165381SAndreas Gohr                        'rev2[1]'  => $r_rev,
103672165381SAndreas Gohr                        'difftype' => $type,
103772165381SAndreas Gohr                      ));
103872165381SAndreas Gohr        ptln('<br /><a class="wikilink1" href="'.$diffurl.'">'.$lang['difflink'].'</a>');
10398d9e6ae7SAnika Henke        ptln('</p>');
1040226bf2dcSGina Haeussge    }
1041f3f0262cSandi    ?>
104272165381SAndreas Gohr    <table class="diff diff_<?php echo $type?>">
1043f3f0262cSandi    <tr>
1044e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
104577707b04SAndreas Gohr    <?php echo $l_head?>
1046daf4ca4eSAnika Henke    </th>
1047e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
104877707b04SAndreas Gohr    <?php echo $r_head?>
1049daf4ca4eSAnika Henke    </th>
1050f3f0262cSandi    </tr>
10514da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
1052f3f0262cSandi    </table>
10534da078a3Smatthiasgrimm    <?php
1054f3f0262cSandi}
1055f3f0262cSandi
105615fae107Sandi/**
105715fae107Sandi * show warning on conflict detection
105815fae107Sandi *
105915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
106015fae107Sandi */
1061f3f0262cSandifunction html_conflict($text,$summary){
1062f3f0262cSandi    global $ID;
1063f3f0262cSandi    global $lang;
1064f3f0262cSandi
1065c112d578Sandi    print p_locale_xhtml('conflict');
1066e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1067fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1068fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1069fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1070fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1071fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1072fdb8d77bSTom N Harris    html_form('conflict', $form);
1073fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1074f3f0262cSandi}
1075f3f0262cSandi
1076f3f0262cSandi/**
107715fae107Sandi * Prints the global message array
107815fae107Sandi *
107915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1080f3f0262cSandi */
1081f3f0262cSandifunction html_msgarea(){
1082cc58224cSMichael Hamann    global $MSG, $MSG_shown;
1083cc58224cSMichael Hamann    // store if the global $MSG has already been shown and thus HTML output has been started
1084cc58224cSMichael Hamann    $MSG_shown = true;
1085cc58224cSMichael Hamann
1086f3f0262cSandi    if(!isset($MSG)) return;
1087f3f0262cSandi
10884af9f0d4SAndreas Gohr    $shown = array();
1089f3f0262cSandi    foreach($MSG as $msg){
10904af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10914af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1092f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1093f3f0262cSandi        print $msg['msg'];
1094f3f0262cSandi        print '</div>';
10954af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1096f3f0262cSandi    }
1097cc58224cSMichael Hamann
1098cc58224cSMichael Hamann    unset($GLOBALS['MSG']);
1099f3f0262cSandi}
1100f3f0262cSandi
1101f3f0262cSandi/**
1102f3f0262cSandi * Prints the registration form
110315fae107Sandi *
110415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1105f3f0262cSandi */
1106f3f0262cSandifunction html_register(){
1107f3f0262cSandi    global $lang;
1108cab2716aSmatthias.grimm    global $conf;
1109f3f0262cSandi    global $ID;
1110f3f0262cSandi
1111c112d578Sandi    print p_locale_xhtml('register');
1112fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1113e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1114fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1115fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1116fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1117fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1118cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1119fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1120fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1121cab2716aSmatthias.grimm    }
1122fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1123fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1124fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1125fdb8d77bSTom N Harris    $form->endFieldset();
1126fdb8d77bSTom N Harris    html_form('register', $form);
1127cab2716aSmatthias.grimm
1128fdb8d77bSTom N Harris    print '</div>'.NL;
1129f3f0262cSandi}
1130f3f0262cSandi
1131f3f0262cSandi/**
11328b06d178Schris * Print the update profile form
11338b06d178Schris *
11348b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
11358b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
11368b06d178Schris */
11378b06d178Schrisfunction html_updateprofile(){
11388b06d178Schris    global $lang;
11398b06d178Schris    global $conf;
11408b06d178Schris    global $ID;
11418b06d178Schris    global $INFO;
114282fd59b6SAndreas Gohr    global $auth;
11438b06d178Schris
11448b06d178Schris    print p_locale_xhtml('updateprofile');
11458b06d178Schris
11468b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
11478b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1148fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1149e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1150fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1151fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1152fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1153fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1154fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1155fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1156fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
115739ba8890SAndreas Gohr    $attr = array('size'=>'50');
115839ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1159fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1160fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1161fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1162fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1163fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1164fdb8d77bSTom N Harris    }
1165fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1166fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1167fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1168fdb8d77bSTom N Harris    }
1169fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1170fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1171fdb8d77bSTom N Harris    $form->endFieldset();
1172fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1173fdb8d77bSTom N Harris    print '</div>'.NL;
11748b06d178Schris}
11758b06d178Schris
11768b06d178Schris/**
11777c4635c4SAdrian Lang * Preprocess edit form data
117815fae107Sandi *
117915fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
11802ffea8f2SAdrian Lang *
11812ffea8f2SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1182f3f0262cSandi */
11835a932e77SAdrian Langfunction html_edit(){
1184f3f0262cSandi    global $ID;
1185f3f0262cSandi    global $REV;
1186f3f0262cSandi    global $DATE;
1187f3f0262cSandi    global $PRE;
1188f3f0262cSandi    global $SUF;
1189f3f0262cSandi    global $INFO;
1190f3f0262cSandi    global $SUM;
1191f3f0262cSandi    global $lang;
1192f3f0262cSandi    global $conf;
119345a99335SAdrian Lang    global $TEXT;
1194d141c8dcSAdrian Lang    global $RANGE;
1195f3f0262cSandi
11968fe3bb00STom N Harris    if (isset($_REQUEST['changecheck'])) {
11978fe3bb00STom N Harris        $check = $_REQUEST['changecheck'];
119845a99335SAdrian Lang    } elseif(!$INFO['exists']){
119945a99335SAdrian Lang        // $TEXT has been loaded from page template
120045a99335SAdrian Lang        $check = md5('');
12018fe3bb00STom N Harris    } else {
120245a99335SAdrian Lang        $check = md5($TEXT);
12038fe3bb00STom N Harris    }
120445a99335SAdrian Lang    $mod = md5($TEXT) !== $check;
1205f3f0262cSandi
120627eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
120745a99335SAdrian Lang    $include = 'edit';
1208f3f0262cSandi    if($wr){
1209ffde0ac9SAdrian Lang        if ($REV) $include = 'editrev';
1210f3f0262cSandi    }else{
1211409d7af7SAndreas Gohr        // check pseudo action 'source'
1212409d7af7SAndreas Gohr        if(!actionOK('source')){
1213409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1214409d7af7SAndreas Gohr            return;
1215409d7af7SAndreas Gohr        }
1216ffde0ac9SAdrian Lang        $include = 'read';
1217f3f0262cSandi    }
12187c4635c4SAdrian Lang
12197c4635c4SAdrian Lang    global $license;
122042c7abd6SAndreas Gohr
1221e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1222fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1223fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1224fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
122542de51b1SAdrian Lang    $form->addHidden('prefix', $PRE . '.');
1226fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1227fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
12288e4da260SAdrian Lang
12292ffea8f2SAdrian Lang    $data = array('form' => $form,
12302ffea8f2SAdrian Lang                  'wr'   => $wr,
12312ffea8f2SAdrian Lang                  'media_manager' => true,
123212c96aceSAdrian Lang                  'target' => (isset($_REQUEST['target']) && $wr &&
123312c96aceSAdrian Lang                               $RANGE !== '') ? $_REQUEST['target'] : 'section',
12342ffea8f2SAdrian Lang                  'intro_locale' => $include);
123512c96aceSAdrian Lang
123612c96aceSAdrian Lang    if ($data['target'] !== 'section') {
123712c96aceSAdrian Lang        // Only emit event if page is writable, section edit data is valid and
123812c96aceSAdrian Lang        // edit target is not section.
12398e4da260SAdrian Lang        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
12402ffea8f2SAdrian Lang    } else {
12412ffea8f2SAdrian Lang        html_edit_form($data);
12422ffea8f2SAdrian Lang    }
1243ffde0ac9SAdrian Lang    if (isset($data['intro_locale'])) {
1244ffde0ac9SAdrian Lang        echo p_locale_xhtml($data['intro_locale']);
1245ffde0ac9SAdrian Lang    }
12468e4da260SAdrian Lang
1247b7eccc60SAdrian Lang    $form->addHidden('target', $data['target']);
1248fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1249fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1250fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1251fdb8d77bSTom N Harris    if ($wr) {
1252fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1253fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1254fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1255fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1256fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1257fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1258fdb8d77bSTom N Harris        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1259fdb8d77bSTom N Harris        $elem = html_minoredit();
1260fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1261fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1262fdb8d77bSTom N Harris    }
1263fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
12645808bc54SAndreas Gohr    if($wr && $conf['license']){
1265066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1266066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1267066fee30SAndreas Gohr        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
126884645d8cSAndreas Gohr        if(isset($conf['target']['extern'])) $out .= ' target="'.$conf['target']['extern'].'"';
1269066fee30SAndreas Gohr        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1270066fee30SAndreas Gohr        $form->addElement($out);
1271066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1272066fee30SAndreas Gohr    }
12738e4da260SAdrian Lang
12748e4da260SAdrian Lang    if ($wr) {
12758e4da260SAdrian Lang        // sets changed to true when previewed
12762e61e4dfSAdrian Lang        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'. NL;
12778e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
12782e61e4dfSAdrian Lang        echo '//--><!]]></script>' . NL;
12798e4da260SAdrian Lang    } ?>
12808e4da260SAdrian Lang    <div style="width:99%;">
12818e4da260SAdrian Lang
12828e4da260SAdrian Lang    <div class="toolbar">
12838e4da260SAdrian Lang    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
12848e4da260SAdrian 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']?>"
12858e4da260SAdrian Lang        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
12868e4da260SAdrian Lang
12878e4da260SAdrian Lang    </div>
12888e4da260SAdrian Lang    <?php
12898e4da260SAdrian Lang
1290fdb8d77bSTom N Harris    html_form('edit', $form);
1291fdb8d77bSTom N Harris    print '</div>'.NL;
1292f3f0262cSandi}
1293f3f0262cSandi
1294f3f0262cSandi/**
12958e4da260SAdrian Lang * Display the default edit form
12968e4da260SAdrian Lang *
12978e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
12988e4da260SAdrian Lang */
12998e4da260SAdrian Langfunction html_edit_form($param) {
130045a99335SAdrian Lang    global $TEXT;
130112c96aceSAdrian Lang
130212c96aceSAdrian Lang    if ($param['target'] !== 'section') {
130312c96aceSAdrian Lang        msg('No editor for edit target ' . $param['target'] . ' found.', -1);
130412c96aceSAdrian Lang    }
130512c96aceSAdrian Lang
13068e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
130712c96aceSAdrian Lang    if (!$param['wr']) $attr['readonly'] = 'readonly';
130812c96aceSAdrian Lang
130912c96aceSAdrian Lang    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
13108e4da260SAdrian Lang}
13118e4da260SAdrian Lang
13128e4da260SAdrian Lang/**
1313b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1314b6912aeaSAndreas Gohr *
1315b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1316b6912aeaSAndreas Gohr */
1317b6912aeaSAndreas Gohrfunction html_minoredit(){
1318b6912aeaSAndreas Gohr    global $conf;
1319b6912aeaSAndreas Gohr    global $lang;
1320b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1321b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1322fdb8d77bSTom N Harris        return false;
1323b6912aeaSAndreas Gohr    }
1324b6912aeaSAndreas Gohr
1325b6912aeaSAndreas Gohr    $p = array();
1326b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1327bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1328fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1329b6912aeaSAndreas Gohr}
1330b6912aeaSAndreas Gohr
1331b6912aeaSAndreas Gohr/**
1332f3f0262cSandi * prints some debug info
133315fae107Sandi *
133415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1335f3f0262cSandi */
1336f3f0262cSandifunction html_debug(){
1337f3f0262cSandi    global $conf;
1338d16a4edaSandi    global $lang;
13395298a619SAndreas Gohr    global $auth;
1340100a97e3SAndreas Gohr    global $INFO;
1341100a97e3SAndreas Gohr
134228fb55ffSandi    //remove sensitive data
134328fb55ffSandi    $cnf = $conf;
134424297a69SAndreas Gohr    debug_guard($cnf);
1345100a97e3SAndreas Gohr    $nfo = $INFO;
134624297a69SAndreas Gohr    debug_guard($nfo);
1347100a97e3SAndreas Gohr    $ses = $_SESSION;
134824297a69SAndreas Gohr    debug_guard($ses);
1349f3f0262cSandi
1350f3f0262cSandi    print '<html><body>';
1351f3f0262cSandi
1352f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1353f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1354f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1355f3f0262cSandi
1356100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1357100a97e3SAndreas Gohr    print_r($nfo);
1358100a97e3SAndreas Gohr    print '</pre>';
1359100a97e3SAndreas Gohr
1360f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1361f3f0262cSandi    print_r($_SERVER);
1362f3f0262cSandi    print '</pre>';
1363f3f0262cSandi
1364f3f0262cSandi    print '<b>$conf:</b><pre>';
136528fb55ffSandi    print_r($cnf);
1366f3f0262cSandi    print '</pre>';
1367f3f0262cSandi
1368ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1369ed7b5f09Sandi    print DOKU_BASE;
1370f3f0262cSandi    print '</pre>';
1371f3f0262cSandi
1372ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1373ed7b5f09Sandi    print DOKU_URL;
1374ed7b5f09Sandi    print '</pre>';
1375ed7b5f09Sandi
1376ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1377f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1378f3f0262cSandi    print '</pre>';
1379f3f0262cSandi
1380f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1381f3f0262cSandi    print phpversion();
1382f3f0262cSandi    print '</pre>';
1383f3f0262cSandi
1384f3f0262cSandi    print '<b>locale:</b><pre>';
1385f3f0262cSandi    print setlocale(LC_ALL,0);
1386f3f0262cSandi    print '</pre>';
1387f3f0262cSandi
1388d16a4edaSandi    print '<b>encoding:</b><pre>';
1389d16a4edaSandi    print $lang['encoding'];
1390d16a4edaSandi    print '</pre>';
1391d16a4edaSandi
13925298a619SAndreas Gohr    if($auth){
13935298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13945298a619SAndreas Gohr        print_r($auth->cando);
13955298a619SAndreas Gohr        print '</pre>';
13965298a619SAndreas Gohr    }
13975298a619SAndreas Gohr
13983aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1399100a97e3SAndreas Gohr    print_r($ses);
14003aa54d7cSAndreas Gohr    print '</pre>';
14013aa54d7cSAndreas Gohr
1402f3f0262cSandi    print '<b>Environment:</b><pre>';
1403f3f0262cSandi    print_r($_ENV);
1404f3f0262cSandi    print '</pre>';
1405f3f0262cSandi
1406f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1407f3f0262cSandi    $inis = ini_get_all();
1408f3f0262cSandi    print_r($inis);
1409f3f0262cSandi    print '</pre>';
1410f3f0262cSandi
1411f3f0262cSandi    print '</body></html>';
1412f3f0262cSandi}
1413f3f0262cSandi
141410271ce4SAndreas Gohr/**
141510271ce4SAndreas Gohr * List available Administration Tasks
141610271ce4SAndreas Gohr *
141710271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
141810271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
141910271ce4SAndreas Gohr */
1420c19fe9c0Sandifunction html_admin(){
1421c19fe9c0Sandi    global $ID;
1422f8cc712eSAndreas Gohr    global $INFO;
1423c19fe9c0Sandi    global $lang;
1424ca3a6df1SMatthias Grimm    global $conf;
142510271ce4SAndreas Gohr    global $auth;
1426c19fe9c0Sandi
142711e2ce22Schris    // build menu of admin functions from the plugins that handle them
142811e2ce22Schris    $pluginlist = plugin_list('admin');
142911e2ce22Schris    $menu = array();
143011e2ce22Schris    foreach ($pluginlist as $p) {
1431db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1432f8cc712eSAndreas Gohr
1433f8cc712eSAndreas Gohr        // check permissions
1434f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1435f8cc712eSAndreas Gohr
143610271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
143711e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
143811e2ce22Schris                'sort' => $obj->getMenuSort()
143911e2ce22Schris                );
144011e2ce22Schris    }
144111e2ce22Schris
1442c95a5b7dSAndreas Gohr    // data security check
1443c95a5b7dSAndreas Gohr    echo '<a style="background: transparent url(data/security.png) left top no-repeat;
1444c95a5b7dSAndreas Gohr                  display: block; width:380px; height:73px; border:none; float:right"
1445c95a5b7dSAndreas Gohr           target="_blank"
1446c95a5b7dSAndreas Gohr           href="http://www.dokuwiki.org/security#web_access_security"></a>';
1447c95a5b7dSAndreas Gohr
144810271ce4SAndreas Gohr    print p_locale_xhtml('admin');
144910271ce4SAndreas Gohr
145010271ce4SAndreas Gohr    // Admin Tasks
145110271ce4SAndreas Gohr    if($INFO['isadmin']){
145210271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
145310271ce4SAndreas Gohr
145476c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
145510271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
145610271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
145710271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
145810271ce4SAndreas Gohr        }
145910271ce4SAndreas Gohr        unset($menu['usermanager']);
146010271ce4SAndreas Gohr
146176c65fd3SAndreas Gohr        if($menu['acl']){
146210271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
146310271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
146410271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
146576c65fd3SAndreas Gohr        }
146610271ce4SAndreas Gohr        unset($menu['acl']);
146710271ce4SAndreas Gohr
146876c65fd3SAndreas Gohr        if($menu['plugin']){
146910271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
147010271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
147110271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
147276c65fd3SAndreas Gohr        }
147310271ce4SAndreas Gohr        unset($menu['plugin']);
147410271ce4SAndreas Gohr
147576c65fd3SAndreas Gohr        if($menu['config']){
147610271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
147710271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
147810271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
147976c65fd3SAndreas Gohr        }
148010271ce4SAndreas Gohr        unset($menu['config']);
148110271ce4SAndreas Gohr    }
148210271ce4SAndreas Gohr    ptln('</ul>');
148310271ce4SAndreas Gohr
148410271ce4SAndreas Gohr    // Manager Tasks
148510271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
148610271ce4SAndreas Gohr
148776c65fd3SAndreas Gohr    if($menu['revert']){
148810271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
148910271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
149010271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
149176c65fd3SAndreas Gohr    }
149210271ce4SAndreas Gohr    unset($menu['revert']);
149310271ce4SAndreas Gohr
149476c65fd3SAndreas Gohr    if($menu['popularity']){
149510271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
149610271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
149710271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
149876c65fd3SAndreas Gohr    }
149910271ce4SAndreas Gohr    unset($menu['popularity']);
150010271ce4SAndreas Gohr
15019a2cec2eSAndreas Gohr    // print DokuWiki version:
150210271ce4SAndreas Gohr    ptln('</ul>');
15039a2cec2eSAndreas Gohr    echo '<div id="admin__version">';
15049a2cec2eSAndreas Gohr    echo getVersion();
15059a2cec2eSAndreas Gohr    echo '</div>';
150610271ce4SAndreas Gohr
150710271ce4SAndreas Gohr    // print the rest as sorted list
150810271ce4SAndreas Gohr    if(count($menu)){
1509746855cfSBen Coburn        usort($menu, 'p_sort_modes');
151011e2ce22Schris        // output the menu
151110271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
151210271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
151311e2ce22Schris        ptln('<ul>');
151411e2ce22Schris        foreach ($menu as $item) {
151511e2ce22Schris            if (!$item['prompt']) continue;
15160c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
151711e2ce22Schris        }
151811e2ce22Schris        ptln('</ul>');
1519ca3a6df1SMatthias Grimm    }
152010271ce4SAndreas Gohr}
1521c19fe9c0Sandi
15228b06d178Schris/**
15238b06d178Schris * Form to request a new password for an existing account
15248b06d178Schris *
15258b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
152611e2ce22Schris */
15278b06d178Schrisfunction html_resendpwd() {
15288b06d178Schris    global $lang;
15298b06d178Schris    global $conf;
15308b06d178Schris    global $ID;
1531c19fe9c0Sandi
15328b06d178Schris    print p_locale_xhtml('resendpwd');
1533fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1534e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1535fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1536fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1537fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1538fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1539fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1540fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1541fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1542fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1543fdb8d77bSTom N Harris    $form->endFieldset();
1544fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1545fdb8d77bSTom N Harris    print '</div>'.NL;
1546fdb8d77bSTom N Harris}
1547fdb8d77bSTom N Harris
1548fdb8d77bSTom N Harris/**
1549b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1550b8595a66SAndreas Gohr *
1551b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1552b8595a66SAndreas Gohr */
1553b8595a66SAndreas Gohrfunction html_TOC($toc){
1554b8595a66SAndreas Gohr    if(!count($toc)) return '';
1555b8595a66SAndreas Gohr    global $lang;
1556b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1557b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1558b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1559b8595a66SAndreas Gohr    $out .= $lang['toc'];
1560b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1561b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1562b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1563b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1564b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1565db959ae3SAndreas Gohr    return $out;
1566db959ae3SAndreas Gohr}
1567b8595a66SAndreas Gohr
1568b8595a66SAndreas Gohr/**
1569b8595a66SAndreas Gohr * Callback for html_buildlist
1570b8595a66SAndreas Gohr */
1571b8595a66SAndreas Gohrfunction html_list_toc($item){
1572c66972f2SAdrian Lang    if(isset($item['hid'])){
15737d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15747d91652aSAndreas Gohr    }else{
15757d91652aSAndreas Gohr        $link = $item['link'];
15767d91652aSAndreas Gohr    }
15777d91652aSAndreas Gohr
15787d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1579b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1580b8595a66SAndreas Gohr}
1581b8595a66SAndreas Gohr
1582b8595a66SAndreas Gohr/**
1583b8595a66SAndreas Gohr * Helper function to build TOC items
1584b8595a66SAndreas Gohr *
1585b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1586b8595a66SAndreas Gohr *
1587b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1588b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1589b8595a66SAndreas Gohr * @param int    $level - nesting level
1590b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1591b8595a66SAndreas Gohr */
1592b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1593b8595a66SAndreas Gohr    global $conf;
1594b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1595b8595a66SAndreas Gohr            'title' => $text,
1596b8595a66SAndreas Gohr            'type'  => 'ul',
15972bb0d541Schris            'level' => $level);
1598b8595a66SAndreas Gohr}
1599b8595a66SAndreas Gohr
1600b8595a66SAndreas Gohr/**
1601fdb8d77bSTom N Harris * Output a Doku_Form object.
1602fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1603fdb8d77bSTom N Harris *
1604fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1605fdb8d77bSTom N Harris */
1606fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1607fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1608fdb8d77bSTom N Harris    $form->endFieldset();
1609fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1610fdb8d77bSTom N Harris}
1611fdb8d77bSTom N Harris
1612fdb8d77bSTom N Harris/**
1613fdb8d77bSTom N Harris * Form print function.
1614fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1615fdb8d77bSTom N Harris */
1616fdb8d77bSTom N Harrisfunction html_form_output($data) {
1617fdb8d77bSTom N Harris    $data->printForm();
16188b06d178Schris}
1619340756e4Sandi
162007bf32b2SAndreas Gohr/**
162107bf32b2SAndreas Gohr * Embed a flash object in HTML
162207bf32b2SAndreas Gohr *
162307bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
162407bf32b2SAndreas Gohr * compatble way using valid XHTML
162507bf32b2SAndreas Gohr *
162607bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
162707bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
162807bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
162907bf32b2SAndreas Gohr * $lang['noflash'] is used.
163007bf32b2SAndreas Gohr *
163107bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
163207bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
163307bf32b2SAndreas Gohr *
163407bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
163507bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
163607bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
163707bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
163807bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
163907bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
164007bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
164107bf32b2SAndreas Gohr * @returns string         - the XHTML markup
164207bf32b2SAndreas Gohr */
164307bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
164407bf32b2SAndreas Gohr    global $lang;
164507bf32b2SAndreas Gohr
164607bf32b2SAndreas Gohr    $out = '';
164707bf32b2SAndreas Gohr
164807bf32b2SAndreas Gohr    // prepare the object attributes
164907bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
165007bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1651d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
165207bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
165307bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
165407bf32b2SAndreas Gohr
165507bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
165607bf32b2SAndreas Gohr    $std = $atts;
165707bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
165807bf32b2SAndreas Gohr    $std['data'] = $swf;
165907bf32b2SAndreas Gohr
166007bf32b2SAndreas Gohr    // add object attributes for IE
166107bf32b2SAndreas Gohr    $ie  = $atts;
166207bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
166307bf32b2SAndreas Gohr
166407bf32b2SAndreas Gohr    // open object (with conditional comments)
166507bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
166607bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
166707bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
166807bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
166907bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
167007bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16719ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
167207bf32b2SAndreas Gohr
167307bf32b2SAndreas Gohr    // print params
167407bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
167507bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
167607bf32b2SAndreas Gohr    }
167707bf32b2SAndreas Gohr
167807bf32b2SAndreas Gohr    // add flashvars
167907bf32b2SAndreas Gohr    if(is_array($flashvars)){
1680d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
168107bf32b2SAndreas Gohr    }
168207bf32b2SAndreas Gohr
168307bf32b2SAndreas Gohr    // alternative content
168407bf32b2SAndreas Gohr    if($alt){
168507bf32b2SAndreas Gohr        $out .= $alt.NL;
168607bf32b2SAndreas Gohr    }else{
168707bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
168807bf32b2SAndreas Gohr    }
168907bf32b2SAndreas Gohr
169007bf32b2SAndreas Gohr    // finish
169107bf32b2SAndreas Gohr    $out .= '</object>'.NL;
169207bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
169307bf32b2SAndreas Gohr
169407bf32b2SAndreas Gohr    return $out;
169507bf32b2SAndreas Gohr}
169607bf32b2SAndreas Gohr
1697