Completed
Push — authpdo ( f7028a...7f89f0 )
by Andreas
06:16
created

html.php ➔ html_admin()   F

Complexity

Conditions 22
Paths 4224

Size

Total Lines 125
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 22
eloc 75
c 1
b 0
f 0
nc 4224
nop 0
dl 0
loc 125
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * HTML output functions
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Andreas Gohr <[email protected]>
7
 */
8
9
if(!defined('DOKU_INC')) die('meh.');
10
if(!defined('NL')) define('NL',"\n");
11
12
/**
13
 * Convenience function to quickly build a wikilink
14
 *
15
 * @author Andreas Gohr <[email protected]>
16
 * @param string  $id      id of the target page
17
 * @param string  $name    the name of the link, i.e. the text that is displayed
18
 * @param string|array  $search  search string(s) that shall be highlighted in the target page
19
 * @return string the HTML code of the link
20
 */
21
function html_wikilink($id,$name=null,$search=''){
22
    /** @var Doku_Renderer_xhtml $xhtml_renderer */
23
    static $xhtml_renderer = null;
24
    if(is_null($xhtml_renderer)){
25
        $xhtml_renderer = p_get_renderer('xhtml');
26
    }
27
28
    return $xhtml_renderer->internallink($id,$name,$search,true,'navigation');
29
}
30
31
/**
32
 * The loginform
33
 *
34
 * @author   Andreas Gohr <[email protected]>
35
 */
36
function html_login(){
37
    global $lang;
38
    global $conf;
39
    global $ID;
40
    global $INPUT;
41
42
    print p_locale_xhtml('login');
43
    print '<div class="centeralign">'.NL;
44
    $form = new Doku_Form(array('id' => 'dw__login'));
45
    $form->startFieldset($lang['btn_login']);
46
    $form->addHidden('id', $ID);
47
    $form->addHidden('do', 'login');
48
    $form->addElement(form_makeTextField('u', ((!$INPUT->bool('http_credentials')) ? $INPUT->str('u') : ''), $lang['user'], 'focus__this', 'block'));
49
    $form->addElement(form_makePasswordField('p', $lang['pass'], '', 'block'));
50
    if($conf['rememberme']) {
51
        $form->addElement(form_makeCheckboxField('r', '1', $lang['remember'], 'remember__me', 'simple'));
52
    }
53
    $form->addElement(form_makeButton('submit', '', $lang['btn_login']));
54
    $form->endFieldset();
55
56
    if(actionOK('register')){
57
        $form->addElement('<p>'.$lang['reghere'].': '.tpl_actionlink('register','','','',true).'</p>');
58
    }
59
60
    if (actionOK('resendpwd')) {
61
        $form->addElement('<p>'.$lang['pwdforget'].': '.tpl_actionlink('resendpwd','','','',true).'</p>');
62
    }
63
64
    html_form('login', $form);
65
    print '</div>'.NL;
66
}
67
68
69
/**
70
 * Denied page content
71
 *
72
 * @return string html
73
 */
74
function html_denied() {
75
    print p_locale_xhtml('denied');
76
77
    if(empty($_SERVER['REMOTE_USER'])){
78
        html_login();
79
    }
80
}
81
82
/**
83
 * inserts section edit buttons if wanted or removes the markers
84
 *
85
 * @author Andreas Gohr <[email protected]>
86
 *
87
 * @param string $text
88
 * @param bool   $show show section edit buttons?
89
 * @return string
90
 */
91
function html_secedit($text,$show=true){
92
    global $INFO;
93
94
    $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#';
95
96
    if(!$INFO['writable'] || !$show || $INFO['rev']){
97
        return preg_replace($regexp,'',$text);
98
    }
99
100
    return preg_replace_callback($regexp,
101
                'html_secedit_button', $text);
102
}
103
104
/**
105
 * prepares section edit button data for event triggering
106
 * used as a callback in html_secedit
107
 *
108
 * @author Andreas Gohr <[email protected]>
109
 *
110
 * @param array $matches matches with regexp
111
 * @return string
112
 * @triggers HTML_SECEDIT_BUTTON
113
 */
114
function html_secedit_button($matches){
115
    $data = array('secid'  => $matches[1],
116
                  'target' => strtolower($matches[2]),
117
                  'range'  => $matches[count($matches) - 1]);
118
    if (count($matches) === 5) {
119
        $data['name'] = $matches[3];
120
    }
121
122
    return trigger_event('HTML_SECEDIT_BUTTON', $data,
123
                         'html_secedit_get_button');
124
}
125
126
/**
127
 * prints a section editing button
128
 * used as default action form HTML_SECEDIT_BUTTON
129
 *
130
 * @author Adrian Lang <[email protected]>
131
 *
132
 * @param array $data name, section id and target
133
 * @return string html
134
 */
135
function html_secedit_get_button($data) {
136
    global $ID;
137
    global $INFO;
138
139
    if (!isset($data['name']) || $data['name'] === '') return '';
140
141
    $name = $data['name'];
142
    unset($data['name']);
143
144
    $secid = $data['secid'];
145
    unset($data['secid']);
146
147
    return "<div class='secedit editbutton_" . $data['target'] .
148
                       " editbutton_" . $secid . "'>" .
149
           html_btn('secedit', $ID, '',
150
                    array_merge(array('do'  => 'edit',
151
                                      'rev' => $INFO['lastmod'],
152
                                      'summary' => '['.$name.'] '), $data),
153
                    'post', $name) . '</div>';
154
}
155
156
/**
157
 * Just the back to top button (in its own form)
158
 *
159
 * @author Andreas Gohr <[email protected]>
160
 *
161
 * @return string html
162
 */
163
function html_topbtn(){
164
    global $lang;
165
166
    $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>';
167
168
    return $ret;
169
}
170
171
/**
172
 * Displays a button (using its own form)
173
 * If tooltip exists, the access key tooltip is replaced.
174
 *
175
 * @author Andreas Gohr <[email protected]>
176
 *
177
 * @param string         $name
178
 * @param string         $id
179
 * @param string         $akey   access key
180
 * @param string[] $params key-value pairs added as hidden inputs
181
 * @param string         $method
182
 * @param string         $tooltip
183
 * @param bool|string    $label  label text, false: lookup btn_$name in localization
184
 * @return string
185
 */
186
function html_btn($name, $id, $akey, $params, $method='get', $tooltip='', $label=false){
187
    global $conf;
188
    global $lang;
189
190
    if (!$label)
191
        $label = $lang['btn_'.$name];
192
193
    $ret = '';
194
195
    //filter id (without urlencoding)
196
    $id = idfilter($id,false);
197
198
    //make nice URLs even for buttons
199
    if($conf['userewrite'] == 2){
200
        $script = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
201
    }elseif($conf['userewrite']){
202
        $script = DOKU_BASE.$id;
203
    }else{
204
        $script = DOKU_BASE.DOKU_SCRIPT;
205
        $params['id'] = $id;
206
    }
207
208
    $ret .= '<form class="button btn_'.$name.'" method="'.$method.'" action="'.$script.'"><div class="no">';
209
210
    if(is_array($params)){
211
        reset($params);
212
        while (list($key, $val) = each($params)) {
213
            $ret .= '<input type="hidden" name="'.$key.'" ';
214
            $ret .= 'value="'.htmlspecialchars($val).'" />';
215
        }
216
    }
217
218
    if ($tooltip!='') {
219
        $tip = htmlspecialchars($tooltip);
220
    }else{
221
        $tip = htmlspecialchars($label);
222
    }
223
224
    $ret .= '<button type="submit" ';
225
    if($akey){
226
        $tip .= ' ['.strtoupper($akey).']';
227
        $ret .= 'accesskey="'.$akey.'" ';
228
    }
229
    $ret .= 'title="'.$tip.'">';
230
    $ret .= hsc($label);
231
    $ret .= '</button>';
232
    $ret .= '</div></form>';
233
234
    return $ret;
235
}
236
/**
237
 * show a revision warning
238
 *
239
 * @author Szymon Olewniczak <[email protected]>
240
 */
241
function html_showrev() {
242
    print p_locale_xhtml('showrev');
243
}
244
245
/**
246
 * Show a wiki page
247
 *
248
 * @author Andreas Gohr <[email protected]>
249
 *
250
 * @param null|string $txt wiki text or null for showing $ID
251
 */
252
function html_show($txt=null){
253
    global $ID;
254
    global $REV;
255
    global $HIGH;
256
    global $INFO;
257
    global $DATE_AT;
258
    //disable section editing for old revisions or in preview
259
    if($txt || $REV){
0 ignored issues
show
Bug Best Practice introduced by
The expression $txt of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
260
        $secedit = false;
261
    }else{
262
        $secedit = true;
263
    }
264
265
    if (!is_null($txt)){
266
        //PreviewHeader
267
        echo '<br id="scroll__here" />';
268
        echo p_locale_xhtml('preview');
269
        echo '<div class="preview"><div class="pad">';
270
        $html = html_secedit(p_render('xhtml',p_get_instructions($txt),$info),$secedit);
271
        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
272
        echo $html;
273
        echo '<div class="clearer"></div>';
274
        echo '</div></div>';
275
276
    }else{
277
        if ($REV||$DATE_AT){
278
            $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
279
            trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
280
        }
281
        $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
282
        $html = html_secedit($html,$secedit);
0 ignored issues
show
Bug introduced by
It seems like $html can also be of type boolean or null; however, html_secedit() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
283
        if($INFO['prependTOC']) $html = tpl_toc(true).$html;
284
        $html = html_hilight($html,$HIGH);
285
        echo $html;
286
    }
287
}
288
289
/**
290
 * ask the user about how to handle an exisiting draft
291
 *
292
 * @author Andreas Gohr <[email protected]>
293
 */
294
function html_draft(){
295
    global $INFO;
296
    global $ID;
297
    global $lang;
298
    $draft = unserialize(io_readFile($INFO['draft'],false));
299
    $text  = cleanText(con($draft['prefix'],$draft['text'],$draft['suffix'],true));
300
301
    print p_locale_xhtml('draft');
302
    $form = new Doku_Form(array('id' => 'dw__editform'));
303
    $form->addHidden('id', $ID);
304
    $form->addHidden('date', $draft['date']);
305
    $form->addElement(form_makeWikiText($text, array('readonly'=>'readonly')));
306
    $form->addElement(form_makeOpenTag('div', array('id'=>'draft__status')));
307
    $form->addElement($lang['draftdate'].' '. dformat(filemtime($INFO['draft'])));
308
    $form->addElement(form_makeCloseTag('div'));
309
    $form->addElement(form_makeButton('submit', 'recover', $lang['btn_recover'], array('tabindex'=>'1')));
310
    $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_draftdel'], array('tabindex'=>'2')));
311
    $form->addElement(form_makeButton('submit', 'show', $lang['btn_cancel'], array('tabindex'=>'3')));
312
    html_form('draft', $form);
313
}
314
315
/**
316
 * Highlights searchqueries in HTML code
317
 *
318
 * @author Andreas Gohr <[email protected]>
319
 * @author Harry Fuecks <[email protected]>
320
 *
321
 * @param string $html
322
 * @param array|string $phrases
323
 * @return string html
324
 */
