splitbrain /
dokuwiki
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Admin Plugin Prototype |
||
| 4 | * |
||
| 5 | * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) |
||
| 6 | * @author Christopher Smith <[email protected]> |
||
| 7 | */ |
||
| 8 | // must be run within Dokuwiki |
||
| 9 | if(!defined('DOKU_INC')) die(); |
||
| 10 | |||
| 11 | /** |
||
| 12 | * All DokuWiki plugins to extend the admin function |
||
| 13 | * need to inherit from this class |
||
| 14 | */ |
||
| 15 | class DokuWiki_Admin_Plugin extends DokuWiki_Plugin { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Return the text that is displayed at the main admin menu |
||
| 19 | * (Default localized language string 'menu' is returned, override this function for setting another name) |
||
| 20 | * |
||
| 21 | * @param string $language language code |
||
| 22 | * @return string menu string |
||
| 23 | */ |
||
| 24 | public function getMenuText($language) { |
||
| 25 | $menutext = $this->getLang('menu'); |
||
| 26 | if (!$menutext) { |
||
| 27 | $info = $this->getInfo(); |
||
| 28 | $menutext = $info['name'].' ...'; |
||
| 29 | } |
||
| 30 | return $menutext; |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Return the path to the icon being displayed in the main admin menu. |
||
| 35 | * By default it tries to find an 'admin.svg' file in the plugin directory. |
||
| 36 | * (Override this function for setting another image) |
||
| 37 | * |
||
| 38 | * Important: you have to return a single path, monochrome SVG icon! It has to be |
||
| 39 | * under 2 Kilobytes! |
||
| 40 | * |
||
| 41 | * We recommend icons from https://materialdesignicons.com/ or to use a matching |
||
| 42 | * style. |
||
| 43 | * |
||
| 44 | * @return string full path to the icon file |
||
| 45 | */ |
||
| 46 | public function getMenuIcon() { |
||
| 47 | $plugin = $this->getPluginName(); |
||
| 48 | return DOKU_PLUGIN . $plugin . '/admin.svg'; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Determine position in list in admin window |
||
| 53 | * Lower values are sorted up |
||
| 54 | * |
||
| 55 | * @return int |
||
| 56 | */ |
||
| 57 | public function getMenuSort() { |
||
| 58 | return 1000; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Carry out required processing |
||
| 63 | */ |
||
| 64 | public function handle() { |
||
| 65 | trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Output html of the admin page |
||
| 70 | */ |
||
| 71 | public function html() { |
||
| 72 | trigger_error('html() not implemented in '.get_class($this), E_USER_WARNING); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Checks if access should be granted to this admin plugin |
||
| 77 | * |
||
| 78 | * @return bool true if the current user may access this admin plugin |
||
| 79 | */ |
||
| 80 | public function isAccessibleByCurrentUser() { |
||
| 81 | global $INFO; |
||
| 82 | |||
| 83 | $data['instance'] = $this; |
||
|
0 ignored issues
–
show
|
|||
| 84 | $data['hasAccess'] = false; |
||
| 85 | |||
| 86 | $event = new Doku_Event('ADMINPLUGIN_ACCESS_CHECK', $data); |
||
| 87 | if($event->advise_before()) { |
||
| 88 | if ($this->forAdminOnly()) { |
||
| 89 | $data['hasAccess'] = $INFO['isadmin']; |
||
| 90 | } else { |
||
| 91 | $data['hasAccess'] = $INFO['ismanager']; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | $event->advise_after(); |
||
| 95 | |||
| 96 | return $data['hasAccess']; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Return true for access only by admins (config:superuser) or false if managers are allowed as well |
||
| 101 | * |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | public function forAdminOnly() { |
||
| 105 | return true; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Return array with ToC items. Items can be created with the html_mktocitem() |
||
| 110 | * |
||
| 111 | * @see html_mktocitem() |
||
| 112 | * @see tpl_toc() |
||
| 113 | * |
||
| 114 | * @return array |
||
| 115 | */ |
||
| 116 | public function getTOC(){ |
||
| 117 | return array(); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | //Setup VIM: ex: et ts=4 : |
||
| 121 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.