vendredi 24 juillet 2015

Why won't my PHP IF/ELSE work in dokuwiki main.php?

I want to hide show backlinks and show revisions action links in the default template if a visitor is not logged in as admin.

The code that controls the display of those actions in dokuwiki/lib/tpl/dokuwiki/main.php

<?php
                            $data = array(
                                'view'  => 'main',
                                'items' => array(
                                    'edit'      => tpl_action('edit',      1, 'li', 1, '<span>', '</span>'),
                                    'revert'    => tpl_action('revert',    1, 'li', 1, '<span>', '</span>'),
                                    'revisions' => tpl_action('revisions', 1, 'li', 1, '<span>', '</span>'),
                                    'backlink'  => tpl_action('backlink',  1, 'li', 1, '<span>', '</span>'),
                                    'subscribe' => tpl_action('subscribe', 1, 'li', 1, '<span>', '</span>'),
                                    'top'       => tpl_action('top',       1, 'li', 1, '<span>', '</span>')
                                )
                            );


                            $evt = new Doku_Event('TEMPLATE_PAGETOOLS_DISPLAY', $data);
                            if($evt->advise_before()){
                                foreach($evt->data['items'] as $k => $html) echo $html;
                            }
                            $evt->advise_after();
                            unset($data);
                            unset($evt);
                        ?>

Commenting out the revert and revisions lines from the array has the desired effect. So my PHP ignorant solution to the problem is to try and use one of two arrays, one with the revert and revisions, and the other without - using ($INFO['isadmin']) as the test for an IF/ELSE.

I've tried various formatting and many variations to no effect and don't even know if I'm trying to solve the problem wrongly, whether main.php has no access to $INFO, or I've just failed to get the IF/ELSE formatting correct, but I only have a very basic understanding of PHP (gleaned from similar answers here).

Any helpful suggestions would be most appreciated (other than go study PHP for a week).

Aucun commentaire:

Enregistrer un commentaire