325
function html_hilight($html,$phrases){
326
    $phrases = (array) $phrases;
327
    $phrases = array_map('preg_quote_cb', $phrases);
328
    $phrases = array_map('ft_snippet_re_preprocess', $phrases);
329
    $phrases = array_filter($phrases);
330
    $regex = join('|',$phrases);
331
332
    if ($regex === '') return $html;
333
    if (!utf8_check($regex)) return $html;
334
    $html = @preg_replace_callback("/((<[^>]*)|$regex)/ui",'html_hilight_callback',$html);
335
    return $html;
336
}
337
338
/**
339
 * Callback used by html_hilight()
340
 *
341
 * @author Harry Fuecks <[email protected]>
342
 *
343
 * @param array $m matches
344
 * @return string html
345
 */
346
function html_hilight_callback($m) {
347
    $hlight = unslash($m[0]);
348
    if ( !isset($m[2])) {
349
        $hlight = '<span class="search_hit">'.$hlight.'</span>';
350
    }
351
    return $hlight;
352
}
353
354
/**
355
 * Run a search and display the result
356
 *
357
 * @author Andreas Gohr <[email protected]>
358
 */
359
function html_search(){
360
    global $QUERY, $ID;
361
    global $lang;
362
363
    $intro = p_locale_xhtml('searchpage');
364
    // allow use of placeholder in search intro
365
    $pagecreateinfo = (auth_quickaclcheck($ID) >= AUTH_CREATE) ? $lang['searchcreatepage'] : '';
366
    $intro = str_replace(
367
        array('@QUERY@', '@SEARCH@', '@CREATEPAGEINFO@'),
368
        array(hsc(rawurlencode($QUERY)), hsc($QUERY), $pagecreateinfo),
369
        $intro
370
    );
371
    echo $intro;
372
    flush();
373
374
    //show progressbar
375
    print '<div id="dw__loading">'.NL;
376
    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
377
    print 'showLoadBar();'.NL;
378
    print '/*!]]>*/</script>'.NL;
379
    print '</div>'.NL;
380
    flush();
381
382
    //do quick pagesearch
383
    $data = ft_pageLookup($QUERY,true,useHeading('navigation'));
384
    if(count($data)){
385
        print '<div class="search_quickresult">';
386
        print '<h3>'.$lang['quickhits'].':</h3>';
387
        print '<ul class="search_quickhits">';
388
        foreach($data as $id => $title){
389
            print '<li> ';
390
            if (useHeading('navigation')) {
391
                $name = $title;
392
            }else{
393
                $ns = getNS($id);
394
                if($ns){
0 ignored issues
show
Bug Best Practice introduced by
The expression $ns of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
395
                    $name = shorten(noNS($id), ' ('.$ns.')',30);
396
                }else{
397
                    $name = $id;
398
                }
399
            }
400
            print html_wikilink(':'.$id,$name);
401
            print '</li> ';
402
        }
403
        print '</ul> ';
404
        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
405
        print '<div class="clearer"></div>';
406
        print '</div>';
407
    }
408
    flush();
409
410
    //do fulltext search
411
    $data = ft_pageSearch($QUERY,$regex);
412
    if(count($data)){
413
        print '<dl class="search_results">';
414
        $num = 1;
415
        foreach($data as $id => $cnt){
416
            print '<dt>';
417
            print html_wikilink(':'.$id,useHeading('navigation')?null:$id,$regex);
418
            if($cnt !== 0){
419
                print ': '.$cnt.' '.$lang['hits'].'';
420
            }
421
            print '</dt>';
422
            if($cnt !== 0){
423
                if($num < FT_SNIPPET_NUMBER){ // create snippets for the first number of matches only
424
                    print '<dd>'.ft_snippet($id,$regex).'</dd>';
425
                }
426
                $num++;
427
            }
428
            flush();
429
        }
430
        print '</dl>';
431
    }else{
432
        print '<div class="nothing">'.$lang['nothingfound'].'</div>';
433
    }
434
435
    //hide progressbar
436
    print '<script type="text/javascript">/*<![CDATA[*/'.NL;
437
    print 'hideLoadBar("dw__loading");'.NL;
438
    print '/*!]]>*/</script>'.NL;
439
    flush();
440
}
441
442
/**
443
 * Display error on locked pages
444
 *
445
 * @author Andreas Gohr <[email protected]>
446
 */
447
function html_locked(){
448
    global $ID;
449
    global $conf;
450
    global $lang;
451
    global $INFO;
452
453
    $locktime = filemtime(wikiLockFN($ID));
454
    $expire = dformat($locktime + $conf['locktime']);
455
    $min    = round(($conf['locktime'] - (time() - $locktime) )/60);
456
457
    print p_locale_xhtml('locked');
458
    print '<ul>';
459
    print '<li><div class="li"><strong>'.$lang['lockedby'].'</strong> '.editorinfo($INFO['locked']).'</div></li>';
460
    print '<li><div class="li"><strong>'.$lang['lockexpire'].'</strong> '.$expire.' ('.$min.' min)</div></li>';
461
    print '</ul>';
462
}
463
464
/**
465
 * list old revisions
466
 *
467
 * @author Andreas Gohr <[email protected]>
468
 * @author Ben Coburn <[email protected]>
469
 * @author Kate Arzamastseva <[email protected]>
470
 *
471
 * @param int $first skip the first n changelog lines
472
 * @param bool|string $media_id id of media, or false for current page
473
 */
474
function html_revisions($first=0, $media_id = false){
475
    global $ID;
476
    global $INFO;
477
    global $conf;
478
    global $lang;
479
    $id = $ID;
480
    if ($media_id) {
481
        $id = $media_id;
482
        $changelog = new MediaChangeLog($id);
483
    } else {
484
        $changelog = new PageChangeLog($id);
485
    }
486
487
    /* we need to get one additional log entry to be able to
488
     * decide if this is the last page or is there another one.
489
     * see html_recent()
490
     */
491
492
    $revisions = $changelog->getRevisions($first, $conf['recent']+1);
493
494
    if(count($revisions)==0 && $first!=0){
495
        $first=0;
496
        $revisions = $changelog->getRevisions($first, $conf['recent']+1);
497
    }
498
    $hasNext = false;
499
    if (count($revisions)>$conf['recent']) {
500
        $hasNext = true;
501
        array_pop($revisions); // remove extra log entry
502
    }
503
504
    if (!$media_id) $date = dformat($INFO['lastmod']);
505
    else $date = dformat(@filemtime(mediaFN($id)));
506
507
    if (!$media_id) print p_locale_xhtml('revisions');
508
509
    $params = array('id' => 'page__revisions', 'class' => 'changes');
510
    if ($media_id) $params['action'] = media_managerURL(array('image' => $media_id), '&');
511
512
    $form = new Doku_Form($params);
513
    $form->addElement(form_makeOpenTag('ul'));
514
515
    if (!$media_id) $exists = $INFO['exists'];
516
    else $exists = file_exists(mediaFN($id));
517
518
    $display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id;
519
    if (!$display_name) $display_name = $id;
520
521
    if($exists && $first==0){
522
        if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
523
            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
524
        else
525
            $form->addElement(form_makeOpenTag('li'));
526
        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
527
        $form->addElement(form_makeTag('input', array(
528
                        'type' => 'checkbox',
529
                        'name' => 'rev2[]',
530
                        'value' => 'current')));
531
532
        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
533
        $form->addElement($date);
534
        $form->addElement(form_makeCloseTag('span'));
535
536
        $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
537
538
        if (!$media_id) $href = wl($id);
539
        else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&');
540
        $form->addElement(form_makeOpenTag('a', array(
541
                        'class' => 'wikilink1',
542
                        'href'  => $href)));
543
        $form->addElement($display_name);
544
        $form->addElement(form_makeCloseTag('a'));
545
546
        if ($media_id) $form->addElement(form_makeOpenTag('div'));
547
548
        if (!$media_id) {
549
            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
550
            $form->addElement(' – ');
551
            $form->addElement(htmlspecialchars($INFO['sum']));
552
            $form->addElement(form_makeCloseTag('span'));
553
        }
554
555
        $changelog->setChunkSize(1024);
556
557
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
558
        if($media_id) {
559
            $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id))));
560
            if($revinfo['user']) {
561
                $editor = $revinfo['user'];
562
            } else {
563
                $editor = $revinfo['ip'];
564
            }
565
        } else {
566
            $editor = $INFO['editor'];
567
        }
568
        $form->addElement((empty($editor))?('('.$lang['external_edit'].')'):editorinfo($editor));
569
        $form->addElement(form_makeCloseTag('span'));
570
571
        $form->addElement('('.$lang['current'].')');
572
573
        if ($media_id) $form->addElement(form_makeCloseTag('div'));
574
575
        $form->addElement(form_makeCloseTag('div'));
576
        $form->addElement(form_makeCloseTag('li'));
577
    }
578
579
    foreach($revisions as $rev){
580
        $date = dformat($rev);
581
        $info = $changelog->getRevisionInfo($rev);
582
        if($media_id) {
583
            $exists = file_exists(mediaFN($id, $rev));
584
        } else {
585
            $exists = page_exists($id, $rev);
586
        }
587
588
        if ($info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
589
            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
590
        else
591
            $form->addElement(form_makeOpenTag('li'));
592
        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
593
        if($exists){
594
            $form->addElement(form_makeTag('input', array(
595
                            'type' => 'checkbox',
596
                            'name' => 'rev2[]',
597
                            'value' => $rev)));
598
        }else{
599
            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
600
        }
601
602
        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
603
        $form->addElement($date);
604
        $form->addElement(form_makeCloseTag('span'));
605
606
        if($exists){
607
            if (!$media_id) $href = wl($id,"rev=$rev,do=diff", false, '&');
608
            else $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&');
609
            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link')));
610
            $form->addElement(form_makeTag('img', array(
611
                            'src'    => DOKU_BASE.'lib/images/diff.png',
612
                            'width'  => 15,
613
                            'height' => 11,
614
                            'title'  => $lang['diff'],
615
                            'alt'    => $lang['diff'])));
616
            $form->addElement(form_makeCloseTag('a'));
617
            if (!$media_id) $href = wl($id,"rev=$rev",false,'&');
618
            else $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&');
619
            $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1')));
620
            $form->addElement($display_name);
621
            $form->addElement(form_makeCloseTag('a'));
622
        }else{
623
            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
624
            $form->addElement($display_name);
625
        }
626
627
        if ($media_id) $form->addElement(form_makeOpenTag('div'));
628
629
        if ($info['sum']) {
630
            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
631
            if (!$media_id) $form->addElement(' – ');
632
            $form->addElement('<bdi>'.htmlspecialchars($info['sum']).'</bdi>');
633
            $form->addElement(form_makeCloseTag('span'));
634
        }
635
636
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
637
        if($info['user']){
638
            $form->addElement('<bdi>'.editorinfo($info['user']).'</bdi>');
639
            if(auth_ismanager()){
640
                $form->addElement(' <bdo dir="ltr">('.$info['ip'].')</bdo>');
641
            }
642
        }else{
643
            $form->addElement('<bdo dir="ltr">'.$info['ip'].'</bdo>');
644
        }
645
        $form->addElement(form_makeCloseTag('span'));
646
647
        if ($media_id) $form->addElement(form_makeCloseTag('div'));
648
649
        $form->addElement(form_makeCloseTag('div'));
650
        $form->addElement(form_makeCloseTag('li'));
651
    }
652
    $form->addElement(form_makeCloseTag('ul'));
653
    if (!$media_id) {
654
        $form->addElement(form_makeButton('submit', 'diff', $lang['diff2']));
655
    } else {
656
        $form->addHidden('mediado', 'diff');
657
        $form->addElement(form_makeButton('submit', '', $lang['diff2']));
658
    }
659
    html_form('revisions', $form);
660
661
    print '<div class="pagenav">';
662
    $last = $first + $conf['recent'];
663
    if ($first > 0) {
664
        $first -= $conf['recent'];
665
        if ($first < 0) $first = 0;
666
        print '<div class="pagenav-prev">';
667
        if ($media_id) {
668
            print html_btn('newer',$media_id,"p",media_managerURL(array('first' => $first), '&amp;', false, true));
669
        } else {
670
            print html_btn('newer',$id,"p",array('do' => 'revisions', 'first' => $first));
671
        }
672
        print '</div>';
673
    }
674
    if ($hasNext) {
675
        print '<div class="pagenav-next">';
676
        if ($media_id) {
677
            print html_btn('older',$media_id,"n",media_managerURL(array('first' => $last), '&amp;', false, true));
678
        } else {
679
            print html_btn('older',$id,"n",array('do' => 'revisions', 'first' => $last));
680
        }
681
        print '</div>';
682
    }
683
    print '</div>';
684
685
}
686
687
/**
688
 * display recent changes
689
 *
690
 * @author Andreas Gohr <[email protected]>
691
 * @author Matthias Grimm <[email protected]>
692
 * @author Ben Coburn <[email protected]>
693
 * @author Kate Arzamastseva <[email protected]>
694
 *
695
 * @param int $first
696
 * @param string $show_changes
697
 */
