xref: /dokuwiki/inc/html.php (revision d822118c9a034bb7ecb820df6ac46cb078d5d4b9)
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
94b081e262SAdrian Lang    $edittarget = ($matches[1] === 'SECTION') ? 'plain' :
95b081e262SAdrian Lang                  strtolower($matches[1]);
96b081e262SAdrian Lang
97b081e262SAdrian Lang    $section = $matches[3];
98b081e262SAdrian Lang    $name = $matches[2];
99041d7a86SBen Coburn
100f3f0262cSandi    $secedit  = '';
101*d822118cSAdrian Lang    $secedit .= '<div class="secedit editbutton_' . $edittarget . '">';
102f3f0262cSandi    $secedit .= html_btn('secedit',$ID,'',
103f3f0262cSandi            array('do'      => 'edit',
104b081e262SAdrian Lang                'lines'   => $section,
105b081e262SAdrian Lang                'edittarget' => $edittarget,
106306b2c85SDenis Simakov                'rev' => $INFO['lastmod']),
107*d822118cSAdrian Lang            'post', $name);
108f3f0262cSandi    $secedit .= '</div>';
109f3f0262cSandi    return $secedit;
110f3f0262cSandi}
111f3f0262cSandi
11215fae107Sandi/**
11315fae107Sandi * inserts section edit buttons if wanted or removes the markers
11415fae107Sandi *
11515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
11615fae107Sandi */
117f3f0262cSandifunction html_secedit($text,$show=true){
118f3f0262cSandi    global $INFO;
11935dae8b0SBen Coburn
120b081e262SAdrian Lang    $regexp = '#<!-- ([A-Z]+) (?:"(.*)" )?\[(\d+-\d*)\] -->#';
121b081e262SAdrian Lang
122c112d578Sandi    if($INFO['writable'] && $show && !$INFO['rev']){
123b081e262SAdrian Lang        $text = preg_replace_callback($regexp,
12435dae8b0SBen Coburn                'html_secedit_button', $text);
125f3f0262cSandi    }else{
126b081e262SAdrian Lang        $text = preg_replace($regexp,'',$text);
127f3f0262cSandi    }
12835dae8b0SBen Coburn
129f3f0262cSandi    return $text;
130f3f0262cSandi}
131f3f0262cSandi
132f3f0262cSandi/**
133d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1346b13307fSandi *
1356b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1366b13307fSandi */
1376b13307fSandifunction html_topbtn(){
1386b13307fSandi    global $lang;
1396b13307fSandi
1406b13307fSandi    $ret  = '';
14111ea018fSAndreas 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>';
142df7b6005Sandi
1436b13307fSandi    return $ret;
1446b13307fSandi}
1456b13307fSandi
1466b13307fSandi/**
147d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
14835dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
14915fae107Sandi *
15015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
151f3f0262cSandi */
152*d822118cSAdrian Langfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
153f3f0262cSandi    global $conf;
154f3f0262cSandi    global $lang;
155f3f0262cSandi
156f3f0262cSandi    $label = $lang['btn_'.$name];
157f3f0262cSandi
158f3f0262cSandi    $ret = '';
15935dae8b0SBen Coburn    $tip = '';
160f3f0262cSandi
16149c713a3Sandi    //filter id (without urlencoding)
16249c713a3Sandi    $id = idfilter($id,false);
163f3f0262cSandi
164f3f0262cSandi    //make nice URLs even for buttons
1656c7843b5Sandi    if($conf['userewrite'] == 2){
1666c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1676c7843b5Sandi    }elseif($conf['userewrite']){
1686c7843b5Sandi        $script = DOKU_BASE.$id;
1696c7843b5Sandi    }else{
1708b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
171f3f0262cSandi        $params['id'] = $id;
172f3f0262cSandi    }
173f3f0262cSandi
174b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
175f3f0262cSandi
17606a4bf8fSAndreas Gohr    if(is_array($params)){
177f3f0262cSandi        reset($params);
178f3f0262cSandi        while (list($key, $val) = each($params)) {
179f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
180f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
181f3f0262cSandi        }
18206a4bf8fSAndreas Gohr    }
183f3f0262cSandi
18435dae8b0SBen Coburn    if ($tooltip!='') {
18535dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
18611ea018fSAndreas Gohr    }else{
18711ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
18811ea018fSAndreas Gohr    }
18911ea018fSAndreas Gohr
190*d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
19111ea018fSAndreas Gohr    if($akey){
19207493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
19387cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
19435dae8b0SBen Coburn    }
19535dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
196f3f0262cSandi    $ret .= '/>';
1974beabca9SAnika Henke    $ret .= '</div></form>';
198f3f0262cSandi
199f3f0262cSandi    return $ret;
200f3f0262cSandi}
201f3f0262cSandi
202f3f0262cSandi/**
20315fae107Sandi * show a wiki page
20415fae107Sandi *
20515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
20615fae107Sandi */
2076bbae538Sandifunction html_show($txt=''){
208f3f0262cSandi    global $ID;
209f3f0262cSandi    global $REV;
210f3f0262cSandi    global $HIGH;
211b8595a66SAndreas Gohr    global $INFO;
212f3f0262cSandi    //disable section editing for old revisions or in preview
2135400331dSandi    if($txt || $REV){
2146bbae538Sandi        $secedit = false;
2156bbae538Sandi    }else{
2166bbae538Sandi        $secedit = true;
217f3f0262cSandi    }
218f3f0262cSandi
2196bbae538Sandi    if ($txt){
220f3f0262cSandi        //PreviewHeader
221b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
222b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
223b8595a66SAndreas Gohr        echo '<div class="preview">';
224b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
225b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
226b8595a66SAndreas Gohr        echo $html;
227b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
228b8595a66SAndreas Gohr        echo '</div>';
2296bbae538Sandi
230f3f0262cSandi    }else{
231c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
232c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2336bbae538Sandi        $html = html_secedit($html,$secedit);
234b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
235b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
236b8595a66SAndreas Gohr        echo $html;
237f3f0262cSandi    }
238f3f0262cSandi}
239f3f0262cSandi
240f3f0262cSandi/**
241ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
242ee4c4a1bSAndreas Gohr *
243ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
244ee4c4a1bSAndreas Gohr */
245ee4c4a1bSAndreas Gohrfunction html_draft(){
246ee4c4a1bSAndreas Gohr    global $INFO;
247ee4c4a1bSAndreas Gohr    global $ID;
248ee4c4a1bSAndreas Gohr    global $lang;
249ee4c4a1bSAndreas Gohr    global $conf;
250ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
251ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
252ee4c4a1bSAndreas Gohr
253fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
254e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
255fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
256fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
257fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
258fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
259f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
260fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
261fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
262fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
263fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
264fdb8d77bSTom N Harris    html_form('draft', $form);
265ee4c4a1bSAndreas Gohr}
266ee4c4a1bSAndreas Gohr
267ee4c4a1bSAndreas Gohr/**
268f3f0262cSandi * Highlights searchqueries in HTML code
26915fae107Sandi *
27015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2717209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
272f3f0262cSandi */
273546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
274808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
275808551e3SAndreas Gohr    $regex = join('|',array_map('preg_quote_cb',$phrases));
27660c15d7dSAndreas Gohr
27760c15d7dSAndreas Gohr    if ($regex === '') return $html;
2781db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
279f3f0262cSandi    return $html;
280f3f0262cSandi}
281f3f0262cSandi
282f3f0262cSandi/**
2837209be23SAndreas Gohr * Callback used by html_hilight()
2847209be23SAndreas Gohr *
2857209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2867209be23SAndreas Gohr */
2877209be23SAndreas Gohrfunction html_hilight_callback($m) {
2887209be23SAndreas Gohr    $hlight = unslash($m[0]);
2897209be23SAndreas Gohr    if ( !isset($m[2])) {
290688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
2917209be23SAndreas Gohr    }
2927209be23SAndreas Gohr    return $hlight;
2937209be23SAndreas Gohr}
2947209be23SAndreas Gohr
2957209be23SAndreas Gohr/**
29615fae107Sandi * Run a search and display the result
29715fae107Sandi *
29815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
299f3f0262cSandi */
300f3f0262cSandifunction html_search(){
301ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
302506fa893SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
303f3f0262cSandi    global $conf;
304f3f0262cSandi    global $QUERY;
305f3f0262cSandi    global $ID;
306f3f0262cSandi    global $lang;
307f3f0262cSandi
308c112d578Sandi    print p_locale_xhtml('searchpage');
309f3f0262cSandi    flush();
310f3f0262cSandi
311d0ab54f6SMichael Klier chi@chimeric.de    //check if search is restricted to namespace
312b42bcfe7Sdaniel.lindgren    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
313d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($match[1]);
314d0ab54f6SMichael Klier chi@chimeric.de    } else {
315d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($QUERY);
316d0ab54f6SMichael Klier chi@chimeric.de    }
317d0ab54f6SMichael Klier chi@chimeric.de
3184d9ff3d5Sandi    //show progressbar
319e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
320e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
321e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
322e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
323e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3249edac8a8SAndreas Gohr    flush();
3254d9ff3d5Sandi
326f3f0262cSandi    //do quick pagesearch
327f3f0262cSandi    $data = array();
328d0ab54f6SMichael Klier chi@chimeric.de
329865c2687SKazutaka Miyasaka    if($id) $data = ft_pageLookup($id);
330f3f0262cSandi    if(count($data)){
331f3f0262cSandi        print '<div class="search_quickresult">';
332746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3334f732f0eSAnika Henke        print '<ul class="search_quickhits">';
334140c93f3SAnika Henke        foreach($data as $id){
3354f732f0eSAnika Henke            print '<li> ';
336bd2f6c2fSAndreas Gohr            $ns = getNS($id);
337bd2f6c2fSAndreas Gohr            if($ns){
338bd2f6c2fSAndreas Gohr                $name = shorten(noNS($id), ' ('.$ns.')',30);
339bd2f6c2fSAndreas Gohr            }else{
340bd2f6c2fSAndreas Gohr                $name = $id;
341bd2f6c2fSAndreas Gohr            }
342bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3434f732f0eSAnika Henke            print '</li> ';
344f3f0262cSandi        }
345140c93f3SAnika Henke        print '</ul> ';
346f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
347f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
348f3f0262cSandi        print '</div>';
349f3f0262cSandi    }
350f3f0262cSandi    flush();
351f3f0262cSandi
352f3f0262cSandi    //do fulltext search
35360c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
354f3f0262cSandi    if(count($data)){
355506fa893SAndreas Gohr        $num = 1;
356506fa893SAndreas Gohr        foreach($data as $id => $cnt){
357f3f0262cSandi            print '<div class="search_result">';
358db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
359865c2687SKazutaka Miyasaka            if($cnt !== 0){
360506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
361506fa893SAndreas Gohr                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
36260c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
363506fa893SAndreas Gohr                }
364865c2687SKazutaka Miyasaka                $num++;
365865c2687SKazutaka Miyasaka            }
366f3f0262cSandi            print '</div>';
367506fa893SAndreas Gohr            flush();
368f3f0262cSandi        }
369f3f0262cSandi    }else{
370820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
371f3f0262cSandi    }
3724d9ff3d5Sandi
3734d9ff3d5Sandi    //hide progressbar
374e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
375e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
376e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3779edac8a8SAndreas Gohr    flush();
378f3f0262cSandi}
379f3f0262cSandi
38015fae107Sandi/**
38115fae107Sandi * Display error on locked pages
38215fae107Sandi *
38315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
38415fae107Sandi */
385ee20e7d1Sandifunction html_locked(){
386f3f0262cSandi    global $ID;
387f3f0262cSandi    global $conf;
388f3f0262cSandi    global $lang;
38988f522e9Sandi    global $INFO;
390f3f0262cSandi
391c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
392f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
393f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
394f3f0262cSandi
395c112d578Sandi    print p_locale_xhtml('locked');
396f3f0262cSandi    print '<ul>';
3976d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
3980c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
399f3f0262cSandi    print '</ul>';
400f3f0262cSandi}
401f3f0262cSandi
40215fae107Sandi/**
40315fae107Sandi * list old revisions
40415fae107Sandi *
40515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
40671726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
40715fae107Sandi */
40871726d78SBen Coburnfunction html_revisions($first=0){
409f3f0262cSandi    global $ID;
410f3f0262cSandi    global $INFO;
411f3f0262cSandi    global $conf;
412f3f0262cSandi    global $lang;
41371726d78SBen Coburn    /* we need to get one additionally log entry to be able to
41471726d78SBen Coburn     * decide if this is the last page or is there another one.
41571726d78SBen Coburn     * see html_recent()
41671726d78SBen Coburn     */
41771726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
41871726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
41971726d78SBen Coburn        $first=0;
42071726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
42171726d78SBen Coburn    }
42271726d78SBen Coburn    $hasNext = false;
42371726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
42471726d78SBen Coburn        $hasNext = true;
42571726d78SBen Coburn        array_pop($revisions); // remove extra log entry
42671726d78SBen Coburn    }
42771726d78SBen Coburn
428f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
429f3f0262cSandi
430c112d578Sandi    print p_locale_xhtml('revisions');
43137a1dc12Smichael
432e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
43337a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
43471726d78SBen Coburn    if($INFO['exists'] && $first==0){
43537a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
43637a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
43737a1dc12Smichael        else
43837a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
43937a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
44037a1dc12Smichael        $form->addElement(form_makeTag('input', array(
44137a1dc12Smichael                        'type' => 'checkbox',
44237a1dc12Smichael                        'name' => 'rev2[]',
44337a1dc12Smichael                        'value' => 'current')));
444f9b2fe70Sandi
44537a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
44637a1dc12Smichael        $form->addElement($date);
44737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
448f9b2fe70Sandi
44937a1dc12Smichael        $form->addElement(form_makeTag('img', array(
45037a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
45137a1dc12Smichael                        'width' => '15',
45237a1dc12Smichael                        'height' => '11',
45337a1dc12Smichael                        'alt'    => '')));
454cffcc403Sandi
45537a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
45637a1dc12Smichael                        'class' => 'wikilink1',
45737a1dc12Smichael                        'href'  => wl($ID))));
45837a1dc12Smichael        $form->addElement($ID);
45937a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
460652610a2Sandi
46137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
46237a1dc12Smichael        $form->addElement(' &ndash; ');
46337a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
46437a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
465652610a2Sandi
46637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
46737a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
46837a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
46937a1dc12Smichael
47037a1dc12Smichael        $form->addElement('('.$lang['current'].')');
47137a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
47237a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
473f3f0262cSandi    }
474f3f0262cSandi
475f3f0262cSandi    foreach($revisions as $rev){
476f2263577SAndreas Gohr        $date   = dformat($rev);
477fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
478103c256aSChris Smith        $exists = page_exists($ID,$rev);
479652610a2Sandi
48037a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
48137a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
48237a1dc12Smichael        else
48337a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
48437a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
48577707b04SAndreas Gohr        if($exists){
48637a1dc12Smichael            $form->addElement(form_makeTag('input', array(
48737a1dc12Smichael                            'type' => 'checkbox',
48837a1dc12Smichael                            'name' => 'rev2[]',
48937a1dc12Smichael                            'value' => $rev)));
49077707b04SAndreas Gohr        }else{
49137a1dc12Smichael            $form->addElement(form_makeTag('img', array(
49237a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
49337a1dc12Smichael                            'width' => 14,
49437a1dc12Smichael                            'height' => 11,
49537a1dc12Smichael                            'alt' => '')));
49641396b71SAndreas Gohr        }
497f9b2fe70Sandi
49837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
49937a1dc12Smichael        $form->addElement($date);
50037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
50137a1dc12Smichael
50237a1dc12Smichael        if($exists){
50337a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
50437a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50537a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
50637a1dc12Smichael                            'width'  => 15,
50737a1dc12Smichael                            'height' => 11,
50837a1dc12Smichael                            'title'  => $lang['diff'],
50937a1dc12Smichael                            'alt'    => $lang['diff'])));
51037a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
51137a1dc12Smichael
51237a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
51337a1dc12Smichael            $form->addElement($ID);
51437a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
51537a1dc12Smichael        }else{
51637a1dc12Smichael            $form->addElement(form_makeTag('img', array(
51737a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
51837a1dc12Smichael                            'width' => '15',
51937a1dc12Smichael                            'height' => '11',
52037a1dc12Smichael                            'alt'   => '')));
52137a1dc12Smichael            $form->addElement($ID);
52237a1dc12Smichael        }
52337a1dc12Smichael
52437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
52537a1dc12Smichael        $form->addElement(' &ndash; ');
52637a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
52737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
52837a1dc12Smichael
52937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
53088f522e9Sandi        if($info['user']){
53137a1dc12Smichael            $form->addElement(editorinfo($info['user']));
532433efb25SAndreas Gohr            if(auth_ismanager()){
533433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
534433efb25SAndreas Gohr            }
53588f522e9Sandi        }else{
53637a1dc12Smichael            $form->addElement($info['ip']);
53788f522e9Sandi        }
53837a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
539652610a2Sandi
54037a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
54137a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
542f3f0262cSandi    }
54337a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
54437a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
54537a1dc12Smichael    html_form('revisions', $form);
54671726d78SBen Coburn
54771726d78SBen Coburn    print '<div class="pagenav">';
54871726d78SBen Coburn    $last = $first + $conf['recent'];
54971726d78SBen Coburn    if ($first > 0) {
55071726d78SBen Coburn        $first -= $conf['recent'];
55171726d78SBen Coburn        if ($first < 0) $first = 0;
55271726d78SBen Coburn        print '<div class="pagenav-prev">';
553eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
55471726d78SBen Coburn        print '</div>';
55571726d78SBen Coburn    }
55671726d78SBen Coburn    if ($hasNext) {
55771726d78SBen Coburn        print '<div class="pagenav-next">';
558eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
55971726d78SBen Coburn        print '</div>';
56071726d78SBen Coburn    }
56171726d78SBen Coburn    print '</div>';
56271726d78SBen Coburn
563f3f0262cSandi}
564f3f0262cSandi
56515fae107Sandi/**
56615fae107Sandi * display recent changes
56715fae107Sandi *
56815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5695749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
57071726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
57115fae107Sandi */
572a39955b0Smatthiasgrimmfunction html_recent($first=0){
573f3f0262cSandi    global $conf;
574cffcc403Sandi    global $lang;
575dbb00abcSEsther Brunner    global $ID;
5765749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5775749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5785749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5795749f1ceSmatthiasgrimm     */
580b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5815749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5825749f1ceSmatthiasgrimm        $first=0;
58371726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5845749f1ceSmatthiasgrimm    }
58571726d78SBen Coburn    $hasNext = false;
58671726d78SBen Coburn    if (count($recents)>$conf['recent']) {
58771726d78SBen Coburn        $hasNext = true;
58871726d78SBen Coburn        array_pop($recents); // remove extra log entry
58971726d78SBen Coburn    }
590f3f0262cSandi
591c112d578Sandi    print p_locale_xhtml('recent');
592e83cef14SGina Haeussge
593e83cef14SGina Haeussge    if (getNS($ID) != '')
5949e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
595e83cef14SGina Haeussge
596e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
597abdcc39fSmichael    $form->addHidden('sectok', null);
598abdcc39fSmichael    $form->addHidden('do', 'recent');
599abdcc39fSmichael    $form->addHidden('id', $ID);
600abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
601a39955b0Smatthiasgrimm
602d437bcc4SAndreas Gohr    foreach($recents as $recent){
603f2263577SAndreas Gohr        $date = dformat($recent['date']);
604abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
605abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
606abdcc39fSmichael        else
607abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
608cffcc403Sandi
609abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
610f9b2fe70Sandi
611abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
612abdcc39fSmichael        $form->addElement($date);
613abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
614cffcc403Sandi
615cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
616abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
617abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
618abdcc39fSmichael                        'width' => 15,
619abdcc39fSmichael                        'height'=> 11,
620abdcc39fSmichael                        'title' => $lang['diff'],
621abdcc39fSmichael                        'alt'   => $lang['diff']
622abdcc39fSmichael                        )));
623abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
624cffcc403Sandi
625cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
626abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
627abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
628abdcc39fSmichael                        'width' => 12,
629abdcc39fSmichael                        'height'=> 14,
630abdcc39fSmichael                        'title' => $lang['btn_revs'],
631abdcc39fSmichael                        'alt'   => $lang['btn_revs']
632abdcc39fSmichael                        )));
633abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
634b6912aeaSAndreas Gohr
635db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
636abdcc39fSmichael
637abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
638abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
639abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
640abdcc39fSmichael
641abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
642d437bcc4SAndreas Gohr        if($recent['user']){
643abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
644433efb25SAndreas Gohr            if(auth_ismanager()){
645433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
646433efb25SAndreas Gohr            }
64788f522e9Sandi        }else{
648abdcc39fSmichael            $form->addElement($recent['ip']);
64988f522e9Sandi        }
650abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
651cffcc403Sandi
652abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
653abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
654f3f0262cSandi    }
655abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
656a39955b0Smatthiasgrimm
657abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6585749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
659a39955b0Smatthiasgrimm    if ($first > 0) {
660a39955b0Smatthiasgrimm        $first -= $conf['recent'];
661a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
662abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
663abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
664abdcc39fSmichael                    'type'  => 'submit',
665abdcc39fSmichael                    'name'  => 'first['.$first.']',
666cddd152cSmichael                    'value' => $lang['btn_newer'],
667cddd152cSmichael                    'accesskey' => 'n',
668f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
66918d107cbSMichael Klier                    'class' => 'button'
670abdcc39fSmichael                    )));
671abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
672a39955b0Smatthiasgrimm    }
67371726d78SBen Coburn    if ($hasNext) {
674abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
675abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
676abdcc39fSmichael                        'type'  => 'submit',
677abdcc39fSmichael                        'name'  => 'first['.$last.']',
678cddd152cSmichael                        'value' => $lang['btn_older'],
679cddd152cSmichael                        'accesskey' => 'p',
680f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
68118d107cbSMichael Klier                        'class' => 'button'
682abdcc39fSmichael                        )));
683abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
684a39955b0Smatthiasgrimm    }
685abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
686abdcc39fSmichael    html_form('recent', $form);
687f3f0262cSandi}
688f3f0262cSandi
68915fae107Sandi/**
69015fae107Sandi * Display page index
69115fae107Sandi *
69215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
69315fae107Sandi */
694f3f0262cSandifunction html_index($ns){
695ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
696f3f0262cSandi    global $conf;
697f3f0262cSandi    global $ID;
698f3f0262cSandi    $dir = $conf['datadir'];
699f3f0262cSandi    $ns  = cleanID($ns);
70030f1737dSandi    #fixme use appropriate function
701f3f0262cSandi    if(empty($ns)){
702f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
703f3f0262cSandi        if($ns == '.') $ns ='';
704f3f0262cSandi    }
70588d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
706f3f0262cSandi
707a06884abSAndreas Gohr    echo p_locale_xhtml('index');
708a06884abSAndreas Gohr    echo '<div id="index__tree">';
709f3f0262cSandi
710f3f0262cSandi    $data = array();
711f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
712a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
713a06884abSAndreas Gohr
714a06884abSAndreas Gohr    echo '</div>';
715f3f0262cSandi}
716f3f0262cSandi
717f3f0262cSandi/**
71815fae107Sandi * Index item formatter
71915fae107Sandi *
720f3f0262cSandi * User function for html_buildlist()
72115fae107Sandi *
72215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
723f3f0262cSandi */
724f3f0262cSandifunction html_list_index($item){
725d98d4540SBen Coburn    global $ID;
726f3f0262cSandi    $ret = '';
727f3f0262cSandi    $base = ':'.$item['id'];
728f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
729f3f0262cSandi    if($item['type']=='d'){
7304a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
731f3f0262cSandi        $ret .= $base;
732ed7ecb79SAnika Henke        $ret .= '</strong></a>';
733f3f0262cSandi    }else{
734f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
735f3f0262cSandi    }
736f3f0262cSandi    return $ret;
737f3f0262cSandi}
738f3f0262cSandi
739f3f0262cSandi/**
740cb70c441Sandi * Index List item
741cb70c441Sandi *
742cb70c441Sandi * This user function is used in html_build_lidt to build the
743cb70c441Sandi * <li> tags for namespaces when displaying the page index
744cb70c441Sandi * it gives different classes to opened or closed "folders"
745cb70c441Sandi *
746cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
747cb70c441Sandi */
748cb70c441Sandifunction html_li_index($item){
749cb70c441Sandi    if($item['type'] == "f"){
750cb70c441Sandi        return '<li class="level'.$item['level'].'">';
751cb70c441Sandi    }elseif($item['open']){
752cb70c441Sandi        return '<li class="open">';
753cb70c441Sandi    }else{
754cb70c441Sandi        return '<li class="closed">';
755cb70c441Sandi    }
756cb70c441Sandi}
757cb70c441Sandi
758cb70c441Sandi/**
759cb70c441Sandi * Default List item
760cb70c441Sandi *
761cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
762cb70c441Sandi */
763cb70c441Sandifunction html_li_default($item){
764cb70c441Sandi    return '<li class="level'.$item['level'].'">';
765cb70c441Sandi}
766cb70c441Sandi
767cb70c441Sandi/**
76815fae107Sandi * Build an unordered list
76915fae107Sandi *
770f3f0262cSandi * Build an unordered list from the given $data array
771f3f0262cSandi * Each item in the array has to have a 'level' property
772f3f0262cSandi * the item itself gets printed by the given $func user
773cb70c441Sandi * function. The second and optional function is used to
774cb70c441Sandi * print the <li> tag. Both user function need to accept
775cb70c441Sandi * a single item.
77615fae107Sandi *
777c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
778c5a8fd96SAndreas Gohr * a member of an object.
779c5a8fd96SAndreas Gohr *
78015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
781f3f0262cSandi */
782cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
783f3f0262cSandi    $level = 0;
784f3f0262cSandi    $opens = 0;
785f3f0262cSandi    $ret   = '';
786f3f0262cSandi
787f3f0262cSandi    foreach ($data as $item){
788f3f0262cSandi
789f3f0262cSandi        if( $item['level'] > $level ){
790f3f0262cSandi            //open new list
791df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
792df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
793f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
794df52d0feSandi            }
795f3f0262cSandi        }elseif( $item['level'] < $level ){
796f3f0262cSandi            //close last item
797f3f0262cSandi            $ret .= "</li>\n";
798f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
799f3f0262cSandi                //close higher lists
800f3f0262cSandi                $ret .= "</ul>\n</li>\n";
801f3f0262cSandi            }
802f3f0262cSandi        }else{
803f3f0262cSandi            //close last item
804f3f0262cSandi            $ret .= "</li>\n";
805f3f0262cSandi        }
806f3f0262cSandi
807f3f0262cSandi        //remember current level
808f3f0262cSandi        $level = $item['level'];
809f3f0262cSandi
810f3f0262cSandi        //print item
81134dbe711Schris        $ret .= call_user_func($lifunc,$item);
8120c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
81334dbe711Schris
81434dbe711Schris        $ret .= call_user_func($func,$item);
8150c6b58a8SAndreas Gohr        $ret .= '</div>';
816f3f0262cSandi    }
817f3f0262cSandi
818f3f0262cSandi    //close remaining items and lists
819f3f0262cSandi    for ($i=0; $i < $level; $i++){
820f3f0262cSandi        $ret .= "</li></ul>\n";
821f3f0262cSandi    }
822f3f0262cSandi
823f3f0262cSandi    return $ret;
824f3f0262cSandi}
825f3f0262cSandi
82615fae107Sandi/**
82715fae107Sandi * display backlinks
82815fae107Sandi *
82915fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
83011df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
83115fae107Sandi */
832f3f0262cSandifunction html_backlinks(){
83354f4c056SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
834f3f0262cSandi    global $ID;
835f3f0262cSandi    global $conf;
83611df47ecSMichael Klier    global $lang;
837f3f0262cSandi
838c112d578Sandi    print p_locale_xhtml('backlinks');
839f3f0262cSandi
84054f4c056SAndreas Gohr    $data = ft_backlinks($ID);
841f3f0262cSandi
84211df47ecSMichael Klier    if(!empty($data)) {
843f3f0262cSandi        print '<ul class="idx">';
84454f4c056SAndreas Gohr        foreach($data as $blink){
8450c6b58a8SAndreas Gohr            print '<li><div class="li">';
846db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8470c6b58a8SAndreas Gohr            print '</div></li>';
848f3f0262cSandi        }
849f3f0262cSandi        print '</ul>';
85011df47ecSMichael Klier    } else {
85111df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
85211df47ecSMichael Klier    }
853f3f0262cSandi}
854f3f0262cSandi
85515fae107Sandi/**
85615fae107Sandi * show diff
85715fae107Sandi *
85815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
85915fae107Sandi */
860f3f0262cSandifunction html_diff($text='',$intro=true){
861ed7b5f09Sandi    require_once(DOKU_INC.'inc/DifferenceEngine.php');
862f3f0262cSandi    global $ID;
863f3f0262cSandi    global $REV;
864f3f0262cSandi    global $lang;
865f3f0262cSandi    global $conf;
866e1bd90ffSAndreas Gohr
86777707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
86877707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
86977707b04SAndreas Gohr    // array in rev2.
87077707b04SAndreas Gohr    $rev1 = $REV;
8717b3f8b16SAndreas Gohr
87277707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
87377707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
87477707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
87554041c77SAndreas Gohr
87654041c77SAndreas Gohr        if(!$rev1){
87754041c77SAndreas Gohr            $rev1 = $rev2;
87854041c77SAndreas Gohr            unset($rev2);
87954041c77SAndreas Gohr        }
880f3f0262cSandi    }else{
88177707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
8824d58bd99Sandi    }
8834d58bd99Sandi
88477707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
88577707b04SAndreas Gohr        $l_rev   = '';
88677707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
88777707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
888f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
88977707b04SAndreas Gohr            $lang['current'];
89077707b04SAndreas Gohr
89177707b04SAndreas Gohr        $r_rev   = '';
89277707b04SAndreas Gohr        $r_text  = cleanText($text);
89377707b04SAndreas Gohr        $r_head  = $lang['yours'];
894e1bd90ffSAndreas Gohr    }else{
89577707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
89654041c77SAndreas Gohr            // make sure order is correct (older on the left)
89777707b04SAndreas Gohr            if($rev1 < $rev2){
89877707b04SAndreas Gohr                $l_rev = $rev1;
89977707b04SAndreas Gohr                $r_rev = $rev2;
90077707b04SAndreas Gohr            }else{
90177707b04SAndreas Gohr                $l_rev = $rev2;
90277707b04SAndreas Gohr                $r_rev = $rev1;
903e1bd90ffSAndreas Gohr            }
90477707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
90577707b04SAndreas Gohr            $r_rev = '';
90677707b04SAndreas Gohr            $l_rev = $rev1;
90777707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
90877707b04SAndreas Gohr            $r_rev = '';
90977707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
91077707b04SAndreas Gohr            $l_rev = $revs[0];
9116f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
91277707b04SAndreas Gohr        }
91377707b04SAndreas Gohr
9147b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9157b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9167b3f8b16SAndreas Gohr            $l_text = '';
9177b3f8b16SAndreas Gohr        }else{
91877707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9197b3f8b16SAndreas Gohr        }
92077707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
92177707b04SAndreas Gohr
9227b3f8b16SAndreas Gohr        if(!$l_rev){
9237b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9247b3f8b16SAndreas Gohr        }else{
925e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
926db959ae3SAndreas Gohr            if($l_info['user']){
927db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
928e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
929db959ae3SAndreas Gohr            } else {
930db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
931db959ae3SAndreas Gohr            }
932e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
933e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
934e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
935e5e61eb0SAnika Henke
93677707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
937f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
938e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9397b3f8b16SAndreas Gohr        }
94077707b04SAndreas Gohr
94177707b04SAndreas Gohr        if($r_rev){
942e5e61eb0SAnika Henke            $r_info   = getRevisionInfo($ID,$r_rev,true);
943db959ae3SAndreas Gohr            if($r_info['user']){
944db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
945e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
946db959ae3SAndreas Gohr            } else {
947db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
948db959ae3SAndreas Gohr            }
949e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
950e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
951e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
952e5e61eb0SAnika Henke
95377707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
954f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
955e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9567b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
957e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
958db959ae3SAndreas Gohr            if($_info['user']){
959db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
960e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
961db959ae3SAndreas Gohr            } else {
962db959ae3SAndreas Gohr                $_user = $_info['ip'];
963db959ae3SAndreas Gohr            }
964e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
965e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
966e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
967e5e61eb0SAnika Henke
96877707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
969f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
970658b1aa0SAnika Henke            '('.$lang['current'].')'.
971e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9727b3f8b16SAndreas Gohr        }else{
973658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
974f3f0262cSandi        }
97577707b04SAndreas Gohr    }
97677707b04SAndreas Gohr
97777707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
97877707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
97977707b04SAndreas Gohr
980f3f0262cSandi    $tdf = new TableDiffFormatter();
981c112d578Sandi    if($intro) print p_locale_xhtml('diff');
982f3f0262cSandi    ?>
983daf4ca4eSAnika Henke    <table class="diff">
984f3f0262cSandi    <tr>
985e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
98677707b04SAndreas Gohr    <?php echo $l_head?>
987daf4ca4eSAnika Henke    </th>
988e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
98977707b04SAndreas Gohr    <?php echo $r_head?>
990daf4ca4eSAnika Henke    </th>
991f3f0262cSandi    </tr>
9924da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
993f3f0262cSandi    </table>
9944da078a3Smatthiasgrimm    <?php
995f3f0262cSandi}
996f3f0262cSandi
99715fae107Sandi/**
99815fae107Sandi * show warning on conflict detection
99915fae107Sandi *
100015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
100115fae107Sandi */
1002f3f0262cSandifunction html_conflict($text,$summary){
1003f3f0262cSandi    global $ID;
1004f3f0262cSandi    global $lang;
1005f3f0262cSandi
1006c112d578Sandi    print p_locale_xhtml('conflict');
1007e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1008fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1009fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1010fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1011fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1012fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1013fdb8d77bSTom N Harris    html_form('conflict', $form);
1014fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1015f3f0262cSandi}
1016f3f0262cSandi
1017f3f0262cSandi/**
101815fae107Sandi * Prints the global message array
101915fae107Sandi *
102015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1021f3f0262cSandi */
1022f3f0262cSandifunction html_msgarea(){
1023f3f0262cSandi    global $MSG;
1024f3f0262cSandi    if(!isset($MSG)) return;
1025f3f0262cSandi
10264af9f0d4SAndreas Gohr    $shown = array();
1027f3f0262cSandi    foreach($MSG as $msg){
10284af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10294af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1030f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1031f3f0262cSandi        print $msg['msg'];
1032f3f0262cSandi        print '</div>';
10334af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1034f3f0262cSandi    }
1035f3f0262cSandi}
1036f3f0262cSandi
1037f3f0262cSandi/**
1038f3f0262cSandi * Prints the registration form
103915fae107Sandi *
104015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1041f3f0262cSandi */
1042f3f0262cSandifunction html_register(){
1043f3f0262cSandi    global $lang;
1044cab2716aSmatthias.grimm    global $conf;
1045f3f0262cSandi    global $ID;
1046f3f0262cSandi
1047c112d578Sandi    print p_locale_xhtml('register');
1048fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1049e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1050fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1051fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1052fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1053fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1054cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1055fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1056fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1057cab2716aSmatthias.grimm    }
1058fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1059fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1060fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1061fdb8d77bSTom N Harris    $form->endFieldset();
1062fdb8d77bSTom N Harris    html_form('register', $form);
1063cab2716aSmatthias.grimm
1064fdb8d77bSTom N Harris    print '</div>'.NL;
1065f3f0262cSandi}
1066f3f0262cSandi
1067f3f0262cSandi/**
10688b06d178Schris * Print the update profile form
10698b06d178Schris *
10708b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10718b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10728b06d178Schris */
10738b06d178Schrisfunction html_updateprofile(){
10748b06d178Schris    global $lang;
10758b06d178Schris    global $conf;
10768b06d178Schris    global $ID;
10778b06d178Schris    global $INFO;
107882fd59b6SAndreas Gohr    global $auth;
10798b06d178Schris
10808b06d178Schris    print p_locale_xhtml('updateprofile');
10818b06d178Schris
10828b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10838b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1084fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1085e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1086fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1087fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1088fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1089fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1090fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1091fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1092fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
109339ba8890SAndreas Gohr    $attr = array('size'=>'50');
109439ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1095fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1096fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1097fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1098fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1099fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1100fdb8d77bSTom N Harris    }
1101fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1102fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1103fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1104fdb8d77bSTom N Harris    }
1105fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1106fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1107fdb8d77bSTom N Harris    $form->endFieldset();
1108fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1109fdb8d77bSTom N Harris    print '</div>'.NL;
11108b06d178Schris}
11118b06d178Schris
11128b06d178Schris/**
11137c4635c4SAdrian Lang * Preprocess edit form data
111415fae107Sandi *
1115016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
111615fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1117f3f0262cSandi */
1118f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1119f3f0262cSandi    global $ID;
1120f3f0262cSandi    global $REV;
1121f3f0262cSandi    global $DATE;
1122f3f0262cSandi    global $RANGE;
1123f3f0262cSandi    global $PRE;
1124f3f0262cSandi    global $SUF;
1125f3f0262cSandi    global $INFO;
1126f3f0262cSandi    global $SUM;
1127f3f0262cSandi    global $lang;
1128f3f0262cSandi    global $conf;
1129f3f0262cSandi
1130f3f0262cSandi    //set summary default
1131f3f0262cSandi    if(!$SUM){
1132f3f0262cSandi        if($REV){
1133f3f0262cSandi            $SUM = $lang['restored'];
1134f3f0262cSandi        }elseif(!$INFO['exists']){
1135f3f0262cSandi            $SUM = $lang['created'];
1136f3f0262cSandi        }
1137f3f0262cSandi    }
1138f3f0262cSandi
1139f3f0262cSandi    //no text? Load it!
1140f3f0262cSandi    if(!isset($text)){
1141f3f0262cSandi        $pr = false; //no preview mode
11427146cee2SAndreas Gohr        if($INFO['exists']){
1143f3f0262cSandi            if($RANGE){
1144f3f0262cSandi                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1145f3f0262cSandi            }else{
1146f3f0262cSandi                $text = rawWiki($ID,$REV);
1147f3f0262cSandi            }
11488fe3bb00STom N Harris            $check = md5($text);
11498fe3bb00STom N Harris            $mod = false;
1150f3f0262cSandi        }else{
11517146cee2SAndreas Gohr            //try to load a pagetemplate
1152b7d5a5f0SAndreas Gohr            $data = array($ID);
1153016b6153SAndreas Gohr            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
11548fe3bb00STom N Harris            $check = md5('');
11558fe3bb00STom N Harris            $mod = $text!=='';
11567146cee2SAndreas Gohr        }
11577146cee2SAndreas Gohr    }else{
1158f3f0262cSandi        $pr = true; //preview mode
11598fe3bb00STom N Harris        if (isset($_REQUEST['changecheck'])) {
11608fe3bb00STom N Harris            $check = $_REQUEST['changecheck'];
11618fe3bb00STom N Harris            $mod = md5($text)!==$check;
11628fe3bb00STom N Harris        } else {
11638fe3bb00STom N Harris            // Why? Assume default text is unmodified.
11648fe3bb00STom N Harris            $check = md5($text);
11658fe3bb00STom N Harris            $mod = false;
11668fe3bb00STom N Harris        }
1167f3f0262cSandi    }
1168f3f0262cSandi
116927eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
1170f3f0262cSandi    if($wr){
1171c112d578Sandi        if ($REV) print p_locale_xhtml('editrev');
1172c112d578Sandi        print p_locale_xhtml($include);
1173f3f0262cSandi    }else{
1174409d7af7SAndreas Gohr        // check pseudo action 'source'
1175409d7af7SAndreas Gohr        if(!actionOK('source')){
1176409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1177409d7af7SAndreas Gohr            return;
1178409d7af7SAndreas Gohr        }
1179c112d578Sandi        print p_locale_xhtml('read');
1180f3f0262cSandi    }
1181f3f0262cSandi    if(!$DATE) $DATE = $INFO['lastmod'];
11827c4635c4SAdrian Lang
11837c4635c4SAdrian Lang    $data = compact('wr', 'text', 'mod', 'check');
11847c4635c4SAdrian Lang    trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
11857c4635c4SAdrian Lang}
11867c4635c4SAdrian Lang
11877c4635c4SAdrian Lang/**
11887c4635c4SAdrian Lang * Display the default edit form
11897c4635c4SAdrian Lang *
11907c4635c4SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
11917c4635c4SAdrian Lang *
11927c4635c4SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
11937c4635c4SAdrian Lang */
11947c4635c4SAdrian Langfunction html_edit_form($param) {
11957c4635c4SAdrian Lang    extract($param);
11967c4635c4SAdrian Lang    global $conf;
11977c4635c4SAdrian Lang    global $license;
11987c4635c4SAdrian Lang    global $lang;
11997c4635c4SAdrian Lang    global $REV;
12007c4635c4SAdrian Lang    global $DATE;
12017c4635c4SAdrian Lang    global $PRE;
12027c4635c4SAdrian Lang    global $SUF;
12037c4635c4SAdrian Lang    global $INFO;
12047c4635c4SAdrian Lang    global $SUM;
12057c4635c4SAdrian Lang    global $ID;
1206f3f0262cSandi    ?>
12077c4635c4SAdrian Lang            <?php if($wr){?>
12087c4635c4SAdrian Lang                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
12097c4635c4SAdrian Lang                    <?php /* sets changed to true when previewed */?>
12107c4635c4SAdrian Lang                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
12117c4635c4SAdrian Lang                //--><!]]></script>
12127c4635c4SAdrian Lang            <?php } ?>
121363afe2a6SAnika Henke        <div style="width:99%;">
121442c7abd6SAndreas Gohr
121563afe2a6SAnika Henke        <div class="toolbar">
1216f2263577SAndreas Gohr        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1217fdb8d77bSTom N Harris        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1218409d7af7SAndreas Gohr            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
121920d062caSAndreas Gohr
122063afe2a6SAnika Henke        </div>
12214da078a3Smatthiasgrimm        <?php
1222e351c80dSAdrian Lang        $form = new Doku_Form(array('id' => 'dw__editform'));
1223fdb8d77bSTom N Harris        $form->addHidden('id', $ID);
1224fdb8d77bSTom N Harris        $form->addHidden('rev', $REV);
1225fdb8d77bSTom N Harris        $form->addHidden('date', $DATE);
1226fdb8d77bSTom N Harris        $form->addHidden('prefix', $PRE);
1227fdb8d77bSTom N Harris        $form->addHidden('suffix', $SUF);
1228fdb8d77bSTom N Harris        $form->addHidden('changecheck', $check);
1229fdb8d77bSTom N Harris        $attr = array('tabindex'=>'1');
1230fdb8d77bSTom N Harris        if (!$wr) $attr['readonly'] = 'readonly';
1231fdb8d77bSTom N Harris        $form->addElement(form_makeWikiText($text, $attr));
1232fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1233fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1234fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1235fdb8d77bSTom N Harris        if ($wr) {
1236fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1237fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1238fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1239fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1240fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1241fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1242fdb8d77bSTom N Harris            $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1243fdb8d77bSTom N Harris            $elem = html_minoredit();
1244fdb8d77bSTom N Harris            if ($elem) $form->addElement($elem);
1245fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1246fdb8d77bSTom N Harris        }
1247fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
12485808bc54SAndreas Gohr        if($wr && $conf['license']){
1249066fee30SAndreas Gohr            $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1250066fee30SAndreas Gohr            $out  = $lang['licenseok'];
1251066fee30SAndreas Gohr            $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1252c0322273SAdrian Lang            if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1253066fee30SAndreas Gohr            $out .= '> '.$license[$conf['license']]['name'].'</a>';
1254066fee30SAndreas Gohr            $form->addElement($out);
1255066fee30SAndreas Gohr            $form->addElement(form_makeCloseTag('div'));
1256066fee30SAndreas Gohr        }
1257fdb8d77bSTom N Harris        html_form('edit', $form);
1258fdb8d77bSTom N Harris        print '</div>'.NL;
1259f3f0262cSandi}
1260f3f0262cSandi
1261f3f0262cSandi/**
1262b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1263b6912aeaSAndreas Gohr *
1264b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1265b6912aeaSAndreas Gohr */
1266b6912aeaSAndreas Gohrfunction html_minoredit(){
1267b6912aeaSAndreas Gohr    global $conf;
1268b6912aeaSAndreas Gohr    global $lang;
1269b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1270b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1271fdb8d77bSTom N Harris        return false;
1272b6912aeaSAndreas Gohr    }
1273b6912aeaSAndreas Gohr
1274b6912aeaSAndreas Gohr    $p = array();
1275b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1276bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1277fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1278b6912aeaSAndreas Gohr}
1279b6912aeaSAndreas Gohr
1280b6912aeaSAndreas Gohr/**
1281f3f0262cSandi * prints some debug info
128215fae107Sandi *
128315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1284f3f0262cSandi */
1285f3f0262cSandifunction html_debug(){
1286f3f0262cSandi    global $conf;
1287d16a4edaSandi    global $lang;
12885298a619SAndreas Gohr    global $auth;
1289100a97e3SAndreas Gohr    global $INFO;
1290100a97e3SAndreas Gohr
129128fb55ffSandi    //remove sensitive data
129228fb55ffSandi    $cnf = $conf;
129324297a69SAndreas Gohr    debug_guard($cnf);
1294100a97e3SAndreas Gohr    $nfo = $INFO;
129524297a69SAndreas Gohr    debug_guard($nfo);
1296100a97e3SAndreas Gohr    $ses = $_SESSION;
129724297a69SAndreas Gohr    debug_guard($ses);
1298f3f0262cSandi
1299f3f0262cSandi    print '<html><body>';
1300f3f0262cSandi
1301f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1302f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1303f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1304f3f0262cSandi
1305100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1306100a97e3SAndreas Gohr    print_r($nfo);
1307100a97e3SAndreas Gohr    print '</pre>';
1308100a97e3SAndreas Gohr
1309f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1310f3f0262cSandi    print_r($_SERVER);
1311f3f0262cSandi    print '</pre>';
1312f3f0262cSandi
1313f3f0262cSandi    print '<b>$conf:</b><pre>';
131428fb55ffSandi    print_r($cnf);
1315f3f0262cSandi    print '</pre>';
1316f3f0262cSandi
1317ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1318ed7b5f09Sandi    print DOKU_BASE;
1319f3f0262cSandi    print '</pre>';
1320f3f0262cSandi
1321ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1322ed7b5f09Sandi    print DOKU_URL;
1323ed7b5f09Sandi    print '</pre>';
1324ed7b5f09Sandi
1325ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1326f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1327f3f0262cSandi    print '</pre>';
1328f3f0262cSandi
1329f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1330f3f0262cSandi    print phpversion();
1331f3f0262cSandi    print '</pre>';
1332f3f0262cSandi
1333f3f0262cSandi    print '<b>locale:</b><pre>';
1334f3f0262cSandi    print setlocale(LC_ALL,0);
1335f3f0262cSandi    print '</pre>';
1336f3f0262cSandi
1337d16a4edaSandi    print '<b>encoding:</b><pre>';
1338d16a4edaSandi    print $lang['encoding'];
1339d16a4edaSandi    print '</pre>';
1340d16a4edaSandi
13415298a619SAndreas Gohr    if($auth){
13425298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13435298a619SAndreas Gohr        print_r($auth->cando);
13445298a619SAndreas Gohr        print '</pre>';
13455298a619SAndreas Gohr    }
13465298a619SAndreas Gohr
13473aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1348100a97e3SAndreas Gohr    print_r($ses);
13493aa54d7cSAndreas Gohr    print '</pre>';
13503aa54d7cSAndreas Gohr
1351f3f0262cSandi    print '<b>Environment:</b><pre>';
1352f3f0262cSandi    print_r($_ENV);
1353f3f0262cSandi    print '</pre>';
1354f3f0262cSandi
1355f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1356f3f0262cSandi    $inis = ini_get_all();
1357f3f0262cSandi    print_r($inis);
1358f3f0262cSandi    print '</pre>';
1359f3f0262cSandi
1360f3f0262cSandi    print '</body></html>';
1361f3f0262cSandi}
1362f3f0262cSandi
136310271ce4SAndreas Gohr/**
136410271ce4SAndreas Gohr * List available Administration Tasks
136510271ce4SAndreas Gohr *
136610271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
136710271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
136810271ce4SAndreas Gohr */
1369c19fe9c0Sandifunction html_admin(){
1370c19fe9c0Sandi    global $ID;
1371f8cc712eSAndreas Gohr    global $INFO;
1372c19fe9c0Sandi    global $lang;
1373ca3a6df1SMatthias Grimm    global $conf;
137410271ce4SAndreas Gohr    global $auth;
1375c19fe9c0Sandi
137611e2ce22Schris    // build menu of admin functions from the plugins that handle them
137711e2ce22Schris    $pluginlist = plugin_list('admin');
137811e2ce22Schris    $menu = array();
137911e2ce22Schris    foreach ($pluginlist as $p) {
1380db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1381f8cc712eSAndreas Gohr
1382f8cc712eSAndreas Gohr        // check permissions
1383f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1384f8cc712eSAndreas Gohr
138510271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
138611e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
138711e2ce22Schris                'sort' => $obj->getMenuSort()
138811e2ce22Schris                );
138911e2ce22Schris    }
139011e2ce22Schris
139110271ce4SAndreas Gohr    print p_locale_xhtml('admin');
139210271ce4SAndreas Gohr
139310271ce4SAndreas Gohr    // Admin Tasks
139410271ce4SAndreas Gohr    if($INFO['isadmin']){
139510271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
139610271ce4SAndreas Gohr
139776c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
139810271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
139910271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
140010271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
140110271ce4SAndreas Gohr        }
140210271ce4SAndreas Gohr        unset($menu['usermanager']);
140310271ce4SAndreas Gohr
140476c65fd3SAndreas Gohr        if($menu['acl']){
140510271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
140610271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
140710271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
140876c65fd3SAndreas Gohr        }
140910271ce4SAndreas Gohr        unset($menu['acl']);
141010271ce4SAndreas Gohr
141176c65fd3SAndreas Gohr        if($menu['plugin']){
141210271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
141310271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
141410271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
141576c65fd3SAndreas Gohr        }
141610271ce4SAndreas Gohr        unset($menu['plugin']);
141710271ce4SAndreas Gohr
141876c65fd3SAndreas Gohr        if($menu['config']){
141910271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
142010271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
142110271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
142276c65fd3SAndreas Gohr        }
142310271ce4SAndreas Gohr        unset($menu['config']);
142410271ce4SAndreas Gohr    }
142510271ce4SAndreas Gohr    ptln('</ul>');
142610271ce4SAndreas Gohr
142710271ce4SAndreas Gohr    // Manager Tasks
142810271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
142910271ce4SAndreas Gohr
143076c65fd3SAndreas Gohr    if($menu['revert']){
143110271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
143210271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
143310271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
143476c65fd3SAndreas Gohr    }
143510271ce4SAndreas Gohr    unset($menu['revert']);
143610271ce4SAndreas Gohr
143776c65fd3SAndreas Gohr    if($menu['popularity']){
143810271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
143910271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
144010271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
144176c65fd3SAndreas Gohr    }
144210271ce4SAndreas Gohr    unset($menu['popularity']);
144310271ce4SAndreas Gohr
144410271ce4SAndreas Gohr    ptln('</ul>');
144510271ce4SAndreas Gohr
144610271ce4SAndreas Gohr    // print the rest as sorted list
144710271ce4SAndreas Gohr    if(count($menu)){
1448746855cfSBen Coburn        usort($menu, 'p_sort_modes');
144911e2ce22Schris        // output the menu
145010271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
145110271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
145211e2ce22Schris        ptln('<ul>');
145311e2ce22Schris        foreach ($menu as $item) {
145411e2ce22Schris            if (!$item['prompt']) continue;
14550c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
145611e2ce22Schris        }
145711e2ce22Schris        ptln('</ul>');
1458ca3a6df1SMatthias Grimm    }
145910271ce4SAndreas Gohr}
1460c19fe9c0Sandi
14618b06d178Schris/**
14628b06d178Schris * Form to request a new password for an existing account
14638b06d178Schris *
14648b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
146511e2ce22Schris */
14668b06d178Schrisfunction html_resendpwd() {
14678b06d178Schris    global $lang;
14688b06d178Schris    global $conf;
14698b06d178Schris    global $ID;
1470c19fe9c0Sandi
14718b06d178Schris    print p_locale_xhtml('resendpwd');
1472fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1473e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1474fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1475fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1476fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1477fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1478fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1479fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1480fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1481fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1482fdb8d77bSTom N Harris    $form->endFieldset();
1483fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1484fdb8d77bSTom N Harris    print '</div>'.NL;
1485fdb8d77bSTom N Harris}
1486fdb8d77bSTom N Harris
1487fdb8d77bSTom N Harris/**
1488b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1489b8595a66SAndreas Gohr *
1490b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1491b8595a66SAndreas Gohr */
1492b8595a66SAndreas Gohrfunction html_TOC($toc){
1493b8595a66SAndreas Gohr    if(!count($toc)) return '';
1494b8595a66SAndreas Gohr    global $lang;
1495b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1496b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1497b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1498b8595a66SAndreas Gohr    $out .= $lang['toc'];
1499b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1500b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1501b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1502b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1503b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1504db959ae3SAndreas Gohr    return $out;
1505db959ae3SAndreas Gohr}
1506b8595a66SAndreas Gohr
1507b8595a66SAndreas Gohr/**
1508b8595a66SAndreas Gohr * Callback for html_buildlist
1509b8595a66SAndreas Gohr */
1510b8595a66SAndreas Gohrfunction html_list_toc($item){
1511c66972f2SAdrian Lang    if(isset($item['hid'])){
15127d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15137d91652aSAndreas Gohr    }else{
15147d91652aSAndreas Gohr        $link = $item['link'];
15157d91652aSAndreas Gohr    }
15167d91652aSAndreas Gohr
15177d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1518b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1519b8595a66SAndreas Gohr}
1520b8595a66SAndreas Gohr
1521b8595a66SAndreas Gohr/**
1522b8595a66SAndreas Gohr * Helper function to build TOC items
1523b8595a66SAndreas Gohr *
1524b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1525b8595a66SAndreas Gohr *
1526b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1527b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1528b8595a66SAndreas Gohr * @param int    $level - nesting level
1529b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1530b8595a66SAndreas Gohr */
1531b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1532b8595a66SAndreas Gohr    global $conf;
1533b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1534b8595a66SAndreas Gohr            'title' => $text,
1535b8595a66SAndreas Gohr            'type'  => 'ul',
15362bb0d541Schris            'level' => $level);
1537b8595a66SAndreas Gohr}
1538b8595a66SAndreas Gohr
1539b8595a66SAndreas Gohr/**
1540fdb8d77bSTom N Harris * Output a Doku_Form object.
1541fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1542fdb8d77bSTom N Harris *
1543fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1544fdb8d77bSTom N Harris */
1545fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1546fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1547fdb8d77bSTom N Harris    $form->endFieldset();
1548fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1549fdb8d77bSTom N Harris}
1550fdb8d77bSTom N Harris
1551fdb8d77bSTom N Harris/**
1552fdb8d77bSTom N Harris * Form print function.
1553fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1554fdb8d77bSTom N Harris */
1555fdb8d77bSTom N Harrisfunction html_form_output($data) {
1556fdb8d77bSTom N Harris    $data->printForm();
15578b06d178Schris}
1558340756e4Sandi
155907bf32b2SAndreas Gohr/**
156007bf32b2SAndreas Gohr * Embed a flash object in HTML
156107bf32b2SAndreas Gohr *
156207bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
156307bf32b2SAndreas Gohr * compatble way using valid XHTML
156407bf32b2SAndreas Gohr *
156507bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
156607bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
156707bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
156807bf32b2SAndreas Gohr * $lang['noflash'] is used.
156907bf32b2SAndreas Gohr *
157007bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
157107bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
157207bf32b2SAndreas Gohr *
157307bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
157407bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
157507bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
157607bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
157707bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
157807bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
157907bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
158007bf32b2SAndreas Gohr * @returns string         - the XHTML markup
158107bf32b2SAndreas Gohr */
158207bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
158307bf32b2SAndreas Gohr    global $lang;
158407bf32b2SAndreas Gohr
158507bf32b2SAndreas Gohr    $out = '';
158607bf32b2SAndreas Gohr
158707bf32b2SAndreas Gohr    // prepare the object attributes
158807bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
158907bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1590d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
159107bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
159207bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
159307bf32b2SAndreas Gohr
159407bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
159507bf32b2SAndreas Gohr    $std = $atts;
159607bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
159707bf32b2SAndreas Gohr    $std['data'] = $swf;
159807bf32b2SAndreas Gohr
159907bf32b2SAndreas Gohr    // add object attributes for IE
160007bf32b2SAndreas Gohr    $ie  = $atts;
160107bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
160207bf32b2SAndreas Gohr
160307bf32b2SAndreas Gohr    // open object (with conditional comments)
160407bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
160507bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
160607bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
160707bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
160807bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
160907bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16109ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
161107bf32b2SAndreas Gohr
161207bf32b2SAndreas Gohr    // print params
161307bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
161407bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
161507bf32b2SAndreas Gohr    }
161607bf32b2SAndreas Gohr
161707bf32b2SAndreas Gohr    // add flashvars
161807bf32b2SAndreas Gohr    if(is_array($flashvars)){
1619d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
162007bf32b2SAndreas Gohr    }
162107bf32b2SAndreas Gohr
162207bf32b2SAndreas Gohr    // alternative content
162307bf32b2SAndreas Gohr    if($alt){
162407bf32b2SAndreas Gohr        $out .= $alt.NL;
162507bf32b2SAndreas Gohr    }else{
162607bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
162707bf32b2SAndreas Gohr    }
162807bf32b2SAndreas Gohr
162907bf32b2SAndreas Gohr    // finish
163007bf32b2SAndreas Gohr    $out .= '</object>'.NL;
163107bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
163207bf32b2SAndreas Gohr
163307bf32b2SAndreas Gohr    return $out;
163407bf32b2SAndreas Gohr}
163507bf32b2SAndreas Gohr
1636