xref: /dokuwiki/inc/html.php (revision 90df9a4d69a2e467433b419b94fe799d11590539)
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 * prints a section editing button
8635dae8b0SBen Coburn * used as a callback in html_secedit
8715fae107Sandi *
8815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8915fae107Sandi */
9035dae8b0SBen Coburnfunction html_secedit_button($matches){
91f3f0262cSandi    global $ID;
92041d7a86SBen Coburn    global $INFO;
93041d7a86SBen Coburn
94*90df9a4dSAdrian Lang    $nr = $matches[1];
95*90df9a4dSAdrian Lang    $target = strtolower($matches[2]);
96b081e262SAdrian Lang
97*90df9a4dSAdrian Lang    $name = $matches[3];
98*90df9a4dSAdrian Lang    $section = $matches[4];
99041d7a86SBen Coburn
100*90df9a4dSAdrian Lang    return "<div class='secedit editbutton_$target editbutton_$nr'>" .
101*90df9a4dSAdrian Lang               html_btn('secedit',$ID,'',
102f3f0262cSandi            array('do'      => 'edit',
103b081e262SAdrian Lang                'lines'   => $section,
104*90df9a4dSAdrian Lang                'edittarget' => $target,
105306b2c85SDenis Simakov                'rev' => $INFO['lastmod']),
106*90df9a4dSAdrian Lang            'post', $name) . '</div>';
107f3f0262cSandi}
108f3f0262cSandi
10915fae107Sandi/**
11015fae107Sandi * inserts section edit buttons if wanted or removes the markers
11115fae107Sandi *
11215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
11315fae107Sandi */
114f3f0262cSandifunction html_secedit($text,$show=true){
115f3f0262cSandi    global $INFO;
11635dae8b0SBen Coburn
117*90df9a4dSAdrian Lang    $regexp = '#<!-- EDIT(\d+) ([A-Z]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
118b081e262SAdrian Lang
119c112d578Sandi    if($INFO['writable'] && $show && !$INFO['rev']){
120b081e262SAdrian Lang        $text = preg_replace_callback($regexp,
12135dae8b0SBen Coburn                'html_secedit_button', $text);
122f3f0262cSandi    }else{
123b081e262SAdrian Lang        $text = preg_replace($regexp,'',$text);
124f3f0262cSandi    }
12535dae8b0SBen Coburn
126f3f0262cSandi    return $text;
127f3f0262cSandi}
128f3f0262cSandi
129f3f0262cSandi/**
130d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1316b13307fSandi *
1326b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1336b13307fSandi */
1346b13307fSandifunction html_topbtn(){
1356b13307fSandi    global $lang;
1366b13307fSandi
1376b13307fSandi    $ret  = '';
13811ea018fSAndreas 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>';
139df7b6005Sandi
1406b13307fSandi    return $ret;
1416b13307fSandi}
1426b13307fSandi
1436b13307fSandi/**
144d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
14535dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
14615fae107Sandi *
14715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
148f3f0262cSandi */
149d822118cSAdrian Langfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
150f3f0262cSandi    global $conf;
151f3f0262cSandi    global $lang;
152f3f0262cSandi
153f3f0262cSandi    $label = $lang['btn_'.$name];
154f3f0262cSandi
155f3f0262cSandi    $ret = '';
15635dae8b0SBen Coburn    $tip = '';
157f3f0262cSandi
15849c713a3Sandi    //filter id (without urlencoding)
15949c713a3Sandi    $id = idfilter($id,false);
160f3f0262cSandi
161f3f0262cSandi    //make nice URLs even for buttons
1626c7843b5Sandi    if($conf['userewrite'] == 2){
1636c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1646c7843b5Sandi    }elseif($conf['userewrite']){
1656c7843b5Sandi        $script = DOKU_BASE.$id;
1666c7843b5Sandi    }else{
1678b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
168f3f0262cSandi        $params['id'] = $id;
169f3f0262cSandi    }
170f3f0262cSandi
171b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
172f3f0262cSandi
17306a4bf8fSAndreas Gohr    if(is_array($params)){
174f3f0262cSandi        reset($params);
175f3f0262cSandi        while (list($key, $val) = each($params)) {
176f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
177f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
178f3f0262cSandi        }
17906a4bf8fSAndreas Gohr    }
180f3f0262cSandi
18135dae8b0SBen Coburn    if ($tooltip!='') {
18235dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
18311ea018fSAndreas Gohr    }else{
18411ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
18511ea018fSAndreas Gohr    }
18611ea018fSAndreas Gohr
187d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
18811ea018fSAndreas Gohr    if($akey){
18907493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
19087cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
19135dae8b0SBen Coburn    }
19235dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
193f3f0262cSandi    $ret .= '/>';
1944beabca9SAnika Henke    $ret .= '</div></form>';
195f3f0262cSandi
196f3f0262cSandi    return $ret;
197f3f0262cSandi}
198f3f0262cSandi
199f3f0262cSandi/**
20015fae107Sandi * show a wiki page
20115fae107Sandi *
20215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
20315fae107Sandi */
2046bbae538Sandifunction html_show($txt=''){
205f3f0262cSandi    global $ID;
206f3f0262cSandi    global $REV;
207f3f0262cSandi    global $HIGH;
208b8595a66SAndreas Gohr    global $INFO;
209f3f0262cSandi    //disable section editing for old revisions or in preview
2105400331dSandi    if($txt || $REV){
2116bbae538Sandi        $secedit = false;
2126bbae538Sandi    }else{
2136bbae538Sandi        $secedit = true;
214f3f0262cSandi    }
215f3f0262cSandi
2166bbae538Sandi    if ($txt){
217f3f0262cSandi        //PreviewHeader
218b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
219b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
220b8595a66SAndreas Gohr        echo '<div class="preview">';
221b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
222b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
223b8595a66SAndreas Gohr        echo $html;
224b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
225b8595a66SAndreas Gohr        echo '</div>';
2266bbae538Sandi
227f3f0262cSandi    }else{
228c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
229c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2306bbae538Sandi        $html = html_secedit($html,$secedit);
231b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
232b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
233b8595a66SAndreas Gohr        echo $html;
234f3f0262cSandi    }
235f3f0262cSandi}
236f3f0262cSandi
237f3f0262cSandi/**
238ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
239ee4c4a1bSAndreas Gohr *
240ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
241ee4c4a1bSAndreas Gohr */
242ee4c4a1bSAndreas Gohrfunction html_draft(){
243ee4c4a1bSAndreas Gohr    global $INFO;
244ee4c4a1bSAndreas Gohr    global $ID;
245ee4c4a1bSAndreas Gohr    global $lang;
246ee4c4a1bSAndreas Gohr    global $conf;
247ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
248ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
249ee4c4a1bSAndreas Gohr
250fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
251e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
252fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
253fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
254fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
255fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
256f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
257fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
258fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
259fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
260fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
261fdb8d77bSTom N Harris    html_form('draft', $form);
262ee4c4a1bSAndreas Gohr}
263ee4c4a1bSAndreas Gohr
264ee4c4a1bSAndreas Gohr/**
265f3f0262cSandi * Highlights searchqueries in HTML code
26615fae107Sandi *
26715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2687209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
269f3f0262cSandi */
270546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
271808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
272808551e3SAndreas Gohr    $regex = join('|',array_map('preg_quote_cb',$phrases));
27360c15d7dSAndreas Gohr
27460c15d7dSAndreas Gohr    if ($regex === '') return $html;
2751db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
276f3f0262cSandi    return $html;
277f3f0262cSandi}
278f3f0262cSandi
279f3f0262cSandi/**
2807209be23SAndreas Gohr * Callback used by html_hilight()
2817209be23SAndreas Gohr *
2827209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2837209be23SAndreas Gohr */
2847209be23SAndreas Gohrfunction html_hilight_callback($m) {
2857209be23SAndreas Gohr    $hlight = unslash($m[0]);
2867209be23SAndreas Gohr    if ( !isset($m[2])) {
287688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
2887209be23SAndreas Gohr    }
2897209be23SAndreas Gohr    return $hlight;
2907209be23SAndreas Gohr}
2917209be23SAndreas Gohr
2927209be23SAndreas Gohr/**
29315fae107Sandi * Run a search and display the result
29415fae107Sandi *
29515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
296f3f0262cSandi */
297f3f0262cSandifunction html_search(){
298ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
299506fa893SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
300f3f0262cSandi    global $conf;
301f3f0262cSandi    global $QUERY;
302f3f0262cSandi    global $ID;
303f3f0262cSandi    global $lang;
304f3f0262cSandi
305c112d578Sandi    print p_locale_xhtml('searchpage');
306f3f0262cSandi    flush();
307f3f0262cSandi
308d0ab54f6SMichael Klier chi@chimeric.de    //check if search is restricted to namespace
309b42bcfe7Sdaniel.lindgren    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
310d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($match[1]);
311d0ab54f6SMichael Klier chi@chimeric.de    } else {
312d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($QUERY);
313d0ab54f6SMichael Klier chi@chimeric.de    }
314d0ab54f6SMichael Klier chi@chimeric.de
3154d9ff3d5Sandi    //show progressbar
316e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
317e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
318e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
319e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
320e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3219edac8a8SAndreas Gohr    flush();
3224d9ff3d5Sandi
323f3f0262cSandi    //do quick pagesearch
324f3f0262cSandi    $data = array();
325d0ab54f6SMichael Klier chi@chimeric.de
326865c2687SKazutaka Miyasaka    if($id) $data = ft_pageLookup($id);
327f3f0262cSandi    if(count($data)){
328f3f0262cSandi        print '<div class="search_quickresult">';
329746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3304f732f0eSAnika Henke        print '<ul class="search_quickhits">';
331140c93f3SAnika Henke        foreach($data as $id){
3324f732f0eSAnika Henke            print '<li> ';
333bd2f6c2fSAndreas Gohr            $ns = getNS($id);
334bd2f6c2fSAndreas Gohr            if($ns){
335bd2f6c2fSAndreas Gohr                $name = shorten(noNS($id), ' ('.$ns.')',30);
336bd2f6c2fSAndreas Gohr            }else{
337bd2f6c2fSAndreas Gohr                $name = $id;
338bd2f6c2fSAndreas Gohr            }
339bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3404f732f0eSAnika Henke            print '</li> ';
341f3f0262cSandi        }
342140c93f3SAnika Henke        print '</ul> ';
343f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
344f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
345f3f0262cSandi        print '</div>';
346f3f0262cSandi    }
347f3f0262cSandi    flush();
348f3f0262cSandi
349f3f0262cSandi    //do fulltext search
35060c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
351f3f0262cSandi    if(count($data)){
352506fa893SAndreas Gohr        $num = 1;
353506fa893SAndreas Gohr        foreach($data as $id => $cnt){
354f3f0262cSandi            print '<div class="search_result">';
355db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
356865c2687SKazutaka Miyasaka            if($cnt !== 0){
357506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
358506fa893SAndreas Gohr                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
35960c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
360506fa893SAndreas Gohr                }
361865c2687SKazutaka Miyasaka                $num++;
362865c2687SKazutaka Miyasaka            }
363f3f0262cSandi            print '</div>';
364506fa893SAndreas Gohr            flush();
365f3f0262cSandi        }
366f3f0262cSandi    }else{
367820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
368f3f0262cSandi    }
3694d9ff3d5Sandi
3704d9ff3d5Sandi    //hide progressbar
371e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
372e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
373e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3749edac8a8SAndreas Gohr    flush();
375f3f0262cSandi}
376f3f0262cSandi
37715fae107Sandi/**
37815fae107Sandi * Display error on locked pages
37915fae107Sandi *
38015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38115fae107Sandi */
382ee20e7d1Sandifunction html_locked(){
383f3f0262cSandi    global $ID;
384f3f0262cSandi    global $conf;
385f3f0262cSandi    global $lang;
38688f522e9Sandi    global $INFO;
387f3f0262cSandi
388c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
389f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
390f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
391f3f0262cSandi
392c112d578Sandi    print p_locale_xhtml('locked');
393f3f0262cSandi    print '<ul>';
3946d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
3950c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
396f3f0262cSandi    print '</ul>';
397f3f0262cSandi}
398f3f0262cSandi
39915fae107Sandi/**
40015fae107Sandi * list old revisions
40115fae107Sandi *
40215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40371726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
40415fae107Sandi */
40571726d78SBen Coburnfunction html_revisions($first=0){
406f3f0262cSandi    global $ID;
407f3f0262cSandi    global $INFO;
408f3f0262cSandi    global $conf;
409f3f0262cSandi    global $lang;
41071726d78SBen Coburn    /* we need to get one additionally log entry to be able to
41171726d78SBen Coburn     * decide if this is the last page or is there another one.
41271726d78SBen Coburn     * see html_recent()
41371726d78SBen Coburn     */
41471726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
41571726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
41671726d78SBen Coburn        $first=0;
41771726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
41871726d78SBen Coburn    }
41971726d78SBen Coburn    $hasNext = false;
42071726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
42171726d78SBen Coburn        $hasNext = true;
42271726d78SBen Coburn        array_pop($revisions); // remove extra log entry
42371726d78SBen Coburn    }
42471726d78SBen Coburn
425f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
426f3f0262cSandi
427c112d578Sandi    print p_locale_xhtml('revisions');
42837a1dc12Smichael
429e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
43037a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
43171726d78SBen Coburn    if($INFO['exists'] && $first==0){
43237a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
43337a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
43437a1dc12Smichael        else
43537a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
43637a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
43737a1dc12Smichael        $form->addElement(form_makeTag('input', array(
43837a1dc12Smichael                        'type' => 'checkbox',
43937a1dc12Smichael                        'name' => 'rev2[]',
44037a1dc12Smichael                        'value' => 'current')));
441f9b2fe70Sandi
44237a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
44337a1dc12Smichael        $form->addElement($date);
44437a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
445f9b2fe70Sandi
44637a1dc12Smichael        $form->addElement(form_makeTag('img', array(
44737a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
44837a1dc12Smichael                        'width' => '15',
44937a1dc12Smichael                        'height' => '11',
45037a1dc12Smichael                        'alt'    => '')));
451cffcc403Sandi
45237a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
45337a1dc12Smichael                        'class' => 'wikilink1',
45437a1dc12Smichael                        'href'  => wl($ID))));
45537a1dc12Smichael        $form->addElement($ID);
45637a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
457652610a2Sandi
45837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
45937a1dc12Smichael        $form->addElement(' &ndash; ');
46037a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
46137a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
462652610a2Sandi
46337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
46437a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
46537a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
46637a1dc12Smichael
46737a1dc12Smichael        $form->addElement('('.$lang['current'].')');
46837a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
46937a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
470f3f0262cSandi    }
471f3f0262cSandi
472f3f0262cSandi    foreach($revisions as $rev){
473f2263577SAndreas Gohr        $date   = dformat($rev);
474fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
475103c256aSChris Smith        $exists = page_exists($ID,$rev);
476652610a2Sandi
47737a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
47837a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
47937a1dc12Smichael        else
48037a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
48137a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
48277707b04SAndreas Gohr        if($exists){
48337a1dc12Smichael            $form->addElement(form_makeTag('input', array(
48437a1dc12Smichael                            'type' => 'checkbox',
48537a1dc12Smichael                            'name' => 'rev2[]',
48637a1dc12Smichael                            'value' => $rev)));
48777707b04SAndreas Gohr        }else{
48837a1dc12Smichael            $form->addElement(form_makeTag('img', array(
48937a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
49037a1dc12Smichael                            'width' => 14,
49137a1dc12Smichael                            'height' => 11,
49237a1dc12Smichael                            'alt' => '')));
49341396b71SAndreas Gohr        }
494f9b2fe70Sandi
49537a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
49637a1dc12Smichael        $form->addElement($date);
49737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
49837a1dc12Smichael
49937a1dc12Smichael        if($exists){
50037a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
50137a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50237a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
50337a1dc12Smichael                            'width'  => 15,
50437a1dc12Smichael                            'height' => 11,
50537a1dc12Smichael                            'title'  => $lang['diff'],
50637a1dc12Smichael                            'alt'    => $lang['diff'])));
50737a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
50837a1dc12Smichael
50937a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
51037a1dc12Smichael            $form->addElement($ID);
51137a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
51237a1dc12Smichael        }else{
51337a1dc12Smichael            $form->addElement(form_makeTag('img', array(
51437a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
51537a1dc12Smichael                            'width' => '15',
51637a1dc12Smichael                            'height' => '11',
51737a1dc12Smichael                            'alt'   => '')));
51837a1dc12Smichael            $form->addElement($ID);
51937a1dc12Smichael        }
52037a1dc12Smichael
52137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
52237a1dc12Smichael        $form->addElement(' &ndash; ');
52337a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
52437a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
52537a1dc12Smichael
52637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
52788f522e9Sandi        if($info['user']){
52837a1dc12Smichael            $form->addElement(editorinfo($info['user']));
529433efb25SAndreas Gohr            if(auth_ismanager()){
530433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
531433efb25SAndreas Gohr            }
53288f522e9Sandi        }else{
53337a1dc12Smichael            $form->addElement($info['ip']);
53488f522e9Sandi        }
53537a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
536652610a2Sandi
53737a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
53837a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
539f3f0262cSandi    }
54037a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
54137a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
54237a1dc12Smichael    html_form('revisions', $form);
54371726d78SBen Coburn
54471726d78SBen Coburn    print '<div class="pagenav">';
54571726d78SBen Coburn    $last = $first + $conf['recent'];
54671726d78SBen Coburn    if ($first > 0) {
54771726d78SBen Coburn        $first -= $conf['recent'];
54871726d78SBen Coburn        if ($first < 0) $first = 0;
54971726d78SBen Coburn        print '<div class="pagenav-prev">';
550eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
55171726d78SBen Coburn        print '</div>';
55271726d78SBen Coburn    }
55371726d78SBen Coburn    if ($hasNext) {
55471726d78SBen Coburn        print '<div class="pagenav-next">';
555eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
55671726d78SBen Coburn        print '</div>';
55771726d78SBen Coburn    }
55871726d78SBen Coburn    print '</div>';
55971726d78SBen Coburn
560f3f0262cSandi}
561f3f0262cSandi
56215fae107Sandi/**
56315fae107Sandi * display recent changes
56415fae107Sandi *
56515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5665749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
56771726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
56815fae107Sandi */
569a39955b0Smatthiasgrimmfunction html_recent($first=0){
570f3f0262cSandi    global $conf;
571cffcc403Sandi    global $lang;
572dbb00abcSEsther Brunner    global $ID;
5735749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5745749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5755749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5765749f1ceSmatthiasgrimm     */
577b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5785749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5795749f1ceSmatthiasgrimm        $first=0;
58071726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5815749f1ceSmatthiasgrimm    }
58271726d78SBen Coburn    $hasNext = false;
58371726d78SBen Coburn    if (count($recents)>$conf['recent']) {
58471726d78SBen Coburn        $hasNext = true;
58571726d78SBen Coburn        array_pop($recents); // remove extra log entry
58671726d78SBen Coburn    }
587f3f0262cSandi
588c112d578Sandi    print p_locale_xhtml('recent');
589e83cef14SGina Haeussge
590e83cef14SGina Haeussge    if (getNS($ID) != '')
5919e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
592e83cef14SGina Haeussge
593e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
594abdcc39fSmichael    $form->addHidden('sectok', null);
595abdcc39fSmichael    $form->addHidden('do', 'recent');
596abdcc39fSmichael    $form->addHidden('id', $ID);
597abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
598a39955b0Smatthiasgrimm
599d437bcc4SAndreas Gohr    foreach($recents as $recent){
600f2263577SAndreas Gohr        $date = dformat($recent['date']);
601abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
602abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
603abdcc39fSmichael        else
604abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
605cffcc403Sandi
606abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
607f9b2fe70Sandi
608abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
609abdcc39fSmichael        $form->addElement($date);
610abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
611cffcc403Sandi
612cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
613abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
614abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
615abdcc39fSmichael                        'width' => 15,
616abdcc39fSmichael                        'height'=> 11,
617abdcc39fSmichael                        'title' => $lang['diff'],
618abdcc39fSmichael                        'alt'   => $lang['diff']
619abdcc39fSmichael                        )));
620abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
621cffcc403Sandi
622cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
623abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
624abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
625abdcc39fSmichael                        'width' => 12,
626abdcc39fSmichael                        'height'=> 14,
627abdcc39fSmichael                        'title' => $lang['btn_revs'],
628abdcc39fSmichael                        'alt'   => $lang['btn_revs']
629abdcc39fSmichael                        )));
630abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
631b6912aeaSAndreas Gohr
632db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
633abdcc39fSmichael
634abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
635abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
636abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
637abdcc39fSmichael
638abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
639d437bcc4SAndreas Gohr        if($recent['user']){
640abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
641433efb25SAndreas Gohr            if(auth_ismanager()){
642433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
643433efb25SAndreas Gohr            }
64488f522e9Sandi        }else{
645abdcc39fSmichael            $form->addElement($recent['ip']);
64688f522e9Sandi        }
647abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
648cffcc403Sandi
649abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
650abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
651f3f0262cSandi    }
652abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
653a39955b0Smatthiasgrimm
654abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6555749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
656a39955b0Smatthiasgrimm    if ($first > 0) {
657a39955b0Smatthiasgrimm        $first -= $conf['recent'];
658a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
659abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
660abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
661abdcc39fSmichael                    'type'  => 'submit',
662abdcc39fSmichael                    'name'  => 'first['.$first.']',
663cddd152cSmichael                    'value' => $lang['btn_newer'],
664cddd152cSmichael                    'accesskey' => 'n',
665f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
66618d107cbSMichael Klier                    'class' => 'button'
667abdcc39fSmichael                    )));
668abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
669a39955b0Smatthiasgrimm    }
67071726d78SBen Coburn    if ($hasNext) {
671abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
672abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
673abdcc39fSmichael                        'type'  => 'submit',
674abdcc39fSmichael                        'name'  => 'first['.$last.']',
675cddd152cSmichael                        'value' => $lang['btn_older'],
676cddd152cSmichael                        'accesskey' => 'p',
677f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
67818d107cbSMichael Klier                        'class' => 'button'
679abdcc39fSmichael                        )));
680abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
681a39955b0Smatthiasgrimm    }
682abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
683abdcc39fSmichael    html_form('recent', $form);
684f3f0262cSandi}
685f3f0262cSandi
68615fae107Sandi/**
68715fae107Sandi * Display page index
68815fae107Sandi *
68915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
69015fae107Sandi */
691f3f0262cSandifunction html_index($ns){
692ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
693f3f0262cSandi    global $conf;
694f3f0262cSandi    global $ID;
695f3f0262cSandi    $dir = $conf['datadir'];
696f3f0262cSandi    $ns  = cleanID($ns);
69730f1737dSandi    #fixme use appropriate function
698f3f0262cSandi    if(empty($ns)){
699f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
700f3f0262cSandi        if($ns == '.') $ns ='';
701f3f0262cSandi    }
70288d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
703f3f0262cSandi
704a06884abSAndreas Gohr    echo p_locale_xhtml('index');
705a06884abSAndreas Gohr    echo '<div id="index__tree">';
706f3f0262cSandi
707f3f0262cSandi    $data = array();
708f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
709a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
710a06884abSAndreas Gohr
711a06884abSAndreas Gohr    echo '</div>';
712f3f0262cSandi}
713f3f0262cSandi
714f3f0262cSandi/**
71515fae107Sandi * Index item formatter
71615fae107Sandi *
717f3f0262cSandi * User function for html_buildlist()
71815fae107Sandi *
71915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
720f3f0262cSandi */
721f3f0262cSandifunction html_list_index($item){
722d98d4540SBen Coburn    global $ID;
723f3f0262cSandi    $ret = '';
724f3f0262cSandi    $base = ':'.$item['id'];
725f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
726f3f0262cSandi    if($item['type']=='d'){
7274a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
728f3f0262cSandi        $ret .= $base;
729ed7ecb79SAnika Henke        $ret .= '</strong></a>';
730f3f0262cSandi    }else{
731f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
732f3f0262cSandi    }
733f3f0262cSandi    return $ret;
734f3f0262cSandi}
735f3f0262cSandi
736f3f0262cSandi/**
737cb70c441Sandi * Index List item
738cb70c441Sandi *
739cb70c441Sandi * This user function is used in html_build_lidt to build the
740cb70c441Sandi * <li> tags for namespaces when displaying the page index
741cb70c441Sandi * it gives different classes to opened or closed "folders"
742cb70c441Sandi *
743cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
744cb70c441Sandi */
745cb70c441Sandifunction html_li_index($item){
746cb70c441Sandi    if($item['type'] == "f"){
747cb70c441Sandi        return '<li class="level'.$item['level'].'">';
748cb70c441Sandi    }elseif($item['open']){
749cb70c441Sandi        return '<li class="open">';
750cb70c441Sandi    }else{
751cb70c441Sandi        return '<li class="closed">';
752cb70c441Sandi    }
753cb70c441Sandi}
754cb70c441Sandi
755cb70c441Sandi/**
756cb70c441Sandi * Default List item
757cb70c441Sandi *
758cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
759cb70c441Sandi */
760cb70c441Sandifunction html_li_default($item){
761cb70c441Sandi    return '<li class="level'.$item['level'].'">';
762cb70c441Sandi}
763cb70c441Sandi
764cb70c441Sandi/**
76515fae107Sandi * Build an unordered list
76615fae107Sandi *
767f3f0262cSandi * Build an unordered list from the given $data array
768f3f0262cSandi * Each item in the array has to have a 'level' property
769f3f0262cSandi * the item itself gets printed by the given $func user
770cb70c441Sandi * function. The second and optional function is used to
771cb70c441Sandi * print the <li> tag. Both user function need to accept
772cb70c441Sandi * a single item.
77315fae107Sandi *
774c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
775c5a8fd96SAndreas Gohr * a member of an object.
776c5a8fd96SAndreas Gohr *
77715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
778f3f0262cSandi */
779cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
780f3f0262cSandi    $level = 0;
781f3f0262cSandi    $opens = 0;
782f3f0262cSandi    $ret   = '';
783f3f0262cSandi
784f3f0262cSandi    foreach ($data as $item){
785f3f0262cSandi
786f3f0262cSandi        if( $item['level'] > $level ){
787f3f0262cSandi            //open new list
788df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
789df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
790f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
791df52d0feSandi            }
792f3f0262cSandi        }elseif( $item['level'] < $level ){
793f3f0262cSandi            //close last item
794f3f0262cSandi            $ret .= "</li>\n";
795f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
796f3f0262cSandi                //close higher lists
797f3f0262cSandi                $ret .= "</ul>\n</li>\n";
798f3f0262cSandi            }
799f3f0262cSandi        }else{
800f3f0262cSandi            //close last item
801f3f0262cSandi            $ret .= "</li>\n";
802f3f0262cSandi        }
803f3f0262cSandi
804f3f0262cSandi        //remember current level
805f3f0262cSandi        $level = $item['level'];
806f3f0262cSandi
807f3f0262cSandi        //print item
80834dbe711Schris        $ret .= call_user_func($lifunc,$item);
8090c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
81034dbe711Schris
81134dbe711Schris        $ret .= call_user_func($func,$item);
8120c6b58a8SAndreas Gohr        $ret .= '</div>';
813f3f0262cSandi    }
814f3f0262cSandi
815f3f0262cSandi    //close remaining items and lists
816f3f0262cSandi    for ($i=0; $i < $level; $i++){
817f3f0262cSandi        $ret .= "</li></ul>\n";
818f3f0262cSandi    }
819f3f0262cSandi
820f3f0262cSandi    return $ret;
821f3f0262cSandi}
822f3f0262cSandi
82315fae107Sandi/**
82415fae107Sandi * display backlinks
82515fae107Sandi *
82615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
82711df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
82815fae107Sandi */
829f3f0262cSandifunction html_backlinks(){
83054f4c056SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
831f3f0262cSandi    global $ID;
832f3f0262cSandi    global $conf;
83311df47ecSMichael Klier    global $lang;
834f3f0262cSandi
835c112d578Sandi    print p_locale_xhtml('backlinks');
836f3f0262cSandi
83754f4c056SAndreas Gohr    $data = ft_backlinks($ID);
838f3f0262cSandi
83911df47ecSMichael Klier    if(!empty($data)) {
840f3f0262cSandi        print '<ul class="idx">';
84154f4c056SAndreas Gohr        foreach($data as $blink){
8420c6b58a8SAndreas Gohr            print '<li><div class="li">';
843db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8440c6b58a8SAndreas Gohr            print '</div></li>';
845f3f0262cSandi        }
846f3f0262cSandi        print '</ul>';
84711df47ecSMichael Klier    } else {
84811df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
84911df47ecSMichael Klier    }
850f3f0262cSandi}
851f3f0262cSandi
85215fae107Sandi/**
85315fae107Sandi * show diff
85415fae107Sandi *
85515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
85615fae107Sandi */
857f3f0262cSandifunction html_diff($text='',$intro=true){
858ed7b5f09Sandi    require_once(DOKU_INC.'inc/DifferenceEngine.php');
859f3f0262cSandi    global $ID;
860f3f0262cSandi    global $REV;
861f3f0262cSandi    global $lang;
862f3f0262cSandi    global $conf;
863e1bd90ffSAndreas Gohr
86477707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
86577707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
86677707b04SAndreas Gohr    // array in rev2.
86777707b04SAndreas Gohr    $rev1 = $REV;
8687b3f8b16SAndreas Gohr
86977707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
87077707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
87177707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
87254041c77SAndreas Gohr
87354041c77SAndreas Gohr        if(!$rev1){
87454041c77SAndreas Gohr            $rev1 = $rev2;
87554041c77SAndreas Gohr            unset($rev2);
87654041c77SAndreas Gohr        }
877f3f0262cSandi    }else{
87877707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
8794d58bd99Sandi    }
8804d58bd99Sandi
88177707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
88277707b04SAndreas Gohr        $l_rev   = '';
88377707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
88477707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
885f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
88677707b04SAndreas Gohr            $lang['current'];
88777707b04SAndreas Gohr
88877707b04SAndreas Gohr        $r_rev   = '';
88977707b04SAndreas Gohr        $r_text  = cleanText($text);
89077707b04SAndreas Gohr        $r_head  = $lang['yours'];
891e1bd90ffSAndreas Gohr    }else{
89277707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
89354041c77SAndreas Gohr            // make sure order is correct (older on the left)
89477707b04SAndreas Gohr            if($rev1 < $rev2){
89577707b04SAndreas Gohr                $l_rev = $rev1;
89677707b04SAndreas Gohr                $r_rev = $rev2;
89777707b04SAndreas Gohr            }else{
89877707b04SAndreas Gohr                $l_rev = $rev2;
89977707b04SAndreas Gohr                $r_rev = $rev1;
900e1bd90ffSAndreas Gohr            }
90177707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
90277707b04SAndreas Gohr            $r_rev = '';
90377707b04SAndreas Gohr            $l_rev = $rev1;
90477707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
90577707b04SAndreas Gohr            $r_rev = '';
90677707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
90777707b04SAndreas Gohr            $l_rev = $revs[0];
9086f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
90977707b04SAndreas Gohr        }
91077707b04SAndreas Gohr
9117b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9127b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9137b3f8b16SAndreas Gohr            $l_text = '';
9147b3f8b16SAndreas Gohr        }else{
91577707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9167b3f8b16SAndreas Gohr        }
91777707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
91877707b04SAndreas Gohr
9197b3f8b16SAndreas Gohr        if(!$l_rev){
9207b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9217b3f8b16SAndreas Gohr        }else{
922e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
923db959ae3SAndreas Gohr            if($l_info['user']){
924db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
925e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
926db959ae3SAndreas Gohr            } else {
927db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
928db959ae3SAndreas Gohr            }
929e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
930e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
931e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
932e5e61eb0SAnika Henke
93377707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
934f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
935e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9367b3f8b16SAndreas Gohr        }
93777707b04SAndreas Gohr
93877707b04SAndreas Gohr        if($r_rev){
939e5e61eb0SAnika Henke            $r_info   = getRevisionInfo($ID,$r_rev,true);
940db959ae3SAndreas Gohr            if($r_info['user']){
941db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
942e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
943db959ae3SAndreas Gohr            } else {
944db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
945db959ae3SAndreas Gohr            }
946e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
947e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
948e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
949e5e61eb0SAnika Henke
95077707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
951f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
952e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9537b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
954e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
955db959ae3SAndreas Gohr            if($_info['user']){
956db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
957e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
958db959ae3SAndreas Gohr            } else {
959db959ae3SAndreas Gohr                $_user = $_info['ip'];
960db959ae3SAndreas Gohr            }
961e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
962e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
963e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
964e5e61eb0SAnika Henke
96577707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
966f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
967658b1aa0SAnika Henke            '('.$lang['current'].')'.
968e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9697b3f8b16SAndreas Gohr        }else{
970658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
971f3f0262cSandi        }
97277707b04SAndreas Gohr    }
97377707b04SAndreas Gohr
97477707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
97577707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
97677707b04SAndreas Gohr
977f3f0262cSandi    $tdf = new TableDiffFormatter();
978c112d578Sandi    if($intro) print p_locale_xhtml('diff');
979f3f0262cSandi    ?>
980daf4ca4eSAnika Henke    <table class="diff">
981f3f0262cSandi    <tr>
982e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
98377707b04SAndreas Gohr    <?php echo $l_head?>
984daf4ca4eSAnika Henke    </th>
985e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
98677707b04SAndreas Gohr    <?php echo $r_head?>
987daf4ca4eSAnika Henke    </th>
988f3f0262cSandi    </tr>
9894da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
990f3f0262cSandi    </table>
9914da078a3Smatthiasgrimm    <?php
992f3f0262cSandi}
993f3f0262cSandi
99415fae107Sandi/**
99515fae107Sandi * show warning on conflict detection
99615fae107Sandi *
99715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
99815fae107Sandi */
999f3f0262cSandifunction html_conflict($text,$summary){
1000f3f0262cSandi    global $ID;
1001f3f0262cSandi    global $lang;
1002f3f0262cSandi
1003c112d578Sandi    print p_locale_xhtml('conflict');
1004e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1005fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1006fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1007fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1008fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1009fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1010fdb8d77bSTom N Harris    html_form('conflict', $form);
1011fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1012f3f0262cSandi}
1013f3f0262cSandi
1014f3f0262cSandi/**
101515fae107Sandi * Prints the global message array
101615fae107Sandi *
101715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1018f3f0262cSandi */
1019f3f0262cSandifunction html_msgarea(){
1020f3f0262cSandi    global $MSG;
1021f3f0262cSandi    if(!isset($MSG)) return;
1022f3f0262cSandi
10234af9f0d4SAndreas Gohr    $shown = array();
1024f3f0262cSandi    foreach($MSG as $msg){
10254af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10264af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1027f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1028f3f0262cSandi        print $msg['msg'];
1029f3f0262cSandi        print '</div>';
10304af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1031f3f0262cSandi    }
1032f3f0262cSandi}
1033f3f0262cSandi
1034f3f0262cSandi/**
1035f3f0262cSandi * Prints the registration form
103615fae107Sandi *
103715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1038f3f0262cSandi */
1039f3f0262cSandifunction html_register(){
1040f3f0262cSandi    global $lang;
1041cab2716aSmatthias.grimm    global $conf;
1042f3f0262cSandi    global $ID;
1043f3f0262cSandi
1044c112d578Sandi    print p_locale_xhtml('register');
1045fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1046e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1047fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1048fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1049fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1050fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1051cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1052fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1053fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1054cab2716aSmatthias.grimm    }
1055fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1056fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1057fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1058fdb8d77bSTom N Harris    $form->endFieldset();
1059fdb8d77bSTom N Harris    html_form('register', $form);
1060cab2716aSmatthias.grimm
1061fdb8d77bSTom N Harris    print '</div>'.NL;
1062f3f0262cSandi}
1063f3f0262cSandi
1064f3f0262cSandi/**
10658b06d178Schris * Print the update profile form
10668b06d178Schris *
10678b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10688b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10698b06d178Schris */
10708b06d178Schrisfunction html_updateprofile(){
10718b06d178Schris    global $lang;
10728b06d178Schris    global $conf;
10738b06d178Schris    global $ID;
10748b06d178Schris    global $INFO;
107582fd59b6SAndreas Gohr    global $auth;
10768b06d178Schris
10778b06d178Schris    print p_locale_xhtml('updateprofile');
10788b06d178Schris
10798b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10808b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1081fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1082e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1083fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1084fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1085fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1086fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1087fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1088fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1089fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
109039ba8890SAndreas Gohr    $attr = array('size'=>'50');
109139ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1092fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1093fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1094fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1095fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1096fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1097fdb8d77bSTom N Harris    }
1098fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1099fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1100fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1101fdb8d77bSTom N Harris    }
1102fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1103fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1104fdb8d77bSTom N Harris    $form->endFieldset();
1105fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1106fdb8d77bSTom N Harris    print '</div>'.NL;
11078b06d178Schris}
11088b06d178Schris
11098b06d178Schris/**
11107c4635c4SAdrian Lang * Preprocess edit form data
111115fae107Sandi *
1112016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
111315fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1114f3f0262cSandi */
1115f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1116f3f0262cSandi    global $ID;
1117f3f0262cSandi    global $REV;
1118f3f0262cSandi    global $DATE;
1119f3f0262cSandi    global $RANGE;
1120f3f0262cSandi    global $PRE;
1121f3f0262cSandi    global $SUF;
1122f3f0262cSandi    global $INFO;
1123f3f0262cSandi    global $SUM;
1124f3f0262cSandi    global $lang;
1125f3f0262cSandi    global $conf;
1126f3f0262cSandi
1127f3f0262cSandi    //set summary default
1128f3f0262cSandi    if(!$SUM){
1129f3f0262cSandi        if($REV){
1130f3f0262cSandi            $SUM = $lang['restored'];
1131f3f0262cSandi        }elseif(!$INFO['exists']){
1132f3f0262cSandi            $SUM = $lang['created'];
1133f3f0262cSandi        }
1134f3f0262cSandi    }
1135f3f0262cSandi
1136f3f0262cSandi    //no text? Load it!
1137f3f0262cSandi    if(!isset($text)){
1138f3f0262cSandi        $pr = false; //no preview mode
11397146cee2SAndreas Gohr        if($INFO['exists']){
1140f3f0262cSandi            if($RANGE){
1141f3f0262cSandi                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1142f3f0262cSandi            }else{
1143f3f0262cSandi                $text = rawWiki($ID,$REV);
1144f3f0262cSandi            }
11458fe3bb00STom N Harris            $check = md5($text);
11468fe3bb00STom N Harris            $mod = false;
1147f3f0262cSandi        }else{
11487146cee2SAndreas Gohr            //try to load a pagetemplate
1149b7d5a5f0SAndreas Gohr            $data = array($ID);
1150016b6153SAndreas Gohr            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
11518fe3bb00STom N Harris            $check = md5('');
11528fe3bb00STom N Harris            $mod = $text!=='';
11537146cee2SAndreas Gohr        }
11547146cee2SAndreas Gohr    }else{
1155f3f0262cSandi        $pr = true; //preview mode
11568fe3bb00STom N Harris        if (isset($_REQUEST['changecheck'])) {
11578fe3bb00STom N Harris            $check = $_REQUEST['changecheck'];
11588fe3bb00STom N Harris            $mod = md5($text)!==$check;
11598fe3bb00STom N Harris        } else {
11608fe3bb00STom N Harris            // Why? Assume default text is unmodified.
11618fe3bb00STom N Harris            $check = md5($text);
11628fe3bb00STom N Harris            $mod = false;
11638fe3bb00STom N Harris        }
1164f3f0262cSandi    }
1165f3f0262cSandi
116627eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
1167f3f0262cSandi    if($wr){
1168c112d578Sandi        if ($REV) print p_locale_xhtml('editrev');
1169c112d578Sandi        print p_locale_xhtml($include);
1170f3f0262cSandi    }else{
1171409d7af7SAndreas Gohr        // check pseudo action 'source'
1172409d7af7SAndreas Gohr        if(!actionOK('source')){
1173409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1174409d7af7SAndreas Gohr            return;
1175409d7af7SAndreas Gohr        }
1176c112d578Sandi        print p_locale_xhtml('read');
1177f3f0262cSandi    }
1178f3f0262cSandi    if(!$DATE) $DATE = $INFO['lastmod'];
11797c4635c4SAdrian Lang
11807c4635c4SAdrian Lang    $data = compact('wr', 'text', 'mod', 'check');
11817c4635c4SAdrian Lang    trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
11827c4635c4SAdrian Lang}
11837c4635c4SAdrian Lang
11847c4635c4SAdrian Lang/**
11857c4635c4SAdrian Lang * Display the default edit form
11867c4635c4SAdrian Lang *
11877c4635c4SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
11887c4635c4SAdrian Lang *
11897c4635c4SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
11907c4635c4SAdrian Lang */
11917c4635c4SAdrian Langfunction html_edit_form($param) {
11927c4635c4SAdrian Lang    extract($param);
11937c4635c4SAdrian Lang    global $conf;
11947c4635c4SAdrian Lang    global $license;
11957c4635c4SAdrian Lang    global $lang;
11967c4635c4SAdrian Lang    global $REV;
11977c4635c4SAdrian Lang    global $DATE;
11987c4635c4SAdrian Lang    global $PRE;
11997c4635c4SAdrian Lang    global $SUF;
12007c4635c4SAdrian Lang    global $INFO;
12017c4635c4SAdrian Lang    global $SUM;
12027c4635c4SAdrian Lang    global $ID;
1203f3f0262cSandi    ?>
12047c4635c4SAdrian Lang            <?php if($wr){?>
12057c4635c4SAdrian Lang                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
12067c4635c4SAdrian Lang                    <?php /* sets changed to true when previewed */?>
12077c4635c4SAdrian Lang                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
12087c4635c4SAdrian Lang                //--><!]]></script>
12097c4635c4SAdrian Lang            <?php } ?>
121063afe2a6SAnika Henke        <div style="width:99%;">
121142c7abd6SAndreas Gohr
121263afe2a6SAnika Henke        <div class="toolbar">
1213f2263577SAndreas Gohr        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1214fdb8d77bSTom N Harris        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1215409d7af7SAndreas Gohr            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
121620d062caSAndreas Gohr
121763afe2a6SAnika Henke        </div>
12184da078a3Smatthiasgrimm        <?php
1219e351c80dSAdrian Lang        $form = new Doku_Form(array('id' => 'dw__editform'));
1220fdb8d77bSTom N Harris        $form->addHidden('id', $ID);
1221fdb8d77bSTom N Harris        $form->addHidden('rev', $REV);
1222fdb8d77bSTom N Harris        $form->addHidden('date', $DATE);
1223fdb8d77bSTom N Harris        $form->addHidden('prefix', $PRE);
1224fdb8d77bSTom N Harris        $form->addHidden('suffix', $SUF);
1225fdb8d77bSTom N Harris        $form->addHidden('changecheck', $check);
1226fdb8d77bSTom N Harris        $attr = array('tabindex'=>'1');
1227fdb8d77bSTom N Harris        if (!$wr) $attr['readonly'] = 'readonly';
1228fdb8d77bSTom N Harris        $form->addElement(form_makeWikiText($text, $attr));
1229fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1230fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1231fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1232fdb8d77bSTom N Harris        if ($wr) {
1233fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1234fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1235fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1236fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1237fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1238fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1239fdb8d77bSTom N Harris            $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1240fdb8d77bSTom N Harris            $elem = html_minoredit();
1241fdb8d77bSTom N Harris            if ($elem) $form->addElement($elem);
1242fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1243fdb8d77bSTom N Harris        }
1244fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
12455808bc54SAndreas Gohr        if($wr && $conf['license']){
1246066fee30SAndreas Gohr            $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1247066fee30SAndreas Gohr            $out  = $lang['licenseok'];
1248066fee30SAndreas Gohr            $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1249c0322273SAdrian Lang            if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1250066fee30SAndreas Gohr            $out .= '> '.$license[$conf['license']]['name'].'</a>';
1251066fee30SAndreas Gohr            $form->addElement($out);
1252066fee30SAndreas Gohr            $form->addElement(form_makeCloseTag('div'));
1253066fee30SAndreas Gohr        }
1254fdb8d77bSTom N Harris        html_form('edit', $form);
1255fdb8d77bSTom N Harris        print '</div>'.NL;
1256f3f0262cSandi}
1257f3f0262cSandi
1258f3f0262cSandi/**
1259b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1260b6912aeaSAndreas Gohr *
1261b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1262b6912aeaSAndreas Gohr */
1263b6912aeaSAndreas Gohrfunction html_minoredit(){
1264b6912aeaSAndreas Gohr    global $conf;
1265b6912aeaSAndreas Gohr    global $lang;
1266b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1267b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1268fdb8d77bSTom N Harris        return false;
1269b6912aeaSAndreas Gohr    }
1270b6912aeaSAndreas Gohr
1271b6912aeaSAndreas Gohr    $p = array();
1272b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1273bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1274fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1275b6912aeaSAndreas Gohr}
1276b6912aeaSAndreas Gohr
1277b6912aeaSAndreas Gohr/**
1278f3f0262cSandi * prints some debug info
127915fae107Sandi *
128015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1281f3f0262cSandi */
1282f3f0262cSandifunction html_debug(){
1283f3f0262cSandi    global $conf;
1284d16a4edaSandi    global $lang;
12855298a619SAndreas Gohr    global $auth;
1286100a97e3SAndreas Gohr    global $INFO;
1287100a97e3SAndreas Gohr
128828fb55ffSandi    //remove sensitive data
128928fb55ffSandi    $cnf = $conf;
129024297a69SAndreas Gohr    debug_guard($cnf);
1291100a97e3SAndreas Gohr    $nfo = $INFO;
129224297a69SAndreas Gohr    debug_guard($nfo);
1293100a97e3SAndreas Gohr    $ses = $_SESSION;
129424297a69SAndreas Gohr    debug_guard($ses);
1295f3f0262cSandi
1296f3f0262cSandi    print '<html><body>';
1297f3f0262cSandi
1298f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1299f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1300f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1301f3f0262cSandi
1302100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1303100a97e3SAndreas Gohr    print_r($nfo);
1304100a97e3SAndreas Gohr    print '</pre>';
1305100a97e3SAndreas Gohr
1306f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1307f3f0262cSandi    print_r($_SERVER);
1308f3f0262cSandi    print '</pre>';
1309f3f0262cSandi
1310f3f0262cSandi    print '<b>$conf:</b><pre>';
131128fb55ffSandi    print_r($cnf);
1312f3f0262cSandi    print '</pre>';
1313f3f0262cSandi
1314ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1315ed7b5f09Sandi    print DOKU_BASE;
1316f3f0262cSandi    print '</pre>';
1317f3f0262cSandi
1318ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1319ed7b5f09Sandi    print DOKU_URL;
1320ed7b5f09Sandi    print '</pre>';
1321ed7b5f09Sandi
1322ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1323f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1324f3f0262cSandi    print '</pre>';
1325f3f0262cSandi
1326f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1327f3f0262cSandi    print phpversion();
1328f3f0262cSandi    print '</pre>';
1329f3f0262cSandi
1330f3f0262cSandi    print '<b>locale:</b><pre>';
1331f3f0262cSandi    print setlocale(LC_ALL,0);
1332f3f0262cSandi    print '</pre>';
1333f3f0262cSandi
1334d16a4edaSandi    print '<b>encoding:</b><pre>';
1335d16a4edaSandi    print $lang['encoding'];
1336d16a4edaSandi    print '</pre>';
1337d16a4edaSandi
13385298a619SAndreas Gohr    if($auth){
13395298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13405298a619SAndreas Gohr        print_r($auth->cando);
13415298a619SAndreas Gohr        print '</pre>';
13425298a619SAndreas Gohr    }
13435298a619SAndreas Gohr
13443aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1345100a97e3SAndreas Gohr    print_r($ses);
13463aa54d7cSAndreas Gohr    print '</pre>';
13473aa54d7cSAndreas Gohr
1348f3f0262cSandi    print '<b>Environment:</b><pre>';
1349f3f0262cSandi    print_r($_ENV);
1350f3f0262cSandi    print '</pre>';
1351f3f0262cSandi
1352f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1353f3f0262cSandi    $inis = ini_get_all();
1354f3f0262cSandi    print_r($inis);
1355f3f0262cSandi    print '</pre>';
1356f3f0262cSandi
1357f3f0262cSandi    print '</body></html>';
1358f3f0262cSandi}
1359f3f0262cSandi
136010271ce4SAndreas Gohr/**
136110271ce4SAndreas Gohr * List available Administration Tasks
136210271ce4SAndreas Gohr *
136310271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
136410271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
136510271ce4SAndreas Gohr */
1366c19fe9c0Sandifunction html_admin(){
1367c19fe9c0Sandi    global $ID;
1368f8cc712eSAndreas Gohr    global $INFO;
1369c19fe9c0Sandi    global $lang;
1370ca3a6df1SMatthias Grimm    global $conf;
137110271ce4SAndreas Gohr    global $auth;
1372c19fe9c0Sandi
137311e2ce22Schris    // build menu of admin functions from the plugins that handle them
137411e2ce22Schris    $pluginlist = plugin_list('admin');
137511e2ce22Schris    $menu = array();
137611e2ce22Schris    foreach ($pluginlist as $p) {
1377db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1378f8cc712eSAndreas Gohr
1379f8cc712eSAndreas Gohr        // check permissions
1380f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1381f8cc712eSAndreas Gohr
138210271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
138311e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
138411e2ce22Schris                'sort' => $obj->getMenuSort()
138511e2ce22Schris                );
138611e2ce22Schris    }
138711e2ce22Schris
138810271ce4SAndreas Gohr    print p_locale_xhtml('admin');
138910271ce4SAndreas Gohr
139010271ce4SAndreas Gohr    // Admin Tasks
139110271ce4SAndreas Gohr    if($INFO['isadmin']){
139210271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
139310271ce4SAndreas Gohr
139476c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
139510271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
139610271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
139710271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
139810271ce4SAndreas Gohr        }
139910271ce4SAndreas Gohr        unset($menu['usermanager']);
140010271ce4SAndreas Gohr
140176c65fd3SAndreas Gohr        if($menu['acl']){
140210271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
140310271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
140410271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
140576c65fd3SAndreas Gohr        }
140610271ce4SAndreas Gohr        unset($menu['acl']);
140710271ce4SAndreas Gohr
140876c65fd3SAndreas Gohr        if($menu['plugin']){
140910271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
141010271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
141110271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
141276c65fd3SAndreas Gohr        }
141310271ce4SAndreas Gohr        unset($menu['plugin']);
141410271ce4SAndreas Gohr
141576c65fd3SAndreas Gohr        if($menu['config']){
141610271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
141710271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
141810271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
141976c65fd3SAndreas Gohr        }
142010271ce4SAndreas Gohr        unset($menu['config']);
142110271ce4SAndreas Gohr    }
142210271ce4SAndreas Gohr    ptln('</ul>');
142310271ce4SAndreas Gohr
142410271ce4SAndreas Gohr    // Manager Tasks
142510271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
142610271ce4SAndreas Gohr
142776c65fd3SAndreas Gohr    if($menu['revert']){
142810271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
142910271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
143010271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
143176c65fd3SAndreas Gohr    }
143210271ce4SAndreas Gohr    unset($menu['revert']);
143310271ce4SAndreas Gohr
143476c65fd3SAndreas Gohr    if($menu['popularity']){
143510271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
143610271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
143710271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
143876c65fd3SAndreas Gohr    }
143910271ce4SAndreas Gohr    unset($menu['popularity']);
144010271ce4SAndreas Gohr
144110271ce4SAndreas Gohr    ptln('</ul>');
144210271ce4SAndreas Gohr
144310271ce4SAndreas Gohr    // print the rest as sorted list
144410271ce4SAndreas Gohr    if(count($menu)){
1445746855cfSBen Coburn        usort($menu, 'p_sort_modes');
144611e2ce22Schris        // output the menu
144710271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
144810271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
144911e2ce22Schris        ptln('<ul>');
145011e2ce22Schris        foreach ($menu as $item) {
145111e2ce22Schris            if (!$item['prompt']) continue;
14520c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
145311e2ce22Schris        }
145411e2ce22Schris        ptln('</ul>');
1455ca3a6df1SMatthias Grimm    }
145610271ce4SAndreas Gohr}
1457c19fe9c0Sandi
14588b06d178Schris/**
14598b06d178Schris * Form to request a new password for an existing account
14608b06d178Schris *
14618b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
146211e2ce22Schris */
14638b06d178Schrisfunction html_resendpwd() {
14648b06d178Schris    global $lang;
14658b06d178Schris    global $conf;
14668b06d178Schris    global $ID;
1467c19fe9c0Sandi
14688b06d178Schris    print p_locale_xhtml('resendpwd');
1469fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1470e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1471fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1472fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1473fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1474fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1475fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1476fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1477fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1478fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1479fdb8d77bSTom N Harris    $form->endFieldset();
1480fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1481fdb8d77bSTom N Harris    print '</div>'.NL;
1482fdb8d77bSTom N Harris}
1483fdb8d77bSTom N Harris
1484fdb8d77bSTom N Harris/**
1485b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1486b8595a66SAndreas Gohr *
1487b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1488b8595a66SAndreas Gohr */
1489b8595a66SAndreas Gohrfunction html_TOC($toc){
1490b8595a66SAndreas Gohr    if(!count($toc)) return '';
1491b8595a66SAndreas Gohr    global $lang;
1492b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1493b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1494b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1495b8595a66SAndreas Gohr    $out .= $lang['toc'];
1496b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1497b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1498b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1499b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1500b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1501db959ae3SAndreas Gohr    return $out;
1502db959ae3SAndreas Gohr}
1503b8595a66SAndreas Gohr
1504b8595a66SAndreas Gohr/**
1505b8595a66SAndreas Gohr * Callback for html_buildlist
1506b8595a66SAndreas Gohr */
1507b8595a66SAndreas Gohrfunction html_list_toc($item){
1508c66972f2SAdrian Lang    if(isset($item['hid'])){
15097d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15107d91652aSAndreas Gohr    }else{
15117d91652aSAndreas Gohr        $link = $item['link'];
15127d91652aSAndreas Gohr    }
15137d91652aSAndreas Gohr
15147d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1515b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1516b8595a66SAndreas Gohr}
1517b8595a66SAndreas Gohr
1518b8595a66SAndreas Gohr/**
1519b8595a66SAndreas Gohr * Helper function to build TOC items
1520b8595a66SAndreas Gohr *
1521b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1522b8595a66SAndreas Gohr *
1523b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1524b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1525b8595a66SAndreas Gohr * @param int    $level - nesting level
1526b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1527b8595a66SAndreas Gohr */
1528b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1529b8595a66SAndreas Gohr    global $conf;
1530b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1531b8595a66SAndreas Gohr            'title' => $text,
1532b8595a66SAndreas Gohr            'type'  => 'ul',
15332bb0d541Schris            'level' => $level);
1534b8595a66SAndreas Gohr}
1535b8595a66SAndreas Gohr
1536b8595a66SAndreas Gohr/**
1537fdb8d77bSTom N Harris * Output a Doku_Form object.
1538fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1539fdb8d77bSTom N Harris *
1540fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1541fdb8d77bSTom N Harris */
1542fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1543fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1544fdb8d77bSTom N Harris    $form->endFieldset();
1545fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1546fdb8d77bSTom N Harris}
1547fdb8d77bSTom N Harris
1548fdb8d77bSTom N Harris/**
1549fdb8d77bSTom N Harris * Form print function.
1550fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1551fdb8d77bSTom N Harris */
1552fdb8d77bSTom N Harrisfunction html_form_output($data) {
1553fdb8d77bSTom N Harris    $data->printForm();
15548b06d178Schris}
1555340756e4Sandi
155607bf32b2SAndreas Gohr/**
155707bf32b2SAndreas Gohr * Embed a flash object in HTML
155807bf32b2SAndreas Gohr *
155907bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
156007bf32b2SAndreas Gohr * compatble way using valid XHTML
156107bf32b2SAndreas Gohr *
156207bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
156307bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
156407bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
156507bf32b2SAndreas Gohr * $lang['noflash'] is used.
156607bf32b2SAndreas Gohr *
156707bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
156807bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
156907bf32b2SAndreas Gohr *
157007bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
157107bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
157207bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
157307bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
157407bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
157507bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
157607bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
157707bf32b2SAndreas Gohr * @returns string         - the XHTML markup
157807bf32b2SAndreas Gohr */
157907bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
158007bf32b2SAndreas Gohr    global $lang;
158107bf32b2SAndreas Gohr
158207bf32b2SAndreas Gohr    $out = '';
158307bf32b2SAndreas Gohr
158407bf32b2SAndreas Gohr    // prepare the object attributes
158507bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
158607bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1587d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
158807bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
158907bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
159007bf32b2SAndreas Gohr
159107bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
159207bf32b2SAndreas Gohr    $std = $atts;
159307bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
159407bf32b2SAndreas Gohr    $std['data'] = $swf;
159507bf32b2SAndreas Gohr
159607bf32b2SAndreas Gohr    // add object attributes for IE
159707bf32b2SAndreas Gohr    $ie  = $atts;
159807bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
159907bf32b2SAndreas Gohr
160007bf32b2SAndreas Gohr    // open object (with conditional comments)
160107bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
160207bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
160307bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
160407bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
160507bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
160607bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16079ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
160807bf32b2SAndreas Gohr
160907bf32b2SAndreas Gohr    // print params
161007bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
161107bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
161207bf32b2SAndreas Gohr    }
161307bf32b2SAndreas Gohr
161407bf32b2SAndreas Gohr    // add flashvars
161507bf32b2SAndreas Gohr    if(is_array($flashvars)){
1616d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
161707bf32b2SAndreas Gohr    }
161807bf32b2SAndreas Gohr
161907bf32b2SAndreas Gohr    // alternative content
162007bf32b2SAndreas Gohr    if($alt){
162107bf32b2SAndreas Gohr        $out .= $alt.NL;
162207bf32b2SAndreas Gohr    }else{
162307bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
162407bf32b2SAndreas Gohr    }
162507bf32b2SAndreas Gohr
162607bf32b2SAndreas Gohr    // finish
162707bf32b2SAndreas Gohr    $out .= '</object>'.NL;
162807bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
162907bf32b2SAndreas Gohr
163007bf32b2SAndreas Gohr    return $out;
163107bf32b2SAndreas Gohr}
163207bf32b2SAndreas Gohr
1633