698
function html_recent($first=0, $show_changes='both'){
699
    global $conf;
700
    global $lang;
701
    global $ID;
702
    /* we need to get one additionally log entry to be able to
703
     * decide if this is the last page or is there another one.
704
     * This is the cheapest solution to get this information.
705
     */
706
    $flags = 0;
707
    if ($show_changes == 'mediafiles' && $conf['mediarevisions']) {
708
        $flags = RECENTS_MEDIA_CHANGES;
709
    } elseif ($show_changes == 'pages') {
710
        $flags = 0;
711
    } elseif ($conf['mediarevisions']) {
712
        $show_changes = 'both';
713
        $flags = RECENTS_MEDIA_PAGES_MIXED;
714
    }
715
716
    $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
0 ignored issues
show
Security Bug introduced by
It seems like getNS($ID) targeting getNS() can also be of type false; however, getRecents() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
717
    if(count($recents) == 0 && $first != 0){
718
        $first=0;
719
        $recents = getRecents($first,$conf['recent'] + 1,getNS($ID),$flags);
0 ignored issues
show
Security Bug introduced by
It seems like getNS($ID) targeting getNS() can also be of type false; however, getRecents() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
720
    }
721
    $hasNext = false;
722
    if (count($recents)>$conf['recent']) {
723
        $hasNext = true;
724
        array_pop($recents); // remove extra log entry
725
    }
726
727
    print p_locale_xhtml('recent');
728
729
    if (getNS($ID) != '')
730
        print '<div class="level1"><p>' . sprintf($lang['recent_global'], getNS($ID), wl('', 'do=recent')) . '</p></div>';
731
732
    $form = new Doku_Form(array('id' => 'dw__recent', 'method' => 'GET', 'class' => 'changes'));
733
    $form->addHidden('sectok', null);
734
    $form->addHidden('do', 'recent');
735
    $form->addHidden('id', $ID);
736
737
    if ($conf['mediarevisions']) {
738
        $form->addElement('<div class="changeType">');
739
        $form->addElement(form_makeListboxField(
740
                    'show_changes',
741
                    array(
742
                        'pages'      => $lang['pages_changes'],
743
                        'mediafiles' => $lang['media_changes'],
744
                        'both'       => $lang['both_changes']),
745
                    $show_changes,
746
                    $lang['changes_type'],
747
                    '','',
748
                    array('class'=>'quickselect')));
749
750
        $form->addElement(form_makeButton('submit', 'recent', $lang['btn_apply']));
751
        $form->addElement('</div>');
752
    }
753
754
    $form->addElement(form_makeOpenTag('ul'));
755
756
    foreach($recents as $recent){
757
        $date = dformat($recent['date']);
758
        if ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT)
759
            $form->addElement(form_makeOpenTag('li', array('class' => 'minor')));
760
        else
761
            $form->addElement(form_makeOpenTag('li'));
762
763
        $form->addElement(form_makeOpenTag('div', array('class' => 'li')));
764
765
        if (!empty($recent['media'])) {
766
            $form->addElement(media_printicon($recent['id']));
767
        } else {
768
            $icon = DOKU_BASE.'lib/images/fileicons/file.png';
769
            $form->addElement('<img src="'.$icon.'" alt="'.$recent['id'].'" class="icon" />');
770
        }
771
772
        $form->addElement(form_makeOpenTag('span', array('class' => 'date')));
773
        $form->addElement($date);
774
        $form->addElement(form_makeCloseTag('span'));
775
776
        $diff = false;
777
        $href = '';
778
779
        if (!empty($recent['media'])) {
780
            $changelog = new MediaChangeLog($recent['id']);
781
            $revs = $changelog->getRevisions(0, 1);
782
            $diff = (count($revs) && file_exists(mediaFN($recent['id'])));
783
            if ($diff) {
784
                $href = media_managerURL(array(
785
                                             'tab_details' => 'history',
786
                                             'mediado' => 'diff',
787
                                             'image' => $recent['id'],
788
                                             'ns' => getNS($recent['id'])
789
                                         ), '&');
790
            }
791
        } else {
792
            $href = wl($recent['id'],"do=diff", false, '&');
793
        }
794
795
        if (!empty($recent['media']) && !$diff) {
796
            $form->addElement('<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />');
797
        } else {
798
            $form->addElement(form_makeOpenTag('a', array('class' => 'diff_link', 'href' => $href)));
799
            $form->addElement(form_makeTag('img', array(
800
                            'src'   => DOKU_BASE.'lib/images/diff.png',
801
                            'width' => 15,
802
                            'height'=> 11,
803
                            'title' => $lang['diff'],
804
                            'alt'   => $lang['diff']
805
                            )));
806
            $form->addElement(form_makeCloseTag('a'));
807
        }
808
809
        if (!empty($recent['media'])) {
810
            $href = media_managerURL(array('tab_details' => 'history',
811
                'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
812
        } else {
813
            $href = wl($recent['id'],"do=revisions",false,'&');
814
        }
815
        $form->addElement(form_makeOpenTag('a', array('class' => 'revisions_link', 'href' => $href)));
816
        $form->addElement(form_makeTag('img', array(
817
                        'src'   => DOKU_BASE.'lib/images/history.png',
818
                        'width' => 12,
819
                        'height'=> 14,
820
                        'title' => $lang['btn_revs'],
821
                        'alt'   => $lang['btn_revs']
822
                        )));
823
        $form->addElement(form_makeCloseTag('a'));
824
825
        if (!empty($recent['media'])) {
826
            $href = media_managerURL(array('tab_details' => 'view', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
827
            $class = (file_exists(mediaFN($recent['id']))) ? 'wikilink1' : $class = 'wikilink2';
828
            $form->addElement(form_makeOpenTag('a', array('class' => $class, 'href' => $href)));
829
            $form->addElement($recent['id']);
830
            $form->addElement(form_makeCloseTag('a'));
831
        } else {
832
            $form->addElement(html_wikilink(':'.$recent['id'],useHeading('navigation')?null:$recent['id']));
833
        }
834
        $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
835
        $form->addElement(' – '.htmlspecialchars($recent['sum']));
836
        $form->addElement(form_makeCloseTag('span'));
837
838
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
839
        if($recent['user']){
840
            $form->addElement('<bdi>'.editorinfo($recent['user']).'</bdi>');
841
            if(auth_ismanager()){
842
                $form->addElement(' <bdo dir="ltr">('.$recent['ip'].')</bdo>');
843
            }
844
        }else{
845
            $form->addElement('<bdo dir="ltr">'.$recent['ip'].'</bdo>');
846
        }
847
        $form->addElement(form_makeCloseTag('span'));
848
849
        $form->addElement(form_makeCloseTag('div'));
850
        $form->addElement(form_makeCloseTag('li'));
851
    }
852
    $form->addElement(form_makeCloseTag('ul'));
853
854
    $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav')));
855
    $last = $first + $conf['recent'];
856
    if ($first > 0) {
857
        $first -= $conf['recent'];
858
        if ($first < 0) $first = 0;
859
        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-prev')));
860
        $form->addElement(form_makeOpenTag('button', array(
861
                    'type'  => 'submit',
862
                    'name'  => 'first['.$first.']',
863
                    'accesskey' => 'n',
864
                    'title' => $lang['btn_newer'].' [N]',
865
                    'class' => 'button show'
866
                    )));
867
        $form->addElement($lang['btn_newer']);
868
        $form->addElement(form_makeCloseTag('button'));
869
        $form->addElement(form_makeCloseTag('div'));
870
    }
871
    if ($hasNext) {
872
        $form->addElement(form_makeOpenTag('div', array('class' => 'pagenav-next')));
873
        $form->addElement(form_makeOpenTag('button', array(
874
                        'type'  => 'submit',
875
                        'name'  => 'first['.$last.']',
876
                        'accesskey' => 'p',
877
                        'title' => $lang['btn_older'].' [P]',
878
                        'class' => 'button show'
879
                        )));
880
        $form->addElement($lang['btn_older']);
881
        $form->addElement(form_makeCloseTag('button'));
882
        $form->addElement(form_makeCloseTag('div'));
883
    }
884
    $form->addElement(form_makeCloseTag('div'));
885
    html_form('recent', $form);
886
}
887
888
/**
889
 * Display page index
890
 *
891
 * @author Andreas Gohr <[email protected]>
892
 *
893
 * @param string $ns
894
 */
895
function html_index($ns){
896
    global $conf;
897
    global $ID;
898
    $ns  = cleanID($ns);
899
    #fixme use appropriate function
900
    if(empty($ns)){
901
        $ns = dirname(str_replace(':','/',$ID));
902
        if($ns == '.') $ns ='';
903
    }
904
    $ns  = utf8_encodeFN(str_replace(':','/',$ns));
905
906
    echo p_locale_xhtml('index');
907
    echo '<div id="index__tree">';
908
909
    $data = array();
910
    search($data,$conf['datadir'],'search_index',array('ns' => $ns));
911
    echo html_buildlist($data,'idx','html_list_index','html_li_index');
912
913
    echo '</div>';
914
}
915
916
/**
917
 * Index item formatter
918
 *
919
 * User function for html_buildlist()
920
 *
921
 * @author Andreas Gohr <[email protected]>
922
 *
923
 * @param array $item
924
 * @return string
925
 */
926
function html_list_index($item){
927
    global $ID, $conf;
928
929
    // prevent searchbots needlessly following links
930
    $nofollow = ($ID != $conf['start'] || $conf['sitemap']) ? ' rel="nofollow"' : '';
931
932
    $ret = '';
933
    $base = ':'.$item['id'];
934
    $base = substr($base,strrpos($base,':')+1);
935
    if($item['type']=='d'){
936
        // FS#2766, no need for search bots to follow namespace links in the index
937
        $ret .= '<a href="'.wl($ID,'idx='.rawurlencode($item['id'])).'" title="' . $item['id'] . '" class="idx_dir"' . $nofollow . '><strong>';
938
        $ret .= $base;
939
        $ret .= '</strong></a>';
940
    }else{
941
        // default is noNSorNS($id), but we want noNS($id) when useheading is off FS#2605
942
        $ret .= html_wikilink(':'.$item['id'], useHeading('navigation') ? null : noNS($item['id']));
943
    }
944
    return $ret;
945
}
946
947
/**
948
 * Index List item
949
 *
950
 * This user function is used in html_buildlist to build the
951
 * <li> tags for namespaces when displaying the page index
952
 * it gives different classes to opened or closed "folders"
953
 *
954
 * @author Andreas Gohr <[email protected]>
955
 *
956
 * @param array $item
957
 * @return string html
958
 */
959
function html_li_index($item){
960
    global $INFO;
961
    global $ACT;
962
963
    $class = '';
964
    $id = '';
965
966
    if($item['type'] == "f"){
967
        // scroll to the current item
968
        if($item['id'] == $INFO['id'] && $ACT == 'index') {
969
            $id = ' id="scroll__here"';
970
            $class = ' bounce';
971
        }
972
        return '<li class="level'.$item['level'].$class.'" '.$id.'>';
973
    }elseif($item['open']){
974
        return '<li class="open">';
975
    }else{
976
        return '<li class="closed">';
977
    }
978
}
979
980
/**
981
 * Default List item
982
 *
983
 * @author Andreas Gohr <[email protected]>
984
 *
985
 * @param array $item
986
 * @return string html
987
 */
988
function html_li_default($item){
989
    return '<li class="level'.$item['level'].'">';
990
}
991
992
/**
993
 * Build an unordered list
994
 *
995
 * Build an unordered list from the given $data array
996
 * Each item in the array has to have a 'level' property
997
 * the item itself gets printed by the given $func user
998
 * function. The second and optional function is used to
999
 * print the <li> tag. Both user function need to accept
1000
 * a single item.
1001
 *
1002
 * Both user functions can be given as array to point to
1003
 * a member of an object.
1004
 *
1005
 * @author Andreas Gohr <[email protected]>
1006
 *
1007
 * @param array    $data  array with item arrays
1008
 * @param string   $class class of ul wrapper
1009
 * @param callable $func  callback to print an list item
1010
 * @param callable $lifunc callback to the opening li tag
1011
 * @param bool     $forcewrapper Trigger building a wrapper ul if the first level is
1012
 *                               0 (we have a root object) or 1 (just the root content)
1013
 * @return string html of an unordered list
1014
 */
1015
function html_buildlist($data,$class,$func,$lifunc='html_li_default',$forcewrapper=false){
1016
    if (count($data) === 0) {
1017
        return '';
1018
    }
1019
1020
    $start_level = $data[0]['level'];
1021
    $level = $start_level;
1022
    $ret   = '';
1023
    $open  = 0;
1024
1025
    foreach ($data as $item){
1026
1027
        if( $item['level'] > $level ){
1028
            //open new list
1029
            for($i=0; $i<($item['level'] - $level); $i++){
1030
                if ($i) $ret .= "<li class=\"clear\">";
1031
                $ret .= "\n<ul class=\"$class\">\n";
1032
                $open++;
1033
            }
1034
            $level = $item['level'];
1035
1036
        }elseif( $item['level'] < $level ){
1037
            //close last item
1038
            $ret .= "</li>\n";
1039
            while( $level > $item['level'] && $open > 0 ){
1040
                //close higher lists
1041
                $ret .= "</ul>\n</li>\n";
1042
                $level--;
1043
                $open--;
1044
            }
1045
        } elseif ($ret !== '') {
1046
            //close previous item
1047
            $ret .= "</li>\n";
1048
        }
1049
1050
        //print item
1051
        $ret .= call_user_func($lifunc,$item);
1052
        $ret .= '<div class="li">';
1053
1054
        $ret .= call_user_func($func,$item);
1055
        $ret .= '</div>';
1056
    }
1057
1058
    //close remaining items and lists
1059
    $ret .= "</li>\n";
1060
    while($open-- > 0) {
1061
        $ret .= "</ul></li>\n";
1062
    }
1063
1064
    if ($forcewrapper || $start_level < 2) {
1065
        // Trigger building a wrapper ul if the first level is
1066
        // 0 (we have a root object) or 1 (just the root content)
1067
        $ret = "\n<ul class=\"$class\">\n".$ret."</ul>\n";
1068
    }
1069
1070
    return $ret;
1071
}
1072
1073
/**
1074
 * display backlinks
1075
 *
1076
 * @author Andreas Gohr <[email protected]>
1077
 * @author Michael Klier <[email protected]>
1078
 */
1079
function html_backlinks(){
1080
    global $ID;
1081
    global $lang;
1082
1083
    print p_locale_xhtml('backlinks');
1084
1085
    $data = ft_backlinks($ID);
1086
1087
    if(!empty($data)) {
1088
        print '<ul class="idx">';
1089
        foreach($data as $blink){
1090
            print '<li><div class="li">';
1091
            print html_wikilink(':'.$blink,useHeading('navigation')?null:$blink);
1092
            print '</div></li>';
1093
        }
1094
        print '</ul>';
1095
    } else {
1096
        print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>';
1097
    }
1098
}
1099
1100
/**
1101
 * Get header of diff HTML
1102
 *
1103
 * @param string $l_rev   Left revisions
1104
 * @param string $r_rev   Right revision
1105
 * @param string $id      Page id, if null $ID is used
1106
 * @param bool   $media   If it is for media files
1107
 * @param bool   $inline  Return the header on a single line
1108
 * @return string[] HTML snippets for diff header
1109
 */
1110
function html_diff_head($l_rev, $r_rev, $id = null, $media = false, $inline = false) {
1111
    global $lang;
1112
    if ($id === null) {
1113
        global $ID;
1114
        $id = $ID;
1115
    }
1116
    $head_separator = $inline ? ' ' : '<br />';
1117
    $media_or_wikiFN = $media ? 'mediaFN' : 'wikiFN';
1118
    $ml_or_wl = $media ? 'ml' : 'wl';
1119
    $l_minor = $r_minor = '';
1120
1121
    if($media) {
1122
        $changelog = new MediaChangeLog($id);
1123
    } else {
1124
        $changelog = new PageChangeLog($id);
1125
    }
1126
    if(!$l_rev){
1127
        $l_head = '&mdash;';
1128
    }else{
1129
        $l_info   = $changelog->getRevisionInfo($l_rev);
1130
        if($l_info['user']){
1131
            $l_user = '<bdi>'.editorinfo($l_info['user']).'</bdi>';
1132
            if(auth_ismanager()) $l_user .= ' <bdo dir="ltr">('.$l_info['ip'].')</bdo>';
1133
        } else {
1134
            $l_user = '<bdo dir="ltr">'.$l_info['ip'].'</bdo>';
1135
        }
1136
        $l_user  = '<span class="user">'.$l_user.'</span>';
1137
        $l_sum   = ($l_info['sum']) ? '<span class="sum"><bdi>'.hsc($l_info['sum']).'</bdi></span>' : '';
1138
        if ($l_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $l_minor = 'class="minor"';
1139
1140
        $l_head_title = ($media) ? dformat($l_rev) : $id.' ['.dformat($l_rev).']';
1141
        $l_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$l_rev").'">'.
1142
        $l_head_title.'</a></bdi>'.
1143
        $head_separator.$l_user.' '.$l_sum;
1144
    }
1145
1146
    if($r_rev){
1147
        $r_info   = $changelog->getRevisionInfo($r_rev);
1148
        if($r_info['user']){
1149
            $r_user = '<bdi>'.editorinfo($r_info['user']).'</bdi>';
1150
            if(auth_ismanager()) $r_user .= ' <bdo dir="ltr">('.$r_info['ip'].')</bdo>';
1151
        } else {
1152
            $r_user = '<bdo dir="ltr">'.$r_info['ip'].'</bdo>';
1153
        }
1154
        $r_user = '<span class="user">'.$r_user.'</span>';
1155
        $r_sum  = ($r_info['sum']) ? '<span class="sum"><bdi>'.hsc($r_info['sum']).'</bdi></span>' : '';
1156
        if ($r_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1157
1158
        $r_head_title = ($media) ? dformat($r_rev) : $id.' ['.dformat($r_rev).']';
1159
        $r_head = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id,"rev=$r_rev").'">'.
1160
        $r_head_title.'</a></bdi>'.
1161
        $head_separator.$r_user.' '.$r_sum;
1162
    }elseif($_rev = @filemtime($media_or_wikiFN($id))){
1163
        $_info   = $changelog->getRevisionInfo($_rev);
1164
        if($_info['user']){
1165
            $_user = '<bdi>'.editorinfo($_info['user']).'</bdi>';
1166
            if(auth_ismanager()) $_user .= ' <bdo dir="ltr">('.$_info['ip'].')</bdo>';
1167
        } else {
1168
            $_user = '<bdo dir="ltr">'.$_info['ip'].'</bdo>';
1169
        }
1170
        $_user = '<span class="user">'.$_user.'</span>';
1171
        $_sum  = ($_info['sum']) ? '<span class="sum"><bdi>'.hsc($_info['sum']).'</span></bdi>' : '';
1172
        if ($_info['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) $r_minor = 'class="minor"';
1173
1174
        $r_head_title = ($media) ? dformat($_rev) : $id.' ['.dformat($_rev).']';
1175
        $r_head  = '<bdi><a class="wikilink1" href="'.$ml_or_wl($id).'">'.
1176
        $r_head_title.'</a></bdi> '.
1177
        '('.$lang['current'].')'.
1178
        $head_separator.$_user.' '.$_sum;
1179
    }else{
1180
        $r_head = '&mdash; ('.$lang['current'].')';
1181
    }
1182
1183
    return array($l_head, $r_head, $l_minor, $r_minor);
1184
}
1185
1186
/**
1187
 * Show diff
1188
 * between current page version and provided $text
1189
 * or between the revisions provided via GET or POST
1190
 *
1191
 * @author Andreas Gohr <[email protected]>
1192
 * @param  string $text  when non-empty: compare with this text with most current version
1193
 * @param  bool   $intro display the intro text
1194
 * @param  string $type  type of the diff (inline or sidebyside)
1195
 */
1196
function html_diff($text = '', $intro = true, $type = null) {
1197
    global $ID;
1198
    global $REV;
1199
    global $lang;
1200
    global $INPUT;
1201
    global $INFO;
1202
    $pagelog = new PageChangeLog($ID);
1203
1204
    /*
1205
     * Determine diff type
1206
     */
1207
    if(!$type) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $type of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1208
        $type = $INPUT->str('difftype');
1209
        if(empty($type)) {
1210
            $type = get_doku_pref('difftype', $type);
1211
            if(empty($type) && $INFO['ismobile']) {
1212
                $type = 'inline';
1213
            }
1214
        }
1215
    }
1216
    if($type != 'inline') $type = 'sidebyside';
1217
1218
    /*
1219
     * Determine requested revision(s)
1220
     */
1221
    // we're trying to be clever here, revisions to compare can be either
1222
    // given as rev and rev2 parameters, with rev2 being optional. Or in an
1223
    // array in rev2.
1224
    $rev1 = $REV;
1225
1226
    $rev2 = $INPUT->ref('rev2');
1227
    if(is_array($rev2)) {
1228
        $rev1 = (int) $rev2[0];
1229
        $rev2 = (int) $rev2[1];
1230
1231
        if(!$rev1) {
1232
            $rev1 = $rev2;
1233
            unset($rev2);
1234
        }
1235
    } else {
1236
        $rev2 = $INPUT->int('rev2');
1237
    }
1238
1239
    /*
1240
     * Determine left and right revision, its texts and the header
1241
     */
1242
    $r_minor = '';
1243
    $l_minor = '';
1244
1245
    if($text) { // compare text to the most current revision
1246
        $l_rev = '';
1247
        $l_text = rawWiki($ID, '');
1248
        $l_head = '<a class="wikilink1" href="' . wl($ID) . '">' .
1249
            $ID . ' ' . dformat((int) @filemtime(wikiFN($ID))) . '</a> ' .
1250
            $lang['current'];
1251
1252
        $r_rev = '';
1253
        $r_text = cleanText($text);
1254
        $r_head = $lang['yours'];
1255
    } else {
1256
        if($rev1 && isset($rev2) && $rev2) { // two specific revisions wanted
1257
            // make sure order is correct (older on the left)
1258
            if($rev1 < $rev2) {
1259
                $l_rev = $rev1;
1260
                $r_rev = $rev2;
1261
            } else {
1262
                $l_rev = $rev2;
1263
                $r_rev = $rev1;
1264
            }
1265
        } elseif($rev1) { // single revision given, compare to current
1266
            $r_rev = '';
1267
            $l_rev = $rev1;
1268
        } else { // no revision was given, compare previous to current
1269
            $r_rev = '';
1270
            $revs = $pagelog->getRevisions(0, 1);
1271
            $l_rev = $revs[0];
1272
            $REV = $l_rev; // store revision back in $REV
1273
        }
1274
1275
        // when both revisions are empty then the page was created just now
1276
        if(!$l_rev && !$r_rev) {
1277
            $l_text = '';
1278
        } else {
1279
            $l_text = rawWiki($ID, $l_rev);
1280
        }
1281
        $r_text = rawWiki($ID, $r_rev);
1282
1283
        list($l_head, $r_head, $l_minor, $r_minor) = html_diff_head($l_rev, $r_rev, null, false, $type == 'inline');
1284
    }
1285
1286
    /*
1287
     * Build navigation
1288
     */
1289
    $l_nav = '';
1290
    $r_nav = '';
1291
    if(!$text) {
1292
        list($l_nav, $r_nav) = html_diff_navigation($pagelog, $type, $l_rev, $r_rev);
1293
    }
1294
    /*
1295
     * Create diff object and the formatter
1296
     */
1297
    $diff = new Diff(explode("\n", $l_text), explode("\n", $r_text));
1298
1299
    if($type == 'inline') {
1300
        $diffformatter = new InlineDiffFormatter();
1301
    } else {
1302
        $diffformatter = new TableDiffFormatter();
1303
    }
1304
    /*
1305
     * Display intro
1306
     */
1307
    if($intro) print p_locale_xhtml('diff');
1308
1309
    /*
1310
     * Display type and exact reference
1311
     */
1312
    if(!$text) {
1313
        ptln('<div class="diffoptions group">');
1314
1315
1316
        $form = new Doku_Form(array('action' => wl()));
1317
        $form->addHidden('id', $ID);
1318
        $form->addHidden('rev2[0]', $l_rev);
1319
        $form->addHidden('rev2[1]', $r_rev);
1320
        $form->addHidden('do', 'diff');
1321
        $form->addElement(
1322
             form_makeListboxField(
1323
                 'difftype',
1324
                 array(
1325
                     'sidebyside' => $lang['diff_side'],
1326
                     'inline' => $lang['diff_inline']
1327
                 ),
1328
                 $type,
1329
                 $lang['diff_type'],
1330
                 '', '',
1331
                 array('class' => 'quickselect')
1332
             )
1333
        );
1334
        $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1335
        $form->printForm();
1336
1337
        ptln('<p>');
1338
        // link to exactly this view FS#2835
1339
        echo html_diff_navigationlink($type, 'difflink', $l_rev, $r_rev ? $r_rev : $INFO['currentrev']);
1340
        ptln('</p>');
1341
1342
        ptln('</div>'); // .diffoptions
1343
    }
1344
1345
    /*
1346
     * Display diff view table
1347
     */
1348
    ?>
1349
    <div class="table">
1350
    <table class="diff diff_<?php echo $type ?>">
1351
1352
        <?php
1353
        //navigation and header
1354
        if($type == 'inline') {
1355
            if(!$text) { ?>
1356
                <tr>
1357
                    <td class="diff-lineheader">-</td>
1358
                    <td class="diffnav"><?php echo $l_nav ?></td>
1359
                </tr>
1360
                <tr>
1361
                    <th class="diff-lineheader">-</th>
1362
                    <th <?php echo $l_minor ?>>
1363
                        <?php echo $l_head ?>
1364
                    </th>
1365
                </tr>
1366
            <?php } ?>
1367
            <tr>
1368
                <td class="diff-lineheader">+</td>
1369
                <td class="diffnav"><?php echo $r_nav ?></td>
1370
            </tr>
1371
            <tr>
1372
                <th class="diff-lineheader">+</th>
1373
                <th <?php echo $r_minor ?>>
1374
                    <?php echo $r_head ?>
1375
                </th>
1376
            </tr>
1377
        <?php } else {
1378
            if(!$text) { ?>
1379
                <tr>
1380
                    <td colspan="2" class="diffnav"><?php echo $l_nav ?></td>
1381
                    <td colspan="2" class="diffnav"><?php echo $r_nav ?></td>
1382
                </tr>
1383
            <?php } ?>
1384
            <tr>
1385
                <th colspan="2" <?php echo $l_minor ?>>
1386
                    <?php echo $l_head ?>
1387
                </th>
1388
                <th colspan="2" <?php echo $r_minor ?>>
1389
                    <?php echo $r_head ?>
1390
                </th>
1391
            </tr>
1392
        <?php }
1393
1394
        //diff view
1395
        echo html_insert_softbreaks($diffformatter->format($diff)); ?>
1396
1397
    </table>
1398
    </div>
1399
<?php
1400
}
1401
1402
/**
1403
 * Create html for revision navigation
1404
 *
1405
 * @param PageChangeLog $pagelog changelog object of current page
1406
 * @param string        $type    inline vs sidebyside
1407
 * @param int           $l_rev   left revision timestamp
1408
 * @param int           $r_rev   right revision timestamp
1409
 * @return string[] html of left and right navigation elements
1410
 */
1411
function html_diff_navigation($pagelog, $type, $l_rev, $r_rev) {
1412
    global $INFO, $ID;
1413
1414
    // last timestamp is not in changelog, retrieve timestamp from metadata
1415
    // note: when page is removed, the metadata timestamp is zero
1416
    if(!$r_rev) {
1417
        if(isset($INFO['meta']['last_change']['date'])) {
1418
            $r_rev = $INFO['meta']['last_change']['date'];
1419
        } else {
1420
            $r_rev = 0;
1421
        }
1422
    }
1423
1424
    //retrieve revisions with additional info
1425
    list($l_revs, $r_revs) = $pagelog->getRevisionsAround($l_rev, $r_rev);
1426
    $l_revisions = array();
1427
    if(!$l_rev) {
1428
        $l_revisions[0] = array(0, "", false); //no left revision given, add dummy
1429
    }
1430
    foreach($l_revs as $rev) {
1431
        $info = $pagelog->getRevisionInfo($rev);
1432
        $l_revisions[$rev] = array(
1433
            $rev,
1434
            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1435
            $r_rev ? $rev >= $r_rev : false //disable?
1436
        );
1437
    }
1438
    $r_revisions = array();
1439
    if(!$r_rev) {
1440
        $r_revisions[0] = array(0, "", false); //no right revision given, add dummy
1441
    }
1442
    foreach($r_revs as $rev) {
1443
        $info = $pagelog->getRevisionInfo($rev);
1444
        $r_revisions[$rev] = array(
1445
            $rev,
1446
            dformat($info['date']) . ' ' . editorinfo($info['user'], true) . ' ' . $info['sum'],
1447
            $rev <= $l_rev //disable?
1448
        );
1449
    }
1450
1451
    //determine previous/next revisions
1452
    $l_index = array_search($l_rev, $l_revs);
1453
    $l_prev = $l_revs[$l_index + 1];
1454
    $l_next = $l_revs[$l_index - 1];
1455
    if($r_rev) {
1456
        $r_index = array_search($r_rev, $r_revs);
1457
        $r_prev = $r_revs[$r_index + 1];
1458
        $r_next = $r_revs[$r_index - 1];
1459
    } else {
1460
        //removed page
1461
        if($l_next) {
1462
            $r_prev = $r_revs[0];
1463
        } else {
1464
            $r_prev = null;
1465
        }
1466
        $r_next = null;
1467
    }
1468
1469
    /*
1470
     * Left side:
1471
     */
1472
    $l_nav = '';
1473
    //move back
1474
    if($l_prev) {
1475
        $l_nav .= html_diff_navigationlink($type, 'diffbothprevrev', $l_prev, $r_prev);
1476
        $l_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_prev, $r_rev);
1477
    }
1478
    //dropdown
1479
    $form = new Doku_Form(array('action' => wl()));
1480
    $form->addHidden('id', $ID);
1481
    $form->addHidden('difftype', $type);
1482
    $form->addHidden('rev2[1]', $r_rev);
1483
    $form->addHidden('do', 'diff');
1484
    $form->addElement(
1485
         form_makeListboxField(
1486
             'rev2[0]',
1487
             $l_revisions,
1488
             $l_rev,
1489
             '', '', '',
1490
             array('class' => 'quickselect')
1491
         )
1492
    );
1493
    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1494
    $l_nav .= $form->getForm();
1495
    //move forward
1496
    if($l_next && ($l_next < $r_rev || !$r_rev)) {
1497
        $l_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_next, $r_rev);
1498
    }
1499
1500
    /*
1501
     * Right side:
1502
     */
1503
    $r_nav = '';
1504
    //move back
1505
    if($l_rev < $r_prev) {
1506
        $r_nav .= html_diff_navigationlink($type, 'diffprevrev', $l_rev, $r_prev);
1507
    }
1508
    //dropdown
1509
    $form = new Doku_Form(array('action' => wl()));
1510
    $form->addHidden('id', $ID);
1511
    $form->addHidden('rev2[0]', $l_rev);
1512
    $form->addHidden('difftype', $type);
1513
    $form->addHidden('do', 'diff');
1514
    $form->addElement(
1515
         form_makeListboxField(
1516
             'rev2[1]',
1517
             $r_revisions,
1518
             $r_rev,
1519
             '', '', '',
1520
             array('class' => 'quickselect')
1521
         )
1522
    );
1523
    $form->addElement(form_makeButton('submit', 'diff', 'Go'));
1524
    $r_nav .= $form->getForm();
1525
    //move forward
1526
    if($r_next) {
1527
        if($pagelog->isCurrentRevision($r_next)) {
1528
            $r_nav .= html_diff_navigationlink($type, 'difflastrev', $l_rev); //last revision is diff with current page
1529
        } else {
1530
            $r_nav .= html_diff_navigationlink($type, 'diffnextrev', $l_rev, $r_next);
1531
        }
1532
        $r_nav .= html_diff_navigationlink($type, 'diffbothnextrev', $l_next, $r_next);
1533
    }
1534
    return array($l_nav, $r_nav);
1535
}
1536
1537
/**
1538
 * Create html link to a diff defined by two revisions
1539
 *
1540
 * @param string $difftype display type
1541
 * @param string $linktype
1542
 * @param int $lrev oldest revision
1543
 * @param int $rrev newest revision or null for diff with current revision
1544
 * @return string html of link to a diff
1545
 */
1546
function html_diff_navigationlink($difftype, $linktype, $lrev, $rrev = null) {
1547
    global $ID, $lang;
1548
    if(!$rrev) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $rrev of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
1549
        $urlparam = array(
1550
            'do' => 'diff',
1551
            'rev' => $lrev,
1552
            'difftype' => $difftype,
1553
        );
1554
    } else {
1555
        $urlparam = array(
1556
            'do' => 'diff',
1557
            'rev2[0]' => $lrev,
1558
            'rev2[1]' => $rrev,
1559
            'difftype' => $difftype,
1560
        );
1561
    }
1562
    return  '<a class="' . $linktype . '" href="' . wl($ID, $urlparam) . '" title="' . $lang[$linktype] . '">' .
1563
                '<span>' . $lang[$linktype] . '</span>' .
1564
            '</a>' . "\n";
1565
}
1566
1567
/**
1568
 * Insert soft breaks in diff html
1569
 *
1570
 * @param string $diffhtml
1571
 * @return string
1572
 */
1573
function html_insert_softbreaks($diffhtml) {
1574
    // search the diff html string for both:
1575
    // - html tags, so these can be ignored
1576
    // - long strings of characters without breaking characters
1577
    return preg_replace_callback('/<[^>]*>|[^<> ]{12,}/','html_softbreak_callback',$diffhtml);
1578
}
1579
1580
/**
1581
 * callback which adds softbreaks
1582
 *
1583
 * @param array $match array with first the complete match
1584
 * @return string the replacement
1585
 */
1586
function html_softbreak_callback($match){
1587
    // if match is an html tag, return it intact
1588
    if ($match[0]{0} == '<') return $match[0];
1589
1590
    // its a long string without a breaking character,
1591
    // make certain characters into breaking characters by inserting a
1592
    // breaking character (zero length space, U+200B / #8203) in front them.
1593
    $regex = <<< REGEX
1594
(?(?=                                 # start a conditional expression with a positive look ahead ...
1595
&\#?\\w{1,6};)                        # ... for html entities - we don't want to split them (ok to catch some invalid combinations)
1596
&\#?\\w{1,6};                         # yes pattern - a quicker match for the html entity, since we know we have one
1597
|
1598
[?/,&\#;:]                            # no pattern - any other group of 'special' characters to insert a breaking character after
1599
)+                                    # end conditional expression
1600
REGEX;
1601
1602
    return preg_replace('<'.$regex.'>xu','\0&#8203;',$match[0]);
1603
}
1604
1605
/**
1606
 * show warning on conflict detection
1607
 *
1608
 * @author Andreas Gohr <[email protected]>
1609
 *
1610
 * @param string $text
1611
 * @param string $summary
1612
 */
1613
function html_conflict($text,$summary){
1614
    global $ID;
1615
    global $lang;
1616
1617
    print p_locale_xhtml('conflict');
1618
    $form = new Doku_Form(array('id' => 'dw__editform'));
1619
    $form->addHidden('id', $ID);
1620
    $form->addHidden('wikitext', $text);
1621
    $form->addHidden('summary', $summary);
1622
    $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('accesskey'=>'s')));
1623
    $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel']));
1624
    html_form('conflict', $form);
1625
    print '<br /><br /><br /><br />'.NL;
1626
}
1627
1628
/**
1629
 * Prints the global message array
1630
 *
1631
 * @author Andreas Gohr <[email protected]>
1632
 */
1633
function html_msgarea(){
1634
    global $MSG, $MSG_shown;
1635
    /** @var array $MSG */
1636
    // store if the global $MSG has already been shown and thus HTML output has been started
1637
    $MSG_shown = true;
1638
1639
    if(!isset($MSG)) return;
1640
1641
    $shown = array();
1642
    foreach($MSG as $msg){
1643
        $hash = md5($msg['msg']);
1644
        if(isset($shown[$hash])) continue; // skip double messages
1645
        if(info_msg_allowed($msg)){
1646
            print '<div class="'.$msg['lvl'].'">';
1647
            print $msg['msg'];
1648
            print '</div>';
1649
        }
1650
        $shown[$hash] = 1;
1651
    }
1652
1653
    unset($GLOBALS['MSG']);
1654
}
1655
1656
/**
1657
 * Prints the registration form
1658
 *
1659
 * @author Andreas Gohr <[email protected]>
1660
 */
1661
function html_register(){
1662
    global $lang;
1663
    global $conf;
1664
    global $INPUT;
1665
1666
    $base_attrs = array('size'=>50,'required'=>'required');
1667
    $email_attrs = $base_attrs + array('type'=>'email','class'=>'edit');
1668
1669
    print p_locale_xhtml('register');
1670
    print '<div class="centeralign">'.NL;
1671
    $form = new Doku_Form(array('id' => 'dw__register'));
1672
    $form->startFieldset($lang['btn_register']);
1673
    $form->addHidden('do', 'register');
1674
    $form->addHidden('save', '1');
1675
    $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block', $base_attrs));
1676
    if (!$conf['autopasswd']) {
1677
        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', $base_attrs));
1678
        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', $base_attrs));
1679
    }
1680
    $form->addElement(form_makeTextField('fullname', $INPUT->post->str('fullname'), $lang['fullname'], '', 'block', $base_attrs));
1681
    $form->addElement(form_makeField('email','email', $INPUT->post->str('email'), $lang['email'], '', 'block', $email_attrs));
1682
    $form->addElement(form_makeButton('submit', '', $lang['btn_register']));
1683
    $form->endFieldset();
1684
    html_form('register', $form);
1685
1686
    print '</div>'.NL;
1687
}
1688
1689
/**
1690
 * Print the update profile form
1691
 *
1692
 * @author Christopher Smith <[email protected]>
1693
 * @author Andreas Gohr <[email protected]>
1694
 */
1695
function html_updateprofile(){
1696
    global $lang;
1697
    global $conf;
1698
    global $INPUT;
1699
    global $INFO;
1700
    /** @var DokuWiki_Auth_Plugin $auth */
1701
    global $auth;
1702
1703
    print p_locale_xhtml('updateprofile');
1704
    print '<div class="centeralign">'.NL;
1705
1706
    $fullname = $INPUT->post->str('fullname', $INFO['userinfo']['name'], true);
1707
    $email = $INPUT->post->str('email', $INFO['userinfo']['mail'], true);
1708
    $form = new Doku_Form(array('id' => 'dw__register'));
1709
    $form->startFieldset($lang['profile']);
1710
    $form->addHidden('do', 'profile');
1711
    $form->addHidden('save', '1');
1712
    $form->addElement(form_makeTextField('login', $_SERVER['REMOTE_USER'], $lang['user'], '', 'block', array('size'=>'50', 'disabled'=>'disabled')));
1713
    $attr = array('size'=>'50');
1714
    if (!$auth->canDo('modName')) $attr['disabled'] = 'disabled';
1715
    $form->addElement(form_makeTextField('fullname', $fullname, $lang['fullname'], '', 'block', $attr));
1716
    $attr = array('size'=>'50', 'class'=>'edit');
1717
    if (!$auth->canDo('modMail')) $attr['disabled'] = 'disabled';
1718
    $form->addElement(form_makeField('email','email', $email, $lang['email'], '', 'block', $attr));
1719
    $form->addElement(form_makeTag('br'));
1720
    if ($auth->canDo('modPass')) {
1721
        $form->addElement(form_makePasswordField('newpass', $lang['newpass'], '', 'block', array('size'=>'50')));
1722
        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
1723
    }
1724
    if ($conf['profileconfirm']) {
1725
        $form->addElement(form_makeTag('br'));
1726
        $form->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1727
    }
1728
    $form->addElement(form_makeButton('submit', '', $lang['btn_save']));
1729
    $form->addElement(form_makeButton('reset', '', $lang['btn_reset']));
1730
1731
    $form->endFieldset();
1732
    html_form('updateprofile', $form);
1733
1734
    if ($auth->canDo('delUser') && actionOK('profile_delete')) {
1735
        $form_profiledelete = new Doku_Form(array('id' => 'dw__profiledelete'));
1736
        $form_profiledelete->startFieldset($lang['profdeleteuser']);
1737
        $form_profiledelete->addHidden('do', 'profile_delete');
1738
        $form_profiledelete->addHidden('delete', '1');
1739
        $form_profiledelete->addElement(form_makeCheckboxField('confirm_delete', '1', $lang['profconfdelete'],'dw__confirmdelete','', array('required' => 'required')));
1740
        if ($conf['profileconfirm']) {
1741
            $form_profiledelete->addElement(form_makeTag('br'));
1742
            $form_profiledelete->addElement(form_makePasswordField('oldpass', $lang['oldpass'], '', 'block', array('size'=>'50', 'required' => 'required')));
1743
        }
1744
        $form_profiledelete->addElement(form_makeButton('submit', '', $lang['btn_deleteuser']));
1745
        $form_profiledelete->endFieldset();
1746
1747
        html_form('profiledelete', $form_profiledelete);
1748
    }
1749
1750
    print '</div>'.NL;
1751
}
1752
1753
/**
1754
 * Preprocess edit form data
1755
 *
1756
 * @author   Andreas Gohr <[email protected]>
1757
 *
1758
 * @triggers HTML_EDITFORM_OUTPUT
1759
 */
1760
function html_edit(){
1761
    global $INPUT;
1762
    global $ID;
1763
    global $REV;
1764
    global $DATE;
1765
    global $PRE;
1766
    global $SUF;
1767
    global $INFO;
1768
    global $SUM;
1769
    global $lang;
1770
    global $conf;
1771
    global $TEXT;
1772
1773
    if ($INPUT->has('changecheck')) {
1774
        $check = $INPUT->str('changecheck');
1775
    } elseif(!$INFO['exists']){
1776
        // $TEXT has been loaded from page template
1777
        $check = md5('');
1778
    } else {
1779
        $check = md5($TEXT);
1780
    }
1781
    $mod = md5($TEXT) !== $check;
1782
1783
    $wr = $INFO['writable'] && !$INFO['locked'];
1784
    $include = 'edit';
1785
    if($wr){
1786
        if ($REV) $include = 'editrev';
1787
    }else{
1788
        // check pseudo action 'source'
1789
        if(!actionOK('source')){
1790
            msg('Command disabled: source',-1);
1791
            return;
1792
        }
1793
        $include = 'read';
1794
    }
1795
1796
    global $license;
1797
1798
    $form = new Doku_Form(array('id' => 'dw__editform'));
1799
    $form->addHidden('id', $ID);
1800
    $form->addHidden('rev', $REV);
1801
    $form->addHidden('date', $DATE);
1802
    $form->addHidden('prefix', $PRE . '.');
1803
    $form->addHidden('suffix', $SUF);
1804
    $form->addHidden('changecheck', $check);
1805
1806
    $data = array('form' => $form,
1807
                  'wr'   => $wr,
1808
                  'media_manager' => true,
1809
                  'target' => ($INPUT->has('target') && $wr) ? $INPUT->str('target') : 'section',
1810
                  'intro_locale' => $include);
1811
1812
    if ($data['target'] !== 'section') {
1813
        // Only emit event if page is writable, section edit data is valid and
1814
        // edit target is not section.
1815
        trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
1816
    } else {
1817
        html_edit_form($data);
1818
    }
1819
    if (isset($data['intro_locale'])) {
1820
        echo p_locale_xhtml($data['intro_locale']);
1821
    }
1822
1823
    $form->addHidden('target', $data['target']);
1824
    $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar')));
1825
    $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl')));
1826
    $form->addElement(form_makeCloseTag('div'));
1827
    if ($wr) {
1828
        $form->addElement(form_makeOpenTag('div', array('class'=>'editButtons')));
1829
        $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id'=>'edbtn__save', 'accesskey'=>'s', 'tabindex'=>'4')));
1830
        $form->addElement(form_makeButton('submit', 'preview', $lang['btn_preview'], array('id'=>'edbtn__preview', 'accesskey'=>'p', 'tabindex'=>'5')));
1831
        $form->addElement(form_makeButton('submit', 'draftdel', $lang['btn_cancel'], array('tabindex'=>'6')));
1832
        $form->addElement(form_makeCloseTag('div'));
1833
        $form->addElement(form_makeOpenTag('div', array('class'=>'summary')));
1834
        $form->addElement(form_makeTextField('summary', $SUM, $lang['summary'], 'edit__summary', 'nowrap', array('size'=>'50', 'tabindex'=>'2')));
1835
        $elem = html_minoredit();
1836
        if ($elem) $form->addElement($elem);
1837
        $form->addElement(form_makeCloseTag('div'));
1838
    }
1839
    $form->addElement(form_makeCloseTag('div'));
1840
    if($wr && $conf['license']){
1841
        $form->addElement(form_makeOpenTag('div', array('class'=>'license')));
1842
        $out  = $lang['licenseok'];
1843
        $out .= ' <a href="'.$license[$conf['license']]['url'].'" rel="license" class="urlextern"';
1844
        if($conf['target']['extern']) $out .= ' target="'.$conf['target']['extern'].'"';
1845
        $out .= '>'.$license[$conf['license']]['name'].'</a>';
1846
        $form->addElement($out);
1847
        $form->addElement(form_makeCloseTag('div'));
1848
    }
1849
1850
    if ($wr) {
1851
        // sets changed to true when previewed
1852
        echo '<script type="text/javascript">/*<![CDATA[*/'. NL;
1853
        echo 'textChanged = ' . ($mod ? 'true' : 'false');
1854
        echo '/*!]]>*/</script>' . NL;
1855
    } ?>
1856
    <div class="editBox" role="application">
1857
1858
    <div class="toolbar group">
1859
        <div id="draft__status"><?php if(!empty($INFO['draft'])) echo $lang['draftdate'].' '.dformat();?></div>
1860
        <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']?>"
1861
            target="_blank"><?php echo $lang['mediaselect'] ?></a><?php }?></div>
1862
    </div>
1863
    <?php
1864
1865
    html_form('edit', $form);
1866
    print '</div>'.NL;
1867
}
1868
1869
/**
1870
 * Display the default edit form
1871
 *
1872
 * Is the default action for HTML_EDIT_FORMSELECTION.
1873
 *
1874
 * @param mixed[] $param
1875
 */
1876
function html_edit_form($param) {
1877
    global $TEXT;
1878
1879
    if ($param['target'] !== 'section') {
1880
        msg('No editor for edit target ' . hsc($param['target']) . ' found.', -1);
1881
    }
1882
1883
    $attr = array('tabindex'=>'1');
1884
    if (!$param['wr']) $attr['readonly'] = 'readonly';
1885
1886
    $param['form']->addElement(form_makeWikiText($TEXT, $attr));
1887
}
1888
1889
/**
1890
 * Adds a checkbox for minor edits for logged in users
1891
 *
1892
 * @author Andreas Gohr <[email protected]>
1893
 *
1894
 * @return array|bool
1895
 */
1896
function html_minoredit(){
1897
    global $conf;
1898
    global $lang;
1899
    global $INPUT;
1900
    // minor edits are for logged in users only
1901
    if(!$conf['useacl'] || !$_SERVER['REMOTE_USER']){
1902
        return false;
1903
    }
1904
1905
    $p = array();
1906
    $p['tabindex'] = 3;
1907
    if($INPUT->bool('minor')) $p['checked']='checked';
1908
    return form_makeCheckboxField('minor', '1', $lang['minoredit'], 'minoredit', 'nowrap', $p);
1909
}
1910
1911
/**
1912
 * prints some debug info
1913
 *
1914
 * @author Andreas Gohr <[email protected]>
1915
 */
1916
function html_debug(){
1917
    global $conf;
1918
    global $lang;
1919
    /** @var DokuWiki_Auth_Plugin $auth */
1920
    global $auth;
1921
    global $INFO;
1922
1923
    //remove sensitive data
1924
    $cnf = $conf;
1925
    debug_guard($cnf);
1926
    $nfo = $INFO;
1927
    debug_guard($nfo);
1928
    $ses = $_SESSION;
1929
    debug_guard($ses);
1930
1931
    print '<html><body>';
1932
1933
    print '<p>When reporting bugs please send all the following ';
1934
    print 'output as a mail to [email protected] ';
1935
    print 'The best way to do this is to save this page in your browser</p>';
1936
1937
    print '<b>$INFO:</b><pre>';
1938
    print_r($nfo);
1939
    print '</pre>';
1940
1941
    print '<b>$_SERVER:</b><pre>';
1942
    print_r($_SERVER);
1943
    print '</pre>';
1944
1945
    print '<b>$conf:</b><pre>';
1946
    print_r($cnf);
1947
    print '</pre>';
1948
1949
    print '<b>DOKU_BASE:</b><pre>';
1950
    print DOKU_BASE;
1951
    print '</pre>';
1952
1953
    print '<b>abs DOKU_BASE:</b><pre>';
1954
    print DOKU_URL;
1955
    print '</pre>';
1956
1957
    print '<b>rel DOKU_BASE:</b><pre>';
1958
    print dirname($_SERVER['PHP_SELF']).'/';
1959
    print '</pre>';
1960
1961
    print '<b>PHP Version:</b><pre>';
1962
    print phpversion();
1963
    print '</pre>';
1964
1965
    print '<b>locale:</b><pre>';
1966
    print setlocale(LC_ALL,0);
1967
    print '</pre>';
1968
1969
    print '<b>encoding:</b><pre>';
1970
    print $lang['encoding'];
1971
    print '</pre>';
1972
1973
    if($auth){
1974
        print '<b>Auth backend capabilities:</b><pre>';
1975
        foreach ($auth->getCapabilities() as $cando){
1976
            print '   '.str_pad($cando,16) . ' => ' . (int)$auth->canDo($cando) . NL;
1977
        }
1978
        print '</pre>';
1979
    }
1980
1981
    print '<b>$_SESSION:</b><pre>';
1982
    print_r($ses);
1983
    print '</pre>';
1984
1985
    print '<b>Environment:</b><pre>';
1986
    print_r($_ENV);
1987
    print '</pre>';
1988
1989
    print '<b>PHP settings:</b><pre>';
1990
    $inis = ini_get_all();
1991
    print_r($inis);
1992
    print '</pre>';
1993
1994
    if (function_exists('apache_get_version')) {
1995
        $apache = array();
1996
        $apache['version'] = apache_get_version();
1997
1998
        if (function_exists('apache_get_modules')) {
1999
            $apache['modules'] = apache_get_modules();
2000
        }
2001
        print '<b>Apache</b><pre>';
2002
        print_r($apache);
2003
        print '</pre>';
2004
    }
2005
2006
    print '</body></html>';
2007
}
2008
2009
/**
2010
 * List available Administration Tasks
2011
 *
2012
 * @author Andreas Gohr <[email protected]>
2013
 * @author Håkan Sandell <[email protected]>
2014
 */
2015
function html_admin(){
2016
    global $ID;
2017
    global $INFO;
2018
    global $conf;
2019
    /** @var DokuWiki_Auth_Plugin $auth */
2020
    global $auth;
2021
2022
    // build menu of admin functions from the plugins that handle them
2023
    $pluginlist = plugin_list('admin');
2024
    $menu = array();
2025
    foreach ($pluginlist as $p) {
2026
        /** @var DokuWiki_Admin_Plugin $obj */
2027
        if(($obj = plugin_load('admin',$p)) === null) continue;
2028
2029
        // check permissions
2030
        if($obj->forAdminOnly() && !$INFO['isadmin']) continue;
0 ignored issues
show
Documentation Bug introduced by
The method forAdminOnly does not exist on object<DokuWiki_Plugin>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
2031
2032
        $menu[$p] = array('plugin' => $p,
2033
                'prompt' => $obj->getMenuText($conf['lang']),
0 ignored issues
show
Documentation Bug introduced by
The method getMenuText does not exist on object<DokuWiki_Plugin>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
2034
                'sort' => $obj->getMenuSort()
0 ignored issues
show
Documentation Bug introduced by
The method getMenuSort does not exist on object<DokuWiki_Plugin>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
2035
                );
2036
    }
2037
2038
    // data security check
2039
    // simple check if the 'savedir' is relative and accessible when appended to DOKU_URL
2040
    // it verifies either:
2041
    //   'savedir' has been moved elsewhere, or
2042
    //   has protection to prevent the webserver serving files from it
2043
    if (substr($conf['savedir'],0,2) == './'){
2044
        echo '<a style="border:none; float:right;"
2045
                href="http://www.dokuwiki.org/security#web_access_security">
2046
                <img src="'.DOKU_URL.$conf['savedir'].'/security.png" alt="Your data directory seems to be protected properly."
2047
                onerror="this.parentNode.style.display=\'none\'" /></a>';
2048
    }
2049
2050
    print p_locale_xhtml('admin');
2051
2052
    // Admin Tasks
2053
    if($INFO['isadmin']){
2054
        ptln('<ul class="admin_tasks">');
2055
2056
        if($menu['usermanager'] && $auth && $auth->canDo('getUsers')){
2057
            ptln('  <li class="admin_usermanager"><div class="li">'.
2058
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'usermanager')).'">'.
2059
                    $menu['usermanager']['prompt'].'</a></div></li>');
2060
        }
2061
        unset($menu['usermanager']);
2062
2063
        if($menu['acl']){
2064
            ptln('  <li class="admin_acl"><div class="li">'.
2065
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'acl')).'">'.
2066
                    $menu['acl']['prompt'].'</a></div></li>');
