xref: /dokuwiki/inc/html.php (revision 40868f2faa85215dfea2fa0c82274a4806d042ab)
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");
116bbae538Sandirequire_once(DOKU_INC.'inc/parserutils.php');
12fdb8d77bSTom N Harrisrequire_once(DOKU_INC.'inc/form.php');
136bbae538Sandi
14f3f0262cSandi/**
15f3f0262cSandi * Convenience function to quickly build a wikilink
1615fae107Sandi *
1715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
18f3f0262cSandi */
19db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
20db959ae3SAndreas Gohr    static $xhtml_renderer = null;
21723d78dbSandi    if(is_null($xhtml_renderer)){
227aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
23f3f0262cSandi    }
24f3f0262cSandi
25fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
26f3f0262cSandi}
27f3f0262cSandi
28f3f0262cSandi/**
29c19fe9c0Sandi * Helps building long attribute lists
30c19fe9c0Sandi *
31c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
32c19fe9c0Sandi */
33c19fe9c0Sandifunction html_attbuild($attributes){
34c19fe9c0Sandi    $ret = '';
35c19fe9c0Sandi    foreach ( $attributes as $key => $value ) {
36e351c80dSAdrian Lang        $ret .= $key.'="'.formText($value).'" ';
37c19fe9c0Sandi    }
38c19fe9c0Sandi    return trim($ret);
39c19fe9c0Sandi}
40c19fe9c0Sandi
41c19fe9c0Sandi/**
42f3f0262cSandi * The loginform
4315fae107Sandi *
4415fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
45f3f0262cSandi */
46f3f0262cSandifunction html_login(){
47f3f0262cSandi    global $lang;
48f3f0262cSandi    global $conf;
49f3f0262cSandi    global $ID;
50cd52f92dSchris    global $auth;
51f3f0262cSandi
52c112d578Sandi    print p_locale_xhtml('login');
53fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
54e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__login'));
55fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
56fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
57fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
58aab557e9SGina Haeussge    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
59fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6017f89d7eSMichael Klier    if($conf['rememberme']) {
61fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6217f89d7eSMichael Klier    }
63fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
64fdb8d77bSTom N Harris    $form->endFieldset();
655b62573aSAndreas Gohr
666957b2eaSAndreas Gohr    if($auth && $auth->canDo('addUser') && actionOK('register')){
6776ec5467SMichael Klier        $form->addElement('<p>'
6876ec5467SMichael Klier                          . $lang['reghere']
6976ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
7076ec5467SMichael Klier                          . '</p>');
71f3f0262cSandi    }
728b06d178Schris
736957b2eaSAndreas Gohr    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
7476ec5467SMichael Klier        $form->addElement('<p>'
7576ec5467SMichael Klier                          . $lang['pwdforget']
7676ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
7776ec5467SMichael Klier                          . '</p>');
788b06d178Schris    }
7976ec5467SMichael Klier
8076ec5467SMichael Klier    html_form('login', $form);
81fdb8d77bSTom N Harris    print '</div>'.NL;
82f3f0262cSandi}
83f3f0262cSandi
84f3f0262cSandi/**
8515fae107Sandi * inserts section edit buttons if wanted or removes the markers
8615fae107Sandi *
8715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8815fae107Sandi */
89f3f0262cSandifunction html_secedit($text,$show=true){
90f3f0262cSandi    global $INFO;
9135dae8b0SBen Coburn
9290df9a4dSAdrian Lang    $regexp = '#<!-- EDIT(\d+) ([A-Z]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
93b081e262SAdrian Lang
94*40868f2fSAdrian Lang    if(!$INFO['writable'] || !$show || $INFO['rev']){
95*40868f2fSAdrian Lang        return preg_replace($regexp,'',$text);
96f3f0262cSandi    }
9735dae8b0SBen Coburn
98*40868f2fSAdrian Lang    return preg_replace_callback($regexp,
99*40868f2fSAdrian Lang                'html_secedit_button', $text);
100*40868f2fSAdrian Lang}
101*40868f2fSAdrian Lang
102*40868f2fSAdrian Lang/**
103*40868f2fSAdrian Lang * prepares section edit button data for event triggering
104*40868f2fSAdrian Lang * used as a callback in html_secedit
105*40868f2fSAdrian Lang *
106*40868f2fSAdrian Lang * @triggers HTML_SECEDIT_BUTTON
107*40868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
108*40868f2fSAdrian Lang */
109*40868f2fSAdrian Langfunction html_secedit_button($matches){
110*40868f2fSAdrian Lang    $data = array('id'     => $matches[1],
111*40868f2fSAdrian Lang                  'target' => strtolower($matches[2]),
112*40868f2fSAdrian Lang                  'range'  => $matches[count($matches) - 1]);
113*40868f2fSAdrian Lang    if (count($matches) === 5) {
114*40868f2fSAdrian Lang        $data['name'] = $matches[3];
115*40868f2fSAdrian Lang    }
116*40868f2fSAdrian Lang
117*40868f2fSAdrian Lang    return trigger_event('HTML_SECEDIT_BUTTON', $data,
118*40868f2fSAdrian Lang                         'html_secedit_get_button');
119*40868f2fSAdrian Lang}
120*40868f2fSAdrian Lang
121*40868f2fSAdrian Lang/**
122*40868f2fSAdrian Lang * prints a section editing button
123*40868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
124*40868f2fSAdrian Lang *
125*40868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
126*40868f2fSAdrian Lang */
127*40868f2fSAdrian Langfunction html_secedit_get_button($data) {
128*40868f2fSAdrian Lang    global $ID;
129*40868f2fSAdrian Lang    global $INFO;
130*40868f2fSAdrian Lang
131*40868f2fSAdrian Lang    if (!isset($data['name']) || $data['name'] === '') return;
132*40868f2fSAdrian Lang
133*40868f2fSAdrian Lang    $name = $data['name'];
134*40868f2fSAdrian Lang    unset($data['name']);
135*40868f2fSAdrian Lang
136*40868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
137*40868f2fSAdrian Lang                       " editbutton_" . $data['id'] . "'>" .
138*40868f2fSAdrian Lang           html_btn('secedit', $ID, '',
139*40868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
140*40868f2fSAdrian Lang                                      'rev' => $INFO['lastmod']), $data),
141*40868f2fSAdrian Lang                    'post', $name) . '</div>';
142f3f0262cSandi}
143f3f0262cSandi
144f3f0262cSandi/**
145d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1466b13307fSandi *
1476b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1486b13307fSandi */
1496b13307fSandifunction html_topbtn(){
1506b13307fSandi    global $lang;
1516b13307fSandi
1526b13307fSandi    $ret  = '';
15311ea018fSAndreas 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>';
154df7b6005Sandi
1556b13307fSandi    return $ret;
1566b13307fSandi}
1576b13307fSandi
1586b13307fSandi/**
159d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
16035dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
16115fae107Sandi *
16215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
163f3f0262cSandi */
164d822118cSAdrian Langfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
165f3f0262cSandi    global $conf;
166f3f0262cSandi    global $lang;
167f3f0262cSandi
168f3f0262cSandi    $label = $lang['btn_'.$name];
169f3f0262cSandi
170f3f0262cSandi    $ret = '';
17135dae8b0SBen Coburn    $tip = '';
172f3f0262cSandi
17349c713a3Sandi    //filter id (without urlencoding)
17449c713a3Sandi    $id = idfilter($id,false);
175f3f0262cSandi
176f3f0262cSandi    //make nice URLs even for buttons
1776c7843b5Sandi    if($conf['userewrite'] == 2){
1786c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1796c7843b5Sandi    }elseif($conf['userewrite']){
1806c7843b5Sandi        $script = DOKU_BASE.$id;
1816c7843b5Sandi    }else{
1828b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
183f3f0262cSandi        $params['id'] = $id;
184f3f0262cSandi    }
185f3f0262cSandi
186b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
187f3f0262cSandi
18806a4bf8fSAndreas Gohr    if(is_array($params)){
189f3f0262cSandi        reset($params);
190f3f0262cSandi        while (list($key, $val) = each($params)) {
191f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
192f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
193f3f0262cSandi        }
19406a4bf8fSAndreas Gohr    }
195f3f0262cSandi
19635dae8b0SBen Coburn    if ($tooltip!='') {
19735dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
19811ea018fSAndreas Gohr    }else{
19911ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
20011ea018fSAndreas Gohr    }
20111ea018fSAndreas Gohr
202d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
20311ea018fSAndreas Gohr    if($akey){
20407493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
20587cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
20635dae8b0SBen Coburn    }
20735dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
208f3f0262cSandi    $ret .= '/>';
2094beabca9SAnika Henke    $ret .= '</div></form>';
210f3f0262cSandi
211f3f0262cSandi    return $ret;
212f3f0262cSandi}
213f3f0262cSandi
214f3f0262cSandi/**
21515fae107Sandi * show a wiki page
21615fae107Sandi *
21715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
21815fae107Sandi */
2196bbae538Sandifunction html_show($txt=''){
220f3f0262cSandi    global $ID;
221f3f0262cSandi    global $REV;
222f3f0262cSandi    global $HIGH;
223b8595a66SAndreas Gohr    global $INFO;
224f3f0262cSandi    //disable section editing for old revisions or in preview
2255400331dSandi    if($txt || $REV){
2266bbae538Sandi        $secedit = false;
2276bbae538Sandi    }else{
2286bbae538Sandi        $secedit = true;
229f3f0262cSandi    }
230f3f0262cSandi
2316bbae538Sandi    if ($txt){
232f3f0262cSandi        //PreviewHeader
233b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
234b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
235b8595a66SAndreas Gohr        echo '<div class="preview">';
236b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
237b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
238b8595a66SAndreas Gohr        echo $html;
239b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
240b8595a66SAndreas Gohr        echo '</div>';
2416bbae538Sandi
242f3f0262cSandi    }else{
243c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
244c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2456bbae538Sandi        $html = html_secedit($html,$secedit);
246b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
247b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
248b8595a66SAndreas Gohr        echo $html;
249f3f0262cSandi    }
250f3f0262cSandi}
251f3f0262cSandi
252f3f0262cSandi/**
253ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
254ee4c4a1bSAndreas Gohr *
255ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
256ee4c4a1bSAndreas Gohr */
257ee4c4a1bSAndreas Gohrfunction html_draft(){
258ee4c4a1bSAndreas Gohr    global $INFO;
259ee4c4a1bSAndreas Gohr    global $ID;
260ee4c4a1bSAndreas Gohr    global $lang;
261ee4c4a1bSAndreas Gohr    global $conf;
262ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
263ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
264ee4c4a1bSAndreas Gohr
265fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
266e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
267fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
268fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
269fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
270fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
271f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
272fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
273fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
274fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
275fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
276fdb8d77bSTom N Harris    html_form('draft', $form);
277ee4c4a1bSAndreas Gohr}
278ee4c4a1bSAndreas Gohr
279ee4c4a1bSAndreas Gohr/**
280f3f0262cSandi * Highlights searchqueries in HTML code
28115fae107Sandi *
28215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2837209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
284f3f0262cSandi */
285546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
286808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
287808551e3SAndreas Gohr    $regex = join('|',array_map('preg_quote_cb',$phrases));
28860c15d7dSAndreas Gohr
28960c15d7dSAndreas Gohr    if ($regex === '') return $html;
2901db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
291f3f0262cSandi    return $html;
292f3f0262cSandi}
293f3f0262cSandi
294f3f0262cSandi/**
2957209be23SAndreas Gohr * Callback used by html_hilight()
2967209be23SAndreas Gohr *
2977209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2987209be23SAndreas Gohr */
2997209be23SAndreas Gohrfunction html_hilight_callback($m) {
3007209be23SAndreas Gohr    $hlight = unslash($m[0]);
3017209be23SAndreas Gohr    if ( !isset($m[2])) {
302688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3037209be23SAndreas Gohr    }
3047209be23SAndreas Gohr    return $hlight;
3057209be23SAndreas Gohr}
3067209be23SAndreas Gohr
3077209be23SAndreas Gohr/**
30815fae107Sandi * Run a search and display the result
30915fae107Sandi *
31015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
311f3f0262cSandi */
312f3f0262cSandifunction html_search(){
313ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
314506fa893SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
315f3f0262cSandi    global $conf;
316f3f0262cSandi    global $QUERY;
317f3f0262cSandi    global $ID;
318f3f0262cSandi    global $lang;
319f3f0262cSandi
320c112d578Sandi    print p_locale_xhtml('searchpage');
321f3f0262cSandi    flush();
322f3f0262cSandi
323d0ab54f6SMichael Klier chi@chimeric.de    //check if search is restricted to namespace
324b42bcfe7Sdaniel.lindgren    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
325d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($match[1]);
326d0ab54f6SMichael Klier chi@chimeric.de    } else {
327d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($QUERY);
328d0ab54f6SMichael Klier chi@chimeric.de    }
329d0ab54f6SMichael Klier chi@chimeric.de
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
341865c2687SKazutaka Miyasaka    if($id) $data = ft_pageLookup($id);
342f3f0262cSandi    if(count($data)){
343f3f0262cSandi        print '<div class="search_quickresult">';
344746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3454f732f0eSAnika Henke        print '<ul class="search_quickhits">';
346140c93f3SAnika Henke        foreach($data as $id){
3474f732f0eSAnika Henke            print '<li> ';
348bd2f6c2fSAndreas Gohr            $ns = getNS($id);
349bd2f6c2fSAndreas Gohr            if($ns){
350bd2f6c2fSAndreas Gohr                $name = shorten(noNS($id), ' ('.$ns.')',30);
351bd2f6c2fSAndreas Gohr            }else{
352bd2f6c2fSAndreas Gohr                $name = $id;
353bd2f6c2fSAndreas Gohr            }
354bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3554f732f0eSAnika Henke            print '</li> ';
356f3f0262cSandi        }
357140c93f3SAnika Henke        print '</ul> ';
358f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
359f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
360f3f0262cSandi        print '</div>';
361f3f0262cSandi    }
362f3f0262cSandi    flush();
363f3f0262cSandi
364f3f0262cSandi    //do fulltext search
36560c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
366f3f0262cSandi    if(count($data)){
367506fa893SAndreas Gohr        $num = 1;
368506fa893SAndreas Gohr        foreach($data as $id => $cnt){
369f3f0262cSandi            print '<div class="search_result">';
370db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
371865c2687SKazutaka Miyasaka            if($cnt !== 0){
372506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
373506fa893SAndreas Gohr                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
37460c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
375506fa893SAndreas Gohr                }
376865c2687SKazutaka Miyasaka                $num++;
377865c2687SKazutaka Miyasaka            }
378f3f0262cSandi            print '</div>';
379506fa893SAndreas Gohr            flush();
380f3f0262cSandi        }
381f3f0262cSandi    }else{
382820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
383f3f0262cSandi    }
3844d9ff3d5Sandi
3854d9ff3d5Sandi    //hide progressbar
386e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
387e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
388e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3899edac8a8SAndreas Gohr    flush();
390f3f0262cSandi}
391f3f0262cSandi
39215fae107Sandi/**
39315fae107Sandi * Display error on locked pages
39415fae107Sandi *
39515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39615fae107Sandi */
397ee20e7d1Sandifunction html_locked(){
398f3f0262cSandi    global $ID;
399f3f0262cSandi    global $conf;
400f3f0262cSandi    global $lang;
40188f522e9Sandi    global $INFO;
402f3f0262cSandi
403c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
404f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
405f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
406f3f0262cSandi
407c112d578Sandi    print p_locale_xhtml('locked');
408f3f0262cSandi    print '<ul>';
4096d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
4100c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
411f3f0262cSandi    print '</ul>';
412f3f0262cSandi}
413f3f0262cSandi
41415fae107Sandi/**
41515fae107Sandi * list old revisions
41615fae107Sandi *
41715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
41871726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
41915fae107Sandi */
42071726d78SBen Coburnfunction html_revisions($first=0){
421f3f0262cSandi    global $ID;
422f3f0262cSandi    global $INFO;
423f3f0262cSandi    global $conf;
424f3f0262cSandi    global $lang;
42571726d78SBen Coburn    /* we need to get one additionally log entry to be able to
42671726d78SBen Coburn     * decide if this is the last page or is there another one.
42771726d78SBen Coburn     * see html_recent()
42871726d78SBen Coburn     */
42971726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
43071726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43171726d78SBen Coburn        $first=0;
43271726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
43371726d78SBen Coburn    }
43471726d78SBen Coburn    $hasNext = false;
43571726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
43671726d78SBen Coburn        $hasNext = true;
43771726d78SBen Coburn        array_pop($revisions); // remove extra log entry
43871726d78SBen Coburn    }
43971726d78SBen Coburn
440f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
441f3f0262cSandi
442c112d578Sandi    print p_locale_xhtml('revisions');
44337a1dc12Smichael
444e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
44537a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
44671726d78SBen Coburn    if($INFO['exists'] && $first==0){
44737a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
44837a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
44937a1dc12Smichael        else
45037a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
45137a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
45237a1dc12Smichael        $form->addElement(form_makeTag('input', array(
45337a1dc12Smichael                        'type' => 'checkbox',
45437a1dc12Smichael                        'name' => 'rev2[]',
45537a1dc12Smichael                        'value' => 'current')));
456f9b2fe70Sandi
45737a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
45837a1dc12Smichael        $form->addElement($date);
45937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
460f9b2fe70Sandi
46137a1dc12Smichael        $form->addElement(form_makeTag('img', array(
46237a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
46337a1dc12Smichael                        'width' => '15',
46437a1dc12Smichael                        'height' => '11',
46537a1dc12Smichael                        'alt'    => '')));
466cffcc403Sandi
46737a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
46837a1dc12Smichael                        'class' => 'wikilink1',
46937a1dc12Smichael                        'href'  => wl($ID))));
47037a1dc12Smichael        $form->addElement($ID);
47137a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
472652610a2Sandi
47337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
47437a1dc12Smichael        $form->addElement(' &ndash; ');
47537a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
47637a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
477652610a2Sandi
47837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
47937a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
48037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
48137a1dc12Smichael
48237a1dc12Smichael        $form->addElement('('.$lang['current'].')');
48337a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
48437a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
485f3f0262cSandi    }
486f3f0262cSandi
487f3f0262cSandi    foreach($revisions as $rev){
488f2263577SAndreas Gohr        $date   = dformat($rev);
489fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
490103c256aSChris Smith        $exists = page_exists($ID,$rev);
491652610a2Sandi
49237a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
49337a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
49437a1dc12Smichael        else
49537a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
49637a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
49777707b04SAndreas Gohr        if($exists){
49837a1dc12Smichael            $form->addElement(form_makeTag('input', array(
49937a1dc12Smichael                            'type' => 'checkbox',
50037a1dc12Smichael                            'name' => 'rev2[]',
50137a1dc12Smichael                            'value' => $rev)));
50277707b04SAndreas Gohr        }else{
50337a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50437a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
50537a1dc12Smichael                            'width' => 14,
50637a1dc12Smichael                            'height' => 11,
50737a1dc12Smichael                            'alt' => '')));
50841396b71SAndreas Gohr        }
509f9b2fe70Sandi
51037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
51137a1dc12Smichael        $form->addElement($date);
51237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
51337a1dc12Smichael
51437a1dc12Smichael        if($exists){
51537a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
51637a1dc12Smichael            $form->addElement(form_makeTag('img', array(
51737a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
51837a1dc12Smichael                            'width'  => 15,
51937a1dc12Smichael                            'height' => 11,
52037a1dc12Smichael                            'title'  => $lang['diff'],
52137a1dc12Smichael                            'alt'    => $lang['diff'])));
52237a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52337a1dc12Smichael
52437a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
52537a1dc12Smichael            $form->addElement($ID);
52637a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52737a1dc12Smichael        }else{
52837a1dc12Smichael            $form->addElement(form_makeTag('img', array(
52937a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
53037a1dc12Smichael                            'width' => '15',
53137a1dc12Smichael                            'height' => '11',
53237a1dc12Smichael                            'alt'   => '')));
53337a1dc12Smichael            $form->addElement($ID);
53437a1dc12Smichael        }
53537a1dc12Smichael
53637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
53737a1dc12Smichael        $form->addElement(' &ndash; ');
53837a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
53937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
54037a1dc12Smichael
54137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
54288f522e9Sandi        if($info['user']){
54337a1dc12Smichael            $form->addElement(editorinfo($info['user']));
544433efb25SAndreas Gohr            if(auth_ismanager()){
545433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
546433efb25SAndreas Gohr            }
54788f522e9Sandi        }else{
54837a1dc12Smichael            $form->addElement($info['ip']);
54988f522e9Sandi        }
55037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
551652610a2Sandi
55237a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
55337a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
554f3f0262cSandi    }
55537a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
55637a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
55737a1dc12Smichael    html_form('revisions', $form);
55871726d78SBen Coburn
55971726d78SBen Coburn    print '<div class="pagenav">';
56071726d78SBen Coburn    $last = $first + $conf['recent'];
56171726d78SBen Coburn    if ($first > 0) {
56271726d78SBen Coburn        $first -= $conf['recent'];
56371726d78SBen Coburn        if ($first < 0) $first = 0;
56471726d78SBen Coburn        print '<div class="pagenav-prev">';
565eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
56671726d78SBen Coburn        print '</div>';
56771726d78SBen Coburn    }
56871726d78SBen Coburn    if ($hasNext) {
56971726d78SBen Coburn        print '<div class="pagenav-next">';
570eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
57171726d78SBen Coburn        print '</div>';
57271726d78SBen Coburn    }
57371726d78SBen Coburn    print '</div>';
57471726d78SBen Coburn
575f3f0262cSandi}
576f3f0262cSandi
57715fae107Sandi/**
57815fae107Sandi * display recent changes
57915fae107Sandi *
58015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5815749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
58271726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
58315fae107Sandi */
584a39955b0Smatthiasgrimmfunction html_recent($first=0){
585f3f0262cSandi    global $conf;
586cffcc403Sandi    global $lang;
587dbb00abcSEsther Brunner    global $ID;
5885749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5895749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5905749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5915749f1ceSmatthiasgrimm     */
592b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5935749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5945749f1ceSmatthiasgrimm        $first=0;
59571726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5965749f1ceSmatthiasgrimm    }
59771726d78SBen Coburn    $hasNext = false;
59871726d78SBen Coburn    if (count($recents)>$conf['recent']) {
59971726d78SBen Coburn        $hasNext = true;
60071726d78SBen Coburn        array_pop($recents); // remove extra log entry
60171726d78SBen Coburn    }
602f3f0262cSandi
603c112d578Sandi    print p_locale_xhtml('recent');
604e83cef14SGina Haeussge
605e83cef14SGina Haeussge    if (getNS($ID) != '')
6069e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
607e83cef14SGina Haeussge
608e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
609abdcc39fSmichael    $form->addHidden('sectok', null);
610abdcc39fSmichael    $form->addHidden('do', 'recent');
611abdcc39fSmichael    $form->addHidden('id', $ID);
612abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
613a39955b0Smatthiasgrimm
614d437bcc4SAndreas Gohr    foreach($recents as $recent){
615f2263577SAndreas Gohr        $date = dformat($recent['date']);
616abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
617abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
618abdcc39fSmichael        else
619abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
620cffcc403Sandi
621abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
622f9b2fe70Sandi
623abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
624abdcc39fSmichael        $form->addElement($date);
625abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
626cffcc403Sandi
627cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
628abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
629abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
630abdcc39fSmichael                        'width' => 15,
631abdcc39fSmichael                        'height'=> 11,
632abdcc39fSmichael                        'title' => $lang['diff'],
633abdcc39fSmichael                        'alt'   => $lang['diff']
634abdcc39fSmichael                        )));
635abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
636cffcc403Sandi
637cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
638abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
639abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
640abdcc39fSmichael                        'width' => 12,
641abdcc39fSmichael                        'height'=> 14,
642abdcc39fSmichael                        'title' => $lang['btn_revs'],
643abdcc39fSmichael                        'alt'   => $lang['btn_revs']
644abdcc39fSmichael                        )));
645abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
646b6912aeaSAndreas Gohr
647db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
648abdcc39fSmichael
649abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
650abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
651abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
652abdcc39fSmichael
653abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
654d437bcc4SAndreas Gohr        if($recent['user']){
655abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
656433efb25SAndreas Gohr            if(auth_ismanager()){
657433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
658433efb25SAndreas Gohr            }
65988f522e9Sandi        }else{
660abdcc39fSmichael            $form->addElement($recent['ip']);
66188f522e9Sandi        }
662abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
663cffcc403Sandi
664abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
665abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
666f3f0262cSandi    }
667abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
668a39955b0Smatthiasgrimm
669abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6705749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
671a39955b0Smatthiasgrimm    if ($first > 0) {
672a39955b0Smatthiasgrimm        $first -= $conf['recent'];
673a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
674abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
675abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
676abdcc39fSmichael                    'type'  => 'submit',
677abdcc39fSmichael                    'name'  => 'first['.$first.']',
678cddd152cSmichael                    'value' => $lang['btn_newer'],
679cddd152cSmichael                    'accesskey' => 'n',
680f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
68118d107cbSMichael Klier                    'class' => 'button'
682abdcc39fSmichael                    )));
683abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
684a39955b0Smatthiasgrimm    }
68571726d78SBen Coburn    if ($hasNext) {
686abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
687abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
688abdcc39fSmichael                        'type'  => 'submit',
689abdcc39fSmichael                        'name'  => 'first['.$last.']',
690cddd152cSmichael                        'value' => $lang['btn_older'],
691cddd152cSmichael                        'accesskey' => 'p',
692f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
69318d107cbSMichael Klier                        'class' => 'button'
694abdcc39fSmichael                        )));
695abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
696a39955b0Smatthiasgrimm    }
697abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
698abdcc39fSmichael    html_form('recent', $form);
699f3f0262cSandi}
700f3f0262cSandi
70115fae107Sandi/**
70215fae107Sandi * Display page index
70315fae107Sandi *
70415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
70515fae107Sandi */
706f3f0262cSandifunction html_index($ns){
707ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
708f3f0262cSandi    global $conf;
709f3f0262cSandi    global $ID;
710f3f0262cSandi    $dir = $conf['datadir'];
711f3f0262cSandi    $ns  = cleanID($ns);
71230f1737dSandi    #fixme use appropriate function
713f3f0262cSandi    if(empty($ns)){
714f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
715f3f0262cSandi        if($ns == '.') $ns ='';
716f3f0262cSandi    }
71788d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
718f3f0262cSandi
719a06884abSAndreas Gohr    echo p_locale_xhtml('index');
720a06884abSAndreas Gohr    echo '<div id="index__tree">';
721f3f0262cSandi
722f3f0262cSandi    $data = array();
723f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
724a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
725a06884abSAndreas Gohr
726a06884abSAndreas Gohr    echo '</div>';
727f3f0262cSandi}
728f3f0262cSandi
729f3f0262cSandi/**
73015fae107Sandi * Index item formatter
73115fae107Sandi *
732f3f0262cSandi * User function for html_buildlist()
73315fae107Sandi *
73415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
735f3f0262cSandi */
736f3f0262cSandifunction html_list_index($item){
737d98d4540SBen Coburn    global $ID;
738f3f0262cSandi    $ret = '';
739f3f0262cSandi    $base = ':'.$item['id'];
740f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
741f3f0262cSandi    if($item['type']=='d'){
7424a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
743f3f0262cSandi        $ret .= $base;
744ed7ecb79SAnika Henke        $ret .= '</strong></a>';
745f3f0262cSandi    }else{
746f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
747f3f0262cSandi    }
748f3f0262cSandi    return $ret;
749f3f0262cSandi}
750f3f0262cSandi
751f3f0262cSandi/**
752cb70c441Sandi * Index List item
753cb70c441Sandi *
754cb70c441Sandi * This user function is used in html_build_lidt to build the
755cb70c441Sandi * <li> tags for namespaces when displaying the page index
756cb70c441Sandi * it gives different classes to opened or closed "folders"
757cb70c441Sandi *
758cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
759cb70c441Sandi */
760cb70c441Sandifunction html_li_index($item){
761cb70c441Sandi    if($item['type'] == "f"){
762cb70c441Sandi        return '<li class="level'.$item['level'].'">';
763cb70c441Sandi    }elseif($item['open']){
764cb70c441Sandi        return '<li class="open">';
765cb70c441Sandi    }else{
766cb70c441Sandi        return '<li class="closed">';
767cb70c441Sandi    }
768cb70c441Sandi}
769cb70c441Sandi
770cb70c441Sandi/**
771cb70c441Sandi * Default List item
772cb70c441Sandi *
773cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
774cb70c441Sandi */
775cb70c441Sandifunction html_li_default($item){
776cb70c441Sandi    return '<li class="level'.$item['level'].'">';
777cb70c441Sandi}
778cb70c441Sandi
779cb70c441Sandi/**
78015fae107Sandi * Build an unordered list
78115fae107Sandi *
782f3f0262cSandi * Build an unordered list from the given $data array
783f3f0262cSandi * Each item in the array has to have a 'level' property
784f3f0262cSandi * the item itself gets printed by the given $func user
785cb70c441Sandi * function. The second and optional function is used to
786cb70c441Sandi * print the <li> tag. Both user function need to accept
787cb70c441Sandi * a single item.
78815fae107Sandi *
789c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
790c5a8fd96SAndreas Gohr * a member of an object.
791c5a8fd96SAndreas Gohr *
79215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
793f3f0262cSandi */
794cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
795f3f0262cSandi    $level = 0;
796f3f0262cSandi    $opens = 0;
797f3f0262cSandi    $ret   = '';
798f3f0262cSandi
799f3f0262cSandi    foreach ($data as $item){
800f3f0262cSandi
801f3f0262cSandi        if( $item['level'] > $level ){
802f3f0262cSandi            //open new list
803df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
804df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
805f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
806df52d0feSandi            }
807f3f0262cSandi        }elseif( $item['level'] < $level ){
808f3f0262cSandi            //close last item
809f3f0262cSandi            $ret .= "</li>\n";
810f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
811f3f0262cSandi                //close higher lists
812f3f0262cSandi                $ret .= "</ul>\n</li>\n";
813f3f0262cSandi            }
814f3f0262cSandi        }else{
815f3f0262cSandi            //close last item
816f3f0262cSandi            $ret .= "</li>\n";
817f3f0262cSandi        }
818f3f0262cSandi
819f3f0262cSandi        //remember current level
820f3f0262cSandi        $level = $item['level'];
821f3f0262cSandi
822f3f0262cSandi        //print item
82334dbe711Schris        $ret .= call_user_func($lifunc,$item);
8240c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
82534dbe711Schris
82634dbe711Schris        $ret .= call_user_func($func,$item);
8270c6b58a8SAndreas Gohr        $ret .= '</div>';
828f3f0262cSandi    }
829f3f0262cSandi
830f3f0262cSandi    //close remaining items and lists
831f3f0262cSandi    for ($i=0; $i < $level; $i++){
832f3f0262cSandi        $ret .= "</li></ul>\n";
833f3f0262cSandi    }
834f3f0262cSandi
835f3f0262cSandi    return $ret;
836f3f0262cSandi}
837f3f0262cSandi
83815fae107Sandi/**
83915fae107Sandi * display backlinks
84015fae107Sandi *
84115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
84211df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
84315fae107Sandi */
844f3f0262cSandifunction html_backlinks(){
84554f4c056SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
846f3f0262cSandi    global $ID;
847f3f0262cSandi    global $conf;
84811df47ecSMichael Klier    global $lang;
849f3f0262cSandi
850c112d578Sandi    print p_locale_xhtml('backlinks');
851f3f0262cSandi
85254f4c056SAndreas Gohr    $data = ft_backlinks($ID);
853f3f0262cSandi
85411df47ecSMichael Klier    if(!empty($data)) {
855f3f0262cSandi        print '<ul class="idx">';
85654f4c056SAndreas Gohr        foreach($data as $blink){
8570c6b58a8SAndreas Gohr            print '<li><div class="li">';
858db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8590c6b58a8SAndreas Gohr            print '</div></li>';
860f3f0262cSandi        }
861f3f0262cSandi        print '</ul>';
86211df47ecSMichael Klier    } else {
86311df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
86411df47ecSMichael Klier    }
865f3f0262cSandi}
866f3f0262cSandi
86715fae107Sandi/**
86815fae107Sandi * show diff
86915fae107Sandi *
87015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
87115fae107Sandi */
872f3f0262cSandifunction html_diff($text='',$intro=true){
873ed7b5f09Sandi    require_once(DOKU_INC.'inc/DifferenceEngine.php');
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');
994f3f0262cSandi    ?>
995daf4ca4eSAnika Henke    <table class="diff">
996f3f0262cSandi    <tr>
997e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
99877707b04SAndreas Gohr    <?php echo $l_head?>
999daf4ca4eSAnika Henke    </th>
1000e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
100177707b04SAndreas Gohr    <?php echo $r_head?>
1002daf4ca4eSAnika Henke    </th>
1003f3f0262cSandi    </tr>
10044da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
1005f3f0262cSandi    </table>
10064da078a3Smatthiasgrimm    <?php
1007f3f0262cSandi}
1008f3f0262cSandi
100915fae107Sandi/**
101015fae107Sandi * show warning on conflict detection
101115fae107Sandi *
101215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
101315fae107Sandi */
1014f3f0262cSandifunction html_conflict($text,$summary){
1015f3f0262cSandi    global $ID;
1016f3f0262cSandi    global $lang;
1017f3f0262cSandi
1018c112d578Sandi    print p_locale_xhtml('conflict');
1019e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1020fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1021fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1022fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1023fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1024fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1025fdb8d77bSTom N Harris    html_form('conflict', $form);
1026fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1027f3f0262cSandi}
1028f3f0262cSandi
1029f3f0262cSandi/**
103015fae107Sandi * Prints the global message array
103115fae107Sandi *
103215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1033f3f0262cSandi */
1034f3f0262cSandifunction html_msgarea(){
1035f3f0262cSandi    global $MSG;
1036f3f0262cSandi    if(!isset($MSG)) return;
1037f3f0262cSandi
10384af9f0d4SAndreas Gohr    $shown = array();
1039f3f0262cSandi    foreach($MSG as $msg){
10404af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10414af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1042f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1043f3f0262cSandi        print $msg['msg'];
1044f3f0262cSandi        print '</div>';
10454af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1046f3f0262cSandi    }
1047f3f0262cSandi}
1048f3f0262cSandi
1049f3f0262cSandi/**
1050f3f0262cSandi * Prints the registration form
105115fae107Sandi *
105215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1053f3f0262cSandi */
1054f3f0262cSandifunction html_register(){
1055f3f0262cSandi    global $lang;
1056cab2716aSmatthias.grimm    global $conf;
1057f3f0262cSandi    global $ID;
1058f3f0262cSandi
1059c112d578Sandi    print p_locale_xhtml('register');
1060fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1061e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1062fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1063fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1064fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1065fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1066cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1067fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1068fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1069cab2716aSmatthias.grimm    }
1070fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1071fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1072fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1073fdb8d77bSTom N Harris    $form->endFieldset();
1074fdb8d77bSTom N Harris    html_form('register', $form);
1075cab2716aSmatthias.grimm
1076fdb8d77bSTom N Harris    print '</div>'.NL;
1077f3f0262cSandi}
1078f3f0262cSandi
1079f3f0262cSandi/**
10808b06d178Schris * Print the update profile form
10818b06d178Schris *
10828b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10838b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10848b06d178Schris */
10858b06d178Schrisfunction html_updateprofile(){
10868b06d178Schris    global $lang;
10878b06d178Schris    global $conf;
10888b06d178Schris    global $ID;
10898b06d178Schris    global $INFO;
109082fd59b6SAndreas Gohr    global $auth;
10918b06d178Schris
10928b06d178Schris    print p_locale_xhtml('updateprofile');
10938b06d178Schris
10948b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10958b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1096fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1097e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1098fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1099fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1100fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1101fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1102fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1103fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1104fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
110539ba8890SAndreas Gohr    $attr = array('size'=>'50');
110639ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1107fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1108fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1109fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1110fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1111fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1112fdb8d77bSTom N Harris    }
1113fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1114fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1115fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1116fdb8d77bSTom N Harris    }
1117fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1118fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1119fdb8d77bSTom N Harris    $form->endFieldset();
1120fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1121fdb8d77bSTom N Harris    print '</div>'.NL;
11228b06d178Schris}
11238b06d178Schris
11248b06d178Schris/**
11257c4635c4SAdrian Lang * Preprocess edit form data
112615fae107Sandi *
1127016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
112815fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1129f3f0262cSandi */
1130f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1131f3f0262cSandi    global $ID;
1132f3f0262cSandi    global $REV;
1133f3f0262cSandi    global $DATE;
1134f3f0262cSandi    global $RANGE;
1135f3f0262cSandi    global $PRE;
1136f3f0262cSandi    global $SUF;
1137f3f0262cSandi    global $INFO;
1138f3f0262cSandi    global $SUM;
1139f3f0262cSandi    global $lang;
1140f3f0262cSandi    global $conf;
1141f3f0262cSandi
1142f3f0262cSandi    //set summary default
1143f3f0262cSandi    if(!$SUM){
1144f3f0262cSandi        if($REV){
1145f3f0262cSandi            $SUM = $lang['restored'];
1146f3f0262cSandi        }elseif(!$INFO['exists']){
1147f3f0262cSandi            $SUM = $lang['created'];
1148f3f0262cSandi        }
1149f3f0262cSandi    }
1150f3f0262cSandi
1151f3f0262cSandi    //no text? Load it!
1152f3f0262cSandi    if(!isset($text)){
1153f3f0262cSandi        $pr = false; //no preview mode
11547146cee2SAndreas Gohr        if($INFO['exists']){
1155f3f0262cSandi            if($RANGE){
1156f3f0262cSandi                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1157f3f0262cSandi            }else{
1158f3f0262cSandi                $text = rawWiki($ID,$REV);
1159f3f0262cSandi            }
11608fe3bb00STom N Harris            $check = md5($text);
11618fe3bb00STom N Harris            $mod = false;
1162f3f0262cSandi        }else{
11637146cee2SAndreas Gohr            //try to load a pagetemplate
1164b7d5a5f0SAndreas Gohr            $data = array($ID);
1165016b6153SAndreas Gohr            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
11668fe3bb00STom N Harris            $check = md5('');
11678fe3bb00STom N Harris            $mod = $text!=='';
11687146cee2SAndreas Gohr        }
11697146cee2SAndreas Gohr    }else{
1170f3f0262cSandi        $pr = true; //preview mode
11718fe3bb00STom N Harris        if (isset($_REQUEST['changecheck'])) {
11728fe3bb00STom N Harris            $check = $_REQUEST['changecheck'];
11738fe3bb00STom N Harris            $mod = md5($text)!==$check;
11748fe3bb00STom N Harris        } else {
11758fe3bb00STom N Harris            // Why? Assume default text is unmodified.
11768fe3bb00STom N Harris            $check = md5($text);
11778fe3bb00STom N Harris            $mod = false;
11788fe3bb00STom N Harris        }
1179f3f0262cSandi    }
1180f3f0262cSandi
118127eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
1182f3f0262cSandi    if($wr){
1183c112d578Sandi        if ($REV) print p_locale_xhtml('editrev');
1184c112d578Sandi        print p_locale_xhtml($include);
1185f3f0262cSandi    }else{
1186409d7af7SAndreas Gohr        // check pseudo action 'source'
1187409d7af7SAndreas Gohr        if(!actionOK('source')){
1188409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1189409d7af7SAndreas Gohr            return;
1190409d7af7SAndreas Gohr        }
1191c112d578Sandi        print p_locale_xhtml('read');
1192f3f0262cSandi    }
1193f3f0262cSandi    if(!$DATE) $DATE = $INFO['lastmod'];
11947c4635c4SAdrian Lang
11957c4635c4SAdrian Lang    $data = compact('wr', 'text', 'mod', 'check');
11967c4635c4SAdrian Lang    trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
11977c4635c4SAdrian Lang}
11987c4635c4SAdrian Lang
11997c4635c4SAdrian Lang/**
12007c4635c4SAdrian Lang * Display the default edit form
12017c4635c4SAdrian Lang *
12027c4635c4SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
12037c4635c4SAdrian Lang *
12047c4635c4SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
12057c4635c4SAdrian Lang */
12067c4635c4SAdrian Langfunction html_edit_form($param) {
12077c4635c4SAdrian Lang    extract($param);
12087c4635c4SAdrian Lang    global $conf;
12097c4635c4SAdrian Lang    global $license;
12107c4635c4SAdrian Lang    global $lang;
12117c4635c4SAdrian Lang    global $REV;
12127c4635c4SAdrian Lang    global $DATE;
12137c4635c4SAdrian Lang    global $PRE;
12147c4635c4SAdrian Lang    global $SUF;
12157c4635c4SAdrian Lang    global $INFO;
12167c4635c4SAdrian Lang    global $SUM;
12177c4635c4SAdrian Lang    global $ID;
1218f3f0262cSandi    ?>
12197c4635c4SAdrian Lang            <?php if($wr){?>
12207c4635c4SAdrian Lang                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
12217c4635c4SAdrian Lang                    <?php /* sets changed to true when previewed */?>
12227c4635c4SAdrian Lang                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
12237c4635c4SAdrian Lang                //--><!]]></script>
12247c4635c4SAdrian Lang            <?php } ?>
122563afe2a6SAnika Henke        <div style="width:99%;">
122642c7abd6SAndreas Gohr
122763afe2a6SAnika Henke        <div class="toolbar">
1228f2263577SAndreas Gohr        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1229fdb8d77bSTom N Harris        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1230409d7af7SAndreas Gohr            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
123120d062caSAndreas Gohr
123263afe2a6SAnika Henke        </div>
12334da078a3Smatthiasgrimm        <?php
1234e351c80dSAdrian Lang        $form = new Doku_Form(array('id' => 'dw__editform'));
1235fdb8d77bSTom N Harris        $form->addHidden('id', $ID);
1236fdb8d77bSTom N Harris        $form->addHidden('rev', $REV);
1237fdb8d77bSTom N Harris        $form->addHidden('date', $DATE);
1238fdb8d77bSTom N Harris        $form->addHidden('prefix', $PRE);
1239fdb8d77bSTom N Harris        $form->addHidden('suffix', $SUF);
1240fdb8d77bSTom N Harris        $form->addHidden('changecheck', $check);
1241fdb8d77bSTom N Harris        $attr = array('tabindex'=>'1');
1242fdb8d77bSTom N Harris        if (!$wr) $attr['readonly'] = 'readonly';
1243fdb8d77bSTom N Harris        $form->addElement(form_makeWikiText($text, $attr));
1244fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1245fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1246fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1247fdb8d77bSTom N Harris        if ($wr) {
1248fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1249fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1250fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1251fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1252fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1253fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1254fdb8d77bSTom N Harris            $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1255fdb8d77bSTom N Harris            $elem = html_minoredit();
1256fdb8d77bSTom N Harris            if ($elem) $form->addElement($elem);
1257fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1258fdb8d77bSTom N Harris        }
1259fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
12605808bc54SAndreas Gohr        if($wr && $conf['license']){
1261066fee30SAndreas Gohr            $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1262066fee30SAndreas Gohr            $out  = $lang['licenseok'];
1263066fee30SAndreas Gohr            $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1264c0322273SAdrian Lang            if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1265066fee30SAndreas Gohr            $out .= '> '.$license[$conf['license']]['name'].'</a>';
1266066fee30SAndreas Gohr            $form->addElement($out);
1267066fee30SAndreas Gohr            $form->addElement(form_makeCloseTag('div'));
1268066fee30SAndreas Gohr        }
1269fdb8d77bSTom N Harris        html_form('edit', $form);
1270fdb8d77bSTom N Harris        print '</div>'.NL;
1271f3f0262cSandi}
1272f3f0262cSandi
1273f3f0262cSandi/**
1274b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1275b6912aeaSAndreas Gohr *
1276b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1277b6912aeaSAndreas Gohr */
1278b6912aeaSAndreas Gohrfunction html_minoredit(){
1279b6912aeaSAndreas Gohr    global $conf;
1280b6912aeaSAndreas Gohr    global $lang;
1281b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1282b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1283fdb8d77bSTom N Harris        return false;
1284b6912aeaSAndreas Gohr    }
1285b6912aeaSAndreas Gohr
1286b6912aeaSAndreas Gohr    $p = array();
1287b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1288bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1289fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1290b6912aeaSAndreas Gohr}
1291b6912aeaSAndreas Gohr
1292b6912aeaSAndreas Gohr/**
1293f3f0262cSandi * prints some debug info
129415fae107Sandi *
129515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1296f3f0262cSandi */
1297f3f0262cSandifunction html_debug(){
1298f3f0262cSandi    global $conf;
1299d16a4edaSandi    global $lang;
13005298a619SAndreas Gohr    global $auth;
1301100a97e3SAndreas Gohr    global $INFO;
1302100a97e3SAndreas Gohr
130328fb55ffSandi    //remove sensitive data
130428fb55ffSandi    $cnf = $conf;
130524297a69SAndreas Gohr    debug_guard($cnf);
1306100a97e3SAndreas Gohr    $nfo = $INFO;
130724297a69SAndreas Gohr    debug_guard($nfo);
1308100a97e3SAndreas Gohr    $ses = $_SESSION;
130924297a69SAndreas Gohr    debug_guard($ses);
1310f3f0262cSandi
1311f3f0262cSandi    print '<html><body>';
1312f3f0262cSandi
1313f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1314f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1315f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1316f3f0262cSandi
1317100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1318100a97e3SAndreas Gohr    print_r($nfo);
1319100a97e3SAndreas Gohr    print '</pre>';
1320100a97e3SAndreas Gohr
1321f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1322f3f0262cSandi    print_r($_SERVER);
1323f3f0262cSandi    print '</pre>';
1324f3f0262cSandi
1325f3f0262cSandi    print '<b>$conf:</b><pre>';
132628fb55ffSandi    print_r($cnf);
1327f3f0262cSandi    print '</pre>';
1328f3f0262cSandi
1329ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1330ed7b5f09Sandi    print DOKU_BASE;
1331f3f0262cSandi    print '</pre>';
1332f3f0262cSandi
1333ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1334ed7b5f09Sandi    print DOKU_URL;
1335ed7b5f09Sandi    print '</pre>';
1336ed7b5f09Sandi
1337ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1338f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1339f3f0262cSandi    print '</pre>';
1340f3f0262cSandi
1341f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1342f3f0262cSandi    print phpversion();
1343f3f0262cSandi    print '</pre>';
1344f3f0262cSandi
1345f3f0262cSandi    print '<b>locale:</b><pre>';
1346f3f0262cSandi    print setlocale(LC_ALL,0);
1347f3f0262cSandi    print '</pre>';
1348f3f0262cSandi
1349d16a4edaSandi    print '<b>encoding:</b><pre>';
1350d16a4edaSandi    print $lang['encoding'];
1351d16a4edaSandi    print '</pre>';
1352d16a4edaSandi
13535298a619SAndreas Gohr    if($auth){
13545298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13555298a619SAndreas Gohr        print_r($auth->cando);
13565298a619SAndreas Gohr        print '</pre>';
13575298a619SAndreas Gohr    }
13585298a619SAndreas Gohr
13593aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1360100a97e3SAndreas Gohr    print_r($ses);
13613aa54d7cSAndreas Gohr    print '</pre>';
13623aa54d7cSAndreas Gohr
1363f3f0262cSandi    print '<b>Environment:</b><pre>';
1364f3f0262cSandi    print_r($_ENV);
1365f3f0262cSandi    print '</pre>';
1366f3f0262cSandi
1367f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1368f3f0262cSandi    $inis = ini_get_all();
1369f3f0262cSandi    print_r($inis);
1370f3f0262cSandi    print '</pre>';
1371f3f0262cSandi
1372f3f0262cSandi    print '</body></html>';
1373f3f0262cSandi}
1374f3f0262cSandi
137510271ce4SAndreas Gohr/**
137610271ce4SAndreas Gohr * List available Administration Tasks
137710271ce4SAndreas Gohr *
137810271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
137910271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
138010271ce4SAndreas Gohr */
1381c19fe9c0Sandifunction html_admin(){
1382c19fe9c0Sandi    global $ID;
1383f8cc712eSAndreas Gohr    global $INFO;
1384c19fe9c0Sandi    global $lang;
1385ca3a6df1SMatthias Grimm    global $conf;
138610271ce4SAndreas Gohr    global $auth;
1387c19fe9c0Sandi
138811e2ce22Schris    // build menu of admin functions from the plugins that handle them
138911e2ce22Schris    $pluginlist = plugin_list('admin');
139011e2ce22Schris    $menu = array();
139111e2ce22Schris    foreach ($pluginlist as $p) {
1392db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1393f8cc712eSAndreas Gohr
1394f8cc712eSAndreas Gohr        // check permissions
1395f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1396f8cc712eSAndreas Gohr
139710271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
139811e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
139911e2ce22Schris                'sort' => $obj->getMenuSort()
140011e2ce22Schris                );
140111e2ce22Schris    }
140211e2ce22Schris
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
145610271ce4SAndreas Gohr    ptln('</ul>');
145710271ce4SAndreas Gohr
145810271ce4SAndreas Gohr    // print the rest as sorted list
145910271ce4SAndreas Gohr    if(count($menu)){
1460746855cfSBen Coburn        usort($menu, 'p_sort_modes');
146111e2ce22Schris        // output the menu
146210271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
146310271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
146411e2ce22Schris        ptln('<ul>');
146511e2ce22Schris        foreach ($menu as $item) {
146611e2ce22Schris            if (!$item['prompt']) continue;
14670c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
146811e2ce22Schris        }
146911e2ce22Schris        ptln('</ul>');
1470ca3a6df1SMatthias Grimm    }
147110271ce4SAndreas Gohr}
1472c19fe9c0Sandi
14738b06d178Schris/**
14748b06d178Schris * Form to request a new password for an existing account
14758b06d178Schris *
14768b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
147711e2ce22Schris */
14788b06d178Schrisfunction html_resendpwd() {
14798b06d178Schris    global $lang;
14808b06d178Schris    global $conf;
14818b06d178Schris    global $ID;
1482c19fe9c0Sandi
14838b06d178Schris    print p_locale_xhtml('resendpwd');
1484fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1485e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1486fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1487fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1488fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1489fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1490fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1491fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1492fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1493fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1494fdb8d77bSTom N Harris    $form->endFieldset();
1495fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1496fdb8d77bSTom N Harris    print '</div>'.NL;
1497fdb8d77bSTom N Harris}
1498fdb8d77bSTom N Harris
1499fdb8d77bSTom N Harris/**
1500b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1501b8595a66SAndreas Gohr *
1502b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1503b8595a66SAndreas Gohr */
1504b8595a66SAndreas Gohrfunction html_TOC($toc){
1505b8595a66SAndreas Gohr    if(!count($toc)) return '';
1506b8595a66SAndreas Gohr    global $lang;
1507b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1508b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1509b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1510b8595a66SAndreas Gohr    $out .= $lang['toc'];
1511b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1512b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1513b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1514b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1515b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1516db959ae3SAndreas Gohr    return $out;
1517db959ae3SAndreas Gohr}
1518b8595a66SAndreas Gohr
1519b8595a66SAndreas Gohr/**
1520b8595a66SAndreas Gohr * Callback for html_buildlist
1521b8595a66SAndreas Gohr */
1522b8595a66SAndreas Gohrfunction html_list_toc($item){
1523c66972f2SAdrian Lang    if(isset($item['hid'])){
15247d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15257d91652aSAndreas Gohr    }else{
15267d91652aSAndreas Gohr        $link = $item['link'];
15277d91652aSAndreas Gohr    }
15287d91652aSAndreas Gohr
15297d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1530b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1531b8595a66SAndreas Gohr}
1532b8595a66SAndreas Gohr
1533b8595a66SAndreas Gohr/**
1534b8595a66SAndreas Gohr * Helper function to build TOC items
1535b8595a66SAndreas Gohr *
1536b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1537b8595a66SAndreas Gohr *
1538b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1539b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1540b8595a66SAndreas Gohr * @param int    $level - nesting level
1541b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1542b8595a66SAndreas Gohr */
1543b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1544b8595a66SAndreas Gohr    global $conf;
1545b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1546b8595a66SAndreas Gohr            'title' => $text,
1547b8595a66SAndreas Gohr            'type'  => 'ul',
15482bb0d541Schris            'level' => $level);
1549b8595a66SAndreas Gohr}
1550b8595a66SAndreas Gohr
1551b8595a66SAndreas Gohr/**
1552fdb8d77bSTom N Harris * Output a Doku_Form object.
1553fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1554fdb8d77bSTom N Harris *
1555fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1556fdb8d77bSTom N Harris */
1557fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1558fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1559fdb8d77bSTom N Harris    $form->endFieldset();
1560fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1561fdb8d77bSTom N Harris}
1562fdb8d77bSTom N Harris
1563fdb8d77bSTom N Harris/**
1564fdb8d77bSTom N Harris * Form print function.
1565fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1566fdb8d77bSTom N Harris */
1567fdb8d77bSTom N Harrisfunction html_form_output($data) {
1568fdb8d77bSTom N Harris    $data->printForm();
15698b06d178Schris}
1570340756e4Sandi
157107bf32b2SAndreas Gohr/**
157207bf32b2SAndreas Gohr * Embed a flash object in HTML
157307bf32b2SAndreas Gohr *
157407bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
157507bf32b2SAndreas Gohr * compatble way using valid XHTML
157607bf32b2SAndreas Gohr *
157707bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
157807bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
157907bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
158007bf32b2SAndreas Gohr * $lang['noflash'] is used.
158107bf32b2SAndreas Gohr *
158207bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
158307bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
158407bf32b2SAndreas Gohr *
158507bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
158607bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
158707bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
158807bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
158907bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
159007bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
159107bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
159207bf32b2SAndreas Gohr * @returns string         - the XHTML markup
159307bf32b2SAndreas Gohr */
159407bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
159507bf32b2SAndreas Gohr    global $lang;
159607bf32b2SAndreas Gohr
159707bf32b2SAndreas Gohr    $out = '';
159807bf32b2SAndreas Gohr
159907bf32b2SAndreas Gohr    // prepare the object attributes
160007bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
160107bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1602d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
160307bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
160407bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
160507bf32b2SAndreas Gohr
160607bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
160707bf32b2SAndreas Gohr    $std = $atts;
160807bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
160907bf32b2SAndreas Gohr    $std['data'] = $swf;
161007bf32b2SAndreas Gohr
161107bf32b2SAndreas Gohr    // add object attributes for IE
161207bf32b2SAndreas Gohr    $ie  = $atts;
161307bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
161407bf32b2SAndreas Gohr
161507bf32b2SAndreas Gohr    // open object (with conditional comments)
161607bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
161707bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
161807bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
161907bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
162007bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
162107bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16229ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
162307bf32b2SAndreas Gohr
162407bf32b2SAndreas Gohr    // print params
162507bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
162607bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
162707bf32b2SAndreas Gohr    }
162807bf32b2SAndreas Gohr
162907bf32b2SAndreas Gohr    // add flashvars
163007bf32b2SAndreas Gohr    if(is_array($flashvars)){
1631d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
163207bf32b2SAndreas Gohr    }
163307bf32b2SAndreas Gohr
163407bf32b2SAndreas Gohr    // alternative content
163507bf32b2SAndreas Gohr    if($alt){
163607bf32b2SAndreas Gohr        $out .= $alt.NL;
163707bf32b2SAndreas Gohr    }else{
163807bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
163907bf32b2SAndreas Gohr    }
164007bf32b2SAndreas Gohr
164107bf32b2SAndreas Gohr    // finish
164207bf32b2SAndreas Gohr    $out .= '</object>'.NL;
164307bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
164407bf32b2SAndreas Gohr
164507bf32b2SAndreas Gohr    return $out;
164607bf32b2SAndreas Gohr}
164707bf32b2SAndreas Gohr
1648