xref: /dokuwiki/inc/html.php (revision 8e4da260f71ec0ef3b8559d38fc3f8f22208ec0f)
1ed7b5f09Sandi<?php
215fae107Sandi/**
315fae107Sandi * HTML output functions
415fae107Sandi *
515fae107Sandi * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
615fae107Sandi * @author     Andreas Gohr <andi@splitbrain.org>
715fae107Sandi */
815fae107Sandi
9fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
10e226efe1SAndreas Gohrif(!defined('NL')) define('NL',"\n");
116bbae538Sandirequire_once(DOKU_INC.'inc/parserutils.php');
12fdb8d77bSTom N Harrisrequire_once(DOKU_INC.'inc/form.php');
136bbae538Sandi
14f3f0262cSandi/**
15f3f0262cSandi * Convenience function to quickly build a wikilink
1615fae107Sandi *
1715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
18f3f0262cSandi */
19db959ae3SAndreas Gohrfunction html_wikilink($id,$name=null,$search=''){
20db959ae3SAndreas Gohr    static $xhtml_renderer = null;
21723d78dbSandi    if(is_null($xhtml_renderer)){
227aea91afSChris Smith        $xhtml_renderer = p_get_renderer('xhtml');
23f3f0262cSandi    }
24f3f0262cSandi
25fe9ec250SChris Smith    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
26f3f0262cSandi}
27f3f0262cSandi
28f3f0262cSandi/**
29c19fe9c0Sandi * Helps building long attribute lists
30c19fe9c0Sandi *
31c19fe9c0Sandi * @author Andreas Gohr <andi@splitbrain.org>
32c19fe9c0Sandi */
33c19fe9c0Sandifunction html_attbuild($attributes){
34c19fe9c0Sandi    $ret = '';
35c19fe9c0Sandi    foreach ( $attributes as $key => $value ) {
36e351c80dSAdrian Lang        $ret .= $key.'="'.formText($value).'" ';
37c19fe9c0Sandi    }
38c19fe9c0Sandi    return trim($ret);
39c19fe9c0Sandi}
40c19fe9c0Sandi
41c19fe9c0Sandi/**
42f3f0262cSandi * The loginform
4315fae107Sandi *
4415fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
45f3f0262cSandi */
46f3f0262cSandifunction html_login(){
47f3f0262cSandi    global $lang;
48f3f0262cSandi    global $conf;
49f3f0262cSandi    global $ID;
50cd52f92dSchris    global $auth;
51f3f0262cSandi
52c112d578Sandi    print p_locale_xhtml('login');
53fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
54e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__login'));
55fdb8d77bSTom N Harris    $form->startFieldset($lang['btn_login']);
56fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
57fdb8d77bSTom N Harris    $form->addHidden('do', 'login');
58aab557e9SGina Haeussge    $form->addElement(form_makeTextField('u', ((!$_REQUEST['http_credentials']) ? $_REQUEST['u'] : ''), $lang['user'], 'focus__this', 'block'));
59fdb8d77bSTom N Harris    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
6017f89d7eSMichael Klier    if($conf['rememberme']) {
61fdb8d77bSTom N Harris        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
6217f89d7eSMichael Klier    }
63fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
64fdb8d77bSTom N Harris    $form->endFieldset();
655b62573aSAndreas Gohr
666957b2eaSAndreas Gohr    if($auth && $auth->canDo('addUser') && actionOK('register')){
6776ec5467SMichael Klier        $form->addElement('<p>'
6876ec5467SMichael Klier                          . $lang['reghere']
6976ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>'
7076ec5467SMichael Klier                          . '</p>');
71f3f0262cSandi    }
728b06d178Schris
736957b2eaSAndreas Gohr    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
7476ec5467SMichael Klier        $form->addElement('<p>'
7576ec5467SMichael Klier                          . $lang['pwdforget']
7676ec5467SMichael Klier                          . ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>'
7776ec5467SMichael Klier                          . '</p>');
788b06d178Schris    }
7976ec5467SMichael Klier
8076ec5467SMichael Klier    html_form('login', $form);
81fdb8d77bSTom N Harris    print '</div>'.NL;
82f3f0262cSandi}
83f3f0262cSandi
84f3f0262cSandi/**
8515fae107Sandi * inserts section edit buttons if wanted or removes the markers
8615fae107Sandi *
8715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8815fae107Sandi */
89f3f0262cSandifunction html_secedit($text,$show=true){
90f3f0262cSandi    global $INFO;
9135dae8b0SBen Coburn
9290df9a4dSAdrian Lang    $regexp = '#<!-- EDIT(\d+) ([A-Z]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
93b081e262SAdrian Lang
9440868f2fSAdrian Lang    if(!$INFO['writable'] || !$show || $INFO['rev']){
9540868f2fSAdrian Lang        return preg_replace($regexp,'',$text);
96f3f0262cSandi    }
9735dae8b0SBen Coburn
9840868f2fSAdrian Lang    return preg_replace_callback($regexp,
9940868f2fSAdrian Lang                'html_secedit_button', $text);
10040868f2fSAdrian Lang}
10140868f2fSAdrian Lang
10240868f2fSAdrian Lang/**
10340868f2fSAdrian Lang * prepares section edit button data for event triggering
10440868f2fSAdrian Lang * used as a callback in html_secedit
10540868f2fSAdrian Lang *
10640868f2fSAdrian Lang * @triggers HTML_SECEDIT_BUTTON
10740868f2fSAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
10840868f2fSAdrian Lang */
10940868f2fSAdrian Langfunction html_secedit_button($matches){
110905fa971SAdrian Lang    $data = array('secid'  => $matches[1],
11140868f2fSAdrian Lang                  'target' => strtolower($matches[2]),
11240868f2fSAdrian Lang                  'range'  => $matches[count($matches) - 1]);
11340868f2fSAdrian Lang    if (count($matches) === 5) {
11440868f2fSAdrian Lang        $data['name'] = $matches[3];
11540868f2fSAdrian Lang    }
11640868f2fSAdrian Lang
11740868f2fSAdrian Lang    return trigger_event('HTML_SECEDIT_BUTTON', $data,
11840868f2fSAdrian Lang                         'html_secedit_get_button');
11940868f2fSAdrian Lang}
12040868f2fSAdrian Lang
12140868f2fSAdrian Lang/**
12240868f2fSAdrian Lang * prints a section editing button
12340868f2fSAdrian Lang * used as default action form HTML_SECEDIT_BUTTON
12440868f2fSAdrian Lang *
12540868f2fSAdrian Lang * @author Adrian Lang <lang@cosmocode.de>
12640868f2fSAdrian Lang */
12740868f2fSAdrian Langfunction html_secedit_get_button($data) {
12840868f2fSAdrian Lang    global $ID;
12940868f2fSAdrian Lang    global $INFO;
13040868f2fSAdrian Lang
13140868f2fSAdrian Lang    if (!isset($data['name']) || $data['name'] === '') return;
13240868f2fSAdrian Lang
13340868f2fSAdrian Lang    $name = $data['name'];
13440868f2fSAdrian Lang    unset($data['name']);
13540868f2fSAdrian Lang
136905fa971SAdrian Lang    $secid = $data['secid'];
137905fa971SAdrian Lang    unset($data['secid']);
138905fa971SAdrian Lang
13940868f2fSAdrian Lang    return "<div class='secedit editbutton_" . $data['target'] .
140defa93a1SAdrian Lang                       " editbutton_" . $secid . "'>" .
14140868f2fSAdrian Lang           html_btn('secedit', $ID, '',
14240868f2fSAdrian Lang                    array_merge(array('do'  => 'edit',
14340868f2fSAdrian Lang                                      'rev' => $INFO['lastmod']), $data),
14440868f2fSAdrian Lang                    'post', $name) . '</div>';
145f3f0262cSandi}
146f3f0262cSandi
147f3f0262cSandi/**
148d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1496b13307fSandi *
1506b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1516b13307fSandi */
1526b13307fSandifunction html_topbtn(){
1536b13307fSandi    global $lang;
1546b13307fSandi
1556b13307fSandi    $ret  = '';
15611ea018fSAndreas 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>';
157df7b6005Sandi
1586b13307fSandi    return $ret;
1596b13307fSandi}
1606b13307fSandi
1616b13307fSandi/**
162d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
16335dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
16415fae107Sandi *
16515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
166f3f0262cSandi */
167d822118cSAdrian Langfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
168f3f0262cSandi    global $conf;
169f3f0262cSandi    global $lang;
170f3f0262cSandi
171f3f0262cSandi    $label = $lang['btn_'.$name];
172f3f0262cSandi
173f3f0262cSandi    $ret = '';
17435dae8b0SBen Coburn    $tip = '';
175f3f0262cSandi
17649c713a3Sandi    //filter id (without urlencoding)
17749c713a3Sandi    $id = idfilter($id,false);
178f3f0262cSandi
179f3f0262cSandi    //make nice URLs even for buttons
1806c7843b5Sandi    if($conf['userewrite'] == 2){
1816c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1826c7843b5Sandi    }elseif($conf['userewrite']){
1836c7843b5Sandi        $script = DOKU_BASE.$id;
1846c7843b5Sandi    }else{
1858b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
186f3f0262cSandi        $params['id'] = $id;
187f3f0262cSandi    }
188f3f0262cSandi
189b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
190f3f0262cSandi
19106a4bf8fSAndreas Gohr    if(is_array($params)){
192f3f0262cSandi        reset($params);
193f3f0262cSandi        while (list($key, $val) = each($params)) {
194f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
195f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
196f3f0262cSandi        }
19706a4bf8fSAndreas Gohr    }
198f3f0262cSandi
19935dae8b0SBen Coburn    if ($tooltip!='') {
20035dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
20111ea018fSAndreas Gohr    }else{
20211ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
20311ea018fSAndreas Gohr    }
20411ea018fSAndreas Gohr
205d822118cSAdrian Lang    $ret .= '<input type="submit" value="'.hsc($label).'" class="button" ';
20611ea018fSAndreas Gohr    if($akey){
20707493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
20887cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
20935dae8b0SBen Coburn    }
21035dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
211f3f0262cSandi    $ret .= '/>';
2124beabca9SAnika Henke    $ret .= '</div></form>';
213f3f0262cSandi
214f3f0262cSandi    return $ret;
215f3f0262cSandi}
216f3f0262cSandi
217f3f0262cSandi/**
21815fae107Sandi * show a wiki page
21915fae107Sandi *
22015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
22115fae107Sandi */
2226bbae538Sandifunction html_show($txt=''){
223f3f0262cSandi    global $ID;
224f3f0262cSandi    global $REV;
225f3f0262cSandi    global $HIGH;
226b8595a66SAndreas Gohr    global $INFO;
227f3f0262cSandi    //disable section editing for old revisions or in preview
2285400331dSandi    if($txt || $REV){
2296bbae538Sandi        $secedit = false;
2306bbae538Sandi    }else{
2316bbae538Sandi        $secedit = true;
232f3f0262cSandi    }
233f3f0262cSandi
2346bbae538Sandi    if ($txt){
235f3f0262cSandi        //PreviewHeader
236b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
237b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
238b8595a66SAndreas Gohr        echo '<div class="preview">';
239b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
240b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
241b8595a66SAndreas Gohr        echo $html;
242b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
243b8595a66SAndreas Gohr        echo '</div>';
2446bbae538Sandi
245f3f0262cSandi    }else{
246c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
247c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2486bbae538Sandi        $html = html_secedit($html,$secedit);
249b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
250b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
251b8595a66SAndreas Gohr        echo $html;
252f3f0262cSandi    }
253f3f0262cSandi}
254f3f0262cSandi
255f3f0262cSandi/**
256ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
257ee4c4a1bSAndreas Gohr *
258ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
259ee4c4a1bSAndreas Gohr */
260ee4c4a1bSAndreas Gohrfunction html_draft(){
261ee4c4a1bSAndreas Gohr    global $INFO;
262ee4c4a1bSAndreas Gohr    global $ID;
263ee4c4a1bSAndreas Gohr    global $lang;
264ee4c4a1bSAndreas Gohr    global $conf;
265ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
266ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
267ee4c4a1bSAndreas Gohr
268fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
269e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
270fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
271fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
272fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
273fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
274f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
275fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
276fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
277fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
278fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
279fdb8d77bSTom N Harris    html_form('draft', $form);
280ee4c4a1bSAndreas Gohr}
281ee4c4a1bSAndreas Gohr
282ee4c4a1bSAndreas Gohr/**
283f3f0262cSandi * Highlights searchqueries in HTML code
28415fae107Sandi *
28515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2867209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
287f3f0262cSandi */
288546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
289808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
290808551e3SAndreas Gohr    $regex = join('|',array_map('preg_quote_cb',$phrases));
29160c15d7dSAndreas Gohr
29260c15d7dSAndreas Gohr    if ($regex === '') return $html;
2931db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
294f3f0262cSandi    return $html;
295f3f0262cSandi}
296f3f0262cSandi
297f3f0262cSandi/**
2987209be23SAndreas Gohr * Callback used by html_hilight()
2997209be23SAndreas Gohr *
3007209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
3017209be23SAndreas Gohr */
3027209be23SAndreas Gohrfunction html_hilight_callback($m) {
3037209be23SAndreas Gohr    $hlight = unslash($m[0]);
3047209be23SAndreas Gohr    if ( !isset($m[2])) {
305688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
3067209be23SAndreas Gohr    }
3077209be23SAndreas Gohr    return $hlight;
3087209be23SAndreas Gohr}
3097209be23SAndreas Gohr
3107209be23SAndreas Gohr/**
31115fae107Sandi * Run a search and display the result
31215fae107Sandi *
31315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
314f3f0262cSandi */
315f3f0262cSandifunction html_search(){
316ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
317506fa893SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
318f3f0262cSandi    global $conf;
319f3f0262cSandi    global $QUERY;
320f3f0262cSandi    global $ID;
321f3f0262cSandi    global $lang;
322f3f0262cSandi
323c112d578Sandi    print p_locale_xhtml('searchpage');
324f3f0262cSandi    flush();
325f3f0262cSandi
326d0ab54f6SMichael Klier chi@chimeric.de    //check if search is restricted to namespace
327b42bcfe7Sdaniel.lindgren    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
328d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($match[1]);
329d0ab54f6SMichael Klier chi@chimeric.de    } else {
330d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($QUERY);
331d0ab54f6SMichael Klier chi@chimeric.de    }
332d0ab54f6SMichael Klier chi@chimeric.de
3334d9ff3d5Sandi    //show progressbar
334e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
335e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
336e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
337e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
338e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3399edac8a8SAndreas Gohr    flush();
3404d9ff3d5Sandi
341f3f0262cSandi    //do quick pagesearch
342f3f0262cSandi    $data = array();
343d0ab54f6SMichael Klier chi@chimeric.de
344865c2687SKazutaka Miyasaka    if($id) $data = ft_pageLookup($id);
345f3f0262cSandi    if(count($data)){
346f3f0262cSandi        print '<div class="search_quickresult">';
347746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3484f732f0eSAnika Henke        print '<ul class="search_quickhits">';
349140c93f3SAnika Henke        foreach($data as $id){
3504f732f0eSAnika Henke            print '<li> ';
351bd2f6c2fSAndreas Gohr            $ns = getNS($id);
352bd2f6c2fSAndreas Gohr            if($ns){
353bd2f6c2fSAndreas Gohr                $name = shorten(noNS($id), ' ('.$ns.')',30);
354bd2f6c2fSAndreas Gohr            }else{
355bd2f6c2fSAndreas Gohr                $name = $id;
356bd2f6c2fSAndreas Gohr            }
357bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3584f732f0eSAnika Henke            print '</li> ';
359f3f0262cSandi        }
360140c93f3SAnika Henke        print '</ul> ';
361f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
362f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
363f3f0262cSandi        print '</div>';
364f3f0262cSandi    }
365f3f0262cSandi    flush();
366f3f0262cSandi
367f3f0262cSandi    //do fulltext search
36860c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
369f3f0262cSandi    if(count($data)){
370506fa893SAndreas Gohr        $num = 1;
371506fa893SAndreas Gohr        foreach($data as $id => $cnt){
372f3f0262cSandi            print '<div class="search_result">';
373db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
374865c2687SKazutaka Miyasaka            if($cnt !== 0){
375506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
376bd0293e7SAndreas Gohr                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
37760c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
378506fa893SAndreas Gohr                }
379865c2687SKazutaka Miyasaka                $num++;
380865c2687SKazutaka Miyasaka            }
381f3f0262cSandi            print '</div>';
382506fa893SAndreas Gohr            flush();
383f3f0262cSandi        }
384f3f0262cSandi    }else{
385820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
386f3f0262cSandi    }
3874d9ff3d5Sandi
3884d9ff3d5Sandi    //hide progressbar
389e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
390e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
391e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3929edac8a8SAndreas Gohr    flush();
393f3f0262cSandi}
394f3f0262cSandi
39515fae107Sandi/**
39615fae107Sandi * Display error on locked pages
39715fae107Sandi *
39815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39915fae107Sandi */
400ee20e7d1Sandifunction html_locked(){
401f3f0262cSandi    global $ID;
402f3f0262cSandi    global $conf;
403f3f0262cSandi    global $lang;
40488f522e9Sandi    global $INFO;
405f3f0262cSandi
406c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
407f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
408f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
409f3f0262cSandi
410c112d578Sandi    print p_locale_xhtml('locked');
411f3f0262cSandi    print '<ul>';
4126d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
4130c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
414f3f0262cSandi    print '</ul>';
415f3f0262cSandi}
416f3f0262cSandi
41715fae107Sandi/**
41815fae107Sandi * list old revisions
41915fae107Sandi *
42015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
42171726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
42215fae107Sandi */
42371726d78SBen Coburnfunction html_revisions($first=0){
424f3f0262cSandi    global $ID;
425f3f0262cSandi    global $INFO;
426f3f0262cSandi    global $conf;
427f3f0262cSandi    global $lang;
42871726d78SBen Coburn    /* we need to get one additionally log entry to be able to
42971726d78SBen Coburn     * decide if this is the last page or is there another one.
43071726d78SBen Coburn     * see html_recent()
43171726d78SBen Coburn     */
43271726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
43371726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
43471726d78SBen Coburn        $first=0;
43571726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
43671726d78SBen Coburn    }
43771726d78SBen Coburn    $hasNext = false;
43871726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
43971726d78SBen Coburn        $hasNext = true;
44071726d78SBen Coburn        array_pop($revisions); // remove extra log entry
44171726d78SBen Coburn    }
44271726d78SBen Coburn
443f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
444f3f0262cSandi
445c112d578Sandi    print p_locale_xhtml('revisions');
44637a1dc12Smichael
447e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'page__revisions'));
44837a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
44971726d78SBen Coburn    if($INFO['exists'] && $first==0){
45037a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
45137a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
45237a1dc12Smichael        else
45337a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
45437a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
45537a1dc12Smichael        $form->addElement(form_makeTag('input', array(
45637a1dc12Smichael                        'type' => 'checkbox',
45737a1dc12Smichael                        'name' => 'rev2[]',
45837a1dc12Smichael                        'value' => 'current')));
459f9b2fe70Sandi
46037a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
46137a1dc12Smichael        $form->addElement($date);
46237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
463f9b2fe70Sandi
46437a1dc12Smichael        $form->addElement(form_makeTag('img', array(
46537a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
46637a1dc12Smichael                        'width' => '15',
46737a1dc12Smichael                        'height' => '11',
46837a1dc12Smichael                        'alt'    => '')));
469cffcc403Sandi
47037a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
47137a1dc12Smichael                        'class' => 'wikilink1',
47237a1dc12Smichael                        'href'  => wl($ID))));
47337a1dc12Smichael        $form->addElement($ID);
47437a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
475652610a2Sandi
47637a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
47737a1dc12Smichael        $form->addElement(' &ndash; ');
47837a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
47937a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
480652610a2Sandi
48137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
48237a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
48337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
48437a1dc12Smichael
48537a1dc12Smichael        $form->addElement('('.$lang['current'].')');
48637a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
48737a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
488f3f0262cSandi    }
489f3f0262cSandi
490f3f0262cSandi    foreach($revisions as $rev){
491f2263577SAndreas Gohr        $date   = dformat($rev);
492fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
493103c256aSChris Smith        $exists = page_exists($ID,$rev);
494652610a2Sandi
49537a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
49637a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
49737a1dc12Smichael        else
49837a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
49937a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
50077707b04SAndreas Gohr        if($exists){
50137a1dc12Smichael            $form->addElement(form_makeTag('input', array(
50237a1dc12Smichael                            'type' => 'checkbox',
50337a1dc12Smichael                            'name' => 'rev2[]',
50437a1dc12Smichael                            'value' => $rev)));
50577707b04SAndreas Gohr        }else{
50637a1dc12Smichael            $form->addElement(form_makeTag('img', array(
50737a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
50837a1dc12Smichael                            'width' => 14,
50937a1dc12Smichael                            'height' => 11,
51037a1dc12Smichael                            'alt' => '')));
51141396b71SAndreas Gohr        }
512f9b2fe70Sandi
51337a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
51437a1dc12Smichael        $form->addElement($date);
51537a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
51637a1dc12Smichael
51737a1dc12Smichael        if($exists){
51837a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
51937a1dc12Smichael            $form->addElement(form_makeTag('img', array(
52037a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
52137a1dc12Smichael                            'width'  => 15,
52237a1dc12Smichael                            'height' => 11,
52337a1dc12Smichael                            'title'  => $lang['diff'],
52437a1dc12Smichael                            'alt'    => $lang['diff'])));
52537a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
52637a1dc12Smichael
52737a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
52837a1dc12Smichael            $form->addElement($ID);
52937a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
53037a1dc12Smichael        }else{
53137a1dc12Smichael            $form->addElement(form_makeTag('img', array(
53237a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
53337a1dc12Smichael                            'width' => '15',
53437a1dc12Smichael                            'height' => '11',
53537a1dc12Smichael                            'alt'   => '')));
53637a1dc12Smichael            $form->addElement($ID);
53737a1dc12Smichael        }
53837a1dc12Smichael
53937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
54037a1dc12Smichael        $form->addElement(' &ndash; ');
54137a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
54237a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
54337a1dc12Smichael
54437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
54588f522e9Sandi        if($info['user']){
54637a1dc12Smichael            $form->addElement(editorinfo($info['user']));
547433efb25SAndreas Gohr            if(auth_ismanager()){
548433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
549433efb25SAndreas Gohr            }
55088f522e9Sandi        }else{
55137a1dc12Smichael            $form->addElement($info['ip']);
55288f522e9Sandi        }
55337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
554652610a2Sandi
55537a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
55637a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
557f3f0262cSandi    }
55837a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
55937a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
56037a1dc12Smichael    html_form('revisions', $form);
56171726d78SBen Coburn
56271726d78SBen Coburn    print '<div class="pagenav">';
56371726d78SBen Coburn    $last = $first + $conf['recent'];
56471726d78SBen Coburn    if ($first > 0) {
56571726d78SBen Coburn        $first -= $conf['recent'];
56671726d78SBen Coburn        if ($first < 0) $first = 0;
56771726d78SBen Coburn        print '<div class="pagenav-prev">';
568eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
56971726d78SBen Coburn        print '</div>';
57071726d78SBen Coburn    }
57171726d78SBen Coburn    if ($hasNext) {
57271726d78SBen Coburn        print '<div class="pagenav-next">';
573eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
57471726d78SBen Coburn        print '</div>';
57571726d78SBen Coburn    }
57671726d78SBen Coburn    print '</div>';
57771726d78SBen Coburn
578f3f0262cSandi}
579f3f0262cSandi
58015fae107Sandi/**
58115fae107Sandi * display recent changes
58215fae107Sandi *
58315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5845749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
58571726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
58615fae107Sandi */
587a39955b0Smatthiasgrimmfunction html_recent($first=0){
588f3f0262cSandi    global $conf;
589cffcc403Sandi    global $lang;
590dbb00abcSEsther Brunner    global $ID;
5915749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5925749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5935749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5945749f1ceSmatthiasgrimm     */
595b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5965749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5975749f1ceSmatthiasgrimm        $first=0;
59871726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5995749f1ceSmatthiasgrimm    }
60071726d78SBen Coburn    $hasNext = false;
60171726d78SBen Coburn    if (count($recents)>$conf['recent']) {
60271726d78SBen Coburn        $hasNext = true;
60371726d78SBen Coburn        array_pop($recents); // remove extra log entry
60471726d78SBen Coburn    }
605f3f0262cSandi
606c112d578Sandi    print p_locale_xhtml('recent');
607e83cef14SGina Haeussge
608e83cef14SGina Haeussge    if (getNS($ID) != '')
6099e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
610e83cef14SGina Haeussge
611e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET'));
612abdcc39fSmichael    $form->addHidden('sectok', null);
613abdcc39fSmichael    $form->addHidden('do', 'recent');
614abdcc39fSmichael    $form->addHidden('id', $ID);
615abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
616a39955b0Smatthiasgrimm
617d437bcc4SAndreas Gohr    foreach($recents as $recent){
618f2263577SAndreas Gohr        $date = dformat($recent['date']);
619abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
620abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
621abdcc39fSmichael        else
622abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
623cffcc403Sandi
624abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
625f9b2fe70Sandi
626abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
627abdcc39fSmichael        $form->addElement($date);
628abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
629cffcc403Sandi
630cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
631abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
632abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
633abdcc39fSmichael                        'width' => 15,
634abdcc39fSmichael                        'height'=> 11,
635abdcc39fSmichael                        'title' => $lang['diff'],
636abdcc39fSmichael                        'alt'   => $lang['diff']
637abdcc39fSmichael                        )));
638abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
639cffcc403Sandi
640cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
641abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
642abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
643abdcc39fSmichael                        'width' => 12,
644abdcc39fSmichael                        'height'=> 14,
645abdcc39fSmichael                        'title' => $lang['btn_revs'],
646abdcc39fSmichael                        'alt'   => $lang['btn_revs']
647abdcc39fSmichael                        )));
648abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
649b6912aeaSAndreas Gohr
650db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
651abdcc39fSmichael
652abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
653abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
654abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
655abdcc39fSmichael
656abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
657d437bcc4SAndreas Gohr        if($recent['user']){
658abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
659433efb25SAndreas Gohr            if(auth_ismanager()){
660433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
661433efb25SAndreas Gohr            }
66288f522e9Sandi        }else{
663abdcc39fSmichael            $form->addElement($recent['ip']);
66488f522e9Sandi        }
665abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
666cffcc403Sandi
667abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
668abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
669f3f0262cSandi    }
670abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
671a39955b0Smatthiasgrimm
672abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6735749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
674a39955b0Smatthiasgrimm    if ($first > 0) {
675a39955b0Smatthiasgrimm        $first -= $conf['recent'];
676a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
677abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
678abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
679abdcc39fSmichael                    'type'  => 'submit',
680abdcc39fSmichael                    'name'  => 'first['.$first.']',
681cddd152cSmichael                    'value' => $lang['btn_newer'],
682cddd152cSmichael                    'accesskey' => 'n',
683f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
68418d107cbSMichael Klier                    'class' => 'button'
685abdcc39fSmichael                    )));
686abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
687a39955b0Smatthiasgrimm    }
68871726d78SBen Coburn    if ($hasNext) {
689abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
690abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
691abdcc39fSmichael                        'type'  => 'submit',
692abdcc39fSmichael                        'name'  => 'first['.$last.']',
693cddd152cSmichael                        'value' => $lang['btn_older'],
694cddd152cSmichael                        'accesskey' => 'p',
695f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
69618d107cbSMichael Klier                        'class' => 'button'
697abdcc39fSmichael                        )));
698abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
699a39955b0Smatthiasgrimm    }
700abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
701abdcc39fSmichael    html_form('recent', $form);
702f3f0262cSandi}
703f3f0262cSandi
70415fae107Sandi/**
70515fae107Sandi * Display page index
70615fae107Sandi *
70715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
70815fae107Sandi */
709f3f0262cSandifunction html_index($ns){
710ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
711f3f0262cSandi    global $conf;
712f3f0262cSandi    global $ID;
713f3f0262cSandi    $dir = $conf['datadir'];
714f3f0262cSandi    $ns  = cleanID($ns);
71530f1737dSandi    #fixme use appropriate function
716f3f0262cSandi    if(empty($ns)){
717f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
718f3f0262cSandi        if($ns == '.') $ns ='';
719f3f0262cSandi    }
72088d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
721f3f0262cSandi
722a06884abSAndreas Gohr    echo p_locale_xhtml('index');
723a06884abSAndreas Gohr    echo '<div id="index__tree">';
724f3f0262cSandi
725f3f0262cSandi    $data = array();
726f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
727a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
728a06884abSAndreas Gohr
729a06884abSAndreas Gohr    echo '</div>';
730f3f0262cSandi}
731f3f0262cSandi
732f3f0262cSandi/**
73315fae107Sandi * Index item formatter
73415fae107Sandi *
735f3f0262cSandi * User function for html_buildlist()
73615fae107Sandi *
73715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
738f3f0262cSandi */
739f3f0262cSandifunction html_list_index($item){
740d98d4540SBen Coburn    global $ID;
741f3f0262cSandi    $ret = '';
742f3f0262cSandi    $base = ':'.$item['id'];
743f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
744f3f0262cSandi    if($item['type']=='d'){
7454a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
746f3f0262cSandi        $ret .= $base;
747ed7ecb79SAnika Henke        $ret .= '</strong></a>';
748f3f0262cSandi    }else{
749f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
750f3f0262cSandi    }
751f3f0262cSandi    return $ret;
752f3f0262cSandi}
753f3f0262cSandi
754f3f0262cSandi/**
755cb70c441Sandi * Index List item
756cb70c441Sandi *
757cb70c441Sandi * This user function is used in html_build_lidt to build the
758cb70c441Sandi * <li> tags for namespaces when displaying the page index
759cb70c441Sandi * it gives different classes to opened or closed "folders"
760cb70c441Sandi *
761cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
762cb70c441Sandi */
763cb70c441Sandifunction html_li_index($item){
764cb70c441Sandi    if($item['type'] == "f"){
765cb70c441Sandi        return '<li class="level'.$item['level'].'">';
766cb70c441Sandi    }elseif($item['open']){
767cb70c441Sandi        return '<li class="open">';
768cb70c441Sandi    }else{
769cb70c441Sandi        return '<li class="closed">';
770cb70c441Sandi    }
771cb70c441Sandi}
772cb70c441Sandi
773cb70c441Sandi/**
774cb70c441Sandi * Default List item
775cb70c441Sandi *
776cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
777cb70c441Sandi */
778cb70c441Sandifunction html_li_default($item){
779cb70c441Sandi    return '<li class="level'.$item['level'].'">';
780cb70c441Sandi}
781cb70c441Sandi
782cb70c441Sandi/**
78315fae107Sandi * Build an unordered list
78415fae107Sandi *
785f3f0262cSandi * Build an unordered list from the given $data array
786f3f0262cSandi * Each item in the array has to have a 'level' property
787f3f0262cSandi * the item itself gets printed by the given $func user
788cb70c441Sandi * function. The second and optional function is used to
789cb70c441Sandi * print the <li> tag. Both user function need to accept
790cb70c441Sandi * a single item.
79115fae107Sandi *
792c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
793c5a8fd96SAndreas Gohr * a member of an object.
794c5a8fd96SAndreas Gohr *
79515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
796f3f0262cSandi */
797cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
798f3f0262cSandi    $level = 0;
799f3f0262cSandi    $opens = 0;
800f3f0262cSandi    $ret   = '';
801f3f0262cSandi
802f3f0262cSandi    foreach ($data as $item){
803f3f0262cSandi
804f3f0262cSandi        if( $item['level'] > $level ){
805f3f0262cSandi            //open new list
806df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
807df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
808f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
809df52d0feSandi            }
810f3f0262cSandi        }elseif( $item['level'] < $level ){
811f3f0262cSandi            //close last item
812f3f0262cSandi            $ret .= "</li>\n";
813f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
814f3f0262cSandi                //close higher lists
815f3f0262cSandi                $ret .= "</ul>\n</li>\n";
816f3f0262cSandi            }
817f3f0262cSandi        }else{
818f3f0262cSandi            //close last item
819f3f0262cSandi            $ret .= "</li>\n";
820f3f0262cSandi        }
821f3f0262cSandi
822f3f0262cSandi        //remember current level
823f3f0262cSandi        $level = $item['level'];
824f3f0262cSandi
825f3f0262cSandi        //print item
82634dbe711Schris        $ret .= call_user_func($lifunc,$item);
8270c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
82834dbe711Schris
82934dbe711Schris        $ret .= call_user_func($func,$item);
8300c6b58a8SAndreas Gohr        $ret .= '</div>';
831f3f0262cSandi    }
832f3f0262cSandi
833f3f0262cSandi    //close remaining items and lists
834f3f0262cSandi    for ($i=0; $i < $level; $i++){
835f3f0262cSandi        $ret .= "</li></ul>\n";
836f3f0262cSandi    }
837f3f0262cSandi
838f3f0262cSandi    return $ret;
839f3f0262cSandi}
840f3f0262cSandi
84115fae107Sandi/**
84215fae107Sandi * display backlinks
84315fae107Sandi *
84415fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
84511df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
84615fae107Sandi */
847f3f0262cSandifunction html_backlinks(){
84854f4c056SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
849f3f0262cSandi    global $ID;
850f3f0262cSandi    global $conf;
85111df47ecSMichael Klier    global $lang;
852f3f0262cSandi
853c112d578Sandi    print p_locale_xhtml('backlinks');
854f3f0262cSandi
85554f4c056SAndreas Gohr    $data = ft_backlinks($ID);
856f3f0262cSandi
85711df47ecSMichael Klier    if(!empty($data)) {
858f3f0262cSandi        print '<ul class="idx">';
85954f4c056SAndreas Gohr        foreach($data as $blink){
8600c6b58a8SAndreas Gohr            print '<li><div class="li">';
861db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8620c6b58a8SAndreas Gohr            print '</div></li>';
863f3f0262cSandi        }
864f3f0262cSandi        print '</ul>';
86511df47ecSMichael Klier    } else {
86611df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
86711df47ecSMichael Klier    }
868f3f0262cSandi}
869f3f0262cSandi
87015fae107Sandi/**
87115fae107Sandi * show diff
87215fae107Sandi *
87315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
87415fae107Sandi */
875f3f0262cSandifunction html_diff($text='',$intro=true){
876ed7b5f09Sandi    require_once(DOKU_INC.'inc/DifferenceEngine.php');
877f3f0262cSandi    global $ID;
878f3f0262cSandi    global $REV;
879f3f0262cSandi    global $lang;
880f3f0262cSandi    global $conf;
881e1bd90ffSAndreas Gohr
88277707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
88377707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
88477707b04SAndreas Gohr    // array in rev2.
88577707b04SAndreas Gohr    $rev1 = $REV;
8867b3f8b16SAndreas Gohr
88777707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
88877707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
88977707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
89054041c77SAndreas Gohr
89154041c77SAndreas Gohr        if(!$rev1){
89254041c77SAndreas Gohr            $rev1 = $rev2;
89354041c77SAndreas Gohr            unset($rev2);
89454041c77SAndreas Gohr        }
895f3f0262cSandi    }else{
89677707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
8974d58bd99Sandi    }
8984d58bd99Sandi
89977707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
90077707b04SAndreas Gohr        $l_rev   = '';
90177707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
90277707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
903f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
90477707b04SAndreas Gohr            $lang['current'];
90577707b04SAndreas Gohr
90677707b04SAndreas Gohr        $r_rev   = '';
90777707b04SAndreas Gohr        $r_text  = cleanText($text);
90877707b04SAndreas Gohr        $r_head  = $lang['yours'];
909e1bd90ffSAndreas Gohr    }else{
91077707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
91154041c77SAndreas Gohr            // make sure order is correct (older on the left)
91277707b04SAndreas Gohr            if($rev1 < $rev2){
91377707b04SAndreas Gohr                $l_rev = $rev1;
91477707b04SAndreas Gohr                $r_rev = $rev2;
91577707b04SAndreas Gohr            }else{
91677707b04SAndreas Gohr                $l_rev = $rev2;
91777707b04SAndreas Gohr                $r_rev = $rev1;
918e1bd90ffSAndreas Gohr            }
91977707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
92077707b04SAndreas Gohr            $r_rev = '';
92177707b04SAndreas Gohr            $l_rev = $rev1;
92277707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
92377707b04SAndreas Gohr            $r_rev = '';
92477707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
92577707b04SAndreas Gohr            $l_rev = $revs[0];
9266f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
92777707b04SAndreas Gohr        }
92877707b04SAndreas Gohr
9297b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9307b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9317b3f8b16SAndreas Gohr            $l_text = '';
9327b3f8b16SAndreas Gohr        }else{
93377707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9347b3f8b16SAndreas Gohr        }
93577707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
93677707b04SAndreas Gohr
9377b3f8b16SAndreas Gohr        if(!$l_rev){
9387b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9397b3f8b16SAndreas Gohr        }else{
940e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
941db959ae3SAndreas Gohr            if($l_info['user']){
942db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
943e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
944db959ae3SAndreas Gohr            } else {
945db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
946db959ae3SAndreas Gohr            }
947e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
948e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
949e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
950e5e61eb0SAnika Henke
95177707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
952f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
953e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9547b3f8b16SAndreas Gohr        }
95577707b04SAndreas Gohr
95677707b04SAndreas Gohr        if($r_rev){
957e5e61eb0SAnika Henke            $r_info   = getRevisionInfo($ID,$r_rev,true);
958db959ae3SAndreas Gohr            if($r_info['user']){
959db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
960e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
961db959ae3SAndreas Gohr            } else {
962db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
963db959ae3SAndreas Gohr            }
964e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
965e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
966e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
967e5e61eb0SAnika Henke
96877707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
969f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
970e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9717b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
972e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
973db959ae3SAndreas Gohr            if($_info['user']){
974db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
975e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
976db959ae3SAndreas Gohr            } else {
977db959ae3SAndreas Gohr                $_user = $_info['ip'];
978db959ae3SAndreas Gohr            }
979e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
980e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
981e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
982e5e61eb0SAnika Henke
98377707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
984f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
985658b1aa0SAnika Henke            '('.$lang['current'].')'.
986e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9877b3f8b16SAndreas Gohr        }else{
988658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
989f3f0262cSandi        }
99077707b04SAndreas Gohr    }
99177707b04SAndreas Gohr
99277707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
99377707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
99477707b04SAndreas Gohr
995f3f0262cSandi    $tdf = new TableDiffFormatter();
996c112d578Sandi    if($intro) print p_locale_xhtml('diff');
997f3f0262cSandi    ?>
998daf4ca4eSAnika Henke    <table class="diff">
999f3f0262cSandi    <tr>
1000e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
100177707b04SAndreas Gohr    <?php echo $l_head?>
1002daf4ca4eSAnika Henke    </th>
1003e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
100477707b04SAndreas Gohr    <?php echo $r_head?>
1005daf4ca4eSAnika Henke    </th>
1006f3f0262cSandi    </tr>
10074da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
1008f3f0262cSandi    </table>
10094da078a3Smatthiasgrimm    <?php
1010f3f0262cSandi}
1011f3f0262cSandi
101215fae107Sandi/**
101315fae107Sandi * show warning on conflict detection
101415fae107Sandi *
101515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
101615fae107Sandi */
1017f3f0262cSandifunction html_conflict($text,$summary){
1018f3f0262cSandi    global $ID;
1019f3f0262cSandi    global $lang;
1020f3f0262cSandi
1021c112d578Sandi    print p_locale_xhtml('conflict');
1022e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1023fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1024fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1025fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1026fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1027fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1028fdb8d77bSTom N Harris    html_form('conflict', $form);
1029fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1030f3f0262cSandi}
1031f3f0262cSandi
1032f3f0262cSandi/**
103315fae107Sandi * Prints the global message array
103415fae107Sandi *
103515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1036f3f0262cSandi */
1037f3f0262cSandifunction html_msgarea(){
1038f3f0262cSandi    global $MSG;
1039f3f0262cSandi    if(!isset($MSG)) return;
1040f3f0262cSandi
10414af9f0d4SAndreas Gohr    $shown = array();
1042f3f0262cSandi    foreach($MSG as $msg){
10434af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10444af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1045f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1046f3f0262cSandi        print $msg['msg'];
1047f3f0262cSandi        print '</div>';
10484af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1049f3f0262cSandi    }
1050f3f0262cSandi}
1051f3f0262cSandi
1052f3f0262cSandi/**
1053f3f0262cSandi * Prints the registration form
105415fae107Sandi *
105515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1056f3f0262cSandi */
1057f3f0262cSandifunction html_register(){
1058f3f0262cSandi    global $lang;
1059cab2716aSmatthias.grimm    global $conf;
1060f3f0262cSandi    global $ID;
1061f3f0262cSandi
1062c112d578Sandi    print p_locale_xhtml('register');
1063fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1064e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1065fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1066fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1067fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1068fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1069cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1070fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1071fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1072cab2716aSmatthias.grimm    }
1073fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1074fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1075fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1076fdb8d77bSTom N Harris    $form->endFieldset();
1077fdb8d77bSTom N Harris    html_form('register', $form);
1078cab2716aSmatthias.grimm
1079fdb8d77bSTom N Harris    print '</div>'.NL;
1080f3f0262cSandi}
1081f3f0262cSandi
1082f3f0262cSandi/**
10838b06d178Schris * Print the update profile form
10848b06d178Schris *
10858b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10868b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10878b06d178Schris */
10888b06d178Schrisfunction html_updateprofile(){
10898b06d178Schris    global $lang;
10908b06d178Schris    global $conf;
10918b06d178Schris    global $ID;
10928b06d178Schris    global $INFO;
109382fd59b6SAndreas Gohr    global $auth;
10948b06d178Schris
10958b06d178Schris    print p_locale_xhtml('updateprofile');
10968b06d178Schris
10978b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10988b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1099fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1100e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__register'));
1101fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1102fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1103fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1104fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1105fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1106fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1107fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
110839ba8890SAndreas Gohr    $attr = array('size'=>'50');
110939ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1110fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1111fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1112fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1113fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1114fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1115fdb8d77bSTom N Harris    }
1116fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1117fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1118fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1119fdb8d77bSTom N Harris    }
1120fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1121fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1122fdb8d77bSTom N Harris    $form->endFieldset();
1123fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1124fdb8d77bSTom N Harris    print '</div>'.NL;
11258b06d178Schris}
11268b06d178Schris
11278b06d178Schris/**
11287c4635c4SAdrian Lang * Preprocess edit form data
112915fae107Sandi *
1130016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
113115fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1132f3f0262cSandi */
1133f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1134f3f0262cSandi    global $ID;
1135f3f0262cSandi    global $REV;
1136f3f0262cSandi    global $DATE;
1137f3f0262cSandi    global $RANGE;
1138f3f0262cSandi    global $PRE;
1139f3f0262cSandi    global $SUF;
1140f3f0262cSandi    global $INFO;
1141f3f0262cSandi    global $SUM;
1142f3f0262cSandi    global $lang;
1143f3f0262cSandi    global $conf;
1144f3f0262cSandi
1145f3f0262cSandi    //set summary default
1146f3f0262cSandi    if(!$SUM){
1147f3f0262cSandi        if($REV){
1148f3f0262cSandi            $SUM = $lang['restored'];
1149f3f0262cSandi        }elseif(!$INFO['exists']){
1150f3f0262cSandi            $SUM = $lang['created'];
1151f3f0262cSandi        }
1152f3f0262cSandi    }
1153f3f0262cSandi
1154f3f0262cSandi    //no text? Load it!
1155f3f0262cSandi    if(!isset($text)){
1156f3f0262cSandi        $pr = false; //no preview mode
11577146cee2SAndreas Gohr        if($INFO['exists']){
1158f3f0262cSandi            if($RANGE){
1159f3f0262cSandi                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1160f3f0262cSandi            }else{
1161f3f0262cSandi                $text = rawWiki($ID,$REV);
1162f3f0262cSandi            }
11638fe3bb00STom N Harris            $check = md5($text);
11648fe3bb00STom N Harris            $mod = false;
1165f3f0262cSandi        }else{
11667146cee2SAndreas Gohr            //try to load a pagetemplate
1167b7d5a5f0SAndreas Gohr            $data = array($ID);
1168016b6153SAndreas Gohr            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
11698fe3bb00STom N Harris            $check = md5('');
11708fe3bb00STom N Harris            $mod = $text!=='';
11717146cee2SAndreas Gohr        }
11727146cee2SAndreas Gohr    }else{
1173f3f0262cSandi        $pr = true; //preview mode
11748fe3bb00STom N Harris        if (isset($_REQUEST['changecheck'])) {
11758fe3bb00STom N Harris            $check = $_REQUEST['changecheck'];
11768fe3bb00STom N Harris            $mod = md5($text)!==$check;
11778fe3bb00STom N Harris        } else {
11788fe3bb00STom N Harris            // Why? Assume default text is unmodified.
11798fe3bb00STom N Harris            $check = md5($text);
11808fe3bb00STom N Harris            $mod = false;
11818fe3bb00STom N Harris        }
1182f3f0262cSandi    }
1183f3f0262cSandi
118427eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
1185f3f0262cSandi    if($wr){
1186c112d578Sandi        if ($REV) print p_locale_xhtml('editrev');
1187c112d578Sandi        print p_locale_xhtml($include);
1188f3f0262cSandi    }else{
1189409d7af7SAndreas Gohr        // check pseudo action 'source'
1190409d7af7SAndreas Gohr        if(!actionOK('source')){
1191409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1192409d7af7SAndreas Gohr            return;
1193409d7af7SAndreas Gohr        }
1194c112d578Sandi        print p_locale_xhtml('read');
1195f3f0262cSandi    }
1196f3f0262cSandi    if(!$DATE) $DATE = $INFO['lastmod'];
11977c4635c4SAdrian Lang
11987c4635c4SAdrian Lang    global $conf;
11997c4635c4SAdrian Lang    global $license;
12007c4635c4SAdrian Lang    global $lang;
12017c4635c4SAdrian Lang    global $REV;
12027c4635c4SAdrian Lang    global $DATE;
12037c4635c4SAdrian Lang    global $PRE;
12047c4635c4SAdrian Lang    global $SUF;
12057c4635c4SAdrian Lang    global $INFO;
12067c4635c4SAdrian Lang    global $SUM;
12077c4635c4SAdrian Lang    global $ID;
120842c7abd6SAndreas Gohr
1209e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__editform'));
1210fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1211fdb8d77bSTom N Harris    $form->addHidden('rev', $REV);
1212fdb8d77bSTom N Harris    $form->addHidden('date', $DATE);
1213fdb8d77bSTom N Harris    $form->addHidden('prefix', $PRE);
1214fdb8d77bSTom N Harris    $form->addHidden('suffix', $SUF);
1215fdb8d77bSTom N Harris    $form->addHidden('changecheck', $check);
1216*8e4da260SAdrian Lang
1217*8e4da260SAdrian Lang    $data = compact('wr', 'text', 'form');
1218*8e4da260SAdrian Lang    $data['media_manager'] = true;
1219*8e4da260SAdrian Lang    trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1220*8e4da260SAdrian Lang
1221fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1222fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1223fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
1224fdb8d77bSTom N Harris    if ($wr) {
1225fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1226fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1227fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1228fdb8d77bSTom N Harris        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1229fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1230fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1231fdb8d77bSTom N Harris        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1232fdb8d77bSTom N Harris        $elem = html_minoredit();
1233fdb8d77bSTom N Harris        if ($elem) $form->addElement($elem);
1234fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1235fdb8d77bSTom N Harris    }
1236fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
12375808bc54SAndreas Gohr    if($wr && $conf['license']){
1238066fee30SAndreas Gohr        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1239066fee30SAndreas Gohr        $out  = $lang['licenseok'];
1240066fee30SAndreas Gohr        $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1241c0322273SAdrian Lang        if(isset($conf['target']['external'])) $out .= ' target="'.$conf['target']['external'].'"';
1242066fee30SAndreas Gohr        $out .= '> '.$license[$conf['license']]['name'].'</a>';
1243066fee30SAndreas Gohr        $form->addElement($out);
1244066fee30SAndreas Gohr        $form->addElement(form_makeCloseTag('div'));
1245066fee30SAndreas Gohr    }
1246*8e4da260SAdrian Lang
1247*8e4da260SAdrian Lang    if ($wr) {
1248*8e4da260SAdrian Lang        // sets changed to true when previewed
1249*8e4da260SAdrian Lang        echo '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--';
1250*8e4da260SAdrian Lang        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1251*8e4da260SAdrian Lang        echo '//--><!]]></script>';
1252*8e4da260SAdrian Lang    } ?>
1253*8e4da260SAdrian Lang    <div style="width:99%;">
1254*8e4da260SAdrian Lang
1255*8e4da260SAdrian Lang    <div class="toolbar">
1256*8e4da260SAdrian Lang    <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1257*8e4da260SAdrian Lang    <div id="tool__bar"><?php if ($wr && $data['media_manager']){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1258*8e4da260SAdrian Lang        target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1259*8e4da260SAdrian Lang
1260*8e4da260SAdrian Lang    </div>
1261*8e4da260SAdrian Lang    <?php
1262*8e4da260SAdrian Lang
1263fdb8d77bSTom N Harris    html_form('edit', $form);
1264fdb8d77bSTom N Harris    print '</div>'.NL;
1265f3f0262cSandi}
1266f3f0262cSandi
1267f3f0262cSandi/**
1268*8e4da260SAdrian Lang * Display the default edit form
1269*8e4da260SAdrian Lang *
1270*8e4da260SAdrian Lang * Is the default action for HTML_EDIT_FORMSELECTION.
1271*8e4da260SAdrian Lang *
1272*8e4da260SAdrian Lang * @triggers HTML_EDITFORM_OUTPUT
1273*8e4da260SAdrian Lang */
1274*8e4da260SAdrian Langfunction html_edit_form($param) {
1275*8e4da260SAdrian Lang    extract($param);
1276*8e4da260SAdrian Lang    $attr = array('tabindex'=>'1');
1277*8e4da260SAdrian Lang    if (!$wr) $attr['readonly'] = 'readonly';
1278*8e4da260SAdrian Lang    $form->addElement(form_makeWikiText($text, $attr));
1279*8e4da260SAdrian Lang}
1280*8e4da260SAdrian Lang
1281*8e4da260SAdrian Lang/**
1282b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1283b6912aeaSAndreas Gohr *
1284b1f92db2SAdrian Lang * @author Andreas Gohr <andi@splitbrain.org>
1285b6912aeaSAndreas Gohr */
1286b6912aeaSAndreas Gohrfunction html_minoredit(){
1287b6912aeaSAndreas Gohr    global $conf;
1288b6912aeaSAndreas Gohr    global $lang;
1289b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1290b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1291fdb8d77bSTom N Harris        return false;
1292b6912aeaSAndreas Gohr    }
1293b6912aeaSAndreas Gohr
1294b6912aeaSAndreas Gohr    $p = array();
1295b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1296bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1297fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1298b6912aeaSAndreas Gohr}
1299b6912aeaSAndreas Gohr
1300b6912aeaSAndreas Gohr/**
1301f3f0262cSandi * prints some debug info
130215fae107Sandi *
130315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1304f3f0262cSandi */
1305f3f0262cSandifunction html_debug(){
1306f3f0262cSandi    global $conf;
1307d16a4edaSandi    global $lang;
13085298a619SAndreas Gohr    global $auth;
1309100a97e3SAndreas Gohr    global $INFO;
1310100a97e3SAndreas Gohr
131128fb55ffSandi    //remove sensitive data
131228fb55ffSandi    $cnf = $conf;
131324297a69SAndreas Gohr    debug_guard($cnf);
1314100a97e3SAndreas Gohr    $nfo = $INFO;
131524297a69SAndreas Gohr    debug_guard($nfo);
1316100a97e3SAndreas Gohr    $ses = $_SESSION;
131724297a69SAndreas Gohr    debug_guard($ses);
1318f3f0262cSandi
1319f3f0262cSandi    print '<html><body>';
1320f3f0262cSandi
1321f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1322f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1323f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1324f3f0262cSandi
1325100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1326100a97e3SAndreas Gohr    print_r($nfo);
1327100a97e3SAndreas Gohr    print '</pre>';
1328100a97e3SAndreas Gohr
1329f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1330f3f0262cSandi    print_r($_SERVER);
1331f3f0262cSandi    print '</pre>';
1332f3f0262cSandi
1333f3f0262cSandi    print '<b>$conf:</b><pre>';
133428fb55ffSandi    print_r($cnf);
1335f3f0262cSandi    print '</pre>';
1336f3f0262cSandi
1337ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1338ed7b5f09Sandi    print DOKU_BASE;
1339f3f0262cSandi    print '</pre>';
1340f3f0262cSandi
1341ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1342ed7b5f09Sandi    print DOKU_URL;
1343ed7b5f09Sandi    print '</pre>';
1344ed7b5f09Sandi
1345ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1346f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1347f3f0262cSandi    print '</pre>';
1348f3f0262cSandi
1349f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1350f3f0262cSandi    print phpversion();
1351f3f0262cSandi    print '</pre>';
1352f3f0262cSandi
1353f3f0262cSandi    print '<b>locale:</b><pre>';
1354f3f0262cSandi    print setlocale(LC_ALL,0);
1355f3f0262cSandi    print '</pre>';
1356f3f0262cSandi
1357d16a4edaSandi    print '<b>encoding:</b><pre>';
1358d16a4edaSandi    print $lang['encoding'];
1359d16a4edaSandi    print '</pre>';
1360d16a4edaSandi
13615298a619SAndreas Gohr    if($auth){
13625298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13635298a619SAndreas Gohr        print_r($auth->cando);
13645298a619SAndreas Gohr        print '</pre>';
13655298a619SAndreas Gohr    }
13665298a619SAndreas Gohr
13673aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1368100a97e3SAndreas Gohr    print_r($ses);
13693aa54d7cSAndreas Gohr    print '</pre>';
13703aa54d7cSAndreas Gohr
1371f3f0262cSandi    print '<b>Environment:</b><pre>';
1372f3f0262cSandi    print_r($_ENV);
1373f3f0262cSandi    print '</pre>';
1374f3f0262cSandi
1375f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1376f3f0262cSandi    $inis = ini_get_all();
1377f3f0262cSandi    print_r($inis);
1378f3f0262cSandi    print '</pre>';
1379f3f0262cSandi
1380f3f0262cSandi    print '</body></html>';
1381f3f0262cSandi}
1382f3f0262cSandi
138310271ce4SAndreas Gohr/**
138410271ce4SAndreas Gohr * List available Administration Tasks
138510271ce4SAndreas Gohr *
138610271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
138710271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
138810271ce4SAndreas Gohr */
1389c19fe9c0Sandifunction html_admin(){
1390c19fe9c0Sandi    global $ID;
1391f8cc712eSAndreas Gohr    global $INFO;
1392c19fe9c0Sandi    global $lang;
1393ca3a6df1SMatthias Grimm    global $conf;
139410271ce4SAndreas Gohr    global $auth;
1395c19fe9c0Sandi
139611e2ce22Schris    // build menu of admin functions from the plugins that handle them
139711e2ce22Schris    $pluginlist = plugin_list('admin');
139811e2ce22Schris    $menu = array();
139911e2ce22Schris    foreach ($pluginlist as $p) {
1400db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1401f8cc712eSAndreas Gohr
1402f8cc712eSAndreas Gohr        // check permissions
1403f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1404f8cc712eSAndreas Gohr
140510271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
140611e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
140711e2ce22Schris                'sort' => $obj->getMenuSort()
140811e2ce22Schris                );
140911e2ce22Schris    }
141011e2ce22Schris
141110271ce4SAndreas Gohr    print p_locale_xhtml('admin');
141210271ce4SAndreas Gohr
141310271ce4SAndreas Gohr    // Admin Tasks
141410271ce4SAndreas Gohr    if($INFO['isadmin']){
141510271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
141610271ce4SAndreas Gohr
141776c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
141810271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
141910271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
142010271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
142110271ce4SAndreas Gohr        }
142210271ce4SAndreas Gohr        unset($menu['usermanager']);
142310271ce4SAndreas Gohr
142476c65fd3SAndreas Gohr        if($menu['acl']){
142510271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
142610271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
142710271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
142876c65fd3SAndreas Gohr        }
142910271ce4SAndreas Gohr        unset($menu['acl']);
143010271ce4SAndreas Gohr
143176c65fd3SAndreas Gohr        if($menu['plugin']){
143210271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
143310271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
143410271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
143576c65fd3SAndreas Gohr        }
143610271ce4SAndreas Gohr        unset($menu['plugin']);
143710271ce4SAndreas Gohr
143876c65fd3SAndreas Gohr        if($menu['config']){
143910271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
144010271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
144110271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
144276c65fd3SAndreas Gohr        }
144310271ce4SAndreas Gohr        unset($menu['config']);
144410271ce4SAndreas Gohr    }
144510271ce4SAndreas Gohr    ptln('</ul>');
144610271ce4SAndreas Gohr
144710271ce4SAndreas Gohr    // Manager Tasks
144810271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
144910271ce4SAndreas Gohr
145076c65fd3SAndreas Gohr    if($menu['revert']){
145110271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
145210271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
145310271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
145476c65fd3SAndreas Gohr    }
145510271ce4SAndreas Gohr    unset($menu['revert']);
145610271ce4SAndreas Gohr
145776c65fd3SAndreas Gohr    if($menu['popularity']){
145810271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
145910271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
146010271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
146176c65fd3SAndreas Gohr    }
146210271ce4SAndreas Gohr    unset($menu['popularity']);
146310271ce4SAndreas Gohr
146410271ce4SAndreas Gohr    ptln('</ul>');
146510271ce4SAndreas Gohr
146610271ce4SAndreas Gohr    // print the rest as sorted list
146710271ce4SAndreas Gohr    if(count($menu)){
1468746855cfSBen Coburn        usort($menu, 'p_sort_modes');
146911e2ce22Schris        // output the menu
147010271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
147110271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
147211e2ce22Schris        ptln('<ul>');
147311e2ce22Schris        foreach ($menu as $item) {
147411e2ce22Schris            if (!$item['prompt']) continue;
14750c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
147611e2ce22Schris        }
147711e2ce22Schris        ptln('</ul>');
1478ca3a6df1SMatthias Grimm    }
147910271ce4SAndreas Gohr}
1480c19fe9c0Sandi
14818b06d178Schris/**
14828b06d178Schris * Form to request a new password for an existing account
14838b06d178Schris *
14848b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
148511e2ce22Schris */
14868b06d178Schrisfunction html_resendpwd() {
14878b06d178Schris    global $lang;
14888b06d178Schris    global $conf;
14898b06d178Schris    global $ID;
1490c19fe9c0Sandi
14918b06d178Schris    print p_locale_xhtml('resendpwd');
1492fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1493e351c80dSAdrian Lang    $form = new Doku_Form(array('id' => 'dw__resendpwd'));
1494fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1495fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1496fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1497fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1498fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1499fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1500fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1501fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1502fdb8d77bSTom N Harris    $form->endFieldset();
1503fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1504fdb8d77bSTom N Harris    print '</div>'.NL;
1505fdb8d77bSTom N Harris}
1506fdb8d77bSTom N Harris
1507fdb8d77bSTom N Harris/**
1508b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1509b8595a66SAndreas Gohr *
1510b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1511b8595a66SAndreas Gohr */
1512b8595a66SAndreas Gohrfunction html_TOC($toc){
1513b8595a66SAndreas Gohr    if(!count($toc)) return '';
1514b8595a66SAndreas Gohr    global $lang;
1515b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1516b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1517b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1518b8595a66SAndreas Gohr    $out .= $lang['toc'];
1519b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1520b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1521b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1522b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1523b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1524db959ae3SAndreas Gohr    return $out;
1525db959ae3SAndreas Gohr}
1526b8595a66SAndreas Gohr
1527b8595a66SAndreas Gohr/**
1528b8595a66SAndreas Gohr * Callback for html_buildlist
1529b8595a66SAndreas Gohr */
1530b8595a66SAndreas Gohrfunction html_list_toc($item){
1531c66972f2SAdrian Lang    if(isset($item['hid'])){
15327d91652aSAndreas Gohr        $link = '#'.$item['hid'];
15337d91652aSAndreas Gohr    }else{
15347d91652aSAndreas Gohr        $link = $item['link'];
15357d91652aSAndreas Gohr    }
15367d91652aSAndreas Gohr
15377d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1538b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1539b8595a66SAndreas Gohr}
1540b8595a66SAndreas Gohr
1541b8595a66SAndreas Gohr/**
1542b8595a66SAndreas Gohr * Helper function to build TOC items
1543b8595a66SAndreas Gohr *
1544b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1545b8595a66SAndreas Gohr *
1546b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1547b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1548b8595a66SAndreas Gohr * @param int    $level - nesting level
1549b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1550b8595a66SAndreas Gohr */
1551b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1552b8595a66SAndreas Gohr    global $conf;
1553b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1554b8595a66SAndreas Gohr            'title' => $text,
1555b8595a66SAndreas Gohr            'type'  => 'ul',
15562bb0d541Schris            'level' => $level);
1557b8595a66SAndreas Gohr}
1558b8595a66SAndreas Gohr
1559b8595a66SAndreas Gohr/**
1560fdb8d77bSTom N Harris * Output a Doku_Form object.
1561fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1562fdb8d77bSTom N Harris *
1563fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1564fdb8d77bSTom N Harris */
1565fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1566fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1567fdb8d77bSTom N Harris    $form->endFieldset();
1568fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1569fdb8d77bSTom N Harris}
1570fdb8d77bSTom N Harris
1571fdb8d77bSTom N Harris/**
1572fdb8d77bSTom N Harris * Form print function.
1573fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1574fdb8d77bSTom N Harris */
1575fdb8d77bSTom N Harrisfunction html_form_output($data) {
1576fdb8d77bSTom N Harris    $data->printForm();
15778b06d178Schris}
1578340756e4Sandi
157907bf32b2SAndreas Gohr/**
158007bf32b2SAndreas Gohr * Embed a flash object in HTML
158107bf32b2SAndreas Gohr *
158207bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
158307bf32b2SAndreas Gohr * compatble way using valid XHTML
158407bf32b2SAndreas Gohr *
158507bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
158607bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
158707bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
158807bf32b2SAndreas Gohr * $lang['noflash'] is used.
158907bf32b2SAndreas Gohr *
159007bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
159107bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
159207bf32b2SAndreas Gohr *
159307bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
159407bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
159507bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
159607bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
159707bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
159807bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
159907bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
160007bf32b2SAndreas Gohr * @returns string         - the XHTML markup
160107bf32b2SAndreas Gohr */
160207bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
160307bf32b2SAndreas Gohr    global $lang;
160407bf32b2SAndreas Gohr
160507bf32b2SAndreas Gohr    $out = '';
160607bf32b2SAndreas Gohr
160707bf32b2SAndreas Gohr    // prepare the object attributes
160807bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
160907bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1610d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
161107bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
161207bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
161307bf32b2SAndreas Gohr
161407bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
161507bf32b2SAndreas Gohr    $std = $atts;
161607bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
161707bf32b2SAndreas Gohr    $std['data'] = $swf;
161807bf32b2SAndreas Gohr
161907bf32b2SAndreas Gohr    // add object attributes for IE
162007bf32b2SAndreas Gohr    $ie  = $atts;
162107bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
162207bf32b2SAndreas Gohr
162307bf32b2SAndreas Gohr    // open object (with conditional comments)
162407bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
162507bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
162607bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
162707bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
162807bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
162907bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
16309ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
163107bf32b2SAndreas Gohr
163207bf32b2SAndreas Gohr    // print params
163307bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
163407bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
163507bf32b2SAndreas Gohr    }
163607bf32b2SAndreas Gohr
163707bf32b2SAndreas Gohr    // add flashvars
163807bf32b2SAndreas Gohr    if(is_array($flashvars)){
1639d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
164007bf32b2SAndreas Gohr    }
164107bf32b2SAndreas Gohr
164207bf32b2SAndreas Gohr    // alternative content
164307bf32b2SAndreas Gohr    if($alt){
164407bf32b2SAndreas Gohr        $out .= $alt.NL;
164507bf32b2SAndreas Gohr    }else{
164607bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
164707bf32b2SAndreas Gohr    }
164807bf32b2SAndreas Gohr
164907bf32b2SAndreas Gohr    // finish
165007bf32b2SAndreas Gohr    $out .= '</object>'.NL;
165107bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
165207bf32b2SAndreas Gohr
165307bf32b2SAndreas Gohr    return $out;
165407bf32b2SAndreas Gohr}
165507bf32b2SAndreas Gohr
1656