2067
        }
2068
        unset($menu['acl']);
2069
2070
        if($menu['extension']){
2071
            ptln('  <li class="admin_plugin"><div class="li">'.
2072
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'extension')).'">'.
2073
                    $menu['extension']['prompt'].'</a></div></li>');
2074
        }
2075
        unset($menu['extension']);
2076
2077
        if($menu['config']){
2078
            ptln('  <li class="admin_config"><div class="li">'.
2079
                    '<a href="'.wl($ID, array('do' => 'admin','page' => 'config')).'">'.
2080
                    $menu['config']['prompt'].'</a></div></li>');
2081
        }
2082
        unset($menu['config']);
2083
2084
        if($menu['styling']){
2085
            ptln('  <li class="admin_styling"><div class="li">'.
2086
                '<a href="'.wl($ID, array('do' => 'admin','page' => 'styling')).'">'.
2087
                $menu['styling']['prompt'].'</a></div></li>');
2088
        }
2089
        unset($menu['styling']);
2090
    }
2091
    ptln('</ul>');
2092
2093
    // Manager Tasks
2094
    ptln('<ul class="admin_tasks">');
2095
2096
    if($menu['revert']){
2097
        ptln('  <li class="admin_revert"><div class="li">'.
2098
                '<a href="'.wl($ID, array('do' => 'admin','page' => 'revert')).'">'.
2099
                $menu['revert']['prompt'].'</a></div></li>');
2100
    }
