xref: /dokuwiki/inc/html.php (revision 5808bc5485ac98b967e5912db9cdde0cc2fb6ac0)
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 ) {
36c19fe9c0Sandi        $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;
54fdb8d77bSTom N Harris    $form = new Doku_Form('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();
65fdb8d77bSTom N Harris    html_form('login', $form);
665b62573aSAndreas Gohr
676957b2eaSAndreas Gohr    if($auth && $auth->canDo('addUser') && actionOK('register')){
68f3f0262cSandi        print '<p>';
69f3f0262cSandi        print $lang['reghere'];
701d5856cfSAndreas Gohr        print ': <a href="'.wl($ID,'do=register').'" rel="nofollow" class="wikilink1">'.$lang['register'].'</a>';
71f3f0262cSandi        print '</p>';
72f3f0262cSandi    }
738b06d178Schris
746957b2eaSAndreas Gohr    if ($auth && $auth->canDo('modPass') && actionOK('resendpwd')) {
758b06d178Schris        print '<p>';
768b06d178Schris        print $lang['pwdforget'];
771d5856cfSAndreas Gohr        print ': <a href="'.wl($ID,'do=resendpwd').'" rel="nofollow" class="wikilink1">'.$lang['btn_resendpwd'].'</a>';
788b06d178Schris        print '</p>';
798b06d178Schris    }
80fdb8d77bSTom N Harris    print '</div>'.NL;
81f3f0262cSandi}
82f3f0262cSandi
83f3f0262cSandi/**
8415fae107Sandi * prints a section editing button
8535dae8b0SBen Coburn * used as a callback in html_secedit
8615fae107Sandi *
8715fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
8815fae107Sandi */
8935dae8b0SBen Coburnfunction html_secedit_button($matches){
90f3f0262cSandi    global $ID;
91041d7a86SBen Coburn    global $INFO;
92041d7a86SBen Coburn
93041d7a86SBen Coburn    $section = $matches[2];
94041d7a86SBen Coburn    $name = $matches[1];
95041d7a86SBen Coburn
96f3f0262cSandi    $secedit  = '';
97f3f0262cSandi    $secedit .= '<div class="secedit">';
98f3f0262cSandi    $secedit .= html_btn('secedit',$ID,'',
99f3f0262cSandi            array('do'      => 'edit',
100306b2c85SDenis Simakov                'lines'   => "$section",
101306b2c85SDenis Simakov                'rev' => $INFO['lastmod']),
10235dae8b0SBen Coburn            'post', $name);
103f3f0262cSandi    $secedit .= '</div>';
104f3f0262cSandi    return $secedit;
105f3f0262cSandi}
106f3f0262cSandi
10715fae107Sandi/**
10815fae107Sandi * inserts section edit buttons if wanted or removes the markers
10915fae107Sandi *
11015fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
11115fae107Sandi */
112f3f0262cSandifunction html_secedit($text,$show=true){
113f3f0262cSandi    global $INFO;
11435dae8b0SBen Coburn
115c112d578Sandi    if($INFO['writable'] && $show && !$INFO['rev']){
11635dae8b0SBen Coburn        $text = preg_replace_callback('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#',
11735dae8b0SBen Coburn                'html_secedit_button', $text);
118f3f0262cSandi    }else{
11935dae8b0SBen Coburn        $text = preg_replace('#<!-- SECTION "(.*?)" \[(\d+-\d*)\] -->#','',$text);
120f3f0262cSandi    }
12135dae8b0SBen Coburn
122f3f0262cSandi    return $text;
123f3f0262cSandi}
124f3f0262cSandi
125f3f0262cSandi/**
126d6c9c552Smatthiasgrimm * Just the back to top button (in its own form)
1276b13307fSandi *
1286b13307fSandi * @author Andreas Gohr <andi@splitbrain.org>
1296b13307fSandi */
1306b13307fSandifunction html_topbtn(){
1316b13307fSandi    global $lang;
1326b13307fSandi
1336b13307fSandi    $ret  = '';
13411ea018fSAndreas 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>';
135df7b6005Sandi
1366b13307fSandi    return $ret;
1376b13307fSandi}
1386b13307fSandi
1396b13307fSandi/**
140d67ca2c0Smatthiasgrimm * Displays a button (using its own form)
14135dae8b0SBen Coburn * If tooltip exists, the access key tooltip is replaced.
14215fae107Sandi *
14315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
144f3f0262cSandi */
14535dae8b0SBen Coburnfunction html_btn($name,$id,$akey,$params,$method='get',$tooltip=''){
146f3f0262cSandi    global $conf;
147f3f0262cSandi    global $lang;
148f3f0262cSandi
149f3f0262cSandi    $label = $lang['btn_'.$name];
150f3f0262cSandi
151f3f0262cSandi    $ret = '';
15235dae8b0SBen Coburn    $tip = '';
153f3f0262cSandi
15449c713a3Sandi    //filter id (without urlencoding)
15549c713a3Sandi    $id = idfilter($id,false);
156f3f0262cSandi
157f3f0262cSandi    //make nice URLs even for buttons
1586c7843b5Sandi    if($conf['userewrite'] == 2){
1596c7843b5Sandi        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
1606c7843b5Sandi    }elseif($conf['userewrite']){
1616c7843b5Sandi        $script = DOKU_BASE.$id;
1626c7843b5Sandi    }else{
1638b00ebcfSandi        $script = DOKU_BASE.DOKU_SCRIPT;
164f3f0262cSandi        $params['id'] = $id;
165f3f0262cSandi    }
166f3f0262cSandi
167b278f2deSAndreas Gohr    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
168f3f0262cSandi
16906a4bf8fSAndreas Gohr    if(is_array($params)){
170f3f0262cSandi        reset($params);
171f3f0262cSandi        while (list($key, $val) = each($params)) {
172f3f0262cSandi            $ret .= '<input type="hidden" name="'.$key.'" ';
173f3f0262cSandi            $ret .= 'value="'.htmlspecialchars($val).'" />';
174f3f0262cSandi        }
17506a4bf8fSAndreas Gohr    }
176f3f0262cSandi
17735dae8b0SBen Coburn    if ($tooltip!='') {
17835dae8b0SBen Coburn        $tip = htmlspecialchars($tooltip);
17911ea018fSAndreas Gohr    }else{
18011ea018fSAndreas Gohr        $tip = htmlspecialchars($label);
18111ea018fSAndreas Gohr    }
18211ea018fSAndreas Gohr
18311ea018fSAndreas Gohr    $ret .= '<input type="submit" value="'.htmlspecialchars($label).'" class="button" ';
18411ea018fSAndreas Gohr    if($akey){
18507493d05SAnika Henke        $tip .= ' ['.strtoupper($akey).']';
18687cb01b7SAnika Henke        $ret .= 'accesskey="'.$akey.'" ';
18735dae8b0SBen Coburn    }
18835dae8b0SBen Coburn    $ret .= 'title="'.$tip.'" ';
189f3f0262cSandi    $ret .= '/>';
1904beabca9SAnika Henke    $ret .= '</div></form>';
191f3f0262cSandi
192f3f0262cSandi    return $ret;
193f3f0262cSandi}
194f3f0262cSandi
195f3f0262cSandi/**
19615fae107Sandi * show a wiki page
19715fae107Sandi *
19815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
19915fae107Sandi */
2006bbae538Sandifunction html_show($txt=''){
201f3f0262cSandi    global $ID;
202f3f0262cSandi    global $REV;
203f3f0262cSandi    global $HIGH;
204b8595a66SAndreas Gohr    global $INFO;
205f3f0262cSandi    //disable section editing for old revisions or in preview
2065400331dSandi    if($txt || $REV){
2076bbae538Sandi        $secedit = false;
2086bbae538Sandi    }else{
2096bbae538Sandi        $secedit = true;
210f3f0262cSandi    }
211f3f0262cSandi
2126bbae538Sandi    if ($txt){
213f3f0262cSandi        //PreviewHeader
214b8595a66SAndreas Gohr        echo '<br id="scroll__here" />';
215b8595a66SAndreas Gohr        echo p_locale_xhtml('preview');
216b8595a66SAndreas Gohr        echo '<div class="preview">';
217b8595a66SAndreas Gohr        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
218b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
219b8595a66SAndreas Gohr        echo $html;
220b8595a66SAndreas Gohr        echo '<div class="clearer"></div>';
221b8595a66SAndreas Gohr        echo '</div>';
2226bbae538Sandi
223f3f0262cSandi    }else{
224c112d578Sandi        if ($REV) print p_locale_xhtml('showrev');
225c112d578Sandi        $html = p_wiki_xhtml($ID,$REV,true);
2266bbae538Sandi        $html = html_secedit($html,$secedit);
227b8595a66SAndreas Gohr        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
228b8595a66SAndreas Gohr        $html = html_hilight($html,$HIGH);
229b8595a66SAndreas Gohr        echo $html;
230f3f0262cSandi    }
231f3f0262cSandi}
232f3f0262cSandi
233f3f0262cSandi/**
234ee4c4a1bSAndreas Gohr * ask the user about how to handle an exisiting draft
235ee4c4a1bSAndreas Gohr *
236ee4c4a1bSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
237ee4c4a1bSAndreas Gohr */
238ee4c4a1bSAndreas Gohrfunction html_draft(){
239ee4c4a1bSAndreas Gohr    global $INFO;
240ee4c4a1bSAndreas Gohr    global $ID;
241ee4c4a1bSAndreas Gohr    global $lang;
242ee4c4a1bSAndreas Gohr    global $conf;
243ee4c4a1bSAndreas Gohr    $draft = unserialize(io_readFile($INFO['draft'],false));
244ee4c4a1bSAndreas Gohr    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
245ee4c4a1bSAndreas Gohr
246fdb8d77bSTom N Harris    print p_locale_xhtml('draft');
247fdb8d77bSTom N Harris    $form = new Doku_Form('dw__editform');
248fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
249fdb8d77bSTom N Harris    $form->addHidden('date', $draft['date']);
250fdb8d77bSTom N Harris    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
251fdb8d77bSTom N Harris    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
252f2263577SAndreas Gohr    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
253fdb8d77bSTom N Harris    $form->addElement(form_makeCloseTag('div'));
254fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
255fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
256fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
257fdb8d77bSTom N Harris    html_form('draft', $form);
258ee4c4a1bSAndreas Gohr}
259ee4c4a1bSAndreas Gohr
260ee4c4a1bSAndreas Gohr/**
261f3f0262cSandi * Highlights searchqueries in HTML code
26215fae107Sandi *
26315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
2647209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
265f3f0262cSandi */
266546d3a99SAndreas Gohrfunction html_hilight($html,$phrases){
267808551e3SAndreas Gohr    $phrases = array_filter((array) $phrases);
268808551e3SAndreas Gohr    $regex = join('|',array_map('preg_quote_cb',$phrases));
26960c15d7dSAndreas Gohr
27060c15d7dSAndreas Gohr    if ($regex === '') return $html;
2711db218e9SAndreas Gohr    $html = preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
272f3f0262cSandi    return $html;
273f3f0262cSandi}
274f3f0262cSandi
275f3f0262cSandi/**
2767209be23SAndreas Gohr * Callback used by html_hilight()
2777209be23SAndreas Gohr *
2787209be23SAndreas Gohr * @author Harry Fuecks <hfuecks@gmail.com>
2797209be23SAndreas Gohr */
2807209be23SAndreas Gohrfunction html_hilight_callback($m) {
2817209be23SAndreas Gohr    $hlight = unslash($m[0]);
2827209be23SAndreas Gohr    if ( !isset($m[2])) {
283688774a0SAnika Henke        $hlight = '<span class="search_hit">'.$hlight.'</span>';
2847209be23SAndreas Gohr    }
2857209be23SAndreas Gohr    return $hlight;
2867209be23SAndreas Gohr}
2877209be23SAndreas Gohr
2887209be23SAndreas Gohr/**
28915fae107Sandi * Run a search and display the result
29015fae107Sandi *
29115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
292f3f0262cSandi */
293f3f0262cSandifunction html_search(){
294ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
295506fa893SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
296f3f0262cSandi    global $conf;
297f3f0262cSandi    global $QUERY;
298f3f0262cSandi    global $ID;
299f3f0262cSandi    global $lang;
300f3f0262cSandi
301c112d578Sandi    print p_locale_xhtml('searchpage');
302f3f0262cSandi    flush();
303f3f0262cSandi
304d0ab54f6SMichael Klier chi@chimeric.de    //check if search is restricted to namespace
305b42bcfe7Sdaniel.lindgren    if(preg_match('/@([^@]*)/',$QUERY,$match)) {
306d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($match[1]);
307d0ab54f6SMichael Klier chi@chimeric.de    } else {
308d0ab54f6SMichael Klier chi@chimeric.de        $id = cleanID($QUERY);
309d0ab54f6SMichael Klier chi@chimeric.de    }
310d0ab54f6SMichael Klier chi@chimeric.de
3114d9ff3d5Sandi    //show progressbar
312e226efe1SAndreas Gohr    print '<div class="centeralign" id="dw__loading">'.NL;
313e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
314e226efe1SAndreas Gohr    print 'showLoadBar();'.NL;
315e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
316e226efe1SAndreas Gohr    print '<br /></div>'.NL;
3179edac8a8SAndreas Gohr    flush();
3184d9ff3d5Sandi
319f3f0262cSandi    //do quick pagesearch
320f3f0262cSandi    $data = array();
321d0ab54f6SMichael Klier chi@chimeric.de
322865c2687SKazutaka Miyasaka    if($id) $data = ft_pageLookup($id);
323f3f0262cSandi    if(count($data)){
324f3f0262cSandi        print '<div class="search_quickresult">';
325746855cfSBen Coburn        print '<h3>'.$lang['quickhits'].':</h3>';
3264f732f0eSAnika Henke        print '<ul class="search_quickhits">';
327140c93f3SAnika Henke        foreach($data as $id){
3284f732f0eSAnika Henke            print '<li> ';
329bd2f6c2fSAndreas Gohr            $ns = getNS($id);
330bd2f6c2fSAndreas Gohr            if($ns){
331bd2f6c2fSAndreas Gohr                $name = shorten(noNS($id), ' ('.$ns.')',30);
332bd2f6c2fSAndreas Gohr            }else{
333bd2f6c2fSAndreas Gohr                $name = $id;
334bd2f6c2fSAndreas Gohr            }
335bd2f6c2fSAndreas Gohr            print html_wikilink(':'.$id,$name);
3364f732f0eSAnika Henke            print '</li> ';
337f3f0262cSandi        }
338140c93f3SAnika Henke        print '</ul> ';
339f3f0262cSandi        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
340f3f0262cSandi        print '<div class="clearer">&nbsp;</div>';
341f3f0262cSandi        print '</div>';
342f3f0262cSandi    }
343f3f0262cSandi    flush();
344f3f0262cSandi
345f3f0262cSandi    //do fulltext search
34660c15d7dSAndreas Gohr    $data = ft_pageSearch($QUERY,$regex);
347f3f0262cSandi    if(count($data)){
348506fa893SAndreas Gohr        $num = 1;
349506fa893SAndreas Gohr        foreach($data as $id => $cnt){
350f3f0262cSandi            print '<div class="search_result">';
351db959ae3SAndreas Gohr            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
352865c2687SKazutaka Miyasaka            if($cnt !== 0){
353506fa893SAndreas Gohr                print ': <span class="search_cnt">'.$cnt.' '.$lang['hits'].'</span><br />';
354506fa893SAndreas Gohr                if($num < 15){ // create snippets for the first number of matches only #FIXME add to conf ?
35560c15d7dSAndreas Gohr                    print '<div class="search_snippet">'.ft_snippet($id,$regex).'</div>';
356506fa893SAndreas Gohr                }
357865c2687SKazutaka Miyasaka                $num++;
358865c2687SKazutaka Miyasaka            }
359f3f0262cSandi            print '</div>';
360506fa893SAndreas Gohr            flush();
361f3f0262cSandi        }
362f3f0262cSandi    }else{
363820fa24bSandi        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
364f3f0262cSandi    }
3654d9ff3d5Sandi
3664d9ff3d5Sandi    //hide progressbar
367e226efe1SAndreas Gohr    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--'.NL;
368e226efe1SAndreas Gohr    print 'hideLoadBar("dw__loading");'.NL;
369e226efe1SAndreas Gohr    print '//--><!]]></script>'.NL;
3709edac8a8SAndreas Gohr    flush();
371f3f0262cSandi}
372f3f0262cSandi
37315fae107Sandi/**
37415fae107Sandi * Display error on locked pages
37515fae107Sandi *
37615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
37715fae107Sandi */
378ee20e7d1Sandifunction html_locked(){
379f3f0262cSandi    global $ID;
380f3f0262cSandi    global $conf;
381f3f0262cSandi    global $lang;
38288f522e9Sandi    global $INFO;
383f3f0262cSandi
384c9b4bd1eSBen Coburn    $locktime = filemtime(wikiLockFN($ID));
385f2263577SAndreas Gohr    $expire = dformat($locktime + $conf['locktime']);
386f3f0262cSandi    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
387f3f0262cSandi
388c112d578Sandi    print p_locale_xhtml('locked');
389f3f0262cSandi    print '<ul>';
3906d233a0cSAndy Webber    print '<li><div class="li"><strong>'.$lang['lockedby'].':</strong> '.editorinfo($INFO['locked']).'</div></li>';
3910c6b58a8SAndreas Gohr    print '<li><div class="li"><strong>'.$lang['lockexpire'].':</strong> '.$expire.' ('.$min.' min)</div></li>';
392f3f0262cSandi    print '</ul>';
393f3f0262cSandi}
394f3f0262cSandi
39515fae107Sandi/**
39615fae107Sandi * list old revisions
39715fae107Sandi *
39815fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
39971726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
40015fae107Sandi */
40171726d78SBen Coburnfunction html_revisions($first=0){
402f3f0262cSandi    global $ID;
403f3f0262cSandi    global $INFO;
404f3f0262cSandi    global $conf;
405f3f0262cSandi    global $lang;
40671726d78SBen Coburn    /* we need to get one additionally log entry to be able to
40771726d78SBen Coburn     * decide if this is the last page or is there another one.
40871726d78SBen Coburn     * see html_recent()
40971726d78SBen Coburn     */
41071726d78SBen Coburn    $revisions = getRevisions($ID, $first, $conf['recent']+1);
41171726d78SBen Coburn    if(count($revisions)==0 && $first!=0){
41271726d78SBen Coburn        $first=0;
41371726d78SBen Coburn        $revisions = getRevisions($ID, $first, $conf['recent']+1);;
41471726d78SBen Coburn    }
41571726d78SBen Coburn    $hasNext = false;
41671726d78SBen Coburn    if (count($revisions)>$conf['recent']) {
41771726d78SBen Coburn        $hasNext = true;
41871726d78SBen Coburn        array_pop($revisions); // remove extra log entry
41971726d78SBen Coburn    }
42071726d78SBen Coburn
421f2263577SAndreas Gohr    $date = dformat($INFO['lastmod']);
422f3f0262cSandi
423c112d578Sandi    print p_locale_xhtml('revisions');
42437a1dc12Smichael
42537a1dc12Smichael    $form = new Doku_Form('page__revisions', wl($ID));
42637a1dc12Smichael    $form->addElement(form_makeOpenTag('ul'));
42771726d78SBen Coburn    if($INFO['exists'] && $first==0){
42837a1dc12Smichael        if (isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
42937a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
43037a1dc12Smichael        else
43137a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
43237a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
43337a1dc12Smichael        $form->addElement(form_makeTag('input', array(
43437a1dc12Smichael                        'type' => 'checkbox',
43537a1dc12Smichael                        'name' => 'rev2[]',
43637a1dc12Smichael                        'value' => 'current')));
437f9b2fe70Sandi
43837a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
43937a1dc12Smichael        $form->addElement($date);
44037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
441f9b2fe70Sandi
44237a1dc12Smichael        $form->addElement(form_makeTag('img', array(
44337a1dc12Smichael                        'src' =>  DOKU_BASE.'lib/images/blank.gif',
44437a1dc12Smichael                        'width' => '15',
44537a1dc12Smichael                        'height' => '11',
44637a1dc12Smichael                        'alt'    => '')));
447cffcc403Sandi
44837a1dc12Smichael        $form->addElement(form_makeOpenTag('a', array(
44937a1dc12Smichael                        'class' => 'wikilink1',
45037a1dc12Smichael                        'href'  => wl($ID))));
45137a1dc12Smichael        $form->addElement($ID);
45237a1dc12Smichael        $form->addElement(form_makeCloseTag('a'));
453652610a2Sandi
45437a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
45537a1dc12Smichael        $form->addElement(' &ndash; ');
45637a1dc12Smichael        $form->addElement(htmlspecialchars($INFO['sum']));
45737a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
458652610a2Sandi
45937a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
46037a1dc12Smichael        $form->addElement((empty($INFO['editor']))?('('.$lang['external_edit'].')'):editorinfo($INFO['editor']));
46137a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
46237a1dc12Smichael
46337a1dc12Smichael        $form->addElement('('.$lang['current'].')');
46437a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
46537a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
466f3f0262cSandi    }
467f3f0262cSandi
468f3f0262cSandi    foreach($revisions as $rev){
469f2263577SAndreas Gohr        $date   = dformat($rev);
470fb53bfe2SBen Coburn        $info   = getRevisionInfo($ID,$rev,true);
471103c256aSChris Smith        $exists = page_exists($ID,$rev);
472652610a2Sandi
47337a1dc12Smichael        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
47437a1dc12Smichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
47537a1dc12Smichael        else
47637a1dc12Smichael            $form->addElement(form_makeOpenTag('li'));
47737a1dc12Smichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
47877707b04SAndreas Gohr        if($exists){
47937a1dc12Smichael            $form->addElement(form_makeTag('input', array(
48037a1dc12Smichael                            'type' => 'checkbox',
48137a1dc12Smichael                            'name' => 'rev2[]',
48237a1dc12Smichael                            'value' => $rev)));
48377707b04SAndreas Gohr        }else{
48437a1dc12Smichael            $form->addElement(form_makeTag('img', array(
48537a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
48637a1dc12Smichael                            'width' => 14,
48737a1dc12Smichael                            'height' => 11,
48837a1dc12Smichael                            'alt' => '')));
48941396b71SAndreas Gohr        }
490f9b2fe70Sandi
49137a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
49237a1dc12Smichael        $form->addElement($date);
49337a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
49437a1dc12Smichael
49537a1dc12Smichael        if($exists){
49637a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev,do=diff", false, '&'), 'class' => 'diff_link')));
49737a1dc12Smichael            $form->addElement(form_makeTag('img', array(
49837a1dc12Smichael                            'src'    => DOKU_BASE.'lib/images/diff.png',
49937a1dc12Smichael                            'width'  => 15,
50037a1dc12Smichael                            'height' => 11,
50137a1dc12Smichael                            'title'  => $lang['diff'],
50237a1dc12Smichael                            'alt'    => $lang['diff'])));
50337a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
50437a1dc12Smichael
50537a1dc12Smichael            $form->addElement(form_makeOpenTag('a', array('href' => wl($ID,"rev=$rev",false,'&'), 'class' => 'wikilink1')));
50637a1dc12Smichael            $form->addElement($ID);
50737a1dc12Smichael            $form->addElement(form_makeCloseTag('a'));
50837a1dc12Smichael        }else{
50937a1dc12Smichael            $form->addElement(form_makeTag('img', array(
51037a1dc12Smichael                            'src' => DOKU_BASE.'lib/images/blank.gif',
51137a1dc12Smichael                            'width' => '15',
51237a1dc12Smichael                            'height' => '11',
51337a1dc12Smichael                            'alt'   => '')));
51437a1dc12Smichael            $form->addElement($ID);
51537a1dc12Smichael        }
51637a1dc12Smichael
51737a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
51837a1dc12Smichael        $form->addElement(' &ndash; ');
51937a1dc12Smichael        $form->addElement(htmlspecialchars($info['sum']));
52037a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
52137a1dc12Smichael
52237a1dc12Smichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
52388f522e9Sandi        if($info['user']){
52437a1dc12Smichael            $form->addElement(editorinfo($info['user']));
525433efb25SAndreas Gohr            if(auth_ismanager()){
526433efb25SAndreas Gohr                $form->addElement(' ('.$info['ip'].')');
527433efb25SAndreas Gohr            }
52888f522e9Sandi        }else{
52937a1dc12Smichael            $form->addElement($info['ip']);
53088f522e9Sandi        }
53137a1dc12Smichael        $form->addElement(form_makeCloseTag('span'));
532652610a2Sandi
53337a1dc12Smichael        $form->addElement(form_makeCloseTag('div'));
53437a1dc12Smichael        $form->addElement(form_makeCloseTag('li'));
535f3f0262cSandi    }
53637a1dc12Smichael    $form->addElement(form_makeCloseTag('ul'));
53737a1dc12Smichael    $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
53837a1dc12Smichael    html_form('revisions', $form);
53971726d78SBen Coburn
54071726d78SBen Coburn    print '<div class="pagenav">';
54171726d78SBen Coburn    $last = $first + $conf['recent'];
54271726d78SBen Coburn    if ($first > 0) {
54371726d78SBen Coburn        $first -= $conf['recent'];
54471726d78SBen Coburn        if ($first < 0) $first = 0;
54571726d78SBen Coburn        print '<div class="pagenav-prev">';
546eeb83e57SBen Coburn        print html_btn('newer',$ID,"p",array('do' => 'revisions', 'first' => $first));
54771726d78SBen Coburn        print '</div>';
54871726d78SBen Coburn    }
54971726d78SBen Coburn    if ($hasNext) {
55071726d78SBen Coburn        print '<div class="pagenav-next">';
551eeb83e57SBen Coburn        print html_btn('older',$ID,"n",array('do' => 'revisions', 'first' => $last));
55271726d78SBen Coburn        print '</div>';
55371726d78SBen Coburn    }
55471726d78SBen Coburn    print '</div>';
55571726d78SBen Coburn
556f3f0262cSandi}
557f3f0262cSandi
55815fae107Sandi/**
55915fae107Sandi * display recent changes
56015fae107Sandi *
56115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
5625749f1ceSmatthiasgrimm * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
56371726d78SBen Coburn * @author Ben Coburn <btcoburn@silicodon.net>
56415fae107Sandi */
565a39955b0Smatthiasgrimmfunction html_recent($first=0){
566f3f0262cSandi    global $conf;
567cffcc403Sandi    global $lang;
568dbb00abcSEsther Brunner    global $ID;
5695749f1ceSmatthiasgrimm    /* we need to get one additionally log entry to be able to
5705749f1ceSmatthiasgrimm     * decide if this is the last page or is there another one.
5715749f1ceSmatthiasgrimm     * This is the cheapest solution to get this information.
5725749f1ceSmatthiasgrimm     */
573b6912aeaSAndreas Gohr    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5745749f1ceSmatthiasgrimm    if(count($recents) == 0 && $first != 0){
5755749f1ceSmatthiasgrimm        $first=0;
57671726d78SBen Coburn        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID));
5775749f1ceSmatthiasgrimm    }
57871726d78SBen Coburn    $hasNext = false;
57971726d78SBen Coburn    if (count($recents)>$conf['recent']) {
58071726d78SBen Coburn        $hasNext = true;
58171726d78SBen Coburn        array_pop($recents); // remove extra log entry
58271726d78SBen Coburn    }
583f3f0262cSandi
584c112d578Sandi    print p_locale_xhtml('recent');
585e83cef14SGina Haeussge
586e83cef14SGina Haeussge    if (getNS($ID) != '')
5879e561443SAndreas Gohr        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
588e83cef14SGina Haeussge
589abdcc39fSmichael    $form = new Doku_Form('dw__recent', script(), 'get');
590abdcc39fSmichael    $form->addHidden('sectok', null);
591abdcc39fSmichael    $form->addHidden('do', 'recent');
592abdcc39fSmichael    $form->addHidden('id', $ID);
593abdcc39fSmichael    $form->addElement(form_makeOpenTag('ul'));
594a39955b0Smatthiasgrimm
595d437bcc4SAndreas Gohr    foreach($recents as $recent){
596f2263577SAndreas Gohr        $date = dformat($recent['date']);
597abdcc39fSmichael        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
598abdcc39fSmichael            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
599abdcc39fSmichael        else
600abdcc39fSmichael            $form->addElement(form_makeOpenTag('li'));
601cffcc403Sandi
602abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
603f9b2fe70Sandi
604abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
605abdcc39fSmichael        $form->addElement($date);
606abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
607cffcc403Sandi
608cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => wl($recent['id'],"do=diff", false, '&'))));
609abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
610abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/diff.png',
611abdcc39fSmichael                        'width' => 15,
612abdcc39fSmichael                        'height'=> 11,
613abdcc39fSmichael                        'title' => $lang['diff'],
614abdcc39fSmichael                        'alt'   => $lang['diff']
615abdcc39fSmichael                        )));
616abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
617cffcc403Sandi
618cddd152cSmichael        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => wl($recent['id'],"do=revisions",false,'&'))));
619abdcc39fSmichael        $form->addElement(form_makeTag('img', array(
620abdcc39fSmichael                        'src'   => DOKU_BASE.'lib/images/history.png',
621abdcc39fSmichael                        'width' => 12,
622abdcc39fSmichael                        'height'=> 14,
623abdcc39fSmichael                        'title' => $lang['btn_revs'],
624abdcc39fSmichael                        'alt'   => $lang['btn_revs']
625abdcc39fSmichael                        )));
626abdcc39fSmichael        $form->addElement(form_makeCloseTag('a'));
627b6912aeaSAndreas Gohr
628db959ae3SAndreas Gohr        $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
629abdcc39fSmichael
630abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
631abdcc39fSmichael        $form->addElement(' &ndash; '.htmlspecialchars($recent['sum']));
632abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
633abdcc39fSmichael
634abdcc39fSmichael        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
635d437bcc4SAndreas Gohr        if($recent['user']){
636abdcc39fSmichael            $form->addElement(editorinfo($recent['user']));
637433efb25SAndreas Gohr            if(auth_ismanager()){
638433efb25SAndreas Gohr                $form->addElement(' ('.$recent['ip'].')');
639433efb25SAndreas Gohr            }
64088f522e9Sandi        }else{
641abdcc39fSmichael            $form->addElement($recent['ip']);
64288f522e9Sandi        }
643abdcc39fSmichael        $form->addElement(form_makeCloseTag('span'));
644cffcc403Sandi
645abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
646abdcc39fSmichael        $form->addElement(form_makeCloseTag('li'));
647f3f0262cSandi    }
648abdcc39fSmichael    $form->addElement(form_makeCloseTag('ul'));
649a39955b0Smatthiasgrimm
650abdcc39fSmichael    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
6515749f1ceSmatthiasgrimm    $last = $first + $conf['recent'];
652a39955b0Smatthiasgrimm    if ($first > 0) {
653a39955b0Smatthiasgrimm        $first -= $conf['recent'];
654a39955b0Smatthiasgrimm        if ($first < 0) $first = 0;
655abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
656abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
657abdcc39fSmichael                    'type'  => 'submit',
658abdcc39fSmichael                    'name'  => 'first['.$first.']',
659cddd152cSmichael                    'value' => $lang['btn_newer'],
660cddd152cSmichael                    'accesskey' => 'n',
661f948eeabSMichael Klier                    'title' => $lang['btn_newer'].' [N]',
66218d107cbSMichael Klier                    'class' => 'button'
663abdcc39fSmichael                    )));
664abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
665a39955b0Smatthiasgrimm    }
66671726d78SBen Coburn    if ($hasNext) {
667abdcc39fSmichael        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
668abdcc39fSmichael        $form->addElement(form_makeTag('input', array(
669abdcc39fSmichael                        'type'  => 'submit',
670abdcc39fSmichael                        'name'  => 'first['.$last.']',
671cddd152cSmichael                        'value' => $lang['btn_older'],
672cddd152cSmichael                        'accesskey' => 'p',
673f948eeabSMichael Klier                        'title' => $lang['btn_older'].' [P]',
67418d107cbSMichael Klier                        'class' => 'button'
675abdcc39fSmichael                        )));
676abdcc39fSmichael        $form->addElement(form_makeCloseTag('div'));
677a39955b0Smatthiasgrimm    }
678abdcc39fSmichael    $form->addElement(form_makeCloseTag('div'));
679abdcc39fSmichael    html_form('recent', $form);
680f3f0262cSandi}
681f3f0262cSandi
68215fae107Sandi/**
68315fae107Sandi * Display page index
68415fae107Sandi *
68515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
68615fae107Sandi */
687f3f0262cSandifunction html_index($ns){
688ed7b5f09Sandi    require_once(DOKU_INC.'inc/search.php');
689f3f0262cSandi    global $conf;
690f3f0262cSandi    global $ID;
691f3f0262cSandi    $dir = $conf['datadir'];
692f3f0262cSandi    $ns  = cleanID($ns);
69330f1737dSandi    #fixme use appropriate function
694f3f0262cSandi    if(empty($ns)){
695f3f0262cSandi        $ns = dirname(str_replace(':','/',$ID));
696f3f0262cSandi        if($ns == '.') $ns ='';
697f3f0262cSandi    }
69888d3a917Sandi    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
699f3f0262cSandi
700a06884abSAndreas Gohr    echo p_locale_xhtml('index');
701a06884abSAndreas Gohr    echo '<div id="index__tree">';
702f3f0262cSandi
703f3f0262cSandi    $data = array();
704f3f0262cSandi    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
705a06884abSAndreas Gohr    echo html_buildlist($data,'idx','html_list_index','html_li_index');
706a06884abSAndreas Gohr
707a06884abSAndreas Gohr    echo '</div>';
708f3f0262cSandi}
709f3f0262cSandi
710f3f0262cSandi/**
71115fae107Sandi * Index item formatter
71215fae107Sandi *
713f3f0262cSandi * User function for html_buildlist()
71415fae107Sandi *
71515fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
716f3f0262cSandi */
717f3f0262cSandifunction html_list_index($item){
718d98d4540SBen Coburn    global $ID;
719f3f0262cSandi    $ret = '';
720f3f0262cSandi    $base = ':'.$item['id'];
721f3f0262cSandi    $base = substr($base,strrpos($base,':')+1);
722f3f0262cSandi    if($item['type']=='d'){
7234a119027SAndreas Gohr        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" class="idx_dir"><strong>';
724f3f0262cSandi        $ret .= $base;
725ed7ecb79SAnika Henke        $ret .= '</strong></a>';
726f3f0262cSandi    }else{
727f3f0262cSandi        $ret .= html_wikilink(':'.$item['id']);
728f3f0262cSandi    }
729f3f0262cSandi    return $ret;
730f3f0262cSandi}
731f3f0262cSandi
732f3f0262cSandi/**
733cb70c441Sandi * Index List item
734cb70c441Sandi *
735cb70c441Sandi * This user function is used in html_build_lidt to build the
736cb70c441Sandi * <li> tags for namespaces when displaying the page index
737cb70c441Sandi * it gives different classes to opened or closed "folders"
738cb70c441Sandi *
739cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
740cb70c441Sandi */
741cb70c441Sandifunction html_li_index($item){
742cb70c441Sandi    if($item['type'] == "f"){
743cb70c441Sandi        return '<li class="level'.$item['level'].'">';
744cb70c441Sandi    }elseif($item['open']){
745cb70c441Sandi        return '<li class="open">';
746cb70c441Sandi    }else{
747cb70c441Sandi        return '<li class="closed">';
748cb70c441Sandi    }
749cb70c441Sandi}
750cb70c441Sandi
751cb70c441Sandi/**
752cb70c441Sandi * Default List item
753cb70c441Sandi *
754cb70c441Sandi * @author Andreas Gohr <andi@splitbrain.org>
755cb70c441Sandi */
756cb70c441Sandifunction html_li_default($item){
757cb70c441Sandi    return '<li class="level'.$item['level'].'">';
758cb70c441Sandi}
759cb70c441Sandi
760cb70c441Sandi/**
76115fae107Sandi * Build an unordered list
76215fae107Sandi *
763f3f0262cSandi * Build an unordered list from the given $data array
764f3f0262cSandi * Each item in the array has to have a 'level' property
765f3f0262cSandi * the item itself gets printed by the given $func user
766cb70c441Sandi * function. The second and optional function is used to
767cb70c441Sandi * print the <li> tag. Both user function need to accept
768cb70c441Sandi * a single item.
76915fae107Sandi *
770c5a8fd96SAndreas Gohr * Both user functions can be given as array to point to
771c5a8fd96SAndreas Gohr * a member of an object.
772c5a8fd96SAndreas Gohr *
77315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
774f3f0262cSandi */
775cb70c441Sandifunction html_buildlist($data,$class,$func,$lifunc='html_li_default'){
776f3f0262cSandi    $level = 0;
777f3f0262cSandi    $opens = 0;
778f3f0262cSandi    $ret   = '';
779f3f0262cSandi
780f3f0262cSandi    foreach ($data as $item){
781f3f0262cSandi
782f3f0262cSandi        if( $item['level'] > $level ){
783f3f0262cSandi            //open new list
784df52d0feSandi            for($i=0; $i<($item['level'] - $level); $i++){
785df52d0feSandi                if ($i) $ret .= "<li class=\"clear\">\n";
786f3f0262cSandi                $ret .= "\n<ul class=\"$class\">\n";
787df52d0feSandi            }
788f3f0262cSandi        }elseif( $item['level'] < $level ){
789f3f0262cSandi            //close last item
790f3f0262cSandi            $ret .= "</li>\n";
791f3f0262cSandi            for ($i=0; $i<($level - $item['level']); $i++){
792f3f0262cSandi                //close higher lists
793f3f0262cSandi                $ret .= "</ul>\n</li>\n";
794f3f0262cSandi            }
795f3f0262cSandi        }else{
796f3f0262cSandi            //close last item
797f3f0262cSandi            $ret .= "</li>\n";
798f3f0262cSandi        }
799f3f0262cSandi
800f3f0262cSandi        //remember current level
801f3f0262cSandi        $level = $item['level'];
802f3f0262cSandi
803f3f0262cSandi        //print item
80434dbe711Schris        $ret .= call_user_func($lifunc,$item);
8050c6b58a8SAndreas Gohr        $ret .= '<div class="li">';
80634dbe711Schris
80734dbe711Schris        $ret .= call_user_func($func,$item);
8080c6b58a8SAndreas Gohr        $ret .= '</div>';
809f3f0262cSandi    }
810f3f0262cSandi
811f3f0262cSandi    //close remaining items and lists
812f3f0262cSandi    for ($i=0; $i < $level; $i++){
813f3f0262cSandi        $ret .= "</li></ul>\n";
814f3f0262cSandi    }
815f3f0262cSandi
816f3f0262cSandi    return $ret;
817f3f0262cSandi}
818f3f0262cSandi
81915fae107Sandi/**
82015fae107Sandi * display backlinks
82115fae107Sandi *
82215fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
82311df47ecSMichael Klier * @author Michael Klier <chi@chimeric.de>
82415fae107Sandi */
825f3f0262cSandifunction html_backlinks(){
82654f4c056SAndreas Gohr    require_once(DOKU_INC.'inc/fulltext.php');
827f3f0262cSandi    global $ID;
828f3f0262cSandi    global $conf;
82911df47ecSMichael Klier    global $lang;
830f3f0262cSandi
831c112d578Sandi    print p_locale_xhtml('backlinks');
832f3f0262cSandi
83354f4c056SAndreas Gohr    $data = ft_backlinks($ID);
834f3f0262cSandi
83511df47ecSMichael Klier    if(!empty($data)) {
836f3f0262cSandi        print '<ul class="idx">';
83754f4c056SAndreas Gohr        foreach($data as $blink){
8380c6b58a8SAndreas Gohr            print '<li><div class="li">';
839db959ae3SAndreas Gohr            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
8400c6b58a8SAndreas Gohr            print '</div></li>';
841f3f0262cSandi        }
842f3f0262cSandi        print '</ul>';
84311df47ecSMichael Klier    } else {
84411df47ecSMichael Klier        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
84511df47ecSMichael Klier    }
846f3f0262cSandi}
847f3f0262cSandi
84815fae107Sandi/**
84915fae107Sandi * show diff
85015fae107Sandi *
85115fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
85215fae107Sandi */
853f3f0262cSandifunction html_diff($text='',$intro=true){
854ed7b5f09Sandi    require_once(DOKU_INC.'inc/DifferenceEngine.php');
855f3f0262cSandi    global $ID;
856f3f0262cSandi    global $REV;
857f3f0262cSandi    global $lang;
858f3f0262cSandi    global $conf;
859e1bd90ffSAndreas Gohr
86077707b04SAndreas Gohr    // we're trying to be clever here, revisions to compare can be either
86177707b04SAndreas Gohr    // given as rev and rev2 parameters, with rev2 being optional. Or in an
86277707b04SAndreas Gohr    // array in rev2.
86377707b04SAndreas Gohr    $rev1 = $REV;
8647b3f8b16SAndreas Gohr
86577707b04SAndreas Gohr    if(is_array($_REQUEST['rev2'])){
86677707b04SAndreas Gohr        $rev1 = (int) $_REQUEST['rev2'][0];
86777707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'][1];
86854041c77SAndreas Gohr
86954041c77SAndreas Gohr        if(!$rev1){
87054041c77SAndreas Gohr            $rev1 = $rev2;
87154041c77SAndreas Gohr            unset($rev2);
87254041c77SAndreas Gohr        }
873f3f0262cSandi    }else{
87477707b04SAndreas Gohr        $rev2 = (int) $_REQUEST['rev2'];
8754d58bd99Sandi    }
8764d58bd99Sandi
87777707b04SAndreas Gohr    if($text){                      // compare text to the most current revision
87877707b04SAndreas Gohr        $l_rev   = '';
87977707b04SAndreas Gohr        $l_text  = rawWiki($ID,'');
88077707b04SAndreas Gohr        $l_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
881f2263577SAndreas Gohr            $ID.' '.dformat((int) @filemtime(wikiFN($ID))).'</a> '.
88277707b04SAndreas Gohr            $lang['current'];
88377707b04SAndreas Gohr
88477707b04SAndreas Gohr        $r_rev   = '';
88577707b04SAndreas Gohr        $r_text  = cleanText($text);
88677707b04SAndreas Gohr        $r_head  = $lang['yours'];
887e1bd90ffSAndreas Gohr    }else{
88877707b04SAndreas Gohr        if($rev1 && $rev2){            // two specific revisions wanted
88954041c77SAndreas Gohr            // make sure order is correct (older on the left)
89077707b04SAndreas Gohr            if($rev1 < $rev2){
89177707b04SAndreas Gohr                $l_rev = $rev1;
89277707b04SAndreas Gohr                $r_rev = $rev2;
89377707b04SAndreas Gohr            }else{
89477707b04SAndreas Gohr                $l_rev = $rev2;
89577707b04SAndreas Gohr                $r_rev = $rev1;
896e1bd90ffSAndreas Gohr            }
89777707b04SAndreas Gohr        }elseif($rev1){                // single revision given, compare to current
89877707b04SAndreas Gohr            $r_rev = '';
89977707b04SAndreas Gohr            $l_rev = $rev1;
90077707b04SAndreas Gohr        }else{                        // no revision was given, compare previous to current
90177707b04SAndreas Gohr            $r_rev = '';
90277707b04SAndreas Gohr            $revs = getRevisions($ID, 0, 1);
90377707b04SAndreas Gohr            $l_rev = $revs[0];
9046f8e9f59SAndreas Gohr            $REV = $l_rev; // store revision back in $REV
90577707b04SAndreas Gohr        }
90677707b04SAndreas Gohr
9077b3f8b16SAndreas Gohr        // when both revisions are empty then the page was created just now
9087b3f8b16SAndreas Gohr        if(!$l_rev && !$r_rev){
9097b3f8b16SAndreas Gohr            $l_text = '';
9107b3f8b16SAndreas Gohr        }else{
91177707b04SAndreas Gohr            $l_text = rawWiki($ID,$l_rev);
9127b3f8b16SAndreas Gohr        }
91377707b04SAndreas Gohr        $r_text = rawWiki($ID,$r_rev);
91477707b04SAndreas Gohr
9157b3f8b16SAndreas Gohr        if(!$l_rev){
9167b3f8b16SAndreas Gohr            $l_head = '&mdash;';
9177b3f8b16SAndreas Gohr        }else{
918e5e61eb0SAnika Henke            $l_info   = getRevisionInfo($ID,$l_rev,true);
919db959ae3SAndreas Gohr            if($l_info['user']){
920db959ae3SAndreas Gohr                $l_user = editorinfo($l_info['user']);
921e5e61eb0SAnika Henke                if(auth_ismanager()) $l_user .= ' ('.$l_info['ip'].')';
922db959ae3SAndreas Gohr            } else {
923db959ae3SAndreas Gohr                $l_user = $l_info['ip'];
924db959ae3SAndreas Gohr            }
925e5e61eb0SAnika Henke            $l_user  = '<span class="user">'.$l_user.'</span>';
926e5e61eb0SAnika Henke            $l_sum   = ($l_info['sum']) ? '<span class="sum">'.hsc($l_info['sum']).'</span>' : '';
927e5e61eb0SAnika Henke            if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
928e5e61eb0SAnika Henke
92977707b04SAndreas Gohr            $l_head = '<a class="wikilink1" href="'.wl($ID,"rev=$l_rev").'">'.
930f2263577SAndreas Gohr            $ID.' ['.dformat($l_rev).']</a>'.
931e5e61eb0SAnika Henke            '<br />'.$l_user.' '.$l_sum;
9327b3f8b16SAndreas Gohr        }
93377707b04SAndreas Gohr
93477707b04SAndreas Gohr        if($r_rev){
935e5e61eb0SAnika Henke            $r_info   = getRevisionInfo($ID,$r_rev,true);
936db959ae3SAndreas Gohr            if($r_info['user']){
937db959ae3SAndreas Gohr                $r_user = editorinfo($r_info['user']);
938e5e61eb0SAnika Henke                if(auth_ismanager()) $r_user .= ' ('.$r_info['ip'].')';
939db959ae3SAndreas Gohr            } else {
940db959ae3SAndreas Gohr                $r_user = $r_info['ip'];
941db959ae3SAndreas Gohr            }
942e5e61eb0SAnika Henke            $r_user = '<span class="user">'.$r_user.'</span>';
943e5e61eb0SAnika Henke            $r_sum  = ($r_info['sum']) ? '<span class="sum">'.hsc($r_info['sum']).'</span>' : '';
944e5e61eb0SAnika Henke            if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
945e5e61eb0SAnika Henke
94677707b04SAndreas Gohr            $r_head = '<a class="wikilink1" href="'.wl($ID,"rev=$r_rev").'">'.
947f2263577SAndreas Gohr            $ID.' ['.dformat($r_rev).']</a>'.
948e5e61eb0SAnika Henke            '<br />'.$r_user.' '.$r_sum;
9497b3f8b16SAndreas Gohr        }elseif($_rev = @filemtime(wikiFN($ID))){
950e5e61eb0SAnika Henke            $_info   = getRevisionInfo($ID,$_rev,true);
951db959ae3SAndreas Gohr            if($_info['user']){
952db959ae3SAndreas Gohr                $_user = editorinfo($_info['user']);
953e5e61eb0SAnika Henke                if(auth_ismanager()) $_user .= ' ('.$_info['ip'].')';
954db959ae3SAndreas Gohr            } else {
955db959ae3SAndreas Gohr                $_user = $_info['ip'];
956db959ae3SAndreas Gohr            }
957e5e61eb0SAnika Henke            $_user = '<span class="user">'.$_user.'</span>';
958e5e61eb0SAnika Henke            $_sum  = ($_info['sum']) ? '<span class="sum">'.hsc($_info['sum']).'</span>' : '';
959e5e61eb0SAnika Henke            if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
960e5e61eb0SAnika Henke
96177707b04SAndreas Gohr            $r_head  = '<a class="wikilink1" href="'.wl($ID).'">'.
962f2263577SAndreas Gohr            $ID.' ['.dformat($_rev).']</a> '.
963658b1aa0SAnika Henke            '('.$lang['current'].')'.
964e5e61eb0SAnika Henke            '<br />'.$_user.' '.$_sum;
9657b3f8b16SAndreas Gohr        }else{
966658b1aa0SAnika Henke            $r_head = '&mdash; ('.$lang['current'].')';
967f3f0262cSandi        }
96877707b04SAndreas Gohr    }
96977707b04SAndreas Gohr
97077707b04SAndreas Gohr    $df = new Diff(explode("\n",htmlspecialchars($l_text)),
97177707b04SAndreas Gohr        explode("\n",htmlspecialchars($r_text)));
97277707b04SAndreas Gohr
973f3f0262cSandi    $tdf = new TableDiffFormatter();
974c112d578Sandi    if($intro) print p_locale_xhtml('diff');
975f3f0262cSandi    ?>
976daf4ca4eSAnika Henke    <table class="diff">
977f3f0262cSandi    <tr>
978e5e61eb0SAnika Henke    <th colspan="2" <?php echo $l_minor?>>
97977707b04SAndreas Gohr    <?php echo $l_head?>
980daf4ca4eSAnika Henke    </th>
981e5e61eb0SAnika Henke    <th colspan="2" <?php echo $r_minor?>>
98277707b04SAndreas Gohr    <?php echo $r_head?>
983daf4ca4eSAnika Henke    </th>
984f3f0262cSandi    </tr>
9854da078a3Smatthiasgrimm    <?php echo $tdf->format($df)?>
986f3f0262cSandi    </table>
9874da078a3Smatthiasgrimm    <?php
988f3f0262cSandi}
989f3f0262cSandi
99015fae107Sandi/**
99115fae107Sandi * show warning on conflict detection
99215fae107Sandi *
99315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
99415fae107Sandi */
995f3f0262cSandifunction html_conflict($text,$summary){
996f3f0262cSandi    global $ID;
997f3f0262cSandi    global $lang;
998f3f0262cSandi
999c112d578Sandi    print p_locale_xhtml('conflict');
1000fdb8d77bSTom N Harris    $form = new Doku_Form('dw__editform');
1001fdb8d77bSTom N Harris    $form->addHidden('id', $ID);
1002fdb8d77bSTom N Harris    $form->addHidden('wikitext', $text);
1003fdb8d77bSTom N Harris    $form->addHidden('summary', $summary);
1004fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1005fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1006fdb8d77bSTom N Harris    html_form('conflict', $form);
1007fdb8d77bSTom N Harris    print '<br /><br /><br /><br />'.NL;
1008f3f0262cSandi}
1009f3f0262cSandi
1010f3f0262cSandi/**
101115fae107Sandi * Prints the global message array
101215fae107Sandi *
101315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1014f3f0262cSandi */
1015f3f0262cSandifunction html_msgarea(){
1016f3f0262cSandi    global $MSG;
1017f3f0262cSandi    if(!isset($MSG)) return;
1018f3f0262cSandi
10194af9f0d4SAndreas Gohr    $shown = array();
1020f3f0262cSandi    foreach($MSG as $msg){
10214af9f0d4SAndreas Gohr        $hash = md5($msg['msg']);
10224af9f0d4SAndreas Gohr        if(isset($shown[$hash])) continue; // skip double messages
1023f3f0262cSandi        print '<div class="'.$msg['lvl'].'">';
1024f3f0262cSandi        print $msg['msg'];
1025f3f0262cSandi        print '</div>';
10264af9f0d4SAndreas Gohr        $shown[$hash] = 1;
1027f3f0262cSandi    }
1028f3f0262cSandi}
1029f3f0262cSandi
1030f3f0262cSandi/**
1031f3f0262cSandi * Prints the registration form
103215fae107Sandi *
103315fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1034f3f0262cSandi */
1035f3f0262cSandifunction html_register(){
1036f3f0262cSandi    global $lang;
1037cab2716aSmatthias.grimm    global $conf;
1038f3f0262cSandi    global $ID;
1039f3f0262cSandi
1040c112d578Sandi    print p_locale_xhtml('register');
1041fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1042fdb8d77bSTom N Harris    $form = new Doku_Form('dw__register', wl($ID));
1043fdb8d77bSTom N Harris    $form->startFieldset($lang['register']);
1044fdb8d77bSTom N Harris    $form->addHidden('do', 'register');
1045fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1046fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], null, 'block', array('size'=>'50')));
1047cab2716aSmatthias.grimm    if (!$conf['autopasswd']) {
1048fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
1049fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1050cab2716aSmatthias.grimm    }
1051fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', array('size'=>'50')));
1052fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', array('size'=>'50')));
1053fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['register']));
1054fdb8d77bSTom N Harris    $form->endFieldset();
1055fdb8d77bSTom N Harris    html_form('register', $form);
1056cab2716aSmatthias.grimm
1057fdb8d77bSTom N Harris    print '</div>'.NL;
1058f3f0262cSandi}
1059f3f0262cSandi
1060f3f0262cSandi/**
10618b06d178Schris * Print the update profile form
10628b06d178Schris *
10638b06d178Schris * @author Christopher Smith <chris@jalakai.co.uk>
10648b06d178Schris * @author Andreas Gohr <andi@splitbrain.org>
10658b06d178Schris */
10668b06d178Schrisfunction html_updateprofile(){
10678b06d178Schris    global $lang;
10688b06d178Schris    global $conf;
10698b06d178Schris    global $ID;
10708b06d178Schris    global $INFO;
107182fd59b6SAndreas Gohr    global $auth;
10728b06d178Schris
10738b06d178Schris    print p_locale_xhtml('updateprofile');
10748b06d178Schris
10758b06d178Schris    if (empty($_POST['fullname'])) $_POST['fullname'] = $INFO['userinfo']['name'];
10768b06d178Schris    if (empty($_POST['email'])) $_POST['email'] = $INFO['userinfo']['mail'];
1077fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1078fdb8d77bSTom N Harris    $form = new Doku_Form('dw__register', wl($ID));
1079fdb8d77bSTom N Harris    $form->startFieldset($lang['profile']);
1080fdb8d77bSTom N Harris    $form->addHidden('do', 'profile');
1081fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1082fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1083fdb8d77bSTom N Harris    $attr = array('size'=>'50');
1084fdb8d77bSTom N Harris    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1085fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('fullname', $_POST['fullname'], $lang['fullname'], '', 'block', $attr));
108639ba8890SAndreas Gohr    $attr = array('size'=>'50');
108739ba8890SAndreas Gohr    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1088fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('email', $_POST['email'], $lang['email'], '', 'block', $attr));
1089fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1090fdb8d77bSTom N Harris    if ($auth->canDo('modPass')) {
1091fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1092fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1093fdb8d77bSTom N Harris    }
1094fdb8d77bSTom N Harris    if ($conf['profileconfirm']) {
1095fdb8d77bSTom N Harris        $form->addElement(form_makeTag('br'));
1096fdb8d77bSTom N Harris        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50')));
1097fdb8d77bSTom N Harris    }
1098fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1099fdb8d77bSTom N Harris    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1100fdb8d77bSTom N Harris    $form->endFieldset();
1101fdb8d77bSTom N Harris    html_form('updateprofile', $form);
1102fdb8d77bSTom N Harris    print '</div>'.NL;
11038b06d178Schris}
11048b06d178Schris
11058b06d178Schris/**
1106f3f0262cSandi * This displays the edit form (lots of logic included)
110715fae107Sandi *
11087146cee2SAndreas Gohr * @fixme    this is a huge lump of code and should be modularized
1109016b6153SAndreas Gohr * @triggers HTML_PAGE_FROMTEMPLATE
1110c9570649SAndreas Gohr * @triggers HTML_EDITFORM_INJECTION
111115fae107Sandi * @author   Andreas Gohr <andi@splitbrain.org>
1112f3f0262cSandi */
1113f3f0262cSandifunction html_edit($text=null,$include='edit'){ //FIXME: include needed?
1114f3f0262cSandi    global $ID;
1115f3f0262cSandi    global $REV;
1116f3f0262cSandi    global $DATE;
1117f3f0262cSandi    global $RANGE;
1118f3f0262cSandi    global $PRE;
1119f3f0262cSandi    global $SUF;
1120f3f0262cSandi    global $INFO;
1121f3f0262cSandi    global $SUM;
1122f3f0262cSandi    global $lang;
1123f3f0262cSandi    global $conf;
1124066fee30SAndreas Gohr    global $license;
1125f3f0262cSandi
1126f3f0262cSandi    //set summary default
1127f3f0262cSandi    if(!$SUM){
1128f3f0262cSandi        if($REV){
1129f3f0262cSandi            $SUM = $lang['restored'];
1130f3f0262cSandi        }elseif(!$INFO['exists']){
1131f3f0262cSandi            $SUM = $lang['created'];
1132f3f0262cSandi        }
1133f3f0262cSandi    }
1134f3f0262cSandi
1135f3f0262cSandi    //no text? Load it!
1136f3f0262cSandi    if(!isset($text)){
1137f3f0262cSandi        $pr = false; //no preview mode
11387146cee2SAndreas Gohr        if($INFO['exists']){
1139f3f0262cSandi            if($RANGE){
1140f3f0262cSandi                list($PRE,$text,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
1141f3f0262cSandi            }else{
1142f3f0262cSandi                $text = rawWiki($ID,$REV);
1143f3f0262cSandi            }
11448fe3bb00STom N Harris            $check = md5($text);
11458fe3bb00STom N Harris            $mod = false;
1146f3f0262cSandi        }else{
11477146cee2SAndreas Gohr            //try to load a pagetemplate
1148b7d5a5f0SAndreas Gohr            $data = array($ID);
1149016b6153SAndreas Gohr            $text = trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
11508fe3bb00STom N Harris            $check = md5('');
11518fe3bb00STom N Harris            $mod = $text!=='';
11527146cee2SAndreas Gohr        }
11537146cee2SAndreas Gohr    }else{
1154f3f0262cSandi        $pr = true; //preview mode
11558fe3bb00STom N Harris        if (isset($_REQUEST['changecheck'])) {
11568fe3bb00STom N Harris            $check = $_REQUEST['changecheck'];
11578fe3bb00STom N Harris            $mod = md5($text)!==$check;
11588fe3bb00STom N Harris        } else {
11598fe3bb00STom N Harris            // Why? Assume default text is unmodified.
11608fe3bb00STom N Harris            $check = md5($text);
11618fe3bb00STom N Harris            $mod = false;
11628fe3bb00STom N Harris        }
1163f3f0262cSandi    }
1164f3f0262cSandi
116527eb9321SAnika Henke    $wr = $INFO['writable'] && !$INFO['locked'];
1166f3f0262cSandi    if($wr){
1167c112d578Sandi        if ($REV) print p_locale_xhtml('editrev');
1168c112d578Sandi        print p_locale_xhtml($include);
1169f3f0262cSandi    }else{
1170409d7af7SAndreas Gohr        // check pseudo action 'source'
1171409d7af7SAndreas Gohr        if(!actionOK('source')){
1172409d7af7SAndreas Gohr            msg('Command disabled: source',-1);
1173409d7af7SAndreas Gohr            return;
1174409d7af7SAndreas Gohr        }
1175c112d578Sandi        print p_locale_xhtml('read');
1176f3f0262cSandi    }
1177f3f0262cSandi    if(!$DATE) $DATE = $INFO['lastmod'];
1178f3f0262cSandi    ?>
117963afe2a6SAnika Henke        <div style="width:99%;">
118042c7abd6SAndreas Gohr
118163afe2a6SAnika Henke        <div class="toolbar">
1182f2263577SAndreas Gohr        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1183fdb8d77bSTom N Harris        <div id="tool__bar"><?php if($wr){?><a href="<?php echo DOKU_BASE?>lib/exe/mediamanager.php?ns=<?php echo $INFO['namespace']?>"
1184409d7af7SAndreas Gohr            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
118520d062caSAndreas Gohr
11864da078a3Smatthiasgrimm            <?php if($wr){?>
1187e226efe1SAndreas Gohr                <script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--
11884da078a3Smatthiasgrimm                    <?php /* sets changed to true when previewed */?>
11898fe3bb00STom N Harris                    textChanged = <?php ($mod) ? print 'true' : print 'false' ?>;
1190e226efe1SAndreas Gohr                //--><!]]></script>
119124a33b42SAndreas Gohr                <span id="spell__action"></span>
1192ee4c4a1bSAndreas Gohr            <?php } ?>
119363afe2a6SAnika Henke        </div>
11944da078a3Smatthiasgrimm        <?php
1195fdb8d77bSTom N Harris        $form = new Doku_Form('dw__editform');
1196fdb8d77bSTom N Harris        $form->addHidden('id', $ID);
1197fdb8d77bSTom N Harris        $form->addHidden('rev', $REV);
1198fdb8d77bSTom N Harris        $form->addHidden('date', $DATE);
1199fdb8d77bSTom N Harris        $form->addHidden('prefix', $PRE);
1200fdb8d77bSTom N Harris        $form->addHidden('suffix', $SUF);
1201fdb8d77bSTom N Harris        $form->addHidden('changecheck', $check);
1202fdb8d77bSTom N Harris        $attr = array('tabindex'=>'1');
1203fdb8d77bSTom N Harris        if (!$wr) $attr['readonly'] = 'readonly';
1204fdb8d77bSTom N Harris        $form->addElement(form_makeWikiText($text, $attr));
1205fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar')));
1206fdb8d77bSTom N Harris        $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1207fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1208fdb8d77bSTom N Harris        if ($wr) {
1209fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1210fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1211fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1212fdb8d77bSTom N Harris            $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1213fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1214fdb8d77bSTom N Harris            $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1215fdb8d77bSTom N Harris            $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1216fdb8d77bSTom N Harris            $elem = html_minoredit();
1217fdb8d77bSTom N Harris            if ($elem) $form->addElement($elem);
1218fdb8d77bSTom N Harris            $form->addElement(form_makeCloseTag('div'));
1219fdb8d77bSTom N Harris        }
1220fdb8d77bSTom N Harris        $form->addElement(form_makeCloseTag('div'));
1221*5808bc54SAndreas Gohr        if($wr && $conf['license']){
1222066fee30SAndreas Gohr            $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1223066fee30SAndreas Gohr            $out  = $lang['licenseok'];
1224066fee30SAndreas Gohr            $out .= '<a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1225066fee30SAndreas Gohr            if($conf['target']['external']) $out .= ' target="'.$conf['target']['external'].'"';
1226066fee30SAndreas Gohr            $out .= '> '.$license[$conf['license']]['name'].'</a>';
1227066fee30SAndreas Gohr            $form->addElement($out);
1228066fee30SAndreas Gohr            $form->addElement(form_makeCloseTag('div'));
1229066fee30SAndreas Gohr        }
1230fdb8d77bSTom N Harris        html_form('edit', $form);
1231fdb8d77bSTom N Harris        print '</div>'.NL;
1232f3f0262cSandi}
1233f3f0262cSandi
1234f3f0262cSandi/**
1235b6912aeaSAndreas Gohr * Adds a checkbox for minor edits for logged in users
1236b6912aeaSAndreas Gohr *
1237b6912aeaSAndreas Gohr * @author Andrea Gohr <andi@splitbrain.org>
1238b6912aeaSAndreas Gohr */
1239b6912aeaSAndreas Gohrfunction html_minoredit(){
1240b6912aeaSAndreas Gohr    global $conf;
1241b6912aeaSAndreas Gohr    global $lang;
1242b6912aeaSAndreas Gohr    // minor edits are for logged in users only
1243b6912aeaSAndreas Gohr    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1244fdb8d77bSTom N Harris        return false;
1245b6912aeaSAndreas Gohr    }
1246b6912aeaSAndreas Gohr
1247b6912aeaSAndreas Gohr    $p = array();
1248b6912aeaSAndreas Gohr    $p['tabindex'] = 3;
1249bb4866bdSchris    if(!empty($_REQUEST['minor'])) $p['checked']='checked';
1250fdb8d77bSTom N Harris    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1251b6912aeaSAndreas Gohr}
1252b6912aeaSAndreas Gohr
1253b6912aeaSAndreas Gohr/**
1254f3f0262cSandi * prints some debug info
125515fae107Sandi *
125615fae107Sandi * @author Andreas Gohr <andi@splitbrain.org>
1257f3f0262cSandi */
1258f3f0262cSandifunction html_debug(){
1259f3f0262cSandi    global $conf;
1260d16a4edaSandi    global $lang;
12615298a619SAndreas Gohr    global $auth;
1262100a97e3SAndreas Gohr    global $INFO;
1263100a97e3SAndreas Gohr
126428fb55ffSandi    //remove sensitive data
126528fb55ffSandi    $cnf = $conf;
126624297a69SAndreas Gohr    debug_guard($cnf);
1267100a97e3SAndreas Gohr    $nfo = $INFO;
126824297a69SAndreas Gohr    debug_guard($nfo);
1269100a97e3SAndreas Gohr    $ses = $_SESSION;
127024297a69SAndreas Gohr    debug_guard($ses);
1271f3f0262cSandi
1272f3f0262cSandi    print '<html><body>';
1273f3f0262cSandi
1274f3f0262cSandi    print '<p>When reporting bugs please send all the following ';
1275f3f0262cSandi    print 'output as a mail to andi@splitbrain.org ';
1276f3f0262cSandi    print 'The best way to do this is to save this page in your browser</p>';
1277f3f0262cSandi
1278100a97e3SAndreas Gohr    print '<b>$INFO:</b><pre>';
1279100a97e3SAndreas Gohr    print_r($nfo);
1280100a97e3SAndreas Gohr    print '</pre>';
1281100a97e3SAndreas Gohr
1282f3f0262cSandi    print '<b>$_SERVER:</b><pre>';
1283f3f0262cSandi    print_r($_SERVER);
1284f3f0262cSandi    print '</pre>';
1285f3f0262cSandi
1286f3f0262cSandi    print '<b>$conf:</b><pre>';
128728fb55ffSandi    print_r($cnf);
1288f3f0262cSandi    print '</pre>';
1289f3f0262cSandi
1290ed7b5f09Sandi    print '<b>DOKU_BASE:</b><pre>';
1291ed7b5f09Sandi    print DOKU_BASE;
1292f3f0262cSandi    print '</pre>';
1293f3f0262cSandi
1294ed7b5f09Sandi    print '<b>abs DOKU_BASE:</b><pre>';
1295ed7b5f09Sandi    print DOKU_URL;
1296ed7b5f09Sandi    print '</pre>';
1297ed7b5f09Sandi
1298ed7b5f09Sandi    print '<b>rel DOKU_BASE:</b><pre>';
1299f3f0262cSandi    print dirname($_SERVER['PHP_SELF']).'/';
1300f3f0262cSandi    print '</pre>';
1301f3f0262cSandi
1302f3f0262cSandi    print '<b>PHP Version:</b><pre>';
1303f3f0262cSandi    print phpversion();
1304f3f0262cSandi    print '</pre>';
1305f3f0262cSandi
1306f3f0262cSandi    print '<b>locale:</b><pre>';
1307f3f0262cSandi    print setlocale(LC_ALL,0);
1308f3f0262cSandi    print '</pre>';
1309f3f0262cSandi
1310d16a4edaSandi    print '<b>encoding:</b><pre>';
1311d16a4edaSandi    print $lang['encoding'];
1312d16a4edaSandi    print '</pre>';
1313d16a4edaSandi
13145298a619SAndreas Gohr    if($auth){
13155298a619SAndreas Gohr        print '<b>Auth backend capabilities:</b><pre>';
13165298a619SAndreas Gohr        print_r($auth->cando);
13175298a619SAndreas Gohr        print '</pre>';
13185298a619SAndreas Gohr    }
13195298a619SAndreas Gohr
13203aa54d7cSAndreas Gohr    print '<b>$_SESSION:</b><pre>';
1321100a97e3SAndreas Gohr    print_r($ses);
13223aa54d7cSAndreas Gohr    print '</pre>';
13233aa54d7cSAndreas Gohr
1324f3f0262cSandi    print '<b>Environment:</b><pre>';
1325f3f0262cSandi    print_r($_ENV);
1326f3f0262cSandi    print '</pre>';
1327f3f0262cSandi
1328f3f0262cSandi    print '<b>PHP settings:</b><pre>';
1329f3f0262cSandi    $inis = ini_get_all();
1330f3f0262cSandi    print_r($inis);
1331f3f0262cSandi    print '</pre>';
1332f3f0262cSandi
1333f3f0262cSandi    print '</body></html>';
1334f3f0262cSandi}
1335f3f0262cSandi
133610271ce4SAndreas Gohr/**
133710271ce4SAndreas Gohr * List available Administration Tasks
133810271ce4SAndreas Gohr *
133910271ce4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
134010271ce4SAndreas Gohr * @author Håkan Sandell <hakan.sandell@home.se>
134110271ce4SAndreas Gohr */
1342c19fe9c0Sandifunction html_admin(){
1343c19fe9c0Sandi    global $ID;
1344f8cc712eSAndreas Gohr    global $INFO;
1345c19fe9c0Sandi    global $lang;
1346ca3a6df1SMatthias Grimm    global $conf;
134710271ce4SAndreas Gohr    global $auth;
1348c19fe9c0Sandi
134911e2ce22Schris    // build menu of admin functions from the plugins that handle them
135011e2ce22Schris    $pluginlist = plugin_list('admin');
135111e2ce22Schris    $menu = array();
135211e2ce22Schris    foreach ($pluginlist as $p) {
1353db959ae3SAndreas Gohr        if($obj =& plugin_load('admin',$p) === null) continue;
1354f8cc712eSAndreas Gohr
1355f8cc712eSAndreas Gohr        // check permissions
1356f8cc712eSAndreas Gohr        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
1357f8cc712eSAndreas Gohr
135810271ce4SAndreas Gohr        $menu[$p] = array('plugin' => $p,
135911e2ce22Schris                'prompt' => $obj->getMenuText($conf['lang']),
136011e2ce22Schris                'sort' => $obj->getMenuSort()
136111e2ce22Schris                );
136211e2ce22Schris    }
136311e2ce22Schris
136410271ce4SAndreas Gohr    print p_locale_xhtml('admin');
136510271ce4SAndreas Gohr
136610271ce4SAndreas Gohr    // Admin Tasks
136710271ce4SAndreas Gohr    if($INFO['isadmin']){
136810271ce4SAndreas Gohr        ptln('<ul class="admin_tasks">');
136910271ce4SAndreas Gohr
137076c65fd3SAndreas Gohr        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
137110271ce4SAndreas Gohr            ptln('  <li class="admin_usermanager"><div class="li">'.
137210271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
137310271ce4SAndreas Gohr                    $menu['usermanager']['prompt'].'</a></div></li>');
137410271ce4SAndreas Gohr        }
137510271ce4SAndreas Gohr        unset($menu['usermanager']);
137610271ce4SAndreas Gohr
137776c65fd3SAndreas Gohr        if($menu['acl']){
137810271ce4SAndreas Gohr            ptln('  <li class="admin_acl"><div class="li">'.
137910271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
138010271ce4SAndreas Gohr                    $menu['acl']['prompt'].'</a></div></li>');
138176c65fd3SAndreas Gohr        }
138210271ce4SAndreas Gohr        unset($menu['acl']);
138310271ce4SAndreas Gohr
138476c65fd3SAndreas Gohr        if($menu['plugin']){
138510271ce4SAndreas Gohr            ptln('  <li class="admin_plugin"><div class="li">'.
138610271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'plugin')).'">'.
138710271ce4SAndreas Gohr                    $menu['plugin']['prompt'].'</a></div></li>');
138876c65fd3SAndreas Gohr        }
138910271ce4SAndreas Gohr        unset($menu['plugin']);
139010271ce4SAndreas Gohr
139176c65fd3SAndreas Gohr        if($menu['config']){
139210271ce4SAndreas Gohr            ptln('  <li class="admin_config"><div class="li">'.
139310271ce4SAndreas Gohr                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
139410271ce4SAndreas Gohr                    $menu['config']['prompt'].'</a></div></li>');
139576c65fd3SAndreas Gohr        }
139610271ce4SAndreas Gohr        unset($menu['config']);
139710271ce4SAndreas Gohr    }
139810271ce4SAndreas Gohr    ptln('</ul>');
139910271ce4SAndreas Gohr
140010271ce4SAndreas Gohr    // Manager Tasks
140110271ce4SAndreas Gohr    ptln('<ul class="admin_tasks">');
140210271ce4SAndreas Gohr
140376c65fd3SAndreas Gohr    if($menu['revert']){
140410271ce4SAndreas Gohr        ptln('  <li class="admin_revert"><div class="li">'.
140510271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
140610271ce4SAndreas Gohr                $menu['revert']['prompt'].'</a></div></li>');
140776c65fd3SAndreas Gohr    }
140810271ce4SAndreas Gohr    unset($menu['revert']);
140910271ce4SAndreas Gohr
141076c65fd3SAndreas Gohr    if($menu['popularity']){
141110271ce4SAndreas Gohr        ptln('  <li class="admin_popularity"><div class="li">'.
141210271ce4SAndreas Gohr                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
141310271ce4SAndreas Gohr                $menu['popularity']['prompt'].'</a></div></li>');
141476c65fd3SAndreas Gohr    }
141510271ce4SAndreas Gohr    unset($menu['popularity']);
141610271ce4SAndreas Gohr
141710271ce4SAndreas Gohr    ptln('</ul>');
141810271ce4SAndreas Gohr
141910271ce4SAndreas Gohr    // print the rest as sorted list
142010271ce4SAndreas Gohr    if(count($menu)){
1421746855cfSBen Coburn        usort($menu, 'p_sort_modes');
142211e2ce22Schris        // output the menu
142310271ce4SAndreas Gohr        ptln('<div class="clearer"></div>');
142410271ce4SAndreas Gohr        print p_locale_xhtml('adminplugins');
142511e2ce22Schris        ptln('<ul>');
142611e2ce22Schris        foreach ($menu as $item) {
142711e2ce22Schris            if (!$item['prompt']) continue;
14280c6b58a8SAndreas Gohr            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
142911e2ce22Schris        }
143011e2ce22Schris        ptln('</ul>');
1431ca3a6df1SMatthias Grimm    }
143210271ce4SAndreas Gohr}
1433c19fe9c0Sandi
14348b06d178Schris/**
14358b06d178Schris * Form to request a new password for an existing account
14368b06d178Schris *
14378b06d178Schris * @author Benoit Chesneau <benoit@bchesneau.info>
143811e2ce22Schris */
14398b06d178Schrisfunction html_resendpwd() {
14408b06d178Schris    global $lang;
14418b06d178Schris    global $conf;
14428b06d178Schris    global $ID;
1443c19fe9c0Sandi
14448b06d178Schris    print p_locale_xhtml('resendpwd');
1445fdb8d77bSTom N Harris    print '<div class="centeralign">'.NL;
1446fdb8d77bSTom N Harris    $form = new Doku_Form('dw__resendpwd', wl($ID));
1447fdb8d77bSTom N Harris    $form->startFieldset($lang['resendpwd']);
1448fdb8d77bSTom N Harris    $form->addHidden('do', 'resendpwd');
1449fdb8d77bSTom N Harris    $form->addHidden('save', '1');
1450fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1451fdb8d77bSTom N Harris    $form->addElement(form_makeTextField('login', $_POST['login'], $lang['user'], '', 'block'));
1452fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1453fdb8d77bSTom N Harris    $form->addElement(form_makeTag('br'));
1454fdb8d77bSTom N Harris    $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
1455fdb8d77bSTom N Harris    $form->endFieldset();
1456fdb8d77bSTom N Harris    html_form('resendpwd', $form);
1457fdb8d77bSTom N Harris    print '</div>'.NL;
1458fdb8d77bSTom N Harris}
1459fdb8d77bSTom N Harris
1460fdb8d77bSTom N Harris/**
1461b8595a66SAndreas Gohr * Return the TOC rendered to XHTML
1462b8595a66SAndreas Gohr *
1463b8595a66SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
1464b8595a66SAndreas Gohr */
1465b8595a66SAndreas Gohrfunction html_TOC($toc){
1466b8595a66SAndreas Gohr    if(!count($toc)) return '';
1467b8595a66SAndreas Gohr    global $lang;
1468b8595a66SAndreas Gohr    $out  = '<!-- TOC START -->'.DOKU_LF;
1469b8595a66SAndreas Gohr    $out .= '<div class="toc">'.DOKU_LF;
1470b8595a66SAndreas Gohr    $out .= '<div class="tocheader toctoggle" id="toc__header">';
1471b8595a66SAndreas Gohr    $out .= $lang['toc'];
1472b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF;
1473b8595a66SAndreas Gohr    $out .= '<div id="toc__inside">'.DOKU_LF;
1474b8595a66SAndreas Gohr    $out .= html_buildlist($toc,'toc','html_list_toc');
1475b8595a66SAndreas Gohr    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
1476b8595a66SAndreas Gohr    $out .= '<!-- TOC END -->'.DOKU_LF;
1477db959ae3SAndreas Gohr    return $out;
1478db959ae3SAndreas Gohr}
1479b8595a66SAndreas Gohr
1480b8595a66SAndreas Gohr/**
1481b8595a66SAndreas Gohr * Callback for html_buildlist
1482b8595a66SAndreas Gohr */
1483b8595a66SAndreas Gohrfunction html_list_toc($item){
14847d91652aSAndreas Gohr    if($item['hid']){
14857d91652aSAndreas Gohr        $link = '#'.$item['hid'];
14867d91652aSAndreas Gohr    }else{
14877d91652aSAndreas Gohr        $link = $item['link'];
14887d91652aSAndreas Gohr    }
14897d91652aSAndreas Gohr
14907d91652aSAndreas Gohr    return '<span class="li"><a href="'.$link.'" class="toc">'.
1491b8595a66SAndreas Gohr        hsc($item['title']).'</a></span>';
1492b8595a66SAndreas Gohr}
1493b8595a66SAndreas Gohr
1494b8595a66SAndreas Gohr/**
1495b8595a66SAndreas Gohr * Helper function to build TOC items
1496b8595a66SAndreas Gohr *
1497b8595a66SAndreas Gohr * Returns an array ready to be added to a TOC array
1498b8595a66SAndreas Gohr *
1499b8595a66SAndreas Gohr * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
1500b8595a66SAndreas Gohr * @param string $text  - what to display in the TOC
1501b8595a66SAndreas Gohr * @param int    $level - nesting level
1502b8595a66SAndreas Gohr * @param string $hash  - is prepended to the given $link, set blank if you want full links
1503b8595a66SAndreas Gohr */
1504b8595a66SAndreas Gohrfunction html_mktocitem($link, $text, $level, $hash='#'){
1505b8595a66SAndreas Gohr    global $conf;
1506b8595a66SAndreas Gohr    return  array( 'link'  => $hash.$link,
1507b8595a66SAndreas Gohr            'title' => $text,
1508b8595a66SAndreas Gohr            'type'  => 'ul',
15092bb0d541Schris            'level' => $level);
1510b8595a66SAndreas Gohr}
1511b8595a66SAndreas Gohr
1512b8595a66SAndreas Gohr/**
1513fdb8d77bSTom N Harris * Output a Doku_Form object.
1514fdb8d77bSTom N Harris * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
1515fdb8d77bSTom N Harris *
1516fdb8d77bSTom N Harris * @author Tom N Harris <tnharris@whoopdedo.org>
1517fdb8d77bSTom N Harris */
1518fdb8d77bSTom N Harrisfunction html_form($name, &$form) {
1519fdb8d77bSTom N Harris    // Safety check in case the caller forgets.
1520fdb8d77bSTom N Harris    $form->endFieldset();
1521fdb8d77bSTom N Harris    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
1522fdb8d77bSTom N Harris}
1523fdb8d77bSTom N Harris
1524fdb8d77bSTom N Harris/**
1525fdb8d77bSTom N Harris * Form print function.
1526fdb8d77bSTom N Harris * Just calls printForm() on the data object.
1527fdb8d77bSTom N Harris */
1528fdb8d77bSTom N Harrisfunction html_form_output($data) {
1529fdb8d77bSTom N Harris    $data->printForm();
15308b06d178Schris}
1531340756e4Sandi
153207bf32b2SAndreas Gohr/**
153307bf32b2SAndreas Gohr * Embed a flash object in HTML
153407bf32b2SAndreas Gohr *
153507bf32b2SAndreas Gohr * This will create the needed HTML to embed a flash movie in a cross browser
153607bf32b2SAndreas Gohr * compatble way using valid XHTML
153707bf32b2SAndreas Gohr *
153807bf32b2SAndreas Gohr * The parameters $params, $flashvars and $atts need to be associative arrays.
153907bf32b2SAndreas Gohr * No escaping needs to be done for them. The alternative content *has* to be
154007bf32b2SAndreas Gohr * escaped because it is used as is. If no alternative content is given
154107bf32b2SAndreas Gohr * $lang['noflash'] is used.
154207bf32b2SAndreas Gohr *
154307bf32b2SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org>
154407bf32b2SAndreas Gohr * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
154507bf32b2SAndreas Gohr *
154607bf32b2SAndreas Gohr * @param string $swf      - the SWF movie to embed
154707bf32b2SAndreas Gohr * @param int $width       - width of the flash movie in pixels
154807bf32b2SAndreas Gohr * @param int $height      - height of the flash movie in pixels
154907bf32b2SAndreas Gohr * @param array $params    - additional parameters (<param>)
155007bf32b2SAndreas Gohr * @param array $flashvars - parameters to be passed in the flashvar parameter
155107bf32b2SAndreas Gohr * @param array $atts      - additional attributes for the <object> tag
155207bf32b2SAndreas Gohr * @param string $alt      - alternative content (is NOT automatically escaped!)
155307bf32b2SAndreas Gohr * @returns string         - the XHTML markup
155407bf32b2SAndreas Gohr */
155507bf32b2SAndreas Gohrfunction html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
155607bf32b2SAndreas Gohr    global $lang;
155707bf32b2SAndreas Gohr
155807bf32b2SAndreas Gohr    $out = '';
155907bf32b2SAndreas Gohr
156007bf32b2SAndreas Gohr    // prepare the object attributes
156107bf32b2SAndreas Gohr    if(is_null($atts)) $atts = array();
156207bf32b2SAndreas Gohr    $atts['width']  = (int) $width;
1563d4c61e61SAndreas Gohr    $atts['height'] = (int) $height;
156407bf32b2SAndreas Gohr    if(!$atts['width'])  $atts['width']  = 425;
156507bf32b2SAndreas Gohr    if(!$atts['height']) $atts['height'] = 350;
156607bf32b2SAndreas Gohr
156707bf32b2SAndreas Gohr    // add object attributes for standard compliant browsers
156807bf32b2SAndreas Gohr    $std = $atts;
156907bf32b2SAndreas Gohr    $std['type'] = 'application/x-shockwave-flash';
157007bf32b2SAndreas Gohr    $std['data'] = $swf;
157107bf32b2SAndreas Gohr
157207bf32b2SAndreas Gohr    // add object attributes for IE
157307bf32b2SAndreas Gohr    $ie  = $atts;
157407bf32b2SAndreas Gohr    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
157507bf32b2SAndreas Gohr
157607bf32b2SAndreas Gohr    // open object (with conditional comments)
157707bf32b2SAndreas Gohr    $out .= '<!--[if !IE]> -->'.NL;
157807bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($std).'>'.NL;
157907bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
158007bf32b2SAndreas Gohr    $out .= '<!--[if IE]>'.NL;
158107bf32b2SAndreas Gohr    $out .= '<object '.buildAttributes($ie).'>'.NL;
158207bf32b2SAndreas Gohr    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
15839ae41cdcSAndreas Gohr    $out .= '<!--><!-- -->'.NL;
158407bf32b2SAndreas Gohr
158507bf32b2SAndreas Gohr    // print params
158607bf32b2SAndreas Gohr    if(is_array($params)) foreach($params as $key => $val){
158707bf32b2SAndreas Gohr        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
158807bf32b2SAndreas Gohr    }
158907bf32b2SAndreas Gohr
159007bf32b2SAndreas Gohr    // add flashvars
159107bf32b2SAndreas Gohr    if(is_array($flashvars)){
1592d4c61e61SAndreas Gohr        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
159307bf32b2SAndreas Gohr    }
159407bf32b2SAndreas Gohr
159507bf32b2SAndreas Gohr    // alternative content
159607bf32b2SAndreas Gohr    if($alt){
159707bf32b2SAndreas Gohr        $out .= $alt.NL;
159807bf32b2SAndreas Gohr    }else{
159907bf32b2SAndreas Gohr        $out .= $lang['noflash'].NL;
160007bf32b2SAndreas Gohr    }
160107bf32b2SAndreas Gohr
160207bf32b2SAndreas Gohr    // finish
160307bf32b2SAndreas Gohr    $out .= '</object>'.NL;
160407bf32b2SAndreas Gohr    $out .= '<!-- <![endif]-->'.NL;
160507bf32b2SAndreas Gohr
160607bf32b2SAndreas Gohr    return $out;
160707bf32b2SAndreas Gohr}
160807bf32b2SAndreas Gohr
1609