2101
    unset($menu['revert']);
2102
2103
    if($menu['popularity']){
2104
        ptln('  <li class="admin_popularity"><div class="li">'.
2105
                '<a href="'.wl($ID, array('do' => 'admin','page' => 'popularity')).'">'.
2106
                $menu['popularity']['prompt'].'</a></div></li>');
2107
    }
2108
    unset($menu['popularity']);
2109
2110
    // print DokuWiki version:
2111
    ptln('</ul>');
2112
    echo '<div id="admin__version">';
2113
    echo getVersion();
2114
    echo '</div>';
2115
2116
    // print the rest as sorted list
2117
    if(count($menu)){
2118
        // sort by name, then sort
2119
        usort(
2120
            $menu,
2121
            function ($a, $b) {
2122
                $strcmp = strcasecmp($a['prompt'], $b['prompt']);
2123
                if($strcmp != 0) return $strcmp;
2124
                if($a['sort'] == $b['sort']) return 0;
2125
                return ($a['sort'] < $b['sort']) ? -1 : 1;
2126
            }
2127
        );
2128
2129
        // output the menu
2130
        ptln('<div class="clearer"></div>');
2131
        print p_locale_xhtml('adminplugins');
2132
        ptln('<ul>');
2133
        foreach ($menu as $item) {
2134
            if (!$item['prompt']) continue;
2135
            ptln('  <li><div class="li"><a href="'.wl($ID, 'do=admin&amp;page='.$item['plugin']).'">'.$item['prompt'].'</a></div></li>');
2136
        }
2137
        ptln('</ul>');
2138
    }
2139
}
2140
2141
/**
2142
 * Form to request a new password for an existing account
2143
 *
2144
 * @author Benoit Chesneau <[email protected]>
2145
 * @author Andreas Gohr <[email protected]>
2146
 */
2147
function html_resendpwd() {
2148
    global $lang;
2149
    global $conf;
2150
    global $INPUT;
2151
2152
    $token = preg_replace('/[^a-f0-9]+/','',$INPUT->str('pwauth'));
2153
2154
    if(!$conf['autopasswd'] && $token){
2155
        print p_locale_xhtml('resetpwd');
2156
        print '<div class="centeralign">'.NL;
2157
        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2158
        $form->startFieldset($lang['btn_resendpwd']);
2159
        $form->addHidden('token', $token);
2160
        $form->addHidden('do', 'resendpwd');
2161
2162
        $form->addElement(form_makePasswordField('pass', $lang['pass'], '', 'block', array('size'=>'50')));
2163
        $form->addElement(form_makePasswordField('passchk', $lang['passchk'], '', 'block', array('size'=>'50')));
2164
2165
        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2166
        $form->endFieldset();
2167
        html_form('resendpwd', $form);
2168
        print '</div>'.NL;
2169
    }else{
2170
        print p_locale_xhtml('resendpwd');
2171
        print '<div class="centeralign">'.NL;
2172
        $form = new Doku_Form(array('id' => 'dw__resendpwd'));
2173
        $form->startFieldset($lang['resendpwd']);
2174
        $form->addHidden('do', 'resendpwd');
2175
        $form->addHidden('save', '1');
2176
        $form->addElement(form_makeTag('br'));
2177
        $form->addElement(form_makeTextField('login', $INPUT->post->str('login'), $lang['user'], '', 'block'));
2178
        $form->addElement(form_makeTag('br'));
2179
        $form->addElement(form_makeTag('br'));
2180
        $form->addElement(form_makeButton('submit', '', $lang['btn_resendpwd']));
2181
        $form->endFieldset();
2182
        html_form('resendpwd', $form);
2183
        print '</div>'.NL;
2184
    }
2185
}
2186
2187
/**
2188
 * Return the TOC rendered to XHTML
2189
 *
2190
 * @author Andreas Gohr <[email protected]>
2191
 *
2192
 * @param array $toc
2193
 * @return string html
2194
 */
2195
function html_TOC($toc){
2196
    if(!count($toc)) return '';
2197
    global $lang;
2198
    $out  = '<!-- TOC START -->'.DOKU_LF;
2199
    $out .= '<div id="dw__toc">'.DOKU_LF;
2200
    $out .= '<h3 class="toggle">';
2201
    $out .= $lang['toc'];
2202
    $out .= '</h3>'.DOKU_LF;
2203
    $out .= '<div>'.DOKU_LF;
2204
    $out .= html_buildlist($toc,'toc','html_list_toc','html_li_default',true);
2205
    $out .= '</div>'.DOKU_LF.'</div>'.DOKU_LF;
2206
    $out .= '<!-- TOC END -->'.DOKU_LF;
2207
    return $out;
2208
}
2209
2210
/**
2211
 * Callback for html_buildlist
2212
 *
2213
 * @param array $item
2214
 * @return string html
2215
 */
2216
function html_list_toc($item){
2217
    if(isset($item['hid'])){
2218
        $link = '#'.$item['hid'];
2219
    }else{
2220
        $link = $item['link'];
2221
    }
2222
2223
    return '<a href="'.$link.'">'.hsc($item['title']).'</a>';
2224
}
2225
2226
/**
2227
 * Helper function to build TOC items
2228
 *
2229
 * Returns an array ready to be added to a TOC array
2230
 *
2231
 * @param string $link  - where to link (if $hash set to '#' it's a local anchor)
2232
 * @param string $text  - what to display in the TOC
2233
 * @param int    $level - nesting level
2234
 * @param string $hash  - is prepended to the given $link, set blank if you want full links
2235
 * @return array the toc item
2236
 */
2237
function html_mktocitem($link, $text, $level, $hash='#'){
2238
    return  array( 'link'  => $hash.$link,
2239
            'title' => $text,
2240
            'type'  => 'ul',
2241
            'level' => $level);
2242
}
2243
2244
/**
2245
 * Output a Doku_Form object.
2246
 * Triggers an event with the form name: HTML_{$name}FORM_OUTPUT
2247
 *
2248
 * @author Tom N Harris <[email protected]>
2249
 *
2250
 * @param string     $name The name of the form
2251
 * @param Doku_Form  $form The form
2252
 */
2253
function html_form($name, &$form) {
2254
    // Safety check in case the caller forgets.
2255
    $form->endFieldset();
2256
    trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
2257
}
2258
2259
/**
2260
 * Form print function.
2261
 * Just calls printForm() on the data object.
2262
 *
2263
 * @param Doku_Form $data The form
2264
 */
2265
function html_form_output($data) {
2266
    $data->printForm();
2267
}
2268
2269
/**
2270
 * Embed a flash object in HTML
2271
 *
2272
 * This will create the needed HTML to embed a flash movie in a cross browser
2273
 * compatble way using valid XHTML
2274
 *
2275
 * The parameters $params, $flashvars and $atts need to be associative arrays.
2276
 * No escaping needs to be done for them. The alternative content *has* to be
2277
 * escaped because it is used as is. If no alternative content is given
2278
 * $lang['noflash'] is used.
2279
 *
2280
 * @author Andreas Gohr <[email protected]>
2281
 * @link   http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
2282
 *
2283
 * @param string $swf      - the SWF movie to embed
2284
 * @param int $width       - width of the flash movie in pixels
2285
 * @param int $height      - height of the flash movie in pixels
2286
 * @param array $params    - additional parameters (<param>)
2287
 * @param array $flashvars - parameters to be passed in the flashvar parameter
2288
 * @param array $atts      - additional attributes for the <object> tag
2289
 * @param string $alt      - alternative content (is NOT automatically escaped!)
2290
 * @return string         - the XHTML markup
2291
 */
2292
function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){
2293
    global $lang;
2294
2295
    $out = '';
2296
2297
    // prepare the object attributes
2298
    if(is_null($atts)) $atts = array();
2299
    $atts['width']  = (int) $width;
2300
    $atts['height'] = (int) $height;
2301
    if(!$atts['width'])  $atts['width']  = 425;
2302
    if(!$atts['height']) $atts['height'] = 350;
2303
2304
    // add object attributes for standard compliant browsers
2305
    $std = $atts;
2306
    $std['type'] = 'application/x-shockwave-flash';
2307
    $std['data'] = $swf;
2308
2309
    // add object attributes for IE
2310
    $ie  = $atts;
2311
    $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
2312
2313
    // open object (with conditional comments)
2314
    $out .= '<!--[if !IE]> -->'.NL;
2315
    $out .= '<object '.buildAttributes($std).'>'.NL;
2316
    $out .= '<!-- <![endif]-->'.NL;
2317
    $out .= '<!--[if IE]>'.NL;
2318
    $out .= '<object '.buildAttributes($ie).'>'.NL;
2319
    $out .= '    <param name="movie" value="'.hsc($swf).'" />'.NL;
2320
    $out .= '<!--><!-- -->'.NL;
2321
2322
    // print params
2323
    if(is_array($params)) foreach($params as $key => $val){
2324
        $out .= '  <param name="'.hsc($key).'" value="'.hsc($val).'" />'.NL;
2325
    }
2326
2327
    // add flashvars
2328
    if(is_array($flashvars)){
2329
        $out .= '  <param name="FlashVars" value="'.buildURLparams($flashvars).'" />'.NL;
2330
    }
2331
2332
    // alternative content
2333
    if($alt){
2334
        $out .= $alt.NL;
2335
    }else{
2336
        $out .= $lang['noflash'].NL;
2337
    }
2338
2339
    // finish
2340
    $out .= '</object>'.NL;
2341
    $out .= '<!-- <![endif]-->'.NL;
2342
2343
    return $out;
2344
}
2345
2346
/**
2347
 * Prints HTML code for the given tab structure
2348
 *
2349
 * @param array  $tabs        tab structure
2350
 * @param string $current_tab the current tab id
2351
 */
2352
function html_tabs($tabs, $current_tab = null) {
2353
    echo '<ul class="tabs">'.NL;
2354
2355
    foreach($tabs as $id => $tab) {
2356
        html_tab($tab['href'], $tab['caption'], $id === $current_tab);
2357
    }
2358
2359
    echo '</ul>'.NL;
2360
}
2361
/**
2362
 * Prints a single tab
2363
 *
2364
 * @author Kate Arzamastseva <[email protected]>
2365
 * @author Adrian Lang <[email protected]>
2366
 *
2367
 * @param string $href - tab href
2368
 * @param string $caption - tab caption
2369
 * @param boolean $selected - is tab selected
2370
 */
2371
2372
function html_tab($href, $caption, $selected=false) {
2373
    $tab = '<li>';
2374
    if ($selected) {
2375
        $tab .= '<strong>';
2376
    } else {
2377
        $tab .= '<a href="' . hsc($href) . '">';
2378
    }
2379
    $tab .= hsc($caption)
2380
         .  '</' . ($selected ? 'strong' : 'a') . '>'
2381
         .  '</li>'.NL;
2382
    echo $tab;
2383
}
2384
2385